AD-SAL: Filter packet-in based on container flow 57/8357/4
authorAlessandro Boch <aboch@cisco.com>
Tue, 24 Jun 2014 23:52:12 +0000 (16:52 -0700)
committerAlessandro Boch <aboch@cisco.com>
Fri, 27 Jun 2014 00:01:01 +0000 (17:01 -0700)
- In AD-SAL openflow plugin incoming packets are delivered
  to listeners in respective container only based on incoming port.
- This patch enforces the container flow filtering logic as well

Change-Id: I6a23b114712e63b8ffb18c173bbbaad5fb7634bd
Signed-off-by: Alessandro Boch <aboch@cisco.com>
17 files changed:
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DataPacketMuxDemux.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/ARP.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/Ethernet.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/IEEE8021Q.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/IPv4.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDP.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDPTLV.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/Packet.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/TCP.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/UDP.java
opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/packet/ARPTest.java
opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/packet/EthernetTest.java
opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/packet/IEEE8021QTest.java
opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/packet/IPv4Test.java
opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/packet/PacketTest.java
opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/packet/TCPTest.java
opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/packet/UDPTest.java

index 5c2af6d8b430471d25f68a68c25e8915c9d02e97..54d5fb888a268ab25ca508498069ff3d2811acd6 100644 (file)
@@ -32,11 +32,15 @@ import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.core.Property;
 import org.opendaylight.controller.sal.core.UpdateType;
 import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.core.Property;
 import org.opendaylight.controller.sal.core.UpdateType;
+import org.opendaylight.controller.sal.match.Match;
+import org.opendaylight.controller.sal.packet.Ethernet;
 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
 import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
+import org.opendaylight.controller.sal.packet.PacketException;
 import org.opendaylight.controller.sal.packet.PacketResult;
 import org.opendaylight.controller.sal.packet.RawPacket;
 import org.opendaylight.controller.sal.utils.GlobalConstants;
 import org.opendaylight.controller.sal.utils.HexEncode;
 import org.opendaylight.controller.sal.packet.PacketResult;
 import org.opendaylight.controller.sal.packet.RawPacket;
 import org.opendaylight.controller.sal.utils.GlobalConstants;
 import org.opendaylight.controller.sal.utils.HexEncode;
+import org.opendaylight.controller.sal.utils.NetUtils;
 import org.openflow.protocol.OFMessage;
 import org.openflow.protocol.OFPacketIn;
 import org.openflow.protocol.OFPacketOut;
 import org.openflow.protocol.OFMessage;
 import org.openflow.protocol.OFPacketIn;
 import org.openflow.protocol.OFPacketOut;
@@ -169,12 +173,10 @@ public class DataPacketMuxDemux implements IContainerListener,
 
     @Override
     public void receive(ISwitch sw, OFMessage msg) {
 
     @Override
     public void receive(ISwitch sw, OFMessage msg) {
-        if (sw == null || msg == null
-                || this.pluginOutDataPacketServices == null) {
+        if (sw == null || msg == null || this.pluginOutDataPacketServices == null) {
             // Something fishy, we cannot do anything
             // Something fishy, we cannot do anything
-            logger.debug(
-                    "sw: {} and/or msg: {} and/or pluginOutDataPacketServices: {} is null!",
-                    new Object[] { sw, msg, this.pluginOutDataPacketServices });
+            logger.debug("sw: {} and/or msg: {} and/or pluginOutDataPacketServices: {} is null!", new Object[] { sw,
+                    msg, this.pluginOutDataPacketServices });
             return;
         }
 
             return;
         }
 
@@ -185,8 +187,7 @@ public class DataPacketMuxDemux implements IContainerListener,
                 logger.debug("Connection service refused DataPacketMuxDemux receive {} {}", sw, msg);
                 return;
             }
                 logger.debug("Connection service refused DataPacketMuxDemux receive {} {}", sw, msg);
                 return;
             }
-        }
-        catch (Exception e) {
+        } catch (Exception e) {
             return;
         }
 
             return;
         }
 
@@ -204,30 +205,22 @@ public class DataPacketMuxDemux implements IContainerListener,
                 // pass the parsed packet simply because once the
                 // packet infra is settled all the packets will passed
                 // around as parsed and read-only
                 // pass the parsed packet simply because once the
                 // packet infra is settled all the packets will passed
                 // around as parsed and read-only
-                for (int i = 0; i < this.iDataPacketListen.size(); i++) {
-                    IDataPacketListen s = this.iDataPacketListen.get(i);
-                    if (s.receiveDataPacket(dataPacket).equals(
-                            PacketResult.CONSUME)) {
+                for (IDataPacketListen s : this.iDataPacketListen) {
+                      if (s.receiveDataPacket(dataPacket).equals(PacketResult.CONSUME)) {
                         logger.trace("Consumed locally data packet");
                         return;
                     }
                 }
 
                         logger.trace("Consumed locally data packet");
                         return;
                     }
                 }
 
-                // Now dispatch the packet toward SAL at least for
-                // default container, we need to revisit this in a general
-                // slicing architecture refresh
+                // Now dispatch the packet toward SAL for default container
                 IPluginOutDataPacketService defaultOutService = this.pluginOutDataPacketServices
                         .get(GlobalConstants.DEFAULT.toString());
                 if (defaultOutService != null) {
                     defaultOutService.receiveDataPacket(dataPacket);
                     if (logger.isTraceEnabled()) {
                 IPluginOutDataPacketService defaultOutService = this.pluginOutDataPacketServices
                         .get(GlobalConstants.DEFAULT.toString());
                 if (defaultOutService != null) {
                     defaultOutService.receiveDataPacket(dataPacket);
                     if (logger.isTraceEnabled()) {
-                      logger.trace(
-                              "Dispatched to apps a frame of size: {} on " +
-                              "container: {}: {}", new Object[] {
-                                    ofPacket.getPacketData().length,
-                                    GlobalConstants.DEFAULT.toString(),
-                                    HexEncode.bytesToHexString(dataPacket
-                                            .getPacketData()) });
+                        logger.trace("Dispatched to apps a frame of size: {} on " + "container: {}: {}",
+                                new Object[] { ofPacket.getPacketData().length, GlobalConstants.DEFAULT.toString(),
+                                        HexEncode.bytesToHexString(dataPacket.getPacketData()) });
                     }
                 }
                 // Now check the mapping between nodeConnector and
                     }
                 }
                 // Now check the mapping between nodeConnector and
@@ -235,32 +228,43 @@ public class DataPacketMuxDemux implements IContainerListener,
                 // flowSpec
                 List<String> containersRX = this.nc2Container.get(p);
                 if (containersRX != null) {
                 // flowSpec
                 List<String> containersRX = this.nc2Container.get(p);
                 if (containersRX != null) {
-                    for (int i = 0; i < containersRX.size(); i++) {
-                        String container = containersRX.get(i);
-                        IPluginOutDataPacketService s = this.pluginOutDataPacketServices
-                                .get(container);
-                        if (s != null) {
-                            // TODO add filtering on a per-flowSpec base
-                            s.receiveDataPacket(dataPacket);
-                            if (logger.isTraceEnabled()) {
-                              logger.trace(
-                                      "Dispatched to apps a frame of size: {}" +
-                                      " on container: {}: {}", new Object[] {
-                                            ofPacket.getPacketData().length,
-                                            container,
-                                            HexEncode.bytesToHexString(dataPacket
-                                                    .getPacketData()) });
+                    Ethernet frame = new Ethernet();
+                    byte data[] = dataPacket.getPacketData();
+                    frame.deserialize(data, 0, data.length * NetUtils.NumBitsInAByte);
+                    Match packetMatch = frame.getMatch();
+                    for (String container : containersRX) {
+                        boolean notify = true;
+                        List<ContainerFlow> containerFlows = this.container2FlowSpecs.get(container);
+                        if (containerFlows != null) {
+                            notify = false;
+                            for (ContainerFlow cFlow : containerFlows) {
+                                if (cFlow.allowsMatch(packetMatch)) {
+                                    notify = true;
+                                    break;
+                                }
+                            }
+                            if (notify) {
+                                IPluginOutDataPacketService s = this.pluginOutDataPacketServices.get(container);
+                                if (s != null) {
+                                    s.receiveDataPacket(dataPacket);
+                                    if (logger.isTraceEnabled()) {
+                                        logger.trace(
+                                                "Dispatched to apps a frame of size: {}" + " on container: {}: {}",
+                                                new Object[] { ofPacket.getPacketData().length, container,
+                                                        HexEncode.bytesToHexString(dataPacket.getPacketData()) });
+                                    }
+                                }
                             }
                         }
                     }
                 }
                             }
                         }
                     }
                 }
-
                 // This is supposed to be the catch all for all the
                 // DataPacket hence we will assume it has been handled
                 return;
             } catch (ConstructionException cex) {
                 // This is supposed to be the catch all for all the
                 // DataPacket hence we will assume it has been handled
                 return;
             } catch (ConstructionException cex) {
+            } catch (PacketException e) {
+                logger.debug("Failed to deserialize raw packet: ", e.getMessage());
             }
             }
-
             // If we reach this point something went wrong.
             return;
         } else {
             // If we reach this point something went wrong.
             return;
         } else {
index 8fc0d625ebe0dd5b08bff4df864efe6a2e3068bd..21c17b366c04c025683b5c032981f043428e326a 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
 
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -258,18 +258,23 @@ public class ARP extends Packet {
 
     @Override
     public boolean equals(Object obj) {
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
             return true;
-        if (!super.equals(obj))
+        }
+        if (!super.equals(obj)) {
             return false;
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()) {
             return false;
             return false;
+        }
         ARP other = (ARP) obj;
         if (fieldValues == null) {
         ARP other = (ARP) obj;
         if (fieldValues == null) {
-            if (other.fieldValues != null)
+            if (other.fieldValues != null) {
                 return false;
                 return false;
-        } else if (!fieldValues.equals(other.fieldValues))
+            }
+        } else if (!fieldValues.equals(other.fieldValues)) {
             return false;
             return false;
+        }
         return true;
     }
 }
         return true;
     }
 }
index d0068564a93b29a326395b1e6cae9eeacf968a53..235e71a760faa01eb9cf9d2acf92a73c8acf00ce 100644 (file)
@@ -15,6 +15,8 @@ import java.util.Map;
 
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
+import org.opendaylight.controller.sal.match.Match;
+import org.opendaylight.controller.sal.match.MatchType;
 import org.opendaylight.controller.sal.utils.EtherTypes;
 import org.opendaylight.controller.sal.utils.NetUtils;
 
 import org.opendaylight.controller.sal.utils.EtherTypes;
 import org.opendaylight.controller.sal.utils.NetUtils;
 
@@ -139,4 +141,10 @@ public class Ethernet extends Packet {
         return this;
     }
 
         return this;
     }
 
+    @Override
+    public void populateMatch(Match match) {
+        match.setField(MatchType.DL_SRC, this.getSourceMACAddress());
+        match.setField(MatchType.DL_DST, this.getDestinationMACAddress());
+        match.setField(MatchType.DL_TYPE, this.getEtherType());
+    }
 }
 }
index 39c7d386bc1fe3ccf5ff397ebfcc491fe108aad6..9825d0eefb791098bf1724d5996c44f881c0da6f 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -13,6 +13,8 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 import java.util.Map;
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
+import org.opendaylight.controller.sal.match.Match;
+import org.opendaylight.controller.sal.match.MatchType;
 
 /**
  * Class that represents the IEEE 802.1Q objects
 
 /**
  * Class that represents the IEEE 802.1Q objects
@@ -148,4 +150,10 @@ public class IEEE8021Q extends Packet {
         return this;
     }
 
         return this;
     }
 
+    @Override
+    public void populateMatch(Match match) {
+        match.setField(MatchType.DL_VLAN, this.getVid());
+        match.setField(MatchType.DL_VLAN_PR, this.getPcp());
+        match.setField(MatchType.DL_TYPE, this.getEtherType());
+    }
 }
 }
index 559acd633ab7e56b6cb22042f7d3974a1e217212..3363f423d695f1b2f090e6c5274715f47d765e3c 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
 
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -20,6 +20,8 @@ import java.util.Random;
 
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
+import org.opendaylight.controller.sal.match.Match;
+import org.opendaylight.controller.sal.match.MatchType;
 import org.opendaylight.controller.sal.utils.IPProtocols;
 import org.opendaylight.controller.sal.utils.NetUtils;
 import org.slf4j.Logger;
 import org.opendaylight.controller.sal.utils.IPProtocols;
 import org.opendaylight.controller.sal.utils.NetUtils;
 import org.slf4j.Logger;
@@ -577,4 +579,12 @@ public class IPv4 extends Packet {
             corrupted = true;
         }
     }
             corrupted = true;
         }
     }
+
+    @Override
+    public void populateMatch(Match match) {
+        match.setField(MatchType.NW_SRC, NetUtils.getInetAddress(this.getSourceAddress()));
+        match.setField(MatchType.NW_DST, NetUtils.getInetAddress(this.getDestinationAddress()));
+        match.setField(MatchType.NW_PROTO, this.getProtocol());
+        match.setField(MatchType.NW_TOS, this.getDiffServ());
+    }
 }
 }
index 6f5cf04a529ed5a2872ff1d7c299eac71a1e060a..9b5dc082bb2303084775026131a11552b5614add 100644 (file)
@@ -12,6 +12,7 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+
 import org.opendaylight.controller.sal.utils.HexEncode;
 import org.opendaylight.controller.sal.utils.NetUtils;
 
 import org.opendaylight.controller.sal.utils.HexEncode;
 import org.opendaylight.controller.sal.utils.NetUtils;
 
index efb938e37f50745aae8f1f560b0d85f2bb7e7c07..35244ea697d871617b09db6e232da95af0d51ebf 100644 (file)
@@ -151,18 +151,23 @@ public class LLDPTLV extends Packet {
 
     @Override
     public boolean equals(Object obj) {
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
             return true;
-        if (!super.equals(obj))
+        }
+        if (!super.equals(obj)) {
             return false;
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()) {
             return false;
             return false;
+        }
         LLDPTLV other = (LLDPTLV) obj;
         if (fieldValues == null) {
         LLDPTLV other = (LLDPTLV) obj;
         if (fieldValues == null) {
-            if (other.fieldValues != null)
+            if (other.fieldValues != null) {
                 return false;
                 return false;
-        } else if (!fieldValues.equals(other.fieldValues))
+            }
+        } else if (!fieldValues.equals(other.fieldValues)) {
             return false;
             return false;
+        }
         return true;
     }
 
         return true;
     }
 
index 58b5d3914aa2dc199111dd2f2dc1ff8d5289dcc0..789aa126533c93c16660e5eafcfc995dc510fab1 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -13,6 +13,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 
 import org.apache.commons.lang3.tuple.Pair;
 import java.util.Map.Entry;
 
 import org.apache.commons.lang3.tuple.Pair;
+import org.opendaylight.controller.sal.match.Match;
 import org.opendaylight.controller.sal.utils.HexEncode;
 import org.opendaylight.controller.sal.utils.NetUtils;
 import org.slf4j.Logger;
 import org.opendaylight.controller.sal.utils.HexEncode;
 import org.opendaylight.controller.sal.utils.NetUtils;
 import org.slf4j.Logger;
@@ -364,4 +365,31 @@ public abstract class Packet {
         return true;
     }
 
         return true;
     }
 
+    /**
+     * Adds to the passed Match this packet's header fields
+     *
+     * @param match
+     *            The Match object to populate
+     */
+    public void populateMatch(Match match) {
+        // To be overridden by derived packet classes which have well known
+        // header fields so that Packet.getMatch would return desired result
+    }
+
+    /**
+     * Returns the Match object containing this packet and its payload
+     * encapsulated packets' header fields
+     *
+     * @return The Match containing the header fields of this packet and of its
+     *         payload encapsulated packets
+     */
+    public Match getMatch() {
+        Match match = new Match();
+        Packet packet = this;
+        while (packet != null) {
+            packet.populateMatch(match);
+            packet = packet.getPayload();
+        }
+        return match;
+    }
 }
 }
index 8253ac46d3f5405ace57da8022be90a183645a68..d27494599c280418044e4ef78210678562852cc0 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
 
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -15,6 +15,8 @@ import java.util.Map;
 
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
+import org.opendaylight.controller.sal.match.Match;
+import org.opendaylight.controller.sal.match.MatchType;
 
 /**
  * Class that represents the TCP segment objects
 
 /**
  * Class that represents the TCP segment objects
@@ -238,4 +240,9 @@ public class TCP extends Packet {
         return (BitBufferHelper.getShort(fieldValues.get(CHECKSUM)));
     }
 
         return (BitBufferHelper.getShort(fieldValues.get(CHECKSUM)));
     }
 
+    @Override
+    public void populateMatch(Match match) {
+        match.setField(MatchType.TP_SRC, this.getSourcePort());
+        match.setField(MatchType.TP_DST, this.getDestinationPort());
+    }
 }
 }
index f82ed8fcaee00115bef01f4a6b03813389bf1a0c..069a277f89d9ee44df2e4ca22d9783fb9b9a6404 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
 
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -15,6 +15,8 @@ import java.util.Map;
 
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
+import org.opendaylight.controller.sal.match.Match;
+import org.opendaylight.controller.sal.match.MatchType;
 
 /**
  * Class that represents the UDP datagram objects
 
 /**
  * Class that represents the UDP datagram objects
@@ -156,4 +158,10 @@ public class UDP extends Packet {
         fieldValues.put(CHECKSUM, checksum);
         return this;
     }
         fieldValues.put(CHECKSUM, checksum);
         return this;
     }
+
+    @Override
+    public void populateMatch(Match match) {
+        match.setField(MatchType.TP_SRC, this.getSourcePort());
+        match.setField(MatchType.TP_DST, this.getDestinationPort());
+    }
 }
 }
index a3ebd7ee0d164163b18f8091199f63bc89c4e30a..10bd535eb2790a1876fe2f9cfa29afb681b4ed1b 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
 
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
index 2494eb6b2d459460c0ab825e9b18c0fc15d30029..494dd2abf28c0d0e660debeb6a9936c3c752315a 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
 
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -9,9 +9,14 @@
 
 package org.opendaylight.controller.sal.packet;
 
 
 package org.opendaylight.controller.sal.packet;
 
+import java.util.Arrays;
+
 import junit.framework.Assert;
 
 import org.junit.Test;
 import junit.framework.Assert;
 
 import org.junit.Test;
+import org.opendaylight.controller.sal.match.Match;
+import org.opendaylight.controller.sal.match.MatchType;
+import org.opendaylight.controller.sal.utils.EtherTypes;
 
 public class EthernetTest {
 
 
 public class EthernetTest {
 
@@ -95,4 +100,22 @@ public class EthernetTest {
 
     }
 
 
     }
 
+    @Test
+    public void testGetMatch() throws Exception {
+        Ethernet eth = new Ethernet();
+        byte smac[] = { (byte) 0xf0, (byte) 0xde, (byte) 0xf1, (byte) 0x71, (byte) 0x72, (byte) 0x8d };
+        byte dmac[] = { (byte) 0xde, (byte) 0x28, (byte) 0xdb, (byte) 0xb3, (byte) 0x7c, (byte) 0xf8 };
+        short ethType = EtherTypes.IPv4.shortValue();
+        eth.setDestinationMACAddress(dmac);
+        eth.setSourceMACAddress(smac);
+        eth.setEtherType(ethType);
+
+        Match match = eth.getMatch();
+
+        Assert.assertTrue(Arrays.equals(smac, (byte[]) match.getField(MatchType.DL_SRC).getValue()));
+        Assert.assertTrue(Arrays.equals(dmac, (byte[]) match.getField(MatchType.DL_DST).getValue()));
+        Assert.assertEquals(ethType, (short) match.getField(MatchType.DL_TYPE).getValue());
+
+    }
+
 }
 }
index a4c6c1fc4b335472d302c655ffd52e1544767e36..2443b491c7e8a7fb69fba50c65681a6bd691f597 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -9,7 +9,11 @@
 package org.opendaylight.controller.sal.packet;
 
 import junit.framework.Assert;
 package org.opendaylight.controller.sal.packet;
 
 import junit.framework.Assert;
+
 import org.junit.Test;
 import org.junit.Test;
+import org.opendaylight.controller.sal.match.Match;
+import org.opendaylight.controller.sal.match.MatchType;
+import org.opendaylight.controller.sal.utils.EtherTypes;
 import org.opendaylight.controller.sal.utils.NetUtils;
 
 public class IEEE8021QTest {
 import org.opendaylight.controller.sal.utils.NetUtils;
 
 public class IEEE8021QTest {
@@ -212,4 +216,21 @@ public class IEEE8021QTest {
         Assert.assertTrue(data[44] == (byte) 0x09);
         Assert.assertTrue(data[45] == (byte) 0xFE);
     }
         Assert.assertTrue(data[44] == (byte) 0x09);
         Assert.assertTrue(data[45] == (byte) 0xFE);
     }
+
+    @Test
+    public void testGetMatchFullPacket() throws Exception {
+        IEEE8021Q dot1q = new IEEE8021Q();
+        byte priority = 4;
+        short vlanId = 59;
+        short ethType = EtherTypes.IPv4.shortValue();
+        dot1q.setPcp(priority);
+        dot1q.setVid(vlanId);
+        dot1q.setEtherType(ethType);
+
+        Match match = dot1q.getMatch();
+
+        Assert.assertEquals(priority, (byte) match.getField(MatchType.DL_VLAN_PR).getValue());
+        Assert.assertEquals(vlanId, (short) match.getField(MatchType.DL_VLAN).getValue());
+        Assert.assertEquals(ethType, (short) match.getField(MatchType.DL_TYPE).getValue());
+    }
 }
 }
index 5afcd8be7dc4f47d79270dd00b6c3c8870c07631..f5298711b677a64ef9c80863580743ce2c394e52 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -15,6 +15,8 @@ import java.util.Arrays;
 import junit.framework.Assert;
 
 import org.junit.Test;
 import junit.framework.Assert;
 
 import org.junit.Test;
+import org.opendaylight.controller.sal.match.Match;
+import org.opendaylight.controller.sal.match.MatchType;
 import org.opendaylight.controller.sal.utils.EtherTypes;
 import org.opendaylight.controller.sal.utils.IPProtocols;
 import org.opendaylight.controller.sal.utils.NetUtils;
 import org.opendaylight.controller.sal.utils.EtherTypes;
 import org.opendaylight.controller.sal.utils.IPProtocols;
 import org.opendaylight.controller.sal.utils.NetUtils;
@@ -452,4 +454,31 @@ public class IPv4Test {
         Assert.assertFalse(decIcmp.isCorrupted());
         Assert.assertTrue(Arrays.equals(icmpRawPayload, decIcmp.getRawPayload()));
     }
         Assert.assertFalse(decIcmp.isCorrupted());
         Assert.assertTrue(Arrays.equals(icmpRawPayload, decIcmp.getRawPayload()));
     }
+
+    @Test
+    public void testGetMatch() throws Exception {
+        IPv4 ip = new IPv4();
+        InetAddress sourceAddress = InetAddress.getByName("172.168.190.15");
+        InetAddress destintationAddress = InetAddress.getByName("23.128.0.11");
+        byte protocol = IPProtocols.TCP.byteValue();
+        byte tos = 7;
+        ip.setVersion((byte) 4);
+        ip.setIdentification((short) 5);
+        ip.setDiffServ(tos);
+        ip.setECN((byte) 0);
+        ip.setTotalLength((short) 84);
+        ip.setFlags((byte) 2);
+        ip.setFragmentOffset((short) 0);
+        ip.setTtl((byte) 64);
+        ip.setProtocol(protocol);
+        ip.setDestinationAddress(destintationAddress);
+        ip.setSourceAddress(sourceAddress);
+
+        Match match = ip.getMatch();
+
+        Assert.assertEquals(sourceAddress, match.getField(MatchType.NW_SRC).getValue());
+        Assert.assertEquals(destintationAddress, match.getField(MatchType.NW_DST).getValue());
+        Assert.assertEquals(protocol, (byte) match.getField(MatchType.NW_PROTO).getValue());
+        Assert.assertEquals(tos, (byte) match.getField(MatchType.NW_TOS).getValue());
+    }
 }
 }
index 8f3b283b2ea020a175b53e952d08f41cd7ca1c69..95eff32ef1899f39a3838f2f46fea8c0f51923fa 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
 
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -9,11 +9,17 @@
 
 package org.opendaylight.controller.sal.packet;
 
 
 package org.opendaylight.controller.sal.packet;
 
+import java.net.InetAddress;
+import java.util.Arrays;
 import java.util.Map;
 
 import junit.framework.Assert;
 
 import org.junit.Test;
 import java.util.Map;
 
 import junit.framework.Assert;
 
 import org.junit.Test;
+import org.opendaylight.controller.sal.match.Match;
+import org.opendaylight.controller.sal.match.MatchType;
+import org.opendaylight.controller.sal.utils.EtherTypes;
+import org.opendaylight.controller.sal.utils.IPProtocols;
 
 public class PacketTest {
 
 
 public class PacketTest {
 
@@ -120,9 +126,9 @@ public class PacketTest {
         eth.setSourceMACAddress(sMAC);
         eth.setEtherType(etherType);
 
         eth.setSourceMACAddress(sMAC);
         eth.setEtherType(etherType);
 
-        dMACdata = (byte[]) fCValues.get("DestinationMACAddress");
-        sMACdata = (byte[]) fCValues.get("SourceMACAddress");
-        etherTypedata = (byte[]) fCValues.get("EtherType");
+        dMACdata = fCValues.get("DestinationMACAddress");
+        sMACdata = fCValues.get("SourceMACAddress");
+        etherTypedata = fCValues.get("EtherType");
 
         Assert.assertTrue(dMACdata[0] == 10);
         Assert.assertTrue(dMACdata[1] == 12);
 
         Assert.assertTrue(dMACdata[0] == 10);
         Assert.assertTrue(dMACdata[1] == 12);
@@ -160,4 +166,62 @@ public class PacketTest {
         Assert.assertTrue(data[13] == 6);
 
     }
         Assert.assertTrue(data[13] == 6);
 
     }
+
+    @Test
+    public void testGetMatch() throws Exception {
+        TCP tcp = new TCP();
+        short sport = (short) 11093;
+        short dport = (short) 23;
+        tcp.setSourcePort(sport);
+        tcp.setDestinationPort(dport);
+
+        IPv4 ip = new IPv4();
+        InetAddress sourceAddress = InetAddress.getByName("192.168.100.100");
+        InetAddress destintationAddress = InetAddress.getByName("192.168.100.101");
+        byte protocol = IPProtocols.TCP.byteValue();
+        byte tos = 5;
+        ip.setVersion((byte) 4);
+        ip.setIdentification((short) 5);
+        ip.setDiffServ(tos);
+        ip.setECN((byte) 0);
+        ip.setTotalLength((short) 84);
+        ip.setFlags((byte) 2);
+        ip.setFragmentOffset((short) 0);
+        ip.setTtl((byte) 64);
+        ip.setProtocol(protocol);
+        ip.setDestinationAddress(destintationAddress);
+        ip.setSourceAddress(sourceAddress);
+        ip.setPayload(tcp);
+
+        IEEE8021Q dot1q = new IEEE8021Q();
+        byte priority = 4;
+        short vlanId = 59;
+        short ethType = EtherTypes.IPv4.shortValue();
+        dot1q.setPcp(priority);
+        dot1q.setVid(vlanId);
+        dot1q.setEtherType(ethType);
+        dot1q.setPayload(ip);
+
+        Ethernet eth = new Ethernet();
+        byte smac[] = { (byte) 0xf0, (byte) 0xde, (byte) 0xf1, (byte) 0x71, (byte) 0x72, (byte) 0x8d };
+        byte dmac[] = { (byte) 0xde, (byte) 0x28, (byte) 0xdb, (byte) 0xb3, (byte) 0x7c, (byte) 0xf8 };
+        eth.setDestinationMACAddress(dmac);
+        eth.setSourceMACAddress(smac);
+        eth.setEtherType(EtherTypes.VLANTAGGED.shortValue());
+        eth.setPayload(dot1q);
+
+        Match match = eth.getMatch();
+
+        Assert.assertTrue(Arrays.equals(smac, (byte[]) match.getField(MatchType.DL_SRC).getValue()));
+        Assert.assertTrue(Arrays.equals(dmac, (byte[]) match.getField(MatchType.DL_DST).getValue()));
+        Assert.assertEquals(priority, (byte) match.getField(MatchType.DL_VLAN_PR).getValue());
+        Assert.assertEquals(vlanId, (short) match.getField(MatchType.DL_VLAN).getValue());
+        Assert.assertEquals(ethType, (short) match.getField(MatchType.DL_TYPE).getValue());
+        Assert.assertEquals(sourceAddress, match.getField(MatchType.NW_SRC).getValue());
+        Assert.assertEquals(destintationAddress, match.getField(MatchType.NW_DST).getValue());
+        Assert.assertEquals(protocol, (byte) match.getField(MatchType.NW_PROTO).getValue());
+        Assert.assertEquals(tos, (byte) match.getField(MatchType.NW_TOS).getValue());
+        Assert.assertEquals(sport, (short) match.getField(MatchType.TP_SRC).getValue());
+        Assert.assertEquals(dport, (short) match.getField(MatchType.TP_DST).getValue());
+    }
 }
 }
index 3e18aedfdb38b7238ef9a72c9d49bff151aec685..e56f41e5c1b301cf78eb8e1e5df3f29fcbe1e7e2 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
 
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -12,6 +12,8 @@ package org.opendaylight.controller.sal.packet;
 import junit.framework.Assert;
 
 import org.junit.Test;
 import junit.framework.Assert;
 
 import org.junit.Test;
+import org.opendaylight.controller.sal.match.Match;
+import org.opendaylight.controller.sal.match.MatchType;
 
 public class TCPTest {
 
 
 public class TCPTest {
 
@@ -113,4 +115,18 @@ public class TCPTest {
         short checksum = tcp.getChecksum();
         Assert.assertTrue(checksum == 200);
     }
         short checksum = tcp.getChecksum();
         Assert.assertTrue(checksum == 200);
     }
+
+    @Test
+    public void testGetMatch() throws Exception {
+        TCP tcp = new TCP();
+        short sport = (short) 52012;
+        short dport = (short) 40345;
+        tcp.setSourcePort(sport);
+        tcp.setDestinationPort(dport);
+
+        Match match = tcp.getMatch();
+
+        Assert.assertEquals(sport, (short) match.getField(MatchType.TP_SRC).getValue());
+        Assert.assertEquals(dport, (short) match.getField(MatchType.TP_DST).getValue());
+    }
 }
 }
index 8d5be849a034d5a147998d7adcf5099481acb552..a3a597a82d0fcb4524da02f174c9ca0419174c81 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
 
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -12,6 +12,8 @@ package org.opendaylight.controller.sal.packet;
 import junit.framework.Assert;
 
 import org.junit.Test;
 import junit.framework.Assert;
 
 import org.junit.Test;
+import org.opendaylight.controller.sal.match.Match;
+import org.opendaylight.controller.sal.match.MatchType;
 
 public class UDPTest {
 
 
 public class UDPTest {
 
@@ -95,4 +97,19 @@ public class UDPTest {
 
     }
 
 
     }
 
+    @Test
+    public void testGetMatch() throws Exception {
+        UDP udp = new UDP();
+        short sport = (short) 33000;
+        short dport = (short) 843;
+        udp.setSourcePort(sport);
+        udp.setDestinationPort(dport);
+
+        Match match = udp.getMatch();
+
+        Assert.assertEquals(sport, (short) match.getField(MatchType.TP_SRC).getValue());
+        Assert.assertEquals(dport, (short) match.getField(MatchType.TP_DST).getValue());
+
+    }
+
 }
 }