def add_hsia_flow(self, intf_id, onu_id, uplink_classifier, uplink_action, downlink_classifier, downlink_action, hsia_id): gemport_id = self.mk_gemport_id(onu_id) flow_id = self.mk_flow_id(intf_id, onu_id, hsia_id) self.log.info('add upstream flow', onu_id=onu_id, classifier=uplink_classifier, action=uplink_action, gemport_id=gemport_id, flow_id=flow_id) flow = openolt_pb2.Flow( onu_id=onu_id, flow_id=flow_id, flow_type="upstream", gemport_id=gemport_id, classifier=self.mk_classifier(uplink_classifier), action=self.mk_action(uplink_action)) self.stub.FlowAdd(flow) time.sleep(0.1) # FIXME self.log.info('add downstream flow', classifier=downlink_classifier, action=downlink_action, gemport_id=gemport_id, flow_id=flow_id) flow = openolt_pb2.Flow( onu_id=onu_id, flow_id=flow_id, flow_type="downstream", access_intf_id=intf_id, gemport_id=gemport_id, classifier=self.mk_classifier(downlink_classifier), action=self.mk_action(downlink_action)) self.stub.FlowAdd(flow) time.sleep(0.1) # FIXME
def add_dhcp_trap(self, intf_id, onu_id, priority, classifier, action): self.log.debug('add dhcp upstream trap', classifier=classifier, action=action) action.clear() action['trap_to_host'] = True classifier['pkt_tag_type'] = 'single_tag' classifier.pop('vlan_vid', None) gemport_id = platform.mk_gemport_id(onu_id) flow_id = platform.mk_flow_id(intf_id, onu_id, DHCP_FLOW_INDEX) upstream_flow = openolt_pb2.Flow( onu_id=onu_id, flow_id=flow_id, flow_type="upstream", access_intf_id=intf_id, network_intf_id=0, gemport_id=gemport_id, priority=priority, classifier=self.mk_classifier(classifier), action=self.mk_action(action)) self.stub.FlowAdd(upstream_flow) # FIXME - Fix OpenOLT handling of downstream flows instead # of duplicating the downstream flow from the upstream # flow. # FIXME - ONOS should send explicit upstream and downstream # exact dhcp trap flow. classifier['udp_src'] = 67 classifier['udp_dst'] = 68 classifier['pkt_tag_type'] = 'double_tag' action.pop('push_vlan', None) flow_id = platform.mk_flow_id(intf_id, onu_id, DHCP_DOWNLINK_FLOW_INDEX) downstream_flow = openolt_pb2.Flow( onu_id=onu_id, flow_id=flow_id, flow_type="downstream", access_intf_id=intf_id, network_intf_id=0, gemport_id=gemport_id, priority=priority, classifier=self.mk_classifier(classifier), action=self.mk_action(action)) self.log.debug('add dhcp downstream trap', access_intf_id=intf_id, onu_id=onu_id, flow_id=flow_id) self.stub.FlowAdd(downstream_flow)
def add_dhcp_trap(self, intf_id, onu_id, classifier, action, logical_flow): self.log.debug('add dhcp upstream trap', classifier=classifier, action=action) action.clear() action['trap_to_host'] = True classifier['pkt_tag_type'] = 'single_tag' classifier.pop('vlan_vid', None) gemport_id = self.platform.mk_gemport_id(intf_id, onu_id) flow_id = self.platform.mk_flow_id(intf_id, onu_id, DHCP_FLOW_INDEX) upstream_flow = openolt_pb2.Flow( onu_id=onu_id, flow_id=flow_id, flow_type="upstream", access_intf_id=intf_id, gemport_id=gemport_id, priority=logical_flow.priority, classifier=self.mk_classifier(classifier), action=self.mk_action(action)) self.add_flow_to_device(upstream_flow, logical_flow) # FIXME - ONOS should send explicit upstream and downstream # exact dhcp trap flow. downstream_logical_flow = copy.deepcopy(logical_flow) for oxm_field in downstream_logical_flow.match.oxm_fields: if oxm_field.ofb_field.type == OFPXMT_OFB_IN_PORT: oxm_field.ofb_field.port = \ self.platform.intf_id_to_port_no(0, Port.ETHERNET_NNI) classifier['udp_src'] = 67 classifier['udp_dst'] = 68 classifier['pkt_tag_type'] = 'double_tag' action.pop('push_vlan', None) flow_id = self.platform.mk_flow_id(intf_id, onu_id, DHCP_DOWNLINK_FLOW_INDEX) downstream_flow = openolt_pb2.Flow( onu_id=onu_id, flow_id=flow_id, flow_type="downstream", access_intf_id=intf_id, network_intf_id=0, gemport_id=gemport_id, priority=logical_flow.priority, classifier=self.mk_classifier(classifier), action=self.mk_action(action)) self.add_flow_to_device(downstream_flow, downstream_logical_flow)
def add_lldp_flow(self, intf_id, onu_id, logical_flow, classifier, action): self.log.debug('add lldp downstream trap', classifier=classifier, action=action) action.clear() action['trap_to_host'] = True classifier['pkt_tag_type'] = 'untagged' gemport_id = self.platform.mk_gemport_id(onu_id) flow_id = self.platform.mk_flow_id(intf_id, onu_id, LLDP_FLOW_INDEX) downstream_flow = openolt_pb2.Flow( onu_id=onu_id, flow_id=flow_id, flow_type="downstream", access_intf_id=3, network_intf_id=0, gemport_id=gemport_id, priority=logical_flow.priority, classifier=self.mk_classifier(classifier), action=self.mk_action(action)) self.log.debug('add lldp downstream trap', access_intf_id=intf_id, onu_id=onu_id, flow_id=flow_id) self.stub.FlowAdd(downstream_flow)
def add_dhcp_trap(self, intf_id, onu_id, classifier, action, logical_flow): self.log.debug('add dhcp upstream trap', classifier=classifier, intf_id=intf_id, onu_id=onu_id, action=action) action.clear() action[TRAP_TO_HOST] = True classifier[PACKET_TAG_TYPE] = SINGLE_TAG classifier.pop(VLAN_VID, None) 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 ) flow_id = self.platform.mk_flow_id(intf_id, onu_id, DHCP_FLOW_INDEX) dhcp_flow = openolt_pb2.Flow( onu_id=onu_id, flow_id=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(classifier), action=self.mk_action(action)) self.add_flow_to_device(dhcp_flow, logical_flow)
def add_dhcp_trap(self, intf_id, onu_id, classifier, action, logical_flow, alloc_id, gemport_id): self.log.debug('add dhcp upstream trap', classifier=classifier, intf_id=intf_id, onu_id=onu_id, action=action) action.clear() action[TRAP_TO_HOST] = True classifier[UDP_SRC] = 68 classifier[UDP_DST] = 67 classifier[PACKET_TAG_TYPE] = SINGLE_TAG classifier.pop(VLAN_VID, None) pon_intf_onu_id = (intf_id, onu_id) flow_id = self.resource_mgr.get_flow_id(pon_intf_onu_id) dhcp_flow = openolt_pb2.Flow(onu_id=onu_id, flow_id=flow_id, flow_type=UPSTREAM, access_intf_id=intf_id, gemport_id=gemport_id, alloc_id=alloc_id, network_intf_id=0, priority=logical_flow.priority, classifier=self.mk_classifier(classifier), action=self.mk_action(action)) if self.add_flow_to_device(dhcp_flow, logical_flow): flow_info = self._get_flow_info_as_json_blob(dhcp_flow, DHCP_FLOW) self.update_flow_info_to_kv_store(dhcp_flow.access_intf_id, dhcp_flow.onu_id, dhcp_flow.flow_id, flow_info)
def add_hsia_flow(self, intf_id, onu_id, priority, uplink_classifier, uplink_action, downlink_classifier, downlink_action, hsia_id): gemport_id = platform.mk_gemport_id(onu_id) flow_id = platform.mk_flow_id(intf_id, onu_id, hsia_id) self.log.debug('add upstream flow', onu_id=onu_id, classifier=uplink_classifier, action=uplink_action, gemport_id=gemport_id, flow_id=flow_id) flow = openolt_pb2.Flow( onu_id=onu_id, flow_id=flow_id, flow_type="upstream", access_intf_id=intf_id, gemport_id=gemport_id, priority=priority, classifier=self.mk_classifier(uplink_classifier), action=self.mk_action(uplink_action)) self.stub.FlowAdd(flow) self.log.debug('add downstream flow', classifier=downlink_classifier, action=downlink_action, gemport_id=gemport_id, flow_id=flow_id) flow = openolt_pb2.Flow( onu_id=onu_id, flow_id=flow_id, flow_type="downstream", access_intf_id=intf_id, gemport_id=gemport_id, priority=priority, classifier=self.mk_classifier(downlink_classifier), action=self.mk_action(downlink_action)) self.stub.FlowAdd(flow)
def add_eapol_flow(self, intf_id, onu_id, uplink_classifier, uplink_action, uplink_eapol_id=EAPOL_FLOW_INDEX, downlink_eapol_id=EAPOL_DOWNLINK_FLOW_INDEX, vlan_id=DEFAULT_MGMT_VLAN): self.log.debug('add eapol flow', classifier=uplink_classifier, action=uplink_action) downlink_classifier = dict(uplink_classifier) downlink_action = dict(uplink_action) gemport_id = platform.mk_gemport_id(onu_id) uplink_flow_id = platform.mk_flow_id(intf_id, onu_id, uplink_eapol_id) # Add Upstream EAPOL Flow. uplink_classifier['pkt_tag_type'] = 'single_tag' uplink_classifier['vlan_vid'] = vlan_id uplink_action.clear() uplink_action['trap_to_host'] = True 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, classifier=self.mk_classifier(uplink_classifier), action=self.mk_action(uplink_action)) self.stub.FlowAdd(upstream_flow) # Add Downstream EAPOL Flow. downlink_flow_id = platform.mk_flow_id(intf_id, onu_id, downlink_eapol_id) downlink_classifier['pkt_tag_type'] = 'single_tag' downlink_classifier['vlan_vid'] = vlan_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, classifier=self.mk_classifier(downlink_classifier), action=self.mk_action(downlink_action)) self.stub.FlowAdd(downstream_flow)
def add_hsia_flow(self, intf_id, onu_id, classifier, action, direction, hsia_id, logical_flow): gemport_id = self.platform.mk_gemport_id(intf_id, onu_id) flow_id = self.platform.mk_flow_id(intf_id, onu_id, hsia_id) flow = openolt_pb2.Flow( onu_id=onu_id, flow_id=flow_id, flow_type=direction, access_intf_id=intf_id, gemport_id=gemport_id, priority=logical_flow.priority, classifier=self.mk_classifier(classifier), action=self.mk_action(action)) self.add_flow_to_device(flow, logical_flow)
def remove_flow(self, flow): self.log.debug('trying to remove flows from logical flow :', logical_flow=flow) device_flows_to_remove = [] device_flows = self.flows_proxy.get('/').items for f in device_flows: if f.cookie == flow.id: device_flows_to_remove.append(f) for f in device_flows_to_remove: (id, direction) = self.decode_stored_id(f.id) flow_to_remove = openolt_pb2.Flow(flow_id=id, flow_type=direction) try: self.stub.FlowRemove(flow_to_remove) except grpc.RpcError as grpc_e: if grpc_e.code() == grpc.StatusCode.NOT_FOUND: self.log.debug( 'This flow does not exist on the switch, ' 'normal after an OLT reboot', flow=flow_to_remove) else: raise grpc_e # once we have successfully deleted the flow on the device # release the flow_id on resource pool and also clear any # data associated with the flow_id on KV store. self._clear_flow_id_from_rm(f, id, direction) self.log.debug('flow removed from device', flow=f, flow_key=flow_to_remove) if len(device_flows_to_remove) > 0: new_flows = [] flows_ids_to_remove = [f.id for f in device_flows_to_remove] for f in device_flows: if f.id not in flows_ids_to_remove: new_flows.append(f) self.flows_proxy.update('/', Flows(items=new_flows)) self.log.debug('flows removed from the data store', flow_ids_removed=flows_ids_to_remove, number_of_flows_removed=(len(device_flows) - len(new_flows)), expected_flows_removed=len(device_flows_to_remove)) else: self.log.debug( 'no device flow to remove for this flow (normal ' 'for multi table flows)', flow=flow)
def clear_flows_and_scheduler_for_logical_port(self, child_device, logical_port): ofp_port_name = logical_port.ofp_port.name pon_port = child_device.proxy_address.channel_id onu_id = child_device.proxy_address.onu_id # TODO: The DEFAULT_TECH_PROFILE_ID is assumed. Right way to do, # is probably to maintain a list of Tech-profile table IDs associated # with the UNI logical_port. This way, when the logical port is deleted, # all the associated tech-profile configuration with the UNI logical_port # can be cleared. tech_profile_instance = self.tech_profile[pon_port]. \ get_tech_profile_instance( DEFAULT_TECH_PROFILE_TABLE_ID, ofp_port_name) flow_ids = self.resource_mgr.get_current_flow_ids_for_onu( pon_port, onu_id) self.log.debug("outstanding-flows-to-be-cleared", flow_ids=flow_ids) for flow_id in flow_ids: flow_infos = self.resource_mgr.get_flow_id_info( pon_port, onu_id, flow_id) for flow_info in flow_infos: direction = flow_info['flow_type'] flow_to_remove = openolt_pb2.Flow(flow_id=flow_id, flow_type=direction) try: self.stub.FlowRemove(flow_to_remove) except grpc.RpcError as grpc_e: if grpc_e.code() == grpc.StatusCode.NOT_FOUND: self.log.debug( 'This flow does not exist on the switch, ' 'normal after an OLT reboot', flow=flow_to_remove) else: raise grpc_e self.resource_mgr.free_flow_id(pon_port, onu_id, flow_id) try: tconts = self.tech_profile[pon_port].get_tconts( tech_profile_instance) self.stub.RemoveTconts( openolt_pb2.Tconts(intf_id=pon_port, onu_id=onu_id, tconts=tconts)) except grpc.RpcError as grpc_e: self.log.error('error-removing-tcont-scheduler-queues', err=grpc_e)
def add_dhcp_trap(intf_id, onu_id, self, classifier, action): self.log.info('add dhcp trap', classifier=classifier, action=action) action.clear() action['trap_to_host'] = True classifier['pkt_tag_type'] = 'single_tag' classifier.pop('vlan_vid', None) gemport_id = self.mk_gemport_id(onu_id) flow_id = self.mk_flow_id(intf_id, onu_id, DHCP_FLOW_INDEX) upstream_flow = openolt_pb2.Flow( onu_id=onu_id, flow_id=flow_id, flow_type="upstream", gemport_id=gemport_id, classifier=self.mk_classifier(classifier), action=self.mk_action(action)) self.stub.FlowAdd(upstream_flow)
def add_lldp_flow(self, logical_flow, network_intf_id=0): classifier = dict() classifier[ETH_TYPE] = LLDP_ETH_TYPE classifier[PACKET_TAG_TYPE] = UNTAGGED action = dict() action[TRAP_TO_HOST] = True # LLDP flow is installed to trap LLDP packets on the NNI port. # We manage flow_id resource pool on per PON port basis. # Since this situation is tricky, as a hack, we pass the NNI port # index (network_intf_id) as PON port Index for the flow_id resource # pool. Also, there is no ONU Id available for trapping LLDP packets # on NNI port, use onu_id as -1 (invalid) # ****************** CAVEAT ******************* # This logic works if the NNI Port Id falls within the same valid # range of PON Port Ids. If this doesn't work for some OLT Vendor # we need to have a re-look at this. # ********************************************* onu_id = -1 intf_id_onu_id = (network_intf_id, onu_id) flow_id = self.resource_mgr.get_flow_id(intf_id_onu_id) downstream_flow = openolt_pb2.Flow( access_intf_id=-1, # access_intf_id not required onu_id=onu_id, # onu_id not required flow_id=flow_id, flow_type=DOWNSTREAM, network_intf_id=network_intf_id, gemport_id=-1, # gemport_id not required classifier=self.mk_classifier(classifier), action=self.mk_action(action), priority=logical_flow.priority) self.log.debug('add lldp downstream trap', classifier=classifier, action=action, flow=downstream_flow) if self.add_flow_to_device(downstream_flow, logical_flow): self.update_flow_info_to_kv_store(network_intf_id, onu_id, flow_id, downstream_flow)
def add_lldp_flow(self, logical_flow, network_intf_id=0): classifier = {} classifier[ETH_TYPE] = LLDP_ETH_TYPE classifier[PACKET_TAG_TYPE] = UNTAGGED action = {} action[TRAP_TO_HOST] = True flow_id = LLDP_FLOW_ID # FIXME downstream_flow = openolt_pb2.Flow( onu_id=-1, # onu_id not required gemport_id=-1, # gemport_id not required access_intf_id=-1, # access_intf_id not required flow_id=flow_id, flow_type=DOWNSTREAM, priority=logical_flow.priority, network_intf_id=network_intf_id, classifier=self.mk_classifier(classifier), action=self.mk_action(action)) self.log.debug('add lldp downstream trap', classifier=classifier, action=action, flow=downstream_flow) self.add_flow_to_device(downstream_flow, logical_flow)
def add_hsia_flow(self, intf_id, onu_id, classifier, action, direction, logical_flow, alloc_id, gemport_id): flow_id = self.resource_mgr.get_hsia_flow_for_onu( intf_id, onu_id, gemport_id) if flow_id is None: self.log.error("hsia-flow-unavailable") return flow = openolt_pb2.Flow(access_intf_id=intf_id, onu_id=onu_id, flow_id=flow_id, flow_type=direction, alloc_id=alloc_id, network_intf_id=0, gemport_id=gemport_id, classifier=self.mk_classifier(classifier), action=self.mk_action(action), priority=logical_flow.priority) if self.add_flow_to_device(flow, logical_flow): flow_info = self._get_flow_info_as_json_blob(flow, HSIA_FLOW) self.update_flow_info_to_kv_store(flow.access_intf_id, flow.onu_id, flow.flow_id, flow_info)
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, 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)
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, uplink_eapol_id=EAPOL_FLOW_INDEX, downlink_eapol_id=EAPOL_DOWNLINK_FLOW_INDEX, vlan_id=DEFAULT_MGMT_VLAN): # self.log.debug('add eapol flow pre-process', # classifier=uplink_classifier) # #action=uplink_action) downlink_classifier = {} downlink_classifier['eth_type'] = EAP_ETH_TYPE downlink_classifier['pkt_tag_type'] = 'single_tag' downlink_classifier['vlan_vid'] = vlan_id downlink_action = {} downlink_action['push_vlan'] = True downlink_action['vlan_vid'] = vlan_id 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 = platform.mk_gemport_id(onu_id) self.log.debug('add eapol flow', uplink_classifier=uplink_classifier, uplink_action=uplink_action, downlink_classifier=downlink_classifier, downlink_action=downlink_action) # Add Upstream EAPOL Flow. uplink_flow_id = 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, classifier=self.mk_classifier(uplink_classifier), action=self.mk_action(uplink_action)) self.stub.FlowAdd(upstream_flow) # Add Downstream EAPOL Flow. downlink_flow_id = 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, classifier=self.mk_classifier(downlink_classifier), action=self.mk_action(downlink_action)) self.stub.FlowAdd(downstream_flow) self.log.debug('eap flows', upstream_flow=upstream_flow, downstream_flow=downstream_flow)