def test_bpf1(self): vid = 4090 pcp = 7 frame_match = 'ether[14:2] = 0x{:01x}{:03x}'.format(pcp << 1, vid) filter = BpfProgramFilter(frame_match) self.assertTrue(filter(str(Ether()/Dot1Q(prio=pcp, vlan=vid)))) self.assertFalse(filter(str(Ether()/Dot1Q(prio=pcp, vlan=4000))))
def test_bpf2(self): vid1 = 4090 pcp1 = 7 frame_match_case1 = 'ether[14:2] = 0x{:01x}{:03x}'.format( pcp1 << 1, vid1) vid2 = 4000 frame_match_case2 = '(ether[14:2] & 0xfff) = 0x{:03x}'.format(vid2) filter = BpfProgramFilter('{} or {}'.format( frame_match_case1, frame_match_case2)) self.assertTrue(filter(str(Ether()/Dot1Q(prio=pcp1, vlan=vid1)))) self.assertTrue(filter(str(Ether()/Dot1Q(vlan=vid2)))) self.assertFalse(filter(str(Ether()/Dot1Q(vlan=4001))))
def test_packet_send_receive_with_filter(self): rcvd = DeferredWithTimeout() filter = BpfProgramFilter('ip dst host 123.123.123.123') p0 = self.mgr.open_port('veth0', none).up() p1 = self.mgr.open_port('veth1', lambda p, f: rcvd.callback((p, f)), filter=filter).up() # sending bogus packet would not be received ip_packet = str(Ether() / IP(dst='123.123.123.123')) p0.send(ip_packet) # check that we receved packet port, frame = yield rcvd self.assertEqual(port, p1) self.assertEqual(frame, ip_packet)
def test_packet_send_drop_with_filter(self): rcvd = DeferredWithTimeout() filter = BpfProgramFilter('ip dst host 123.123.123.123') p0 = self.mgr.open_port('veth0', none).up() self.mgr.open_port('veth1', lambda p, f: rcvd.callback((p, f)), filter=filter).up() # sending bogus packet would not be received p0.send('bogus packet') try: _ = yield rcvd except TimeOutError: pass else: self.fail('not timed out')
def test_concurrent_packet_send_receive_with_filter(self): done = Deferred() queue1 = [] queue2 = [] n = 100 def append(queue): def _append(_, frame): queue.append(frame) if len(queue1) == n / 2 and len(queue2) == n / 2: done.callback(None) return _append filter = BpfProgramFilter('vlan 100') p1in = self.mgr.open_port('veth0', none).up() self.mgr.open_port('veth1', append(queue1), filter).up() p2in = self.mgr.open_port('veth2', none).up() self.mgr.open_port('veth3', append(queue2), filter).up() @inlineCallbacks def send_packets(port, n): for i in xrange(n): # packets have alternating VLAN ids 100 and 101 pkt = Ether() / Dot1Q(vlan=100 + i % 2) port.send(str(pkt)) yield asleep(0.00001 * random.random()) # to interleave # sending two concurrent streams send_packets(p1in, n) send_packets(p2in, n) # verify that both queue got all packets yield done
def test_shared_interface(self): queue1 = DeferredQueue() queue2 = DeferredQueue() # two senders hooked up to the same interface (sharing it) # here we test if they can both send pin1 = self.mgr.open_port('veth0', none).up() pin2 = self.mgr.open_port('veth0', none).up() pout1 = self.mgr.open_port('veth1', lambda p, f: queue1.put( (p, f))).up() filter = BpfProgramFilter('ip dst host 123.123.123.123') pout2 = self.mgr.open_port('veth1', lambda p, f: queue2.put((p, f)), filter=filter).up() # sending from pin1, should be received by pout1 bogus_frame = 'bogus packet' bogus_frame_padded = bogus_frame + '\x00' * (FrameIOPort.MIN_PKT_SIZE - len(bogus_frame)) pin1.send(bogus_frame_padded) port, frame = yield queue1.get() self.assertEqual(port, pout1) self.assertEqual(frame, bogus_frame_padded) self.assertEqual(len(queue1.pending), 0) self.assertEqual(len(queue2.pending), 0) # sending from pin2, should be received by pout1 pin2.send(bogus_frame_padded) port, frame = yield queue1.get() self.assertEqual(port, pout1) self.assertEqual(frame, bogus_frame_padded) self.assertEqual(len(queue1.pending), 0) self.assertEqual(len(queue2.pending), 0) # sending from pin1, should be received by both pouts ip_packet = str(Ether() / IP(dst='123.123.123.123')) pin1.send(ip_packet) port, frame = yield queue1.get() self.assertEqual(port, pout1) self.assertEqual(frame, ip_packet) self.assertEqual(len(queue1.pending), 0) port, frame = yield queue2.get() self.assertEqual(port, pout2) self.assertEqual(frame, ip_packet) self.assertEqual(len(queue2.pending), 0) # sending from pin2, should be received by pout1 ip_packet = str(Ether() / IP(dst='123.123.123.123')) pin2.send(ip_packet) port, frame = yield queue1.get() self.assertEqual(port, pout1) self.assertEqual(frame, ip_packet) self.assertEqual(len(queue1.pending), 0) port, frame = yield queue2.get() self.assertEqual(port, pout2) self.assertEqual(frame, ip_packet) self.assertEqual(len(queue2.pending), 0) self.mgr.close_port(pin1) self.mgr.close_port(pin2) self.mgr.close_port(pout1) self.mgr.close_port(pout2)
from google.protobuf.empty_pb2 import Empty from voltha.protos.logical_device_pb2 import LogicalPort, LogicalDevice from voltha.protos.openflow_13_pb2 import OFPPS_LIVE, OFPPF_FIBER, \ OFPPF_1GB_FD, \ OFPC_GROUP_STATS, OFPC_PORT_STATS, OFPC_TABLE_STATS, OFPC_FLOW_STATS, \ ofp_switch_features, ofp_desc from voltha.protos.openflow_13_pb2 import ofp_port from voltha.protos.ponsim_pb2 import FlowTable from voltha.registry import registry _ = third_party log = structlog.get_logger() PACKET_IN_VLAN = 4000 is_inband_frame = BpfProgramFilter('(ether[14:2] & 0xfff) = 0x{:03x}'.format( PACKET_IN_VLAN)) class AdapterPmMetrics: def __init__(self, device): self.pm_names = {'tx_64_pkts', 'tx_65_127_pkts', 'tx_128_255_pkts', 'tx_256_511_pkts', 'tx_512_1023_pkts', 'tx_1024_1518_pkts', 'tx_1519_9k_pkts', 'rx_64_pkts', 'rx_65_127_pkts', 'rx_128_255_pkts', 'rx_256_511_pkts', 'rx_512_1023_pkts', 'rx_1024_1518_pkts', 'rx_1519_9k_pkts'} self.device = device self.id = device.id self.name = 'ponsim_olt' # self.id = "abc"
TIBIT_ONU_LINK_INDEX = 2 # Match on the MGMT VLAN, Priority 7 TIBIT_MGMT_VLAN = 4090 TIBIT_MGMT_PRIORITY = 7 frame_match_case1 = 'ether[14:2] = 0x{:01x}{:03x}'.format( TIBIT_MGMT_PRIORITY << 1, TIBIT_MGMT_VLAN) TIBIT_PACKET_IN_VLAN = 4000 frame_match_case2 = '(ether[14:2] & 0xfff) = 0x{:03x}'.format( TIBIT_PACKET_IN_VLAN) TIBIT_PACKET_OUT_VLAN = 4000 is_tibit_frame = BpfProgramFilter('{} or {}'.format( frame_match_case1, frame_match_case2)) #is_tibit_frame = lambda x: True # Extract OLT MAC address: This is a good # example of getting the OLT mac address #for mac, device in self.device_ids.iteritems(): # if device == dev_id: # olt_mac_address = mac # log.info('packet-out', olt_mac_address=olt_mac_address) # To be removed in favor of OAM class TBJSON(Packet): """ TBJSON 'packet' layer. """ name = "TBJSON"