Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into HEAD
Browse files Browse the repository at this point in the history
Change-Id: I98c5244ab0c96dcb174d0263d39f5cfbf478907a
  • Loading branch information
bocon13 committed Sep 3, 2015
2 parents a259e3f + 6085236 commit 108d37a
Show file tree
Hide file tree
Showing 24 changed files with 744 additions and 733 deletions.
3 changes: 3 additions & 0 deletions java_gen/java_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,9 @@ def gen_fixed_length_string_jtype(length):
'of_oxm_bsn_inner_eth_src' : { 'value' : mac_addr },
'of_oxm_bsn_inner_eth_src_masked' : { 'value' : mac_addr, 'value_mask' : mac_addr },

'of_oxm_bsn_inner_vlan_vid' : { 'value' : vlan_vid_match },
'of_oxm_bsn_inner_vlan_vid_masked' : { 'value' : vlan_vid_match, 'value_mask' : vlan_vid_match },

'of_table_stats_entry': { 'wildcards': table_stats_wildcards },
'of_match_v1': { 'vlan_vid' : vlan_vid_match, 'vlan_pcp': vlan_pcp,
'eth_type': eth_type, 'ip_dscp': ip_dscp, 'ip_proto': ip_proto,
Expand Down
16 changes: 8 additions & 8 deletions java_gen/pre-written/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>org.onosproject</groupId>
<artifactId>openflowj</artifactId>
<version>0.4.1.onos-SNAPSHOT</version>
<version>0.9.0.onos-SNAPSHOT</version>
<packaging>jar</packaging>

<name>OpenFlowJ-Loxi</name>
Expand Down Expand Up @@ -44,12 +44,12 @@
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>2.0.2</version>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -61,27 +61,27 @@
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
<version>3.9.0.Final</version>
<version>3.10.4.Final</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>17.0</version>
<version>18.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.0.13</version>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
<version>1.1.3</version>
</dependency>
</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@
import org.projectfloodlight.openflow.types.OFVlanVidMatch;
import org.projectfloodlight.openflow.types.TransportPort;
import org.projectfloodlight.openflow.types.U16;
import org.projectfloodlight.openflow.types.U64;
import org.projectfloodlight.openflow.types.U32;
import org.projectfloodlight.openflow.types.U64;
import org.projectfloodlight.openflow.types.U8;
import org.projectfloodlight.openflow.types.UDF;
import org.projectfloodlight.openflow.types.VRF;
import org.projectfloodlight.openflow.types.VlanPcp;
import org.projectfloodlight.openflow.types.CircuitSignalID;
import org.projectfloodlight.openflow.types.OduSignalID;

@SuppressWarnings("unchecked")
public class MatchField<F extends OFValueType<F>> {
private final String name;
public final MatchFields id;
Expand Down Expand Up @@ -290,6 +289,9 @@ private MatchField(final String name, final MatchFields id, Prerequisite<?>... p
public final static MatchField<MacAddress> BSN_INNER_ETH_SRC =
new MatchField<MacAddress>("bsn_inner_eth_src", MatchFields.BSN_INNER_ETH_SRC);

public final static MatchField<OFVlanVidMatch> BSN_INNER_VLAN_VID =
new MatchField<OFVlanVidMatch>("bsn_inner_vlan_vid", MatchFields.BSN_INNER_VLAN_VID);

public final static MatchField<OduSignalID> EXP_ODU_SIG_ID =
new MatchField<OduSignalID>("exp_odu_sig_id", MatchFields.EXP_ODU_SIG_ID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public enum MatchFields {
BSN_VXLAN_NETWORK_ID,
BSN_INNER_ETH_DST,
BSN_INNER_ETH_SRC,
BSN_INNER_VLAN_VID,
OCH_SIGTYPE,
OCH_SIGTYPE_BASIC,
OCH_SIGID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.projectfloodlight.openflow.types;

import javax.annotation.Nonnull;

import org.projectfloodlight.openflow.annotations.Immutable;
import org.projectfloodlight.openflow.util.HexString;

Expand Down Expand Up @@ -36,6 +38,15 @@ public static DatapathId of(byte[] bytes) {
return new DatapathId(Longs.fromByteArray(bytes));
}

/**
* Creates a {@link DatapathId} from a {@link MacAddress}.
* @param mac the {@link MacAddress} to create the {@link DatapathId} from
* @return a {@link DatapathId} derived from the supplied {@link MacAddress}
*/
public static DatapathId of(@Nonnull MacAddress mac) {
return DatapathId.of(mac.getLong());
}

public long getLong() {
return rawValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.projectfloodlight.openflow.exceptions.OFParseError;
import org.projectfloodlight.openflow.util.HexString;

import com.google.common.base.Preconditions;
import com.google.common.hash.PrimitiveSink;
import com.google.common.primitives.Longs;

Expand All @@ -33,6 +34,10 @@ public class MacAddress implements OFValueType<MacAddress> {
private static final long LLDP_MAC_ADDRESS_MASK = 0xfffffffffff0L;
private static final long LLDP_MAC_ADDRESS_VALUE = 0x0180c2000000L;

private static final String FORMAT_ERROR = "Mac address is not well-formed. " +
"It must consist of 6 hex digit pairs separated by colons: ";
private static final int MAC_STRING_LENGTH = 6 * 2 + 5;

private MacAddress(final long rawValue) {
this.rawValue = rawValue;
}
Expand Down Expand Up @@ -69,14 +74,14 @@ public static MacAddress of(@Nonnull final String macString) throws IllegalArgum
if (macString == null) {
throw new NullPointerException("macString must not be null");
}

int index = 0;
int shift = 40;
final String FORMAT_ERROR = "Mac address is not well-formed. " +
"It must consist of 6 hex digit pairs separated by colons: ";

long raw = 0;
if (macString.length() != 6 * 2 + 5)

if (macString.length() != MAC_STRING_LENGTH) {
throw new IllegalArgumentException(FORMAT_ERROR + macString);
}

while (shift >= 0) {
int digit1 = Character.digit(macString.charAt(index++), 16);
Expand All @@ -94,6 +99,25 @@ public static MacAddress of(@Nonnull final String macString) throws IllegalArgum
return MacAddress.of(raw);
}

/**
* Creates a {@link MacAddress} from a {@link DatapathId}. This factory
* method assumes that the first two bytes of the {@link DatapathId} are 0 bytes.
* @param dpid the {@link DatapathId} to create the {@link MacAddress} from
* @return a {@link MacAddress} derived from the supplied {@link DatapathId}
*/
public static MacAddress of(@Nonnull DatapathId dpid) {
Preconditions.checkNotNull(dpid, "dpid must not be null");

long raw = dpid.getLong();

// Mask out valid bytes
if( (raw & ~BROADCAST_VAL) != 0L) {
throw new IllegalArgumentException("First two bytes of supplied "
+ "Datapathid must be 0");
}
return of(raw);
}

private volatile byte[] bytesCache = null;

public byte[] getBytes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class OFBooleanValue implements Writeable, OFValueType<OFBooleanValue> {
public final static OFBooleanValue NO_MASK = TRUE;
public final static OFBooleanValue FULL_MASK = FALSE;

public final static Reader READER_INSTANCE = new Reader();

private final boolean value;

private OFBooleanValue(boolean value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
package org.projectfloodlight.openflow.types;

import java.util.ArrayList;

import javax.annotation.concurrent.Immutable;


/** User-facing object representing a bitmap of ports that can be matched on.
* This is implemented by the custom BSN OXM type of_oxm_bsn_in_ports_512.
*
* You can call set() on the builder for all the Ports you want to match on
* and unset to exclude the port.
*
* <b>Implementation note:</b> to comply with the matching semantics of OXM (which is a logical "AND" not "OR")
* the underlying match uses a data format which is very unintuitive. The value is always
* 0, and the mask has the bits set for the ports that should <b>NOT</b> be included in the
* range.
*
* For the curious: We transformed the bitmap (a logical OR) problem into a logical
* AND NOT problem.
*
* We logically mean: Inport is 1 OR 3
* We technically say: Inport IS NOT 2 AND IS NOT 4 AND IS NOT 5 AND IS NOT ....
* The second term cannot be represented in OXM, the second can.
*
* That said, all that craziness is hidden from the user of this object.
*
* <h2>Usage</h2>
* OFPortBitmap is meant to be used with MatchField <tt>BSN_IN_PORTS_512</tt> in place
* of the raw type Masked&lt;OFBitMask512&gt;.
*
* <h3>Example:</h3>:
* <pre>
* OFPortBitMap portBitMap;
* Match.Builder matchBuilder;
* // initialize
* matchBuilder.setMasked(MatchField.BSN_IN_PORTS_512, portBitmap);
* </pre>
*
* @author Andreas Wundsam {@literal <}[email protected]{@literal >}
*/
@Immutable
public class OFPortBitMap512 extends Masked<OFBitMask512> {

private OFPortBitMap512(OFBitMask512 mask) {
super(OFBitMask512.NONE, mask);
}

/** @return whether or not the given port is logically included in the
* match, i.e., whether a packet from in-port <em>port</em> be matched by
* this OXM.
*/
public boolean isOn(OFPort port) {
// see the implementation note above about the logical inversion of the mask
return !(this.mask.isOn(port.getPortNumber()));
}

public static OFPortBitMap512 ofPorts(OFPort... ports) {
Builder builder = new Builder();
for (OFPort port: ports) {
builder.set(port);
}
return builder.build();
}

/** @return an OFPortBitmap based on the 'mask' part of an OFBitMask512, as, e.g., returned
* by the switch.
**/
public static OFPortBitMap512 of(OFBitMask512 mask) {
return new OFPortBitMap512(mask);
}

/** @return iterating over all ports that are logically included in the
* match, i.e., whether a packet from in-port <em>port</em> be matched by
* this OXM.
*/
public Iterable<OFPort> getOnPorts() {
ArrayList<OFPort> ports = new ArrayList<>();
for(int i=0; i < 511; i++) {
if(!(this.mask.isOn(i))) {
ports.add(OFPort.of(i));
}
}
return ports;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof OFPortBitMap512))
return false;
OFPortBitMap512 other = (OFPortBitMap512)obj;
return (other.value.equals(this.value) && other.mask.equals(this.mask));
}

@Override
public int hashCode() {
return 619 * mask.hashCode() + 257 * value.hashCode();
}

public static class Builder {
private long raw1 = -1, raw2 = -1, raw3 = -1, raw4 = -1,
raw5 = -1, raw6 = -1, raw7 = -1, raw8 = -1;

public Builder() {

}

/** @return whether or not the given port is logically included in the
* match, i.e., whether a packet from in-port <em>port</em> be matched by
* this OXM.
*/
public boolean isOn(OFPort port) {
// see the implementation note above about the logical inversion of the mask
return !(OFBitMask512.isBitOn(raw1, raw2, raw3, raw4,
raw5, raw6, raw7, raw8, port.getPortNumber()));
}

/** remove this port from the match, i.e., packets from this in-port
* will NOT be matched.
*/
public Builder unset(OFPort port) {
// see the implementation note above about the logical inversion of the mask
int bit = port.getPortNumber();
if (bit < 0 || bit > 511)
throw new IndexOutOfBoundsException("Port number is out of bounds");
else if (bit == 511)
// the highest order bit in the bitmask is reserved. The switch will
// set that bit for all ports >= 511. The reason is that we don't want
// the OFPortMap to match all ports out of its range (i.e., a packet
// coming in on port 581 would match *any* OFPortMap).
throw new IndexOutOfBoundsException("The highest order bit in the bitmask is reserved.");
else if (bit < 64) {
raw8 |= ((long)1 << bit);
} else if (bit < 128) {
raw7 |= ((long)1 << bit - 64);
} else if (bit < 192) {
raw6 |= ((long)1 << bit - 128);
} else if (bit < 256) {
raw5 |= ((long)1 << bit - 192);
} else if (bit < 320) {
raw4 |= ((long)1 << bit - 256);
} else if (bit < 384) {
raw3 |= ((long)1 << bit - 320);
} else if (bit < 448) {
raw2 |= ((long)1 << bit - 384);
} else {
raw1 |= ((long)1 << (bit - 448));
}
return this;
}

/** add this port from the match, i.e., packets from this in-port
* will NOT be matched.
*/
public Builder set(OFPort port) {
// see the implementation note above about the logical inversion of the mask
int bit = port.getPortNumber();
if (bit < 0 || bit > 511)
throw new IndexOutOfBoundsException("Port number is out of bounds");
else if (bit == 511)
// the highest order bit in the bitmask is reserved. The switch will
// set that bit for all ports >= 511. The reason is that we don't want
// the OFPortMap to match all ports out of its range (i.e., a packet
// coming in on port 581 would match *any* OFPortMap).
throw new IndexOutOfBoundsException("The highest order bit in the bitmask is reserved.");
else if (bit < 64) {
raw8 &= ~((long)1 << bit);
} else if (bit < 128) {
raw7 &= ~((long)1 << bit - 64);
} else if (bit < 192) {
raw6 &= ~((long)1 << bit - 128);
} else if (bit < 256) {
raw5 &= ~((long)1 << bit - 192);
} else if (bit < 320) {
raw4 &= ~((long)1 << bit - 256);
} else if (bit < 384) {
raw3 &= ~((long)1 << bit - 320);
} else if (bit < 448) {
raw2 &= ~((long)1 << bit - 384);
} else {
raw1 &= ~((long)1 << (bit - 448));
}
return this;
}

public OFPortBitMap512 build() {
return new OFPortBitMap512(OFBitMask512.of(raw1, raw2, raw3, raw4,
raw5, raw6, raw7, raw8));
}
}

}
Loading

0 comments on commit 108d37a

Please sign in to comment.