X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=third-party%2Fopenflowj_netty%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenflow%2Fprotocol%2FWildcards.java;fp=third-party%2Fopenflowj_netty%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenflow%2Fprotocol%2FWildcards.java;h=fbda8586ab25c106cf7991cab6c4f328bfd9712b;hb=85073423c6069e4b58fffde7cf19c806b2b52dd5;hp=0000000000000000000000000000000000000000;hpb=c5630f2945eb5370f9829514ef72de41d41eb2be;p=controller.git diff --git a/third-party/openflowj_netty/src/main/java/org/openflow/protocol/Wildcards.java b/third-party/openflowj_netty/src/main/java/org/openflow/protocol/Wildcards.java new file mode 100644 index 0000000000..fbda8586ab --- /dev/null +++ b/third-party/openflowj_netty/src/main/java/org/openflow/protocol/Wildcards.java @@ -0,0 +1,527 @@ +/** + * Copyright 2013, Big Switch Networks, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + **/ + +package org.openflow.protocol; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.Iterator; +import java.util.List; + + +/** + * a more user friendly representation of the wildcards bits in an OpenFlow + * match. The Wildcards object is + *
+ * You can construct a Wildcard object from either its integer representation + *
+ *
+ * Wildcard.of(0x3820e0);
+ *
+ * + * Or start with either an empty or full wildcard, and select/unselect foo. + *
+ *
+ * Wildcard w = Wildcards.NONE
+ * .set(Flag.DL_SRC, Flag. DL_DST, Flag.DL_VLAN_PCP)
+ * .setNwDstMask(8)
+ * .setNwSrcMask(8);
+ *
+ * + * Remember: Wildcards objects are immutable. set... operations have + * NO EFFECT on the current wildcard object. You HAVE to use the returned + * changed object. + *
+ * + * @author Andreas Wundsam+ * NOTE: NOT a mutator function. 'this' wildcard object stays + * unmodified. + */ + public Wildcards wildcard(Wildcards.Flag flag) { + int flags = flag.wildcard(this.flags); + if (flags == this.flags) + return this; + else + return new Wildcards(flags); + } + + /** + * return a Wildcards object that has the given flags set + *
+ * NOTE: NOT a mutator function. 'this' wildcard object stays + * unmodified. + */ + public Wildcards wildcard(Wildcards.Flag flag, Wildcards.Flag flag2) { + int flags = flag.wildcard(flag2.wildcard(this.flags)); + if (flags == this.flags) + return this; + else + return new Wildcards(flags); + } + + /** + * return a Wildcards object that has the given flags wildcarded + *
+ * NOTE: NOT a mutator function. 'this' wildcard object stays + * unmodified. + */ + public Wildcards wildcard(Wildcards.Flag... setFlags) { + int flags = this.flags; + for (Wildcards.Flag flag : setFlags) + flags = flag.wildcard(flags); + if (flags == this.flags) + return this; + else + return new Wildcards(flags); + } + + /** + * return a Wildcards object that matches on exactly the given flag + *
+ * NOTE: NOT a mutator function. 'this' wildcard object stays + * unmodified. + */ + public Wildcards matchOn(Wildcards.Flag flag) { + int flags = flag.matchOn(this.flags); + if (flags == this.flags) + return this; + else + return new Wildcards(flags); + } + + /** + * return a Wildcards object that matches on exactly the given flags + *
+ * NOTE: NOT a mutator function. 'this' wildcard object stays + * unmodified. + */ + public Wildcards matchOn(Wildcards.Flag flag, Wildcards.Flag flag2) { + int flags = flag.matchOn(flag2.matchOn(this.flags)); + if (flags == this.flags) + return this; + else + return new Wildcards(flags); + } + + /** + * return a Wildcards object that matches on exactly the given flags + *
+ * NOTE: NOT a mutator function. 'this' wildcard object stays
+ * unmodified.
+ */
+ public Wildcards matchOn(Wildcards.Flag... setFlags) {
+ int flags = this.flags;
+ for (Wildcards.Flag flag : setFlags)
+ flags = flag.matchOn(flags);
+ if (flags == this.flags)
+ return this;
+ else
+ return new Wildcards(flags);
+ }
+
+ /**
+ * return the nw src mask in normal CIDR style, e.g., 8 means x.x.x.x/8
+ * means 8 bits wildcarded
+ */
+ public int getNwSrcMask() {
+ return Math.max(0, 32 - Flag.NW_SRC.getInt(flags));
+ }
+
+ /**
+ * return the nw dst mask in normal CIDR style, e.g., 8 means x.x.x.x/8
+ * means 8 bits wildcarded
+ */
+ public int getNwDstMask() {
+ return Math.max(0, 32 - Flag.NW_DST.getInt(flags));
+ }
+
+ /**
+ * return a Wildcard object that has the given nwSrcCidrMask set.
+ * NOTE: NOT a mutator function. 'this' wildcard object stays
+ * unmodified.
+ *
+ * @param srcCidrMask
+ * source mask to set in normal CIDR notation, i.e., 8
+ * means x.x.x.x/8
+ * @return a modified object
+ */
+ public Wildcards withNwSrcMask(int srcCidrMask) {
+ int flags = Flag.NW_SRC.setInt(this.flags, Math.max(0, 32 - srcCidrMask));
+ if (flags == this.flags)
+ return this;
+ else
+ return new Wildcards(flags);
+ }
+
+ /**
+ * return a Wildcard object that has the given nwDstCidrMask set.
+ * NOTE: NOT a mutator function. 'this' wildcard object stays
+ * unmodified.
+ *
+ * @param dstCidrMask
+ * dest mask to set in normal CIDR notation, i.e., 8 means
+ * x.x.x.x/8
+ * @return a modified object
+ */
+ public Wildcards withNwDstMask(int dstCidrMask) {
+ int flags = Flag.NW_DST.setInt(this.flags, Math.max(0, 32 - dstCidrMask));
+ if (flags == this.flags)
+ return this;
+ else
+ return new Wildcards(flags);
+ }
+
+ /**
+ * return a Wildcard object that is inverted to this wildcard object.
+ * NOTE: NOT a mutator function. 'this' wildcard object stays
+ * unmodified.
+ * @return a modified object
+ */
+ public Wildcards inverted() {
+ return Wildcards.of(flags ^ OFMatch.OFPFW_ALL_SANITIZED);
+ }
+
+ public boolean isWildcarded(Flag flag) {
+ return flag.isFullyOn(flags);
+ }
+
+ /**
+ * return all wildcard flags that are fully wildcarded as an EnumSet. Do not
+ * modify. Note: some flags (like NW_SRC and NW_DST) that are partially
+ * wildcarded are not returned in this set.
+ *
+ * @return the EnumSet of wildcards
+ */
+ public EnumSet