From 5bdf763c2dc77c92cff97268087811077837e151 Mon Sep 17 00:00:00 2001
From: Shigeru Yasuda
@@ -742,16 +742,16 @@ public class VTNFlowDatabase { * returned {@link FlowRemoveTask} object. *
* - * @param mgr VTN Manager service. - * @param fmatch A {@link VTNFlowMatch} instance which determines VTN - * flows to be removed. - * Specifying {@code null} results in undefined behavior. + * @param mgr VTN Manager service. + * @param selector A {@link FlowSelector} instance which determines VTN + * flows to be removed. + * Specifying {@code null} results in undefined behavior. * @return A {@link FlowRemoveTask} object that will execute the actual * work is returned. {@code null} is returned if there is no flow * entry to be removed. */ public synchronized FlowRemoveTask removeFlows(VTNManagerImpl mgr, - VTNFlowMatch fmatch) { + FlowSelector selector) { VTNManagerProvider provider = mgr.getVTNProvider(); if (provider == null) { return null; @@ -761,12 +761,12 @@ public class VTNFlowDatabase { for (Iterator- * Controller's MAC address is used as source MAC adddress, and zero - * is used as sender protocol address. - *
- * - * @param dst Destination MAC address. - * @param addr Target IP address. - * @return An ethernet frame. {@code null} is returned if {@code addr} - * is invalid. - */ - public Ethernet createArpRequest(byte[] dst, InetAddress addr) { - return createArpRequest(dst, addr, (short)0); - } - - /** - * Create an ethernet frame which contains an ARP request message. - * - *- * Controller's MAC address is used as source MAC adddress, and zero - * is used as sender protocol address. - *
- * - * @param dst Destination MAC address. - * @param addr Target IP address. - * @param vlan VLAN ID. Zero means VLAN tag should not be added. - * @return An ethernet frame. {@code null} is returned if {@code addr} - * is invalid. - */ - public Ethernet createArpRequest(byte[] dst, InetAddress addr, - short vlan) { - // IP address must be an IPv4 address. - if (addr instanceof Inet4Address) { - return createArpRequest(dst, addr.getAddress(), vlan); - } - return null; - } - - /** - * Create an ethernet frame which contains an ARP request message. - * - *- * Controller's MAC address is used as source MAC adddress, and zero - * is used as sender protocol address. - *
- * - * @param dst Destination MAC address. - * @param target Target IP address. - * @param vlan VLAN ID. Zero means VLAN tag should not be added. - * @return An ethernet frame. - */ - public Ethernet createArpRequest(byte[] dst, byte[] target, short vlan) { - // Set controller's MAC address to source MAC address. - byte[] src = getVTNConfig().getControllerMacAddress().getBytes(); - - // Create an ARP request message. - // Set zero to sender protocol address. - byte[] sender = new byte[]{0, 0, 0, 0}; - return createArp(ARP.REQUEST, src, dst, sender, target, vlan); - } - - /** - * Create an ethernet frame which contains an ARP message. - * - * @param op Operation code defined by ARP. - * @param src Source MAC address. - * @param dst Destination MAC address. - * @param sender Sender IP address. - * @param target Target IP address. - * @param vlan VLAN ID. Zero means VLAN tag should not be added. - * @return An ethernet frame. - */ - public Ethernet createArp(short op, byte[] src, byte[] dst, byte[] sender, - byte[] target, short vlan) { - assert src.length == EthernetAddress.SIZE && - dst.length == EthernetAddress.SIZE && - sender.length == IPV4_ADDRLEN && target.length == IPV4_ADDRLEN; - - byte[] tha = (EtherAddress.isBroadcast(dst)) - ? new byte[]{0, 0, 0, 0, 0, 0} : dst; - - // Create an ARP request message. - ARP arp = new ARP(); - arp.setHardwareType(ARP.HW_TYPE_ETHERNET). - setProtocolType(EtherTypes.IPv4.shortValue()). - setHardwareAddressLength((byte)EthernetAddress.SIZE). - setProtocolAddressLength((byte)target.length). - setOpCode(op). - setSenderHardwareAddress(src).setSenderProtocolAddress(sender). - setTargetHardwareAddress(tha).setTargetProtocolAddress(target); - - short ethType = EtherTypes.ARP.shortValue(); - Packet payload = arp; - if (vlan != 0) { - // Add a VLAN tag. - IEEE8021Q tag = new IEEE8021Q(); - tag.setCfi((byte)0).setPcp((byte)0).setVid(vlan). - setEtherType(ethType).setPayload(arp); - ethType = EtherTypes.VLANTAGGED.shortValue(); - payload = tag; - } - - // Create an ethernet frame. - Ethernet ether = new Ethernet(); - ether.setSourceMACAddress(src).setDestinationMACAddress(dst). - setEtherType(ethType).setPayload(payload); - - return ether; - } - /** * Save virtual tenant configuration, and apply current configuration to * the VTN Manager. @@ -1888,11 +1756,6 @@ public class VTNManagerImpl loadTenantConfig(ctx, cfg, name); } - // Load flow conditions. - for (String name: cfg.getKeys(ContainerConfig.Type.FLOWCOND)) { - loadFlowCondition(cfg, name); - } - // Load container path maps. for (String name: cfg.getKeys(ContainerConfig.Type.PATHMAP)) { loadContainerPathMap(cfg, name); @@ -1917,16 +1780,6 @@ public class VTNManagerImpl // Remove configuration files for obsolete tenants. cfg.deleteAll(ContainerConfig.Type.TENANT, names); - // Update configuration files for flow conditions. - names.clear(); - for (FlowCondImpl fc: flowCondDB.values()) { - fc.saveConfig(this); - names.add(fc.getName()); - } - - // Remove configuration files for obsolete flow conditions. - cfg.deleteAll(ContainerConfig.Type.FLOWCOND, names); - // Update configuration files for container path maps. names.clear(); for (ContainerPathMapImpl cpm: pathMapDB.values()) { @@ -1964,29 +1817,6 @@ public class VTNManagerImpl } } - /** - * Load the specified flow condition from the file. - * - * @param cfg A {@link ContainerConfig} instance. - * @param name The name of the flow condition. - */ - private void loadFlowCondition(ContainerConfig cfg, String name) { - FlowCondImpl newfc = (FlowCondImpl) - cfg.load(ContainerConfig.Type.FLOWCOND, name); - if (newfc != null) { - FlowCondImpl fc = flowCondDB.putIfAbsent(name, newfc); - if (fc == null) { - if (LOG.isTraceEnabled()) { - LOG.trace("{}: Flow condition was loaded.", - containerName); - } else { - LOG.info("{}: Flow condition was loaded: {}", - containerName, name); - } - } - } - } - /** * Load the specified container path map from the file. * @@ -2076,18 +1906,6 @@ public class VTNManagerImpl return new Status(StatusCode.NOTFOUND, msg); } - /** - * Return a failure status that indicates the specified flow condition - * does not exist. - * - * @param name The name of the flow condition. - * @return A failure status. - */ - private Status flowConditionNotFound(String name) { - String msg = name + ": Flow condition does not exist"; - return new Status(StatusCode.NOTFOUND, msg); - } - /** * Return the name of the virtual tenant in the given tenant path. * @@ -2150,59 +1968,6 @@ public class VTNManagerImpl return vtn; } - /** - * Ensure that the specified flow condition name is not null. - * - * @param name The name of the flow condition. - * @throws VTNException An error occurred. - */ - private void checkFlowConditionName(String name) throws VTNException { - if (name == null) { - throw new VTNException(MiscUtils. - argumentIsNull("Flow condition name")); - } - } - - /** - * Return the flow condition instance associated with the given name. - * - *- * This method must be called with the VTN Manager lock. - *
- * - * @param name The name of the flow condition. - * @return A flow condition associated with the specified name. - * @throws VTNException An error occurred. - */ - private FlowCondImpl getFlowCondImpl(String name) throws VTNException { - FlowCondImpl fc = flowCondDB.get(name); - if (fc == null) { - throw new VTNException(flowConditionNotFound(name)); - } - - return fc; - } - - /** - * Return the flow condition instance associated with the given name. - * - *+ * Note that this method removes flow entries present in the specified + * VTN. + *
+ * + * @param tname The name of the VTN. + * @param selector A {@link FlowSelector} instance. + * All flow entries are removed if {@code null} is + * specified. + * @return A {@link VTNFuture} instance associated with flow removal task. + * {@code null} if no flow entry is removed. + */ + VTNFuture> removeFlows(String tname, FlowSelector selector); /** * Return an implementation of the specified RPC service. diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/VTNSubSystem.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/VTNSubSystem.java new file mode 100644 index 00000000..79ef7f8b --- /dev/null +++ b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/VTNSubSystem.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015 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; + +import org.opendaylight.vtn.manager.internal.util.CompositeAutoCloseable; +import org.opendaylight.vtn.manager.internal.util.concurrent.VTNFuture; + +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; + +/** + * {@code VTNSubSystem} describes a manager instance for a subsystem in the + * VTN Manager. + */ +public interface VTNSubSystem extends AutoCloseable { + /** + * Post a MD-SAL datastore transaction task that initializes the + * configuration. + * + * @param master {@code true} if the local node is the configuration + * provider. + * @return A {@link VTNFuture} instance associated with the task for + * initialization. {@code null} means that there is nothing to + * do on initialization. + */ + VTNFuture> initConfig(boolean master); + + /** + * Register RPC implementation required by the subsystem. + * + * @param rpcReg A {@link RpcProviderRegistry} service instance. + * @param regs A {@link CompositeAutoCloseable} instance to store + * RPC registration. + */ + void initRpcServices(RpcProviderRegistry rpcReg, + CompositeAutoCloseable regs); +} diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/VTNThreadData.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/VTNThreadData.java index 4582e542..753936fa 100644 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/VTNThreadData.java +++ b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/VTNThreadData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 NEC Corporation + * Copyright (c) 2013-2015 NEC Corporation * All rights reserved. * * This program and the accompanying materials are made available under the @@ -171,7 +171,7 @@ public final class VTNThreadData { } /** - * Remove all VTN flows accepted by the specified {@link VTNFlowMatch} + * Remove all VTN flows accepted by the specified {@link FlowSelector} * instance. * *@@ -183,22 +183,22 @@ public final class VTNThreadData { * * @param mgr VTN Manager service. * @param tenantName The name of the virtual tenant. - * @param fmatch A {@link VTNFlowMatch} instance which determines + * @param selector A {@link FlowSelector} instance which determines * VTN flows to be removed. * Specifying {@code null} results in undefined * behavior. - * @see VTNFlowDatabase#removeFlows(VTNManagerImpl, VTNFlowMatch) + * @see VTNFlowDatabase#removeFlows(VTNManagerImpl, FlowSelector) */ public static void removeFlows(VTNManagerImpl mgr, String tenantName, - VTNFlowMatch fmatch) { + FlowSelector selector) { VTNFlowDatabase fdb = mgr.getTenantFlowDB(tenantName); if (fdb != null) { - addTask(fdb.removeFlows(mgr, fmatch)); + addTask(fdb.removeFlows(mgr, selector)); } } /** - * Remove all VTN flows accepted by the specified {@link VTNFlowMatch} + * Remove all VTN flows accepted by the specified {@link FlowSelector} * instance. * *
@@ -208,17 +208,18 @@ public final class VTNThreadData { * when {@link #cleanUp(VTNManagerImpl)} is called. *
* - * @param mgr VTN Manager service. - * @param fdb VTN flow database object associated with the virtual tenant. - * @param fmatch A {@link VTNFlowMatch} instance which determines - * VTN flows to be removed. - * Specifying {@code null} results in undefined - * behavior. - * @see VTNFlowDatabase#removeFlows(VTNManagerImpl, VTNFlowMatch) + * @param mgr VTN Manager service. + * @param fdb VTN flow database object associated with the virtual + * tenant. + * @param selector A {@link FlowSelector} instance which determines + * VTN flows to be removed. + * Specifying {@code null} results in undefined + * behavior. + * @see VTNFlowDatabase#removeFlows(VTNManagerImpl, FlowSelector) */ public static void removeFlows(VTNManagerImpl mgr, VTNFlowDatabase fdb, - VTNFlowMatch fmatch) { - addTask(fdb.removeFlows(mgr, fmatch)); + FlowSelector selector) { + addTask(fdb.removeFlows(mgr, selector)); } /** diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/DlAddrActionImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/DlAddrActionImpl.java index da09167d..497d3ecd 100644 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/DlAddrActionImpl.java +++ b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/DlAddrActionImpl.java @@ -9,11 +9,10 @@ package org.opendaylight.vtn.manager.internal.cluster; -import java.util.Arrays; +import java.util.Objects; import org.opendaylight.vtn.manager.VTNException; import org.opendaylight.vtn.manager.flow.action.DlAddrAction; -import org.opendaylight.vtn.manager.util.ByteUtils; import org.opendaylight.vtn.manager.util.EtherAddress; import org.opendaylight.vtn.manager.internal.util.MiscUtils; @@ -39,7 +38,7 @@ public abstract class DlAddrActionImpl extends FlowActionImpl { /** * MAC address to be set. */ - private final byte[] address; + private final EtherAddress address; /** * Construct a new instance. @@ -56,45 +55,37 @@ public abstract class DlAddrActionImpl extends FlowActionImpl { throw new VTNException(st); } - byte[] addr = act.getAddress(); - if (addr == null) { + address = act.getEtherAddress(); + if (address == null) { String msg = getErrorMessage(act, "MAC address"); st = MiscUtils.argumentIsNull(msg); throw new VTNException(st); } - if (addr.length != EtherAddress.SIZE) { - String msg = getErrorMessage( - act, "Invalid MAC address length: ", - ByteUtils.toHexString(addr)); - throw new VTNException(StatusCode.BADREQUEST, msg); - } - - if (EtherAddress.isBroadcast(addr)) { + if (address.isBroadcast()) { String msg = getErrorMessage( act, "Broadcast address cannot be specified"); throw new VTNException(StatusCode.BADREQUEST, msg); } - if (!EtherAddress.isUnicast(addr)) { + if (!address.isUnicast()) { String msg = getErrorMessage( act, "Multicast address cannot be specified: ", - ByteUtils.toHexString(addr)); + address.getText()); throw new VTNException(StatusCode.BADREQUEST, msg); } - if (EtherAddress.toLong(addr) == 0) { + if (address.getAddress() == 0L) { String msg = getErrorMessage(act, "Zero cannot be specified"); throw new VTNException(StatusCode.BADREQUEST, msg); } - - address = addr.clone(); } /** * Return a raw bytes of MAC address. * - * @return An array of bytes which represents a MAC address. + * @return An {@link EtherAddress} instance which represents + * a MAC address. */ - protected final byte[] getAddress() { + protected final EtherAddress getAddress() { return address; } @@ -114,7 +105,7 @@ public abstract class DlAddrActionImpl extends FlowActionImpl { } DlAddrActionImpl act = (DlAddrActionImpl)o; - return Arrays.equals(address, act.address); + return Objects.equals(address, act.address); } /** @@ -124,7 +115,12 @@ public abstract class DlAddrActionImpl extends FlowActionImpl { */ @Override public final int hashCode() { - return super.hashCode() ^ Arrays.hashCode(address); + int hash = super.hashCode(); + if (address != null) { + hash ^= address.hashCode(); + } + + return hash; } /** @@ -136,7 +132,6 @@ public abstract class DlAddrActionImpl extends FlowActionImpl { public String toString() { StringBuilder builder = new StringBuilder(getClass().getSimpleName()); return builder.append("[addr="). - append(ByteUtils.toHexString(address)). - append(']').toString(); + append(address.getText()).append(']').toString(); } } diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/EthernetMatchImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/EthernetMatchImpl.java deleted file mode 100644 index d50a2331..00000000 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/EthernetMatchImpl.java +++ /dev/null @@ -1,422 +0,0 @@ -/* - * Copyright (c) 2014-2015 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.cluster; - -import org.opendaylight.vtn.manager.VTNException; -import org.opendaylight.vtn.manager.flow.cond.EthernetMatch; -import org.opendaylight.vtn.manager.util.EtherAddress; -import org.opendaylight.vtn.manager.util.NumberUtils; - -import org.opendaylight.vtn.manager.internal.PacketContext; -import org.opendaylight.vtn.manager.internal.packet.cache.EtherPacket; -import org.opendaylight.vtn.manager.internal.util.MiscUtils; -import org.opendaylight.vtn.manager.internal.util.ProtocolUtils; - -import org.opendaylight.controller.sal.match.MatchType; -import org.opendaylight.controller.sal.packet.address.EthernetAddress; -import org.opendaylight.controller.sal.utils.Status; -import org.opendaylight.controller.sal.utils.StatusCode; - -/** - * {@code EthernetMatchImpl} describes the condition to match Ethernet header - * fields in packet. - * - *- * Although this class is public to other packages, this class does not - * provide any API. Applications other than VTN Manager must not use this - * class. - *
- */ -public final class EthernetMatchImpl implements PacketMatch { - /** - * Version number for serialization. - */ - private static final long serialVersionUID = -3306965790129460767L; - - /** - * A pseudo MAC address which indicates every MAC address should match. - */ - private static final long MAC_ANY = -1L; - - /** - * A pseudo Ethernet type value which indicates every Ethernet type - * should match. - */ - private static final int ETHTYPE_ANY = -1; - - /** - * A pseudo VLAN ID which indicates every VLAN ID should match. - */ - private static final short VLAN_ANY = -1; - - /** - * A pseudo VLAN priority which indicates every VLAN priority should match. - */ - private static final byte VLANPRI_ANY = -1; - - /** - * A mask value which represents valid bits in an Ethernet type. - */ - private static final int MASK_TYPE = 0xffff; - - /** - * Source MAC address to match. - */ - private final long sourceAddress; - - /** - * Destination MAC address to match. - */ - private final long destinationAddress; - - /** - * Ethernet type to match. - */ - private int etherType; - - /** - * VLAN ID to match. - */ - private final short vlan; - - /** - * VLAN priority to match. - */ - private final byte vlanPriority; - - /** - * Construct a new instance which specifies only the condition for the - * Ethernet type. - * - * @param type An Ethernet type. - */ - public EthernetMatchImpl(int type) { - sourceAddress = MAC_ANY; - destinationAddress = MAC_ANY; - etherType = type; - vlan = VLAN_ANY; - vlanPriority = VLANPRI_ANY; - } - - /** - * Construct a new instance. - * - * @param match An {@link EthernetMatch} instance. - * @throws NullPointerException - * {@code match} is {@code null}. - * @throws VTNException - * {@code match} contains invalid value. - */ - public EthernetMatchImpl(EthernetMatch match) throws VTNException { - Status st = match.getValidationStatus(); - if (st != null) { - throw new VTNException(st); - } - - sourceAddress = getMacAddress(match.getSourceAddress()); - destinationAddress = getMacAddress(match.getDestinationAddress()); - - Integer i = match.getType(); - if (i == null) { - etherType = ETHTYPE_ANY; - } else { - etherType = i.intValue(); - if ((etherType & ~MASK_TYPE) != 0) { - String msg = "Invalid Ethernet type: " + i; - throw new VTNException(StatusCode.BADREQUEST, msg); - } - } - - Short s = match.getVlan(); - if (s == null) { - vlan = VLAN_ANY; - } else { - vlan = s.shortValue(); - ProtocolUtils.checkVlan(vlan); - } - - Byte b = match.getVlanPriority(); - if (b == null) { - vlanPriority = VLANPRI_ANY; - } else { - vlanPriority = b.byteValue(); - if (!ProtocolUtils.isVlanPriorityValid(vlanPriority)) { - String msg = "Invalid VLAN priority: " + b; - throw new VTNException(StatusCode.BADREQUEST, msg); - } - if (vlan <= 0) { - String msg = "VLAN priority requires a valid VLAN ID."; - throw new VTNException(StatusCode.BADREQUEST, msg); - } - } - } - - /** - * Return a long value which represents the source MAC address to match - * against packets. - * - * @return A long value which represents the source MAC address to match. - * A negative value is returned if the source MAC address is - * not specified. - */ - public long getSourceAddress() { - return sourceAddress; - } - - /** - * Return a long value which represents the destination MAC address to - * match against packets. - * - * @return A long value which represents the destination MAC address to - * match. A negative value is returned if the source MAC address - * is not specified. - */ - public long getDestinationAddress() { - return destinationAddress; - } - - /** - * Return the Ethernet type to match against packets. - * - * @return An integer which represents the Ethernet type to mach against - * packets. A negative value is returned if the Ethernet type is - * not specified. - */ - public int getEtherType() { - return etherType; - } - - /** - * Return the VLAN ID to match against packets. - * - * @return A short integer value which represents the VLAN ID to mach - * against packets. A negative value is returned if the VLAN ID - * is not specified. - */ - public short getVlan() { - return vlan; - } - - /** - * Return the VLAN priority to match against packets. - * - * @return A byte value which represents the VLAN priority to mach - * against packets. A negative value is returned if the - * VLAN priority is not specified. - */ - public byte getVlanPriority() { - return vlanPriority; - } - - /** - * Return an {@link EthernetMatch} instance which represents this - * condition. - * - * @return An {@link EthernetMatch} instance. - */ - public EthernetMatch getMatch() { - EthernetAddress src = toEthernetAddress(sourceAddress); - EthernetAddress dst = toEthernetAddress(destinationAddress); - Integer ethType = (etherType < 0) ? null : Integer.valueOf(etherType); - Short vid = (vlan < 0) ? null : Short.valueOf(vlan); - Byte pri = (vlanPriority < 0) ? null : Byte.valueOf(vlanPriority); - - return new EthernetMatch(src, dst, ethType, vid, pri); - } - - /** - * Set the Ethernet type to match against packets. - * - * @param type An Ethernet type. - * @throws VTNException - * The specified type is different from the type in this instance. - */ - void setEtherType(int type) throws VTNException { - if (etherType != ETHTYPE_ANY && etherType != type) { - StringBuilder builder = - new StringBuilder("Ethernet type conflict: type=0x"); - builder.append(Integer.toHexString(etherType)). - append(", expected=0x").append(Integer.toHexString(type)); - throw new VTNException(StatusCode.BADREQUEST, builder.toString()); - } - - etherType = type; - } - - /** - * Convert an {@link EthernetAddress} instance into a long integer value. - * - * @param eaddr An {@link EthernetAddress} instance or {@code null}. - * @return A long integer which represents the specified value. - * {@link #MAC_ANY} is returned if {@code null} is specified. - */ - private long getMacAddress(EthernetAddress eaddr) { - if (eaddr == null) { - return MAC_ANY; - } - - byte[] raw = eaddr.getValue(); - return EtherAddress.toLong(raw); - } - - /** - * Convert a long integer value into an {@link EthernetAddress} instance. - * - * @param mac A long integer which represents a MAC address. - * @return A {@link EthernetAddress} instance converted from the specified - * value. - * {@code null} is returned if {@link #MAC_ANY} is specified. - */ - private EthernetAddress toEthernetAddress(long mac) { - if (mac == MAC_ANY) { - return null; - } - - byte[] b = EtherAddress.toBytes(mac); - try { - return new EthernetAddress(b); - } catch (Exception e) { - // This should never happen. - StringBuilder builder = - new StringBuilder("Unexpected exception: addr="); - builder.append(Long.toHexString(mac)); - throw new IllegalStateException(builder.toString(), e); - } - } - - /** - * Determine whether the given object is identical to this object. - * - * @param o An object to be compared. - * @return {@code true} if identical. Otherwise {@code false}. - */ - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (!(o instanceof EthernetMatchImpl)) { - return false; - } - - EthernetMatchImpl match = (EthernetMatchImpl)o; - return (sourceAddress == match.sourceAddress && - destinationAddress == match.destinationAddress && - etherType == match.etherType && vlan == match.vlan && - vlanPriority == match.vlanPriority); - } - - /** - * Return the hash code of this object. - * - * @return The hash code. - */ - @Override - public int hashCode() { - return NumberUtils.hashCode(sourceAddress) + - (NumberUtils.hashCode(destinationAddress) * 7) + - (etherType * 13) + ((int)vlan * 17) * (vlanPriority * 31); - } - - /** - * Return a string representation of this object. - * - * @return A string representation of this object. - */ - @Override - public String toString() { - StringBuilder builder = new StringBuilder("EthernetMatchImpl["); - String sep = ""; - if (sourceAddress != MAC_ANY) { - builder.append(sep).append("src="). - append(MiscUtils.formatMacAddress(sourceAddress)); - sep = ","; - } - if (destinationAddress != MAC_ANY) { - builder.append(sep).append("dst="). - append(MiscUtils.formatMacAddress(destinationAddress)); - sep = ","; - } - if (etherType != ETHTYPE_ANY) { - builder.append(sep).append("type=0x"). - append(Integer.toHexString(etherType)); - sep = ","; - } - if (vlan != VLAN_ANY) { - builder.append(sep).append("vlan=").append((int)vlan); - sep = ","; - } - if (vlanPriority != VLANPRI_ANY) { - builder.append(sep).append("pcp=").append((int)vlanPriority); - } - - builder.append(']'); - - return builder.toString(); - } - - // PacketMatch - - /** - * Determine whether the specified packet matches the condition defined - * by this instance. - * - * @param pctx The context of the packet to be tested. - * @return {@code true} if the specified packet matches the condition. - * Otherwise {@code false}. - */ - @Override - public boolean match(PacketContext pctx) { - EtherPacket ether = pctx.getEtherPacket(); - - // Test source MAC address. - if (sourceAddress != MAC_ANY) { - pctx.addMatchField(MatchType.DL_SRC); - if (sourceAddress != ether.getSourceMacAddress()) { - return false; - } - } - - // Test destination MAC address. - if (destinationAddress != MAC_ANY) { - pctx.addMatchField(MatchType.DL_DST); - if (destinationAddress != ether.getDestinationMacAddress()) { - return false; - } - } - - // Test Ethernet type. - if (etherType != ETHTYPE_ANY) { - pctx.addMatchField(MatchType.DL_TYPE); - if (etherType != ether.getEtherType()) { - return false; - } - } - - // Test VLAN ID. - // We don't need to set DL_VLAN field to PacketContext because it is - // mandatory. - if (vlan != VLAN_ANY) { - if (vlan != ether.getVlan()) { - return false; - } - - // Test VLAN priority only if a VLAN ID is specified. - if (vlanPriority != VLANPRI_ANY) { - pctx.addMatchField(MatchType.DL_VLAN_PR); - if (vlanPriority != ether.getVlanPriority()) { - return false; - } - } - } - - return true; - } -} diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/FlowCondImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/FlowCondImpl.java deleted file mode 100644 index e3c3ec3e..00000000 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/FlowCondImpl.java +++ /dev/null @@ -1,468 +0,0 @@ -/* - * Copyright (c) 2014 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.cluster; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; -import java.util.NavigableMap; -import java.util.TreeMap; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.opendaylight.vtn.manager.VTNException; -import org.opendaylight.vtn.manager.flow.cond.FlowCondition; -import org.opendaylight.vtn.manager.flow.cond.FlowMatch; -import org.opendaylight.vtn.manager.internal.ContainerConfig; -import org.opendaylight.vtn.manager.internal.PacketContext; -import org.opendaylight.vtn.manager.internal.VTNManagerImpl; - -import org.opendaylight.controller.sal.core.UpdateType; -import org.opendaylight.controller.sal.utils.Status; -import org.opendaylight.controller.sal.utils.StatusCode; - -/** - * Implementation of flow condition. - * - *- * Although this class is public to other packages, this class does not - * provide any API. Applications other than VTN Manager must not use this - * class. - *
- */ -public final class FlowCondImpl implements Serializable, Cloneable { - /** - * Version number for serialization. - */ - private static final long serialVersionUID = -8740384891077272459L; - - /** - * Logger instance. - */ - private static final Logger LOG = - LoggerFactory.getLogger(FlowCondImpl.class); - - /** - * The name of the flow condition. - */ - private final String name; - - /** - * A list of {@link FlowMatchImpl} instances sorted by match index. - */ - private NavigableMap- * Although this class is public to other packages, this class does not - * provide any API. Applications other than VTN Manager must not use this - * class. - *
- */ -public final class FlowConditionEvent extends ClusterEvent { - /** - * Version number for serialization. - */ - private static final long serialVersionUID = -7615218001174276730L; - - /** - * A pseudo match index which indicates the flow condition itself. - */ - private static final int INDEX_SELF = -1; - - /** - * The name of the flow condition. - */ - private final String name; - - /** - * The match index which specifies the flow match condition in the - * flow condition. - */ - private final int index; - - /** - * Update type of this event. - */ - private final UpdateType updateType; - - /** - * Generate a flow condition event which indicates that the flow condition - * was added, removed, or changed. - * - * @param mgr VTN Manager service. - * @param name The name of the flow condition. - * @param type Update type. - */ - public static void raise(VTNManagerImpl mgr, String name, - UpdateType type) { - raise(mgr, name, INDEX_SELF, type); - } - - /** - * Generate a flow condition event which indicates that the flow match - * condition in the flow condition was added, removed, or changed. - * - * @param mgr VTN Manager service. - * @param name The name of the flow condition. - * @param index The match index that specifies the flow match condition. - * A negative value means that the flow condition itself - * was added, removed, or changed. - * @param type Update type. - */ - public static void raise(VTNManagerImpl mgr, String name, int index, - UpdateType type) { - mgr.enqueueEvent(new FlowConditionEvent(name, index, type)); - } - - /** - * Construct a new flow condition event. - * - * @param name The name of the flow condition. - * @param index The match index that specifies the flow match condition. - * A negative value means that the flow condition itself - * was added, removed, or changed. - * @param type Update type. - */ - private FlowConditionEvent(String name, int index, UpdateType type) { - this.name = name; - this.index = index; - updateType = type; - } - - /** - * Return the name of the flow condition. - * - * @return The name of the flow condition. - */ - public String getName() { - return name; - } - - /** - * Return the match index which specifies the flow match condition in the - * flow condition. - * - * @return The match index. - * A negative value is returned if this event notifies that the - * flow condition was added, removed, or changed. - */ - public int getIndex() { - return index; - } - - /** - * Return update type of this event. - * - * @return Update type. - */ - public UpdateType getUpdateType() { - return updateType; - } - - /** - * Invoked when a cluster event has been received. - * - * @param mgr VTN Manager service. - * @param local {@code true} if this event is generated by the local node. - */ - @Override - protected void eventReceived(VTNManagerImpl mgr, boolean local) { - if (!local) { - mgr.updateFlowCondition(name, index, updateType); - } - } - - /** - * Record a trace log which indicates that a cluster event has been - * received from remote node. - * - * @param mgr VTN Manager service. - * @param logger A logger instance. - * @param key A cluster event key associated with this event. - */ - @Override - public void traceLog(VTNManagerImpl mgr, Logger logger, - ClusterEventId key) { - logger.trace("{}:{}: Received flow condition event: " + - "name={}, type={}, index={}", - mgr.getContainerName(), key, name, updateType, index); - } - - /** - * Determine whether this event should be delivered on the VTN task thread - * or not. - * - * @param local {@code true} if this event is generated by the local node. - * {@code false} if this event is generated by remote cluster - * node. - * @return {@code true} is returned if this event should be delivered - * on the VTN task thread. Otherwise {@code false} is returned. - */ - @Override - public boolean isSingleThreaded(boolean local) { - return true; - } -} diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/FlowFilterImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/FlowFilterImpl.java index ca0a71c7..993ed389 100644 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/FlowFilterImpl.java +++ b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/FlowFilterImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 NEC Corporation + * Copyright (c) 2014-2015 NEC Corporation * All rights reserved. * * This program and the accompanying materials are made available under the @@ -26,6 +26,8 @@ import org.opendaylight.vtn.manager.flow.filter.RedirectFilter; import org.opendaylight.vtn.manager.internal.PacketContext; import org.opendaylight.vtn.manager.internal.VTNManagerImpl; import org.opendaylight.vtn.manager.internal.util.MiscUtils; +import org.opendaylight.vtn.manager.internal.util.flow.cond.FlowCondReader; +import org.opendaylight.vtn.manager.internal.util.flow.cond.VTNFlowCondition; import org.opendaylight.controller.sal.utils.Status; import org.opendaylight.controller.sal.utils.StatusCode; @@ -210,8 +212,8 @@ public abstract class FlowFilterImpl implements Serializable { throws DropFlowException, RedirectFlowException { boolean ret = false; try { - FlowCondImpl fc = getCondition(mgr, pctx); - if (fc.match(mgr, pctx)) { + VTNFlowCondition vfcond = getCondition(pctx); + if (vfcond.match(pctx)) { // Apply this flow filter. if (needFlowAction()) { applyFlowActions(pctx, ffmap); @@ -355,7 +357,7 @@ public abstract class FlowFilterImpl implements Serializable { } /** - * Return a {@link FlowCondImpl} instance which determines whether this + * Return a {@link VTNFlowCondition} instance which determines whether this * flow filter needs to be applied to the given packet. * *@@ -363,13 +365,12 @@ public abstract class FlowFilterImpl implements Serializable { * the given packet or not. *
* - * @param mgr VTN Manager service. * @param pctx A packet context which contains the packet. - * @return A {@link FlowCondImpl} instance which selects the packet. + * @return A {@link VTNFlowCondition} instance which selects the packet. * @throws UnsupportedPacketException * This flow filter does not support the given packet. */ - private FlowCondImpl getCondition(VTNManagerImpl mgr, PacketContext pctx) + private VTNFlowCondition getCondition(PacketContext pctx) throws UnsupportedPacketException { if (!pctx.isUnicast() && !isMulticastSupported()) { throw new UnsupportedPacketException( @@ -381,12 +382,13 @@ public abstract class FlowFilterImpl implements Serializable { "flooding packet is not supported"); } - FlowCondImpl fc = mgr.getFlowCondDB().get(condition); - if (fc == null) { - throw new UnsupportedPacketException("flow condition not found"); + FlowCondReader reader = pctx.getTxContext().getFlowCondReader(); + VTNFlowCondition vfcond = reader.get(condition); + if (vfcond == null) { + throw new UnsupportedPacketException("Flow condition not found"); } - return fc; + return vfcond; } /** diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/FlowMatchImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/FlowMatchImpl.java deleted file mode 100644 index c7dd2f7d..00000000 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/FlowMatchImpl.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Copyright (c) 2014 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.cluster; - -import java.util.Objects; - -import org.opendaylight.vtn.manager.VTNException; -import org.opendaylight.vtn.manager.flow.cond.EthernetMatch; -import org.opendaylight.vtn.manager.flow.cond.FlowMatch; -import org.opendaylight.vtn.manager.flow.cond.InetMatch; -import org.opendaylight.vtn.manager.flow.cond.L4Match; -import org.opendaylight.vtn.manager.internal.PacketContext; -import org.opendaylight.vtn.manager.internal.util.MiscUtils; - -import org.opendaylight.controller.sal.utils.Status; -import org.opendaylight.controller.sal.utils.StatusCode; - -/** - * Implementation of flow match. - * - *- * Although this class is public to other packages, this class does not - * provide any API. Applications other than VTN Manager must not use this - * class. - *
- */ -public final class FlowMatchImpl implements PacketMatch { - /** - * Version number for serialization. - */ - private static final long serialVersionUID = -2201310174894943217L; - - /** - * The minimum value of match index. - */ - private static final int INDEX_MIN = 1; - - /** - * The maximum value of match index. - */ - private static final int INDEX_MAX = 65535; - - /** - * An index value assigned to this condition. - */ - private final int index; - - /** - * Condition to test Ethernet header. - */ - private final EthernetMatchImpl ethernetMatch; - - /** - * Condition to test IP header. - */ - private final InetMatchImpl inetMatch; - - /** - * Condition to layer 4 protocol header in an IP packet. - */ - private final L4MatchImpl l4Match; - - /** - * Construct a new instance. - * - * @param match A {@link FlowMatch} instance. - * @throws VTNException - * {@code match} contains invalid value. - */ - public FlowMatchImpl(FlowMatch match) throws VTNException { - if (match == null) { - Status st = MiscUtils.argumentIsNull("Flow match"); - throw new VTNException(st); - } - - Integer idx = match.getIndex(); - if (idx == null) { - Status st = MiscUtils.argumentIsNull("Match index"); - throw new VTNException(st); - } - - index = idx.intValue(); - if (index < INDEX_MIN || index > INDEX_MAX) { - String msg = "Invalid match index: " + idx; - throw new VTNException(StatusCode.BADREQUEST, msg); - } - - EthernetMatch eth = match.getEthernetMatch(); - InetMatch inet = match.getInetMatch(); - L4Match l4 = match.getLayer4Match(); - - EthernetMatchImpl ematch = (eth == null) - ? null : new EthernetMatchImpl(eth); - InetMatchImpl imatch = (inet == null) - ? null : InetMatchImpl.create(inet); - - if (l4 == null) { - l4Match = null; - } else { - l4Match = L4MatchImpl.create(l4); - - // IP protocol number must be specified. - short proto = l4Match.getInetProtocol(); - if (imatch == null) { - imatch = new Inet4MatchImpl(proto); - } else { - imatch.setProtocol(proto); - } - } - - if (imatch != null) { - // Ethernet type must be specified. - int etype = imatch.getEtherType(); - if (ematch == null) { - ematch = new EthernetMatchImpl(etype); - } else { - ematch.setEtherType(etype); - } - } - - ethernetMatch = ematch; - inetMatch = imatch; - } - - /** - * Return the match index assigned to this instance. - * - * @return The match index. - */ - public int getIndex() { - return index; - } - - /** - * Return a {@link FlowMatch} instance which represents this condition. - * - * @return A {@link FlowMatch} instance. - */ - public FlowMatch getMatch() { - EthernetMatch eth = (ethernetMatch == null) - ? null : ethernetMatch.getMatch(); - InetMatch inet = (inetMatch == null) ? null : inetMatch.getMatch(); - L4Match l4 = (l4Match == null) ? null : l4Match.getMatch(); - - return new FlowMatch(index, eth, inet, l4); - } - - /** - * Determine whether the given object is identical to this object. - * - * @param o An object to be compared. - * @return {@code true} if identical. Otherwise {@code false}. - */ - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (!(o instanceof FlowMatchImpl)) { - return false; - } - - FlowMatchImpl match = (FlowMatchImpl)o; - return (index == match.index && - Objects.equals(ethernetMatch, match.ethernetMatch) && - Objects.equals(inetMatch, match.inetMatch) && - Objects.equals(l4Match, match.l4Match)); - } - - /** - * Return the hash code of this object. - * - * @return The hash code. - */ - @Override - public int hashCode() { - return Objects.hash(ethernetMatch, inetMatch, l4Match) ^ index; - } - - /** - * Return a string representation of this object. - * - * @return A string representation of this object. - */ - @Override - public String toString() { - StringBuilder builder = new StringBuilder("FlowMatchImpl[index="); - builder.append(index); - if (ethernetMatch != null) { - builder.append(",ether=").append(ethernetMatch.toString()); - } - if (inetMatch != null) { - builder.append(",inet=").append(inetMatch.toString()); - } - if (l4Match != null) { - builder.append(",L4=").append(l4Match.toString()); - } - builder.append(']'); - - return builder.toString(); - } - - // PacketMatch - - /** - * Determine whether the specified packet matches the condition defined - * by this instance. - * - * @param pctx The context of the packet to be tested. - * @return {@code true} if the specified packet matches the condition. - * Otherwise {@code false}. - */ - @Override - public boolean match(PacketContext pctx) { - // Test Ethernet header. - if (ethernetMatch != null && !ethernetMatch.match(pctx)) { - return false; - } - - // Test IP header. - if (inetMatch != null && !inetMatch.match(pctx)) { - return false; - } - - // Test layer 4 protocol header. - return (l4Match == null || l4Match.match(pctx)); - } -} diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/IcmpMatchImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/IcmpMatchImpl.java deleted file mode 100644 index 25a63199..00000000 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/IcmpMatchImpl.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright (c) 2014-2015 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.cluster; - -import org.opendaylight.vtn.manager.VTNException; -import org.opendaylight.vtn.manager.flow.cond.IcmpMatch; -import org.opendaylight.vtn.manager.flow.cond.L4Match; -import org.opendaylight.vtn.manager.util.NumberUtils; - -import org.opendaylight.vtn.manager.internal.PacketContext; -import org.opendaylight.vtn.manager.internal.packet.cache.CachedPacket; -import org.opendaylight.vtn.manager.internal.packet.cache.IcmpPacket; -import org.opendaylight.vtn.manager.internal.util.ProtocolUtils; - -import org.opendaylight.controller.sal.match.MatchType; -import org.opendaylight.controller.sal.utils.IPProtocols; -import org.opendaylight.controller.sal.utils.StatusCode; - -/** - * {@code IcmpMatchImpl} describes the condition to match ICMP header fields - * in IPv4 packet. - * - *- * Although this class is public to other packages, this class does not - * provide any API. Applications other than VTN Manager must not use this - * class. - *
- */ -public final class IcmpMatchImpl extends L4MatchImpl { - /** - * Version number for serialization. - */ - private static final long serialVersionUID = -5344880600123638848L; - - /** - * A value which indicates every ICMP type and code should match. - */ - private static final short VALUE_ANY = -1; - - /** - * ICMP type value to match. - */ - private final short type; - - /** - * ICMP code value to match. - */ - private final short code; - - /** - * Construct a new instance. - * - * @param match An {@link IcmpMatch} instance. - * @throws NullPointerException - * {@code match} is {@code null}. - * @throws VTNException - * {@code match} contains invalid value. - */ - public IcmpMatchImpl(IcmpMatch match) throws VTNException { - type = getValue(match.getType(), "ICMP type"); - code = getValue(match.getCode(), "ICMP code"); - } - - /** - * Return ICMP type value configured in this instance. - * - * @return An ICMP type value. - * A negative value is returned if ICMP type is not specified. - */ - public short getType() { - return type; - } - - /** - * Return ICMP code value configured in this instance. - * - * @return An ICMP code value. - * A negative value is returned if ICMP code is not specified. - */ - public short getCode() { - return code; - } - - /** - * Return a short value in the specified instance. - * - * @param s A {@link Short} instance. - * @param desc A brief description about the value. - * @return A short integer value in the given instance. - * {@link #VALUE_ANY} is returned if {@code null} is specified - * to {@code s}. - * @throws VTNException - * An invalid value is configured in {@code s}. - */ - private short getValue(Short s, String desc) throws VTNException { - if (s == null) { - return VALUE_ANY; - } - - short value = s.shortValue(); - if (!ProtocolUtils.isIcmpValueValid(value)) { - throw new VTNException(StatusCode.BADREQUEST, - "Invalid value for " + desc + ": " + s); - } - - return value; - } - - /** - * Return a {@link Short} instance which represents the given value. - * - * @param value A short value. - * @return A {@link Short} instance. - * {@code null} is returned if a negative value is specified. - */ - private Short getShort(short value) { - return (value < 0) ? null : Short.valueOf(value); - } - - /** - * Determine whether the given object is identical to this object. - * - * @param o An object to be compared. - * @return {@code true} if identical. Otherwise {@code false}. - */ - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (!(o instanceof IcmpMatchImpl)) { - return false; - } - - IcmpMatchImpl match = (IcmpMatchImpl)o; - return (type == match.type && code == match.code); - } - - /** - * Return the hash code of this object. - * - * @return The hash code. - */ - @Override - public int hashCode() { - return (int)(((int)type << Short.SIZE) | - (int)(code & NumberUtils.MASK_SHORT)); - } - - // L4PacketMatch - - /** - * Return an IP protocol number assigned to this protocol. - * - * @return An IP protocol number. - */ - @Override - public short getInetProtocol() { - return IPProtocols.ICMP.shortValue(); - } - - /** - * Return a {@link L4Match} instance which represents this condition. - * - * @return A {@link L4Match} instance. - */ - @Override - public L4Match getMatch() { - return new IcmpMatch(getShort(type), getShort(code)); - } - - // PacketMatch - - /** - * Determine whether the specified packet matches the condition defined - * by this instance. - * - * @param pctx The context of the packet to be tested. - * @return {@code true} if the specified packet matches the condition. - * Otherwise {@code false}. - */ - @Override - public boolean match(PacketContext pctx) { - CachedPacket packet = pctx.getL4Packet(); - if (!(packet instanceof IcmpPacket)) { - return false; - } - - IcmpPacket icmp = (IcmpPacket)packet; - if (type >= 0) { - pctx.addMatchField(MatchType.TP_SRC); - if (type != icmp.getType()) { - return false; - } - } - if (code >= 0) { - pctx.addMatchField(MatchType.TP_DST); - if (code != icmp.getCode()) { - return false; - } - } - - return true; - } - - /** - * Return a string representation of this object. - * - * @return A string representation of this object. - */ - @Override - public String toString() { - StringBuilder builder = new StringBuilder("IcmpMatchImpl["); - String sep = ""; - if (type != VALUE_ANY) { - builder.append("type=").append((int)type); - sep = ","; - } - if (code != VALUE_ANY) { - builder.append(sep).append("code=").append((int)code); - } - builder.append(']'); - - return builder.toString(); - } -} diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/Inet4AddressMatch.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/Inet4AddressMatch.java deleted file mode 100644 index 37c0c7cf..00000000 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/Inet4AddressMatch.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright (c) 2014-2015 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.cluster; - -import java.net.InetAddress; -import java.io.Serializable; - -import org.opendaylight.vtn.manager.VTNException; -import org.opendaylight.vtn.manager.util.NumberUtils; - -import org.opendaylight.vtn.manager.internal.util.MiscUtils; - -import org.opendaylight.controller.sal.utils.StatusCode; - -/** - * {@code Inet4AddressMatch} describes an IPv4 address and netmask. - * - *- * Although this class is public to other packages, this class does not - * provide any API. Applications other than VTN Manager must not use this - * class. - *
- */ -public final class Inet4AddressMatch implements Serializable { - /** - * Version number for serialization. - */ - private static final long serialVersionUID = -4629368100388947618L; - - /** - * An IP address mask value which indicates all bits in an IPv4 address. - */ - public static final int MASK_ALL = -1; - - /** - * The number of bits in an IPv4 address. - */ - private static final int LENGTH = 32; - - /** - * The minimum value of the CIDR suffix. - */ - protected static final int CIDR_SUFFIX_MIN = 1; - - /** - * The maximum value of the CIDR suffix. - */ - protected static final int CIDR_SUFFIX_MAX = LENGTH - 1; - - /** - * An IPv4 address. - */ - private final int address; - - /** - * A netmask used to test IP address. - */ - private final int mask; - - /** - * Construct a new instance. - * - * @param addr An {@link InetAddress} instance which represents an - * IPv4 address. - * @param suff A {@link Short} instance which represents a CIDR suffix - * which represents netmask. - * @throws NullPointerException - * {@code addr} is {@code null}. - * @throws VTNException - * Invalid value is specified to {@code suff}. - */ - public Inet4AddressMatch(InetAddress addr, Short suff) - throws VTNException { - mask = toNetMask(suff); - address = NumberUtils.toInteger(addr.getAddress()) & mask; - } - - /** - * Return an integer value which represents an IPv4 address configured in - * this instance. - * - * @return An integer value which represents an IPv4 address. - */ - public int getAddress() { - return address; - } - - /** - * Return an {@link InetAddress} instance configured in this instance. - * - * @return An {@link InetAddress} instance. - * @throws IllegalStateException - * An error occurred. - */ - public InetAddress getInetAddress() { - return MiscUtils.toInetAddress(address); - } - - /** - * Return a netmask configured in this instance. - * - * @return A netmask configured in this instance. - * {@link #MASK_ALL} is returned if no netmask is configured. - */ - public int getMask() { - return mask; - } - - /** - * Return a CIDR suffix configured in this instance. - * - * @return A {@link Short} instance which represents a CIDR suffix. - * {@code null} is returned if no CIDR suffix is configured. - */ - public Short getCidrSuffix() { - if (mask == MASK_ALL) { - return null; - } - - int nbits = Integer.SIZE - Integer.numberOfTrailingZeros(mask); - return Short.valueOf((short)nbits); - } - - /** - * Determine whether the specified IPv4 address match the condition - * described by this instance. - * - * @param addr An integer value which represents an IPv4 address. - * @return {@code true} is returned if the specified IPv4 address matches - * the condition. Otherwise {@code false} is returned. - */ - public boolean match(int addr) { - return (address == (addr & mask)); - } - - /** - * Convert a CIDR suffix into netmask. - * - * @param suffix A {@link Short} instance which represents a CIDR suffix. - * @return A netmask converted from {@code suffix}. - * @throws VTNException - * An invalid CIDR suffix is specified. - */ - private int toNetMask(Short suffix) throws VTNException { - if (suffix == null) { - return MASK_ALL; - } - - int suff = suffix.intValue(); - if (suff < CIDR_SUFFIX_MIN || suff > CIDR_SUFFIX_MAX) { - String msg = "Invalid CIDR suffix: " + suff; - throw new VTNException(StatusCode.BADREQUEST, msg); - } - - int nzeroes = LENGTH - suff; - return (MASK_ALL << nzeroes); - } - - /** - * Determine whether the given object is identical to this object. - * - * @param o An object to be compared. - * @return {@code true} if identical. Otherwise {@code false}. - */ - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (!(o instanceof Inet4AddressMatch)) { - return false; - } - - Inet4AddressMatch cond = (Inet4AddressMatch)o; - - return (address == cond.address && mask == cond.mask); - } - - /** - * Return the hash code of this object. - * - * @return The hash code. - */ - @Override - public int hashCode() { - int h = address; - if (mask != MASK_ALL) { - h += Integer.numberOfTrailingZeros(mask); - } - - return h; - } - - /** - * Return a string representation of this object. - * - * @return A string representation of this object. - */ - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - byte[] addr = NumberUtils.toBytes(address); - String sep = ""; - for (byte b: addr) { - int i = NumberUtils.getUnsigned(b); - builder.append(sep).append(i); - sep = "."; - } - - if (mask != MASK_ALL) { - int suff = Integer.SIZE - Integer.numberOfTrailingZeros(mask); - builder.append('/').append(suff); - } - - return builder.toString(); - } -} diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/Inet4MatchImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/Inet4MatchImpl.java deleted file mode 100644 index b81f48a2..00000000 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/Inet4MatchImpl.java +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (c) 2014-2015 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.cluster; - -import java.net.InetAddress; -import java.util.Objects; - -import org.opendaylight.vtn.manager.VTNException; -import org.opendaylight.vtn.manager.flow.cond.Inet4Match; -import org.opendaylight.vtn.manager.flow.cond.InetMatch; -import org.opendaylight.vtn.manager.internal.PacketContext; -import org.opendaylight.vtn.manager.internal.packet.cache.Inet4Packet; - -import org.opendaylight.controller.sal.match.MatchType; -import org.opendaylight.controller.sal.utils.EtherTypes; - -/** - * {@code Inet4MatchImpl} describes the condition to match IPv4 header fields - * in packet. - * - *- * Although this class is public to other packages, this class does not - * provide any API. Applications other than VTN Manager must not use this - * class. - *
- */ -public final class Inet4MatchImpl extends InetMatchImpl { - /** - * Version number for serialization. - */ - private static final long serialVersionUID = 2950598600572887764L; - - /** - * A source IP address to match against packets. - */ - private final Inet4AddressMatch source; - - /** - * A destination IP address to match against packets. - */ - private final Inet4AddressMatch destination; - - /** - * Construct a new instance that contains only the condition for the - * IP protocol number. - * - * @param proto An IP protocol number to match. - */ - public Inet4MatchImpl(short proto) { - super(proto); - source = null; - destination = null; - } - - /** - * Construct a new instance. - * - * @param match An {@link InetMatch} instance. - * @throws NullPointerException - * {@code match} is {@code null}. - * @throws VTNException - * {@code match} contains invalid value. - */ - public Inet4MatchImpl(InetMatch match) throws VTNException { - super(match); - - InetAddress addr = match.getSourceAddress(); - if (addr == null) { - source = null; - } else { - Short suffix = match.getSourceSuffix(); - source = new Inet4AddressMatch(addr, suffix); - } - - addr = match.getDestinationAddress(); - if (addr == null) { - destination = null; - } else { - Short suffix = match.getDestinationSuffix(); - destination = new Inet4AddressMatch(addr, suffix); - } - } - - /** - * Return an {@link Inet4AddressMatch} instance which represents the source - * IP address to match against packets. - * - * @return An {@link Inet4AddressMatch} instance which represents a - * source IP address. {@code null} is returned if this condition - * does not specify the source IP address. - */ - public Inet4AddressMatch getSource() { - return source; - } - - /** - * Return an {@link Inet4AddressMatch} instance which represents the - * destination IP address to match against packets. - * - * @return An {@link Inet4AddressMatch} instance which represents the - * destination IP address. {@code null} is returned if this - * condition does not specify the destination IP address. - */ - public Inet4AddressMatch getDestination() { - return destination; - } - - /** - * Determine whether the given object is identical to this object. - * - * @param o An object to be compared. - * @return {@code true} if identical. Otherwise {@code false}. - */ - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (!super.equals(o)) { - return false; - } - - Inet4MatchImpl match = (Inet4MatchImpl)o; - return (Objects.equals(source, match.source) && - Objects.equals(destination, match.destination)); - } - - /** - * Return the hash code of this object. - * - * @return The hash code. - */ - @Override - public int hashCode() { - return Objects.hash(source, destination) + (super.hashCode() * 31); - } - - /** - * Return a string representation of this object. - * - * @return A string representation of this object. - */ - @Override - public String toString() { - StringBuilder builder = new StringBuilder("Inet4MatchImpl["); - String sep = ""; - if (source != null) { - builder.append("src=").append(source.toString()); - sep = ","; - } - if (destination != null) { - builder.append(sep).append("dst=").append(destination.toString()); - sep = ","; - } - - short proto = getProtocol(); - if (proto >= 0) { - builder.append(sep).append("proto=").append((int)proto); - sep = ","; - } - - byte dscp = getDscp(); - if (dscp >= 0) { - builder.append(sep).append("dscp=").append((int)dscp); - } - builder.append(']'); - - return builder.toString(); - } - - // PacketMatch - - /** - * Determine whether the specified packet matches the condition defined - * by this instance. - * - * @param pctx The context of the packet to be tested. - * @return {@code true} if the specified packet matches the condition. - * Otherwise {@code false}. - */ - @Override - public boolean match(PacketContext pctx) { - Inet4Packet ipv4 = pctx.getInet4Packet(); - if (ipv4 == null) { - return false; - } - - // Test source IP address. - if (source != null) { - pctx.addMatchField(MatchType.NW_SRC); - if (!source.match(ipv4.getSourceAddress())) { - return false; - } - } - - // Test destination IP address. - if (destination != null) { - pctx.addMatchField(MatchType.NW_DST); - if (!destination.match(ipv4.getDestinationAddress())) { - return false; - } - } - - return match(pctx, ipv4.getProtocol(), ipv4.getDscp()); - } - - // InetMatchImpl - - /** - * Return an Ethernet protocol type assigned to this protocol. - * - * @return An Ethernet protocol type for IPv4. - */ - @Override - public int getEtherType() { - return EtherTypes.IPv4.intValue(); - } - - /** - * Return an {@link InetMatch} instance which represents this condition. - * - * @return An {@link InetMatch} instance. - */ - @Override - public InetMatch getMatch() { - InetAddress src, dst; - Short srcSuff, dstSuff; - if (source == null) { - src = null; - srcSuff = null; - } else { - src = source.getInetAddress(); - srcSuff = source.getCidrSuffix(); - } - - if (destination == null) { - dst = null; - dstSuff = null; - } else { - dst = destination.getInetAddress(); - dstSuff = destination.getCidrSuffix(); - } - - return new Inet4Match(src, srcSuff, dst, dstSuff, getProtocolShort(), - getDscpByte()); - } -} diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/InetAddressActionImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/InetAddressActionImpl.java index f07ed70c..28d984f8 100644 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/InetAddressActionImpl.java +++ b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/InetAddressActionImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 NEC Corporation + * Copyright (c) 2014-2015 NEC Corporation * All rights reserved. * * This program and the accompanying materials are made available under the @@ -9,10 +9,9 @@ package org.opendaylight.vtn.manager.internal.cluster; -import java.net.InetAddress; - import org.opendaylight.vtn.manager.VTNException; import org.opendaylight.vtn.manager.flow.action.InetAddressAction; +import org.opendaylight.vtn.manager.util.IpNetwork; import org.opendaylight.vtn.manager.internal.util.MiscUtils; @@ -36,7 +35,7 @@ public abstract class InetAddressActionImpl extends FlowActionImpl { /** * IP address to be set. */ - private final InetAddress address; + private final IpNetwork address; /** * Construct a new instance. @@ -54,7 +53,7 @@ public abstract class InetAddressActionImpl extends FlowActionImpl { throw new VTNException(st); } - address = act.getAddress(); + address = act.getIpNetwork(); if (address == null) { String msg = getErrorMessage(act, "IP address"); st = MiscUtils.argumentIsNull(msg); @@ -65,9 +64,9 @@ public abstract class InetAddressActionImpl extends FlowActionImpl { /** * Return an IP address to be set. * - * @return An {@link InetAddress} instance. + * @return An {@link IpNetwork} instance. */ - protected final InetAddress getAddress() { + protected final IpNetwork getAddress() { return address; } @@ -108,7 +107,7 @@ public abstract class InetAddressActionImpl extends FlowActionImpl { @Override public String toString() { StringBuilder builder = new StringBuilder(getClass().getSimpleName()); - return builder.append("[addr=").append(address.getHostAddress()). + return builder.append("[addr=").append(address.getText()). append(']').toString(); } } diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/InetMatchImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/InetMatchImpl.java deleted file mode 100644 index f3b439ae..00000000 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/InetMatchImpl.java +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright (c) 2014-2015 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.cluster; - -import org.opendaylight.vtn.manager.VTNException; -import org.opendaylight.vtn.manager.flow.cond.Inet4Match; -import org.opendaylight.vtn.manager.flow.cond.InetMatch; -import org.opendaylight.vtn.manager.util.NumberUtils; - -import org.opendaylight.vtn.manager.internal.PacketContext; -import org.opendaylight.vtn.manager.internal.util.ProtocolUtils; - -import org.opendaylight.controller.sal.match.MatchType; -import org.opendaylight.controller.sal.utils.Status; -import org.opendaylight.controller.sal.utils.StatusCode; - -/** - * {@code InetMatchImpl} describes the condition to match IP protocol header - * fields in packet. - * - *- * Although this class is public to other packages, this class does not - * provide any API. Applications other than VTN Manager must not use this - * class. - *
- */ -public abstract class InetMatchImpl implements PacketMatch { - /** - * Version number for serialization. - */ - private static final long serialVersionUID = 7890231558329145625L; - - /** - * A pseudo IP protocol number which indicates every protocol number - * shold match. - */ - protected static final short PROTO_ANY = -1; - - /** - * A pseudo DSCP field value which indicates every DSCP value should match. - */ - protected static final byte DSCP_ANY = -1; - - /** - * A mask value which represents valid bits in an IP protocol number. - */ - private static final short MASK_PROTO = 0xff; - - /** - * An IP protocol type value to match against packets. - */ - private short protocol; - - /** - * A DSCP field value to match against packets. - */ - private final byte dscp; - - /** - * Create a new {@code InetMatchImpl} instance from the given - * {@link InetMatch} instance. - * - * @param match A {@link InetMatch} instance. - * @return A {@link InetMatch} instance constructed from {@code match}. - * @throws VTNException - * An invalid instance is specified to {@code match}. - */ - public static final InetMatchImpl create(InetMatch match) - throws VTNException { - if (match instanceof Inet4Match) { - return new Inet4MatchImpl((Inet4Match)match); - } - - // This should never happen. - throw new VTNException(StatusCode.BADREQUEST, - "Unexpected inet match instance: " + match); - } - - /** - * Construct a new instance that contains only the condition for the - * IP protocol number. - * - * @param proto An IP protocol number to match. - */ - protected InetMatchImpl(short proto) { - protocol = proto; - dscp = DSCP_ANY; - } - - /** - * Construct a new instance. - * - * @param match An {@link InetMatch} instance. - * @throws NullPointerException - * {@code match} is {@code null}. - * @throws VTNException - * {@code match} contains invalid value. - */ - protected InetMatchImpl(InetMatch match) throws VTNException { - Status st = match.getValidationStatus(); - if (st != null) { - throw new VTNException(st); - } - - Short proto = match.getProtocol(); - if (proto == null) { - protocol = PROTO_ANY; - } else { - protocol = proto.shortValue(); - if ((protocol & ~MASK_PROTO) != 0) { - String msg = "Invalid IP protocol number: " + proto; - throw new VTNException(StatusCode.BADREQUEST, msg); - } - } - - Byte d = match.getDscp(); - if (d == null) { - dscp = DSCP_ANY; - } else { - dscp = d.byteValue(); - if (!ProtocolUtils.isDscpValid(dscp)) { - String msg = "Invalid DSCP field value: " + d; - throw new VTNException(StatusCode.BADREQUEST, msg); - } - } - } - - /** - * Return the IP protocol type to match against packets. - * - * @return A short integer value which represents the IP protocol type - * to match against packets. - * A negative value is returned if this instance does not - * specify the IP protocol type to match. - */ - public final short getProtocol() { - return protocol; - } - - /** - * Return the IP protocol type to match against packets. - * - * @return A {@link Short} instance which represents the IP protocol type - * to match against packets. - * {@code null} is returned if this instance does not - * specify the IP protocol type to match. - */ - public final Short getProtocolShort() { - return (protocol < 0) ? null : Short.valueOf(protocol); - } - - /** - * Return the DSCP field value to match against packets. - * - * @return A byte value which represents the DSCP field value to match - * against packets. - * A negative value is returned if this instance does not - * specify the DSCP field value to match. - */ - public final byte getDscp() { - return dscp; - } - - /** - * Return the DSCP field value to match against packets. - * - * @return A {@link Byte} instance which represents the DSCP field value - * to match against packets. - * {@code null} is returned if this instance does not specify - * the DSCP field value to match. - */ - public final Byte getDscpByte() { - return (dscp < 0) ? null : Byte.valueOf(dscp); - } - - /** - * Determine whether the IP protocol number and DSCP field match the - * condition described by this instance. - * - * @param pctx The context of the packet to be tested. - * @param proto An IP protocol number to be tested. - * @param ds A DSCP field value to be tested. - * @return {@code true} is returned if the specified arguments match the - * condition. Otherwise {@code false} is returned. - */ - public final boolean match(PacketContext pctx, short proto, byte ds) { - if (protocol >= 0) { - pctx.addMatchField(MatchType.NW_PROTO); - if (protocol != proto) { - return false; - } - } - - if (dscp >= 0) { - pctx.addMatchField(MatchType.NW_TOS); - if (dscp != ds) { - return false; - } - } - - return true; - } - - /** - * Set the IP protocol number to match against packets. - * - * @param proto An IP protocol number. - * @throws VTNException - * The specified protocol number is different from the number configured - * in this instance. - */ - void setProtocol(short proto) throws VTNException { - if (protocol != PROTO_ANY && protocol != proto) { - StringBuilder builder = - new StringBuilder("IP protocol conflict: proto="); - builder.append((int)protocol).append(", expected="). - append((int)proto); - throw new VTNException(StatusCode.BADREQUEST, builder.toString()); - } - - protocol = proto; - } - - /** - * Determine whether the given object is identical to this object. - * - * @param o An object to be compared. - * @return {@code true} if identical. Otherwise {@code false}. - */ - @Override - public boolean equals(Object o) { - if (o == null || !getClass().equals(o.getClass())) { - return false; - } - - InetMatchImpl match = (InetMatchImpl)o; - return (protocol == match.protocol && dscp == match.dscp); - } - - /** - * Return the hash code of this object. - * - * @return The hash code. - */ - @Override - public int hashCode() { - int h = (int)(((int)protocol << Byte.SIZE) | - (dscp & NumberUtils.MASK_BYTE)); - return h; - } - - /** - * Return an Ethernet protocol type assigned to this protocol. - * - * @return An Ethernet protocol type. - */ - public abstract int getEtherType(); - - /** - * Return an {@link InetMatch} instance which represents this condition. - * - * @return An {@link InetMatch} instance. - */ - public abstract InetMatch getMatch(); -} diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/L4MatchImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/L4MatchImpl.java deleted file mode 100644 index e2adbe7e..00000000 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/L4MatchImpl.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2014 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.cluster; - -import org.opendaylight.vtn.manager.VTNException; -import org.opendaylight.vtn.manager.flow.cond.IcmpMatch; -import org.opendaylight.vtn.manager.flow.cond.L4Match; -import org.opendaylight.vtn.manager.flow.cond.TcpMatch; -import org.opendaylight.vtn.manager.flow.cond.UdpMatch; - -import org.opendaylight.controller.sal.utils.StatusCode; - -/** - * {@code L4MatchImpl} describes the condition to match layer 4 protocol - * header fields in packet. - * - *- * Although this class is public to other packages, this class does not - * provide any API. Applications other than VTN Manager must not use this - * class. - *
- */ -public final class L4PortMatch implements Serializable { - /** - * Version number for serialization. - */ - private static final long serialVersionUID = 5154123070973523206L; - - /** - * The minimum value (inclusive) in the range of TCP/UDP port numbers - * to match against packets. - */ - private final int portFrom; - - /** - * The maximum value (inclusive) in the range of TCP/UDP port numbers - * to match against packets. - */ - private final int portTo; - - /** - * Construct a new instance. - * - * @param match A {@link PortMatch} instance. - * @throws NullPointerException - * {@code match} is {@code null}. - * @throws VTNException - * {@code match} contains invalid value. - */ - public L4PortMatch(PortMatch match) throws VTNException { - Integer from = match.getPortFrom(); - if (from == null) { - throw new VTNException(StatusCode.BADREQUEST, - "\"from\" is not specified."); - } - - portFrom = from.intValue(); - checkPort(portFrom, "from"); - - Integer to = match.getPortTo(); - if (to == null) { - portTo = portFrom; - } else { - portTo = to.intValue(); - checkPort(portTo, "to"); - if (from > to) { - StringBuilder builder = - new StringBuilder("Invalid port range: from="); - builder.append(portFrom).append(", to=").append(portTo); - throw new VTNException(StatusCode.BADREQUEST, - builder.toString()); - } - } - } - - /** - * Return the minimum (inclusive) value in the range of TCP/UDP port - * numbers to match against packets. - * - * @return The minimum value in the range of TCP/UDP port numbers. - */ - public int getPortFrom() { - return portFrom; - } - - /** - * Return the maximum (inclusive) value in the range of TCP/UDP port - * numbers to match against packets. - * - * @return The maximum value in the range of TCP/UDP port numbers. - */ - public int getPortTo() { - return portTo; - } - - /** - * Determine whether the given port number is in the range configured - * in this instance. - * - * @param port A port number to be tested. - * @return {@code true} is returned if the specified port number is - * in the range of port numbers specified by this instance. - * Otherwise {@code false} is returned. - */ - public boolean match(int port) { - return (port >= portFrom && port <= portTo); - } - - /** - * Validate the given port number. - * - * @param port A port number. - * @param desc A brief description about the value. - * @throws VTNException - * An invalid port number is specified. - */ - private void checkPort(int port, String desc) throws VTNException { - if (!ProtocolUtils.isPortNumberValid(port)) { - StringBuilder builder = new StringBuilder(desc); - builder.append(": Invalid port number: ").append(port); - throw new VTNException(StatusCode.BADREQUEST, builder.toString()); - } - } - - /** - * Determine whether the given object is identical to this object. - * - * @param o An object to be compared. - * @return {@code true} if identical. Otherwise {@code false}. - */ - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (!(o instanceof L4PortMatch)) { - return false; - } - - L4PortMatch match = (L4PortMatch)o; - return (portFrom == match.portFrom && portTo == match.portTo); - } - - /** - * Return the hash code of this object. - * - * @return The hash code. - */ - @Override - public int hashCode() { - return portFrom + portTo * 17; - } - - /** - * Return a string representation of this object. - * - * @return A string representation of this object. - */ - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append(portFrom); - if (portTo != portFrom) { - builder.append('-').append(portTo); - } - - return builder.toString(); - } -} diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/MapType.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/MapType.java index 0b2fb902..378cdf60 100644 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/MapType.java +++ b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/MapType.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 NEC Corporation + * Copyright (c) 2013-2015 NEC Corporation * All rights reserved. * * This program and the accompanying materials are made available under the @@ -11,7 +11,7 @@ package org.opendaylight.vtn.manager.internal.cluster; import org.opendaylight.vtn.manager.VNodeRoute.Reason; -import org.opendaylight.controller.sal.match.MatchType; +import org.opendaylight.vtn.manager.internal.util.flow.match.FlowMatchType; /** * {@code MapType} class represents types of mappings between virtual and @@ -26,7 +26,7 @@ public enum MapType { /** * MAC mapping. */ - MAC(1 << 1, Reason.MACMAPPED, MatchType.DL_SRC), + MAC(1 << 1, Reason.MACMAPPED, FlowMatchType.DL_SRC), /** * VLAN mapping. @@ -50,10 +50,10 @@ public enum MapType { private final Reason reason; /** - * A {@link MatchType} instance which represents flow match field + * A {@link FlowMatchType} instance which represents flow match field * to be specfied in the ingress flow entry. */ - private final MatchType matchType; + private final FlowMatchType matchType; /** * Construct a new mapping type. @@ -81,10 +81,10 @@ public enum MapType { * @param mask A bitmask which identifies the mapping type. * @param reason A {@link Reason} instance associated with the mapping * type. - * @param mtype A {@link MatchType} instance which represents flow match - * fields to specify the packet. + * @param mtype A {@link FlowMatchType} instance which represents flow + * match fields to specify the packet. */ - private MapType(int mask, Reason reason, MatchType mtype) { + private MapType(int mask, Reason reason, FlowMatchType mtype) { this.mask = mask; this.reason = reason; matchType = mtype; @@ -112,14 +112,14 @@ public enum MapType { } /** - * Return a {@link MatchType} instance which represents the flow match + * Return a {@link FlowMatchType} instance which represents the flow match * field to be specified in the ingress flow entry. * - * @return A {@link MatchType} instance. + * @return A {@link FlowMatchType} instance. * {@code null} is returned if no additional match field is * required. */ - public MatchType getMatchType() { + public FlowMatchType getMatchType() { return matchType; } } diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/PacketMatch.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/PacketMatch.java deleted file mode 100644 index e4679fb9..00000000 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/PacketMatch.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2014 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.cluster; - -import java.io.Serializable; - -import org.opendaylight.vtn.manager.internal.PacketContext; - -/** - * {@code PacketMatch} defines interfaces to be implemented by classes - * which tests protocol header files in packet. - * - *- * Although this interface is public to other packages, this class does not - * provide any API. Applications other than VTN Manager must not use this - * class. - *
- */ -public interface PacketMatch extends Serializable { - /** - * Determine whether the specified packet matches the condition defined - * by this instance. - * - * @param pctx The context of the packet to be tested. - * @return {@code true} if the specified packet matches the condition. - * Otherwise {@code false}. - */ - boolean match(PacketContext pctx); -} diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/PathMapImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/PathMapImpl.java index d3391e69..9d613ade 100644 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/PathMapImpl.java +++ b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/PathMapImpl.java @@ -21,6 +21,8 @@ import org.opendaylight.vtn.manager.internal.PacketContext; import org.opendaylight.vtn.manager.internal.RouteResolver; import org.opendaylight.vtn.manager.internal.VTNManagerImpl; import org.opendaylight.vtn.manager.internal.util.MiscUtils; +import org.opendaylight.vtn.manager.internal.util.flow.cond.FlowCondReader; +import org.opendaylight.vtn.manager.internal.util.flow.cond.VTNFlowCondition; import org.opendaylight.vtn.manager.internal.util.pathpolicy.PathPolicyConfigBuilder; import org.opendaylight.controller.sal.core.NodeConnector; @@ -199,9 +201,10 @@ public abstract class PathMapImpl * packet. Otherwise {@code null}. */ public RouteResolver evaluate(VTNManagerImpl mgr, PacketContext pctx) { - FlowCondImpl fc = mgr.getFlowCondDB().get(condition); + FlowCondReader reader = pctx.getTxContext().getFlowCondReader(); + VTNFlowCondition vfcond = reader.get(condition); Logger logger = getLogger(); - if (fc == null) { + if (vfcond == null) { logger.debug("{}{}: Ignore path map: condition not found: {}", mgr.getContainerName(), getLogPrefix(), condition); return null; @@ -214,7 +217,7 @@ public abstract class PathMapImpl return null; } - if (fc.match(mgr, pctx)) { + if (vfcond.match(pctx)) { if (idleTimeout >= 0) { // Set flow timeout. pctx.setFlowTimeout(idleTimeout, hardTimeout); diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/PortBridge.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/PortBridge.java index 597c4c34..8ab11447 100644 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/PortBridge.java +++ b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/PortBridge.java @@ -22,7 +22,6 @@ import org.opendaylight.vtn.manager.VNodePath; import org.opendaylight.vtn.manager.VNodeState; import org.opendaylight.vtn.manager.VTNException; import org.opendaylight.vtn.manager.VTenantPath; -import org.opendaylight.vtn.manager.util.EtherAddress; import org.opendaylight.vtn.manager.internal.ActionList; import org.opendaylight.vtn.manager.internal.LockStack; @@ -198,8 +197,8 @@ public abstract class PortBridge- * Although this class is public to other packages, this class does not - * provide any API. Applications other than VTN Manager must not use this - * class. - *
- */ -public abstract class PortProtoMatchImpl extends L4MatchImpl { - /** - * Version number for serialization. - */ - private static final long serialVersionUID = -5599948746651922234L; - - /** - * A {@link L4PortMatch} instance which describes the range of - * source port numbers to match against packets. - */ - private final L4PortMatch sourcePort; - - /** - * A {@link L4PortMatch} instance which describes the range of - * destination port numbers to match against packets. - */ - private final L4PortMatch destinationPort; - - /** - * Construct a new instance. - * - * @param match An {@link PortProtoMatch} instance. - * @throws NullPointerException - * {@code match} is {@code null}. - * @throws VTNException - * {@code match} contains invalid value. - */ - protected PortProtoMatchImpl(PortProtoMatch match) throws VTNException { - sourcePort = getL4PortMatch(match.getSourcePort(), "source"); - destinationPort = getL4PortMatch(match.getDestinationPort(), - "destination"); - } - - /** - * Return a {@link L4PortMatch} instance which describes the range of - * source port numbers to match against packets. - * - * @return A {@link L4PortMatch} instances which describes the source - * port numbers to match. - * {@code null} is returned if no source port number is specified. - */ - public final L4PortMatch getSourcePort() { - return sourcePort; - } - - /** - * Return a {@link L4PortMatch} instance which describes the range of - * destination port numbers to match against packets. - * - * @return A {@link L4PortMatch} instance which describes the destination - * port numbers to match. - * {@code null} is returned if no destination port number is - * specified. - */ - public final L4PortMatch getDestinationPort() { - return destinationPort; - } - - /** - * Return a {@link PortMatch} instance which represents the specified - * {@link L4PortMatch} instance. - * - * @param match A {@link L4PortMatch} instance. - * @return A {@link PortMatch} instance. - * {@code null} is returned if {@code null} is specified. - */ - protected PortMatch getPortMatch(L4PortMatch match) { - if (match == null) { - return null; - } - - int from = match.getPortFrom(); - int to = match.getPortTo(); - return (from == to) - ? new PortMatch(Integer.valueOf(from)) - : new PortMatch(Integer.valueOf(from), Integer.valueOf(to)); - } - - /** - * Return a {@link L4PortMatch} instance which represents the contents - * of the specified {@link PortMatch} instance. - * - * @param match A {@link PortMatch} instance. - * @param desc A brief description about the value. - * @return A {@link L4PortMatch} instance. - * {@code null} is returned if {@code match} is {@code null}. - * @throws VTNException - * {@code match} contains invalid value. - */ - private L4PortMatch getL4PortMatch(PortMatch match, String desc) - throws VTNException { - if (match == null) { - return null; - } - - try { - return new L4PortMatch(match); - } catch (VTNException e) { - StringBuilder builder = new StringBuilder(desc); - builder.append(": ").append(e.getStatus().getDescription()); - Status st = new Status(StatusCode.BADREQUEST, builder.toString()); - throw new VTNException(st, e); - } - } - - /** - * Determine whether the given object is identical to this object. - * - * @param o An object to be compared. - * @return {@code true} if identical. Otherwise {@code false}. - */ - @Override - public final boolean equals(Object o) { - if (o == this) { - return true; - } - if (o == null || !getClass().equals(o.getClass())) { - return false; - } - - PortProtoMatchImpl match = (PortProtoMatchImpl)o; - return (Objects.equals(sourcePort, match.sourcePort) && - Objects.equals(destinationPort, match.destinationPort)); - } - - /** - * Return the hash code of this object. - * - * @return The hash code. - */ - @Override - public final int hashCode() { - return Objects.hash(sourcePort, destinationPort); - } - - /** - * Return a string representation of this object. - * - * @return A string representation of this object. - */ - @Override - public final String toString() { - StringBuilder builder = new StringBuilder(getClass().getSimpleName()); - builder.append('['); - String sep = ""; - - if (sourcePort != null) { - builder.append("src=").append(sourcePort.toString()); - sep = ","; - } - if (destinationPort != null) { - builder.append(sep).append("dst="). - append(destinationPort.toString()); - } - builder.append(']'); - - return builder.toString(); - } -} diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetDlDstActionImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetDlDstActionImpl.java index c92023b4..88450a87 100644 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetDlDstActionImpl.java +++ b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetDlDstActionImpl.java @@ -11,6 +11,7 @@ package org.opendaylight.vtn.manager.internal.cluster; import org.opendaylight.vtn.manager.VTNException; import org.opendaylight.vtn.manager.flow.action.SetDlDstAction; +import org.opendaylight.vtn.manager.util.EtherAddress; import org.opendaylight.vtn.manager.internal.PacketContext; import org.opendaylight.vtn.manager.internal.packet.cache.EtherPacket; @@ -60,9 +61,9 @@ public final class SetDlDstActionImpl extends DlAddrActionImpl { @Override public boolean apply(PacketContext pctx) { EtherPacket ether = pctx.getEtherPacket(); - byte[] addr = getAddress(); + EtherAddress addr = getAddress(); ether.setDestinationAddress(addr); - pctx.addFilterAction(new SetDlDst(addr)); + pctx.addFilterAction(new SetDlDst(addr.getBytes())); return true; } } diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetDlSrcActionImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetDlSrcActionImpl.java index 5e1c5ba5..07b9e431 100644 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetDlSrcActionImpl.java +++ b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetDlSrcActionImpl.java @@ -11,6 +11,7 @@ package org.opendaylight.vtn.manager.internal.cluster; import org.opendaylight.vtn.manager.VTNException; import org.opendaylight.vtn.manager.flow.action.SetDlSrcAction; +import org.opendaylight.vtn.manager.util.EtherAddress; import org.opendaylight.vtn.manager.internal.PacketContext; import org.opendaylight.vtn.manager.internal.packet.cache.EtherPacket; @@ -60,9 +61,9 @@ public final class SetDlSrcActionImpl extends DlAddrActionImpl { @Override public boolean apply(PacketContext pctx) { EtherPacket ether = pctx.getEtherPacket(); - byte[] addr = getAddress(); + EtherAddress addr = getAddress(); ether.setSourceAddress(addr); - pctx.addFilterAction(new SetDlSrc(addr)); + pctx.addFilterAction(new SetDlSrc(addr.getBytes())); return true; } } diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetIcmpCodeActionImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetIcmpCodeActionImpl.java index 1cd7f41b..1012a4a1 100644 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetIcmpCodeActionImpl.java +++ b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetIcmpCodeActionImpl.java @@ -119,7 +119,7 @@ public final class SetIcmpCodeActionImpl extends FlowActionImpl { L4Packet packet = pctx.getL4Packet(); if (packet instanceof IcmpPacket) { IcmpPacket icmp = (IcmpPacket)packet; - icmp.setCode(code); + icmp.setIcmpCode(code); pctx.addFilterAction(new SetTpDst((int)code)); return true; } diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetIcmpTypeActionImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetIcmpTypeActionImpl.java index cbe2e2b9..02ecaeb4 100644 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetIcmpTypeActionImpl.java +++ b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetIcmpTypeActionImpl.java @@ -119,7 +119,7 @@ public final class SetIcmpTypeActionImpl extends FlowActionImpl { L4Packet packet = pctx.getL4Packet(); if (packet instanceof IcmpPacket) { IcmpPacket icmp = (IcmpPacket)packet; - icmp.setType(type); + icmp.setIcmpType(type); pctx.addFilterAction(new SetTpSrc((int)type)); return true; } diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetInet4DstActionImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetInet4DstActionImpl.java index 4c43ee63..fae879c7 100644 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetInet4DstActionImpl.java +++ b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetInet4DstActionImpl.java @@ -9,10 +9,9 @@ package org.opendaylight.vtn.manager.internal.cluster; -import java.net.InetAddress; - import org.opendaylight.vtn.manager.VTNException; import org.opendaylight.vtn.manager.flow.action.SetInet4DstAction; +import org.opendaylight.vtn.manager.util.IpNetwork; import org.opendaylight.vtn.manager.internal.PacketContext; import org.opendaylight.vtn.manager.internal.packet.cache.Inet4Packet; @@ -63,9 +62,9 @@ public final class SetInet4DstActionImpl extends InetAddressActionImpl { public boolean apply(PacketContext pctx) { Inet4Packet ipv4 = pctx.getInet4Packet(); if (ipv4 != null) { - InetAddress iaddr = getAddress(); - ipv4.setDestinationAddress(iaddr); - pctx.addFilterAction(new SetNwDst(iaddr)); + IpNetwork ipn = getAddress(); + ipv4.setDestinationAddress(ipn); + pctx.addFilterAction(new SetNwDst(ipn.getInetAddress())); return true; } diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetInet4SrcActionImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetInet4SrcActionImpl.java index c6e298fc..5e1f546c 100644 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetInet4SrcActionImpl.java +++ b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/SetInet4SrcActionImpl.java @@ -9,10 +9,9 @@ package org.opendaylight.vtn.manager.internal.cluster; -import java.net.InetAddress; - import org.opendaylight.vtn.manager.VTNException; import org.opendaylight.vtn.manager.flow.action.SetInet4SrcAction; +import org.opendaylight.vtn.manager.util.IpNetwork; import org.opendaylight.vtn.manager.internal.PacketContext; import org.opendaylight.vtn.manager.internal.packet.cache.Inet4Packet; @@ -63,9 +62,9 @@ public final class SetInet4SrcActionImpl extends InetAddressActionImpl { public boolean apply(PacketContext pctx) { Inet4Packet ipv4 = pctx.getInet4Packet(); if (ipv4 != null) { - InetAddress iaddr = getAddress(); - ipv4.setSourceAddress(iaddr); - pctx.addFilterAction(new SetNwSrc(iaddr)); + IpNetwork ipn = getAddress(); + ipv4.setSourceAddress(ipn); + pctx.addFilterAction(new SetNwSrc(ipn.getInetAddress())); return true; } diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/TcpMatchImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/TcpMatchImpl.java deleted file mode 100644 index 4c22f542..00000000 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/TcpMatchImpl.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2014-2015 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.cluster; - -import org.opendaylight.vtn.manager.VTNException; -import org.opendaylight.vtn.manager.flow.cond.L4Match; -import org.opendaylight.vtn.manager.flow.cond.TcpMatch; -import org.opendaylight.vtn.manager.internal.PacketContext; -import org.opendaylight.vtn.manager.internal.packet.cache.CachedPacket; -import org.opendaylight.vtn.manager.internal.packet.cache.TcpPacket; - -import org.opendaylight.controller.sal.match.MatchType; -import org.opendaylight.controller.sal.utils.IPProtocols; - -/** - * {@code TcpMatchImpl} describes the condition to match TCP header fields - * in IP packet. - * - *- * Although this class is public to other packages, this class does not - * provide any API. Applications other than VTN Manager must not use this - * class. - *
- */ -public final class TcpMatchImpl extends PortProtoMatchImpl { - /** - * Version number for serialization. - */ - private static final long serialVersionUID = 4196379454588474512L; - - /** - * Construct a new instance. - * - * @param match A {@link TcpMatch} instance. - * @throws NullPointerException - * {@code match} is {@code null}. - * @throws VTNException - * {@code match} contains invalid value. - */ - public TcpMatchImpl(TcpMatch match) throws VTNException { - super(match); - } - - // L4MatchImpl - - /** - * Return an IP protocol number assigned to this protocol. - * - * @return An IP protocol number. - */ - @Override - public short getInetProtocol() { - return IPProtocols.TCP.shortValue(); - } - - - /** - * Return a {@link L4Match} instance which represents this condition. - * - * @return A {@link L4Match} instance. - */ - @Override - public L4Match getMatch() { - L4PortMatch src = getSourcePort(); - L4PortMatch dst = getDestinationPort(); - return new TcpMatch(getPortMatch(src), getPortMatch(dst)); - } - - // PacketMatch - - /** - * Determine whether the specified packet matches the condition defined - * by this instance. - * - * @param pctx The context of the packet to be tested. - * @return {@code true} if the specified packet matches the condition. - * Otherwise {@code false}. - */ - @Override - public boolean match(PacketContext pctx) { - CachedPacket packet = pctx.getL4Packet(); - if (!(packet instanceof TcpPacket)) { - return false; - } - - TcpPacket tcp = (TcpPacket)packet; - L4PortMatch src = getSourcePort(); - L4PortMatch dst = getDestinationPort(); - - if (src != null) { - pctx.addMatchField(MatchType.TP_SRC); - int port = tcp.getSourcePort(); - if (!src.match(port)) { - return false; - } - } - - if (dst != null) { - pctx.addMatchField(MatchType.TP_DST); - int port = tcp.getDestinationPort(); - if (!dst.match(port)) { - return false; - } - } - - return true; - } -} diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/UdpMatchImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/UdpMatchImpl.java deleted file mode 100644 index cc9c5665..00000000 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/UdpMatchImpl.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2014-2015 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.cluster; - -import org.opendaylight.vtn.manager.VTNException; -import org.opendaylight.vtn.manager.flow.cond.L4Match; -import org.opendaylight.vtn.manager.flow.cond.UdpMatch; -import org.opendaylight.vtn.manager.internal.PacketContext; -import org.opendaylight.vtn.manager.internal.packet.cache.CachedPacket; -import org.opendaylight.vtn.manager.internal.packet.cache.UdpPacket; - -import org.opendaylight.controller.sal.match.MatchType; -import org.opendaylight.controller.sal.utils.IPProtocols; - -/** - * {@code UdpMatchImpl} describes the condition to match UDP header fields - * in IP packet. - * - *- * Although this class is public to other packages, this class does not - * provide any API. Applications other than VTN Manager must not use this - * class. - *
- */ -public final class UdpMatchImpl extends PortProtoMatchImpl { - /** - * Version number for serialization. - */ - private static final long serialVersionUID = 6510518830317668833L; - - /** - * Construct a new instance. - * - * @param match A {@link UdpMatch} instance. - * @throws NullPointerException - * {@code match} is {@code null}. - * @throws VTNException - * {@code match} contains invalid value. - */ - public UdpMatchImpl(UdpMatch match) throws VTNException { - super(match); - } - - // L4MatchImpl - - /** - * Return an IP protocol number assigned to this protocol. - * - * @return An IP protocol number. - */ - @Override - public short getInetProtocol() { - return IPProtocols.UDP.shortValue(); - } - - /** - * Return a {@link L4Match} instance which represents this condition. - * - * @return A {@link L4Match} instance. - */ - @Override - public L4Match getMatch() { - L4PortMatch src = getSourcePort(); - L4PortMatch dst = getDestinationPort(); - return new UdpMatch(getPortMatch(src), getPortMatch(dst)); - } - - // PacketMatch - - /** - * Determine whether the specified packet matches the condition defined - * by this instance. - * - * @param pctx The context of the packet to be tested. - * @return {@code true} if the specified packet matches the condition. - * Otherwise {@code false}. - */ - @Override - public boolean match(PacketContext pctx) { - CachedPacket packet = pctx.getL4Packet(); - if (!(packet instanceof UdpPacket)) { - return false; - } - - UdpPacket udp = (UdpPacket)packet; - L4PortMatch src = getSourcePort(); - L4PortMatch dst = getDestinationPort(); - - if (src != null) { - pctx.addMatchField(MatchType.TP_SRC); - int port = udp.getSourcePort(); - if (!src.match(port)) { - return false; - } - } - if (dst != null) { - pctx.addMatchField(MatchType.TP_DST); - int port = udp.getDestinationPort(); - if (!dst.match(port)) { - return false; - } - } - - return true; - } -} diff --git a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/VBridgeImpl.java b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/VBridgeImpl.java index 1286159e..7c897544 100644 --- a/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/VBridgeImpl.java +++ b/manager/implementation/src/main/java/org/opendaylight/vtn/manager/internal/cluster/VBridgeImpl.java @@ -810,14 +810,14 @@ public final class VBridgeImpl extends PortBridge+ * Note that this class is not synchronized. + *
+ */ +final class FlowCondChange { + /** + * A map that keeps updated flow conditions. + */ + private final Map+ * This task returns current {@link VtnFlowConditions} instance. + *
+ */ + private class FlowCondLoadTask extends AbstractTxTask+ * This task returns current {@link VtnFlowConditions} instance. + *
+ */ + private static class FlowCondSaveTask + extends AbstractTxTask+ * A task corresponding to this task is used as a sub task for + * {@link RemoveFlowMatchTask}. + *
+ * + * @see RemoveFlowMatchTask + */ +public final class RemoveMatchTask extends DeleteDataTask+ * This method always return true in order to create the root container + * for the flow condition if missing. + *
+ * + * @return {@code true}. + */ + @Override + protected boolean fixMissingParents() { + return true; + } + + /** + * {@inheritDoc} + */ + @Override + protected void onStarted(TxContext ctx, VtnFlowCondition current) + throws VTNException { + if (current == null && present) { + // The target flow condition is not present. + throw FlowCondUtils.getNotFoundException(name); + } + } + + // TxTask + + /** + * {@inheritDoc} + */ + @Override + public void onSuccess(VTNManagerProvider provider, VtnUpdateType result) { + if (result != null) { + // REVISIT: Select flow entries affected by the change. + addBackgroundTasks(provider.removeFlows(null)); + } + } + + // RpcOutputGenerator + + /** + * {@inheritDoc} + */ + @Override + public Class+ * A task corresponding to this task is used as a sub task for + * {@link SetFlowMatchTask}. + *
+ * + * @see SetFlowMatchTask + */ +public final class SetMatchTask extends PutDataTask+ * Each subsystem manager is represented by {@link VTNSubSystem} interface, + * and it is indexed by its class. + *
+ */ +public final class SubSystemRegistry { + /** + * Logger instance. + */ + private static final Logger LOG = + LoggerFactory.getLogger(SubSystemRegistry.class); + + /** + * Pairs of subsystem provider classes and instances. + */ + private final AtomicReference