Esempio n. 1
0
    def test_eq(self, SwitchCls):
        sw1 = mock.MagicMock()
        sw1.dpid = 1
        sw2 = SwitchCls()
        sw2.dpid = 2
        # It's really hard to mock this, because of using assert_type
        p1 = ofp_phy_port(port_no=1)
        p2 = ofp_phy_port(port_no=2)
        sw1.ports = [p1]
        sw2.ports = [p2]
        link1 = Link(sw1, p1, sw2, p2)
        link2 = Link(sw2, p2, sw1, p1)

        self.assertEquals(link1, link1)
        self.assertNotEquals(link1, link2)
Esempio n. 2
0
 def test_from_json(self):
   # Arrange
   sw1 = mock.Mock()
   sw1.dpid = 1
   sw1.to_json.return_value = 1
   sw2 = mock.Mock()
   sw2.dpid = 2
   sw2.to_json.return_value = 2
   # It's really hard to mock this, because of using assert_type
   p1 = ofp_phy_port(port_no=1)
   p2 = ofp_phy_port(port_no=2)
   sw1.ports = [p1]
   sw2.ports = [p2]
   json_dict = {'start_port': {'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},
                'start_node': 1,
                'end_port': {'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': 2},
                '__type__': 'sts.entities.sts_entities.Link',
                'end_node': 2}
   # Act
   link = Link.from_json(json_dict)
   # Assert
   self.assertEquals(link.start_node, json_dict['start_node'])
   self.assertEquals(link.start_port.port_no, json_dict['start_port']['port_no'])
   self.assertEquals(link.end_node, json_dict['end_node'])
   self.assertEquals(link.end_port.port_no, json_dict['end_port']['port_no'])
Esempio n. 3
0
    def test_reversed_link(self, SwitchCls):
        sw1 = mock.MagicMock()
        sw1.dpid = 1
        sw2 = SwitchCls()
        sw2.dpid = 2
        # It's really hard to mock this, because of using assert_type
        p1 = ofp_phy_port(port_no=1)
        p2 = ofp_phy_port(port_no=2)
        sw1.ports = [p1]
        sw2.ports = [p2]
        link1 = Link(sw1, p1, sw2, p2)
        link2 = link1.reversed_link()

        self.assertNotEquals(link1, link2)
        self.assertEquals(sw2.dpid, link2.start_software_switch.dpid)
        self.assertEquals(sw1.dpid, link2.end_software_switch.dpid)
        self.assertEquals(p2, link2.start_port)
        self.assertEquals(p1, link2.end_port)
Esempio n. 4
0
  def test_reversed_link(self, SwitchCls):
    sw1 = mock.MagicMock()
    sw1.dpid = 1
    sw2 = SwitchCls()
    sw2.dpid = 2
    # It's really hard to mock this, because of using assert_type
    p1 = ofp_phy_port(port_no=1)
    p2 = ofp_phy_port(port_no=2)
    sw1.ports = [p1]
    sw2.ports = [p2]
    link1 = Link(sw1, p1, sw2, p2)
    link2 = link1.reversed_link()

    self.assertNotEquals(link1, link2)
    self.assertEquals(sw2.dpid, link2.start_software_switch.dpid)
    self.assertEquals(sw1.dpid, link2.end_software_switch.dpid)
    self.assertEquals(p2, link2.start_port)
    self.assertEquals(p1, link2.end_port)
Esempio n. 5
0
 def test_to_json(self):
     # Arrange
     sw1 = mock.Mock()
     sw1.dpid = 1
     sw1.to_json.return_value = 1
     sw2 = mock.Mock()
     sw2.dpid = 2
     sw2.to_json.return_value = 2
     # It's really hard to mock this, because of using assert_type
     p1 = ofp_phy_port(port_no=1)
     p2 = ofp_phy_port(port_no=2)
     sw1.ports = [p1]
     sw2.ports = [p2]
     link = Link(sw1, p1, sw2, p2)
     # Act
     json_dict = link.to_json()
     # Assert
     self.assertEquals(json_dict['start_node'], 1)
     self.assertEquals(json_dict['start_port']['port_no'], 1)
     self.assertEquals(json_dict['end_node'], 2)
     self.assertEquals(json_dict['end_port']['port_no'], 2)
Esempio n. 6
0
 def test_to_json(self):
   # Arrange
   sw1 = mock.Mock()
   sw1.dpid = 1
   sw1.to_json.return_value = 1
   sw2 = mock.Mock()
   sw2.dpid = 2
   sw2.to_json.return_value = 2
   # It's really hard to mock this, because of using assert_type
   p1 = ofp_phy_port(port_no=1)
   p2 = ofp_phy_port(port_no=2)
   sw1.ports = [p1]
   sw2.ports = [p2]
   link = Link(sw1, p1, sw2, p2)
   # Act
   json_dict = link.to_json()
   # Assert
   self.assertEquals(json_dict['start_node'], 1)
   self.assertEquals(json_dict['start_port']['port_no'], 1)
   self.assertEquals(json_dict['end_node'], 2)
   self.assertEquals(json_dict['end_port']['port_no'], 2)
Esempio n. 7
0
 def test_from_json(self):
     # Arrange
     sw1 = mock.Mock()
     sw1.dpid = 1
     sw1.to_json.return_value = 1
     sw2 = mock.Mock()
     sw2.dpid = 2
     sw2.to_json.return_value = 2
     # It's really hard to mock this, because of using assert_type
     p1 = ofp_phy_port(port_no=1)
     p2 = ofp_phy_port(port_no=2)
     sw1.ports = [p1]
     sw2.ports = [p2]
     json_dict = {
         'start_port': {
             '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
         },
         'start_node': 1,
         'end_port': {
             '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': 2
         },
         '__type__': 'sts.entities.sts_entities.Link',
         'end_node': 2
     }
     # Act
     link = Link.from_json(json_dict)
     # Assert
     self.assertEquals(link.start_node, json_dict['start_node'])
     self.assertEquals(link.start_port.port_no,
                       json_dict['start_port']['port_no'])
     self.assertEquals(link.end_node, json_dict['end_node'])
     self.assertEquals(link.end_port.port_no,
                       json_dict['end_port']['port_no'])