예제 #1
0
 def test_serialize_no_attrs_wildcarded(self):
     m = 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)
     self.assertEqual(
         '\x00\x00\x00\x00'
         '\x00\x13'
         '\x13\x24\x35\x46\x57\x68'
         '\x12\x23\x34\x45\x56\x67'
         '\x00\x11'
         '\x22\x00'
         '\x33\x44'
         '\x80\xcc\x00\x00'
         '\xaa\xbb\xcc\xdd'
         '\x21\x32\x43\x54'
         '\x00\x38\x00\x49', m.serialize())
예제 #2
0
 def test_create_wildcarded_every_attr(self):
     m_orig = 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)
     for attr_name in ofmatch.Match._fields:
         attr_value = m_orig._asdict()[attr_name]
         m = ofmatch.Match.create_wildcarded(**{attr_name: attr_value})
         m_dict = {
             'in_port': None,
             'dl_src': None,
             'dl_dst': None,
             'dl_vlan': None,
             'dl_vlan_pcp': None,
             'dl_type': None,
             'nw_tos': None,
             'nw_proto': None,
             'nw_src': None,
             'nw_dst': None,
             'tp_src': None,
             'tp_dst': None
         }
         m_dict[attr_name] = attr_value
         self.assertDictEqual(m_dict, m._asdict())
예제 #3
0
 def test_create(self):
     m = 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)
예제 #4
0
 def setUp(self):
     self.buf = buffer.ReceiveBuffer()
     self.match = 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)
     self.flow_stats = ofstats.FlowStats(
         0xac, self.match, 0x10203040, 0x11223344, 0x1002, 0x0136, 0x0247,
         0xffeeddccbbaa9988, 0x42, 0x0153, (
             ofaction.ActionOutput(port=0x1234, max_len=0x9abc),
             ofaction.ActionSetDlDst(dl_addr='\x12\x34\x56\x78\xab\xcd')))
예제 #5
0
 def test_serialize_deserialize_no_attrs_wildcarded(self):
     m = 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)
     self.buf.append(m.serialize())
     self.buf.set_message_boundaries(40)
     self.assertTupleEqual(m, ofmatch.Match.deserialize(self.buf))
예제 #6
0
 def test_wildcards_every_nw_dst_prefix_length(self):
     m_orig = 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)
     for i in xrange(1, 33):
         m = m_orig._replace(nw_dst=('\x21\x32\x43\x54', i))
         wildcards = (32 - i) << 14
         self.assertEqual(wildcards, m.wildcards.serialize())
예제 #7
0
 def test_serialize_deserialize_wildcards_every_nw_dst_prefix_length(self):
     m_orig = 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)
     for i in xrange(1, 33):
         m = m_orig._replace(nw_dst=('\x21\x32\x43\x54', i))
         self.buf.append(m.serialize())
         self.buf.set_message_boundaries(40)
         self.assertTupleEqual(m, ofmatch.Match.deserialize(self.buf))
예제 #8
0
 def test_serialize_deserialize_wildcards_every_msb(self):
     m_orig = 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)
     for attr_name in ('dl_vlan_pcp', 'nw_tos'):
         attr_value = m_orig._asdict()[attr_name]
         m = ofmatch.Match.create_wildcarded(**{attr_name: attr_value})
         self.buf.append(m.serialize())
         self.buf.set_message_boundaries(40)
         self.assertTupleEqual(m, ofmatch.Match.deserialize(self.buf))
예제 #9
0
 def test_wildcards_every_msb(self):
     m_orig = 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)
     wildcard_bit = 1 << 20
     for attr_name in ('dl_vlan_pcp', 'nw_tos'):
         attr_value = m_orig._asdict()[attr_name]
         m = ofmatch.Match.create_wildcarded(**{attr_name: attr_value})
         self.assertEqual(0x3820ff & ~wildcard_bit, m.wildcards.serialize())
         wildcard_bit = wildcard_bit << 1
예제 #10
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)