X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fprotocol_plugins%2Fopenflow%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fprotocol_plugin%2Fopenflow%2Finternal%2FFlowConverter.java;h=074774a25e2e8c295801c5ae9763f4661ba6a79c;hb=refs%2Fchanges%2F49%2F449%2F1;hp=7e89cd0a42658a50d5579dd21649266d99ff6ab1;hpb=b7a34b47e39a9fe25617c9e536817858e58b2558;p=controller.git diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowConverter.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowConverter.java index 7e89cd0a42..074774a25e 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowConverter.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowConverter.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -17,29 +16,6 @@ import java.util.List; import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6FlowMod; import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match; -import org.openflow.protocol.OFFlowMod; -import org.openflow.protocol.OFMatch; -import org.openflow.protocol.OFMessage; -import org.openflow.protocol.OFPacketOut; -import org.openflow.protocol.OFPort; -import org.openflow.protocol.OFVendor; -import org.openflow.protocol.action.OFAction; -import org.openflow.protocol.action.OFActionDataLayerDestination; -import org.openflow.protocol.action.OFActionDataLayerSource; -import org.openflow.protocol.action.OFActionNetworkLayerAddress; -import org.openflow.protocol.action.OFActionNetworkLayerDestination; -import org.openflow.protocol.action.OFActionNetworkLayerSource; -import org.openflow.protocol.action.OFActionNetworkTypeOfService; -import org.openflow.protocol.action.OFActionOutput; -import org.openflow.protocol.action.OFActionStripVirtualLan; -import org.openflow.protocol.action.OFActionTransportLayer; -import org.openflow.protocol.action.OFActionTransportLayerDestination; -import org.openflow.protocol.action.OFActionTransportLayerSource; -import org.openflow.protocol.action.OFActionVirtualLanIdentifier; -import org.openflow.protocol.action.OFActionVirtualLanPriorityCodePoint; -import org.openflow.util.U16; -import org.openflow.util.U32; - import org.opendaylight.controller.sal.action.Action; import org.opendaylight.controller.sal.action.ActionType; import org.opendaylight.controller.sal.action.Controller; @@ -68,14 +44,37 @@ import org.opendaylight.controller.sal.match.MatchField; import org.opendaylight.controller.sal.match.MatchType; import org.opendaylight.controller.sal.utils.NetUtils; import org.opendaylight.controller.sal.utils.NodeConnectorCreator; +import org.openflow.protocol.OFFlowMod; +import org.openflow.protocol.OFMatch; +import org.openflow.protocol.OFMessage; +import org.openflow.protocol.OFPacketOut; +import org.openflow.protocol.OFPort; +import org.openflow.protocol.OFVendor; +import org.openflow.protocol.action.OFAction; +import org.openflow.protocol.action.OFActionDataLayerDestination; +import org.openflow.protocol.action.OFActionDataLayerSource; +import org.openflow.protocol.action.OFActionNetworkLayerAddress; +import org.openflow.protocol.action.OFActionNetworkLayerDestination; +import org.openflow.protocol.action.OFActionNetworkLayerSource; +import org.openflow.protocol.action.OFActionNetworkTypeOfService; +import org.openflow.protocol.action.OFActionOutput; +import org.openflow.protocol.action.OFActionStripVirtualLan; +import org.openflow.protocol.action.OFActionTransportLayer; +import org.openflow.protocol.action.OFActionTransportLayerDestination; +import org.openflow.protocol.action.OFActionTransportLayerSource; +import org.openflow.protocol.action.OFActionVirtualLanIdentifier; +import org.openflow.protocol.action.OFActionVirtualLanPriorityCodePoint; +import org.openflow.util.U16; +import org.openflow.util.U32; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Utility class for converting a SAL Flow into the OF flow and vice-versa - * - * - * */ public class FlowConverter { + protected static final Logger logger = LoggerFactory + .getLogger(FlowConverter.class); private Flow flow; // SAL Flow private OFMatch ofMatch; // OF 1.0 match or OF 1.0 + IPv6 extension match private List actionsList; // OF 1.0 actions @@ -99,8 +98,9 @@ public class FlowConverter { } /** - * Returns the match in OF 1.0 (OFMatch) form or OF 1.0 + IPv6 extensions form (V6Match) - * + * Returns the match in OF 1.0 (OFMatch) form or OF 1.0 + IPv6 extensions + * form (V6Match) + * * @return */ public OFMatch getOFMatch() { @@ -173,11 +173,11 @@ public class FlowConverter { } if (match.isPresent(MatchType.NW_TOS)) { /* - * OF 1.0 switch expects the TOS as the 6 msb in the byte. - * it is actually the DSCP field followed by a zero ECN + * OF 1.0 switch expects the TOS as the 6 msb in the byte. it is + * actually the DSCP field followed by a zero ECN */ byte tos = (Byte) match.getField(MatchType.NW_TOS).getValue(); - byte dscp = (byte)((int)tos << 2); + byte dscp = (byte) ((int) tos << 2); if (!isIPv6) { ofMatch.setNetworkTypeOfService(dscp); wildcards &= ~OFMatch.OFPFW_NW_TOS; @@ -255,12 +255,14 @@ public class FlowConverter { ofMatch.setWildcards(U32.t(Long.valueOf(wildcards))); } } - + logger.trace("SAL Match: {} Openflow Match: {}", flow.getMatch(), + ofMatch); return ofMatch; } /** * Returns the list of actions in OF 1.0 form + * * @return */ public List getOFActions() { @@ -303,7 +305,8 @@ public class FlowConverter { if (action.getType() == ActionType.CONTROLLER) { OFActionOutput ofAction = new OFActionOutput(); ofAction.setPort(OFPort.OFPP_CONTROLLER.getValue()); - // We want the whole frame hitting the match be sent to the controller + // We want the whole frame hitting the match be sent to the + // controller ofAction.setMaxLength((short) 0xffff); actionsList.add(ofAction); actionsLength += OFActionOutput.MINIMUM_LENGTH; @@ -408,18 +411,20 @@ public class FlowConverter { continue; } if (action.getType() == ActionType.SET_NEXT_HOP) { - //TODO + // TODO continue; } } } + logger.trace("SAL Actions: {} Openflow Actions: {}", flow.getActions(), + actionsList); return actionsList; } /** - * Utility to convert a SAL flow to an OF 1.0 (OFFlowMod) or - * to an OF 1.0 + IPv6 extension (V6FlowMod) Flow modifier Message - * + * Utility to convert a SAL flow to an OF 1.0 (OFFlowMod) or to an OF 1.0 + + * IPv6 extension (V6FlowMod) Flow modifier Message + * * @param sw * @param command * @param port @@ -447,6 +452,14 @@ public class FlowConverter { if (port != null) { ((OFFlowMod) fm).setOutPort(port); } + if (command == OFFlowMod.OFPFC_ADD + || command == OFFlowMod.OFPFC_MODIFY + || command == OFFlowMod.OFPFC_MODIFY_STRICT) { + if (flow.getIdleTimeout() != 0 || flow.getHardTimeout() != 0) { + // Instruct switch to let controller know when flow expires + ((OFFlowMod) fm).setFlags((short) 1); + } + } } else { ((V6FlowMod) fm).setVendor(); ((V6FlowMod) fm).setMatch((V6Match) ofMatch); @@ -463,7 +476,18 @@ public class FlowConverter { if (port != null) { ((V6FlowMod) fm).setOutPort(port); } + if (command == OFFlowMod.OFPFC_ADD + || command == OFFlowMod.OFPFC_MODIFY + || command == OFFlowMod.OFPFC_MODIFY_STRICT) { + if (flow.getIdleTimeout() != 0 || flow.getHardTimeout() != 0) { + // Instruct switch to let controller know when flow expires + ((V6FlowMod) fm).setFlags((short) 1); + } + } } + logger.trace("Openflow Match: {} Openflow Actions: {}", ofMatch, + actionsList); + logger.trace("Openflow Mod Message: {}", fm); return fm; } @@ -472,8 +496,8 @@ public class FlowConverter { Match salMatch = new Match(); /* - * Installed flow may not have a Match defined - * like in case of a drop all flow + * Installed flow may not have a Match defined like in case of a + * drop all flow */ if (ofMatch != null) { if (!isIPv6) { @@ -512,38 +536,35 @@ public class FlowConverter { if (ofMatch.getNetworkSource() != 0) { salMatch.setField(MatchType.NW_SRC, NetUtils .getInetAddress(ofMatch.getNetworkSource()), - NetUtils.getInetNetworkMask(ofMatch - .getNetworkSourceMaskLen(), false)); + NetUtils.getInetNetworkMask( + ofMatch.getNetworkSourceMaskLen(), + false)); } if (ofMatch.getNetworkDestination() != 0) { - salMatch - .setField( - MatchType.NW_DST, - NetUtils.getInetAddress(ofMatch - .getNetworkDestination()), - NetUtils - .getInetNetworkMask( - ofMatch - .getNetworkDestinationMaskLen(), - false)); + salMatch.setField(MatchType.NW_DST, + NetUtils.getInetAddress(ofMatch + .getNetworkDestination()), + NetUtils.getInetNetworkMask( + ofMatch.getNetworkDestinationMaskLen(), + false)); } if (ofMatch.getNetworkTypeOfService() != 0) { - int dscp = NetUtils.getUnsignedByte( - ofMatch.getNetworkTypeOfService()); - byte tos = (byte)(dscp >> 2); + int dscp = NetUtils.getUnsignedByte(ofMatch + .getNetworkTypeOfService()); + byte tos = (byte) (dscp >> 2); salMatch.setField(MatchType.NW_TOS, tos); } if (ofMatch.getNetworkProtocol() != 0) { - salMatch.setField(MatchType.NW_PROTO, ofMatch - .getNetworkProtocol()); + salMatch.setField(MatchType.NW_PROTO, + ofMatch.getNetworkProtocol()); } if (ofMatch.getTransportSource() != 0) { - salMatch.setField(MatchType.TP_SRC, ((Short) ofMatch - .getTransportSource())); + salMatch.setField(MatchType.TP_SRC, + ((Short) ofMatch.getTransportSource())); } if (ofMatch.getTransportDestination() != 0) { - salMatch.setField(MatchType.TP_DST, ((Short) ofMatch - .getTransportDestination())); + salMatch.setField(MatchType.TP_DST, + ((Short) ofMatch.getTransportDestination())); } } else { // Compute OF1.0 + IPv6 extensions Match @@ -581,32 +602,32 @@ public class FlowConverter { .getDataLayerVirtualLanPriorityCodePoint()); } if (v6Match.getNetworkSrc() != null) { - salMatch.setField(MatchType.NW_SRC, v6Match - .getNetworkSrc(), v6Match - .getNetworkSourceMask()); + salMatch.setField(MatchType.NW_SRC, + v6Match.getNetworkSrc(), + v6Match.getNetworkSourceMask()); } if (v6Match.getNetworkDest() != null) { - salMatch.setField(MatchType.NW_DST, v6Match - .getNetworkDest(), v6Match - .getNetworkDestinationMask()); + salMatch.setField(MatchType.NW_DST, + v6Match.getNetworkDest(), + v6Match.getNetworkDestinationMask()); } if (v6Match.getNetworkTypeOfService() != 0) { - int dscp = NetUtils.getUnsignedByte( - v6Match.getNetworkTypeOfService()); - byte tos = (byte) (dscp >> 2); + int dscp = NetUtils.getUnsignedByte(v6Match + .getNetworkTypeOfService()); + byte tos = (byte) (dscp >> 2); salMatch.setField(MatchType.NW_TOS, tos); } if (v6Match.getNetworkProtocol() != 0) { - salMatch.setField(MatchType.NW_PROTO, v6Match - .getNetworkProtocol()); + salMatch.setField(MatchType.NW_PROTO, + v6Match.getNetworkProtocol()); } if (v6Match.getTransportSource() != 0) { - salMatch.setField(MatchType.TP_SRC, ((Short) v6Match - .getTransportSource())); + salMatch.setField(MatchType.TP_SRC, + ((Short) v6Match.getTransportSource())); } if (v6Match.getTransportDestination() != 0) { - salMatch.setField(MatchType.TP_DST, ((Short) v6Match - .getTransportDestination())); + salMatch.setField(MatchType.TP_DST, + ((Short) v6Match.getTransportDestination())); } } } @@ -635,10 +656,12 @@ public class FlowConverter { } else if (ofPort == OFPort.OFPP_NORMAL.getValue()) { salAction = new HwPath(); } else if (ofPort == OFPort.OFPP_TABLE.getValue()) { - salAction = new HwPath(); //TODO: we do not handle table in sal for now + salAction = new HwPath(); // TODO: we do not handle + // table in sal for now } else { - salAction = new Output(NodeConnectorCreator - .createOFNodeConnector(ofPort, node)); + salAction = new Output( + NodeConnectorCreator.createOFNodeConnector( + ofPort, node)); } } else if (ofAction instanceof OFActionVirtualLanIdentifier) { salAction = new SetVlanId( @@ -666,7 +689,7 @@ public class FlowConverter { try { ip = InetAddress.getByAddress(addr); } catch (UnknownHostException e) { - e.printStackTrace(); + logger.error("", e); } salAction = new SetNwSrc(ip); } else if (ofAction instanceof OFActionNetworkLayerDestination) { @@ -677,7 +700,7 @@ public class FlowConverter { try { ip = InetAddress.getByAddress(addr); } catch (UnknownHostException e) { - e.printStackTrace(); + logger.error("", e); } salAction = new SetNwDst(ip); } else if (ofAction instanceof OFActionNetworkTypeOfService) { @@ -701,7 +724,10 @@ public class FlowConverter { // Create Flow flow = new Flow(salMatch, salActionList); } + logger.trace("Openflow Match: {} Openflow Actions: {}", ofMatch, + actionsList); + logger.trace("SAL Flow: {}", flow); return flow; } -} \ No newline at end of file +}