Eliminate code duplications detected by Sonar. 30/41330/3
authorShigeru Yasuda <s-yasuda@da.jp.nec.com>
Tue, 5 Jul 2016 13:13:43 +0000 (22:13 +0900)
committerHideyuki Tai <Hideyuki.Tai@necam.com>
Fri, 15 Jul 2016 07:18:20 +0000 (07:18 +0000)
Change-Id: I56b0db7864448a93c3fcf5e7e4665928f7e2dfb5
Signed-off-by: Shigeru Yasuda <s-yasuda@da.jp.nec.com>
32 files changed:
manager/api/src/main/java/org/opendaylight/vtn/manager/packet/EtherTypePacket.java [new file with mode: 0644]
manager/api/src/main/java/org/opendaylight/vtn/manager/packet/Ethernet.java
manager/api/src/main/java/org/opendaylight/vtn/manager/packet/IEEE8021Q.java
manager/api/src/main/java/org/opendaylight/vtn/manager/packet/PortPacket.java [new file with mode: 0644]
manager/api/src/main/java/org/opendaylight/vtn/manager/packet/TCP.java
manager/api/src/main/java/org/opendaylight/vtn/manager/packet/UDP.java
manager/api/src/test/java/org/opendaylight/vtn/manager/packet/EthernetTest.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/flow/cond/FlowMatchTask.java [new file with mode: 0644]
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/flow/cond/RemoveFlowConditionTask.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/flow/cond/RemoveFlowMatchTask.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/flow/cond/SetFlowConditionTask.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/flow/cond/SetFlowMatchTask.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/packet/cache/CachedPacket.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/packet/cache/PortProtoPacket.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/packet/cache/TcpPacket.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/packet/cache/UdpPacket.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/routing/PathCostTask.java [new file with mode: 0644]
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/routing/PathMapTask.java [new file with mode: 0644]
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/routing/RemovePathCostTask.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/routing/RemovePathMapTask.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/routing/SetPathCostTask.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/routing/SetPathMapTask.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/util/flow/cond/FlowCondUtils.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/util/pathpolicy/PathPolicyUtils.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/vnode/FlowFilterTask.java [new file with mode: 0644]
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/vnode/RemoveFlowFilterTask.java
manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/vnode/SetFlowFilterTask.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/packet/cache/TcpPacketTest.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/packet/cache/UdpPacketTest.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/util/flow/cond/FlowCondUtilsTest.java
manager/implementation/src/test/java/org/opendaylight/vtn/manager/internal/util/pathpolicy/PathPolicyUtilsTest.java
manager/neutron/src/main/java/org/opendaylight/vtn/manager/neutron/impl/VTNManagerService.java

diff --git a/manager/api/src/main/java/org/opendaylight/vtn/manager/packet/EtherTypePacket.java b/manager/api/src/main/java/org/opendaylight/vtn/manager/packet/EtherTypePacket.java
new file mode 100644 (file)
index 0000000..338bb70
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2016 NEC Corporation. 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.vtn.manager.packet;
+
+import static org.opendaylight.vtn.manager.util.NumberUtils.toBytes;
+import static org.opendaylight.vtn.manager.util.NumberUtils.toShort;
+
+import java.util.EnumMap;
+import java.util.Map;
+
+import com.google.common.collect.ImmutableMap;
+
+import org.opendaylight.vtn.manager.util.EtherTypes;
+
+/**
+ * {@code EtherTypePacket} describes an layer 2 packet that contains Ethernet
+ * type and layer 3 packet.
+ *
+ * @param <T>  The actual type of class that extends this class.
+ * @since      Boron
+ */
+public abstract class EtherTypePacket<T extends EtherTypePacket>
+    extends Packet {
+    /**
+     * A set of supported payload types.
+     */
+    private static final Map<EtherTypes, Class<? extends Packet>> PAYLOAD_TYPES;
+
+    /**
+     * The field name that indicates the Ethernet type.
+     */
+    static final String  ETHT = "EtherType";
+
+    /**
+     * Initialize static fields.
+     */
+    static {
+        // Initialize the payload types.
+        Map<EtherTypes, Class<? extends Packet>> typeMap =
+            new EnumMap<>(EtherTypes.class);
+        typeMap.put(EtherTypes.IPV4, IPv4.class);
+        typeMap.put(EtherTypes.ARP, ARP.class);
+        typeMap.put(EtherTypes.VLAN, IEEE8021Q.class);
+        PAYLOAD_TYPES = ImmutableMap.copyOf(typeMap);
+    }
+
+    /**
+     * Determine the payload type for the given Ethernet type.
+     *
+     * @param type  The Ethernet type value.
+     * @return  A class for the payload type.
+     *          {@code null} if no payload type is defined for the given
+     *          Ethernet type.
+     */
+    static final Class<? extends Packet> getPayloadClass(short type) {
+        EtherTypes etype = EtherTypes.forValue(type);
+        return (etype == null) ? null : PAYLOAD_TYPES.get(etype);
+    }
+
+    /**
+     * Return the Ethernet type configured in this instance.
+     *
+     * @return  The Ethernet type.
+     */
+    public final short getEtherType() {
+        return getShort(ETHT);
+    }
+
+    /**
+     * Set the Ethernet type that determines the type of the payload for
+     * this instance.
+     *
+     * @param type  The Ethernet type.
+     * @return  This instance.
+     */
+    public final T setEtherType(short type) {
+        getHeaderFieldMap().put(ETHT, toBytes(type));
+
+        @SuppressWarnings("unchecked")
+        T packet = (T)this;
+        return packet;
+    }
+
+    /**
+     * Store the value of fields read from data stream.
+     *
+     * @param name   The name of the header field.
+     * @param value  The value to be associated with the specified header
+     *               field. {@code null} cannot be specified.
+     */
+    @Override
+    protected final void setHeaderField(String name, byte[] value) {
+        if (name.equals(ETHT)) {
+            short etype = toShort(value);
+            setPayloadClass(getPayloadClass(etype));
+        }
+
+        super.setHeaderField(name, value);
+    }
+
+    // Object
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final T clone() {
+        @SuppressWarnings("unchecked")
+        T packet = (T)super.clone();
+        return packet;
+    }
+}
index 9b6cef09139e8f3c903dc4b8eebcd427c8420b7a..dcb0de4864837c1f1ca6bf3514cf47e0756530db 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2013, 2016 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,
@@ -8,16 +8,11 @@
 
 package org.opendaylight.vtn.manager.packet;
 
-import static org.opendaylight.vtn.manager.util.NumberUtils.toBytes;
-import static org.opendaylight.vtn.manager.util.NumberUtils.toShort;
+import static org.opendaylight.vtn.manager.packet.EtherTypePacket.ETHT;
 
-import java.util.EnumMap;
 import java.util.Map;
 
-import com.google.common.collect.ImmutableMap;
-
 import org.opendaylight.vtn.manager.util.EtherAddress;
-import org.opendaylight.vtn.manager.util.EtherTypes;
 
 /**
  * {@code Ethernet} describes an Ethernet frame.
@@ -29,7 +24,7 @@ import org.opendaylight.vtn.manager.util.EtherTypes;
  *
  * @since  Beryllium
  */
-public class Ethernet extends Packet {
+public class Ethernet extends EtherTypePacket<Ethernet> {
     /**
      * The number of bits in the Ethernet header.
      */
@@ -45,21 +40,11 @@ public class Ethernet extends Packet {
      */
     private static final String  SMAC = "SourceMACAddress";
 
-    /**
-     * The field name that indicates the Ethernet type.
-     */
-    static final String  ETHT = "EtherType";
-
     /**
      * A map that determines the IPv4 packet header format.
      */
     private static final Map<String, HeaderField>  HEADER_FORMAT;
 
-    /**
-     * A set of supported payload types.
-     */
-    private static final Map<EtherTypes, Class<? extends Packet>> PAYLOAD_TYPES;
-
     /**
      * Initialize static fields.
      */
@@ -71,27 +56,6 @@ public class Ethernet extends Packet {
             addByte(SMAC, addrSize).
             addNumber(ETHT, Short.SIZE).
             build();
-
-        // Initialize the payload types.
-        Map<EtherTypes, Class<? extends Packet>> typeMap =
-            new EnumMap<>(EtherTypes.class);
-        typeMap.put(EtherTypes.IPV4, IPv4.class);
-        typeMap.put(EtherTypes.ARP, ARP.class);
-        typeMap.put(EtherTypes.VLAN, IEEE8021Q.class);
-        PAYLOAD_TYPES = ImmutableMap.copyOf(typeMap);
-    }
-
-    /**
-     * Determine the payload type for the given Ethernet type.
-     *
-     * @param type  The Ethernet type value.
-     * @return  A class for the payload type.
-     *          {@code null} if no payload type is defined for the given
-     *          Ethernet type.
-     */
-    static Class<? extends Packet> getPayloadClass(short type) {
-        EtherTypes etype = EtherTypes.forValue(type);
-        return (etype == null) ? null : PAYLOAD_TYPES.get(etype);
     }
 
     /**
@@ -114,15 +78,6 @@ public class Ethernet extends Packet {
         return getHeaderFieldMap().get(SMAC);
     }
 
-    /**
-     * Gets the etherType stored.
-     *
-     * @return  The Ethernet type.
-     */
-    public short getEtherType() {
-        return getShort(ETHT);
-    }
-
     /**
      * Sets the destination MAC address for the current Ethernet object.
      *
@@ -147,17 +102,6 @@ public class Ethernet extends Packet {
         return this;
     }
 
-    /**
-     * Sets the etherType for the current Ethernet object.
-     *
-     * @param type  The Ethernet type.
-     * @return  This instance.
-     */
-    public Ethernet setEtherType(short type) {
-        getHeaderFieldMap().put(ETHT, toBytes(type));
-        return this;
-    }
-
     // Packet
 
     /**
@@ -177,31 +121,4 @@ public class Ethernet extends Packet {
     protected Map<String, HeaderField> getHeaderFormat() {
         return HEADER_FORMAT;
     }
-
-    /**
-     * Stores the value of fields read from data stream.
-     *
-     * @param name   The name of the header field.
-     * @param value  The value to be associated with the specified header
-     *               field. {@code null} cannot be specified.
-     */
-    @Override
-    protected void setHeaderField(String name, byte[] value) {
-        if (name.equals(ETHT)) {
-            short etype = toShort(value);
-            setPayloadClass(getPayloadClass(etype));
-        }
-
-        super.setHeaderField(name, value);
-    }
-
-    // Object
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public Ethernet clone() {
-        return (Ethernet)super.clone();
-    }
 }
index 39a2cb5164ebfbac1bfe8d9a043d65a7e18a2bf6..84df3eda00ff7ac394090bc236c7fa6f1f2ef4b0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2013, 2016 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,
@@ -8,10 +8,8 @@
 
 package org.opendaylight.vtn.manager.packet;
 
-import static org.opendaylight.vtn.manager.packet.Ethernet.ETHT;
-import static org.opendaylight.vtn.manager.packet.Ethernet.getPayloadClass;
+import static org.opendaylight.vtn.manager.packet.EtherTypePacket.ETHT;
 import static org.opendaylight.vtn.manager.util.NumberUtils.toBytes;
-import static org.opendaylight.vtn.manager.util.NumberUtils.toShort;
 
 import java.util.Map;
 
@@ -25,7 +23,7 @@ import java.util.Map;
  *
  * @since  Beryllium
  */
-public final class IEEE8021Q extends Packet {
+public final class IEEE8021Q extends EtherTypePacket<IEEE8021Q> {
     /**
      * The number of bits in the VLAN tag.
      */
@@ -105,15 +103,6 @@ public final class IEEE8021Q extends Packet {
         return getShort(VID);
     }
 
-    /**
-     * Gets the Ethernet type stored.
-     *
-     * @return  The Ethernet type.
-     */
-    public short getEtherType() {
-        return getShort(ETHT);
-    }
-
     /**
      * Sets the priority code point(PCP) for the current IEEE 802.1Q object
      * instance.
@@ -149,17 +138,6 @@ public final class IEEE8021Q extends Packet {
         return this;
     }
 
-    /**
-     * Sets the etherType for the current IEEE 802.1Q object instance.
-     *
-     * @param type  The Ethernet type.
-     * @return  This instance.
-     */
-    public IEEE8021Q setEtherType(short type) {
-        getHeaderFieldMap().put(ETHT, toBytes(type));
-        return this;
-    }
-
     // Packet
 
     /**
@@ -179,31 +157,4 @@ public final class IEEE8021Q extends Packet {
     protected Map<String, HeaderField> getHeaderFormat() {
         return HEADER_FORMAT;
     }
-
-    /**
-     * Stores the value of fields read from data stream.
-     *
-     * @param name   The name of the header field.
-     * @param value  The value to be associated with the specified header
-     *               field. {@code null} cannot be specified.
-     */
-    @Override
-    protected void setHeaderField(String name, byte[] value) {
-        if (name.equals(ETHT)) {
-            short etype = toShort(value);
-            setPayloadClass(getPayloadClass(etype));
-        }
-
-        super.setHeaderField(name, value);
-    }
-
-    // Object
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public IEEE8021Q clone() {
-        return (IEEE8021Q)super.clone();
-    }
 }
diff --git a/manager/api/src/main/java/org/opendaylight/vtn/manager/packet/PortPacket.java b/manager/api/src/main/java/org/opendaylight/vtn/manager/packet/PortPacket.java
new file mode 100644 (file)
index 0000000..f2d0c98
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2016 NEC Corporation. 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.vtn.manager.packet;
+
+import static org.opendaylight.vtn.manager.util.NumberUtils.toBytes;
+
+/**
+ * Abstract class that describes protocol packet which identifies the service
+ * using 16-bit port number.
+ *
+ * @param <T>  The actual type of this packet.
+ * @since      Boron
+ */
+public abstract class PortPacket<T extends PortPacket> extends Packet {
+    /**
+     * The field name that indicates the source port number.
+     */
+    static final String  SRCPORT = "SourcePort";
+
+    /**
+     * The field name that indicates the destination port number.
+     */
+    static final String  DESTPORT = "DestinationPort";
+
+    /**
+     * Construct a new instance.
+     */
+    PortPacket() {
+    }
+
+    /**
+     * Return the source port number configured in this instance.
+     *
+     * @return  The source port number.
+     */
+    public final short getSourcePort() {
+        return getShort(SRCPORT);
+    }
+
+    /**
+     * Return the destination port number configured in this instance.
+     *
+     * @return  The destination port number.
+     */
+    public final short getDestinationPort() {
+        return getShort(DESTPORT);
+    }
+
+    /**
+     * Set the source port number into this instance.
+     *
+     * @param port  The source port number.
+     * @return  This instance.
+     */
+    public final T setSourcePort(short port) {
+        return setPort(SRCPORT, port);
+    }
+
+    /**
+     * Set the destination port number into this instance.
+     *
+     * @param port  The destination port number.
+     * @return  This instance.
+     */
+    public final T setDestinationPort(short port) {
+        return setPort(DESTPORT, port);
+    }
+
+    /**
+     * Set the port number into this instance.
+     *
+     * @param field  The name of the field.
+     * @param port   The port number to set.
+     * @return  This instance.
+     */
+    private T setPort(String field, short port) {
+        getHeaderFieldMap().put(field, toBytes(port));
+
+        @SuppressWarnings("unchecked")
+        T packet = (T)this;
+        return packet;
+    }
+
+    // Object
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final T clone() {
+        @SuppressWarnings("unchecked")
+        T packet = (T)super.clone();
+        return packet;
+    }
+}
index 565174f403a8aa811f5fcf898f47bba95ee55d00..5bbe3afbcf468bbe99bfe770b09a7aa16b738bd6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2013, 2016 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,
@@ -26,22 +26,12 @@ import java.util.Map;
  *
  * @since  Beryllium
  */
-public final class TCP extends Packet {
+public final class TCP extends PortPacket<TCP> {
     /**
      * The number of bits in the TCP header, excluding options.
      */
     private static final int  HEADER_SIZE = 160;
 
-    /**
-     * The field name that indicates the source port number.
-     */
-    private static final String  SRCPORT = "SourcePort";
-
-    /**
-     * The field name that indicates the destination port number.
-     */
-    private static final String  DESTPORT = "DestinationPort";
-
     /**
      * The field name that indicates the TCP sequence number.
      */
@@ -120,28 +110,6 @@ public final class TCP extends Packet {
             build();
     }
 
-    /**
-     * Sets the TCP source port for the current TCP object instance.
-     *
-     * @param port  The source port number.
-     * @return  This instance.
-     */
-    public TCP setSourcePort(short port) {
-        getHeaderFieldMap().put(SRCPORT, toBytes(port));
-        return this;
-    }
-
-    /**
-     * Sets the TCP destination port for the current TCP object instance.
-     *
-     * @param port  The destination port number.
-     * @return  This instance.
-     */
-    public TCP setDestinationPort(short port) {
-        getHeaderFieldMap().put(DESTPORT, toBytes(port));
-        return this;
-    }
-
     /**
      * Sets the TCP sequence number for the current TCP object instance.
      *
@@ -230,24 +198,6 @@ public final class TCP extends Packet {
         return this;
     }
 
-    /**
-     * Gets the stored source port value of TCP header.
-     *
-     * @return  The source port number.
-     */
-    public short getSourcePort() {
-        return getShort(SRCPORT);
-    }
-
-    /**
-     * Gets the stored destination port value of TCP header.
-     *
-     * @return  The destination port number.
-     */
-    public short getDestinationPort() {
-        return getShort(DESTPORT);
-    }
-
     /**
      * Return the TCP sequence number.
      *
@@ -339,14 +289,4 @@ public final class TCP extends Packet {
     protected Map<String, HeaderField> getHeaderFormat() {
         return HEADER_FORMAT;
     }
-
-    // Object
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public TCP clone() {
-        return (TCP)super.clone();
-    }
 }
index 9fdaa83f92b8779a25217d1520953bb9fe725419..f8aab4fa5a5c824857d341d047d482bfcd99dc14 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2013, 2016 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,
@@ -22,22 +22,12 @@ import java.util.Map;
  *
  * @since  Beryllium
  */
-public final class UDP extends Packet {
+public final class UDP extends PortPacket<UDP> {
     /**
      * The number of bits in the UDP header.
      */
     private static final int  HEADER_SIZE = 64;
 
-    /**
-     * The field name that indicates the source port number.
-     */
-    private static final String  SRCPORT = "SourcePort";
-
-    /**
-     * The field name that indicates the destination port number.
-     */
-    private static final String  DESTPORT = "DestinationPort";
-
     /**
      * The field name that indicates the packet length.
      */
@@ -65,24 +55,6 @@ public final class UDP extends Packet {
             build();
     }
 
-    /**
-     * Get the stored source port.
-     *
-     * @return  The source port number.
-     */
-    public short getSourcePort() {
-        return getShort(SRCPORT);
-    }
-
-    /**
-     * Get the stored destination port.
-     *
-     * @return  The destination port number.
-     */
-    public short getDestinationPort() {
-        return getShort(DESTPORT);
-    }
-
     /**
      * Gets the stored length of UDP packet.
      *
@@ -101,28 +73,6 @@ public final class UDP extends Packet {
         return getShort(CHECKSUM);
     }
 
-    /**
-     * Sets the sourcePort value for the current UDP object instance.
-     *
-     * @param port  The source port number.
-     * @return  This instance.
-     */
-    public UDP setSourcePort(short port) {
-        getHeaderFieldMap().put(SRCPORT, toBytes(port));
-        return this;
-    }
-
-    /**
-     * Sets the destinationPort value for the current UDP object instance.
-     *
-     * @param port  The destination port number.
-     * @return  This instance.
-     */
-    public UDP setDestinationPort(short port) {
-        getHeaderFieldMap().put(DESTPORT, toBytes(port));
-        return this;
-    }
-
     /**
      * Set the UDP header length value for the current UDP object instance.
      *
@@ -164,14 +114,4 @@ public final class UDP extends Packet {
     protected Map<String, HeaderField> getHeaderFormat() {
         return HEADER_FORMAT;
     }
-
-    // Object
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public UDP clone() {
-        return (UDP)super.clone();
-    }
 }
index 159d206971c658349dce69b72850a5a6f1de3368..23ab0f07d558a51df6adab3b8d1f0af325367fab 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2015, 2016 NEC Corporation. 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,
@@ -21,7 +21,7 @@ import org.opendaylight.vtn.manager.TestBase;
  */
 public class EthernetTest extends TestBase {
     /**
-     * Test case for {@link Ethernet#getPayloadClass(short)}.
+     * Test case for {@link EtherTypePacket#getPayloadClass(short)}.
      */
     @Test
     public void testGetPayloadClass() {
@@ -36,9 +36,12 @@ public class EthernetTest extends TestBase {
             assertEquals(null, Ethernet.getPayloadClass(type));
         }
 
-        assertEquals(IPv4.class, Ethernet.getPayloadClass((short)0x0800));
-        assertEquals(ARP.class, Ethernet.getPayloadClass((short)0x0806));
-        assertEquals(IEEE8021Q.class, Ethernet.getPayloadClass((short)0x8100));
+        assertEquals(IPv4.class,
+                     EtherTypePacket.getPayloadClass((short)0x0800));
+        assertEquals(ARP.class,
+                     EtherTypePacket.getPayloadClass((short)0x0806));
+        assertEquals(IEEE8021Q.class,
+                     EtherTypePacket.getPayloadClass((short)0x8100));
     }
 
     /**
diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/flow/cond/FlowMatchTask.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/flow/cond/FlowMatchTask.java
new file mode 100644 (file)
index 0000000..dbbd5b3
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2016 NEC Corporation. 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.vtn.manager.internal.flow.cond;
+
+import java.util.List;
+
+import org.opendaylight.vtn.manager.VTNException;
+
+import org.opendaylight.vtn.manager.internal.TxContext;
+import org.opendaylight.vtn.manager.internal.VTNManagerProvider;
+import org.opendaylight.vtn.manager.internal.flow.remove.AllFlowRemover;
+import org.opendaylight.vtn.manager.internal.util.flow.cond.FlowCondUtils;
+import org.opendaylight.vtn.manager.internal.util.rpc.RpcOutputGenerator;
+import org.opendaylight.vtn.manager.internal.util.tx.AbstractTxTask;
+import org.opendaylight.vtn.manager.internal.util.tx.CompositeTxTask;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VnodeName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnUpdateType;
+
+/**
+ * Abstract base class for a task that updates the flow match configurations
+ * in the flow condition.
+ *
+ * @param <T>  The type of MD-SAL datastore transaction task that updates
+ *             flow match configuration.
+ * @param <O>  The type of the output of the RPC.
+ */
+public abstract class FlowMatchTask<T extends AbstractTxTask<VtnUpdateType>, O>
+    extends CompositeTxTask<VtnUpdateType, T>
+    implements RpcOutputGenerator<List<VtnUpdateType>, O> {
+    /**
+     * The name of the target flow condition.
+     */
+    private final VnodeName  nodeName;
+
+    /**
+     * Construct a new instance.
+     *
+     * @param vname  A {@link VnodeName} instance that contains the name of the
+     *               target flow condition.
+     * @param tasks  A list of tasks that update flow match configuration.
+     */
+    protected FlowMatchTask(VnodeName vname, List<T> tasks) {
+        super(tasks);
+        nodeName = vname;
+    }
+
+    // CompositeTxTask
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected final void onStarted(TxContext ctx) throws VTNException {
+        // Ensure that the target flow condition is present.
+        FlowCondUtils.checkPresent(ctx.getReadWriteTransaction(), nodeName);
+    }
+
+    // TxTask
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final void onSuccess(VTNManagerProvider provider,
+                                List<VtnUpdateType> result) {
+        for (VtnUpdateType status: result) {
+            if (status != null) {
+                // REVISIT: Select flow entries affected by the change.
+                addBackgroundTask(provider.removeFlows(new AllFlowRemover()));
+                break;
+            }
+        }
+    }
+}
index b34145146f2d40ba8c7b085750a80917624d8211..6359ba53cc916aeff84f401d5b014bcf340c7d8d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 NEC Corporation.  All rights reserved.
+ * Copyright (c) 2015, 2016 NEC Corporation. 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,
@@ -75,8 +75,7 @@ public final class RemoveFlowConditionTask
         throws VTNException {
         if (current == null) {
             // The target flow condition is not present.
-            String name = FlowCondUtils.getName(getTargetPath());
-            throw FlowCondUtils.getNotFoundException(name);
+            throw FlowCondUtils.getNotFoundException(getTargetPath());
         }
     }
 
index 2be2e0aa30cd94976c18b3bf236518156f28bc81..3a6a2dccb12353b220a67c1fd566786f40c9a175 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2015, 2016 NEC Corporation. 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,
@@ -14,18 +14,9 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import org.opendaylight.vtn.manager.VTNException;
-
-import org.opendaylight.vtn.manager.internal.TxContext;
-import org.opendaylight.vtn.manager.internal.VTNManagerProvider;
-import org.opendaylight.vtn.manager.internal.flow.remove.AllFlowRemover;
 import org.opendaylight.vtn.manager.internal.util.flow.cond.FlowCondUtils;
 import org.opendaylight.vtn.manager.internal.util.rpc.RpcException;
-import org.opendaylight.vtn.manager.internal.util.rpc.RpcOutputGenerator;
 import org.opendaylight.vtn.manager.internal.util.rpc.RpcUtils;
-import org.opendaylight.vtn.manager.internal.util.tx.CompositeTxTask;
-
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.flow.cond.rev150313.RemoveFlowConditionMatchInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.flow.cond.rev150313.RemoveFlowConditionMatchOutput;
@@ -43,14 +34,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnUpda
  * @see #create(RemoveFlowConditionMatchInput)
  */
 public final class RemoveFlowMatchTask
-    extends CompositeTxTask<VtnUpdateType, RemoveMatchTask>
-    implements RpcOutputGenerator<List<VtnUpdateType>,
-                                  RemoveFlowConditionMatchOutput> {
-    /**
-     * The name of the target flow condition.
-     */
-    private final VnodeName  nodeName;
-
+    extends FlowMatchTask<RemoveMatchTask, RemoveFlowConditionMatchOutput> {
     /**
      * Construct a new task that removes all the given flow match
      * configurations from the given flow condition.
@@ -92,37 +76,7 @@ public final class RemoveFlowMatchTask
      * @param tasks  A list of tasks that delete flow match configuration.
      */
     private RemoveFlowMatchTask(VnodeName vname, List<RemoveMatchTask> tasks) {
-        super(tasks);
-        nodeName = vname;
-    }
-
-    // CompositeTxTask
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected void onStarted(TxContext ctx) throws VTNException {
-        // Ensure that the target flow condition is present.
-        ReadWriteTransaction tx = ctx.getReadWriteTransaction();
-        FlowCondUtils.checkPresent(tx, nodeName);
-    }
-
-    // TxTask
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onSuccess(VTNManagerProvider provider,
-                          List<VtnUpdateType> result) {
-        for (VtnUpdateType status: result) {
-            if (status != null) {
-                // REVISIT: Select flow entries affected by the change.
-                addBackgroundTask(provider.removeFlows(new AllFlowRemover()));
-                break;
-            }
-        }
+        super(vname, tasks);
     }
 
     // RpcOutputGenerator
index 61638af36e92c071d4c19b9c33d51f20225b7b64..202c44bcab1aeaa4f0a0b4fc405d01da7eeff71b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 NEC Corporation.  All rights reserved.
+ * Copyright (c) 2015, 2016 NEC Corporation. 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,
@@ -39,11 +39,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnUpda
  */
 public final class SetFlowConditionTask extends PutDataTask<VtnFlowCondition>
     implements RpcOutputGenerator<VtnUpdateType, SetFlowConditionOutput> {
-    /**
-     * The name of the target flow condition.
-     */
-    private final String  name;
-
     /**
      * Set {@code true} if the target flow condition is required to be present.
      */
@@ -99,7 +94,6 @@ public final class SetFlowConditionTask extends PutDataTask<VtnFlowCondition>
                                  VtnFlowCondition vfc, boolean repl,
                                  boolean pr) {
         super(LogicalDatastoreType.OPERATIONAL, path, vfc, repl);
-        name = nm;
         present = pr;
     }
 
@@ -128,7 +122,7 @@ public final class SetFlowConditionTask extends PutDataTask<VtnFlowCondition>
         throws VTNException {
         if (current == null && present) {
             // The target flow condition is not present.
-            throw FlowCondUtils.getNotFoundException(name);
+            throw FlowCondUtils.getNotFoundException(getTargetPath());
         }
     }
 
index 6410c1aaf1070f7ded810dc395da0a4ebb3d3207..fff9ea54944a4b666d5a7b7e96d618d685deaeb2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 NEC Corporation.  All rights reserved.
+ * Copyright (c) 2015, 2016 NEC Corporation. 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,
@@ -14,19 +14,10 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import org.opendaylight.vtn.manager.VTNException;
-
-import org.opendaylight.vtn.manager.internal.TxContext;
-import org.opendaylight.vtn.manager.internal.VTNManagerProvider;
-import org.opendaylight.vtn.manager.internal.flow.remove.AllFlowRemover;
 import org.opendaylight.vtn.manager.internal.util.flow.cond.FlowCondUtils;
 import org.opendaylight.vtn.manager.internal.util.flow.cond.VTNFlowMatch;
 import org.opendaylight.vtn.manager.internal.util.rpc.RpcException;
-import org.opendaylight.vtn.manager.internal.util.rpc.RpcOutputGenerator;
 import org.opendaylight.vtn.manager.internal.util.rpc.RpcUtils;
-import org.opendaylight.vtn.manager.internal.util.tx.CompositeTxTask;
-
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
@@ -48,14 +39,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnUpda
  * @see #create(SetFlowConditionMatchInput)
  */
 public final class SetFlowMatchTask
-    extends CompositeTxTask<VtnUpdateType, SetMatchTask>
-    implements RpcOutputGenerator<List<VtnUpdateType>,
-                                  SetFlowConditionMatchOutput> {
-    /**
-     * The name of the target flow condition.
-     */
-    private final VnodeName  nodeName;
-
+    extends FlowMatchTask<SetMatchTask, SetFlowConditionMatchOutput> {
     /**
      * Construct a new task that set all the given flow match configurations
      * into the given flow condition.
@@ -102,37 +86,7 @@ public final class SetFlowMatchTask
      * @param tasks  A list of tasks that set flow match configuration.
      */
     private SetFlowMatchTask(VnodeName vname, List<SetMatchTask> tasks) {
-        super(tasks);
-        nodeName = vname;
-    }
-
-    // CompositeTxTask
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected void onStarted(TxContext ctx) throws VTNException {
-        // Ensure that the target flow condition is present.
-        ReadWriteTransaction tx = ctx.getReadWriteTransaction();
-        FlowCondUtils.checkPresent(tx, nodeName);
-    }
-
-    // TxTask
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onSuccess(VTNManagerProvider provider,
-                          List<VtnUpdateType> result) {
-        for (VtnUpdateType status: result) {
-            if (status != null) {
-                // REVISIT: Select flow entries affected by the change.
-                addBackgroundTask(provider.removeFlows(new AllFlowRemover()));
-                break;
-            }
-        }
+        super(vname, tasks);
     }
 
     // RpcOutputGenerator
index 0d1919657b707a93c86c551a83a17cc6131f365e..e37a85debad2f88b304c7c331d627ff5888d30e0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2014, 2016 NEC Corporation. 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,
@@ -21,7 +21,7 @@ public interface CachedPacket extends Cloneable {
      *
      * <p>
      *   Note that modification to this instance is not applied to the
-     *   returned until {@link #commit(CachedPacketContext)} is called.
+     *   returned packet until {@link #commit(CachedPacketContext)} is called.
      * </p>
      *
      * @return  A {@link Packet} instance.
index 3c9e84789de33539ac55380962707691b45625f0..3ccb027d7865a06e863f0afab6258321910725b7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2014, 2016 NEC Corporation. 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,
@@ -15,7 +15,7 @@ import static org.opendaylight.vtn.manager.util.NumberUtils.MASK_SHORT;
 import java.util.Set;
 
 import org.opendaylight.vtn.manager.VTNException;
-import org.opendaylight.vtn.manager.packet.Packet;
+import org.opendaylight.vtn.manager.packet.PortPacket;
 import org.opendaylight.vtn.manager.util.NumberUtils;
 
 import org.opendaylight.vtn.manager.internal.util.flow.action.VTNSetPortDstAction;
@@ -32,7 +32,7 @@ import org.opendaylight.vtn.manager.internal.util.rpc.RpcException;
  *
  * @param <T>  Type of packet.
  */
-public abstract class PortProtoPacket<T extends Packet>
+public abstract class PortProtoPacket<T extends PortPacket<T>>
     implements L4Packet, Layer4PortHeader {
     /**
      * A pseudo port number which indicates the port number is not specified.
@@ -49,15 +49,20 @@ public abstract class PortProtoPacket<T extends Packet>
      */
     private static final int  MASK_CLEAR_LSB = ~1;
 
+    /**
+     * A raw packet associated with this instance.
+     */
+    private T  rawPacket;
+
     /**
      * Cached values in a protocol header.
      */
-    private Values  values = new Values();
+    private Values<T>  values = new Values<>();
 
     /**
      * Protocol header values to be set.
      */
-    private Values  modifiedValues;
+    private Values<T>  modifiedValues;
 
     /**
      * Set {@code true} if this instance is created by {@link #clone()}.
@@ -66,8 +71,11 @@ public abstract class PortProtoPacket<T extends Packet>
 
     /**
      * This class describes modifiable fields in a protocol hedaer.
+     *
+     * @param <T>  Type of packet.
      */
-    private static final class Values implements Cloneable {
+    private static final class Values<T extends PortPacket<T>>
+        implements Cloneable {
         /**
          * The source port number.
          */
@@ -156,7 +164,7 @@ public abstract class PortProtoPacket<T extends Packet>
          *
          * @param packet  A {@link PortProtoPacket} instance.
          */
-        private void fill(PortProtoPacket packet) {
+        private void fill(PortProtoPacket<T> packet) {
             if (sourcePort == PORT_NONE) {
                 setSourcePort(packet.getRawSourcePort());
             }
@@ -171,9 +179,11 @@ public abstract class PortProtoPacket<T extends Packet>
          * @return  A shallow copy of this instance.
          */
         @Override
-        public Values clone() {
+        public Values<T> clone() {
             try {
-                return (Values)super.clone();
+                @SuppressWarnings("unchecked")
+                Values<T> v = (Values<T>)super.clone();
+                return v;
             } catch (CloneNotSupportedException e) {
                 // This should never happen.
                 throw new IllegalStateException("clone() failed", e);
@@ -222,14 +232,14 @@ public abstract class PortProtoPacket<T extends Packet>
      *
      * @param ipv4    An {@link Inet4Packet} instance that contains the given
      *                packet.
-     * @param packet  A {@link Packet} instance.
+     * @param packet  A {@link PortPacket} instance.
      * @param sumOff  Offset in bytes to the checksum field.
      * @return  A computed checksum.
      * @throws VTNException
      *    An error occurred.
      */
-    protected static final short computeChecksum(Inet4Packet ipv4,
-                                                 Packet packet, int sumOff)
+    protected static final short computeChecksum(
+        Inet4Packet ipv4, PortPacket<?> packet, int sumOff)
         throws VTNException {
         // Serialize the given packet.
         byte[] data;
@@ -252,13 +262,13 @@ public abstract class PortProtoPacket<T extends Packet>
      *
      * @param ipv4    An {@link Inet4Packet} instance that contains the given
      *                packet.
-     * @param packet  A {@link Packet} to be verified.
+     * @param packet  A {@link PortPacket} to be verified.
      * @return  {@code true} is returned only if the verification succeeded.
      * @throws VTNException
      *    An error occurred.
      */
     protected static final boolean verifyChecksum(Inet4Packet ipv4,
-                                                  Packet packet)
+                                                  PortPacket<?> packet)
         throws VTNException {
         // Serialize the given packet.
         byte[] data;
@@ -276,68 +286,31 @@ public abstract class PortProtoPacket<T extends Packet>
 
     /**
      * Construct a new instance.
+     *
+     * @param pkt  A raw packet instance.
      */
-    protected PortProtoPacket() {
+    protected PortProtoPacket(T pkt) {
+        rawPacket = pkt;
     }
 
     /**
-     * Return a {@link Packet} instance to set modified values.
+     * Return a {@link PortPacket} instance to set modified values.
      *
-     * @return  A {@link Packet} instance.
+     * @return  A {@link PortPacket} instance.
      */
     protected final T getPacketForWrite() {
-        T pkt = getPacketForWrite(cloned);
-        cloned = false;
+        T pkt;
+        if (cloned) {
+            pkt = rawPacket.clone();
+            rawPacket = pkt;
+            cloned = false;
+        } else {
+            pkt = rawPacket;
+        }
+
         return pkt;
     }
 
-    /**
-     * Derive the source port number from the packet.
-     *
-     * @return  A short integer value which represents the source port number.
-     */
-    protected abstract short getRawSourcePort();
-
-    /**
-     * Derive the destination port number from the packet.
-     *
-     * @return  A short integer value which represents the destination port
-     *          number.
-     */
-    protected abstract short getRawDestinationPort();
-
-    /**
-     * Set the source port number to the given packet.
-     *
-     * @param pkt   A {@link Packet} instance.
-     * @param port  A short integer value which indicates the source port.
-     */
-    protected abstract void setRawSourcePort(T pkt, short port);
-
-    /**
-     * Set the destination port number to the given packet.
-     *
-     * @param pkt   A {@link Packet} instance.
-     * @param port  A short integer value which indicates the destination port.
-     */
-    protected abstract void setRawDestinationPort(T pkt, short port);
-
-    /**
-     * Return a {@link Packet} instance to set modified values.
-     *
-     * @param doCopy {@code true} is passed if the packet configured in this
-     *               instance needs to be copied.
-     * @return  A {@link Packet} instance.
-     */
-    protected abstract T getPacketForWrite(boolean doCopy);
-
-    /**
-     * Return the name of the protocol.
-     *
-     * @return  The protocol name.
-     */
-    protected abstract String getProtocolName();
-
     /**
      * Construct flow match fields.
      *
@@ -366,13 +339,32 @@ public abstract class PortProtoPacket<T extends Packet>
      */
     public abstract FlowMatchType getDestinationMatchType();
 
+    /**
+     * Derive the source port number from the packet.
+     *
+     * @return  A short integer value which represents the source port number.
+     */
+    private short getRawSourcePort() {
+        return rawPacket.getSourcePort();
+    }
+
+    /**
+     * Derive the destination port number from the packet.
+     *
+     * @return  A short integer value which represents the destination port
+     *          number.
+     */
+    private short getRawDestinationPort() {
+        return rawPacket.getDestinationPort();
+    }
+
     /**
      * Return a {@link Values} instance that keeps current values for
      * protocol header fields.
      *
      * @return  A {@link Values} instance.
      */
-    private Values getValues() {
+    private Values<T> getValues() {
         return (modifiedValues == null) ? values : modifiedValues;
     }
 
@@ -382,7 +374,7 @@ public abstract class PortProtoPacket<T extends Packet>
      *
      * @return  A {@link Values} instance.
      */
-    private Values getModifiedValues() {
+    private Values<T> getModifiedValues() {
         if (modifiedValues == null) {
             values.fill(this);
             modifiedValues = values.clone();
@@ -393,6 +385,14 @@ public abstract class PortProtoPacket<T extends Packet>
 
     // CachedPacket
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final T getPacket() {
+        return rawPacket;
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -410,7 +410,7 @@ public abstract class PortProtoPacket<T extends Packet>
             if (values.getSourcePort() != src) {
                 // Source port was modified.
                 pkt = getPacketForWrite();
-                setRawSourcePort(pkt, (short)src);
+                pkt.setSourcePort((short)src);
                 mod = true;
             } else if (pctx.hasMatchField(getSourceMatchType())) {
                 // Source port in the original packet is unchanged and it will
@@ -425,7 +425,7 @@ public abstract class PortProtoPacket<T extends Packet>
                 if (pkt == null) {
                     pkt = getPacketForWrite();
                 }
-                setRawDestinationPort(pkt, (short)dst);
+                pkt.setDestinationPort((short)dst);
                 mod = true;
             } else if (pctx.hasMatchField(getDestinationMatchType())) {
                 // Destination port in the original packet is unchanged and
@@ -442,10 +442,11 @@ public abstract class PortProtoPacket<T extends Packet>
      * {@inheritDoc}
      */
     @Override
-    public final PortProtoPacket clone() {
+    public final PortProtoPacket<T> clone() {
         try {
-            PortProtoPacket p = (PortProtoPacket)super.clone();
-            Values v = p.values;
+            @SuppressWarnings("unchecked")
+            PortProtoPacket<T> p = (PortProtoPacket<T>)super.clone();
+            Values<T> v = p.values;
             p.values = v.clone();
 
             v = p.modifiedValues;
@@ -469,7 +470,7 @@ public abstract class PortProtoPacket<T extends Packet>
     @Override
     public final VTNLayer4PortMatch createMatch(Set<FlowMatchType> fields)
         throws RpcException {
-        Values v = values;
+        Values<T> v = values;
         v.fill(this);
 
         VTNPortRange src = (fields.contains(getSourceMatchType()))
@@ -489,10 +490,10 @@ public abstract class PortProtoPacket<T extends Packet>
      */
     @Override
     public final int getSourcePort() {
-        Values v = getValues();
+        Values<T> v = getValues();
         int port = v.getSourcePort();
         if (port == PORT_NONE) {
-            short p = getRawSourcePort();
+            short p = rawPacket.getSourcePort();
             port = v.setSourcePort(p);
         }
 
@@ -504,7 +505,7 @@ public abstract class PortProtoPacket<T extends Packet>
      */
     @Override
     public final void setSourcePort(int port) {
-        Values v = getModifiedValues();
+        Values<T> v = getModifiedValues();
         v.setSourcePort(port);
     }
 
@@ -513,7 +514,7 @@ public abstract class PortProtoPacket<T extends Packet>
      */
     @Override
     public final int getDestinationPort() {
-        Values v = getValues();
+        Values<T> v = getValues();
         int port = v.getDestinationPort();
         if (port == PORT_NONE) {
             short p = getRawDestinationPort();
@@ -528,7 +529,7 @@ public abstract class PortProtoPacket<T extends Packet>
      */
     @Override
     public final void setDestinationPort(int port) {
-        Values v = getModifiedValues();
+        Values<T> v = getModifiedValues();
         v.setDestinationPort(port);
     }
 
@@ -541,8 +542,9 @@ public abstract class PortProtoPacket<T extends Packet>
     public void setDescription(StringBuilder builder) {
         int src = getSourcePort();
         int dst = getDestinationPort();
-        builder.append(getProtocolName()).
+        String proto = rawPacket.getClass().getSimpleName();
+        builder.append(proto).
             append("[src=").append(src).
-            append(",dst=").append(dst).append(']');
+            append(", dst=").append(dst).append(']');
     }
 }
index d85ddc8e3c720b80d5db37a59f6fbe79bece4ec7..bf1e6d3596489005cf0effa687c73aba95e39af4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015 NEC Corporation.  All rights reserved.
+ * Copyright (c) 2014, 2016 NEC Corporation. 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,
@@ -26,95 +26,17 @@ public final class TcpPacket extends PortProtoPacket<TCP>
      */
     private static final int  TCP_OFF_CHECKSUM = 16;
 
-    /**
-     * A {@link TCP} packet.
-     */
-    private TCP  packet;
-
     /**
      * Construct a new instance.
      *
      * @param tcp  A {@link TCP} instance.
      */
     public TcpPacket(TCP tcp) {
-        packet = tcp;
+        super(tcp);
     }
 
     // PortProtoPacket
 
-    /**
-     * Derive the source port number from the packet.
-     *
-     * @return  A short integer value which represents the source port number.
-     */
-    @Override
-    protected short getRawSourcePort() {
-        return packet.getSourcePort();
-    }
-
-    /**
-     * Derive the destination port number from the packet.
-     *
-     * @return  A short integer value which represents the destination port
-     *          number.
-     */
-    @Override
-    protected short getRawDestinationPort() {
-        return packet.getDestinationPort();
-    }
-
-    /**
-     * Set the source port number to the given packet.
-     *
-     * @param pkt   A {@link TCP} instance.
-     * @param port  A short integer value which indicates the source port.
-     */
-    @Override
-    protected void setRawSourcePort(TCP pkt, short port) {
-        pkt.setSourcePort(port);
-    }
-
-    /**
-     * Set the destination port number to the given packet.
-     *
-     * @param pkt   A {@link TCP} instance.
-     * @param port  A short integer value which indicates the destination port.
-     */
-    @Override
-    protected void setRawDestinationPort(TCP pkt, short port) {
-        pkt.setDestinationPort(port);
-    }
-
-    /**
-     * Return a {@link TCP} instance to set modified values.
-     *
-     * @param doCopy {@code true} is passed if the packet configured in this
-     *               instance needs to be copied.
-     * @return  A {@link TCP} instance.
-     */
-    @Override
-    protected TCP getPacketForWrite(boolean doCopy) {
-        TCP pkt;
-        if (doCopy) {
-            pkt = packet.clone();
-            packet = pkt;
-        } else {
-            pkt = packet;
-        }
-
-        return pkt;
-    }
-
-    /**
-     * Return the name of the protocol.
-     *
-     * @return  {@code "TCP"}.
-     */
-    @Override
-    protected String getProtocolName() {
-        return "TCP";
-    }
-
     /**
      * Construct TCP flow match fields.
      *
@@ -156,7 +78,7 @@ public final class TcpPacket extends PortProtoPacket<TCP>
      */
     @Override
     public boolean updateChecksum(Inet4Packet ipv4) throws VTNException {
-        short sum = packet.getChecksum();
+        short sum = getPacket().getChecksum();
         TCP pkt = getPacketForWrite();
         short newSum = computeChecksum(ipv4, pkt, TCP_OFF_CHECKSUM);
         boolean mod;
@@ -169,16 +91,4 @@ public final class TcpPacket extends PortProtoPacket<TCP>
 
         return mod;
     }
-
-    // CachedPacket
-
-    /**
-     * Return a {@link TCP} instance configured in this instance.
-     *
-     * @return  A {@link TCP} instance.
-     */
-    @Override
-    public TCP getPacket() {
-        return packet;
-    }
 }
index 47fa6ce7ebe7260094bed803768b6a9f4a2e1780..bfdb7ed58fd4318ea6695d502224f732fef21746 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015 NEC Corporation.  All rights reserved.
+ * Copyright (c) 2014, 2016 NEC Corporation. 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,
@@ -31,91 +31,13 @@ public final class UdpPacket extends PortProtoPacket<UDP>
      */
     private static final short  UDP_CKSUM_DISABLED = 0;
 
-    /**
-     * A {@link UDP} packet.
-     */
-    private UDP  packet;
-
     /**
      * Construct a new instance.
      *
      * @param udp  A {@link UDP} instance.
      */
     public UdpPacket(UDP udp) {
-        packet = udp;
-    }
-
-    /**
-     * Derive the source port number from the packet.
-     *
-     * @return  A short integer value which represents the source port number.
-     */
-    @Override
-    protected short getRawSourcePort() {
-        return packet.getSourcePort();
-    }
-
-    /**
-     * Derive the destination port number from the packet.
-     *
-     * @return  A short integer value which represents the destination port
-     *          number.
-     */
-    @Override
-    protected short getRawDestinationPort() {
-        return packet.getDestinationPort();
-    }
-
-    /**
-     * Set the source port number to the given packet.
-     *
-     * @param pkt   A {@link UDP} instance.
-     * @param port  A short integer value which indicates the source port.
-     */
-    @Override
-    protected void setRawSourcePort(UDP pkt, short port) {
-        pkt.setSourcePort(port);
-    }
-
-    /**
-     * Set the destination port number to the given packet.
-     *
-     * @param pkt   A {@link UDP} instance.
-     * @param port  A short integer value which indicates the destination port.
-     */
-    @Override
-    protected void setRawDestinationPort(UDP pkt, short port) {
-        pkt.setDestinationPort(port);
-    }
-
-    /**
-     * Return a {@link UDP} instance to set modified values.
-     *
-     * @param doCopy {@code true} is passed if the packet configured in this
-     *               instance needs to be copied.
-     * @return  A {@link UDP} instance.
-     */
-    @Override
-    protected UDP getPacketForWrite(boolean doCopy) {
-        UDP pkt;
-        if (doCopy) {
-            pkt = packet.clone();
-            packet = pkt;
-        } else {
-            pkt = packet;
-        }
-
-        return pkt;
-    }
-
-    /**
-     * Return the name of the protocol.
-     *
-     * @return  {@code "UDP"}.
-     */
-    @Override
-    protected String getProtocolName() {
-        return "UDP";
+        super(udp);
     }
 
     /**
@@ -161,7 +83,7 @@ public final class UdpPacket extends PortProtoPacket<UDP>
     public boolean updateChecksum(Inet4Packet ipv4) throws VTNException {
         // Update checksum only if the UDP packet contains a valid checksum.
         boolean mod = false;
-        short sum = packet.getChecksum();
+        short sum = getPacket().getChecksum();
         if (sum != 0) {
             UDP pkt = getPacketForWrite();
             short newSum = computeChecksum(ipv4, pkt, UDP_OFF_CHECKSUM);
@@ -177,16 +99,4 @@ public final class UdpPacket extends PortProtoPacket<UDP>
 
         return mod;
     }
-
-    // CachedPacket
-
-    /**
-     * Return a {@link UDP} instance configured in this instance.
-     *
-     * @return  A {@link UDP} instance.
-     */
-    @Override
-    public UDP getPacket() {
-        return packet;
-    }
 }
diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/routing/PathCostTask.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/routing/PathCostTask.java
new file mode 100644 (file)
index 0000000..efef822
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2016 NEC Corporation. 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.vtn.manager.internal.routing;
+
+import java.util.List;
+
+import org.opendaylight.vtn.manager.VTNException;
+
+import org.opendaylight.vtn.manager.internal.TxContext;
+import org.opendaylight.vtn.manager.internal.VTNManagerProvider;
+import org.opendaylight.vtn.manager.internal.util.pathpolicy.PathPolicyUtils;
+import org.opendaylight.vtn.manager.internal.util.rpc.RpcOutputGenerator;
+import org.opendaylight.vtn.manager.internal.util.tx.AbstractTxTask;
+import org.opendaylight.vtn.manager.internal.util.tx.CompositeTxTask;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnUpdateType;
+
+/**
+ * Abstract base class for a task that updates the path cost configurations
+ * in the path map.
+ *
+ * @param <T>  The type of MD-SAL datastore transaction task that updates
+ *             path cost configuration.
+ * @param <O>  The type of the output of the RPC.
+ */
+public abstract class PathCostTask<T extends AbstractTxTask<VtnUpdateType>, O>
+    extends CompositeTxTask<VtnUpdateType, T>
+    implements RpcOutputGenerator<List<VtnUpdateType>, O> {
+    /**
+     * Runtime context for updating the path policy.
+     */
+    private final PathPolicyRpcContext  context;
+
+    /**
+     * Construct a new instance.
+     *
+     * @param topo   The network topology graph.
+     * @param id     The identifier of the target path policy.
+     * @param tasks  A list of tasks that update link cost configuration.
+     */
+    protected PathCostTask(TopologyGraph topo, Integer id, List<T> tasks) {
+        super(tasks);
+        context = new PathPolicyRpcContext(topo, id);
+    }
+
+    // CompositeTxTask
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected final void onStarted(TxContext ctx) throws VTNException {
+        // Ensure that the target path policy is present.
+        Integer pid = context.getPolicyId();
+        ReadWriteTransaction tx = ctx.getReadWriteTransaction();
+        PathPolicyUtils.readVtnPathPolicy(tx, pid.intValue());
+
+        context.onStarted();
+    }
+
+    // TxTask
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final void onSuccess(VTNManagerProvider provider,
+                                List<VtnUpdateType> result) {
+        for (VtnUpdateType status: result) {
+            if (status != null) {
+                // Remove all flow entries affected by the target path policy.
+                addBackgroundTask(
+                    provider.removeFlows(context.getFlowRemover()));
+
+                context.onUpdated();
+                break;
+            }
+        }
+    }
+}
diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/routing/PathMapTask.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/routing/PathMapTask.java
new file mode 100644 (file)
index 0000000..cdeda40
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2016 NEC Corporation. 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.vtn.manager.internal.routing;
+
+import java.util.List;
+
+import org.opendaylight.vtn.manager.VTNException;
+
+import org.opendaylight.vtn.manager.internal.FlowRemover;
+import org.opendaylight.vtn.manager.internal.TxContext;
+import org.opendaylight.vtn.manager.internal.VTNManagerProvider;
+import org.opendaylight.vtn.manager.internal.flow.remove.AllFlowRemover;
+import org.opendaylight.vtn.manager.internal.flow.remove.TenantFlowRemover;
+import org.opendaylight.vtn.manager.internal.util.rpc.RpcOutputGenerator;
+import org.opendaylight.vtn.manager.internal.util.tx.AbstractTxTask;
+import org.opendaylight.vtn.manager.internal.util.tx.CompositeTxTask;
+import org.opendaylight.vtn.manager.internal.util.vnode.VTenantIdentifier;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnUpdateType;
+
+/**
+ * Abstract base class for a task that updates the path map configuration.
+ *
+ * @param <T>  The type of MD-SAL datastore transaction task that updates
+ *             path map configuration.
+ * @param <O>  The type of the output of the RPC.
+ */
+public abstract class PathMapTask<T extends AbstractTxTask<VtnUpdateType>, O>
+    extends CompositeTxTask<VtnUpdateType, T>
+    implements RpcOutputGenerator<List<VtnUpdateType>, O> {
+    /**
+     * The identifier for the target VTN.
+     *
+     * <p>
+     *   {@code null} means that the global path map is targeted.
+     * </p>
+     */
+    private final VTenantIdentifier  identifier;
+
+    /**
+     * Construct a new instance.
+     *
+     * @param ident  The identifier for the target VTN.
+     *               {@code null} means that the global path map is targeted.
+     * @param tasks  A list of tasks that update path map configuration.
+     */
+    protected PathMapTask(VTenantIdentifier ident, List<T> tasks) {
+        super(tasks);
+        identifier = ident;
+    }
+
+    // CompositeTxTask
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected final void onStarted(TxContext ctx) throws VTNException {
+        if (identifier != null) {
+            // Ensure that the target VTN is present.
+            identifier.fetch(ctx.getReadWriteTransaction());
+        }
+    }
+
+    // TxTask
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final void onSuccess(VTNManagerProvider provider,
+                                List<VtnUpdateType> result) {
+        for (VtnUpdateType status: result) {
+            if (status != null) {
+                // REVISIT: Select flow entries affected by the change.
+                FlowRemover remover = (identifier == null)
+                    ? new AllFlowRemover()
+                    : new TenantFlowRemover(identifier);
+                addBackgroundTask(provider.removeFlows(remover));
+                break;
+            }
+        }
+    }
+}
index d1f27fa12f91853a13ac73b015a9690b2325a729..2a8bc90b23ed1ba9aece45b77c12a038e45f01b7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2015, 2016 NEC Corporation. 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,
@@ -14,18 +14,10 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import org.opendaylight.vtn.manager.VTNException;
-
-import org.opendaylight.vtn.manager.internal.TxContext;
-import org.opendaylight.vtn.manager.internal.VTNManagerProvider;
 import org.opendaylight.vtn.manager.internal.util.inventory.NodeUtils;
 import org.opendaylight.vtn.manager.internal.util.pathpolicy.PathPolicyUtils;
 import org.opendaylight.vtn.manager.internal.util.rpc.RpcException;
-import org.opendaylight.vtn.manager.internal.util.rpc.RpcOutputGenerator;
 import org.opendaylight.vtn.manager.internal.util.rpc.RpcUtils;
-import org.opendaylight.vtn.manager.internal.util.tx.CompositeTxTask;
-
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.pathpolicy.rev150209.RemovePathCostInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.pathpolicy.rev150209.RemovePathCostOutput;
@@ -43,13 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnUpda
  * @see #create(TopologyGraph, RemovePathCostInput)
  */
 public final class RemovePathCostTask
-    extends CompositeTxTask<VtnUpdateType, RemoveCostTask>
-    implements RpcOutputGenerator<List<VtnUpdateType>, RemovePathCostOutput> {
-    /**
-     * Runtime context for updating the path policy.
-     */
-    private final PathPolicyRpcContext  context;
-
+    extends PathCostTask<RemoveCostTask, RemovePathCostOutput> {
     /**
      * Construct a new task that removes all the given link cost configurations
      * from the given path policy.
@@ -121,43 +107,7 @@ public final class RemovePathCostTask
      */
     private RemovePathCostTask(TopologyGraph topo, Integer id,
                                List<RemoveCostTask> tasks) {
-        super(tasks);
-        context = new PathPolicyRpcContext(topo, id);
-    }
-
-    // CompositeTxTask
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected void onStarted(TxContext ctx) throws VTNException {
-        // Ensure that the target path policy is present.
-        Integer pid = context.getPolicyId();
-        ReadWriteTransaction tx = ctx.getReadWriteTransaction();
-        PathPolicyUtils.readVtnPathPolicy(tx, pid.intValue());
-
-        context.onStarted();
-    }
-
-    // TxTask
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onSuccess(VTNManagerProvider provider,
-                          List<VtnUpdateType> result) {
-        for (VtnUpdateType status: result) {
-            if (status != null) {
-                // Remove all flow entries affected by the target path policy.
-                addBackgroundTask(
-                    provider.removeFlows(context.getFlowRemover()));
-
-                context.onUpdated();
-                break;
-            }
-        }
+        super(topo, id, tasks);
     }
 
     // RpcOutputGenerator
index d6f9d91d7bb75e1605cb7ff117019b7e66651a0c..5e5e51f5e6f89c4cd1ba3d5eb65762f899f96972 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2015, 2016 NEC Corporation. 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,
@@ -14,18 +14,9 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import org.opendaylight.vtn.manager.VTNException;
-
-import org.opendaylight.vtn.manager.internal.FlowRemover;
-import org.opendaylight.vtn.manager.internal.TxContext;
-import org.opendaylight.vtn.manager.internal.VTNManagerProvider;
-import org.opendaylight.vtn.manager.internal.flow.remove.AllFlowRemover;
-import org.opendaylight.vtn.manager.internal.flow.remove.TenantFlowRemover;
 import org.opendaylight.vtn.manager.internal.util.pathmap.PathMapUtils;
 import org.opendaylight.vtn.manager.internal.util.rpc.RpcException;
-import org.opendaylight.vtn.manager.internal.util.rpc.RpcOutputGenerator;
 import org.opendaylight.vtn.manager.internal.util.rpc.RpcUtils;
-import org.opendaylight.vtn.manager.internal.util.tx.CompositeTxTask;
 import org.opendaylight.vtn.manager.internal.util.vnode.VTenantIdentifier;
 
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -46,17 +37,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnUpda
  * @see #create(RemovePathMapInput)
  */
 public final class RemovePathMapTask
-    extends CompositeTxTask<VtnUpdateType, RemoveMapTask>
-    implements RpcOutputGenerator<List<VtnUpdateType>, RemovePathMapOutput> {
-    /**
-     * The identifier for the target VTN.
-     *
-     * <p>
-     *   {@code null} means that the global path map is targeted.
-     * </p>
-     */
-    private final VTenantIdentifier  identifier;
-
+    extends PathMapTask<RemoveMapTask, RemovePathMapOutput> {
     /**
      * Construct a new task that removes all the given path map configurations
      * from the global or VTN path map.
@@ -106,41 +87,7 @@ public final class RemovePathMapTask
      */
     private RemovePathMapTask(VTenantIdentifier ident,
                               List<RemoveMapTask> tasks) {
-        super(tasks);
-        identifier = ident;
-    }
-
-    // CompositeTxTask
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected void onStarted(TxContext ctx) throws VTNException {
-        if (identifier != null) {
-            // Ensure that the target VTN is present.
-            identifier.fetch(ctx.getReadWriteTransaction());
-        }
-    }
-
-    // TxTask
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onSuccess(VTNManagerProvider provider,
-                          List<VtnUpdateType> result) {
-        for (VtnUpdateType status: result) {
-            if (status != null) {
-                // REVISIT: Select flow entries affected by the change.
-                FlowRemover remover = (identifier == null)
-                    ? new AllFlowRemover()
-                    : new TenantFlowRemover(identifier);
-                addBackgroundTask(provider.removeFlows(remover));
-                break;
-            }
-        }
+        super(ident, tasks);
     }
 
     // RpcOutputGenerator
index 9d7ce1b22735cca6617af31df166238b1f6719c0..805394ee393050c3b596ecc2641c8ea3ef254c1a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2015, 2016 NEC Corporation. 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,
@@ -14,17 +14,9 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import org.opendaylight.vtn.manager.VTNException;
-
-import org.opendaylight.vtn.manager.internal.TxContext;
-import org.opendaylight.vtn.manager.internal.VTNManagerProvider;
 import org.opendaylight.vtn.manager.internal.util.pathpolicy.PathPolicyUtils;
 import org.opendaylight.vtn.manager.internal.util.rpc.RpcException;
-import org.opendaylight.vtn.manager.internal.util.rpc.RpcOutputGenerator;
 import org.opendaylight.vtn.manager.internal.util.rpc.RpcUtils;
-import org.opendaylight.vtn.manager.internal.util.tx.CompositeTxTask;
-
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.pathpolicy.rev150209.SetPathCostInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.pathpolicy.rev150209.SetPathCostOutput;
@@ -43,13 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnUpda
  * @see #create(TopologyGraph, SetPathCostInput)
  */
 public final class SetPathCostTask
-    extends CompositeTxTask<VtnUpdateType, SetCostTask>
-    implements RpcOutputGenerator<List<VtnUpdateType>, SetPathCostOutput> {
-    /**
-     * Runtime context for updating the path policy.
-     */
-    private final PathPolicyRpcContext  context;
-
+    extends PathCostTask<SetCostTask, SetPathCostOutput> {
     /**
      * Construct a new task that set all the given link cost configurations
      * into the given path policy.
@@ -115,43 +101,7 @@ public final class SetPathCostTask
      */
     private SetPathCostTask(TopologyGraph topo, Integer id,
                             List<SetCostTask> tasks) {
-        super(tasks);
-        context = new PathPolicyRpcContext(topo, id);
-    }
-
-    // CompositeTxTask
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected void onStarted(TxContext ctx) throws VTNException {
-        // Ensure that the target path policy is present.
-        Integer pid = context.getPolicyId();
-        ReadWriteTransaction tx = ctx.getReadWriteTransaction();
-        PathPolicyUtils.readVtnPathPolicy(tx, pid.intValue());
-
-        context.onStarted();
-    }
-
-    // TxTask
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onSuccess(VTNManagerProvider provider,
-                          List<VtnUpdateType> result) {
-        for (VtnUpdateType status: result) {
-            if (status != null) {
-                // Remove all flow entries affected by the target path policy.
-                addBackgroundTask(
-                    provider.removeFlows(context.getFlowRemover()));
-
-                context.onUpdated();
-                break;
-            }
-        }
+        super(topo, id, tasks);
     }
 
     // RpcOutputGenerator
index 93bc6724774ed8d97a4a5c72b4ec5ab3a933a463..045fd1d690993cb9c6f94e2654503693aff809d5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2015, 2016 NEC Corporation. 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,
@@ -14,18 +14,9 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import org.opendaylight.vtn.manager.VTNException;
-
-import org.opendaylight.vtn.manager.internal.FlowRemover;
-import org.opendaylight.vtn.manager.internal.TxContext;
-import org.opendaylight.vtn.manager.internal.VTNManagerProvider;
-import org.opendaylight.vtn.manager.internal.flow.remove.AllFlowRemover;
-import org.opendaylight.vtn.manager.internal.flow.remove.TenantFlowRemover;
 import org.opendaylight.vtn.manager.internal.util.pathmap.PathMapUtils;
 import org.opendaylight.vtn.manager.internal.util.rpc.RpcException;
-import org.opendaylight.vtn.manager.internal.util.rpc.RpcOutputGenerator;
 import org.opendaylight.vtn.manager.internal.util.rpc.RpcUtils;
-import org.opendaylight.vtn.manager.internal.util.tx.CompositeTxTask;
 import org.opendaylight.vtn.manager.internal.util.vnode.VTenantIdentifier;
 
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -47,17 +38,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnUpda
  * @see #create(SetPathMapInput)
  */
 public final class SetPathMapTask
-    extends CompositeTxTask<VtnUpdateType, SetMapTask>
-    implements RpcOutputGenerator<List<VtnUpdateType>, SetPathMapOutput> {
-    /**
-     * The identifier for the target VTN.
-     *
-     * <p>
-     *   {@code null} means that the global path map is targeted.
-     * </p>
-     */
-    private final VTenantIdentifier  identifier;
-
+    extends PathMapTask<SetMapTask, SetPathMapOutput> {
     /**
      * Construct a new task that set all the given path map configurations
      * into the global or VTN path map.
@@ -108,41 +89,7 @@ public final class SetPathMapTask
      * @param tasks  A list of tasks that set path map configuration.
      */
     private SetPathMapTask(VTenantIdentifier ident, List<SetMapTask> tasks) {
-        super(tasks);
-        identifier = ident;
-    }
-
-    // CompositeTxTask
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected void onStarted(TxContext ctx) throws VTNException {
-        if (identifier != null) {
-            // Ensure that the target VTN is present.
-            identifier.fetch(ctx.getReadWriteTransaction());
-        }
-    }
-
-    // TxTask
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onSuccess(VTNManagerProvider provider,
-                          List<VtnUpdateType> result) {
-        for (VtnUpdateType status: result) {
-            if (status != null) {
-                // REVISIT: Select flow entries affected by the change.
-                FlowRemover remover = (identifier == null)
-                    ? new AllFlowRemover()
-                    : new TenantFlowRemover(identifier);
-                addBackgroundTask(provider.removeFlows(remover));
-                break;
-            }
-        }
+        super(ident, tasks);
     }
 
     // RpcOutputGenerator
index 71d60ca8647cfecc0b2288a8d57bc23c2e9b5ed4..5e61e672b31a15df2abd4bda0205f2b437f0fbc5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2015, 2016 NEC Corporation. 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,
@@ -50,6 +50,19 @@ public final class FlowCondUtils {
      */
     private FlowCondUtils() {}
 
+    /**
+     * Return a new {@link RpcException} that indicates the specified flow
+     * condition is not present.
+     *
+     * @param path  An {@link InstanceIdentifier} instance that specifies the
+     *              flow condition.
+     * @return  An {@link RpcException}.
+     */
+    public static RpcException getNotFoundException(
+        InstanceIdentifier<?> path) {
+        return getNotFoundException(getName(path), null);
+    }
+
     /**
      * Return a new {@link RpcException} that indicates the specified flow
      * condition is not present.
index 22421e47a58ab8ed436119f06b026008e663d657..10b2280ddd181935946353aff38df6f97915651a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2015, 2016 NEC Corporation. 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,
@@ -69,7 +69,7 @@ public final class PathPolicyUtils {
      * @param id  The identifier of the path policy.
      * @return  An {@link RpcException}.
      */
-    public static RpcException getNotFoundException(int id) {
+    public static RpcException getNotFoundException(Integer id) {
         return getNotFoundException(id, null);
     }
 
@@ -81,7 +81,8 @@ public final class PathPolicyUtils {
      * @param cause  A {@link Throwable} which indicates the cause of error.
      * @return  An {@link RpcException}.
      */
-    public static RpcException getNotFoundException(int id, Throwable cause) {
+    public static RpcException getNotFoundException(Integer id,
+                                                    Throwable cause) {
         String msg = MiscUtils.joinColon(id, "Path policy does not exist.");
         return RpcException.getNotFoundException(msg, cause);
     }
@@ -395,10 +396,10 @@ public final class PathPolicyUtils {
      * @return  A {@link VtnPathPolicy} instance.
      * @throws VTNException  An error occurred.
      */
-    public static VtnPathPolicy readVtnPathPolicy(ReadTransaction rtx, int id)
+    public static VtnPathPolicy readVtnPathPolicy(ReadTransaction rtx,
+                                                  Integer id)
         throws VTNException {
-        InstanceIdentifier<VtnPathPolicy> path =
-            getIdentifier(Integer.valueOf(id));
+        InstanceIdentifier<VtnPathPolicy> path = getIdentifier(id);
         LogicalDatastoreType store = LogicalDatastoreType.OPERATIONAL;
         VtnPathPolicy vpp = DataStoreUtils.read(rtx, store, path).orNull();
         if (vpp == null) {
diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/vnode/FlowFilterTask.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/vnode/FlowFilterTask.java
new file mode 100644 (file)
index 0000000..498dbdf
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2016 NEC Corporation. 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.vtn.manager.internal.vnode;
+
+import java.util.List;
+
+import org.opendaylight.vtn.manager.VTNException;
+
+import org.opendaylight.vtn.manager.internal.TxContext;
+import org.opendaylight.vtn.manager.internal.VTNManagerProvider;
+import org.opendaylight.vtn.manager.internal.flow.remove.TenantFlowRemover;
+import org.opendaylight.vtn.manager.internal.util.rpc.RpcOutputGenerator;
+import org.opendaylight.vtn.manager.internal.util.tx.AbstractTxTask;
+import org.opendaylight.vtn.manager.internal.util.tx.CompositeTxTask;
+import org.opendaylight.vtn.manager.internal.util.vnode.VNodeIdentifier;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnUpdateType;
+
+/**
+ * Abstract base class for a task that updates the flow filter configurations
+ * in the flow filter list.
+ *
+ * @param <T>  The type of MD-SAL datastore transaction task that updates
+ *             flow filter configuration.
+ * @param <O>  The type of the output of the RPC.
+ */
+public abstract class FlowFilterTask<T extends AbstractTxTask<VtnUpdateType>, O>
+    extends CompositeTxTask<VtnUpdateType, T>
+    implements RpcOutputGenerator<List<VtnUpdateType>, O> {
+    /**
+     * The identifier for the target virtual node.
+     */
+    private final VNodeIdentifier<?>  identifier;
+
+    /**
+     * Construct a new instance.
+     *
+     * @param ident  A {@link VNodeIdentifier} instance that specifies the
+     *               target virtual node.
+     * @param tasks  A list of tasks that update flow filter configuration.
+     */
+    protected FlowFilterTask(VNodeIdentifier<?> ident, List<T> tasks) {
+        super(tasks);
+        identifier = ident;
+    }
+
+    // CompositeTxTask
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected final void onStarted(TxContext ctx) throws VTNException {
+        // Ensure that the target virtual node is present.
+        identifier.fetch(ctx.getReadWriteTransaction());
+    }
+
+    // TxTask
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public final void onSuccess(VTNManagerProvider provider,
+                                List<VtnUpdateType> result) {
+        for (VtnUpdateType status: result) {
+            if (status != null) {
+                // REVISIT: Select flow entries affected by the change.
+                String tname = identifier.getTenantNameString();
+                TenantFlowRemover remover = new TenantFlowRemover(tname);
+                addBackgroundTask(provider.removeFlows(remover));
+                break;
+            }
+        }
+    }
+}
index c1f63495e9837ea1f5ff074802aa602d093dba07..27f53ec8c6e4764c89204c76ed9d16f0f33b5c38 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2015, 2016 NEC Corporation. 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,
@@ -16,14 +16,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import org.opendaylight.vtn.manager.VTNException;
-
-import org.opendaylight.vtn.manager.internal.TxContext;
-import org.opendaylight.vtn.manager.internal.VTNManagerProvider;
-import org.opendaylight.vtn.manager.internal.flow.remove.TenantFlowRemover;
 import org.opendaylight.vtn.manager.internal.util.rpc.RpcException;
-import org.opendaylight.vtn.manager.internal.util.rpc.RpcOutputGenerator;
-import org.opendaylight.vtn.manager.internal.util.tx.CompositeTxTask;
 import org.opendaylight.vtn.manager.internal.util.vnode.VNodeIdentifier;
 
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -43,13 +36,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnUpda
  * @see #create(VNodeIdentifier, boolean, List)
  */
 public final class RemoveFlowFilterTask
-    extends CompositeTxTask<VtnUpdateType, RemoveFilterTask>
-    implements RpcOutputGenerator<List<VtnUpdateType>, RemoveFlowFilterOutput> {
-    /**
-     * The identifier for the target virtual node.
-     */
-    private final VNodeIdentifier<?>  identifier;
-
+    extends FlowFilterTask<RemoveFilterTask, RemoveFlowFilterOutput> {
     /**
      * Construct a new task that removes all the given flow filter
      * configurations from the specified virtual node.
@@ -91,38 +78,7 @@ public final class RemoveFlowFilterTask
      */
     private RemoveFlowFilterTask(VNodeIdentifier<?> ident,
                                  List<RemoveFilterTask> tasks) {
-        super(tasks);
-        identifier = ident;
-    }
-
-    // CompositeTxTask
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected void onStarted(TxContext ctx) throws VTNException {
-        // Ensure that the target virtual node is present.
-        identifier.fetch(ctx.getReadWriteTransaction());
-    }
-
-    // TxTask
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onSuccess(VTNManagerProvider provider,
-                          List<VtnUpdateType> result) {
-        for (VtnUpdateType status: result) {
-            if (status != null) {
-                // REVISIT: Select flow entries affected by the change.
-                String tname = identifier.getTenantNameString();
-                TenantFlowRemover remover = new TenantFlowRemover(tname);
-                addBackgroundTask(provider.removeFlows(remover));
-                break;
-            }
-        }
+        super(ident, tasks);
     }
 
     // RpcOutputGenerator
index b86c0df9c971ab15a0ffea254ee0aa69c6f6312c..8791546ed3b52a2ee18a6ea86700621e97fba4cd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2015, 2016 NEC Corporation. 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,
@@ -14,16 +14,9 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import org.opendaylight.vtn.manager.VTNException;
-
-import org.opendaylight.vtn.manager.internal.TxContext;
-import org.opendaylight.vtn.manager.internal.VTNManagerProvider;
-import org.opendaylight.vtn.manager.internal.flow.remove.TenantFlowRemover;
 import org.opendaylight.vtn.manager.internal.util.flow.filter.VTNFlowFilter;
 import org.opendaylight.vtn.manager.internal.util.rpc.RpcException;
-import org.opendaylight.vtn.manager.internal.util.rpc.RpcOutputGenerator;
 import org.opendaylight.vtn.manager.internal.util.rpc.RpcUtils;
-import org.opendaylight.vtn.manager.internal.util.tx.CompositeTxTask;
 import org.opendaylight.vtn.manager.internal.util.vnode.VNodeIdentifier;
 
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -44,13 +37,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnUpda
  * @see  #create(SetFlowFilterInput)
  */
 public final class SetFlowFilterTask
-    extends CompositeTxTask<VtnUpdateType, SetFilterTask>
-    implements RpcOutputGenerator<List<VtnUpdateType>, SetFlowFilterOutput> {
-    /**
-     * The identifier for the target virtual node.
-     */
-    private final VNodeIdentifier<?>  identifier;
-
+    extends FlowFilterTask<SetFilterTask, SetFlowFilterOutput> {
     /**
      * Construct a new task that set all the given flow filter configurations
      * into the specified flow filter list.
@@ -109,38 +96,7 @@ public final class SetFlowFilterTask
      */
     private SetFlowFilterTask(VNodeIdentifier<?> ident,
                               List<SetFilterTask> tasks) {
-        super(tasks);
-        identifier = ident;
-    }
-
-    // CompositeTxTask
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected void onStarted(TxContext ctx) throws VTNException {
-        // Ensure that the target virtual node is present.
-        identifier.fetch(ctx.getReadWriteTransaction());
-    }
-
-    // TxTask
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onSuccess(VTNManagerProvider provider,
-                          List<VtnUpdateType> result) {
-        for (VtnUpdateType status: result) {
-            if (status != null) {
-                // REVISIT: Select flow entries affected by the change.
-                String tname = identifier.getTenantNameString();
-                TenantFlowRemover remover = new TenantFlowRemover(tname);
-                addBackgroundTask(provider.removeFlows(remover));
-                break;
-            }
-        }
+        super(ident, tasks);
     }
 
     // RpcOutputGenerator
index 83086dacddfaa64c049ceaf8110150c747c739ae..58c4965344f70c5cf775b7363ee0d9890fc2fb43 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2014, 2016 NEC Corporation. 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,
@@ -444,6 +444,37 @@ public class TcpPacketTest extends TestBase {
         verifyZeroInteractions(ctx);
     }
 
+    /**
+     * Test case for {@link TcpPacket#setDescription(StringBuilder)}.
+     */
+    @Test
+    public void testSetDescription() {
+        int[] srcPorts = {0, 100, 4567, 32767, 32768, 40000, 65534, 65535};
+        int[] dstPorts = {1, 333, 12345, 32767, 32768, 55443, 65534, 65535};
+
+        for (int src: srcPorts) {
+            for (int dst: dstPorts) {
+                TCP pkt = new TCP().
+                    setSourcePort((short)src).
+                    setDestinationPort((short)dst);
+                TcpPacket tcp = new TcpPacket(pkt);
+                String expected = "TCP[src=" + src + ", dst=" + dst + "]";
+                StringBuilder builder = new StringBuilder();
+                tcp.setDescription(builder);
+                assertEquals(expected, builder.toString());
+
+                int src1 = (src + 13) & 0xffff;
+                int dst1 = (dst + 53) & 0xffff;
+                tcp.setSourcePort(src1);
+                tcp.setDestinationPort(dst1);
+                expected = expected +
+                    "TCP[src=" + src1 + ", dst=" + dst1 + "]";
+                tcp.setDescription(builder);
+                assertEquals(expected, builder.toString());
+            }
+        }
+    }
+
     /**
      * Create a {@link TCP} instance for test.
      *
index 3baedb5b61cb84ef4101368829d6c809bfb03696..aa1fe696cac900a4ece6b6b97d907206dcfb5df9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2014, 2016 NEC Corporation. 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,
@@ -399,6 +399,37 @@ public class UdpPacketTest extends TestBase {
         verifyZeroInteractions(ctx);
     }
 
+    /**
+     * Test case for {@link UdpPacket#setDescription(StringBuilder)}.
+     */
+    @Test
+    public void testSetDescription() {
+        int[] srcPorts = {0, 100, 4567, 32767, 32768, 40000, 65534, 65535};
+        int[] dstPorts = {1, 333, 12345, 32767, 32768, 55443, 65534, 65535};
+
+        for (int src: srcPorts) {
+            for (int dst: dstPorts) {
+                UDP pkt = new UDP().
+                    setSourcePort((short)src).
+                    setDestinationPort((short)dst);
+                UdpPacket udp = new UdpPacket(pkt);
+                String expected = "UDP[src=" + src + ", dst=" + dst + "]";
+                StringBuilder builder = new StringBuilder();
+                udp.setDescription(builder);
+                assertEquals(expected, builder.toString());
+
+                int src1 = (src + 11) & 0xffff;
+                int dst1 = (dst + 47) & 0xffff;
+                udp.setSourcePort(src1);
+                udp.setDestinationPort(dst1);
+                expected = expected +
+                    "UDP[src=" + src1 + ", dst=" + dst1 + "]";
+                udp.setDescription(builder);
+                assertEquals(expected, builder.toString());
+            }
+        }
+    }
+
     /**
      * Create an {@link UDP} instance for test.
      *
index ea7f50cd7afd01369c6c7fa2be0cebf80783ea2d..4d411c376641005b13cf5f391c56563edd2d92a9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 NEC Corporation.  All rights reserved.
+ * Copyright (c) 2015, 2016 NEC Corporation. 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,
@@ -47,6 +47,7 @@ public class FlowCondUtilsTest extends TestBase {
      * Test case for the following methods.
      *
      * <ul>
+     *   <li>{@link FlowCondUtils#getNotFoundException(InstanceIdentifier)}</li>
      *   <li>{@link FlowCondUtils#getNotFoundException(String)}</li>
      *   <li>{@link FlowCondUtils#getNotFoundException(String, Throwable)}</li>
      *   <li>{@link FlowCondUtils#getMatchIndexMissingException()}</li>
@@ -74,6 +75,17 @@ public class FlowCondUtilsTest extends TestBase {
             assertEquals(RpcErrorTag.DATA_MISSING, e.getErrorTag());
             assertEquals(VtnErrorTag.NOTFOUND, e.getVtnErrorTag());
             assertEquals(msg, e.getMessage());
+
+            VnodeName vname = new VnodeName(name);
+            VtnFlowConditionKey key = new VtnFlowConditionKey(vname);
+            InstanceIdentifier<VtnFlowCondition> path = InstanceIdentifier.
+                builder(VtnFlowConditions.class).
+                child(VtnFlowCondition.class, key).build();
+            e = FlowCondUtils.getNotFoundException(path);
+            assertEquals(null, e.getCause());
+            assertEquals(RpcErrorTag.DATA_MISSING, e.getErrorTag());
+            assertEquals(VtnErrorTag.NOTFOUND, e.getVtnErrorTag());
+            assertEquals(msg, e.getMessage());
         }
 
         String msg = "Match index cannot be null";
index eac23f0a337e2887a462ea558c45d60c90c3347f..592203df411c117798160bc6e1ff9ceaa3e5e58c 100644 (file)
@@ -69,8 +69,8 @@ public class PathPolicyUtilsTest extends TestBase {
      * Test case for utility methods that return an exception.
      *
      * <ul>
-     *   <li>{@link PathPolicyUtils#getNotFoundException(int)}</li>
-     *   <li>{@link PathPolicyUtils#getNotFoundException(int, Throwable)}</li>
+     *   <li>{@link PathPolicyUtils#getNotFoundException(Integer)}</li>
+     *   <li>{@link PathPolicyUtils#getNotFoundException(Integer, Throwable)}</li>
      *   <li>{@link PathPolicyUtils#getInvalidPolicyIdException(Integer, Throwable)}</li>
      *   <li>{@link PathPolicyUtils#getInvalidDefaultCostException(Long, Throwable)}</li>
      *   <li>{@link PathPolicyUtils#getInvalidCostException(Long, Throwable)}</li>
@@ -83,23 +83,24 @@ public class PathPolicyUtilsTest extends TestBase {
     public void testGetException() {
         IllegalArgumentException cause = new IllegalArgumentException();
         for (int i = PATH_POLICY_MIN; i <= PATH_POLICY_MAX; i++) {
-            // getNotFoundException(int)
-            RpcException e = PathPolicyUtils.getNotFoundException(i);
+            // getNotFoundException(Integer)
+            Integer id = Integer.valueOf(i);
+            RpcException e = PathPolicyUtils.getNotFoundException(id);
             assertEquals(RpcErrorTag.DATA_MISSING, e.getErrorTag());
             assertEquals(null, e.getCause());
-            String msg = i + ": Path policy does not exist.";
+            String msg = id + ": Path policy does not exist.";
             assertEquals(VtnErrorTag.NOTFOUND, e.getVtnErrorTag());
             assertEquals(msg, e.getMessage());
 
-            // getNotFoundException(int, Throwable)
-            e = PathPolicyUtils.getNotFoundException(i, cause);
+            // getNotFoundException(Integer, Throwable)
+            e = PathPolicyUtils.getNotFoundException(id, cause);
             assertEquals(RpcErrorTag.DATA_MISSING, e.getErrorTag());
             assertSame(cause, e.getCause());
             assertEquals(VtnErrorTag.NOTFOUND, e.getVtnErrorTag());
             assertEquals(msg, e.getMessage());
         }
 
-        // getInvalidPolicyIdException(int, Throwable)
+        // getInvalidPolicyIdException(Integer, Throwable)
         for (int i = PATH_POLICY_MAX + 1; i < PATH_POLICY_MAX + 10; i++) {
             RpcException e =
                 PathPolicyUtils.getInvalidPolicyIdException(i, cause);
@@ -797,7 +798,7 @@ public class PathPolicyUtilsTest extends TestBase {
 
     /**
      * Test case for
-     * {@link PathPolicyUtils#readVtnPathPolicy(ReadTransaction, int)}.
+     * {@link PathPolicyUtils#readVtnPathPolicy(ReadTransaction, Integer)}.
      *
      * @throws Exception  An error occurred.
      */
index ece508a60cee595583cc9eb9fba4ca7efd0bde28..0a3c3045bb9830b0b1e6c1c77ddb2a27716cd18e 100644 (file)
@@ -55,6 +55,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.rev150328.vtns.VtnKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VnodeName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VnodeUpdateMode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnErrorTag;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnRpcResult;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnUpdateOperationType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnUpdateType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.vbridge.rev150907.RemoveVbridgeInput;
@@ -381,26 +382,7 @@ public final class VTNManagerService {
             build();
         VTNRpcResult<UpdateVtnOutput> result =
             getRpcResult(vtnService.updateVtn(input));
-        int code = result.getStatusCode();
-        if (code != HTTP_OK) {
-            LOG.error("Failed to update VTN: input={}, err={}",
-                      input, result.getErrorMessage());
-        } else if (LOG.isDebugEnabled()) {
-            VtnUpdateType utype = result.getOutput().getStatus();
-            String msg;
-            if (utype == VtnUpdateType.CREATED) {
-                msg = "A VTN has been created";
-            } else if (utype == VtnUpdateType.CHANGED) {
-                msg = "A VTN has been changed";
-            } else {
-                assert utype == null;
-                msg = "A VTN is present and not changed";
-            }
-
-            LOG.debug("{}: name={}", msg, name);
-        }
-
-        return code;
+        return getResult(input, result, "VTN");
     }
 
     /**
@@ -473,26 +455,7 @@ public final class VTNManagerService {
             build();
         VTNRpcResult<UpdateVbridgeOutput> result =
             getRpcResult(vbridgeService.updateVbridge(input));
-        int code = result.getStatusCode();
-        if (code != HTTP_OK) {
-            LOG.error("Failed to update vBridge: input={}, err={}",
-                      input, result.getErrorMessage());
-        } else if (LOG.isDebugEnabled()) {
-            VtnUpdateType utype = result.getOutput().getStatus();
-            String msg;
-            if (utype == VtnUpdateType.CREATED) {
-                msg = "A vBridge has been created";
-            } else if (utype == VtnUpdateType.CHANGED) {
-                msg = "A vBridge has been changed";
-            } else {
-                assert utype == null;
-                msg = "A vBridge is present and not changed";
-            }
-
-            LOG.debug("{}: path={}/{}, desc={}", msg, tname, bname, desc);
-        }
-
-        return code;
+        return getResult(input, result, "vBridge");
     }
 
     /**
@@ -546,26 +509,7 @@ public final class VTNManagerService {
     public int updateInterface(UpdateVinterfaceInput input) {
         VTNRpcResult<UpdateVinterfaceOutput> result =
             getRpcResult(vinterfaceService.updateVinterface(input));
-        int code = result.getStatusCode();
-        if (code != HTTP_OK) {
-            LOG.error("Failed to update virtual interface: input={}, err={}",
-                      input, result.getErrorMessage());
-        } else if (LOG.isDebugEnabled()) {
-            VtnUpdateType utype = result.getOutput().getStatus();
-            String msg;
-            if (utype == VtnUpdateType.CREATED) {
-                msg = "A virtual interface has been created";
-            } else if (utype == VtnUpdateType.CHANGED) {
-                msg = "A virtual interface has been changed";
-            } else {
-                assert utype == null;
-                msg = "A virtual interface is present and not changed";
-            }
-
-            logInput(msg, input);
-        }
-
-        return code;
+        return getResult(input, result, "vInterface");
     }
 
     /**
@@ -603,26 +547,7 @@ public final class VTNManagerService {
     public int setPortMap(SetPortMapInput input) {
         VTNRpcResult<SetPortMapOutput> result =
             getRpcResult(portMapService.setPortMap(input));
-        int code = result.getStatusCode();
-        if (code != HTTP_OK) {
-            LOG.error("Failed to set port mapping: input={}, err={}",
-                      input, result.getErrorMessage());
-        } else if (LOG.isDebugEnabled()) {
-            VtnUpdateType utype = result.getOutput().getStatus();
-            String msg;
-            if (utype == VtnUpdateType.CREATED) {
-                msg = "Port mapping has been created";
-            } else if (utype == VtnUpdateType.CHANGED) {
-                msg = "Port mapping has been changed";
-            } else {
-                assert utype == null;
-                msg = "Port mapping is already configured";
-            }
-
-            logInput(msg, input);
-        }
-
-        return code;
+        return getResult(input, result, "PortMap");
     }
 
     /**
@@ -656,19 +581,43 @@ public final class VTNManagerService {
                 msg = "Port mapping is not configured";
             }
 
-            logInput(msg, input);
+            LOG.debug("{}: input={}", msg, input);
         }
 
         return code;
     }
 
     /**
-     * Record the given RPC input as a debug log.
+     * Return the result code that indicates the result of RPC execution.
      *
-     * @param msg    A debug log message.
-     * @param input  An input of the RPC.
+     * @param input   An RPC input.
+     * @param result  A {@link VTNRpcResult} instance.
+     * @param desc    A brief description about the target virtual node.
+     * @param <I>     The type of the RPC input.
+     * @param <O>     The type of the RPC output.
+     * @return  The result code that indicates the result of RPC execution.
      */
-    private void logInput(String msg, Object input) {
-        LOG.debug("{}: input={}", msg, input);
+    private <I, O extends VtnRpcResult> int getResult(
+        I input, VTNRpcResult<O> result, String desc) {
+        int code = result.getStatusCode();
+        if (code != HTTP_OK) {
+            LOG.error("{}: Failed to update: input={}, err={}",
+                      desc, input, result.getErrorMessage());
+        } else if (LOG.isDebugEnabled()) {
+            VtnUpdateType utype = result.getOutput().getStatus();
+            String msg;
+            if (utype == VtnUpdateType.CREATED) {
+                msg = "has been created";
+            } else if (utype == VtnUpdateType.CHANGED) {
+                msg = "has been changed";
+            } else {
+                assert utype == null;
+                msg = "is present and not changed";
+            }
+
+            LOG.debug("{} {}: input={}", desc, msg, input);
+        }
+
+        return code;
     }
 }