blob: 2d6aafbcc82ec6e39d72dc8b67b96646e33576b7 [file] [log] [blame]
Zsolt Haraszti66862032016-11-28 14:28:39 -08001#
Zsolt Haraszti3eb27a52017-01-03 21:56:48 -08002# Copyright 2017 the original author or authors.
Zsolt Haraszti66862032016-11-28 14:28:39 -08003#
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
17"""
18A mix-in class implementing flow decomposition
19"""
20from collections import OrderedDict
21from copy import copy, deepcopy
22from hashlib import md5
23
Zsolt Harasztiee5c4c82017-01-09 14:37:57 -080024import structlog
25
Zsolt Haraszti3578a1c2017-01-10 15:29:02 -080026from voltha.protos import third_party
Zsolt Haraszti66862032016-11-28 14:28:39 -080027from voltha.protos import openflow_13_pb2 as ofp
28
Zsolt Haraszti3578a1c2017-01-10 15:29:02 -080029_ = third_party
Zsolt Harasztiee5c4c82017-01-09 14:37:57 -080030log = structlog.get_logger()
31
32
Zsolt Haraszti66862032016-11-28 14:28:39 -080033# aliases
34ofb_field = ofp.ofp_oxm_ofb_field
35action = ofp.ofp_action
36
37# OFPAT_* shortcuts
38OUTPUT = ofp.OFPAT_OUTPUT
39COPY_TTL_OUT = ofp.OFPAT_COPY_TTL_OUT
40COPY_TTL_IN = ofp.OFPAT_COPY_TTL_IN
41SET_MPLS_TTL = ofp.OFPAT_SET_MPLS_TTL
42DEC_MPLS_TTL = ofp.OFPAT_DEC_MPLS_TTL
43PUSH_VLAN = ofp.OFPAT_PUSH_VLAN
44POP_VLAN = ofp.OFPAT_POP_VLAN
45PUSH_MPLS = ofp.OFPAT_PUSH_MPLS
46POP_MPLS = ofp.OFPAT_POP_MPLS
47SET_QUEUE = ofp.OFPAT_SET_QUEUE
48GROUP = ofp.OFPAT_GROUP
49SET_NW_TTL = ofp.OFPAT_SET_NW_TTL
50NW_TTL = ofp.OFPAT_DEC_NW_TTL
51SET_FIELD = ofp.OFPAT_SET_FIELD
52PUSH_PBB = ofp.OFPAT_PUSH_PBB
53POP_PBB = ofp.OFPAT_POP_PBB
54EXPERIMENTER = ofp.OFPAT_EXPERIMENTER
55
56# OFPXMT_OFB_* shortcuts (incomplete)
57IN_PORT = ofp.OFPXMT_OFB_IN_PORT
58IN_PHY_PORT = ofp.OFPXMT_OFB_IN_PHY_PORT
59METADATA = ofp.OFPXMT_OFB_METADATA
60ETH_DST = ofp.OFPXMT_OFB_ETH_DST
61ETH_SRC = ofp.OFPXMT_OFB_ETH_SRC
62ETH_TYPE = ofp.OFPXMT_OFB_ETH_TYPE
63VLAN_VID = ofp.OFPXMT_OFB_VLAN_VID
64VLAN_PCP = ofp.OFPXMT_OFB_VLAN_PCP
65IP_DSCP = ofp.OFPXMT_OFB_IP_DSCP
66IP_ECN = ofp.OFPXMT_OFB_IP_ECN
67IP_PROTO = ofp.OFPXMT_OFB_IP_PROTO
68IPV4_SRC = ofp.OFPXMT_OFB_IPV4_SRC
69IPV4_DST = ofp.OFPXMT_OFB_IPV4_DST
70TCP_SRC = ofp.OFPXMT_OFB_TCP_SRC
71TCP_DST = ofp.OFPXMT_OFB_TCP_DST
72UDP_SRC = ofp.OFPXMT_OFB_UDP_SRC
73UDP_DST = ofp.OFPXMT_OFB_UDP_DST
74SCTP_SRC = ofp.OFPXMT_OFB_SCTP_SRC
75SCTP_DST = ofp.OFPXMT_OFB_SCTP_DST
76ICMPV4_TYPE = ofp.OFPXMT_OFB_ICMPV4_TYPE
77ICMPV4_CODE = ofp.OFPXMT_OFB_ICMPV4_CODE
78ARP_OP = ofp.OFPXMT_OFB_ARP_OP
79ARP_SPA = ofp.OFPXMT_OFB_ARP_SPA
80ARP_TPA = ofp.OFPXMT_OFB_ARP_TPA
81ARP_SHA = ofp.OFPXMT_OFB_ARP_SHA
82ARP_THA = ofp.OFPXMT_OFB_ARP_THA
83IPV6_SRC = ofp.OFPXMT_OFB_IPV6_SRC
84IPV6_DST = ofp.OFPXMT_OFB_IPV6_DST
85IPV6_FLABEL = ofp.OFPXMT_OFB_IPV6_FLABEL
86ICMPV6_TYPE = ofp.OFPXMT_OFB_ICMPV6_TYPE
87ICMPV6_CODE = ofp.OFPXMT_OFB_ICMPV6_CODE
88IPV6_ND_TARGET = ofp.OFPXMT_OFB_IPV6_ND_TARGET
89OFB_IPV6_ND_SLL = ofp.OFPXMT_OFB_IPV6_ND_SLL
90IPV6_ND_TLL = ofp.OFPXMT_OFB_IPV6_ND_TLL
91MPLS_LABEL = ofp.OFPXMT_OFB_MPLS_LABEL
92MPLS_TC = ofp.OFPXMT_OFB_MPLS_TC
93MPLS_BOS = ofp.OFPXMT_OFB_MPLS_BOS
94PBB_ISID = ofp.OFPXMT_OFB_PBB_ISID
95TUNNEL_ID = ofp.OFPXMT_OFB_TUNNEL_ID
96IPV6_EXTHDR = ofp.OFPXMT_OFB_IPV6_EXTHDR
97
98# ofp_action_* shortcuts
99
100def output(port, max_len=ofp.OFPCML_MAX):
101 return action(
102 type=OUTPUT,
103 output=ofp.ofp_action_output(port=port, max_len=max_len)
104 )
105
106def mpls_ttl(ttl):
107 return action(
108 type=SET_MPLS_TTL,
109 mpls_ttl=ofp.ofp_action_mpls_ttl(mpls_ttl=ttl)
110 )
111
112def push_vlan(eth_type):
113 return action(
114 type=PUSH_VLAN,
115 push=ofp.ofp_action_push(ethertype=eth_type)
116 )
117
118def pop_vlan():
119 return action(
120 type=POP_VLAN
121 )
122
123def pop_mpls(eth_type):
124 return action(
125 type=POP_MPLS,
126 pop_mpls=ofp.ofp_action_pop_mpls(ethertype=eth_type)
127 )
128
129def group(group_id):
130 return action(
131 type=GROUP,
132 group=ofp.ofp_action_group(group_id=group_id)
133 )
134
135def nw_ttl(nw_ttl):
136 return action(
137 type=NW_TTL,
138 nw_ttl=ofp.ofp_action_nw_ttl(nw_ttl=nw_ttl)
139 )
140
141def set_field(field):
142 return action(
143 type=SET_FIELD,
144 set_field=ofp.ofp_action_set_field(
145 field=ofp.ofp_oxm_field(
146 oxm_class=ofp.OFPXMC_OPENFLOW_BASIC,
147 ofb_field=field))
148 )
149
150def experimenter(experimenter, data):
151 return action(
152 type=EXPERIMENTER,
153 experimenter=ofp.ofp_action_experimenter(
154 experimenter=experimenter, data=data)
155 )
156
157
158# ofb_field generators (incomplete set)
159
160def in_port(_in_port):
161 return ofb_field(type=IN_PORT, port=_in_port)
162
163def eth_type(_eth_type):
164 return ofb_field(type=ETH_TYPE, eth_type=_eth_type)
165
166def vlan_vid(_vlan_vid):
167 return ofb_field(type=VLAN_VID, vlan_vid=_vlan_vid)
168
169def vlan_pcp(_vlan_pcp):
170 return ofb_field(type=VLAN_PCP, vlan_pcp=_vlan_pcp)
171
172def ip_dscp(_ip_dscp):
173 return ofb_field(type=IP_DSCP, ip_dscp=_ip_dscp)
174
175def ip_ecn(_ip_ecn):
176 return ofb_field(type=IP_ECN, ip_ecn=_ip_ecn)
177
178def ip_proto(_ip_proto):
179 return ofb_field(type=IP_PROTO, ip_proto=_ip_proto)
180
181def ipv4_src(_ipv4_src):
182 return ofb_field(type=IPV4_SRC, ipv4_src=_ipv4_src)
183
184def ipv4_dst(_ipv4_dst):
185 return ofb_field(type=IPV4_DST, ipv4_dst=_ipv4_dst)
186
187def tcp_src(_tcp_src):
188 return ofb_field(type=TCP_SRC, tcp_src=_tcp_src)
189
190def tcp_dst(_tcp_dst):
191 return ofb_field(type=TCP_DST, tcp_dst=_tcp_dst)
192
193def udp_src(_udp_src):
194 return ofb_field(type=UDP_SRC, udp_src=_udp_src)
195
196def udp_dst(_udp_dst):
197 return ofb_field(type=UDP_DST, udp_dst=_udp_dst)
198
199def sctp_src(_sctp_src):
200 return ofb_field(type=SCTP_SRC, sctp_src=_sctp_src)
201
202def sctp_dst(_sctp_dst):
203 return ofb_field(type=SCTP_DST, sctp_dst=_sctp_dst)
204
205def icmpv4_type(_icmpv4_type):
206 return ofb_field(type=ICMPV4_TYPE, icmpv4_type=_icmpv4_type)
207
208def icmpv4_code(_icmpv4_code):
209 return ofb_field(type=ICMPV4_CODE, icmpv4_code=_icmpv4_code)
210
211def arp_op(_arp_op):
212 return ofb_field(type=ARP_OP, arp_op=_arp_op)
213
214def arp_spa(_arp_spa):
215 return ofb_field(type=ARP_SPA, arp_spa=_arp_spa)
216
217def arp_tpa(_arp_tpa):
218 return ofb_field(type=ARP_TPA, arp_tpa=_arp_tpa)
219
220def arp_sha(_arp_sha):
221 return ofb_field(type=ARP_SHA, arp_sha=_arp_sha)
222
223def arp_tha(_arp_tha):
224 return ofb_field(type=ARP_THA, arp_tha=_arp_tha)
225
Zsolt Haraszti6a5107c2017-01-09 23:42:41 -0800226def metadata(_table_metadata):
227 return ofb_field(type=METADATA, table_metadata=_table_metadata)
228
229
Zsolt Haraszti66862032016-11-28 14:28:39 -0800230# TODO finish for rest of match fields
231
232
233# frequently used extractors:
234
235def get_actions(flow):
236 """Extract list of ofp_action objects from flow spec object"""
237 assert isinstance(flow, ofp.ofp_flow_stats)
238 # we have the following hard assumptions for now
239 for instruction in flow.instructions:
240 if instruction.type == ofp.OFPIT_APPLY_ACTIONS:
241 return instruction.actions.actions
242
243def get_ofb_fields(flow):
244 assert isinstance(flow, ofp.ofp_flow_stats)
245 assert flow.match.type == ofp.OFPMT_OXM
246 ofb_fields = []
247 for field in flow.match.oxm_fields:
248 assert field.oxm_class == ofp.OFPXMC_OPENFLOW_BASIC
249 ofb_fields.append(field.ofb_field)
250 return ofb_fields
251
252def get_out_port(flow):
253 for action in get_actions(flow):
254 if action.type == OUTPUT:
255 return action.output.port
256 return None
257
258def get_in_port(flow):
259 for field in get_ofb_fields(flow):
260 if field.type == IN_PORT:
261 return field.port
262 return None
263
264def get_goto_table_id(flow):
265 for instruction in flow.instructions:
266 if instruction.type == ofp.OFPIT_GOTO_TABLE:
267 return instruction.goto_table.table_id
268 return None
269
270
271# test and extract next table and group information
272
273def has_next_table(flow):
274 return get_goto_table_id(flow) is not None
275
276def get_group(flow):
277 for action in get_actions(flow):
278 if action.type == GROUP:
279 return action.group.group_id
280 return None
281
282def has_group(flow):
283 return get_group(flow) is not None
284
285
286def mk_simple_flow_mod(match_fields, actions, command=ofp.OFPFC_ADD,
287 next_table_id=None, **kw):
288 """
289 Convenience function to generare ofp_flow_mod message with OXM BASIC match
290 composed from the match_fields, and single APPLY_ACTIONS instruction with
291 a list if ofp_action objects.
292 :param match_fields: list(ofp_oxm_ofb_field)
293 :param actions: list(ofp_action)
294 :param command: one of OFPFC_*
295 :param kw: additional keyword-based params to ofp_flow_mod
296 :return: initialized ofp_flow_mod object
297 """
298 instructions = [
299 ofp.ofp_instruction(
300 type=ofp.OFPIT_APPLY_ACTIONS,
301 actions=ofp.ofp_instruction_actions(actions=actions)
302 )
303 ]
304 if next_table_id is not None:
305 instructions.append(ofp.ofp_instruction(
306 type=ofp.OFPIT_GOTO_TABLE,
307 goto_table=ofp.ofp_instruction_goto_table(table_id=next_table_id)
308 ))
309
310 return ofp.ofp_flow_mod(
311 command=command,
312 match=ofp.ofp_match(
313 type=ofp.OFPMT_OXM,
314 oxm_fields=[
315 ofp.ofp_oxm_field(
316 oxm_class=ofp.OFPXMC_OPENFLOW_BASIC,
317 ofb_field=field
318 ) for field in match_fields
319 ]
320 ),
321 instructions=instructions,
322 **kw
323 )
324
325
326def mk_multicast_group_mod(group_id, buckets, command=ofp.OFPGC_ADD):
327 group = ofp.ofp_group_mod(
328 command=command,
329 type=ofp.OFPGT_ALL,
330 group_id=group_id,
331 buckets=buckets
332 )
333 return group
334
335
336def hash_flow_stats(flow):
337 """
338 Return unique 64-bit integer hash for flow covering the following
339 attributes: 'table_id', 'priority', 'flags', 'cookie', 'match'
340 """
341 hex = md5('{},{},{},{},{}'.format(
342 flow.table_id,
343 flow.priority,
344 flow.flags,
345 flow.cookie,
346 flow.match.SerializeToString()
347 )).hexdigest()
348 return int(hex[:16], 16)
349
350
351def flow_stats_entry_from_flow_mod_message(mod):
352 flow = ofp.ofp_flow_stats(
353 table_id=mod.table_id,
354 priority=mod.priority,
355 idle_timeout=mod.idle_timeout,
356 hard_timeout=mod.hard_timeout,
357 flags=mod.flags,
358 cookie=mod.cookie,
359 match=mod.match,
360 instructions=mod.instructions
361 )
362 flow.id = hash_flow_stats(flow)
363 return flow
364
365
366def group_entry_from_group_mod(mod):
367 group = ofp.ofp_group_entry(
368 desc=ofp.ofp_group_desc(
369 type=mod.type,
370 group_id=mod.group_id,
371 buckets=mod.buckets
372 ),
373 stats=ofp.ofp_group_stats(
374 group_id=mod.group_id
375 # TODO do we need to instantiate bucket bins?
376 )
377 )
378 return group
379
380
381def mk_flow_stat(**kw):
382 return flow_stats_entry_from_flow_mod_message(mk_simple_flow_mod(**kw))
383
384
385def mk_group_stat(**kw):
386 return group_entry_from_group_mod(mk_multicast_group_mod(**kw))
387
388class RouteHop(object):
389 __slots__ = ('_device', '_ingress_port', '_egress_port')
390 def __init__(self, device, ingress_port, egress_port):
391 self._device = device
392 self._ingress_port = ingress_port
393 self._egress_port = egress_port
394 @property
395 def device(self): return self._device
396 @property
397 def ingress_port(self): return self._ingress_port
398 @property
399 def egress_port(self): return self._egress_port
400 def __eq__(self, other):
401 return (
402 self._device == other._device and
403 self._ingress_port == other._ingress_port and
404 self._egress_port == other._egress_port)
405
406
407class FlowDecomposer(object):
408
409 def __init__(self, *args, **kw):
410 self.logical_device_id = 'this shall be overwritten in derived class'
411 super(FlowDecomposer, self).__init__(*args, **kw)
412
413 # ~~~~~~~~~~~~~~~~~~~~ methods exposed *to* derived class ~~~~~~~~~~~~~~~~~
414
415 def decompose_rules(self, flows, groups):
416 """
417 Generate per-device flows and flow-groups from the flows and groups
418 defined on a logical device
419 :param flows: logical device flows
420 :param groups: logical device flow groups
421 :return: dict(device_id ->
422 (OrderedDict-of-device-flows, OrderedDict-of-device-flow-groups))
423 """
424
425 device_rules = deepcopy(self.get_all_default_rules())
426 group_map = dict((g.desc.group_id, g) for g in groups)
427
428 for flow in flows:
429 for device_id, (_flows, _groups) \
430 in self.decompose_flow(flow, group_map).iteritems():
431 fl_lst, gr_lst = device_rules.setdefault(
432 device_id, (OrderedDict(), OrderedDict()))
433 for _flow in _flows:
434 if _flow.id not in fl_lst:
435 fl_lst[_flow.id] = _flow
436 for _group in _groups:
437 if _group.group_id not in gr_lst:
438 gr_lst[_group.group_id] = _group
439 return device_rules
440
441 def decompose_flow(self, flow, group_map):
442 assert isinstance(flow, ofp.ofp_flow_stats)
443
444 ####################################################################
445 #
446 # TODO this is a very limited, heuristics based implementation
447 #
448 ####################################################################
449
450 in_port_no = get_in_port(flow)
451 out_port_no = get_out_port(flow) # may be None
452
Zsolt Harasztiee5c4c82017-01-09 14:37:57 -0800453 device_rules = {} # accumulator
454
Zsolt Haraszti66862032016-11-28 14:28:39 -0800455 route = self.get_route(in_port_no, out_port_no)
Zsolt Harasztiee5c4c82017-01-09 14:37:57 -0800456 if route is None:
457 log.error('no-route', in_port_no=in_port_no,
458 out_port_no=out_port_no, comment='ignoring flow')
459 return device_rules
Zsolt Haraszti66862032016-11-28 14:28:39 -0800460
461 assert len(route) == 2
462 ingress_hop, egress_hop = route
463
464 def is_downstream():
465 return ingress_hop.device.root
466
467 def is_upstream():
468 return not is_downstream()
469
Zsolt Haraszti91730da2016-12-12 12:54:38 -0800470 if out_port_no is not None and \
471 (out_port_no & 0x7fffffff) == ofp.OFPP_CONTROLLER:
Zsolt Haraszti66862032016-11-28 14:28:39 -0800472
473 # UPSTREAM CONTROLLER-BOUND FLOW
474
475 # we assume that the ingress device is already pushing a
476 # customer-specific vlan (c-vid), based on its default flow
477 # rules so there is nothing else to do on the ONU
478
479 # on the olt, we need to push a new tag and set it to 4000
480 # which for now represents in-bound channel to the controller
481 # (via Voltha)
482 # TODO make the 4000 configurable
483 fl_lst, _ = device_rules.setdefault(
484 egress_hop.device.id, ([], []))
485 fl_lst.append(mk_flow_stat(
486 priority=flow.priority,
487 cookie=flow.cookie,
488 match_fields=[
489 in_port(egress_hop.ingress_port.port_no)
490 ] + [
491 field for field in get_ofb_fields(flow)
492 if field.type not in (IN_PORT, VLAN_VID)
493 ],
494 actions=[
495 push_vlan(0x8100),
496 set_field(vlan_vid(ofp.OFPVID_PRESENT | 4000)),
497 output(egress_hop.egress_port.port_no)]
498 ))
499
500 else:
501 # NOT A CONTROLLER-BOUND FLOW
502 if is_upstream():
503
504 # We assume that anything that is upstream needs to get Q-in-Q
505 # treatment and that this is expressed via two flow rules,
506 # the first using the goto-statement. We also assume that the
507 # inner tag is applied at the ONU, while the outer tag is
508 # applied at the OLT
509 if has_next_table(flow):
510 assert out_port_no is None
511 fl_lst, _ = device_rules.setdefault(
512 ingress_hop.device.id, ([], []))
513 fl_lst.append(mk_flow_stat(
514 priority=flow.priority,
515 cookie=flow.cookie,
516 match_fields=[
517 in_port(ingress_hop.ingress_port.port_no)
518 ] + [
519 field for field in get_ofb_fields(flow)
520 if field.type not in (IN_PORT,)
521 ],
522 actions=[
523 action for action in get_actions(flow)
524 ] + [
525 output(ingress_hop.egress_port.port_no)
526 ]
527 ))
528
529 else:
530 assert out_port_no is not None
531 fl_lst, _ = device_rules.setdefault(
532 egress_hop.device.id, ([], []))
533 fl_lst.append(mk_flow_stat(
534 priority=flow.priority,
535 cookie=flow.cookie,
536 match_fields=[
537 in_port(egress_hop.ingress_port.port_no),
538 ] + [
539 field for field in get_ofb_fields(flow)
540 if field.type not in (IN_PORT, )
541 ],
542 actions=[
543 action for action in get_actions(flow)
544 if action.type != OUTPUT
545 ] + [
546 output(egress_hop.egress_port.port_no)
547 ]
548 ))
549
550 else: # downstream
551 if has_next_table(flow):
552 assert out_port_no is None
553 fl_lst, _ = device_rules.setdefault(
554 ingress_hop.device.id, ([], []))
555 fl_lst.append(mk_flow_stat(
556 priority=flow.priority,
557 cookie=flow.cookie,
558 match_fields=[
559 in_port(ingress_hop.ingress_port.port_no)
560 ] + [
561 field for field in get_ofb_fields(flow)
562 if field.type not in (IN_PORT,)
563 ],
564 actions=[
565 action for action in get_actions(flow)
566 ] + [
567 output(ingress_hop.egress_port.port_no)
568 ]
569 ))
570 elif out_port_no is not None: # unicast case
571 fl_lst, _ = device_rules.setdefault(
572 egress_hop.device.id, ([], []))
573 fl_lst.append(mk_flow_stat(
574 priority=flow.priority,
575 cookie=flow.cookie,
576 match_fields=[
577 in_port(egress_hop.ingress_port.port_no)
578 ] + [
579 field for field in get_ofb_fields(flow)
580 if field.type not in (IN_PORT,)
581 ],
582 actions=[
583 action for action in get_actions(flow)
584 if action.type not in (OUTPUT,)
585 ] + [
586 output(egress_hop.egress_port.port_no)
587 ]
588
589 ))
590
591 else: # multicast case
592 grp_id = get_group(flow)
593 assert grp_id is not None
594
595 fl_lst, _ = device_rules.setdefault(
596 ingress_hop.device.id, ([], []))
597 fl_lst.append(mk_flow_stat(
598 priority=flow.priority,
599 cookie=flow.cookie,
600 match_fields=[
601 in_port(ingress_hop.ingress_port.port_no)
602 ] + [
603 field for field in get_ofb_fields(flow)
604 if field.type not in (IN_PORT, ETH_TYPE, IPV4_DST)
605 ],
606 actions=[
607 action for action in get_actions(flow)
608 if action.type not in (GROUP,)
609 ] + [
610 pop_vlan(),
611 output(ingress_hop.egress_port.port_no)
612 ]
613 ))
614
Zsolt Haraszti50de7c42016-12-13 15:39:07 -0800615 # having no group yet is the same as having a group with
616 # no buckets
617 group = group_map.get(grp_id, ofp.ofp_group_entry())
618
Zsolt Haraszti66862032016-11-28 14:28:39 -0800619 for bucket in group.desc.buckets:
620 found_pop_vlan = False
621 other_actions = []
622 for action in bucket.actions:
623 if action.type == POP_VLAN:
624 found_pop_vlan = True
625 elif action.type == OUTPUT:
626 out_port_no = action.output.port
627 else:
628 other_actions.append(action)
629 # re-run route request to determine egress device and
630 # ports
631 route2 = self.get_route(in_port_no, out_port_no)
632
633 assert len(route2) == 2
634 ingress_hop2, egress_hop = route2
635 assert ingress_hop == ingress_hop2
636
637 fl_lst, _ = device_rules.setdefault(
638 egress_hop.device.id, ([], []))
639 fl_lst.append(mk_flow_stat(
640 priority=flow.priority,
641 cookie=flow.cookie,
642 match_fields=[
643 in_port(egress_hop.ingress_port.port_no)
644 ] + [
645 field for field in get_ofb_fields(flow)
646 if field.type not in (IN_PORT, VLAN_VID, VLAN_PCP)
647 ],
648 actions=other_actions + [
649 output(egress_hop.egress_port.port_no)
650 ]
651 ))
652
653 return device_rules
654
655 # ~~~~~~~~~~~~ methods expected to be provided by derived class ~~~~~~~~~~~
656
657 def get_all_default_rules(self):
658 raise NotImplementedError('derived class must provide')
659
660 def get_default_rules(self, device_id):
661 raise NotImplementedError('derived class must provide')
662
663 def get_route(self, ingress_port_no, egress_port_no):
664 raise NotImplementedError('derived class must provide')
665
666