Skip to content

Commit

Permalink
add more supporting types
Browse files Browse the repository at this point in the history
  • Loading branch information
xinwu committed Sep 18, 2013
1 parent f17c9af commit c1b011d
Show file tree
Hide file tree
Showing 7 changed files with 383 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ tags
.*.swo
*.cache
openflowj-loxi
/bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.projectfloodlight.openflow.types;

import org.projectfloodlight.openflow.annotations.Immutable;

@Immutable
public class ClassId implements OFValueType<ClassId> {
static final int LENGTH = 4;
private final int rawValue;

public static final ClassId NO_ClassId = ClassId.of(0xFFFFFFFF);
public static final ClassId FULL_MASK = ClassId.of(0x00000000);

private ClassId(final int rawValue) {
this.rawValue = rawValue;
}

public static ClassId of(final int raw) {
return new ClassId(raw);
}

public int getInt() {
return rawValue;
}

@Override
public int getLength() {
return LENGTH;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + rawValue;
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ClassId other = (ClassId) obj;
if (rawValue != other.rawValue)
return false;
return true;
}

@Override
public String toString() {
return Integer.toString(rawValue);
}

@Override
public ClassId applyMask(ClassId mask) {
return ClassId.of(this.rawValue & mask.rawValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.projectfloodlight.openflow.types;

import org.projectfloodlight.openflow.annotations.Immutable;

@Immutable
public class L2MulticastId implements OFValueType<L2MulticastId> {
static final int LENGTH = 4;
private final int rawValue;

public static final L2MulticastId NO_ClassId = L2MulticastId.of(0xFFFFFFFF);
public static final L2MulticastId FULL_MASK = L2MulticastId.of(0x00000000);

private L2MulticastId(final int rawValue) {
this.rawValue = rawValue;
}

public static L2MulticastId of(final int raw) {
return new L2MulticastId(raw);
}

public int getInt() {
return rawValue;
}

@Override
public int getLength() {
return LENGTH;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + rawValue;
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
L2MulticastId other = (L2MulticastId) obj;
if (rawValue != other.rawValue)
return false;
return true;
}

@Override
public String toString() {
return Integer.toString(rawValue);
}

@Override
public L2MulticastId applyMask(L2MulticastId mask) {
return L2MulticastId.of(this.rawValue & mask.rawValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.projectfloodlight.openflow.types;

import org.jboss.netty.buffer.ChannelBuffer;
import org.projectfloodlight.openflow.annotations.Immutable;

@Immutable
public class LagId implements OFValueType<LagId> {
static final int LENGTH = 4;
private final int rawValue;

public static final LagId NO_ClassId = LagId.of(0xFFFFFFFF);
public static final LagId FULL_MASK = LagId.of(0x00000000);

private LagId(final int rawValue) {
this.rawValue = rawValue;
}

public static LagId of(final int raw) {
return new LagId(raw);
}

public int getInt() {
return rawValue;
}

@Override
public int getLength() {
return LENGTH;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + rawValue;
return result;
}

@Override
public String toString() {
return Integer.toString(rawValue);
}

@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
LagId other = (LagId) obj;
if (rawValue != other.rawValue)
return false;
return true;
}

@Override
public LagId applyMask(LagId mask) {
return LagId.of(this.rawValue & mask.rawValue);
}

public void write4Bytes(ChannelBuffer c) {
c.writeInt(rawValue);
}

public static LagId read4Bytes(ChannelBuffer c) {
return LagId.of(c.readInt());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.projectfloodlight.openflow.types;

import org.jboss.netty.buffer.ChannelBuffer;
import org.projectfloodlight.openflow.exceptions.OFParseError;
import org.projectfloodlight.openflow.annotations.Immutable;

@Immutable
public enum PortType implements OFValueType<PortType> {
PHYSICA((byte)0),
LAG((byte)1);

private final byte type;
static final int LENGTH = 1;

public static final PortType NO_MASK = PortType.of((byte)0xFF);
public static final PortType FULL_MASK = PortType.of((byte)0x00);

private PortType(byte type) {
this.type = type;
}

public static PortType of(byte type) {
switch (type) {
case 0:
return PHYSICA;
case 1:
return LAG;
default:
throw new IllegalArgumentException("Illegal Port Type: " + type);
}
}

@Override
public int getLength() {
return LENGTH;
}

@Override
public String toString() {
return Integer.toHexString(type);
}

@Override
public PortType applyMask(PortType mask) {
return PortType.of((byte)(this.type & mask.type));
}

public void writeByte(ChannelBuffer c) {
c.writeByte(this.type);
}

public static PortType readByte(ChannelBuffer c) throws OFParseError {
return PortType.of((byte)(c.readUnsignedByte()));
}

public byte getPortType() {
return type;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.projectfloodlight.openflow.types;

import org.projectfloodlight.openflow.annotations.Immutable;

@Immutable
public class Priority implements OFValueType<Priority> {
static final int LENGTH = 4;
private final int rawValue;

public static final Priority NO_ClassId = Priority.of(0xFFFFFFFF);
public static final Priority FULL_MASK = Priority.of(0x00000000);

private Priority(final int rawValue) {
this.rawValue = rawValue;
}

public static Priority of(final int raw) {
return new Priority(raw);
}

public int getInt() {
return rawValue;
}

@Override
public int getLength() {
return LENGTH;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + rawValue;
return result;
}

@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Priority other = (Priority) obj;
if (rawValue != other.rawValue)
return false;
return true;
}

@Override
public String toString() {
return Integer.toString(rawValue);
}

@Override
public Priority applyMask(Priority mask) {
return Priority.of(this.rawValue & mask.rawValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.projectfloodlight.openflow.types;

import org.jboss.netty.buffer.ChannelBuffer;
import org.projectfloodlight.openflow.annotations.Immutable;

@Immutable
public class VRF implements OFValueType<VRF> {
static final int LENGTH = 4;
private final int rawValue;

public static final VRF NO_MASK = VRF.of(0xFFFFFFFF);
public static final VRF FULL_MASK = VRF.of(0x00000000);

private VRF(final int rawValue) {
this.rawValue = rawValue;
}

public static VRF of(final int raw) {
return new VRF(raw);
}

public int getInt() {
return rawValue;
}

@Override
public int getLength() {
return LENGTH;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + rawValue;
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VRF other = (VRF) obj;
if (rawValue != other.rawValue)
return false;
return true;
}

@Override
public String toString() {
return Integer.toString(rawValue);
}

public void write4Bytes(ChannelBuffer c) {
c.writeInt(rawValue);
}

public static VRF read4Bytes(ChannelBuffer c) {
return VRF.of(c.readInt());
}

@Override
public VRF applyMask(VRF mask) {
return VRF.of(this.rawValue & mask.rawValue);
}
}

0 comments on commit c1b011d

Please sign in to comment.