コード例 #1
0
 def test_init(self, SwitchCls):
     # Arrange
     sw1 = SwitchCls()
     sw1.dpid = 1
     # It's really hard to mock this, because of using assert_type
     p1 = ofp_phy_port(port_no=1)
     hw_addr_str = "11:22:33:44:55:66"
     hw_addr = EthAddr(hw_addr_str)
     ip_str = "127.0.0.1"
     ip = IPAddr(ip_str)
     ifname = "eth0"
     interface = HostInterface(hw_addr, ip, name=ifname)
     hname = "h1"
     hid = 1
     host = Host(interface, name=hname, hid=hid)
     # Act
     link = AccessLink(host, interface, sw1, p1)
     # Assert
     self.assertEquals(link.host, host)
     self.assertEquals(link.interface, interface)
コード例 #2
0
 def test_to_jsont(self, SwitchCls):
     # Arrange
     sw1 = SwitchCls()
     sw1.dpid = 1
     sw1.to_json.return_value = 1
     # It's really hard to mock this, because of using assert_type
     p1 = ofp_phy_port(port_no=1)
     hw_addr_str = "11:22:33:44:55:66"
     hw_addr = EthAddr(hw_addr_str)
     ip_str = "127.0.0.1"
     ip = IPAddr(ip_str)
     ifname = "eth0"
     interface = HostInterface(hw_addr, ip, name=ifname)
     hname = "h1"
     hid = 1
     host = Host(interface, name=hname, hid=hid)
     link = AccessLink(host, interface, sw1, p1)
     # Act
     json_dict = link.to_json()
     # Assert
     self.assertEquals(json_dict['node1'], host.to_json())
     self.assertEquals(json_dict['port1'], interface.to_json())
     self.assertEquals(json_dict['node2'], 1)
     self.assertEquals(json_dict['port2'], p1.to_json())