def test_to_jsont(self, SwitchCls): # Arrange json_dict = { "node1": { "hid": 1, "interfaces": [{ "hw_addr": "11:22:33:44:55:66", "ips": ["127.0.0.1"], "__type__": "sts.entities.hosts.HostInterface", "name": "eth0" }], "__type__": "sts.entities.hosts.Host", "name": "h1" }, "port2": { "hw_addr": "00:00:00:00:00:00", "curr": 0, "name": "", "supported": 0, "__type__": "pox.openflow.libopenflow_01.ofp_phy_port", "state": 0, "advertised": 0, "peer": 0, "config": 0, "port_no": 1 }, "node2": 1, "__type__": "sts.entities.sts_entities.AccessLink", "port1": { "hw_addr": "11:22:33:44:55:66", "ips": ["127.0.0.1"], "__type__": "sts.entities.hosts.HostInterface", "name": "eth0" } } 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) # Act link = AccessLink.from_json(json_dict) # Assert self.assertEquals(link.host.to_json(), host.to_json()) self.assertEquals(link.interface.to_json(), interface.to_json()) self.assertEquals(link.switch, 1) self.assertEquals(link.switch_port.to_json(), p1.to_json())
def test_to_json(self): # Arrange 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 json_dict = host.to_json() # Assert self.assertEquals(json_dict['name'], hname) self.assertEquals(json_dict['hid'], hid) self.assertEquals(len(json_dict['interfaces']), 1) self.assertEquals(json_dict['interfaces'][0], interface.to_json())
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())
def test_to_jsont(self, SwitchCls): # Arrange json_dict = { "node1": { "hid": 1, "interfaces": [ { "hw_addr": "11:22:33:44:55:66", "ips": [ "127.0.0.1" ], "__type__": "sts.entities.hosts.HostInterface", "name": "eth0" } ], "__type__": "sts.entities.hosts.Host", "name": "h1" }, "port2": { "hw_addr": "00:00:00:00:00:00", "curr": 0, "name": "", "supported": 0, "__type__": "pox.openflow.libopenflow_01.ofp_phy_port", "state": 0, "advertised": 0, "peer": 0, "config": 0, "port_no": 1 }, "node2": 1, "__type__": "sts.entities.sts_entities.AccessLink", "port1": { "hw_addr": "11:22:33:44:55:66", "ips": [ "127.0.0.1" ], "__type__": "sts.entities.hosts.HostInterface", "name": "eth0" } } 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) # Act link = AccessLink.from_json(json_dict) # Assert self.assertEquals(link.host.to_json(), host.to_json()) self.assertEquals(link.interface.to_json(), interface.to_json()) self.assertEquals(link.switch, 1) self.assertEquals(link.switch_port.to_json(), p1.to_json())