alshabib

fix for cbench

......@@ -9,7 +9,7 @@ import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.Path;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.flow.Instructions;
import org.onlab.onos.net.flow.instructions.Instructions;
import org.onlab.onos.net.host.HostService;
import org.onlab.onos.net.packet.InboundPacket;
import org.onlab.onos.net.packet.PacketContext;
......
......@@ -6,6 +6,7 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.onlab.onos.net.flow.instructions.Instruction;
import org.slf4j.Logger;
@SuppressWarnings("rawtypes")
......
......@@ -2,6 +2,8 @@ package org.onlab.onos.net.flow;
import java.util.List;
import org.onlab.onos.net.flow.instructions.Instruction;
/**
* Abstraction of network traffic treatment.
*/
......
package org.onlab.onos.net.flow;
package org.onlab.onos.net.flow.instructions;
/**
* Abstraction of a single traffic treatment step.
......
package org.onlab.onos.net.flow;
package org.onlab.onos.net.flow.instructions;
import static com.google.common.base.Preconditions.checkNotNull;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.SubType;
import org.onlab.packet.MACAddress;
/**
* Factory class for creating various traffic treatment instructions.
*/
public final class Instructions {
// Ban construction
private Instructions() {}
......@@ -23,12 +27,52 @@ public final class Instructions {
return new OutputInstruction(number);
}
// TODO: Move these out into separate classes and to flow.instruction package
/**
* Creates a drop instruction.
* @return drop instruction
*/
public static DropInstruction createDrop() {
return new DropInstruction();
}
// TODO: add create methods
/**
* Creates a l2 src modification.
* @param addr the mac address to modify to.
* @return a l2 modification
*/
public static L2ModificationInstruction modL2Src(MACAddress addr) {
checkNotNull(addr, "Src l2 address cannot be null");
return new ModEtherInstruction(SubType.L2_SRC, addr);
}
/**
* Creates a L2 dst modification.
* @param addr the mac address to modify to.
* @return a L2 modification
*/
public static L2ModificationInstruction modL2Dst(MACAddress addr) {
checkNotNull(addr, "Dst l2 address cannot be null");
return new L2ModificationInstruction.ModEtherInstruction(SubType.L2_DST, addr);
}
/**
* Creates a L2 type modification.
* @param l2Type the type to change to
* @return a L2 modifications
*/
public static L2ModificationInstruction modL2Type(Short l2Type) {
checkNotNull(l2Type, "L2 type cannot be null");
return new L2ModificationInstruction.ModEtherTypeInstruction(l2Type);
}
public static L2ModificationInstruction modVlanId(Short vlanId) {
checkNotNull(vlanId, "VLAN id cannot be null");
return new L2ModificationInstruction.ModVlanIdInstruction(vlanId);
}
/*
* Output instructions
*/
public static final class DropInstruction implements Instruction {
@Override
......
package org.onlab.onos.net.flow.instructions;
import org.onlab.packet.MACAddress;
/**
* Abstraction of a single traffic treatment step.
* @param <T> the type parameter for the instruction
*/
public abstract class L2ModificationInstruction implements Instruction {
/**
* Represents the type of traffic treatment.
*/
public enum SubType {
/**
* Ether src modification.
*/
L2_SRC,
/**
* Ether dst modification.
*/
L2_DST,
/**
* Ethertype modification.
*/
L2_TYPE,
/**
* VLAN id modification.
*/
VLAN_ID,
/**
* VLAN priority modification.
*/
VLAN_PCP
}
// TODO: Create factory class 'Instructions' that will have various factory
// to create specific instructions.
/**
* Returns the subtype of the modification instruction.
* @return type of instruction
*/
public abstract SubType subtype();
@Override
public Type type() {
return Type.MODIFICATION;
}
/**
* Represents a L2 src/dst modification instruction.
*/
public static final class ModEtherInstruction extends L2ModificationInstruction {
private final SubType subtype;
private final MACAddress mac;
public ModEtherInstruction(SubType subType, MACAddress addr) {
this.subtype = subType;
this.mac = addr;
}
@Override
public SubType subtype() {
return this.subtype;
}
public MACAddress mac() {
return this.mac;
}
}
/**
* Represents a L2 type modification instruction.
*/
public static final class ModEtherTypeInstruction extends L2ModificationInstruction {
public final short l2Type;
public ModEtherTypeInstruction(short l2Type) {
this.l2Type = l2Type;
}
@Override
public SubType subtype() {
return SubType.L2_TYPE;
}
public short l2Type() {
return this.l2Type;
}
}
/**
* Represents a VLAN id modification instruction.
*/
public static final class ModVlanIdInstruction extends L2ModificationInstruction {
public final Short vlanId;
public ModVlanIdInstruction(Short vlanId) {
this.vlanId = vlanId;
}
@Override
public SubType subtype() {
return SubType.VLAN_ID;
}
public Short vlanId() {
return this.vlanId;
}
}
}
......@@ -77,6 +77,11 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver {
this.dpid = dp;
}
public AbstractOpenFlowSwitch(Dpid dpid, OFDescStatsReply desc) {
this.dpid = dpid;
this.desc = desc;
}
//************************
// Channel related
//************************
......
......@@ -11,6 +11,7 @@ import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriver;
import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriverFactory;
import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
import org.projectfloodlight.openflow.protocol.OFMessage;
import org.projectfloodlight.openflow.protocol.OFPortDesc;
import org.projectfloodlight.openflow.protocol.OFVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -57,7 +58,7 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory {
log.warn("DriverManager could not identify switch desc: {}. "
+ "Assigning AbstractOpenFlowSwich", desc);
return new AbstractOpenFlowSwitch(dpid) {
return new AbstractOpenFlowSwitch(dpid, desc) {
@Override
public void write(List<OFMessage> msgs) {
......@@ -85,6 +86,15 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory {
public boolean isDriverHandshakeComplete() {
return true;
}
@Override
public List<OFPortDesc> getPorts() {
if (this.factory().getVersion() == OFVersion.OF_10) {
return Collections.unmodifiableList(features.getPorts());
} else {
return Collections.unmodifiableList(ports.getEntries());
}
}
};
}
......
......@@ -5,9 +5,9 @@ import static org.slf4j.LoggerFactory.getLogger;
import java.util.List;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.flow.Instruction;
import org.onlab.onos.net.flow.Instruction.Type;
import org.onlab.onos.net.flow.Instructions.OutputInstruction;
import org.onlab.onos.net.flow.instructions.Instruction;
import org.onlab.onos.net.flow.instructions.Instruction.Type;
import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction;
import org.onlab.onos.net.packet.DefaultPacketContext;
import org.onlab.onos.net.packet.InboundPacket;
import org.onlab.onos.net.packet.OutboundPacket;
......