blob: b1a56cf90915b55408b0a5dc7999928f45ea2309 [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
25EAPOL_FLOW_INDEX = 2 # FIXME
26EAPOL_DOWNLINK_FLOW_INDEX = 3 # FIXME
Nicolas Palpacuer61815162018-06-20 18:12:04 -040027EAPOL_DOWNLINK_SECONDARY_FLOW_INDEX = 4 # FIXME
28EAPOL_UPLINK_SECONDARY_FLOW_INDEX = 5 # FIXME
29
30
31EAP_ETH_TYPE = 0x888e
Shad Ansari2dda4f32018-05-17 07:16:07 +000032
33# FIXME - see also BRDCM_DEFAULT_VLAN in broadcom_onu.py
34DEFAULT_MGMT_VLAN = 4091
35
Shad Ansarif9d2d102018-06-13 02:15:26 +000036
Shad Ansari2dda4f32018-05-17 07:16:07 +000037class OpenOltFlowMgr(object):
38
Nicolas Palpacuer61815162018-06-20 18:12:04 -040039 def __init__(self, log, stub, device_id):
Shad Ansari2dda4f32018-05-17 07:16:07 +000040 self.log = log
41 self.stub = stub
Nicolas Palpacuer61815162018-06-20 18:12:04 -040042 self.device_id = device_id
43 self.flow_proxy = registry('core').get_proxy(
44 '/devices/{}/flows'.format(self.device_id))
Shad Ansari2dda4f32018-05-17 07:16:07 +000045
46 def add_flow(self, flow, is_down_stream):
Shad Ansarie048aaa2018-05-18 18:27:21 +000047 self.log.debug('add flow', flow=flow, is_down_stream=is_down_stream)
Shad Ansari2dda4f32018-05-17 07:16:07 +000048 classifier_info = dict()
49 action_info = dict()
50
51 in_port = fd.get_in_port(flow)
52 assert in_port is not None
53
54 for field in fd.get_ofb_fields(flow):
55 if field.type == fd.ETH_TYPE:
56 classifier_info['eth_type'] = field.eth_type
Shad Ansarie048aaa2018-05-18 18:27:21 +000057 self.log.debug('field-type-eth-type',
Shad Ansarif9d2d102018-06-13 02:15:26 +000058 eth_type=classifier_info['eth_type'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000059 elif field.type == fd.IP_PROTO:
60 classifier_info['ip_proto'] = field.ip_proto
Shad Ansarie048aaa2018-05-18 18:27:21 +000061 self.log.debug('field-type-ip-proto',
Shad Ansarif9d2d102018-06-13 02:15:26 +000062 ip_proto=classifier_info['ip_proto'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000063 elif field.type == fd.IN_PORT:
64 classifier_info['in_port'] = field.port
Shad Ansarie048aaa2018-05-18 18:27:21 +000065 self.log.debug('field-type-in-port',
Shad Ansarif9d2d102018-06-13 02:15:26 +000066 in_port=classifier_info['in_port'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000067 elif field.type == fd.VLAN_VID:
68 classifier_info['vlan_vid'] = field.vlan_vid & 0xfff
Shad Ansarie048aaa2018-05-18 18:27:21 +000069 self.log.debug('field-type-vlan-vid',
Shad Ansarif9d2d102018-06-13 02:15:26 +000070 vlan=classifier_info['vlan_vid'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000071 elif field.type == fd.VLAN_PCP:
72 classifier_info['vlan_pcp'] = field.vlan_pcp
Shad Ansarie048aaa2018-05-18 18:27:21 +000073 self.log.debug('field-type-vlan-pcp',
Shad Ansarif9d2d102018-06-13 02:15:26 +000074 pcp=classifier_info['vlan_pcp'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000075 elif field.type == fd.UDP_DST:
76 classifier_info['udp_dst'] = field.udp_dst
Shad Ansarie048aaa2018-05-18 18:27:21 +000077 self.log.debug('field-type-udp-dst',
Shad Ansarif9d2d102018-06-13 02:15:26 +000078 udp_dst=classifier_info['udp_dst'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000079 elif field.type == fd.UDP_SRC:
80 classifier_info['udp_src'] = field.udp_src
Shad Ansarie048aaa2018-05-18 18:27:21 +000081 self.log.debug('field-type-udp-src',
Shad Ansarif9d2d102018-06-13 02:15:26 +000082 udp_src=classifier_info['udp_src'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000083 elif field.type == fd.IPV4_DST:
84 classifier_info['ipv4_dst'] = field.ipv4_dst
Shad Ansarie048aaa2018-05-18 18:27:21 +000085 self.log.debug('field-type-ipv4-dst',
Shad Ansarif9d2d102018-06-13 02:15:26 +000086 ipv4_dst=classifier_info['ipv4_dst'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000087 elif field.type == fd.IPV4_SRC:
88 classifier_info['ipv4_src'] = field.ipv4_src
Shad Ansarie048aaa2018-05-18 18:27:21 +000089 self.log.debug('field-type-ipv4-src',
Shad Ansarif9d2d102018-06-13 02:15:26 +000090 ipv4_dst=classifier_info['ipv4_src'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000091 elif field.type == fd.METADATA:
92 classifier_info['metadata'] = field.table_metadata
Shad Ansarie048aaa2018-05-18 18:27:21 +000093 self.log.debug('field-type-metadata',
Shad Ansarif9d2d102018-06-13 02:15:26 +000094 metadata=classifier_info['metadata'])
Shad Ansari2dda4f32018-05-17 07:16:07 +000095 else:
96 raise NotImplementedError('field.type={}'.format(
97 field.type))
98
99 for action in fd.get_actions(flow):
100 if action.type == fd.OUTPUT:
101 action_info['output'] = action.output.port
Shad Ansarie048aaa2018-05-18 18:27:21 +0000102 self.log.debug('action-type-output',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000103 output=action_info['output'],
104 in_port=classifier_info['in_port'])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000105 elif action.type == fd.POP_VLAN:
106 action_info['pop_vlan'] = True
Shad Ansarie048aaa2018-05-18 18:27:21 +0000107 self.log.debug('action-type-pop-vlan', in_port=in_port)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000108 elif action.type == fd.PUSH_VLAN:
109 action_info['push_vlan'] = True
110 action_info['tpid'] = action.push.ethertype
Shad Ansarie048aaa2018-05-18 18:27:21 +0000111 self.log.debug('action-type-push-vlan',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000112 push_tpid=action_info['tpid'], in_port=in_port)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000113 if action.push.ethertype != 0x8100:
114 self.log.error('unhandled-tpid',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000115 ethertype=action.push.ethertype)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000116 elif action.type == fd.SET_FIELD:
117 # action_info['action_type'] = 'set_field'
118 _field = action.set_field.field.ofb_field
119 assert (action.set_field.field.oxm_class ==
120 OFPXMC_OPENFLOW_BASIC)
Shad Ansarie048aaa2018-05-18 18:27:21 +0000121 self.log.debug('action-type-set-field',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000122 field=_field, in_port=in_port)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000123 if _field.type == fd.VLAN_VID:
Shad Ansarie048aaa2018-05-18 18:27:21 +0000124 self.log.debug('set-field-type-vlan-vid',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000125 vlan_vid=_field.vlan_vid & 0xfff)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000126 action_info['vlan_vid'] = (_field.vlan_vid & 0xfff)
127 else:
128 self.log.error('unsupported-action-set-field-type',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000129 field_type=_field.type)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000130 else:
131 self.log.error('unsupported-action-type',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000132 action_type=action.type, in_port=in_port)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000133
134 # FIXME - Why ignore downstream flows?
135 if is_down_stream is False:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000136 intf_id = platform.intf_id_from_uni_port_num(
137 classifier_info['in_port'])
138 onu_id = platform.onu_id_from_port_num(
139 classifier_info['in_port'])
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400140 self.divide_and_add_flow(intf_id, onu_id,
141 flow.priority, classifier_info,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000142 action_info)
143 # else:
Shad Ansari2dda4f32018-05-17 07:16:07 +0000144 # self.log.info('ignore downstream flow', flow=flow,
145 # classifier_info=classifier_info,
146 # action_info=action_info)
147
148 # FIXME - No need for divide_and_add_flow if
149 # both upstream and downstream flows
150 # are acted upon (not just upstream flows).
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400151 def divide_and_add_flow(self, intf_id, onu_id, priority, classifier,
152 action):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000153 if 'ip_proto' in classifier:
154 if classifier['ip_proto'] == 17:
155 self.log.debug('dhcp flow add')
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400156 self.add_dhcp_trap(intf_id, onu_id, priority, classifier,
157 action)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000158 elif classifier['ip_proto'] == 2:
Shad Ansarie048aaa2018-05-18 18:27:21 +0000159 self.log.debug('igmp flow add ignored')
Shad Ansari2dda4f32018-05-17 07:16:07 +0000160 else:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000161 self.log.debug("Invalid-Classifier-to-handle",
162 classifier=classifier,
163 action=action)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000164 elif 'eth_type' in classifier:
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400165 if classifier['eth_type'] == EAP_ETH_TYPE:
Shad Ansarie048aaa2018-05-18 18:27:21 +0000166 self.log.debug('eapol flow add')
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400167 self.add_eapol_flow(intf_id, onu_id, priority)
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400168
Shad Ansari2dda4f32018-05-17 07:16:07 +0000169 elif 'push_vlan' in action:
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400170 self.add_data_flow(intf_id, onu_id, priority, classifier, action)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000171 else:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000172 self.log.debug('Invalid-flow-type-to-handle',
173 classifier=classifier,
174 action=action)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000175
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400176 def add_data_flow(self, intf_id, onu_id, priority, uplink_classifier, uplink_action):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000177
178 downlink_classifier = dict(uplink_classifier)
179 downlink_action = dict(uplink_action)
180
181 uplink_classifier['pkt_tag_type'] = 'single_tag'
182
183 downlink_classifier['pkt_tag_type'] = 'double_tag'
184 downlink_classifier['vlan_vid'] = uplink_action['vlan_vid']
185 downlink_classifier['metadata'] = uplink_classifier['vlan_vid']
186 del downlink_action['push_vlan']
187 downlink_action['pop_vlan'] = True
188
189 # To-Do right now only one GEM port is supported, so below method
190 # will take care of handling all the p bits.
191 # We need to revisit when mulitple gem port per p bits is needed.
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400192 self.add_hsia_flow(intf_id, onu_id, priority, uplink_classifier, uplink_action,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000193 downlink_classifier, downlink_action,
194 HSIA_FLOW_INDEX)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000195
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400196 # Secondary EAP on the subscriber vlan
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400197 (eap_active, eap_priority) = self.is_eap_enabled(intf_id, onu_id)
198 if eap_active:
199 self.add_eapol_flow(intf_id, onu_id, eap_priority,
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400200 uplink_eapol_id=EAPOL_UPLINK_SECONDARY_FLOW_INDEX,
201 downlink_eapol_id=EAPOL_DOWNLINK_SECONDARY_FLOW_INDEX,
202 vlan_id=uplink_classifier['vlan_vid'])
203
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400204 def add_hsia_flow(self, intf_id, onu_id, priority, uplink_classifier, uplink_action,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000205 downlink_classifier, downlink_action, hsia_id):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000206
207 gemport_id = platform.mk_gemport_id(onu_id)
208 flow_id = platform.mk_flow_id(intf_id, onu_id, hsia_id)
209
Shad Ansarif9d2d102018-06-13 02:15:26 +0000210 self.log.debug('add upstream flow', onu_id=onu_id,
211 classifier=uplink_classifier, action=uplink_action,
212 gemport_id=gemport_id, flow_id=flow_id)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000213
214 flow = openolt_pb2.Flow(
Shad Ansarif9d2d102018-06-13 02:15:26 +0000215 onu_id=onu_id, flow_id=flow_id, flow_type="upstream",
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400216 access_intf_id=intf_id, gemport_id=gemport_id, priority=priority,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000217 classifier=self.mk_classifier(uplink_classifier),
218 action=self.mk_action(uplink_action))
Shad Ansari2dda4f32018-05-17 07:16:07 +0000219
220 self.stub.FlowAdd(flow)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000221
Shad Ansarie048aaa2018-05-18 18:27:21 +0000222 self.log.debug('add downstream flow', classifier=downlink_classifier,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000223 action=downlink_action, gemport_id=gemport_id,
224 flow_id=flow_id)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000225
226 flow = openolt_pb2.Flow(
227 onu_id=onu_id, flow_id=flow_id, flow_type="downstream",
228 access_intf_id=intf_id, gemport_id=gemport_id,
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400229 priority=priority,
Shad Ansari2dda4f32018-05-17 07:16:07 +0000230 classifier=self.mk_classifier(downlink_classifier),
231 action=self.mk_action(downlink_action))
232
233 self.stub.FlowAdd(flow)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000234
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400235 def add_dhcp_trap(self, intf_id, onu_id, priority, classifier, action):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000236
Shad Ansarie048aaa2018-05-18 18:27:21 +0000237 self.log.debug('add dhcp trap', classifier=classifier, action=action)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000238
239 action.clear()
240 action['trap_to_host'] = True
241 classifier['pkt_tag_type'] = 'single_tag'
242 classifier.pop('vlan_vid', None)
243
244 gemport_id = platform.mk_gemport_id(onu_id)
245 flow_id = platform.mk_flow_id(intf_id, onu_id, DHCP_FLOW_INDEX)
246
247 upstream_flow = openolt_pb2.Flow(
Shad Ansarif9d2d102018-06-13 02:15:26 +0000248 onu_id=onu_id, flow_id=flow_id, flow_type="upstream",
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400249 access_intf_id=intf_id, gemport_id=gemport_id, priority=priority,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000250 classifier=self.mk_classifier(classifier),
251 action=self.mk_action(action))
Shad Ansari2dda4f32018-05-17 07:16:07 +0000252
253 self.stub.FlowAdd(upstream_flow)
254
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400255 def add_eapol_flow(self, intf_id, onu_id, priority,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000256 uplink_eapol_id=EAPOL_FLOW_INDEX,
257 downlink_eapol_id=EAPOL_DOWNLINK_FLOW_INDEX,
258 vlan_id=DEFAULT_MGMT_VLAN):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000259
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400260 # self.log.debug('add eapol flow pre-process',
261 # classifier=uplink_classifier)
262 # #action=uplink_action)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000263
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400264 downlink_classifier = {}
265 downlink_classifier['eth_type'] = EAP_ETH_TYPE
266 downlink_classifier['pkt_tag_type'] = 'single_tag'
267 downlink_classifier['vlan_vid'] = vlan_id
Shad Ansari2dda4f32018-05-17 07:16:07 +0000268
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400269 downlink_action = {}
270 downlink_action['push_vlan'] = True
271 downlink_action['vlan_vid'] = vlan_id
Shad Ansari2dda4f32018-05-17 07:16:07 +0000272
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400273 uplink_classifier = {}
274 uplink_classifier['eth_type'] = EAP_ETH_TYPE
Shad Ansari2dda4f32018-05-17 07:16:07 +0000275 uplink_classifier['pkt_tag_type'] = 'single_tag'
276 uplink_classifier['vlan_vid'] = vlan_id
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400277
278 uplink_action = {}
Shad Ansari2dda4f32018-05-17 07:16:07 +0000279 uplink_action['trap_to_host'] = True
280
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400281 gemport_id = platform.mk_gemport_id(onu_id)
282
283
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400284 # Add Upstream EAPOL Flow.
285
286 uplink_flow_id = platform.mk_flow_id(intf_id, onu_id, uplink_eapol_id)
287
Shad Ansari2dda4f32018-05-17 07:16:07 +0000288 upstream_flow = openolt_pb2.Flow(
Shad Ansarif9d2d102018-06-13 02:15:26 +0000289 onu_id=onu_id, flow_id=uplink_flow_id, flow_type="upstream",
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400290 access_intf_id=intf_id, gemport_id=gemport_id, priority=priority,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000291 classifier=self.mk_classifier(uplink_classifier),
292 action=self.mk_action(uplink_action))
Shad Ansari2dda4f32018-05-17 07:16:07 +0000293
294 self.stub.FlowAdd(upstream_flow)
295
296 # Add Downstream EAPOL Flow.
Shad Ansarif9d2d102018-06-13 02:15:26 +0000297 downlink_flow_id = platform.mk_flow_id(intf_id, onu_id,
298 downlink_eapol_id)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000299
300 downstream_flow = openolt_pb2.Flow(
Shad Ansarif9d2d102018-06-13 02:15:26 +0000301 onu_id=onu_id, flow_id=downlink_flow_id, flow_type="downstream",
302 access_intf_id=intf_id, gemport_id=gemport_id,
303 classifier=self.mk_classifier(downlink_classifier),
304 action=self.mk_action(downlink_action))
Shad Ansari2dda4f32018-05-17 07:16:07 +0000305
306 self.stub.FlowAdd(downstream_flow)
307
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400308 self.log.debug('eap flows', upstream_flow=upstream_flow,
309 downstream_flow=downstream_flow)
310
Shad Ansari2dda4f32018-05-17 07:16:07 +0000311 def mk_classifier(self, classifier_info):
312
313 classifier = openolt_pb2.Classifier()
314
315 if 'eth_type' in classifier_info:
316 classifier.eth_type = classifier_info['eth_type']
317 if 'ip_proto' in classifier_info:
318 classifier.ip_proto = classifier_info['ip_proto']
319 if 'vlan_vid' in classifier_info:
320 classifier.o_vid = classifier_info['vlan_vid']
321 if 'metadata' in classifier_info:
322 classifier.i_vid = classifier_info['metadata']
323 if 'vlan_pcp' in classifier_info:
324 classifier.o_pbits = classifier_info['vlan_pcp']
325 if 'udp_src' in classifier_info:
326 classifier.src_port = classifier_info['udp_src']
327 if 'udp_dst' in classifier_info:
328 classifier.dst_port = classifier_info['udp_dst']
329 if 'ipv4_dst' in classifier_info:
330 classifier.dst_ip = classifier_info['ipv4_dst']
331 if 'ipv4_src' in classifier_info:
332 classifier.src_ip = classifier_info['ipv4_src']
333 if 'pkt_tag_type' in classifier_info:
334 if classifier_info['pkt_tag_type'] == 'single_tag':
335 classifier.pkt_tag_type = 'single_tag'
336 elif classifier_info['pkt_tag_type'] == 'double_tag':
337 classifier.pkt_tag_type = 'double_tag'
338 elif classifier_info['pkt_tag_type'] == 'untagged':
339 classifier.pkt_tag_type = 'untagged'
340 else:
341 classifier.pkt_tag_type = 'none'
342
343 return classifier
344
345 def mk_action(self, action_info):
346 action = openolt_pb2.Action()
347
Shad Ansarif9d2d102018-06-13 02:15:26 +0000348 if 'pop_vlan' in action_info:
349 action.o_vid = action_info['vlan_vid']
Shad Ansari2dda4f32018-05-17 07:16:07 +0000350 action.cmd.remove_outer_tag = True
Shad Ansarif9d2d102018-06-13 02:15:26 +0000351 elif 'push_vlan' in action_info:
352 action.o_vid = action_info['vlan_vid']
Shad Ansari2dda4f32018-05-17 07:16:07 +0000353 action.cmd.add_outer_tag = True
Shad Ansarif9d2d102018-06-13 02:15:26 +0000354 elif 'trap_to_host' in action_info:
Shad Ansari2dda4f32018-05-17 07:16:07 +0000355 action.cmd.trap_to_host = True
Shad Ansarif9d2d102018-06-13 02:15:26 +0000356 else:
357 self.log.info('Invalid-action-field')
358 return
Shad Ansari2dda4f32018-05-17 07:16:07 +0000359 return action
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400360
361 def is_eap_enabled(self, intf_id, onu_id):
362 flows = self.flow_proxy.get('/').items
363
364 for flow in flows:
365 eap_flow = False
366 eap_intf_id = None
367 eap_onu_id = None
368 for field in fd.get_ofb_fields(flow):
369 if field.type == fd.ETH_TYPE:
370 if field.eth_type == EAP_ETH_TYPE:
371 eap_flow = True
372 if field.type == fd.IN_PORT:
373 eap_intf_id = platform.intf_id_from_uni_port_num(field.port)
374 eap_onu_id = platform.onu_id_from_port_num(field.port)
375
376 if eap_flow:
377 self.log.debug('eap flow detected', onu_id=onu_id,
378 intf_id=intf_id, eap_intf_id=eap_intf_id,
379 eap_onu_id=eap_onu_id)
380 if eap_flow and intf_id == eap_intf_id and onu_id == eap_onu_id:
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400381 return (True, flow.priority)
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400382
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400383 return (False, 0)