Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2018 the original author or authors. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 17 | from voltha.protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC |
| 18 | import voltha.core.flow_decomposer as fd |
| 19 | import openolt_platform as platform |
| 20 | from voltha.adapters.openolt.protos import openolt_pb2 |
| 21 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 22 | HSIA_FLOW_INDEX = 0 # FIXME |
| 23 | DHCP_FLOW_INDEX = 1 # FIXME |
| 24 | EAPOL_FLOW_INDEX = 2 # FIXME |
| 25 | EAPOL_DOWNLINK_FLOW_INDEX = 3 # FIXME |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 26 | |
| 27 | # FIXME - see also BRDCM_DEFAULT_VLAN in broadcom_onu.py |
| 28 | DEFAULT_MGMT_VLAN = 4091 |
| 29 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 30 | |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 31 | class OpenOltFlowMgr(object): |
| 32 | |
| 33 | def __init__(self, log, stub): |
| 34 | self.log = log |
| 35 | self.stub = stub |
| 36 | |
| 37 | def add_flow(self, flow, is_down_stream): |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 38 | self.log.debug('add flow', flow=flow, is_down_stream=is_down_stream) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 39 | classifier_info = dict() |
| 40 | action_info = dict() |
| 41 | |
| 42 | in_port = fd.get_in_port(flow) |
| 43 | assert in_port is not None |
| 44 | |
| 45 | for field in fd.get_ofb_fields(flow): |
| 46 | if field.type == fd.ETH_TYPE: |
| 47 | classifier_info['eth_type'] = field.eth_type |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 48 | self.log.debug('field-type-eth-type', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 49 | eth_type=classifier_info['eth_type']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 50 | elif field.type == fd.IP_PROTO: |
| 51 | classifier_info['ip_proto'] = field.ip_proto |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 52 | self.log.debug('field-type-ip-proto', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 53 | ip_proto=classifier_info['ip_proto']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 54 | elif field.type == fd.IN_PORT: |
| 55 | classifier_info['in_port'] = field.port |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 56 | self.log.debug('field-type-in-port', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 57 | in_port=classifier_info['in_port']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 58 | elif field.type == fd.VLAN_VID: |
| 59 | classifier_info['vlan_vid'] = field.vlan_vid & 0xfff |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 60 | self.log.debug('field-type-vlan-vid', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 61 | vlan=classifier_info['vlan_vid']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 62 | elif field.type == fd.VLAN_PCP: |
| 63 | classifier_info['vlan_pcp'] = field.vlan_pcp |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 64 | self.log.debug('field-type-vlan-pcp', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 65 | pcp=classifier_info['vlan_pcp']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 66 | elif field.type == fd.UDP_DST: |
| 67 | classifier_info['udp_dst'] = field.udp_dst |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 68 | self.log.debug('field-type-udp-dst', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 69 | udp_dst=classifier_info['udp_dst']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 70 | elif field.type == fd.UDP_SRC: |
| 71 | classifier_info['udp_src'] = field.udp_src |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 72 | self.log.debug('field-type-udp-src', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 73 | udp_src=classifier_info['udp_src']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 74 | elif field.type == fd.IPV4_DST: |
| 75 | classifier_info['ipv4_dst'] = field.ipv4_dst |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 76 | self.log.debug('field-type-ipv4-dst', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 77 | ipv4_dst=classifier_info['ipv4_dst']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 78 | elif field.type == fd.IPV4_SRC: |
| 79 | classifier_info['ipv4_src'] = field.ipv4_src |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 80 | self.log.debug('field-type-ipv4-src', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 81 | ipv4_dst=classifier_info['ipv4_src']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 82 | elif field.type == fd.METADATA: |
| 83 | classifier_info['metadata'] = field.table_metadata |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 84 | self.log.debug('field-type-metadata', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 85 | metadata=classifier_info['metadata']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 86 | else: |
| 87 | raise NotImplementedError('field.type={}'.format( |
| 88 | field.type)) |
| 89 | |
| 90 | for action in fd.get_actions(flow): |
| 91 | if action.type == fd.OUTPUT: |
| 92 | action_info['output'] = action.output.port |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 93 | self.log.debug('action-type-output', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 94 | output=action_info['output'], |
| 95 | in_port=classifier_info['in_port']) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 96 | elif action.type == fd.POP_VLAN: |
| 97 | action_info['pop_vlan'] = True |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 98 | self.log.debug('action-type-pop-vlan', in_port=in_port) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 99 | elif action.type == fd.PUSH_VLAN: |
| 100 | action_info['push_vlan'] = True |
| 101 | action_info['tpid'] = action.push.ethertype |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 102 | self.log.debug('action-type-push-vlan', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 103 | push_tpid=action_info['tpid'], in_port=in_port) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 104 | if action.push.ethertype != 0x8100: |
| 105 | self.log.error('unhandled-tpid', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 106 | ethertype=action.push.ethertype) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 107 | elif action.type == fd.SET_FIELD: |
| 108 | # action_info['action_type'] = 'set_field' |
| 109 | _field = action.set_field.field.ofb_field |
| 110 | assert (action.set_field.field.oxm_class == |
| 111 | OFPXMC_OPENFLOW_BASIC) |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 112 | self.log.debug('action-type-set-field', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 113 | field=_field, in_port=in_port) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 114 | if _field.type == fd.VLAN_VID: |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 115 | self.log.debug('set-field-type-vlan-vid', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 116 | vlan_vid=_field.vlan_vid & 0xfff) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 117 | action_info['vlan_vid'] = (_field.vlan_vid & 0xfff) |
| 118 | else: |
| 119 | self.log.error('unsupported-action-set-field-type', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 120 | field_type=_field.type) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 121 | else: |
| 122 | self.log.error('unsupported-action-type', |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 123 | action_type=action.type, in_port=in_port) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 124 | |
| 125 | # FIXME - Why ignore downstream flows? |
| 126 | if is_down_stream is False: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 127 | intf_id = platform.intf_id_from_uni_port_num( |
| 128 | classifier_info['in_port']) |
| 129 | onu_id = platform.onu_id_from_port_num( |
| 130 | classifier_info['in_port']) |
| 131 | self.divide_and_add_flow(intf_id, onu_id, classifier_info, |
| 132 | action_info) |
| 133 | # else: |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 134 | # self.log.info('ignore downstream flow', flow=flow, |
| 135 | # classifier_info=classifier_info, |
| 136 | # action_info=action_info) |
| 137 | |
| 138 | # FIXME - No need for divide_and_add_flow if |
| 139 | # both upstream and downstream flows |
| 140 | # are acted upon (not just upstream flows). |
| 141 | def divide_and_add_flow(self, intf_id, onu_id, classifier, action): |
| 142 | if 'ip_proto' in classifier: |
| 143 | if classifier['ip_proto'] == 17: |
| 144 | self.log.debug('dhcp flow add') |
| 145 | self.add_dhcp_trap(intf_id, onu_id, classifier, action) |
| 146 | elif classifier['ip_proto'] == 2: |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 147 | self.log.debug('igmp flow add ignored') |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 148 | else: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 149 | self.log.debug("Invalid-Classifier-to-handle", |
| 150 | classifier=classifier, |
| 151 | action=action) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 152 | elif 'eth_type' in classifier: |
| 153 | if classifier['eth_type'] == 0x888e: |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 154 | self.log.debug('eapol flow add') |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 155 | self.add_eapol_flow(intf_id, onu_id, classifier, action) |
| 156 | elif 'push_vlan' in action: |
| 157 | self.add_data_flow(intf_id, onu_id, classifier, action) |
| 158 | else: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 159 | self.log.debug('Invalid-flow-type-to-handle', |
| 160 | classifier=classifier, |
| 161 | action=action) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 162 | |
| 163 | def add_data_flow(self, intf_id, onu_id, uplink_classifier, uplink_action): |
| 164 | |
| 165 | downlink_classifier = dict(uplink_classifier) |
| 166 | downlink_action = dict(uplink_action) |
| 167 | |
| 168 | uplink_classifier['pkt_tag_type'] = 'single_tag' |
| 169 | |
| 170 | downlink_classifier['pkt_tag_type'] = 'double_tag' |
| 171 | downlink_classifier['vlan_vid'] = uplink_action['vlan_vid'] |
| 172 | downlink_classifier['metadata'] = uplink_classifier['vlan_vid'] |
| 173 | del downlink_action['push_vlan'] |
| 174 | downlink_action['pop_vlan'] = True |
| 175 | |
| 176 | # To-Do right now only one GEM port is supported, so below method |
| 177 | # will take care of handling all the p bits. |
| 178 | # We need to revisit when mulitple gem port per p bits is needed. |
| 179 | self.add_hsia_flow(intf_id, onu_id, uplink_classifier, uplink_action, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 180 | downlink_classifier, downlink_action, |
| 181 | HSIA_FLOW_INDEX) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 182 | |
| 183 | def add_hsia_flow(self, intf_id, onu_id, uplink_classifier, uplink_action, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 184 | downlink_classifier, downlink_action, hsia_id): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 185 | |
| 186 | gemport_id = platform.mk_gemport_id(onu_id) |
| 187 | flow_id = platform.mk_flow_id(intf_id, onu_id, hsia_id) |
| 188 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 189 | self.log.debug('add upstream flow', onu_id=onu_id, |
| 190 | classifier=uplink_classifier, action=uplink_action, |
| 191 | gemport_id=gemport_id, flow_id=flow_id) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 192 | |
| 193 | flow = openolt_pb2.Flow( |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 194 | onu_id=onu_id, flow_id=flow_id, flow_type="upstream", |
| 195 | access_intf_id=intf_id, gemport_id=gemport_id, |
| 196 | classifier=self.mk_classifier(uplink_classifier), |
| 197 | action=self.mk_action(uplink_action)) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 198 | |
| 199 | self.stub.FlowAdd(flow) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 200 | |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 201 | self.log.debug('add downstream flow', classifier=downlink_classifier, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 202 | action=downlink_action, gemport_id=gemport_id, |
| 203 | flow_id=flow_id) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 204 | |
| 205 | flow = openolt_pb2.Flow( |
| 206 | onu_id=onu_id, flow_id=flow_id, flow_type="downstream", |
| 207 | access_intf_id=intf_id, gemport_id=gemport_id, |
| 208 | classifier=self.mk_classifier(downlink_classifier), |
| 209 | action=self.mk_action(downlink_action)) |
| 210 | |
| 211 | self.stub.FlowAdd(flow) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 212 | |
| 213 | def add_dhcp_trap(self, intf_id, onu_id, classifier, action): |
| 214 | |
Shad Ansari | e048aaa | 2018-05-18 18:27:21 +0000 | [diff] [blame] | 215 | self.log.debug('add dhcp trap', classifier=classifier, action=action) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 216 | |
| 217 | action.clear() |
| 218 | action['trap_to_host'] = True |
| 219 | classifier['pkt_tag_type'] = 'single_tag' |
| 220 | classifier.pop('vlan_vid', None) |
| 221 | |
| 222 | gemport_id = platform.mk_gemport_id(onu_id) |
| 223 | flow_id = platform.mk_flow_id(intf_id, onu_id, DHCP_FLOW_INDEX) |
| 224 | |
| 225 | upstream_flow = openolt_pb2.Flow( |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 226 | onu_id=onu_id, flow_id=flow_id, flow_type="upstream", |
| 227 | access_intf_id=intf_id, gemport_id=gemport_id, |
| 228 | classifier=self.mk_classifier(classifier), |
| 229 | action=self.mk_action(action)) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 230 | |
| 231 | self.stub.FlowAdd(upstream_flow) |
| 232 | |
| 233 | def add_eapol_flow(self, intf_id, onu_id, uplink_classifier, uplink_action, |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 234 | uplink_eapol_id=EAPOL_FLOW_INDEX, |
| 235 | downlink_eapol_id=EAPOL_DOWNLINK_FLOW_INDEX, |
| 236 | vlan_id=DEFAULT_MGMT_VLAN): |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 237 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 238 | self.log.debug('add eapol flow', classifier=uplink_classifier, |
| 239 | action=uplink_action) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 240 | |
| 241 | downlink_classifier = dict(uplink_classifier) |
| 242 | downlink_action = dict(uplink_action) |
| 243 | |
| 244 | gemport_id = platform.mk_gemport_id(onu_id) |
| 245 | uplink_flow_id = platform.mk_flow_id(intf_id, onu_id, uplink_eapol_id) |
| 246 | |
| 247 | # Add Upstream EAPOL Flow. |
| 248 | uplink_classifier['pkt_tag_type'] = 'single_tag' |
| 249 | uplink_classifier['vlan_vid'] = vlan_id |
| 250 | uplink_action.clear() |
| 251 | uplink_action['trap_to_host'] = True |
| 252 | |
| 253 | upstream_flow = openolt_pb2.Flow( |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 254 | onu_id=onu_id, flow_id=uplink_flow_id, flow_type="upstream", |
| 255 | access_intf_id=intf_id, gemport_id=gemport_id, |
| 256 | classifier=self.mk_classifier(uplink_classifier), |
| 257 | action=self.mk_action(uplink_action)) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 258 | |
| 259 | self.stub.FlowAdd(upstream_flow) |
| 260 | |
| 261 | # Add Downstream EAPOL Flow. |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 262 | downlink_flow_id = platform.mk_flow_id(intf_id, onu_id, |
| 263 | downlink_eapol_id) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 264 | downlink_classifier['pkt_tag_type'] = 'single_tag' |
| 265 | downlink_classifier['vlan_vid'] = vlan_id |
| 266 | |
| 267 | downstream_flow = openolt_pb2.Flow( |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 268 | onu_id=onu_id, flow_id=downlink_flow_id, flow_type="downstream", |
| 269 | access_intf_id=intf_id, gemport_id=gemport_id, |
| 270 | classifier=self.mk_classifier(downlink_classifier), |
| 271 | action=self.mk_action(downlink_action)) |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 272 | |
| 273 | self.stub.FlowAdd(downstream_flow) |
| 274 | |
| 275 | def mk_classifier(self, classifier_info): |
| 276 | |
| 277 | classifier = openolt_pb2.Classifier() |
| 278 | |
| 279 | if 'eth_type' in classifier_info: |
| 280 | classifier.eth_type = classifier_info['eth_type'] |
| 281 | if 'ip_proto' in classifier_info: |
| 282 | classifier.ip_proto = classifier_info['ip_proto'] |
| 283 | if 'vlan_vid' in classifier_info: |
| 284 | classifier.o_vid = classifier_info['vlan_vid'] |
| 285 | if 'metadata' in classifier_info: |
| 286 | classifier.i_vid = classifier_info['metadata'] |
| 287 | if 'vlan_pcp' in classifier_info: |
| 288 | classifier.o_pbits = classifier_info['vlan_pcp'] |
| 289 | if 'udp_src' in classifier_info: |
| 290 | classifier.src_port = classifier_info['udp_src'] |
| 291 | if 'udp_dst' in classifier_info: |
| 292 | classifier.dst_port = classifier_info['udp_dst'] |
| 293 | if 'ipv4_dst' in classifier_info: |
| 294 | classifier.dst_ip = classifier_info['ipv4_dst'] |
| 295 | if 'ipv4_src' in classifier_info: |
| 296 | classifier.src_ip = classifier_info['ipv4_src'] |
| 297 | if 'pkt_tag_type' in classifier_info: |
| 298 | if classifier_info['pkt_tag_type'] == 'single_tag': |
| 299 | classifier.pkt_tag_type = 'single_tag' |
| 300 | elif classifier_info['pkt_tag_type'] == 'double_tag': |
| 301 | classifier.pkt_tag_type = 'double_tag' |
| 302 | elif classifier_info['pkt_tag_type'] == 'untagged': |
| 303 | classifier.pkt_tag_type = 'untagged' |
| 304 | else: |
| 305 | classifier.pkt_tag_type = 'none' |
| 306 | |
| 307 | return classifier |
| 308 | |
| 309 | def mk_action(self, action_info): |
| 310 | action = openolt_pb2.Action() |
| 311 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 312 | if 'pop_vlan' in action_info: |
| 313 | action.o_vid = action_info['vlan_vid'] |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 314 | action.cmd.remove_outer_tag = True |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 315 | elif 'push_vlan' in action_info: |
| 316 | action.o_vid = action_info['vlan_vid'] |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 317 | action.cmd.add_outer_tag = True |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 318 | elif 'trap_to_host' in action_info: |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 319 | action.cmd.trap_to_host = True |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 320 | else: |
| 321 | self.log.info('Invalid-action-field') |
| 322 | return |
Shad Ansari | 2dda4f3 | 2018-05-17 07:16:07 +0000 | [diff] [blame] | 323 | return action |