Praseed Balakrishnan

sigtype selector and treatment and fix not finding the switch id in test app.

......@@ -83,8 +83,12 @@ public class LambdaForwarding {
int inport;
int outport;
short lambda = 10;
byte sigType = 1;
Integer switchNumber = uglyMap.get(device.id());
if (switchNumber == null) {
return;
}
int switchNumber = uglyMap.get(device.id());
switch (switchNumber) {
case 1:
inport = 10;
......@@ -95,13 +99,15 @@ public class LambdaForwarding {
case 2:
inport = 21;
outport = 11;
sbuilder.matchLambda(lambda).matchInport(PortNumber.portNumber(inport)); // match sigtype
sbuilder.matchLambda(lambda).
matchInport(PortNumber.portNumber(inport)); // match sigtype
tbuilder.setOutput(PortNumber.portNumber(outport));
break;
case 3:
inport = 30;
outport = 31;
sbuilder.matchLambda(lambda).matchInport(PortNumber.portNumber(inport));
sbuilder.matchLambda(lambda).
matchInport(PortNumber.portNumber(inport));
tbuilder.setOutput(PortNumber.portNumber(outport)).setLambda(lambda);
break;
default:
......
......@@ -176,11 +176,17 @@ public final class DefaultTrafficSelector implements TrafficSelector {
}
@Override
public Builder matchLambda(short lambda) {
public Builder matchLambda(Short lambda) {
return add(Criteria.matchLambda(lambda));
}
@Override
public Builder matchOpticalSignalType(Byte signalType) {
return add(Criteria.matchOpticalSignalType(signalType));
}
@Override
public TrafficSelector build() {
return new DefaultTrafficSelector(ImmutableSet.copyOf(selector.values()));
}
......
......@@ -134,7 +134,14 @@ public interface TrafficSelector {
* @param lambda
* @return a selection builder
*/
public Builder matchLambda(short lambda);
public Builder matchLambda(Short lambda);
/**
* Matches an optical Signal Type.
* @param signalType
* @return a selection builder
*/
public Builder matchOpticalSignalType(Byte signalType);
/**
* Builds an immutable traffic selector.
......
......@@ -162,6 +162,17 @@ public final class Criteria {
}
/**
* Creates a match on lambda field using the specified value.
*
* @param lambda
* @return match criterion
*/
public static Criterion matchOpticalSignalType(Byte lambda) {
return new OpticalSignalTypeCriterion(lambda, Type.OCH_SIGTYPE);
}
/**
* Implementations of criteria.
*/
public static final class PortCriterion implements Criterion {
......@@ -577,4 +588,48 @@ public final class Criteria {
}
}
public static final class OpticalSignalTypeCriterion implements Criterion {
private final byte signalType;
private final Type type;
public OpticalSignalTypeCriterion(byte signalType, Type type) {
this.signalType = signalType;
this.type = type;
}
@Override
public Type type() {
return this.type;
}
public Byte signalType() {
return this.signalType;
}
@Override
public String toString() {
return toStringHelper(type().toString())
.add("signalType", signalType).toString();
}
@Override
public int hashCode() {
return Objects.hash(signalType, type);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof OpticalSignalTypeCriterion) {
OpticalSignalTypeCriterion that = (OpticalSignalTypeCriterion) obj;
return Objects.equals(signalType, that.signalType) &&
Objects.equals(type, that.type);
}
return false;
}
}
}
......