def test_ip_addr_to_iface(self): """ Tests ip_addr_to_iface to ensure that the iface name is looked up properly. """ iface_list = { 'eth0': { 'mac_addr': None, 'ip_addr': '10.2.34.6', 'ip_addrs': ['10.2.99.99', '10.2.34.6'], 'link_speed': None, }, 'eth1': { 'mac_addr': None, 'ip_addr': '10.2.99.99', 'ip_addrs': ['10.2.99.99'], 'link_speed': None, } } self.assertEqual(net.ip_addr_to_iface('10.2.34.6', iface_list), 'eth0') self.assertEqual(net.ip_addr_to_iface('10.2.99.99', iface_list), 'eth1') # TODO: If the IP address cannot be found it should probably not # raise a KeyError but instead fail more gracefully self.assertRaises(KeyError, net.ip_addr_to_iface, '10.2.100.100', iface_list)
def commit_xport(self, sid, xport_info): """ Commit transport Saves the transport configuration to the device. Returns the status of the commit. """ self.log.trace("Sanity checking xport_info %s...", str(xport_info)) assert xport_info['type'] == 'UDP' assert any([ xport_info['ipv4'] == x['ip_addr'] for x in itervalues(self._chdr_ifaces) ]) assert xport_info['port'] == str(self.chdr_port) assert len(xport_info.get('src_ipv4')) > 5 assert int(xport_info.get('src_port')) > 0 sender_addr = xport_info['src_ipv4'] sender_port = int(xport_info['src_port']) self.log.trace("Incoming connection is coming from %s:%d", sender_addr, sender_port) mac_addr = net.get_mac_addr(sender_addr) if mac_addr is None: raise RuntimeError( "Could not find MAC address for IP address {}".format( sender_addr)) self.log.trace("Incoming connection is coming from %s", mac_addr) eth_iface = net.ip_addr_to_iface(xport_info['ipv4'], self._chdr_ifaces) xbar_port = self.iface_config[eth_iface]['xbar_port'] self.log.trace("Using Ethernet interface %s, crossbar port %d", eth_iface, xbar_port) xbar_iface = lib.xbar.xbar(self.get_xbar_dev(eth_iface)) xbar_iface.set_route(sid.src_addr, xbar_port) self._eth_dispatchers[eth_iface].set_route(sid.reversed(), sender_addr, sender_port) self.log.trace("UDP transport successfully committed!") self._previous_block_ep[sid.src_addr] = sid.get_dst_block() if xport_info.get('xport_type') == 'TX_DATA': self._allocations[eth_iface] = \ {'tx': self._allocations.get(eth_iface, {}).get('tx', 0) + 1} if xport_info.get('xport_type') == 'RX_DATA': self._allocations[eth_iface] = \ {'rx': self._allocations.get(eth_iface, {}).get('rx', 0) + 1} self.log.trace( "New link allocations for %s: TX: %d RX: %d", eth_iface, self._allocations.get(eth_iface, {}).get('tx', 0), self._allocations.get(eth_iface, {}).get('rx', 0), ) return True
def commit_xport(self, sid, xport_info): """ Commit transport Saves the transport configuration to the device. Returns the status of the commit. """ self.log.trace("Sanity checking xport_info %s...", str(xport_info)) assert xport_info['type'] == 'UDP' assert any([xport_info['ipv4'] == x['ip_addr'] for x in itervalues(self._chdr_ifaces)]) assert xport_info['port'] == str(self.chdr_port) assert len(xport_info.get('src_ipv4')) > 5 assert int(xport_info.get('src_port')) > 0 sender_addr = xport_info['src_ipv4'] sender_port = int(xport_info['src_port']) self.log.trace("Incoming connection is coming from %s:%d", sender_addr, sender_port) mac_addr = net.get_mac_addr(sender_addr) if mac_addr is None: raise RuntimeError( "Could not find MAC address for IP address {}".format( sender_addr)) self.log.trace("Incoming connection is coming from %s", mac_addr) eth_iface = net.ip_addr_to_iface(xport_info['ipv4'], self._chdr_ifaces) xbar_port = self.iface_config[eth_iface]['xbar_port'] self.log.trace("Using Ethernet interface %s, crossbar port %d", eth_iface, xbar_port) xbar_iface = lib.xbar.xbar(self.get_xbar_dev(eth_iface)) xbar_iface.set_route(sid.src_addr, xbar_port) self._eth_dispatchers[eth_iface].set_route( sid.reversed(), sender_addr, sender_port) self.log.trace("UDP transport successfully committed!") self._previous_block_ep[sid.src_addr] = sid.get_dst_block() if xport_info.get('xport_type') == 'TX_DATA': self._allocations[eth_iface] = \ {'tx': self._allocations.get(eth_iface, {}).get('tx', 0) + 1} if xport_info.get('xport_type') == 'RX_DATA': self._allocations[eth_iface] = \ {'rx': self._allocations.get(eth_iface, {}).get('rx', 0) + 1} self.log.trace( "New link allocations for %s: TX: %d RX: %d", eth_iface, self._allocations.get(eth_iface, {}).get('tx', 0), self._allocations.get(eth_iface, {}).get('rx', 0), ) return True