"research/object_detection/utils/tf_version.py" did not exist on "ac5fff19dcb54bb341b7bfb3cf9f554f2d5f92a5"
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 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from click import command
import simbricks.orchestration.experiments as exp
import simbricks.orchestration.nodeconfig as node
import simbricks.orchestration.simulators as sim
......@@ -28,17 +29,20 @@ experiments = []
num_of_netmem =[1, 2, 3, 4]
class MemTest(node.AppConfig):
def __init__(self, addr):
self.addr = addr
def __init__(self):
self.addr = []
def run_cmds(self, node):
return [
f'busybox devmem 0x{self.addr:x} 64 0x42',
f'busybox devmem 0x{self.addr:x} 64'
]
commands = []
for addr in self.addr:
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
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']:
e = exp.Experiment('memsw-' + h)
......@@ -49,13 +53,21 @@ for h in ['gk']:
mem.addr = 0x2000000000 #0x2000000000000000
mem.mac = '00:00:00:00:00:01'
netmem = sim.NetMem()
netmem.mac = '00:00:00:00:00:02'
netmem1 = sim.NetMem()
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.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()
for tp in sw_mem_map:
......@@ -74,7 +86,8 @@ for h in ['gk']:
host.wait = True
mem.set_network(net)
netmem.set_network(net)
netmem1.set_network(net)
netmem2.set_network(net);
e.add_memdev(mem)
host.add_memdev(mem)
......
......@@ -42,9 +42,10 @@
extern "C" {
#include <simbricks/network/if.h>
#include <simbricks/nicif/nicif.h>
#include <simbricks/mem/memop.h>
};
// #define NETSWITCH_DEBUG
#define NETSWITCH_DEBUG
#define NETSWITCH_STAT
struct SimbricksBaseIfParams netParams;
......@@ -71,7 +72,7 @@ union ether_addr
} __attribute__ ((__packed__));
struct table_entry {
int as_id;
uint64_t as_id;
uint64_t vaddr_start;
uint64_t vaddr_end;
union ether_addr node_mac;
......@@ -96,6 +97,11 @@ struct MAC {
}
return true;
}
MAC operator=(const uint8_t *other) const {
MAC mac(other);
return mac;
}
};
namespace std {
template <>
......@@ -394,9 +400,11 @@ static void switch_pkt(NetPort &port, size_t iport) {
// Get MAC addresses
MAC dst((const uint8_t *)pkt_data), src((const uint8_t *)pkt_data + 6);
// MAC learning
if (!(src == bcast_addr)) {
mac_table[src] = iport;
}
// L2 forwarding
auto i = mac_table.find(dst);
if (i != mac_table.end()) {
......@@ -405,6 +413,30 @@ static void switch_pkt(NetPort &port, size_t iport) {
forward_pkt(pkt_data, pkt_len, eport, iport);
} else {
// Broadcast
struct ethhdr *eth_hdr = (struct ethhdr*)pkt_data;
struct MemOp *memop = (struct MemOp *)(((const uint8_t *)pkt_data) +42);
for (size_t i = 0; i < map_table.size(); i++)
{
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
......@@ -412,6 +444,14 @@ static void switch_pkt(NetPort &port, size_t iport) {
}
}
}
break;
}
if (i == map_table.size()-1)
{
fprintf(stderr, "Dest netmem is unavaliable.");
}
}
}
} else if (poll == NetPort::kRxPollSync) {
#ifdef NETSWITCH_STAT
d2n_poll_sync += 1;
......@@ -503,9 +543,10 @@ int main(int argc, char *argv[]) {
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("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);
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