From e7f7f06b498eed374a62fa15894747dd1acf892d Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Mon, 12 Jun 2017 10:33:09 -0700 Subject: mpm: Added eth table preloading capability --- mpm/python/usrp_mpm/ethtable.py | 10 ++++-- mpm/python/usrp_mpm/periph_manager/n310.py | 51 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) (limited to 'mpm') diff --git a/mpm/python/usrp_mpm/ethtable.py b/mpm/python/usrp_mpm/ethtable.py index e97b05856..78f2e60a8 100644 --- a/mpm/python/usrp_mpm/ethtable.py +++ b/mpm/python/usrp_mpm/ethtable.py @@ -87,15 +87,19 @@ class EthDispatcherTable(object): self.log.error( "Could not resolve a MAC address for IP address `{}'".format(ip_addr) ) + dst_ep = sid.dst_ep self.log.debug( - "Routing SID `{sid}' to IP address `{ip}', " \ + "Routing SID `{sid}' (endpoint `{ep}') to IP address `{ip}', " \ "MAC address `{mac}', port `{port}'".format( - sid=str(sid), ip=ip_addr, mac=mac_addr, port=udp_port + sid=str(sid), + ep=dst_ep, + ip=ip_addr, + mac=mac_addr, + port=udp_port ) ) ip_addr_int = int(netaddr.IPAddress(ip_addr)) mac_addr_int = int(netaddr.EUI(mac_addr)) - dst_ep = sid.dst_ep sid_offset = 4 * dst_ep def poke_and_trace(addr, data): " Do a poke32() and log.trace() " diff --git a/mpm/python/usrp_mpm/periph_manager/n310.py b/mpm/python/usrp_mpm/periph_manager/n310.py index 9531672ab..805ffd209 100644 --- a/mpm/python/usrp_mpm/periph_manager/n310.py +++ b/mpm/python/usrp_mpm/periph_manager/n310.py @@ -154,8 +154,59 @@ class n310(PeriphManagerBase): } for ifname, table in iteritems(self._eth_dispatchers): table.set_ipv4_addr(self._chdr_interfaces[ifname]['ip_addr']) + if 'preload_ethtables' in args: + self._preload_ethtables( + self._eth_dispatchers, + args['preload_ethtables'] + ) return result + def _preload_ethtables(self, eth_dispatchers, table_file): + """ + Populates the ethernet tables from a JSON file + """ + import json + try: + eth_table_data = json.load(open(table_file)) + except ValueError as ex: + self.log.warning( + "Bad values in preloading table file: %s", + str(ex) + ) + return + self.log.info( + "Preloading Ethernet dispatch tables from JSON file `%s'.", + table_file + ) + for eth_iface, data in iteritems(eth_table_data): + if eth_iface not in eth_dispatchers: + self.log.warning( + "Request to preload eth dispatcher table for " + "iface `{}', but no such interface is " + "registered. Known interfaces: {}".format( + str(eth_iface), + ",".join(eth_dispatchers.keys()) + ) + ) + continue + eth_dispatcher = eth_dispatchers[eth_iface] + self.log.debug("Preloading {} dispatch table".format(eth_iface)) + try: + for dst_ep, udp_data in iteritems(data): + sid = SID() + sid.set_dst_ep(int(dst_ep)) + eth_dispatcher.set_route( + sid, + udp_data['ip_addr'], + udp_data['port'], + udp_data.get('mac_addr', None) + ) + except ValueError as ex: + self.log.warning( + "Bad values in preloading table file: %s", + str(ex) + ) + def _allocate_sid(self, sender_addr, port, sid, xbar_src_addr, xbar_src_port, new_ep): """ Get the MAC address of the sender and store it in the FPGA ARP table -- cgit v1.2.3