def leaf_device_default_rules(device): ports = self.root_proxy.get('/devices/{}/ports'.format(device.id)) upstream_ports = [ port for port in ports if port.type == Port.PON_ONU \ or port.type == Port.VENET_ONU ] assert len(upstream_ports) == 1 downstream_ports = [ port for port in ports if port.type == Port.ETHERNET_UNI ] # it is possible that the downstream ports are not # created, but the flow_decomposition has already # kicked in. In such scenarios, cut short the processing # and return. if len(downstream_ports) == 0: return None, None # assert len(downstream_ports) == 1 upstream_port = upstream_ports[0] flows = OrderedDict() for downstream_port in downstream_ports: flows.update(OrderedDict((f.id, f) for f in [ mk_flow_stat( priority=500, match_fields=[ in_port(downstream_port.port_no), vlan_vid(ofp.OFPVID_PRESENT | 0) ], actions=[ set_field(vlan_vid(ofp.OFPVID_PRESENT | device.vlan)), output(upstream_port.port_no) ] ), mk_flow_stat( priority=500, match_fields=[ in_port(downstream_port.port_no), vlan_vid(0) ], actions=[ push_vlan(0x8100), set_field(vlan_vid(ofp.OFPVID_PRESENT | device.vlan)), output(upstream_port.port_no) ] ), mk_flow_stat( priority=500, match_fields=[ in_port(upstream_port.port_no), vlan_vid(ofp.OFPVID_PRESENT | device.vlan) ], actions=[ set_field(vlan_vid(ofp.OFPVID_PRESENT | 0)), output(downstream_port.port_no) ] ), ])) groups = OrderedDict() return flows, groups
def leaf_device_default_rules(device): ports = self.root_proxy.get('/devices/{}/ports'.format(device.id)) upstream_ports = [ port for port in ports if port.type == Port.PON_ONU \ or port.type == Port.VENET_ONU ] assert len(upstream_ports) == 1 downstream_ports = [ port for port in ports if port.type == Port.ETHERNET_UNI ] # assert len(downstream_ports) == 1 flows = OrderedDict((f.id, f) for f in [ mk_flow_stat( priority=500, match_fields=[ in_port(downstream_ports[0].port_no), vlan_vid(ofp.OFPVID_PRESENT | 0) ], actions=[ set_field(vlan_vid(ofp.OFPVID_PRESENT | device.vlan)), output(upstream_ports[0].port_no) ] ), mk_flow_stat( priority=500, match_fields=[ in_port(downstream_ports[0].port_no), vlan_vid(0) ], actions=[ push_vlan(0x8100), set_field(vlan_vid(ofp.OFPVID_PRESENT | device.vlan)), output(upstream_ports[0].port_no) ] ), mk_flow_stat( priority=500, match_fields=[ in_port(upstream_ports[0].port_no), vlan_vid(ofp.OFPVID_PRESENT | device.vlan) ], actions=[ set_field(vlan_vid(ofp.OFPVID_PRESENT | 0)), output(downstream_ports[0].port_no) ] ), ]) groups = OrderedDict() return flows, groups
def leaf_device_default_rules(device): ports = self.root_proxy.get('/devices/{}/ports'.format(device.id)) upstream_ports = [ port for port in ports if port.type == Port.PON_ONU \ or port.type == Port.VENET_ONU ] assert len(upstream_ports) == 1 downstream_ports = [ port for port in ports if port.type == Port.ETHERNET_UNI ] # assert len(downstream_ports) == 1 flows = OrderedDict((f.id, f) for f in [ mk_flow_stat( priority=500, match_fields=[ in_port(downstream_ports[0].port_no), vlan_vid(ofp.OFPVID_PRESENT | 0) ], actions=[ set_field(vlan_vid(ofp.OFPVID_PRESENT | device.vlan)), output(upstream_ports[0].port_no) ] ), mk_flow_stat( priority=500, match_fields=[ in_port(downstream_ports[0].port_no), vlan_vid(0) ], actions=[ push_vlan(0x8100), set_field(vlan_vid(ofp.OFPVID_PRESENT | device.vlan)), output(upstream_ports[0].port_no) ] ), mk_flow_stat( priority=500, match_fields=[ in_port(upstream_ports[0].port_no), vlan_vid(ofp.OFPVID_PRESENT | device.vlan) ], actions=[ set_field(vlan_vid(ofp.OFPVID_PRESENT | 0)), output(downstream_ports[0].port_no) ] ), ]) groups = OrderedDict() return flows, groups
def root_device_default_rules(device): ports = self.root_proxy.get('/devices/{}/ports'.format(device.id)) upstream_ports = [ port for port in ports if port.type == Port.ETHERNET_NNI ] assert len(upstream_ports) == 1 downstream_ports = [ port for port in ports if port.type == Port.PON_OLT \ or port.type == Port.VENET_OLT ] _is_any_venet_port = any(_port.type == Port.VENET_OLT for _port in downstream_ports) if _is_any_venet_port != True: assert len(downstream_ports) == 1, \ 'Initially, we only handle one PON port' flows = OrderedDict((f.id, f) for f in [ mk_flow_stat( priority=2000, match_fields=[ in_port(upstream_ports[0].port_no), vlan_vid(ofp.OFPVID_PRESENT | 4000), vlan_pcp(0) ], actions=[ pop_vlan(), output(downstream_ports[0].port_no) ] ) ]) groups = OrderedDict() return flows, groups
def test_create(flow_handler, caplog, downstream): ds_entry, ds_evc = FlowEntry.create(downstream, flow_handler) assert ds_entry is not None, "Entry wasn't created" assert ds_evc is None, "EVC not labeled" upstream = mk_flow_stat(priority=40000, match_fields=[ in_port(5), vlan_vid(ofp.OFPVID_PRESENT | 666), vlan_pcp(7) ], actions=[ push_vlan(0x8100), set_field(vlan_vid(ofp.OFPVID_PRESENT | 4)), set_field(vlan_pcp(7)), output(1) ]) us_entry, us_evc = FlowEntry.create(upstream, flow_handler) assert us_entry is not None, "Entry wasn't created" assert us_evc is not None, "EVC not labeled" us_evc._do_install() assert us_evc._installed, "EVC wasn't installed" edit_configs = flow_handler.netconf_client.edit_config.call_args_list assert len(edit_configs) == 1, "EVC-MAP edit config" for call in edit_configs: log.info("Netconf Calls: {}".format(call))
def downstream(): yield mk_flow_stat(priority=40000, match_fields=[ in_port(1), vlan_vid(ofp.OFPVID_PRESENT | 4), vlan_pcp(7), metadata(666) ], actions=[pop_vlan(), output(5)])
def update_flow_table(self, flows): stub = ponsim_pb2_grpc.PonSimStub(self.get_channel()) self.log.info('pushing-olt-flow-table') eapol_flows = {} eapol_flow_without_vlan = False for flow in flows: classifier_info = self.get_classifier_info(flow) self.log.debug('classifier_info', classifier_info=classifier_info) if IP_PROTO in classifier_info: if classifier_info[IP_PROTO] == 17: if UDP_SRC in classifier_info: if classifier_info[UDP_SRC] == 68: self.log.info('dhcp upstream flow add') elif classifier_info[UDP_SRC] == 67: self.log.info('dhcp downstream flow add') self.to_controller(flow) elif classifier_info[IP_PROTO] == 2: self.log.info('igmp flow add') self.to_controller(flow) else: self.log.warn("Invalid-Classifier-to-handle", classifier_info=classifier_info) elif ETH_TYPE in classifier_info: if classifier_info[ETH_TYPE] == EAP_ETH_TYPE: self.log.info('eapol flow add') self.to_controller(flow) if VLAN_VID in classifier_info: eapol_flows[classifier_info[VLAN_VID]] = flow else: eapol_flow_without_vlan = True # The OLT app is now adding EAPOL flows with VLAN_VID=4091 but Ponsim can't # properly handle this because it uses VLAN_VID to encode the UNI port ID. # Add an EAPOL trap flow with no VLAN_VID match if we see the 4091 match. if 4091 in eapol_flows and not eapol_flow_without_vlan: new_eapol_flow = [ fd.mk_flow_stat( priority=10000, match_fields=[fd.in_port(1), fd.eth_type(EAP_ETH_TYPE)], actions=[fd.output(ofp.OFPP_CONTROLLER)] ) ] flows.extend(new_eapol_flow) self.log.info('add eapol flow with no VLAN_VID match') stub.UpdateFlowTable(FlowTable( port=0, flows=flows )) self.log.info('success')