alshabib

fix for cbench

...@@ -9,7 +9,7 @@ import org.onlab.onos.net.Host; ...@@ -9,7 +9,7 @@ import org.onlab.onos.net.Host;
9 import org.onlab.onos.net.HostId; 9 import org.onlab.onos.net.HostId;
10 import org.onlab.onos.net.Path; 10 import org.onlab.onos.net.Path;
11 import org.onlab.onos.net.PortNumber; 11 import org.onlab.onos.net.PortNumber;
12 -import org.onlab.onos.net.flow.Instructions; 12 +import org.onlab.onos.net.flow.instructions.Instructions;
13 import org.onlab.onos.net.host.HostService; 13 import org.onlab.onos.net.host.HostService;
14 import org.onlab.onos.net.packet.InboundPacket; 14 import org.onlab.onos.net.packet.InboundPacket;
15 import org.onlab.onos.net.packet.PacketContext; 15 import org.onlab.onos.net.packet.PacketContext;
......
...@@ -6,6 +6,7 @@ import java.util.Collections; ...@@ -6,6 +6,7 @@ import java.util.Collections;
6 import java.util.LinkedList; 6 import java.util.LinkedList;
7 import java.util.List; 7 import java.util.List;
8 8
9 +import org.onlab.onos.net.flow.instructions.Instruction;
9 import org.slf4j.Logger; 10 import org.slf4j.Logger;
10 11
11 @SuppressWarnings("rawtypes") 12 @SuppressWarnings("rawtypes")
......
...@@ -2,6 +2,8 @@ package org.onlab.onos.net.flow; ...@@ -2,6 +2,8 @@ package org.onlab.onos.net.flow;
2 2
3 import java.util.List; 3 import java.util.List;
4 4
5 +import org.onlab.onos.net.flow.instructions.Instruction;
6 +
5 /** 7 /**
6 * Abstraction of network traffic treatment. 8 * Abstraction of network traffic treatment.
7 */ 9 */
......
1 -package org.onlab.onos.net.flow; 1 +package org.onlab.onos.net.flow.instructions;
2 2
3 /** 3 /**
4 * Abstraction of a single traffic treatment step. 4 * Abstraction of a single traffic treatment step.
......
1 -package org.onlab.onos.net.flow; 1 +package org.onlab.onos.net.flow.instructions;
2 2
3 import static com.google.common.base.Preconditions.checkNotNull; 3 import static com.google.common.base.Preconditions.checkNotNull;
4 4
5 import org.onlab.onos.net.PortNumber; 5 import org.onlab.onos.net.PortNumber;
6 +import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
7 +import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.SubType;
8 +import org.onlab.packet.MACAddress;
6 /** 9 /**
7 * Factory class for creating various traffic treatment instructions. 10 * Factory class for creating various traffic treatment instructions.
8 */ 11 */
9 public final class Instructions { 12 public final class Instructions {
10 13
14 +
11 // Ban construction 15 // Ban construction
12 private Instructions() {} 16 private Instructions() {}
13 17
...@@ -23,12 +27,52 @@ public final class Instructions { ...@@ -23,12 +27,52 @@ public final class Instructions {
23 return new OutputInstruction(number); 27 return new OutputInstruction(number);
24 } 28 }
25 29
26 - // TODO: Move these out into separate classes and to flow.instruction package 30 + /**
31 + * Creates a drop instruction.
32 + * @return drop instruction
33 + */
27 public static DropInstruction createDrop() { 34 public static DropInstruction createDrop() {
28 return new DropInstruction(); 35 return new DropInstruction();
29 } 36 }
30 37
31 - // TODO: add create methods 38 + /**
39 + * Creates a l2 src modification.
40 + * @param addr the mac address to modify to.
41 + * @return a l2 modification
42 + */
43 + public static L2ModificationInstruction modL2Src(MACAddress addr) {
44 + checkNotNull(addr, "Src l2 address cannot be null");
45 + return new ModEtherInstruction(SubType.L2_SRC, addr);
46 + }
47 +
48 + /**
49 + * Creates a L2 dst modification.
50 + * @param addr the mac address to modify to.
51 + * @return a L2 modification
52 + */
53 + public static L2ModificationInstruction modL2Dst(MACAddress addr) {
54 + checkNotNull(addr, "Dst l2 address cannot be null");
55 + return new L2ModificationInstruction.ModEtherInstruction(SubType.L2_DST, addr);
56 + }
57 +
58 + /**
59 + * Creates a L2 type modification.
60 + * @param l2Type the type to change to
61 + * @return a L2 modifications
62 + */
63 + public static L2ModificationInstruction modL2Type(Short l2Type) {
64 + checkNotNull(l2Type, "L2 type cannot be null");
65 + return new L2ModificationInstruction.ModEtherTypeInstruction(l2Type);
66 + }
67 +
68 + public static L2ModificationInstruction modVlanId(Short vlanId) {
69 + checkNotNull(vlanId, "VLAN id cannot be null");
70 + return new L2ModificationInstruction.ModVlanIdInstruction(vlanId);
71 + }
72 +
73 + /*
74 + * Output instructions
75 + */
32 76
33 public static final class DropInstruction implements Instruction { 77 public static final class DropInstruction implements Instruction {
34 @Override 78 @Override
......
1 +package org.onlab.onos.net.flow.instructions;
2 +
3 +import org.onlab.packet.MACAddress;
4 +
5 +/**
6 + * Abstraction of a single traffic treatment step.
7 + * @param <T> the type parameter for the instruction
8 + */
9 +public abstract class L2ModificationInstruction implements Instruction {
10 +
11 + /**
12 + * Represents the type of traffic treatment.
13 + */
14 + public enum SubType {
15 + /**
16 + * Ether src modification.
17 + */
18 + L2_SRC,
19 +
20 + /**
21 + * Ether dst modification.
22 + */
23 + L2_DST,
24 +
25 + /**
26 + * Ethertype modification.
27 + */
28 + L2_TYPE,
29 +
30 + /**
31 + * VLAN id modification.
32 + */
33 + VLAN_ID,
34 +
35 + /**
36 + * VLAN priority modification.
37 + */
38 + VLAN_PCP
39 + }
40 +
41 + // TODO: Create factory class 'Instructions' that will have various factory
42 + // to create specific instructions.
43 +
44 + /**
45 + * Returns the subtype of the modification instruction.
46 + * @return type of instruction
47 + */
48 + public abstract SubType subtype();
49 +
50 + @Override
51 + public Type type() {
52 + return Type.MODIFICATION;
53 + }
54 +
55 + /**
56 + * Represents a L2 src/dst modification instruction.
57 + */
58 + public static final class ModEtherInstruction extends L2ModificationInstruction {
59 +
60 + private final SubType subtype;
61 + private final MACAddress mac;
62 +
63 + public ModEtherInstruction(SubType subType, MACAddress addr) {
64 + this.subtype = subType;
65 + this.mac = addr;
66 + }
67 +
68 + @Override
69 + public SubType subtype() {
70 + return this.subtype;
71 + }
72 +
73 + public MACAddress mac() {
74 + return this.mac;
75 + }
76 +
77 + }
78 +
79 + /**
80 + * Represents a L2 type modification instruction.
81 + */
82 + public static final class ModEtherTypeInstruction extends L2ModificationInstruction {
83 +
84 + public final short l2Type;
85 +
86 + public ModEtherTypeInstruction(short l2Type) {
87 + this.l2Type = l2Type;
88 + }
89 +
90 + @Override
91 + public SubType subtype() {
92 + return SubType.L2_TYPE;
93 + }
94 +
95 + public short l2Type() {
96 + return this.l2Type;
97 + }
98 +
99 + }
100 +
101 + /**
102 + * Represents a VLAN id modification instruction.
103 + */
104 + public static final class ModVlanIdInstruction extends L2ModificationInstruction {
105 +
106 + public final Short vlanId;
107 +
108 + public ModVlanIdInstruction(Short vlanId) {
109 + this.vlanId = vlanId;
110 + }
111 +
112 + @Override
113 + public SubType subtype() {
114 + return SubType.VLAN_ID;
115 + }
116 +
117 + public Short vlanId() {
118 + return this.vlanId;
119 + }
120 +
121 + }
122 +
123 +
124 +}
...@@ -77,6 +77,11 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver { ...@@ -77,6 +77,11 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver {
77 this.dpid = dp; 77 this.dpid = dp;
78 } 78 }
79 79
80 + public AbstractOpenFlowSwitch(Dpid dpid, OFDescStatsReply desc) {
81 + this.dpid = dpid;
82 + this.desc = desc;
83 + }
84 +
80 //************************ 85 //************************
81 // Channel related 86 // Channel related
82 //************************ 87 //************************
......
...@@ -11,6 +11,7 @@ import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriver; ...@@ -11,6 +11,7 @@ import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriver;
11 import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriverFactory; 11 import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriverFactory;
12 import org.projectfloodlight.openflow.protocol.OFDescStatsReply; 12 import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
13 import org.projectfloodlight.openflow.protocol.OFMessage; 13 import org.projectfloodlight.openflow.protocol.OFMessage;
14 +import org.projectfloodlight.openflow.protocol.OFPortDesc;
14 import org.projectfloodlight.openflow.protocol.OFVersion; 15 import org.projectfloodlight.openflow.protocol.OFVersion;
15 import org.slf4j.Logger; 16 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory; 17 import org.slf4j.LoggerFactory;
...@@ -57,7 +58,7 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory { ...@@ -57,7 +58,7 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory {
57 58
58 log.warn("DriverManager could not identify switch desc: {}. " 59 log.warn("DriverManager could not identify switch desc: {}. "
59 + "Assigning AbstractOpenFlowSwich", desc); 60 + "Assigning AbstractOpenFlowSwich", desc);
60 - return new AbstractOpenFlowSwitch(dpid) { 61 + return new AbstractOpenFlowSwitch(dpid, desc) {
61 62
62 @Override 63 @Override
63 public void write(List<OFMessage> msgs) { 64 public void write(List<OFMessage> msgs) {
...@@ -85,6 +86,15 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory { ...@@ -85,6 +86,15 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory {
85 public boolean isDriverHandshakeComplete() { 86 public boolean isDriverHandshakeComplete() {
86 return true; 87 return true;
87 } 88 }
89 +
90 + @Override
91 + public List<OFPortDesc> getPorts() {
92 + if (this.factory().getVersion() == OFVersion.OF_10) {
93 + return Collections.unmodifiableList(features.getPorts());
94 + } else {
95 + return Collections.unmodifiableList(ports.getEntries());
96 + }
97 + }
88 }; 98 };
89 } 99 }
90 100
......
...@@ -5,9 +5,9 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -5,9 +5,9 @@ import static org.slf4j.LoggerFactory.getLogger;
5 import java.util.List; 5 import java.util.List;
6 6
7 import org.onlab.onos.net.PortNumber; 7 import org.onlab.onos.net.PortNumber;
8 -import org.onlab.onos.net.flow.Instruction; 8 +import org.onlab.onos.net.flow.instructions.Instruction;
9 -import org.onlab.onos.net.flow.Instruction.Type; 9 +import org.onlab.onos.net.flow.instructions.Instruction.Type;
10 -import org.onlab.onos.net.flow.Instructions.OutputInstruction; 10 +import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction;
11 import org.onlab.onos.net.packet.DefaultPacketContext; 11 import org.onlab.onos.net.packet.DefaultPacketContext;
12 import org.onlab.onos.net.packet.InboundPacket; 12 import org.onlab.onos.net.packet.InboundPacket;
13 import org.onlab.onos.net.packet.OutboundPacket; 13 import org.onlab.onos.net.packet.OutboundPacket;
......