blob: 48c877dde666a569f8c18aa4ec70c4927402f042 [file] [log] [blame]
Shad Ansari2dda4f32018-05-17 07:16:07 +00001#
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 Ansari2dda4f32018-05-17 07:16:07 +000017from voltha.protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC
18import voltha.core.flow_decomposer as fd
19import openolt_platform as platform
20from voltha.adapters.openolt.protos import openolt_pb2
Nicolas Palpacuer61815162018-06-20 18:12:04 -040021from voltha.registry import registry
Shad Ansari2dda4f32018-05-17 07:16:07 +000022
Shad Ansarif9d2d102018-06-13 02:15:26 +000023HSIA_FLOW_INDEX = 0 # FIXME
24DHCP_FLOW_INDEX = 1 # FIXME
Shad Ansari47e0c392018-07-17 23:55:07 +000025DHCP_DOWNLINK_FLOW_INDEX = 6 # FIXME
Shad Ansarif9d2d102018-06-13 02:15:26 +000026EAPOL_FLOW_INDEX = 2 # FIXME
27EAPOL_DOWNLINK_FLOW_INDEX = 3 # FIXME
Nicolas Palpacuer61815162018-06-20 18:12:04 -040028EAPOL_DOWNLINK_SECONDARY_FLOW_INDEX = 4 # FIXME
29EAPOL_UPLINK_SECONDARY_FLOW_INDEX = 5 # FIXME
30
31
32EAP_ETH_TYPE = 0x888e
Shad Ansari2dda4f32018-05-17 07:16:07 +000033
34# FIXME - see also BRDCM_DEFAULT_VLAN in broadcom_onu.py
35DEFAULT_MGMT_VLAN = 4091
36
Shad Ansarif9d2d102018-06-13 02:15:26 +000037
Shad Ansari2dda4f32018-05-17 07:16:07 +000038class OpenOltFlowMgr(object):
39
Nicolas Palpacuer61815162018-06-20 18:12:04 -040040 def __init__(self, log, stub, device_id):
Shad Ansari2dda4f32018-05-17 07:16:07 +000041 self.log = log
42 self.stub = stub
Nicolas Palpacuer61815162018-06-20 18:12:04 -040043 self.device_id = device_id
44 self.flow_proxy = registry('core').get_proxy(
45 '/devices/{}/flows'.format(self.device_id))
Shad Ansari2dda4f32018-05-17 07:16:07 +000046
47 def add_flow(self, flow, is_down_stream):
Shad Ansarie048aaa2018-05-18 18:27:21 +000048 self.log.debug('add flow', flow=flow, is_down_stream=is_down_stream)
Shad Ansari2dda4f32018-05-17 07:16:07 +000049 classifier_info = dict()
50 action_info = dict()
51
52 in_port = fd.get_in_port(flow)
53 assert in_port is not None
54
55 for field in fd.get_ofb_fields(flow):
56 if field.type == fd.ETH_TYPE:
57 classifier_info['eth_type'] = field.eth_type
Shad Ansarie048aaa2018-05-18 18:27:21 +000058 self.log.debug('field-type-eth-type',
Shad Ansarif9d2d102018-06-13 02:15:26 +000059 eth_type=classifier_info['eth_type'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000060 elif field.type == fd.IP_PROTO:
61 classifier_info['ip_proto'] = field.ip_proto
Shad Ansarie048aaa2018-05-18 18:27:21 +000062 self.log.debug('field-type-ip-proto',
Shad Ansarif9d2d102018-06-13 02:15:26 +000063 ip_proto=classifier_info['ip_proto'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000064 elif field.type == fd.IN_PORT:
65 classifier_info['in_port'] = field.port
Shad Ansarie048aaa2018-05-18 18:27:21 +000066 self.log.debug('field-type-in-port',
Shad Ansarif9d2d102018-06-13 02:15:26 +000067 in_port=classifier_info['in_port'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000068 elif field.type == fd.VLAN_VID:
69 classifier_info['vlan_vid'] = field.vlan_vid & 0xfff
Shad Ansarie048aaa2018-05-18 18:27:21 +000070 self.log.debug('field-type-vlan-vid',
Shad Ansarif9d2d102018-06-13 02:15:26 +000071 vlan=classifier_info['vlan_vid'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000072 elif field.type == fd.VLAN_PCP:
73 classifier_info['vlan_pcp'] = field.vlan_pcp
Shad Ansarie048aaa2018-05-18 18:27:21 +000074 self.log.debug('field-type-vlan-pcp',
Shad Ansarif9d2d102018-06-13 02:15:26 +000075 pcp=classifier_info['vlan_pcp'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000076 elif field.type == fd.UDP_DST:
77 classifier_info['udp_dst'] = field.udp_dst
Shad Ansarie048aaa2018-05-18 18:27:21 +000078 self.log.debug('field-type-udp-dst',
Shad Ansarif9d2d102018-06-13 02:15:26 +000079 udp_dst=classifier_info['udp_dst'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000080 elif field.type == fd.UDP_SRC:
81 classifier_info['udp_src'] = field.udp_src
Shad Ansarie048aaa2018-05-18 18:27:21 +000082 self.log.debug('field-type-udp-src',
Shad Ansarif9d2d102018-06-13 02:15:26 +000083 udp_src=classifier_info['udp_src'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000084 elif field.type == fd.IPV4_DST:
85 classifier_info['ipv4_dst'] = field.ipv4_dst
Shad Ansarie048aaa2018-05-18 18:27:21 +000086 self.log.debug('field-type-ipv4-dst',
Shad Ansarif9d2d102018-06-13 02:15:26 +000087 ipv4_dst=classifier_info['ipv4_dst'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000088 elif field.type == fd.IPV4_SRC:
89 classifier_info['ipv4_src'] = field.ipv4_src
Shad Ansarie048aaa2018-05-18 18:27:21 +000090 self.log.debug('field-type-ipv4-src',
Shad Ansarif9d2d102018-06-13 02:15:26 +000091 ipv4_dst=classifier_info['ipv4_src'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000092 elif field.type == fd.METADATA:
93 classifier_info['metadata'] = field.table_metadata
Shad Ansarie048aaa2018-05-18 18:27:21 +000094 self.log.debug('field-type-metadata',
Shad Ansarif9d2d102018-06-13 02:15:26 +000095 metadata=classifier_info['metadata'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000096 else:
97 raise NotImplementedError('field.type={}'.format(
98 field.type))
99
100 for action in fd.get_actions(flow):
101 if action.type == fd.OUTPUT:
102 action_info['output'] = action.output.port
Shad Ansarie048aaa2018-05-18 18:27:21 +0000103 self.log.debug('action-type-output',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000104 output=action_info['output'],
105 in_port=classifier_info['in_port'])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000106 elif action.type == fd.POP_VLAN:
107 action_info['pop_vlan'] = True
Shad Ansarie048aaa2018-05-18 18:27:21 +0000108 self.log.debug('action-type-pop-vlan', in_port=in_port)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000109 elif action.type == fd.PUSH_VLAN:
110 action_info['push_vlan'] = True
111 action_info['tpid'] = action.push.ethertype
Shad Ansarie048aaa2018-05-18 18:27:21 +0000112 self.log.debug('action-type-push-vlan',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000113 push_tpid=action_info['tpid'], in_port=in_port)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000114 if action.push.ethertype != 0x8100:
115 self.log.error('unhandled-tpid',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000116 ethertype=action.push.ethertype)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000117 elif action.type == fd.SET_FIELD:
118 # action_info['action_type'] = 'set_field'
119 _field = action.set_field.field.ofb_field
120 assert (action.set_field.field.oxm_class ==
121 OFPXMC_OPENFLOW_BASIC)
Shad Ansarie048aaa2018-05-18 18:27:21 +0000122 self.log.debug('action-type-set-field',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000123 field=_field, in_port=in_port)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000124 if _field.type == fd.VLAN_VID:
Shad Ansarie048aaa2018-05-18 18:27:21 +0000125 self.log.debug('set-field-type-vlan-vid',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000126 vlan_vid=_field.vlan_vid & 0xfff)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000127 action_info['vlan_vid'] = (_field.vlan_vid & 0xfff)
128 else:
129 self.log.error('unsupported-action-set-field-type',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000130 field_type=_field.type)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000131 else:
132 self.log.error('unsupported-action-type',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000133 action_type=action.type, in_port=in_port)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000134
135 # FIXME - Why ignore downstream flows?
136 if is_down_stream is False:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000137 intf_id = platform.intf_id_from_uni_port_num(
138 classifier_info['in_port'])
139 onu_id = platform.onu_id_from_port_num(
140 classifier_info['in_port'])
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400141 self.divide_and_add_flow(intf_id, onu_id,
142 flow.priority, classifier_info,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000143 action_info)
144 # else:
Shad Ansari2dda4f32018-05-17 07:16:07 +0000145 # self.log.info('ignore downstream flow', flow=flow,
146 # classifier_info=classifier_info,
147 # action_info=action_info)
148
149 # FIXME - No need for divide_and_add_flow if
150 # both upstream and downstream flows
151 # are acted upon (not just upstream flows).
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400152 def divide_and_add_flow(self, intf_id, onu_id, priority, classifier,
153 action):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000154 if 'ip_proto' in classifier:
155 if classifier['ip_proto'] == 17:
156 self.log.debug('dhcp flow add')
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400157 self.add_dhcp_trap(intf_id, onu_id, priority, classifier,
158 action)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000159 elif classifier['ip_proto'] == 2:
Shad Ansarie048aaa2018-05-18 18:27:21 +0000160 self.log.debug('igmp flow add ignored')
Shad Ansari2dda4f32018-05-17 07:16:07 +0000161 else:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000162 self.log.debug("Invalid-Classifier-to-handle",
163 classifier=classifier,
164 action=action)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000165 elif 'eth_type' in classifier:
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400166 if classifier['eth_type'] == EAP_ETH_TYPE:
Shad Ansarie048aaa2018-05-18 18:27:21 +0000167 self.log.debug('eapol flow add')
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400168 self.add_eapol_flow(intf_id, onu_id, priority)
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400169
Shad Ansari2dda4f32018-05-17 07:16:07 +0000170 elif 'push_vlan' in action:
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400171 self.add_data_flow(intf_id, onu_id, priority, classifier, action)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000172 else:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000173 self.log.debug('Invalid-flow-type-to-handle',
174 classifier=classifier,
175 action=action)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000176
Shad Ansari47e0c392018-07-17 23:55:07 +0000177 def add_data_flow(self, intf_id, onu_id, priority, uplink_classifier,
178 uplink_action):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000179
180 downlink_classifier = dict(uplink_classifier)
181 downlink_action = dict(uplink_action)
182
183 uplink_classifier['pkt_tag_type'] = 'single_tag'
184
185 downlink_classifier['pkt_tag_type'] = 'double_tag'
186 downlink_classifier['vlan_vid'] = uplink_action['vlan_vid']
187 downlink_classifier['metadata'] = uplink_classifier['vlan_vid']
188 del downlink_action['push_vlan']
189 downlink_action['pop_vlan'] = True
190
191 # To-Do right now only one GEM port is supported, so below method
192 # will take care of handling all the p bits.
193 # We need to revisit when mulitple gem port per p bits is needed.
Shad Ansari47e0c392018-07-17 23:55:07 +0000194 self.add_hsia_flow(intf_id, onu_id, priority, uplink_classifier,
195 uplink_action, downlink_classifier, downlink_action,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000196 HSIA_FLOW_INDEX)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000197
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400198 # Secondary EAP on the subscriber vlan
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400199 (eap_active, eap_priority) = self.is_eap_enabled(intf_id, onu_id)
200 if eap_active:
201 self.add_eapol_flow(intf_id, onu_id, eap_priority,
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400202 uplink_eapol_id=EAPOL_UPLINK_SECONDARY_FLOW_INDEX,
203 downlink_eapol_id=EAPOL_DOWNLINK_SECONDARY_FLOW_INDEX,
204 vlan_id=uplink_classifier['vlan_vid'])
205
Shad Ansari47e0c392018-07-17 23:55:07 +0000206 def add_hsia_flow(self, intf_id, onu_id, priority, uplink_classifier,
207 uplink_action, downlink_classifier, downlink_action,
208 hsia_id):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000209
210 gemport_id = platform.mk_gemport_id(onu_id)
211 flow_id = platform.mk_flow_id(intf_id, onu_id, hsia_id)
212
Shad Ansarif9d2d102018-06-13 02:15:26 +0000213 self.log.debug('add upstream flow', onu_id=onu_id,
214 classifier=uplink_classifier, action=uplink_action,
215 gemport_id=gemport_id, flow_id=flow_id)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000216
217 flow = openolt_pb2.Flow(
Shad Ansarif9d2d102018-06-13 02:15:26 +0000218 onu_id=onu_id, flow_id=flow_id, flow_type="upstream",
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400219 access_intf_id=intf_id, gemport_id=gemport_id, priority=priority,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000220 classifier=self.mk_classifier(uplink_classifier),
221 action=self.mk_action(uplink_action))
Shad Ansari2dda4f32018-05-17 07:16:07 +0000222
223 self.stub.FlowAdd(flow)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000224
Shad Ansarie048aaa2018-05-18 18:27:21 +0000225 self.log.debug('add downstream flow', classifier=downlink_classifier,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000226 action=downlink_action, gemport_id=gemport_id,
227 flow_id=flow_id)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000228
229 flow = openolt_pb2.Flow(
230 onu_id=onu_id, flow_id=flow_id, flow_type="downstream",
231 access_intf_id=intf_id, gemport_id=gemport_id,
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400232 priority=priority,
Shad Ansari2dda4f32018-05-17 07:16:07 +0000233 classifier=self.mk_classifier(downlink_classifier),
234 action=self.mk_action(downlink_action))
235
236 self.stub.FlowAdd(flow)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000237
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400238 def add_dhcp_trap(self, intf_id, onu_id, priority, classifier, action):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000239
Shad Ansari47e0c392018-07-17 23:55:07 +0000240 self.log.debug('add dhcp upstream trap', classifier=classifier,
241 action=action)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000242
243 action.clear()
244 action['trap_to_host'] = True
245 classifier['pkt_tag_type'] = 'single_tag'
246 classifier.pop('vlan_vid', None)
247
248 gemport_id = platform.mk_gemport_id(onu_id)
249 flow_id = platform.mk_flow_id(intf_id, onu_id, DHCP_FLOW_INDEX)
250
251 upstream_flow = openolt_pb2.Flow(
Shad Ansarif9d2d102018-06-13 02:15:26 +0000252 onu_id=onu_id, flow_id=flow_id, flow_type="upstream",
Shad Ansari47e0c392018-07-17 23:55:07 +0000253 access_intf_id=intf_id, network_intf_id=0, gemport_id=gemport_id,
254 priority=priority, classifier=self.mk_classifier(classifier),
Shad Ansarif9d2d102018-06-13 02:15:26 +0000255 action=self.mk_action(action))
Shad Ansari2dda4f32018-05-17 07:16:07 +0000256
257 self.stub.FlowAdd(upstream_flow)
258
Shad Ansari47e0c392018-07-17 23:55:07 +0000259 # FIXME - Fix OpenOLT handling of downstream flows instead
260 # of duplicating the downstream flow from the upstream
261 # flow.
262 # FIXME - ONOS should send explicit upstream and downstream
263 # exact dhcp trap flow.
264 classifier['udp_src'] = 67
265 classifier['udp_dst'] = 68
266 classifier['pkt_tag_type'] = 'double_tag'
267 action.pop('push_vlan', None)
268
269 flow_id = platform.mk_flow_id(intf_id, onu_id,
270 DHCP_DOWNLINK_FLOW_INDEX)
271
272 downstream_flow = openolt_pb2.Flow(
273 onu_id=onu_id, flow_id=flow_id, flow_type="downstream",
274 access_intf_id=intf_id, network_intf_id=0, gemport_id=gemport_id,
275 priority=priority, classifier=self.mk_classifier(classifier),
276 action=self.mk_action(action))
277
278 self.log.debug('add dhcp downstream trap', access_intf_id=intf_id,
279 onu_id=onu_id, flow_id=flow_id)
280 self.stub.FlowAdd(downstream_flow)
281
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400282 def add_eapol_flow(self, intf_id, onu_id, priority,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000283 uplink_eapol_id=EAPOL_FLOW_INDEX,
284 downlink_eapol_id=EAPOL_DOWNLINK_FLOW_INDEX,
285 vlan_id=DEFAULT_MGMT_VLAN):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000286
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400287 # self.log.debug('add eapol flow pre-process',
288 # classifier=uplink_classifier)
289 # #action=uplink_action)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000290
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400291 downlink_classifier = {}
292 downlink_classifier['eth_type'] = EAP_ETH_TYPE
293 downlink_classifier['pkt_tag_type'] = 'single_tag'
294 downlink_classifier['vlan_vid'] = vlan_id
Shad Ansari2dda4f32018-05-17 07:16:07 +0000295
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400296 downlink_action = {}
297 downlink_action['push_vlan'] = True
298 downlink_action['vlan_vid'] = vlan_id
Shad Ansari2dda4f32018-05-17 07:16:07 +0000299
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400300 uplink_classifier = {}
301 uplink_classifier['eth_type'] = EAP_ETH_TYPE
Shad Ansari2dda4f32018-05-17 07:16:07 +0000302 uplink_classifier['pkt_tag_type'] = 'single_tag'
303 uplink_classifier['vlan_vid'] = vlan_id
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400304
305 uplink_action = {}
Shad Ansari2dda4f32018-05-17 07:16:07 +0000306 uplink_action['trap_to_host'] = True
307
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400308 gemport_id = platform.mk_gemport_id(onu_id)
309
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400310 # Add Upstream EAPOL Flow.
311
312 uplink_flow_id = platform.mk_flow_id(intf_id, onu_id, uplink_eapol_id)
313
Shad Ansari2dda4f32018-05-17 07:16:07 +0000314 upstream_flow = openolt_pb2.Flow(
Shad Ansarif9d2d102018-06-13 02:15:26 +0000315 onu_id=onu_id, flow_id=uplink_flow_id, flow_type="upstream",
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400316 access_intf_id=intf_id, gemport_id=gemport_id, priority=priority,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000317 classifier=self.mk_classifier(uplink_classifier),
318 action=self.mk_action(uplink_action))
Shad Ansari2dda4f32018-05-17 07:16:07 +0000319
320 self.stub.FlowAdd(upstream_flow)
321
322 # Add Downstream EAPOL Flow.
Shad Ansarif9d2d102018-06-13 02:15:26 +0000323 downlink_flow_id = platform.mk_flow_id(intf_id, onu_id,
324 downlink_eapol_id)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000325
326 downstream_flow = openolt_pb2.Flow(
Shad Ansarif9d2d102018-06-13 02:15:26 +0000327 onu_id=onu_id, flow_id=downlink_flow_id, flow_type="downstream",
328 access_intf_id=intf_id, gemport_id=gemport_id,
329 classifier=self.mk_classifier(downlink_classifier),
330 action=self.mk_action(downlink_action))
Shad Ansari2dda4f32018-05-17 07:16:07 +0000331
332 self.stub.FlowAdd(downstream_flow)
333
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400334 self.log.debug('eap flows', upstream_flow=upstream_flow,
335 downstream_flow=downstream_flow)
336
Shad Ansari2dda4f32018-05-17 07:16:07 +0000337 def mk_classifier(self, classifier_info):
338
339 classifier = openolt_pb2.Classifier()
340
341 if 'eth_type' in classifier_info:
342 classifier.eth_type = classifier_info['eth_type']
343 if 'ip_proto' in classifier_info:
344 classifier.ip_proto = classifier_info['ip_proto']
345 if 'vlan_vid' in classifier_info:
346 classifier.o_vid = classifier_info['vlan_vid']
347 if 'metadata' in classifier_info:
348 classifier.i_vid = classifier_info['metadata']
349 if 'vlan_pcp' in classifier_info:
350 classifier.o_pbits = classifier_info['vlan_pcp']
351 if 'udp_src' in classifier_info:
352 classifier.src_port = classifier_info['udp_src']
353 if 'udp_dst' in classifier_info:
354 classifier.dst_port = classifier_info['udp_dst']
355 if 'ipv4_dst' in classifier_info:
356 classifier.dst_ip = classifier_info['ipv4_dst']
357 if 'ipv4_src' in classifier_info:
358 classifier.src_ip = classifier_info['ipv4_src']
359 if 'pkt_tag_type' in classifier_info:
360 if classifier_info['pkt_tag_type'] == 'single_tag':
361 classifier.pkt_tag_type = 'single_tag'
362 elif classifier_info['pkt_tag_type'] == 'double_tag':
363 classifier.pkt_tag_type = 'double_tag'
364 elif classifier_info['pkt_tag_type'] == 'untagged':
365 classifier.pkt_tag_type = 'untagged'
366 else:
367 classifier.pkt_tag_type = 'none'
368
369 return classifier
370
371 def mk_action(self, action_info):
372 action = openolt_pb2.Action()
373
Shad Ansarif9d2d102018-06-13 02:15:26 +0000374 if 'pop_vlan' in action_info:
375 action.o_vid = action_info['vlan_vid']
Shad Ansari2dda4f32018-05-17 07:16:07 +0000376 action.cmd.remove_outer_tag = True
Shad Ansarif9d2d102018-06-13 02:15:26 +0000377 elif 'push_vlan' in action_info:
378 action.o_vid = action_info['vlan_vid']
Shad Ansari2dda4f32018-05-17 07:16:07 +0000379 action.cmd.add_outer_tag = True
Shad Ansarif9d2d102018-06-13 02:15:26 +0000380 elif 'trap_to_host' in action_info:
Shad Ansari2dda4f32018-05-17 07:16:07 +0000381 action.cmd.trap_to_host = True
Shad Ansarif9d2d102018-06-13 02:15:26 +0000382 else:
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400383 self.log.info('Invalid-action-field', action_info=action_info)
Shad Ansarif9d2d102018-06-13 02:15:26 +0000384 return
Shad Ansari2dda4f32018-05-17 07:16:07 +0000385 return action
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400386
387 def is_eap_enabled(self, intf_id, onu_id):
388 flows = self.flow_proxy.get('/').items
389
390 for flow in flows:
391 eap_flow = False
392 eap_intf_id = None
393 eap_onu_id = None
394 for field in fd.get_ofb_fields(flow):
395 if field.type == fd.ETH_TYPE:
396 if field.eth_type == EAP_ETH_TYPE:
397 eap_flow = True
398 if field.type == fd.IN_PORT:
Shad Ansari47e0c392018-07-17 23:55:07 +0000399 eap_intf_id = platform.intf_id_from_uni_port_num(
400 field.port)
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400401 eap_onu_id = platform.onu_id_from_port_num(field.port)
402
403 if eap_flow:
404 self.log.debug('eap flow detected', onu_id=onu_id,
405 intf_id=intf_id, eap_intf_id=eap_intf_id,
406 eap_onu_id=eap_onu_id)
407 if eap_flow and intf_id == eap_intf_id and onu_id == eap_onu_id:
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400408 return (True, flow.priority)
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400409
Shad Ansari47e0c392018-07-17 23:55:07 +0000410 return (False, 0)