Commit 86d70837 authored by GAO Bin's avatar GAO Bin
Browse files

mem_switch: add address translation in switch

parent 0db9a96c
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from click import command
import simbricks.orchestration.experiments as exp import simbricks.orchestration.experiments as exp
import simbricks.orchestration.nodeconfig as node import simbricks.orchestration.nodeconfig as node
import simbricks.orchestration.simulators as sim import simbricks.orchestration.simulators as sim
...@@ -28,17 +29,20 @@ experiments = [] ...@@ -28,17 +29,20 @@ experiments = []
num_of_netmem =[1, 2, 3, 4] num_of_netmem =[1, 2, 3, 4]
class MemTest(node.AppConfig): class MemTest(node.AppConfig):
def __init__(self, addr): def __init__(self):
self.addr = addr self.addr = []
def run_cmds(self, node): def run_cmds(self, node):
return [ commands = []
f'busybox devmem 0x{self.addr:x} 64 0x42', for addr in self.addr:
f'busybox devmem 0x{self.addr:x} 64' commands.append(f'busybox devmem 0x{addr:x} 64 0x42')
] commands.append(f'busybox devmem 0x{addr:x} 64')
return commands
# AS_ID,VADDR_START(include),VADDR_END(not include),MEMNODE_MAC,PHYS_START # AS_ID,VADDR_START(include),VADDR_END(not include),MEMNODE_MAC,PHYS_START
sw_mem_map = [(0, 0, 1073741824, '00:00:00:00:00:02', 0)] sw_mem_map = [(0, 0, 1024*1024*1024, '00:00:00:00:00:02', 0),
(0, 1024*1024*1024, 1024*1024*1024*2, '00:00:00:00:00:03', 1024*1024*1024)]
for h in ['gk']: for h in ['gk']:
e = exp.Experiment('memsw-' + h) e = exp.Experiment('memsw-' + h)
...@@ -49,13 +53,21 @@ for h in ['gk']: ...@@ -49,13 +53,21 @@ for h in ['gk']:
mem.addr = 0x2000000000 #0x2000000000000000 mem.addr = 0x2000000000 #0x2000000000000000
mem.mac = '00:00:00:00:00:01' mem.mac = '00:00:00:00:00:01'
netmem = sim.NetMem() netmem1 = sim.NetMem()
netmem.mac = '00:00:00:00:00:02' netmem1.mac = '00:00:00:00:00:02'
netmem1.name = 'netmem1'
netmem2 = sim.NetMem()
netmem2.mac = '00:00:00:00:00:03'
netmem2.name = 'netmem2'
netmem2.addr = mem.addr +netmem1.size
node_config = node.NodeConfig() node_config = node.NodeConfig()
node_config.nockp = True node_config.nockp = True
node_config.app = MemTest(mem.addr) node_config.app = MemTest()
node_config.app.addr.append(mem.addr)
node_config.app.addr.append(mem.addr+netmem1.size)
net = sim.MemSwitchNet() net = sim.MemSwitchNet()
for tp in sw_mem_map: for tp in sw_mem_map:
...@@ -74,7 +86,8 @@ for h in ['gk']: ...@@ -74,7 +86,8 @@ for h in ['gk']:
host.wait = True host.wait = True
mem.set_network(net) mem.set_network(net)
netmem.set_network(net) netmem1.set_network(net)
netmem2.set_network(net);
e.add_memdev(mem) e.add_memdev(mem)
host.add_memdev(mem) host.add_memdev(mem)
......
...@@ -42,9 +42,10 @@ ...@@ -42,9 +42,10 @@
extern "C" { extern "C" {
#include <simbricks/network/if.h> #include <simbricks/network/if.h>
#include <simbricks/nicif/nicif.h> #include <simbricks/nicif/nicif.h>
#include <simbricks/mem/memop.h>
}; };
// #define NETSWITCH_DEBUG #define NETSWITCH_DEBUG
#define NETSWITCH_STAT #define NETSWITCH_STAT
struct SimbricksBaseIfParams netParams; struct SimbricksBaseIfParams netParams;
...@@ -71,7 +72,7 @@ union ether_addr ...@@ -71,7 +72,7 @@ union ether_addr
} __attribute__ ((__packed__)); } __attribute__ ((__packed__));
struct table_entry { struct table_entry {
int as_id; uint64_t as_id;
uint64_t vaddr_start; uint64_t vaddr_start;
uint64_t vaddr_end; uint64_t vaddr_end;
union ether_addr node_mac; union ether_addr node_mac;
...@@ -96,6 +97,11 @@ struct MAC { ...@@ -96,6 +97,11 @@ struct MAC {
} }
return true; return true;
} }
MAC operator=(const uint8_t *other) const {
MAC mac(other);
return mac;
}
}; };
namespace std { namespace std {
template <> template <>
...@@ -394,9 +400,11 @@ static void switch_pkt(NetPort &port, size_t iport) { ...@@ -394,9 +400,11 @@ static void switch_pkt(NetPort &port, size_t iport) {
// Get MAC addresses // Get MAC addresses
MAC dst((const uint8_t *)pkt_data), src((const uint8_t *)pkt_data + 6); MAC dst((const uint8_t *)pkt_data), src((const uint8_t *)pkt_data + 6);
// MAC learning // MAC learning
if (!(src == bcast_addr)) { if (!(src == bcast_addr)) {
mac_table[src] = iport; mac_table[src] = iport;
} }
// L2 forwarding // L2 forwarding
auto i = mac_table.find(dst); auto i = mac_table.find(dst);
if (i != mac_table.end()) { if (i != mac_table.end()) {
...@@ -405,10 +413,42 @@ static void switch_pkt(NetPort &port, size_t iport) { ...@@ -405,10 +413,42 @@ static void switch_pkt(NetPort &port, size_t iport) {
forward_pkt(pkt_data, pkt_len, eport, iport); forward_pkt(pkt_data, pkt_len, eport, iport);
} else { } else {
// Broadcast // Broadcast
for (size_t eport = 0; eport < ports.size(); eport++) { struct ethhdr *eth_hdr = (struct ethhdr*)pkt_data;
if (eport != iport) { struct MemOp *memop = (struct MemOp *)(((const uint8_t *)pkt_data) +42);
// Do not forward to ingress port for (size_t i = 0; i < map_table.size(); i++)
forward_pkt(pkt_data, pkt_len, eport, iport); {
if (memop->as_id == map_table[i].as_id &&
memop->addr >= map_table[i].vaddr_start &&
memop->addr <= map_table[i].vaddr_end){
for (int k = 0; k < ETH_ALEN; k++){
eth_hdr->h_dest[k] = map_table[i].node_mac.ether_addr_octet[k];
}
dst = eth_hdr->h_dest;
auto k = mac_table.find(dst);
if (k != mac_table.end()) {
size_t eport = k->second;
if (eport != iport){
#ifdef NETSWITCH_DEBUG
printf("Forwarding memop to netmem");
#endif
forward_pkt(pkt_data, pkt_len, eport, iport);
}
}else {
#ifdef NETSWITCH_DEBUG
printf("Dest netmem is not in the mac table, broadcast first\n");
#endif
for (size_t eport = 0; eport < ports.size(); eport++) {
if (eport != iport) {
// Do not forward to ingress port
forward_pkt(pkt_data, pkt_len, eport, iport);
}
}
}
break;
}
if (i == map_table.size()-1)
{
fprintf(stderr, "Dest netmem is unavaliable.");
} }
} }
} }
...@@ -503,9 +543,10 @@ int main(int argc, char *argv[]) { ...@@ -503,9 +543,10 @@ int main(int argc, char *argv[]) {
token = strtok(NULL, ","); token = strtok(NULL, ",");
} }
printf("as_id: %d vaddr_start: %lu vadd_end: %lu phys_start: %lu\n", ent.as_id, ent.vaddr_start, ent.vaddr_end, ent.phys_start); #ifdef NETSWITCH_DEBUG
printf("mac_byte: %lx\n", ent.node_mac.ether_addr_64); printf("as_id: %lu vaddr_start: %lu vadd_end: %lu phys_start: %lu\n", ent.as_id, ent.vaddr_start, ent.vaddr_end, ent.phys_start);
printf("mac_byte: %lx\n", ent.node_mac.ether_addr_64);
#endif
map_table.push_back(ent); map_table.push_back(ent);
break; break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment