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()))
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))
def test_serialize_every_capability_flag(self): for i in xrange(0, 7): flag = 1 << i # Bit 4 is reserved and not exposed in the structure. # Shift all bits to the left from bit 4. if i > 3: flag = flag << 1 args = [False] * 6 args.insert(i, True) args[0:0] = [0x123456, 5, 3] args.extend([frozenset((0, 2, 3, 5, 8)), ()]) sf = ofconfig.SwitchFeatures(*args) self.assertEqual( '\x00\x00\x00\x00\x00\x12\x34\x56' '\x00\x00\x00\x05' '\x03\x00\x00\x00' + struct.pack('!L', flag) + '\x00\x00\x01\x2d', ''.join(sf.serialize()))
def test_serialize_no_port(self): 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=()) 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', ''.join(sf.serialize()))
def test_serialize_every_action(self): for i in xrange(0, 32): action_flag = 1 << i 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((i, )), ports=()) self.assertEqual( '\x00\x00\x00\x00\x00\x12\x34\x56' '\x00\x00\x00\x05' '\x03\x00\x00\x00' '\x00\x00\x00\xa5' + struct.pack('!L', action_flag), ''.join(sf.serialize()))
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)