2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.protocol_plugin.openflow.internal;
11 import java.math.BigInteger;
12 import java.net.InetAddress;
13 import java.net.UnknownHostException;
14 import java.util.ArrayList;
15 import java.util.List;
17 import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6FlowMod;
18 import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match;
19 import org.openflow.protocol.OFFlowMod;
20 import org.openflow.protocol.OFMatch;
21 import org.openflow.protocol.OFMessage;
22 import org.openflow.protocol.OFPacketOut;
23 import org.openflow.protocol.OFPort;
24 import org.openflow.protocol.OFVendor;
25 import org.openflow.protocol.action.OFAction;
26 import org.openflow.protocol.action.OFActionDataLayerDestination;
27 import org.openflow.protocol.action.OFActionDataLayerSource;
28 import org.openflow.protocol.action.OFActionNetworkLayerAddress;
29 import org.openflow.protocol.action.OFActionNetworkLayerDestination;
30 import org.openflow.protocol.action.OFActionNetworkLayerSource;
31 import org.openflow.protocol.action.OFActionNetworkTypeOfService;
32 import org.openflow.protocol.action.OFActionOutput;
33 import org.openflow.protocol.action.OFActionStripVirtualLan;
34 import org.openflow.protocol.action.OFActionTransportLayer;
35 import org.openflow.protocol.action.OFActionTransportLayerDestination;
36 import org.openflow.protocol.action.OFActionTransportLayerSource;
37 import org.openflow.protocol.action.OFActionVirtualLanIdentifier;
38 import org.openflow.protocol.action.OFActionVirtualLanPriorityCodePoint;
39 import org.openflow.util.U16;
40 import org.openflow.util.U32;
42 import org.opendaylight.controller.sal.action.Action;
43 import org.opendaylight.controller.sal.action.ActionType;
44 import org.opendaylight.controller.sal.action.Controller;
45 import org.opendaylight.controller.sal.action.Drop;
46 import org.opendaylight.controller.sal.action.Flood;
47 import org.opendaylight.controller.sal.action.FloodAll;
48 import org.opendaylight.controller.sal.action.HwPath;
49 import org.opendaylight.controller.sal.action.Loopback;
50 import org.opendaylight.controller.sal.action.Output;
51 import org.opendaylight.controller.sal.action.PopVlan;
52 import org.opendaylight.controller.sal.action.SetDlDst;
53 import org.opendaylight.controller.sal.action.SetDlSrc;
54 import org.opendaylight.controller.sal.action.SetNwDst;
55 import org.opendaylight.controller.sal.action.SetNwSrc;
56 import org.opendaylight.controller.sal.action.SetNwTos;
57 import org.opendaylight.controller.sal.action.SetTpDst;
58 import org.opendaylight.controller.sal.action.SetTpSrc;
59 import org.opendaylight.controller.sal.action.SetVlanId;
60 import org.opendaylight.controller.sal.action.SetVlanPcp;
61 import org.opendaylight.controller.sal.action.SwPath;
62 import org.opendaylight.controller.sal.core.Node;
63 import org.opendaylight.controller.sal.core.NodeConnector;
64 import org.opendaylight.controller.sal.flowprogrammer.Flow;
65 import org.opendaylight.controller.sal.match.Match;
66 import org.opendaylight.controller.sal.match.MatchField;
67 import org.opendaylight.controller.sal.match.MatchType;
68 import org.opendaylight.controller.sal.utils.NetUtils;
69 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
70 import org.slf4j.Logger;
71 import org.slf4j.LoggerFactory;
74 * Utility class for converting a SAL Flow into the OF flow and vice-versa
76 public class FlowConverter {
77 protected static final Logger logger = LoggerFactory
78 .getLogger(FlowConverter.class);
79 private Flow flow; // SAL Flow
80 private OFMatch ofMatch; // OF 1.0 match or OF 1.0 + IPv6 extension match
81 private List<OFAction> actionsList; // OF 1.0 actions
82 private int actionsLength;
83 private boolean isIPv6;
85 public FlowConverter(OFMatch ofMatch, List<OFAction> actionsList) {
86 this.ofMatch = ofMatch;
87 this.actionsList = actionsList;
88 this.actionsLength = 0;
90 this.isIPv6 = ofMatch instanceof V6Match;
93 public FlowConverter(Flow flow) {
95 this.actionsList = null;
96 this.actionsLength = 0;
98 this.isIPv6 = flow.isIPv6();
102 * Returns the match in OF 1.0 (OFMatch) form or OF 1.0 + IPv6 extensions
107 public OFMatch getOFMatch() {
108 if (ofMatch == null) {
109 Match match = flow.getMatch();
110 ofMatch = (isIPv6) ? new V6Match() : new OFMatch();
112 int wildcards = OFMatch.OFPFW_ALL;
113 if (match.isPresent(MatchType.IN_PORT)) {
114 short port = (Short) ((NodeConnector) match.getField(
115 MatchType.IN_PORT).getValue()).getID();
117 ofMatch.setInputPort(port);
118 wildcards &= ~OFMatch.OFPFW_IN_PORT;
120 ((V6Match) ofMatch).setInputPort(port, (short) 0);
123 if (match.isPresent(MatchType.DL_SRC)) {
124 byte[] srcMac = (byte[]) match.getField(MatchType.DL_SRC)
127 ofMatch.setDataLayerSource(srcMac.clone());
128 wildcards &= ~OFMatch.OFPFW_DL_SRC;
130 ((V6Match) ofMatch).setDataLayerSource(srcMac, null);
133 if (match.isPresent(MatchType.DL_DST)) {
134 byte[] dstMac = (byte[]) match.getField(MatchType.DL_DST)
137 ofMatch.setDataLayerDestination(dstMac.clone());
138 wildcards &= ~OFMatch.OFPFW_DL_DST;
140 ((V6Match) ofMatch).setDataLayerDestination(dstMac, null);
143 if (match.isPresent(MatchType.DL_VLAN)) {
144 short vlan = (Short) match.getField(MatchType.DL_VLAN)
147 ofMatch.setDataLayerVirtualLan(vlan);
148 wildcards &= ~OFMatch.OFPFW_DL_VLAN;
150 ((V6Match) ofMatch).setDataLayerVirtualLan(vlan, (short) 0);
153 if (match.isPresent(MatchType.DL_VLAN_PR)) {
154 byte vlanPr = (Byte) match.getField(MatchType.DL_VLAN_PR)
157 ofMatch.setDataLayerVirtualLanPriorityCodePoint(vlanPr);
158 wildcards &= ~OFMatch.OFPFW_DL_VLAN_PCP;
161 .setDataLayerVirtualLanPriorityCodePoint(vlanPr,
165 if (match.isPresent(MatchType.DL_TYPE)) {
166 short ethType = (Short) match.getField(MatchType.DL_TYPE)
169 ofMatch.setDataLayerType(ethType);
170 wildcards &= ~OFMatch.OFPFW_DL_TYPE;
172 ((V6Match) ofMatch).setDataLayerType(ethType, (short) 0);
175 if (match.isPresent(MatchType.NW_TOS)) {
177 * OF 1.0 switch expects the TOS as the 6 msb in the byte. it is
178 * actually the DSCP field followed by a zero ECN
180 byte tos = (Byte) match.getField(MatchType.NW_TOS).getValue();
181 byte dscp = (byte) ((int) tos << 2);
183 ofMatch.setNetworkTypeOfService(dscp);
184 wildcards &= ~OFMatch.OFPFW_NW_TOS;
186 ((V6Match) ofMatch).setNetworkTypeOfService(dscp, (byte) 0);
189 if (match.isPresent(MatchType.NW_PROTO)) {
190 byte proto = (Byte) match.getField(MatchType.NW_PROTO)
193 ofMatch.setNetworkProtocol(proto);
194 wildcards &= ~OFMatch.OFPFW_NW_PROTO;
196 ((V6Match) ofMatch).setNetworkProtocol(proto, (byte) 0);
199 if (match.isPresent(MatchType.NW_SRC)) {
200 InetAddress address = (InetAddress) match.getField(
201 MatchType.NW_SRC).getValue();
202 InetAddress mask = (InetAddress) match.getField(
203 MatchType.NW_SRC).getMask();
205 ofMatch.setNetworkSource(NetUtils.byteArray4ToInt(address
207 int maskLength = NetUtils
208 .getSubnetMaskLength((mask == null) ? null : mask
210 wildcards = (wildcards & ~OFMatch.OFPFW_NW_SRC_MASK)
211 | (maskLength << OFMatch.OFPFW_NW_SRC_SHIFT);
213 ((V6Match) ofMatch).setNetworkSource(address, mask);
216 if (match.isPresent(MatchType.NW_DST)) {
217 InetAddress address = (InetAddress) match.getField(
218 MatchType.NW_DST).getValue();
219 InetAddress mask = (InetAddress) match.getField(
220 MatchType.NW_DST).getMask();
222 ofMatch.setNetworkDestination(NetUtils
223 .byteArray4ToInt(address.getAddress()));
224 int maskLength = NetUtils
225 .getSubnetMaskLength((mask == null) ? null : mask
227 wildcards = (wildcards & ~OFMatch.OFPFW_NW_DST_MASK)
228 | (maskLength << OFMatch.OFPFW_NW_DST_SHIFT);
230 ((V6Match) ofMatch).setNetworkDestination(address, mask);
233 if (match.isPresent(MatchType.TP_SRC)) {
234 short port = (Short) match.getField(MatchType.TP_SRC)
237 ofMatch.setTransportSource(port);
238 wildcards &= ~OFMatch.OFPFW_TP_SRC;
240 ((V6Match) ofMatch).setTransportSource(port, (short) 0);
243 if (match.isPresent(MatchType.TP_DST)) {
244 short port = (Short) match.getField(MatchType.TP_DST)
247 ofMatch.setTransportDestination(port);
248 wildcards &= ~OFMatch.OFPFW_TP_DST;
251 .setTransportDestination(port, (short) 0);
256 ofMatch.setWildcards(U32.t(Long.valueOf(wildcards)));
264 * Returns the list of actions in OF 1.0 form
268 public List<OFAction> getOFActions() {
269 if (this.actionsList == null) {
270 actionsList = new ArrayList<OFAction>();
271 for (Action action : flow.getActions()) {
272 if (action.getType() == ActionType.OUTPUT) {
273 Output a = (Output) action;
274 OFActionOutput ofAction = new OFActionOutput();
275 ofAction.setMaxLength((short) 0xffff);
276 ofAction.setPort(PortConverter.toOFPort(a.getPort()));
277 actionsList.add(ofAction);
278 actionsLength += OFActionOutput.MINIMUM_LENGTH;
281 if (action.getType() == ActionType.DROP) {
284 if (action.getType() == ActionType.LOOPBACK) {
285 OFActionOutput ofAction = new OFActionOutput();
286 ofAction.setPort(OFPort.OFPP_IN_PORT.getValue());
287 actionsList.add(ofAction);
288 actionsLength += OFActionOutput.MINIMUM_LENGTH;
291 if (action.getType() == ActionType.FLOOD) {
292 OFActionOutput ofAction = new OFActionOutput();
293 ofAction.setPort(OFPort.OFPP_FLOOD.getValue());
294 actionsList.add(ofAction);
295 actionsLength += OFActionOutput.MINIMUM_LENGTH;
298 if (action.getType() == ActionType.FLOOD_ALL) {
299 OFActionOutput ofAction = new OFActionOutput();
300 ofAction.setPort(OFPort.OFPP_ALL.getValue());
301 actionsList.add(ofAction);
302 actionsLength += OFActionOutput.MINIMUM_LENGTH;
305 if (action.getType() == ActionType.CONTROLLER) {
306 OFActionOutput ofAction = new OFActionOutput();
307 ofAction.setPort(OFPort.OFPP_CONTROLLER.getValue());
308 // We want the whole frame hitting the match be sent to the
310 ofAction.setMaxLength((short) 0xffff);
311 actionsList.add(ofAction);
312 actionsLength += OFActionOutput.MINIMUM_LENGTH;
315 if (action.getType() == ActionType.SW_PATH) {
316 OFActionOutput ofAction = new OFActionOutput();
317 ofAction.setPort(OFPort.OFPP_LOCAL.getValue());
318 actionsList.add(ofAction);
319 actionsLength += OFActionOutput.MINIMUM_LENGTH;
322 if (action.getType() == ActionType.HW_PATH) {
323 OFActionOutput ofAction = new OFActionOutput();
324 ofAction.setPort(OFPort.OFPP_NORMAL.getValue());
325 actionsList.add(ofAction);
326 actionsLength += OFActionOutput.MINIMUM_LENGTH;
329 if (action.getType() == ActionType.SET_VLAN_ID) {
330 SetVlanId a = (SetVlanId) action;
331 OFActionVirtualLanIdentifier ofAction = new OFActionVirtualLanIdentifier();
332 ofAction.setVirtualLanIdentifier((short) a.getVlanId());
333 actionsList.add(ofAction);
334 actionsLength += OFActionVirtualLanIdentifier.MINIMUM_LENGTH;
337 if (action.getType() == ActionType.SET_VLAN_PCP) {
338 SetVlanPcp a = (SetVlanPcp) action;
339 OFActionVirtualLanPriorityCodePoint ofAction = new OFActionVirtualLanPriorityCodePoint();
340 ofAction.setVirtualLanPriorityCodePoint(Integer.valueOf(
341 a.getPcp()).byteValue());
342 actionsList.add(ofAction);
343 actionsLength += OFActionVirtualLanPriorityCodePoint.MINIMUM_LENGTH;
346 if (action.getType() == ActionType.POP_VLAN) {
347 OFActionStripVirtualLan ofAction = new OFActionStripVirtualLan();
348 actionsList.add(ofAction);
349 actionsLength += OFActionStripVirtualLan.MINIMUM_LENGTH;
352 if (action.getType() == ActionType.SET_DL_SRC) {
353 SetDlSrc a = (SetDlSrc) action;
354 OFActionDataLayerSource ofAction = new OFActionDataLayerSource();
355 ofAction.setDataLayerAddress(a.getDlAddress());
356 actionsList.add(ofAction);
357 actionsLength += OFActionDataLayerSource.MINIMUM_LENGTH;
360 if (action.getType() == ActionType.SET_DL_DST) {
361 SetDlDst a = (SetDlDst) action;
362 OFActionDataLayerDestination ofAction = new OFActionDataLayerDestination();
363 ofAction.setDataLayerAddress(a.getDlAddress());
364 actionsList.add(ofAction);
365 actionsLength += OFActionDataLayerDestination.MINIMUM_LENGTH;
368 if (action.getType() == ActionType.SET_NW_SRC) {
369 SetNwSrc a = (SetNwSrc) action;
370 OFActionNetworkLayerSource ofAction = new OFActionNetworkLayerSource();
371 ofAction.setNetworkAddress(NetUtils.byteArray4ToInt(a
372 .getAddress().getAddress()));
373 actionsList.add(ofAction);
374 actionsLength += OFActionNetworkLayerAddress.MINIMUM_LENGTH;
377 if (action.getType() == ActionType.SET_NW_DST) {
378 SetNwDst a = (SetNwDst) action;
379 OFActionNetworkLayerDestination ofAction = new OFActionNetworkLayerDestination();
380 ofAction.setNetworkAddress(NetUtils.byteArray4ToInt(a
381 .getAddress().getAddress()));
382 actionsList.add(ofAction);
383 actionsLength += OFActionNetworkLayerAddress.MINIMUM_LENGTH;
386 if (action.getType() == ActionType.SET_NW_TOS) {
387 SetNwTos a = (SetNwTos) action;
388 OFActionNetworkTypeOfService ofAction = new OFActionNetworkTypeOfService();
389 ofAction.setNetworkTypeOfService(Integer.valueOf(
390 a.getNwTos()).byteValue());
391 actionsList.add(ofAction);
392 actionsLength += OFActionNetworkTypeOfService.MINIMUM_LENGTH;
395 if (action.getType() == ActionType.SET_TP_SRC) {
396 SetTpSrc a = (SetTpSrc) action;
397 OFActionTransportLayerSource ofAction = new OFActionTransportLayerSource();
398 ofAction.setTransportPort(Integer.valueOf(a.getPort())
400 actionsList.add(ofAction);
401 actionsLength += OFActionTransportLayer.MINIMUM_LENGTH;
404 if (action.getType() == ActionType.SET_TP_DST) {
405 SetTpDst a = (SetTpDst) action;
406 OFActionTransportLayerDestination ofAction = new OFActionTransportLayerDestination();
407 ofAction.setTransportPort(Integer.valueOf(a.getPort())
409 actionsList.add(ofAction);
410 actionsLength += OFActionTransportLayer.MINIMUM_LENGTH;
413 if (action.getType() == ActionType.SET_NEXT_HOP) {
423 * Utility to convert a SAL flow to an OF 1.0 (OFFlowMod) or to an OF 1.0 +
424 * IPv6 extension (V6FlowMod) Flow modifier Message
431 public OFMessage getOFFlowMod(short command, OFPort port) {
432 OFMessage fm = (isIPv6) ? new V6FlowMod() : new OFFlowMod();
433 if (this.ofMatch == null) {
436 if (this.actionsList == null) {
440 ((OFFlowMod) fm).setMatch(this.ofMatch);
441 ((OFFlowMod) fm).setActions(this.actionsList);
442 ((OFFlowMod) fm).setPriority(flow.getPriority());
443 ((OFFlowMod) fm).setCookie(flow.getId());
444 ((OFFlowMod) fm).setBufferId(OFPacketOut.BUFFER_ID_NONE);
445 ((OFFlowMod) fm).setLength(U16.t(OFFlowMod.MINIMUM_LENGTH
447 ((OFFlowMod) fm).setIdleTimeout(flow.getIdleTimeout());
448 ((OFFlowMod) fm).setHardTimeout(flow.getHardTimeout());
449 ((OFFlowMod) fm).setCommand(command);
451 ((OFFlowMod) fm).setOutPort(port);
453 if (command == OFFlowMod.OFPFC_ADD
454 || command == OFFlowMod.OFPFC_MODIFY
455 || command == OFFlowMod.OFPFC_MODIFY_STRICT) {
456 if (flow.getIdleTimeout() != 0 || flow.getHardTimeout() != 0) {
457 // Instruct switch to let controller know when flow expires
458 ((OFFlowMod) fm).setFlags((short) 1);
462 ((V6FlowMod) fm).setVendor();
463 ((V6FlowMod) fm).setMatch((V6Match) ofMatch);
464 ((V6FlowMod) fm).setActions(this.actionsList);
465 ((V6FlowMod) fm).setPriority(flow.getPriority());
466 ((V6FlowMod) fm).setCookie(flow.getId());
467 ((V6FlowMod) fm).setLength(U16.t(OFVendor.MINIMUM_LENGTH
468 + ((V6Match) ofMatch).getIPv6ExtMinHdrLen()
469 + ((V6Match) ofMatch).getIPv6MatchLen()
470 + ((V6Match) ofMatch).getPadSize() + actionsLength));
471 ((V6FlowMod) fm).setIdleTimeout(flow.getIdleTimeout());
472 ((V6FlowMod) fm).setHardTimeout(flow.getHardTimeout());
473 ((V6FlowMod) fm).setCommand(command);
475 ((V6FlowMod) fm).setOutPort(port);
477 if (command == OFFlowMod.OFPFC_ADD
478 || command == OFFlowMod.OFPFC_MODIFY
479 || command == OFFlowMod.OFPFC_MODIFY_STRICT) {
480 if (flow.getIdleTimeout() != 0 || flow.getHardTimeout() != 0) {
481 // Instruct switch to let controller know when flow expires
482 ((V6FlowMod) fm).setFlags((short) 1);
489 public Flow getFlow(Node node) {
490 if (this.flow == null) {
491 Match salMatch = new Match();
494 * Installed flow may not have a Match defined like in case of a
497 if (ofMatch != null) {
499 // Compute OF1.0 Match
500 if (ofMatch.getInputPort() != 0) {
501 salMatch.setField(new MatchField(MatchType.IN_PORT,
502 NodeConnectorCreator.createNodeConnector(
503 (Short) ofMatch.getInputPort(), node)));
505 if (ofMatch.getDataLayerSource() != null
507 .isZeroMAC(ofMatch.getDataLayerSource())) {
508 byte srcMac[] = ofMatch.getDataLayerSource();
509 salMatch.setField(new MatchField(MatchType.DL_SRC,
512 if (ofMatch.getDataLayerDestination() != null
513 && !NetUtils.isZeroMAC(ofMatch
514 .getDataLayerDestination())) {
515 byte dstMac[] = ofMatch.getDataLayerDestination();
516 salMatch.setField(new MatchField(MatchType.DL_DST,
519 if (ofMatch.getDataLayerType() != 0) {
520 salMatch.setField(new MatchField(MatchType.DL_TYPE,
521 ofMatch.getDataLayerType()));
523 if (ofMatch.getDataLayerVirtualLan() != 0) {
524 salMatch.setField(new MatchField(MatchType.DL_VLAN,
525 ofMatch.getDataLayerVirtualLan()));
527 if (ofMatch.getDataLayerVirtualLanPriorityCodePoint() != 0) {
528 salMatch.setField(MatchType.DL_VLAN_PR, ofMatch
529 .getDataLayerVirtualLanPriorityCodePoint());
531 if (ofMatch.getNetworkSource() != 0) {
532 salMatch.setField(MatchType.NW_SRC, NetUtils
533 .getInetAddress(ofMatch.getNetworkSource()),
534 NetUtils.getInetNetworkMask(
535 ofMatch.getNetworkSourceMaskLen(),
538 if (ofMatch.getNetworkDestination() != 0) {
539 salMatch.setField(MatchType.NW_DST,
540 NetUtils.getInetAddress(ofMatch
541 .getNetworkDestination()),
542 NetUtils.getInetNetworkMask(
543 ofMatch.getNetworkDestinationMaskLen(),
546 if (ofMatch.getNetworkTypeOfService() != 0) {
547 int dscp = NetUtils.getUnsignedByte(ofMatch
548 .getNetworkTypeOfService());
549 byte tos = (byte) (dscp >> 2);
550 salMatch.setField(MatchType.NW_TOS, tos);
552 if (ofMatch.getNetworkProtocol() != 0) {
553 salMatch.setField(MatchType.NW_PROTO,
554 ofMatch.getNetworkProtocol());
556 if (ofMatch.getTransportSource() != 0) {
557 salMatch.setField(MatchType.TP_SRC,
558 ((Short) ofMatch.getTransportSource()));
560 if (ofMatch.getTransportDestination() != 0) {
561 salMatch.setField(MatchType.TP_DST,
562 ((Short) ofMatch.getTransportDestination()));
565 // Compute OF1.0 + IPv6 extensions Match
566 V6Match v6Match = (V6Match) ofMatch;
567 if (v6Match.getInputPort() != 0) {
568 // Mask on input port is not defined
569 salMatch.setField(new MatchField(MatchType.IN_PORT,
570 NodeConnectorCreator.createOFNodeConnector(
571 (Short) v6Match.getInputPort(), node)));
573 if (v6Match.getDataLayerSource() != null
575 .isZeroMAC(ofMatch.getDataLayerSource())) {
576 byte srcMac[] = v6Match.getDataLayerSource();
577 salMatch.setField(new MatchField(MatchType.DL_SRC,
580 if (v6Match.getDataLayerDestination() != null
581 && !NetUtils.isZeroMAC(ofMatch
582 .getDataLayerDestination())) {
583 byte dstMac[] = v6Match.getDataLayerDestination();
584 salMatch.setField(new MatchField(MatchType.DL_DST,
587 if (v6Match.getDataLayerType() != 0) {
588 salMatch.setField(new MatchField(MatchType.DL_TYPE,
589 v6Match.getDataLayerType()));
591 if (v6Match.getDataLayerVirtualLan() != 0) {
592 salMatch.setField(new MatchField(MatchType.DL_VLAN,
593 v6Match.getDataLayerVirtualLan()));
595 if (v6Match.getDataLayerVirtualLanPriorityCodePoint() != 0) {
596 salMatch.setField(MatchType.DL_VLAN_PR, v6Match
597 .getDataLayerVirtualLanPriorityCodePoint());
599 if (v6Match.getNetworkSrc() != null) {
600 salMatch.setField(MatchType.NW_SRC,
601 v6Match.getNetworkSrc(),
602 v6Match.getNetworkSourceMask());
604 if (v6Match.getNetworkDest() != null) {
605 salMatch.setField(MatchType.NW_DST,
606 v6Match.getNetworkDest(),
607 v6Match.getNetworkDestinationMask());
609 if (v6Match.getNetworkTypeOfService() != 0) {
610 int dscp = NetUtils.getUnsignedByte(v6Match
611 .getNetworkTypeOfService());
612 byte tos = (byte) (dscp >> 2);
613 salMatch.setField(MatchType.NW_TOS, tos);
615 if (v6Match.getNetworkProtocol() != 0) {
616 salMatch.setField(MatchType.NW_PROTO,
617 v6Match.getNetworkProtocol());
619 if (v6Match.getTransportSource() != 0) {
620 salMatch.setField(MatchType.TP_SRC,
621 ((Short) v6Match.getTransportSource()));
623 if (v6Match.getTransportDestination() != 0) {
624 salMatch.setField(MatchType.TP_DST,
625 ((Short) v6Match.getTransportDestination()));
631 Action salAction = null;
632 List<Action> salActionList = new ArrayList<Action>();
633 if (actionsList == null) {
634 salActionList.add(new Drop());
636 for (OFAction ofAction : actionsList) {
637 if (ofAction instanceof OFActionOutput) {
638 short ofPort = ((OFActionOutput) ofAction).getPort();
639 if (ofPort == OFPort.OFPP_CONTROLLER.getValue()) {
640 salAction = new Controller();
641 } else if (ofPort == OFPort.OFPP_NONE.getValue()) {
642 salAction = new Drop();
643 } else if (ofPort == OFPort.OFPP_IN_PORT.getValue()) {
644 salAction = new Loopback();
645 } else if (ofPort == OFPort.OFPP_FLOOD.getValue()) {
646 salAction = new Flood();
647 } else if (ofPort == OFPort.OFPP_ALL.getValue()) {
648 salAction = new FloodAll();
649 } else if (ofPort == OFPort.OFPP_LOCAL.getValue()) {
650 salAction = new SwPath();
651 } else if (ofPort == OFPort.OFPP_NORMAL.getValue()) {
652 salAction = new HwPath();
653 } else if (ofPort == OFPort.OFPP_TABLE.getValue()) {
654 salAction = new HwPath(); // TODO: we do not handle
655 // table in sal for now
657 salAction = new Output(
658 NodeConnectorCreator.createOFNodeConnector(
661 } else if (ofAction instanceof OFActionVirtualLanIdentifier) {
662 salAction = new SetVlanId(
663 ((OFActionVirtualLanIdentifier) ofAction)
664 .getVirtualLanIdentifier());
665 } else if (ofAction instanceof OFActionStripVirtualLan) {
666 salAction = new PopVlan();
667 } else if (ofAction instanceof OFActionVirtualLanPriorityCodePoint) {
668 salAction = new SetVlanPcp(
669 ((OFActionVirtualLanPriorityCodePoint) ofAction)
670 .getVirtualLanPriorityCodePoint());
671 } else if (ofAction instanceof OFActionDataLayerSource) {
672 salAction = new SetDlSrc(
673 ((OFActionDataLayerSource) ofAction)
674 .getDataLayerAddress().clone());
675 } else if (ofAction instanceof OFActionDataLayerDestination) {
676 salAction = new SetDlDst(
677 ((OFActionDataLayerDestination) ofAction)
678 .getDataLayerAddress().clone());
679 } else if (ofAction instanceof OFActionNetworkLayerSource) {
680 byte addr[] = BigInteger.valueOf(
681 ((OFActionNetworkLayerSource) ofAction)
682 .getNetworkAddress()).toByteArray();
683 InetAddress ip = null;
685 ip = InetAddress.getByAddress(addr);
686 } catch (UnknownHostException e) {
689 salAction = new SetNwSrc(ip);
690 } else if (ofAction instanceof OFActionNetworkLayerDestination) {
691 byte addr[] = BigInteger.valueOf(
692 ((OFActionNetworkLayerDestination) ofAction)
693 .getNetworkAddress()).toByteArray();
694 InetAddress ip = null;
696 ip = InetAddress.getByAddress(addr);
697 } catch (UnknownHostException e) {
700 salAction = new SetNwDst(ip);
701 } else if (ofAction instanceof OFActionNetworkTypeOfService) {
702 salAction = new SetNwTos(
703 ((OFActionNetworkTypeOfService) ofAction)
704 .getNetworkTypeOfService());
705 } else if (ofAction instanceof OFActionTransportLayerSource) {
706 Short port = ((OFActionTransportLayerSource) ofAction)
708 int intPort = NetUtils.getUnsignedShort(port);
709 salAction = new SetTpSrc(intPort);
710 } else if (ofAction instanceof OFActionTransportLayerDestination) {
711 Short port = ((OFActionTransportLayerDestination) ofAction)
713 int intPort = NetUtils.getUnsignedShort(port);
714 salAction = new SetTpDst(intPort);
716 salActionList.add(salAction);
720 flow = new Flow(salMatch, salActionList);