Exemplo n.º 1
0
 def test_serialize_two_ports(self):
     pp1 = ofconfig.PhyPort(
         port_no=0x42,
         hw_addr='\xab\xcd\xef\xa0\xb1\xc2',
         name='testport1',
         config=_create_port_config(no_stp=True,
                                    no_recv_stp=True,
                                    no_flood=True),
         state_link_down=True,
         state_stp=ofconfig.OFPPS_STP_FORWARD,
         curr=_create_port_features(mode_1gb_fd=True, fiber=True),
         advertised=_create_port_features(mode_1gb_fd=True,
                                          fiber=True,
                                          pause=True),
         supported=_create_port_features(mode_1gb_fd=True,
                                         fiber=True,
                                         pause=True,
                                         pause_asym=True),
         peer=_create_port_features(mode_1gb_fd=True,
                                    fiber=True,
                                    autoneg=True))
     pp2 = ofconfig.PhyPort(
         port_no=0x43,
         hw_addr='\xab\xcd\xef\xa0\xb1\xc3',
         name='testport2',
         config=_create_port_config(no_stp=True,
                                    no_recv_stp=True,
                                    no_flood=True),
         state_link_down=True,
         state_stp=ofconfig.OFPPS_STP_FORWARD,
         curr=_create_port_features(mode_1gb_fd=True, fiber=True),
         advertised=_create_port_features(mode_1gb_fd=True,
                                          fiber=True,
                                          pause=True),
         supported=_create_port_features(mode_1gb_fd=True,
                                         fiber=True,
                                         pause=True,
                                         pause_asym=True),
         peer=_create_port_features(mode_1gb_fd=True,
                                    fiber=True,
                                    autoneg=True))
     sf = ofconfig.SwitchFeatures(datapath_id=0x123456,
                                  n_buffers=5,
                                  n_tables=3,
                                  cap_flow_stats=True,
                                  cap_table_stats=False,
                                  cap_port_stats=True,
                                  cap_stp=False,
                                  cap_ip_reasm=True,
                                  cap_queue_stats=False,
                                  cap_arp_match_ip=True,
                                  actions=frozenset((0, 2, 3, 5, 8)),
                                  ports=(pp1, pp2))
     self.assertEqual(
         '\x00\x00\x00\x00\x00\x12\x34\x56'
         '\x00\x00\x00\x05'
         '\x03\x00\x00\x00'
         '\x00\x00\x00\xa5'
         '\x00\x00\x01\x2d' + pp1.serialize() + pp2.serialize(),
         ''.join(sf.serialize()))
Exemplo n.º 2
0
 def test_deserialize_two_ports(self):
     pp1 = ofconfig.PhyPort(
         port_no=0x42,
         hw_addr='\xab\xcd\xef\xa0\xb1\xc2',
         name='testport1',
         config=_create_port_config(no_stp=True,
                                    no_recv_stp=True,
                                    no_flood=True),
         state_link_down=True,
         state_stp=ofconfig.OFPPS_STP_FORWARD,
         curr=_create_port_features(mode_1gb_fd=True, fiber=True),
         advertised=_create_port_features(mode_1gb_fd=True,
                                          fiber=True,
                                          pause=True),
         supported=_create_port_features(mode_1gb_fd=True,
                                         fiber=True,
                                         pause=True,
                                         pause_asym=True),
         peer=_create_port_features(mode_1gb_fd=True,
                                    fiber=True,
                                    autoneg=True))
     pp2 = ofconfig.PhyPort(
         port_no=0x43,
         hw_addr='\xab\xcd\xef\xa0\xb1\xc3',
         name='testport2',
         config=_create_port_config(no_stp=True,
                                    no_recv_stp=True,
                                    no_flood=True),
         state_link_down=True,
         state_stp=ofconfig.OFPPS_STP_FORWARD,
         curr=_create_port_features(mode_1gb_fd=True, fiber=True),
         advertised=_create_port_features(mode_1gb_fd=True,
                                          fiber=True,
                                          pause=True),
         supported=_create_port_features(mode_1gb_fd=True,
                                         fiber=True,
                                         pause=True,
                                         pause_asym=True),
         peer=_create_port_features(mode_1gb_fd=True,
                                    fiber=True,
                                    autoneg=True))
     self.buf.append('\x00\x00\x00\x00\x00\x12\x34\x56'
                     '\x00\x00\x00\x05'
                     '\x03\x00\x00\x00'
                     '\x00\x00\x00\xa5'
                     '\x00\x00\x01\x2d')
     self.buf.append(pp1.serialize())
     self.buf.append(pp2.serialize())
     self.buf.set_message_boundaries(24 + 48 * 2)
     self.assertTupleEqual(
         (0x123456, 5, 3, True, False, True, False, True, False, True,
          frozenset((0, 2, 3, 5, 8)), (pp1, pp2)),
         ofconfig.SwitchFeatures.deserialize(self.buf))
Exemplo n.º 3
0
 def test_create(self):
     pp1 = ofconfig.PhyPort(
         port_no=0x42,
         hw_addr='\xab\xcd\xef\xa0\xb1\xc2',
         name='testport1',
         config=_create_port_config(no_stp=True,
                                    no_recv_stp=True,
                                    no_flood=True),
         state_link_down=True,
         state_stp=ofconfig.OFPPS_STP_FORWARD,
         curr=_create_port_features(mode_1gb_fd=True, fiber=True),
         advertised=_create_port_features(mode_1gb_fd=True,
                                          fiber=True,
                                          pause=True),
         supported=_create_port_features(mode_1gb_fd=True,
                                         fiber=True,
                                         pause=True,
                                         pause_asym=True),
         peer=_create_port_features(mode_1gb_fd=True,
                                    fiber=True,
                                    autoneg=True))
     pp2 = ofconfig.PhyPort(
         port_no=0x43,
         hw_addr='\xab\xcd\xef\xa0\xb1\xc3',
         name='testport2',
         config=_create_port_config(no_stp=True,
                                    no_recv_stp=True,
                                    no_flood=True),
         state_link_down=True,
         state_stp=ofconfig.OFPPS_STP_FORWARD,
         curr=_create_port_features(mode_1gb_fd=True, fiber=True),
         advertised=_create_port_features(mode_1gb_fd=True,
                                          fiber=True,
                                          pause=True),
         supported=_create_port_features(mode_1gb_fd=True,
                                         fiber=True,
                                         pause=True,
                                         pause_asym=True),
         peer=_create_port_features(mode_1gb_fd=True,
                                    fiber=True,
                                    autoneg=True))
     sf = ofconfig.SwitchFeatures(datapath_id=123456,
                                  n_buffers=42,
                                  n_tables=3,
                                  cap_flow_stats=True,
                                  cap_table_stats=False,
                                  cap_port_stats=True,
                                  cap_stp=False,
                                  cap_ip_reasm=True,
                                  cap_queue_stats=False,
                                  cap_arp_match_ip=True,
                                  actions=frozenset((0, 2, 3, 5)),
                                  ports=(pp1, pp2))
Exemplo n.º 4
0
 def test_serialize_every_state_stp(self):
     for i in (ofconfig.OFPPS_STP_LISTEN, ofconfig.OFPPS_STP_LEARN,
               ofconfig.OFPPS_STP_FORWARD, ofconfig.OFPPS_STP_BLOCK):
         state_ser = i | 1  # state_link_down=True
         pp = ofconfig.PhyPort(
             port_no=0x42,
             hw_addr='\xab\xcd\xef\xa0\xb1\xc2',
             name='testport',
             config=_create_port_config(no_stp=True,
                                        no_recv_stp=True,
                                        no_flood=True),
             state_link_down=True,
             state_stp=i,
             curr=_create_port_features(mode_1gb_fd=True, fiber=True),
             advertised=_create_port_features(mode_1gb_fd=True,
                                              fiber=True,
                                              pause=True),
             supported=_create_port_features(mode_1gb_fd=True,
                                             fiber=True,
                                             pause=True,
                                             pause_asym=True),
             peer=_create_port_features(mode_1gb_fd=True,
                                        fiber=True,
                                        autoneg=True))
         self.assertEqual(
             '\x00\x42'
             '\xab\xcd\xef\xa0\xb1\xc2'
             'testport\x00\x00\x00\x00\x00\x00\x00\x00'
             '\x00\x00\x00\x1a' + struct.pack('!L', state_ser) +
             '\x00\x00\x01\x20'
             '\x00\x00\x05\x20'
             '\x00\x00\x0d\x20'
             '\x00\x00\x03\x20', pp.serialize())
Exemplo n.º 5
0
 def test_serialize(self):
     pp = ofconfig.PhyPort(port_no=0x42,
                           hw_addr='\xab\xcd\xef\xa0\xb1\xc2',
                           name='testport',
                           config=_create_port_config(no_stp=True,
                                                      no_recv_stp=True,
                                                      no_flood=True),
                           state_link_down=True,
                           state_stp=ofconfig.OFPPS_STP_FORWARD,
                           curr=_create_port_features(mode_1gb_fd=True,
                                                      fiber=True),
                           advertised=_create_port_features(
                               mode_1gb_fd=True, fiber=True, pause=True),
                           supported=_create_port_features(mode_1gb_fd=True,
                                                           fiber=True,
                                                           pause=True,
                                                           pause_asym=True),
                           peer=_create_port_features(mode_1gb_fd=True,
                                                      fiber=True,
                                                      autoneg=True))
     self.assertEqual(
         '\x00\x42'
         '\xab\xcd\xef\xa0\xb1\xc2'
         'testport\x00\x00\x00\x00\x00\x00\x00\x00'
         '\x00\x00\x00\x1a'
         '\x00\x00\x02\x01'
         '\x00\x00\x01\x20'
         '\x00\x00\x05\x20'
         '\x00\x00\x0d\x20'
         '\x00\x00\x03\x20', pp.serialize())
Exemplo n.º 6
0
 def test_create(self):
     pp = ofconfig.PhyPort(port_no=0x42,
                           hw_addr='\xab\xcd\xef\xa0\xb1\xc2',
                           name='testport',
                           config=_create_port_config(no_stp=True,
                                                      no_recv_stp=True,
                                                      no_flood=True),
                           state_link_down=False,
                           state_stp=ofconfig.OFPPS_STP_FORWARD,
                           curr=_create_port_features(mode_1gb_fd=True,
                                                      fiber=True),
                           advertised=_create_port_features(
                               mode_1gb_fd=True, fiber=True, pause=True),
                           supported=_create_port_features(mode_1gb_fd=True,
                                                           fiber=True,
                                                           pause=True,
                                                           pause_asym=True),
                           peer=_create_port_features(mode_1gb_fd=True,
                                                      fiber=True,
                                                      autoneg=True))
Exemplo n.º 7
0
 def test_serialize_deserialize(self):
     pp = ofconfig.PhyPort(port_no=0x42,
                           hw_addr='\xab\xcd\xef\xa0\xb1\xc2',
                           name='testport',
                           config=_create_port_config(no_stp=True,
                                                      no_recv_stp=True,
                                                      no_flood=True),
                           state_link_down=True,
                           state_stp=ofconfig.OFPPS_STP_FORWARD,
                           curr=_create_port_features(mode_1gb_fd=True,
                                                      fiber=True),
                           advertised=_create_port_features(
                               mode_1gb_fd=True, fiber=True, pause=True),
                           supported=_create_port_features(mode_1gb_fd=True,
                                                           fiber=True,
                                                           pause=True,
                                                           pause_asym=True),
                           peer=_create_port_features(mode_1gb_fd=True,
                                                      fiber=True,
                                                      autoneg=True))
     self.buf.append(pp.serialize())
     self.buf.set_message_boundaries(48)
     self.assertTupleEqual(pp, ofconfig.PhyPort.deserialize(self.buf))
Exemplo n.º 8
0
    def setUp(self):
        self.reactor = mock_twisted.MockReactorTime()
        self.default_op_timeout = 3
        self.echo_op_period = 5
        self.controller = mock_ofcontroller.MockOpenflowController()

        self.peerproto = mock_ofproto.MockOpenflowProtocolHandler()
        self.peer_vendor_handler = mock_vendor.MockVendorHandler()
        self.peerproto.vendor_handlers = (self.peer_vendor_handler, )
        self.peer_vendor_handler.protocol = weakref.ref(self.peerproto)

        self.proto = ofcontroller.OpenflowControllerStub()
        self.vendor_handler = mock_vendor.MockVendorHandler()
        self.proto.vendor_handlers = (self.vendor_handler, )
        self.vendor_handler.protocol = weakref.ref(self.proto)
        self.proto.reactor = self.reactor
        self.proto.default_op_timeout = self.default_op_timeout
        self.proto.echo_op_period = self.echo_op_period
        self.proto.controller = self.controller

        host_address = twisted.internet.address.IPv4Address(
            'TCP', '192.168.1.1', '14123')
        peer_address = twisted.internet.address.IPv4Address(
            'TCP', '192.168.1.2', '14567')
        self.proto.transport = mock_ofproto.LoopbackTransport(
            self.peerproto, host_address, peer_address)
        self.peerproto.transport = mock_ofproto.LoopbackTransport(
            self.proto, peer_address, host_address)

        self.peerproto.connectionMade()

        self.controller.protocol = weakref.ref(self.proto)

        self.callbacks_made = []

        self.phyport1 = ofconfig.PhyPort(
            port_no=0x42,
            hw_addr='\xab\xcd\xef\xa0\xb1\xc2',
            name='testport1',
            config=test_ofproto._create_port_config(no_stp=True,
                                                    no_recv_stp=True,
                                                    no_flood=True),
            state_link_down=True,
            state_stp=ofconfig.OFPPS_STP_FORWARD,
            curr=test_ofproto._create_port_features(mode_1gb_fd=True,
                                                    fiber=True),
            advertised=test_ofproto._create_port_features(mode_1gb_fd=True,
                                                          fiber=True,
                                                          pause=True),
            supported=test_ofproto._create_port_features(mode_1gb_fd=True,
                                                         fiber=True,
                                                         pause=True,
                                                         pause_asym=True),
            peer=test_ofproto._create_port_features(mode_1gb_fd=True,
                                                    fiber=True,
                                                    autoneg=True))

        self.phyport2 = ofconfig.PhyPort(
            port_no=0x43,
            hw_addr='\xab\xcd\xef\xa0\xb1\xc3',
            name='testport2',
            config=test_ofproto._create_port_config(no_stp=True,
                                                    no_recv_stp=True,
                                                    no_flood=True),
            state_link_down=True,
            state_stp=ofconfig.OFPPS_STP_FORWARD,
            curr=test_ofproto._create_port_features(mode_1gb_fd=True,
                                                    fiber=True),
            advertised=test_ofproto._create_port_features(mode_1gb_fd=True,
                                                          fiber=True,
                                                          pause=True),
            supported=test_ofproto._create_port_features(mode_1gb_fd=True,
                                                         fiber=True,
                                                         pause=True,
                                                         pause_asym=True),
            peer=test_ofproto._create_port_features(mode_1gb_fd=True,
                                                    fiber=True,
                                                    autoneg=True))

        self.features1 = ofconfig.SwitchFeatures(datapath_id=0x123456,
                                                 n_buffers=5,
                                                 n_tables=3,
                                                 cap_flow_stats=True,
                                                 cap_table_stats=False,
                                                 cap_port_stats=True,
                                                 cap_stp=False,
                                                 cap_ip_reasm=True,
                                                 cap_queue_stats=False,
                                                 cap_arp_match_ip=True,
                                                 actions=frozenset(
                                                     (0, 2, 3, 5, 8)),
                                                 ports=(self.phyport1, ))

        self.match1 = ofmatch.Match(in_port=0x13,
                                    dl_src='\x13\x24\x35\x46\x57\x68',
                                    dl_dst='\x12\x23\x34\x45\x56\x67',
                                    dl_vlan=0x11,
                                    dl_vlan_pcp=0x22,
                                    dl_type=0x3344,
                                    nw_tos=0x80,
                                    nw_proto=0xcc,
                                    nw_src=('\xaa\xbb\xcc\xdd', 32),
                                    nw_dst=('\x21\x32\x43\x54', 32),
                                    tp_src=0x38,
                                    tp_dst=0x49)