X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fcontainermanager%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcontainermanager%2FContainerFlowConfig.java;h=9740a9259833c0ef9d60ad821eaea1e0ee723aef;hb=90e562e3dcc64e46a657ef4ab3047b2b709339c7;hp=488f8928de478ec8faab7122d93fd8f21cda0a62;hpb=52757c15dc010e68ef15899daf50f78291966bee;p=controller.git diff --git a/opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/ContainerFlowConfig.java b/opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/ContainerFlowConfig.java index 488f8928de..9740a92598 100644 --- a/opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/ContainerFlowConfig.java +++ b/opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/ContainerFlowConfig.java @@ -55,6 +55,10 @@ public class ContainerFlowConfig implements Serializable { @XmlElement private String name; + /** The vlan. */ + @XmlElement + private String dlVlan; + /** The network Source. */ @XmlElement private String nwSrc; @@ -101,6 +105,7 @@ public class ContainerFlowConfig implements Serializable { public ContainerFlowConfig(String name, String srcIP, String dstIP, String proto, String srcPort, String dstPort) { this.name = name; + this.dlVlan = null; this.nwSrc = srcIP; this.nwDst = dstIP; this.protocol = proto; @@ -109,9 +114,21 @@ public class ContainerFlowConfig implements Serializable { //this.unidirectional = false; } + public ContainerFlowConfig(String name, String dlVlan, String srcIP, String dstIP, String proto, String srcPort, + String dstPort) { + this.name = name; + this.dlVlan = dlVlan; + this.nwSrc = srcIP; + this.nwDst = dstIP; + this.protocol = proto; + this.tpSrc = srcPort; + this.tpDst = dstPort; + } + public ContainerFlowConfig(ContainerFlowConfig containerFlowConfig) { this.name = containerFlowConfig.name; + this.dlVlan = containerFlowConfig.dlVlan; this.nwSrc = containerFlowConfig.nwSrc; this.nwDst = containerFlowConfig.nwDst; this.protocol = containerFlowConfig.protocol; @@ -130,6 +147,15 @@ public class ContainerFlowConfig implements Serializable { return name; } + /** + * Returns the vlan id. + * + * @return the Vlan Id + */ + public String getVlan() { + return (dlVlan == null || dlVlan.isEmpty()) ? null : dlVlan; + } + /** * Returns the Source IP Address. * @@ -192,6 +218,7 @@ public class ContainerFlowConfig implements Serializable { result = prime * result + ((protocol == null) ? 0 : protocol.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((dlVlan == null) ? 0 : dlVlan.hashCode()); result = prime * result + ((nwDst == null) ? 0 : nwDst.hashCode()); result = prime * result + ((tpDst == null) ? 0 : tpDst.hashCode()); result = prime * result + ((nwSrc == null) ? 0 : nwSrc.hashCode()); @@ -221,7 +248,7 @@ public class ContainerFlowConfig implements Serializable { return false; } ContainerFlowConfig other = (ContainerFlowConfig) obj; - if (matchName(other) && matchSrcIP(other) + if (matchName(other) && matchDlVlan(other) && matchSrcIP(other) && matchDstIP(other) && matchProtocol(other) && matchSrcPort(other) && matchDstPort(other)) { return true; @@ -280,6 +307,21 @@ public class ContainerFlowConfig implements Serializable { return name.equals(flowSpec.name); } + /** + * Match Source IP Address. + * + * @param flowSpec Flow Specification + * @return true, if successful + */ + private boolean matchDlVlan(ContainerFlowConfig flowSpec) { + if (dlVlan == flowSpec.dlVlan) { + return true; + } + if (dlVlan == null || flowSpec.dlVlan == null) { + return false; + } + return dlVlan.equals(flowSpec.dlVlan); + } /** * Match Source IP Address. @@ -361,6 +403,21 @@ public class ContainerFlowConfig implements Serializable { return this.tpDst.equals(flowSpec.tpDst); } + /** + * Returns the vlan id number + * + * @return the vlan id number + */ + public Short getVlanId() { + Short vlan = 0; + try { + vlan = Short.parseShort(dlVlan); + } catch (NumberFormatException e) { + + } + return vlan; + } + /** * Returns the Source IP Address mask length. * @@ -479,12 +536,12 @@ public class ContainerFlowConfig implements Serializable { } /** - * Returns the protocol + * Get the IP protocol value * * @return the protocol */ public Short getProtoNum() { - return protocol == null ? IPProtocols.ANY.shortValue() : IPProtocols.getProtocolNumberShort(protocol); + return protocol == null ? null : IPProtocols.getProtocolNumberShort(protocol); } /** @@ -522,7 +579,11 @@ public class ContainerFlowConfig implements Serializable { if (!hasValidName()) { return new Status(StatusCode.BADREQUEST, "Invalid name"); } - Status status = validateIPs(); + Status status = validateVlan(); + if (!status.isSuccess()) { + return status; + } + status = validateIPs(); if (!status.isSuccess()) { return status; } @@ -547,6 +608,26 @@ public class ContainerFlowConfig implements Serializable { return (name != null && !name.isEmpty() && name.matches(regexName)); } + /** + * Validates the vlan number + * + * @return the result of the check as Status object + */ + private Status validateVlan() { + if (dlVlan != null) { + short vlanId = 0; + try { + vlanId = Short.parseShort(dlVlan); + } catch (NumberFormatException e) { + return new Status(StatusCode.BADREQUEST, "Invalid vlan id"); + } + if (vlanId < 0 || vlanId > 0xfff) { + return new Status(StatusCode.BADREQUEST, "Invalid vlan id"); + } + } + return new Status(StatusCode.SUCCESS); + } + /** * Validates the network addresses, checks syntax and semantic * @@ -578,16 +659,15 @@ public class ContainerFlowConfig implements Serializable { /** * Validate the protocol field. Either it can be a enum defined in IPProtocols.java - * or a value between 1 and 255 + * or a valid IP proto value between 0 and 255, see: + * http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml + * for more details. * * @return true if a valid protocol value */ private boolean hasValidProtocol() { - if (protocol != null && !protocol.isEmpty()) { - short proto = this.getProtoNum(); - return (((proto != 0) && (proto > 0) && (proto < 256)) || protocol.equalsIgnoreCase("any")); - } - return true; + IPProtocols p = IPProtocols.fromString(protocol); + return p != null; } /** @@ -638,6 +718,9 @@ public class ContainerFlowConfig implements Serializable { List matches = new ArrayList(); Match match = new Match(); + if (this.dlVlan != null && !this.dlVlan.isEmpty()) { + match.setField(MatchType.DL_VLAN, this.getVlanId()); + } if (this.nwSrc != null && !this.nwSrc.trim().isEmpty()) { String parts[] = this.nwSrc.split("/"); InetAddress ip = NetUtils.parseInetAddress(parts[0]); @@ -664,9 +747,8 @@ public class ContainerFlowConfig implements Serializable { mask = NetUtils.getInetNetworkMask(maskLen, ip instanceof Inet6Address); match.setField(MatchType.NW_DST, ip, mask); } - if (this.protocol != null && !this.protocol.trim().isEmpty() && !this.protocol.equalsIgnoreCase("any")) { - match.setField(MatchType.NW_PROTO, IPProtocols - .getProtocolNumberByte(this.protocol)); + if (IPProtocols.fromString(this.protocol) != IPProtocols.ANY) { + match.setField(MatchType.NW_PROTO, IPProtocols.getProtocolNumberByte(this.protocol)); } if (this.tpSrc != null && !this.tpSrc.trim().isEmpty()) { match.setField(MatchType.TP_SRC, Integer.valueOf(tpSrc).shortValue()); @@ -692,7 +774,7 @@ public class ContainerFlowConfig implements Serializable { */ @Override public String toString() { - return "Container Flow={name:" + name + " nwSrc:" + nwSrc + " nwDst:" + nwDst + " " + "protocol:" + protocol + return "Container Flow={name:" + name + " dlVlan:" + dlVlan + " nwSrc:" + nwSrc + " nwDst:" + nwDst + " " + "protocol:" + protocol + " tpSrc:" + tpSrc + " tpDst:" + tpDst + "}"; } }