Merge "BUG-1167: missing Notification of FLOW_REMOVED"
authorEd Warnicke <eaw@cisco.com>
Thu, 19 Jun 2014 14:06:25 +0000 (14:06 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 19 Jun 2014 14:06:25 +0000 (14:06 +0000)
1  2 
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ToSalConversionsUtils.java

index e790c2c591a59d81c3f8068ee62eac36e5dea6f3,764266140ae777dfa536bde8e746a8f5a941cf5f..b64f17a77028ff018df7691d4f0498027356d4a8
@@@ -55,7 -55,6 +55,7 @@@ import org.opendaylight.controller.sal.
  import org.opendaylight.controller.sal.core.NodeConnector;
  import org.opendaylight.controller.sal.flowprogrammer.Flow;
  import org.opendaylight.controller.sal.match.Match;
 +import org.opendaylight.controller.sal.match.MatchType;
  import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
  import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
  import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
@@@ -95,9 -94,10 +95,11 @@@ import org.opendaylight.yang.gen.v1.urn
  import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address;
  import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4;
  import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6;
+ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemoved;
+ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.GenericFlowAttributes;
  import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
  import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
 +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
  import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
  import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
  import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.MacAddressFilter;
@@@ -116,22 -116,49 +118,53 @@@ import org.opendaylight.yang.gen.v1.urn
  import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
  import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
  import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId;
 +import org.slf4j.Logger;
 +import org.slf4j.LoggerFactory;
  
  import com.google.common.net.InetAddresses;
  
  public class ToSalConversionsUtils {
  
 +    private static final Logger LOG = LoggerFactory.getLogger(ToSalConversionsUtils.class);
 +
      private ToSalConversionsUtils() {
  
      }
  
      public static Flow toFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow source, Node node) {
          final Flow target = new Flow();
+         genericFlowToAdFlow(source, target);
+         
+         target.setMatch(toMatch(source.getMatch()));
  
+         List<Action> actions = getAction(source);
+         if (actions != null) {
+             target.setActions(actionFrom(actions, node));
+         }
+         return target;
+     }
+     
+     /**
+      * @param source notification, missing instructions
+      * @param node corresponding node where the flow change occured
+      * @return ad-sal node, build from given data
+      */
+     public static Flow toFlow(SwitchFlowRemoved source, Node node) {
+         final Flow target = new Flow();
+         genericFlowToAdFlow(source, target);
+         target.setMatch(toMatch(source.getMatch()));
+         return target;
+     }
+     /**
+      * @param source
+      * @param target
+      */
+     private static void genericFlowToAdFlow(GenericFlowAttributes source,
+             final Flow target) {
          Integer hardTimeout = source.getHardTimeout();
          if (hardTimeout != null) {
              target.setHardTimeout(hardTimeout.shortValue());
          if (priority != null) {
              target.setPriority(priority.shortValue());
          }
-         target.setMatch(toMatch(source.getMatch()));
-         List<Action> actions = getAction(source);
-         if (actions != null) {
-             target.setActions(actionFrom(actions, node));
-         }
          target.setId(source.getCookie().getValue().longValue());
-         return target;
      }
+     
      public static List<Action> getAction(
              org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow source) {
          if (source.getInstructions() != null) {
          return nodeConnector;
      }
  
-     public static Match toMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match source) {
+     public static Match toMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match source) {
          Match target = new Match();
          if (source != null) {
              fillFrom(target, source.getVlanMatch());
              fillFrom(target, source.getLayer3Match());
              fillFrom(target, source.getLayer4Match());
              fillFrom(target, source.getIpMatch());
 +            fillFrom(target, source.getInPort());
          }
  
          return target;
      }
  
 +    /**
 +     * @param target
 +     * @param inPort
 +     */
 +    private static void fillFrom(Match target, NodeConnectorId inPort) {
 +        if (inPort != null) {
 +            String inPortValue = inPort.getValue();
 +            if (inPortValue != null) {
 +                try {
 +                    target.setField(MatchType.IN_PORT, NodeMapping.toADNodeConnector(inPort,
 +                            NodeMapping.toAdNodeId(inPort)));
 +                } catch (ConstructionException e) {
 +                    LOG.warn("nodeConnector construction failed", e);
 +                }
 +            }
 +        }
 +    }
 +
      private static void fillFrom(Match target, VlanMatch vlanMatch) {
          if (vlanMatch != null) {
              VlanId vlanId = vlanMatch.getVlanId();