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 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 add_eapol_flow(self, intf_id, onu_id, logical_flow, eapol_id=EAPOL_FLOW_INDEX, vlan_id=DEFAULT_MGMT_VLAN): uplink_classifier = {} uplink_classifier[ETH_TYPE] = EAP_ETH_TYPE uplink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG uplink_classifier[VLAN_VID] = vlan_id uplink_action = {} uplink_action[TRAP_TO_HOST] = True # Add Upstream EAPOL Flow. pon_intf_onu_id = (intf_id, onu_id) gemport_id = self.resource_mgr.get_gemport_id( pon_intf_onu_id=pon_intf_onu_id ) alloc_id = self.resource_mgr.get_alloc_id( pon_intf_onu_id=pon_intf_onu_id ) uplink_flow_id = self.platform.mk_flow_id(intf_id, onu_id, eapol_id) upstream_flow = openolt_pb2.Flow( onu_id=onu_id, flow_id=uplink_flow_id, flow_type=UPSTREAM, access_intf_id=intf_id, gemport_id=gemport_id, alloc_id=alloc_id, priority=logical_flow.priority, classifier=self.mk_classifier(uplink_classifier), action=self.mk_action(uplink_action)) logical_flow = copy.deepcopy(logical_flow) logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([fd.vlan_vid( vlan_id | 0x1000)])) logical_flow.match.type = OFPMT_OXM self.add_flow_to_device(upstream_flow, logical_flow) if vlan_id == DEFAULT_MGMT_VLAN: # Add Downstream EAPOL Flow, Only for first EAP flow (BAL # requirement) special_vlan_downstream_flow = 4000 - onu_id downlink_classifier = {} downlink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG downlink_classifier[VLAN_VID] = special_vlan_downstream_flow downlink_action = {} downlink_action[PUSH_VLAN] = True downlink_action[VLAN_VID] = vlan_id downlink_flow_id = self.platform.mk_flow_id( intf_id, onu_id, DOWNSTREAM_FLOW_FOR_PACKET_OUT) downstream_flow = openolt_pb2.Flow( onu_id=onu_id, flow_id=downlink_flow_id, flow_type=DOWNSTREAM, access_intf_id=intf_id, gemport_id=gemport_id, priority=logical_flow.priority, classifier=self.mk_classifier(downlink_classifier), action=self.mk_action(downlink_action)) downstream_logical_flow = ofp_flow_stats( id=logical_flow.id, cookie=logical_flow.cookie, table_id=logical_flow.table_id, priority=logical_flow.priority, flags=logical_flow.flags) downstream_logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([ fd.in_port(fd.get_out_port(logical_flow)), fd.vlan_vid((special_vlan_downstream_flow) | 0x1000)])) downstream_logical_flow.match.type = OFPMT_OXM downstream_logical_flow.instructions.extend( fd.mk_instructions_from_actions([fd.output( self.platform.mk_uni_port_num(intf_id, onu_id))])) self.add_flow_to_device(downstream_flow, downstream_logical_flow)
def add_eapol_flow(self, intf_id, onu_id, uni_id, port_no, logical_flow, alloc_id, gemport_id, vlan_id=DEFAULT_MGMT_VLAN): uplink_classifier = dict() uplink_classifier[ETH_TYPE] = EAP_ETH_TYPE uplink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG uplink_classifier[VLAN_VID] = vlan_id uplink_action = dict() uplink_action[TRAP_TO_HOST] = True flow_store_cookie = self._get_flow_store_cookie(uplink_classifier, gemport_id) if self.resource_mgr.is_flow_cookie_on_kv_store(intf_id, onu_id, uni_id, flow_store_cookie): self.log.debug('flow-exists--not-re-adding') else: # Add Upstream EAPOL Flow. uplink_flow_id = self.resource_mgr.get_flow_id( intf_id, onu_id, uni_id, flow_store_cookie ) upstream_flow = openolt_pb2.Flow( access_intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, flow_id=uplink_flow_id, flow_type=UPSTREAM, alloc_id=alloc_id, network_intf_id=self.data_model.olt_nni_intf_id(), gemport_id=gemport_id, classifier=self.mk_classifier(uplink_classifier), action=self.mk_action(uplink_action), priority=logical_flow.priority, port_no=port_no, cookie=logical_flow.cookie) logical_flow = copy.deepcopy(logical_flow) logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([fd.vlan_vid( vlan_id | 0x1000)])) logical_flow.match.type = OFPMT_OXM if self.add_flow_to_device(upstream_flow, logical_flow): flow_info = self._get_flow_info_as_json_blob(upstream_flow, flow_store_cookie) self.update_flow_info_to_kv_store(upstream_flow.access_intf_id, upstream_flow.onu_id, upstream_flow.uni_id, upstream_flow.flow_id, flow_info) if vlan_id == DEFAULT_MGMT_VLAN: # Add Downstream EAPOL Flow, Only for first EAP flow (BAL # requirement) # On one of the platforms (Broadcom BAL), when same DL classifier # vlan was used across multiple ONUs, eapol flow re-adds after # flow delete (cases of onu reboot/disable) fails. # In order to generate unique vlan, a combination of intf_id # onu_id and uni_id is used. # uni_id defaults to 0, so add 1 to it. special_vlan_downstream_flow = 4090 - intf_id * onu_id * (uni_id+1) # Assert that we do not generate invalid vlans under no condition assert special_vlan_downstream_flow >= 2 downlink_classifier = dict() downlink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG downlink_classifier[VLAN_VID] = special_vlan_downstream_flow downlink_action = dict() downlink_action[PUSH_VLAN] = True downlink_action[VLAN_VID] = vlan_id flow_store_cookie = self._get_flow_store_cookie( downlink_classifier, gemport_id) if self.resource_mgr.is_flow_cookie_on_kv_store( intf_id, onu_id, uni_id, flow_store_cookie): self.log.debug('flow-exists--not-re-adding') else: downlink_flow_id = self.resource_mgr.get_flow_id( intf_id, onu_id, uni_id, flow_store_cookie ) downstream_flow = openolt_pb2.Flow( access_intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, flow_id=downlink_flow_id, flow_type=DOWNSTREAM, alloc_id=alloc_id, network_intf_id=self.data_model.olt_nni_intf_id(), gemport_id=gemport_id, classifier=self.mk_classifier(downlink_classifier), action=self.mk_action(downlink_action), priority=logical_flow.priority, port_no=port_no, cookie=logical_flow.cookie) downstream_logical_flow = ofp_flow_stats( id=logical_flow.id, cookie=logical_flow.cookie, table_id=logical_flow.table_id, priority=logical_flow.priority, flags=logical_flow.flags) downstream_logical_flow.match.oxm_fields.extend( fd.mk_oxm_fields( [fd.in_port(fd.get_out_port(logical_flow)), fd.vlan_vid(special_vlan_downstream_flow | 0x1000)])) downstream_logical_flow.match.type = OFPMT_OXM downstream_logical_flow.instructions.extend( fd.mk_instructions_from_actions([fd.output( self.platform.mk_uni_port_num(intf_id, onu_id, uni_id))])) if self.add_flow_to_device(downstream_flow, downstream_logical_flow): flow_info = self._get_flow_info_as_json_blob( downstream_flow, flow_store_cookie) self.update_flow_info_to_kv_store( downstream_flow.access_intf_id, downstream_flow.onu_id, downstream_flow.uni_id, downstream_flow.flow_id, flow_info)
def add_eapol_flow(self, intf_id, onu_id, logical_flow, uplink_eapol_id=EAPOL_FLOW_INDEX, downlink_eapol_id=EAPOL_DOWNLINK_FLOW_INDEX, vlan_id=DEFAULT_MGMT_VLAN): uplink_classifier = {} uplink_classifier['eth_type'] = EAP_ETH_TYPE uplink_classifier['pkt_tag_type'] = 'single_tag' uplink_classifier['vlan_vid'] = vlan_id uplink_action = {} uplink_action['trap_to_host'] = True gemport_id = self.platform.mk_gemport_id(intf_id, onu_id) # Add Upstream EAPOL Flow. uplink_flow_id = self.platform.mk_flow_id(intf_id, onu_id, uplink_eapol_id) upstream_flow = openolt_pb2.Flow( onu_id=onu_id, flow_id=uplink_flow_id, flow_type="upstream", access_intf_id=intf_id, gemport_id=gemport_id, priority=logical_flow.priority, classifier=self.mk_classifier(uplink_classifier), action=self.mk_action(uplink_action)) logical_flow = copy.deepcopy(logical_flow) logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([fd.vlan_vid( vlan_id | 0x1000)])) logical_flow.match.type = OFPMT_OXM self.add_flow_to_device(upstream_flow, logical_flow) if vlan_id == DEFAULT_MGMT_VLAN: # Add Downstream EAPOL Flow, Only for first EAP flow downlink_classifier = {} downlink_classifier['pkt_tag_type'] = 'single_tag' downlink_classifier['vlan_vid'] = 4000 - onu_id downlink_action = {} downlink_action['push_vlan'] = True downlink_action['vlan_vid'] = vlan_id downlink_flow_id = self.platform.mk_flow_id(intf_id, onu_id, downlink_eapol_id) downstream_flow = openolt_pb2.Flow( onu_id=onu_id, flow_id=downlink_flow_id, flow_type="downstream", access_intf_id=intf_id, gemport_id=gemport_id, priority=logical_flow.priority, classifier=self.mk_classifier(downlink_classifier), action=self.mk_action(downlink_action)) downstream_logical_flow = ofp_flow_stats(id=logical_flow.id, cookie=logical_flow.cookie, table_id=logical_flow.table_id, priority=logical_flow.priority, flags=logical_flow.flags) downstream_logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([ fd.in_port(fd.get_out_port(logical_flow)), fd.vlan_vid((4000 - onu_id) | 0x1000)])) downstream_logical_flow.match.type = OFPMT_OXM downstream_logical_flow.instructions.extend( fd.mk_instructions_from_actions([fd.output( self.platform.mk_uni_port_num(intf_id, onu_id))])) self.add_flow_to_device(downstream_flow, downstream_logical_flow)
def add_eapol_flow(self, intf_id, onu_id, logical_flow, alloc_id, gemport_id, eapol_flow_category=EAPOL_PRIMARY_FLOW, vlan_id=DEFAULT_MGMT_VLAN): uplink_classifier = dict() uplink_classifier[ETH_TYPE] = EAP_ETH_TYPE uplink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG uplink_classifier[VLAN_VID] = vlan_id uplink_action = dict() uplink_action[TRAP_TO_HOST] = True pon_intf_onu_id = (intf_id, onu_id) # Add Upstream EAPOL Flow. if eapol_flow_category == EAPOL_PRIMARY_FLOW: uplink_flow_id = self.resource_mgr.get_flow_id(pon_intf_onu_id) else: uplink_flow_id = self.resource_mgr.get_flow_id(pon_intf_onu_id) upstream_flow = openolt_pb2.Flow( access_intf_id=intf_id, onu_id=onu_id, flow_id=uplink_flow_id, flow_type=UPSTREAM, alloc_id=alloc_id, network_intf_id=0, gemport_id=gemport_id, classifier=self.mk_classifier(uplink_classifier), action=self.mk_action(uplink_action), priority=logical_flow.priority) logical_flow = copy.deepcopy(logical_flow) logical_flow.match.oxm_fields.extend( fd.mk_oxm_fields([fd.vlan_vid(vlan_id | 0x1000)])) logical_flow.match.type = OFPMT_OXM if self.add_flow_to_device(upstream_flow, logical_flow): if eapol_flow_category == EAPOL_PRIMARY_FLOW: flow_info = self._get_flow_info_as_json_blob( upstream_flow, EAPOL_PRIMARY_FLOW) self.update_flow_info_to_kv_store(upstream_flow.access_intf_id, upstream_flow.onu_id, upstream_flow.flow_id, flow_info) else: flow_info = self._get_flow_info_as_json_blob( upstream_flow, EAPOL_SECONDARY_FLOW) self.update_flow_info_to_kv_store(upstream_flow.access_intf_id, upstream_flow.onu_id, upstream_flow.flow_id, flow_info) if vlan_id == DEFAULT_MGMT_VLAN: # Add Downstream EAPOL Flow, Only for first EAP flow (BAL # requirement) special_vlan_downstream_flow = 4000 - onu_id downlink_classifier = dict() downlink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG downlink_classifier[VLAN_VID] = special_vlan_downstream_flow downlink_action = dict() downlink_action[PUSH_VLAN] = True downlink_action[VLAN_VID] = vlan_id pon_intf_onu_id = (intf_id, onu_id) downlink_flow_id = self.resource_mgr.get_flow_id(pon_intf_onu_id) downstream_flow = openolt_pb2.Flow( access_intf_id=intf_id, onu_id=onu_id, flow_id=downlink_flow_id, flow_type=DOWNSTREAM, alloc_id=alloc_id, network_intf_id=0, gemport_id=gemport_id, classifier=self.mk_classifier(downlink_classifier), action=self.mk_action(downlink_action), priority=logical_flow.priority) downstream_logical_flow = ofp_flow_stats( id=logical_flow.id, cookie=logical_flow.cookie, table_id=logical_flow.table_id, priority=logical_flow.priority, flags=logical_flow.flags) downstream_logical_flow.match.oxm_fields.extend( fd.mk_oxm_fields([ fd.in_port(fd.get_out_port(logical_flow)), fd.vlan_vid(special_vlan_downstream_flow | 0x1000) ])) downstream_logical_flow.match.type = OFPMT_OXM downstream_logical_flow.instructions.extend( fd.mk_instructions_from_actions([ fd.output(self.platform.mk_uni_port_num(intf_id, onu_id)) ])) if self.add_flow_to_device(downstream_flow, downstream_logical_flow): flow_info = self._get_flow_info_as_json_blob( downstream_flow, EAPOL_PRIMARY_FLOW) self.update_flow_info_to_kv_store( downstream_flow.access_intf_id, downstream_flow.onu_id, downstream_flow.flow_id, flow_info)