--- /dev/null
+/*
+ * 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;
+ }
+}
/*
- * 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,
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.
*
* @since Beryllium
*/
-public class Ethernet extends Packet {
+public class Ethernet extends EtherTypePacket<Ethernet> {
/**
* The number of bits in the Ethernet header.
*/
*/
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.
*/
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);
}
/**
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.
*
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
/**
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();
- }
}
/*
- * 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,
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;
*
* @since Beryllium
*/
-public final class IEEE8021Q extends Packet {
+public final class IEEE8021Q extends EtherTypePacket<IEEE8021Q> {
/**
* The number of bits in the VLAN tag.
*/
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.
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
/**
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();
- }
}
--- /dev/null
+/*
+ * 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;
+ }
+}
/*
- * 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,
*
* @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.
*/
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.
*
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.
*
protected Map<String, HeaderField> getHeaderFormat() {
return HEADER_FORMAT;
}
-
- // Object
-
- /**
- * {@inheritDoc}
- */
- @Override
- public TCP clone() {
- return (TCP)super.clone();
- }
}
/*
- * 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,
*
* @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.
*/
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.
*
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.
*
protected Map<String, HeaderField> getHeaderFormat() {
return HEADER_FORMAT;
}
-
- // Object
-
- /**
- * {@inheritDoc}
- */
- @Override
- public UDP clone() {
- return (UDP)super.clone();
- }
}
/*
- * 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,
*/
public class EthernetTest extends TestBase {
/**
- * Test case for {@link Ethernet#getPayloadClass(short)}.
+ * Test case for {@link EtherTypePacket#getPayloadClass(short)}.
*/
@Test
public void testGetPayloadClass() {
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));
}
/**
--- /dev/null
+/*
+ * 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;
+ }
+ }
+ }
+}
/*
- * 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,
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());
}
}
/*
- * 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,
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;
* @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.
* @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
/*
- * 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,
*/
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.
*/
VtnFlowCondition vfc, boolean repl,
boolean pr) {
super(LogicalDatastoreType.OPERATIONAL, path, vfc, repl);
- name = nm;
present = pr;
}
throws VTNException {
if (current == null && present) {
// The target flow condition is not present.
- throw FlowCondUtils.getNotFoundException(name);
+ throw FlowCondUtils.getNotFoundException(getTargetPath());
}
}
/*
- * 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,
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;
* @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.
* @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
/*
- * 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,
*
* <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.
/*
- * 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,
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;
*
* @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.
*/
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()}.
/**
* 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.
*/
*
* @param packet A {@link PortProtoPacket} instance.
*/
- private void fill(PortProtoPacket packet) {
+ private void fill(PortProtoPacket<T> packet) {
if (sourcePort == PORT_NONE) {
setSourcePort(packet.getRawSourcePort());
}
* @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);
*
* @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;
*
* @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;
/**
* 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.
*
*/
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;
}
*
* @return A {@link Values} instance.
*/
- private Values getModifiedValues() {
+ private Values<T> getModifiedValues() {
if (modifiedValues == null) {
values.fill(this);
modifiedValues = values.clone();
// CachedPacket
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final T getPacket() {
+ return rawPacket;
+ }
+
/**
* {@inheritDoc}
*/
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
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
* {@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;
@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()))
*/
@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);
}
*/
@Override
public final void setSourcePort(int port) {
- Values v = getModifiedValues();
+ Values<T> v = getModifiedValues();
v.setSourcePort(port);
}
*/
@Override
public final int getDestinationPort() {
- Values v = getValues();
+ Values<T> v = getValues();
int port = v.getDestinationPort();
if (port == PORT_NONE) {
short p = getRawDestinationPort();
*/
@Override
public final void setDestinationPort(int port) {
- Values v = getModifiedValues();
+ Values<T> v = getModifiedValues();
v.setDestinationPort(port);
}
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(']');
}
}
/*
- * 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,
*/
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.
*
*/
@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;
return mod;
}
-
- // CachedPacket
-
- /**
- * Return a {@link TCP} instance configured in this instance.
- *
- * @return A {@link TCP} instance.
- */
- @Override
- public TCP getPacket() {
- return packet;
- }
}
/*
- * 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,
*/
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);
}
/**
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);
return mod;
}
-
- // CachedPacket
-
- /**
- * Return a {@link UDP} instance configured in this instance.
- *
- * @return A {@link UDP} instance.
- */
- @Override
- public UDP getPacket() {
- return packet;
- }
}
--- /dev/null
+/*
+ * 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;
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+ }
+ }
+}
/*
- * 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,
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;
* @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.
*/
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
/*
- * 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,
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;
* @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.
*/
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
/*
- * 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,
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;
* @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.
*/
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
/*
- * 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,
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;
* @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.
* @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
/*
- * 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,
*/
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.
/*
- * 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,
* @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);
}
* @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);
}
* @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) {
--- /dev/null
+/*
+ * 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;
+ }
+ }
+ }
+}
/*
- * 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,
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;
* @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.
*/
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
/*
- * 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,
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;
* @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.
*/
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
/*
- * 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,
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.
*
/*
- * 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,
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.
*
/*
- * 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,
* 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>
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";
* 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>
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);
/**
* Test case for
- * {@link PathPolicyUtils#readVtnPathPolicy(ReadTransaction, int)}.
+ * {@link PathPolicyUtils#readVtnPathPolicy(ReadTransaction, Integer)}.
*
* @throws Exception An error occurred.
*/
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;
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");
}
/**
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");
}
/**
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");
}
/**
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");
}
/**
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;
}
}