Showing
7 changed files
with
225 additions
and
117 deletions
... | @@ -53,7 +53,8 @@ public class DefaultTrafficTreatment implements TrafficTreatment { | ... | @@ -53,7 +53,8 @@ public class DefaultTrafficTreatment implements TrafficTreatment { |
53 | case OUTPUT: | 53 | case OUTPUT: |
54 | outputs.add(instruction); | 54 | outputs.add(instruction); |
55 | break; | 55 | break; |
56 | - case MODIFICATION: | 56 | + case L2MODIFICATION: |
57 | + case L3MODIFICATION: | ||
57 | // TODO: enforce modification order if any | 58 | // TODO: enforce modification order if any |
58 | modifications.add(instruction); | 59 | modifications.add(instruction); |
59 | break; | 60 | break; | ... | ... |
... | @@ -227,7 +227,7 @@ public final class Criteria { | ... | @@ -227,7 +227,7 @@ public final class Criteria { |
227 | return Type.VLAN_PCP; | 227 | return Type.VLAN_PCP; |
228 | } | 228 | } |
229 | 229 | ||
230 | - public Byte protocol() { | 230 | + public Byte priority() { |
231 | return vlanPcp; | 231 | return vlanPcp; |
232 | } | 232 | } |
233 | 233 | ... | ... |
... | @@ -5,12 +5,6 @@ package org.onlab.onos.net.flow.instructions; | ... | @@ -5,12 +5,6 @@ package org.onlab.onos.net.flow.instructions; |
5 | */ | 5 | */ |
6 | public interface Instruction { | 6 | public interface Instruction { |
7 | 7 | ||
8 | - interface SubType { } | ||
9 | - | ||
10 | - public enum NoneSubType implements SubType { | ||
11 | - NONE; | ||
12 | - } | ||
13 | - | ||
14 | /** | 8 | /** |
15 | * Represents the type of traffic treatment. | 9 | * Represents the type of traffic treatment. |
16 | */ | 10 | */ |
... | @@ -31,9 +25,14 @@ public interface Instruction { | ... | @@ -31,9 +25,14 @@ public interface Instruction { |
31 | GROUP, | 25 | GROUP, |
32 | 26 | ||
33 | /** | 27 | /** |
34 | - * Signifies that the traffic should be modified in some way. | 28 | + * Signifies that the traffic should be modified in L2 way. |
29 | + */ | ||
30 | + L2MODIFICATION, | ||
31 | + | ||
32 | + /** | ||
33 | + * Signifies that the traffic should be modified in L3 way. | ||
35 | */ | 34 | */ |
36 | - MODIFICATION | 35 | + L3MODIFICATION |
37 | } | 36 | } |
38 | 37 | ||
39 | // TODO: Create factory class 'Instructions' that will have various factory | 38 | // TODO: Create factory class 'Instructions' that will have various factory |
... | @@ -45,10 +44,4 @@ public interface Instruction { | ... | @@ -45,10 +44,4 @@ public interface Instruction { |
45 | */ | 44 | */ |
46 | public Type type(); | 45 | public Type type(); |
47 | 46 | ||
48 | - /** | ||
49 | - * Returns the subtype of the modification instruction. | ||
50 | - * @return type of instruction | ||
51 | - */ | ||
52 | - public SubType subtype(); | ||
53 | - | ||
54 | } | 47 | } | ... | ... |
... | @@ -7,7 +7,6 @@ import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.L2SubType; | ... | @@ -7,7 +7,6 @@ import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.L2SubType; |
7 | import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; | 7 | import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; |
8 | import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.L3SubType; | 8 | import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.L3SubType; |
9 | import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; | 9 | import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; |
10 | -import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPProtoInstruction; | ||
11 | import org.onlab.packet.IPAddress; | 10 | import org.onlab.packet.IPAddress; |
12 | import org.onlab.packet.MACAddress; | 11 | import org.onlab.packet.MACAddress; |
13 | import org.onlab.packet.VLANID; | 12 | import org.onlab.packet.VLANID; |
... | @@ -61,16 +60,6 @@ public final class Instructions { | ... | @@ -61,16 +60,6 @@ public final class Instructions { |
61 | } | 60 | } |
62 | 61 | ||
63 | /** | 62 | /** |
64 | - * Creates a L2 type modification. | ||
65 | - * @param l2Type the type to change to | ||
66 | - * @return a L2 modifications | ||
67 | - */ | ||
68 | - public static L2ModificationInstruction modL2Type(Short l2Type) { | ||
69 | - checkNotNull(l2Type, "L2 type cannot be null"); | ||
70 | - return new L2ModificationInstruction.ModEtherTypeInstruction(l2Type); | ||
71 | - } | ||
72 | - | ||
73 | - /** | ||
74 | * Creates a Vlan id modification. | 63 | * Creates a Vlan id modification. |
75 | * @param vlanId the vlan id to modify to. | 64 | * @param vlanId the vlan id to modify to. |
76 | * @return a L2 modification | 65 | * @return a L2 modification |
... | @@ -110,15 +99,6 @@ public final class Instructions { | ... | @@ -110,15 +99,6 @@ public final class Instructions { |
110 | return new ModIPInstruction(L3SubType.L3_DST, addr); | 99 | return new ModIPInstruction(L3SubType.L3_DST, addr); |
111 | } | 100 | } |
112 | 101 | ||
113 | - /** | ||
114 | - * Creates an L3 protocol modification. | ||
115 | - * @param proto the protocol to change to | ||
116 | - * @return a L3 modification | ||
117 | - */ | ||
118 | - public static L3ModificationInstruction modIPProto(Byte proto) { | ||
119 | - checkNotNull(proto, "IP protocol cannot be null"); | ||
120 | - return new ModIPProtoInstruction(proto); | ||
121 | - } | ||
122 | 102 | ||
123 | /* | 103 | /* |
124 | * Output instructions | 104 | * Output instructions |
... | @@ -129,11 +109,6 @@ public final class Instructions { | ... | @@ -129,11 +109,6 @@ public final class Instructions { |
129 | public Type type() { | 109 | public Type type() { |
130 | return Type.DROP; | 110 | return Type.DROP; |
131 | } | 111 | } |
132 | - | ||
133 | - @Override | ||
134 | - public SubType subtype() { | ||
135 | - return NoneSubType.NONE; | ||
136 | - } | ||
137 | } | 112 | } |
138 | 113 | ||
139 | 114 | ||
... | @@ -152,11 +127,6 @@ public final class Instructions { | ... | @@ -152,11 +127,6 @@ public final class Instructions { |
152 | public Type type() { | 127 | public Type type() { |
153 | return Type.OUTPUT; | 128 | return Type.OUTPUT; |
154 | } | 129 | } |
155 | - | ||
156 | - @Override | ||
157 | - public SubType subtype() { | ||
158 | - return NoneSubType.NONE; | ||
159 | - } | ||
160 | } | 130 | } |
161 | 131 | ||
162 | } | 132 | } | ... | ... |
... | @@ -12,7 +12,7 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -12,7 +12,7 @@ public abstract class L2ModificationInstruction implements Instruction { |
12 | /** | 12 | /** |
13 | * Represents the type of traffic treatment. | 13 | * Represents the type of traffic treatment. |
14 | */ | 14 | */ |
15 | - public enum L2SubType implements SubType { | 15 | + public enum L2SubType { |
16 | /** | 16 | /** |
17 | * Ether src modification. | 17 | * Ether src modification. |
18 | */ | 18 | */ |
... | @@ -24,11 +24,6 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -24,11 +24,6 @@ public abstract class L2ModificationInstruction implements Instruction { |
24 | L2_DST, | 24 | L2_DST, |
25 | 25 | ||
26 | /** | 26 | /** |
27 | - * Ethertype modification. | ||
28 | - */ | ||
29 | - L2_TYPE, | ||
30 | - | ||
31 | - /** | ||
32 | * VLAN id modification. | 27 | * VLAN id modification. |
33 | */ | 28 | */ |
34 | VLAN_ID, | 29 | VLAN_ID, |
... | @@ -42,12 +37,11 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -42,12 +37,11 @@ public abstract class L2ModificationInstruction implements Instruction { |
42 | // TODO: Create factory class 'Instructions' that will have various factory | 37 | // TODO: Create factory class 'Instructions' that will have various factory |
43 | // to create specific instructions. | 38 | // to create specific instructions. |
44 | 39 | ||
45 | - @Override | 40 | + public abstract L2SubType subtype(); |
46 | - public abstract SubType subtype(); | ||
47 | 41 | ||
48 | @Override | 42 | @Override |
49 | public Type type() { | 43 | public Type type() { |
50 | - return Type.MODIFICATION; | 44 | + return Type.L2MODIFICATION; |
51 | } | 45 | } |
52 | 46 | ||
53 | /** | 47 | /** |
... | @@ -55,16 +49,16 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -55,16 +49,16 @@ public abstract class L2ModificationInstruction implements Instruction { |
55 | */ | 49 | */ |
56 | public static final class ModEtherInstruction extends L2ModificationInstruction { | 50 | public static final class ModEtherInstruction extends L2ModificationInstruction { |
57 | 51 | ||
58 | - private final SubType subtype; | 52 | + private final L2SubType subtype; |
59 | private final MACAddress mac; | 53 | private final MACAddress mac; |
60 | 54 | ||
61 | - public ModEtherInstruction(SubType subType, MACAddress addr) { | 55 | + public ModEtherInstruction(L2SubType subType, MACAddress addr) { |
62 | this.subtype = subType; | 56 | this.subtype = subType; |
63 | this.mac = addr; | 57 | this.mac = addr; |
64 | } | 58 | } |
65 | 59 | ||
66 | @Override | 60 | @Override |
67 | - public SubType subtype() { | 61 | + public L2SubType subtype() { |
68 | return this.subtype; | 62 | return this.subtype; |
69 | } | 63 | } |
70 | 64 | ||
... | @@ -75,28 +69,6 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -75,28 +69,6 @@ public abstract class L2ModificationInstruction implements Instruction { |
75 | } | 69 | } |
76 | 70 | ||
77 | /** | 71 | /** |
78 | - * Represents a L2 type modification instruction. | ||
79 | - */ | ||
80 | - public static final class ModEtherTypeInstruction extends L2ModificationInstruction { | ||
81 | - | ||
82 | - public final short l2Type; | ||
83 | - | ||
84 | - public ModEtherTypeInstruction(short l2Type) { | ||
85 | - this.l2Type = l2Type; | ||
86 | - } | ||
87 | - | ||
88 | - @Override | ||
89 | - public SubType subtype() { | ||
90 | - return L2SubType.L2_TYPE; | ||
91 | - } | ||
92 | - | ||
93 | - public short l2Type() { | ||
94 | - return this.l2Type; | ||
95 | - } | ||
96 | - | ||
97 | - } | ||
98 | - | ||
99 | - /** | ||
100 | * Represents a VLAN id modification instruction. | 72 | * Represents a VLAN id modification instruction. |
101 | */ | 73 | */ |
102 | public static final class ModVlanIdInstruction extends L2ModificationInstruction { | 74 | public static final class ModVlanIdInstruction extends L2ModificationInstruction { |
... | @@ -108,7 +80,7 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -108,7 +80,7 @@ public abstract class L2ModificationInstruction implements Instruction { |
108 | } | 80 | } |
109 | 81 | ||
110 | @Override | 82 | @Override |
111 | - public SubType subtype() { | 83 | + public L2SubType subtype() { |
112 | return L2SubType.VLAN_ID; | 84 | return L2SubType.VLAN_ID; |
113 | } | 85 | } |
114 | 86 | ||
... | @@ -130,7 +102,7 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -130,7 +102,7 @@ public abstract class L2ModificationInstruction implements Instruction { |
130 | } | 102 | } |
131 | 103 | ||
132 | @Override | 104 | @Override |
133 | - public SubType subtype() { | 105 | + public L2SubType subtype() { |
134 | return L2SubType.VLAN_PCP; | 106 | return L2SubType.VLAN_PCP; |
135 | } | 107 | } |
136 | 108 | ... | ... |
... | @@ -11,7 +11,7 @@ public abstract class L3ModificationInstruction implements Instruction { | ... | @@ -11,7 +11,7 @@ public abstract class L3ModificationInstruction implements Instruction { |
11 | /** | 11 | /** |
12 | * Represents the type of traffic treatment. | 12 | * Represents the type of traffic treatment. |
13 | */ | 13 | */ |
14 | - public enum L3SubType implements SubType { | 14 | + public enum L3SubType { |
15 | /** | 15 | /** |
16 | * Ether src modification. | 16 | * Ether src modification. |
17 | */ | 17 | */ |
... | @@ -20,12 +20,7 @@ public abstract class L3ModificationInstruction implements Instruction { | ... | @@ -20,12 +20,7 @@ public abstract class L3ModificationInstruction implements Instruction { |
20 | /** | 20 | /** |
21 | * Ether dst modification. | 21 | * Ether dst modification. |
22 | */ | 22 | */ |
23 | - L3_DST, | 23 | + L3_DST |
24 | - | ||
25 | - /** | ||
26 | - * Ethertype modification. | ||
27 | - */ | ||
28 | - L3_PROTO, | ||
29 | 24 | ||
30 | //TODO: remaining types | 25 | //TODO: remaining types |
31 | } | 26 | } |
... | @@ -34,11 +29,11 @@ public abstract class L3ModificationInstruction implements Instruction { | ... | @@ -34,11 +29,11 @@ public abstract class L3ModificationInstruction implements Instruction { |
34 | * Returns the subtype of the modification instruction. | 29 | * Returns the subtype of the modification instruction. |
35 | * @return type of instruction | 30 | * @return type of instruction |
36 | */ | 31 | */ |
37 | - public abstract SubType subtype(); | 32 | + public abstract L3SubType subtype(); |
38 | 33 | ||
39 | @Override | 34 | @Override |
40 | public Type type() { | 35 | public Type type() { |
41 | - return Type.MODIFICATION; | 36 | + return Type.L3MODIFICATION; |
42 | } | 37 | } |
43 | 38 | ||
44 | /** | 39 | /** |
... | @@ -46,16 +41,16 @@ public abstract class L3ModificationInstruction implements Instruction { | ... | @@ -46,16 +41,16 @@ public abstract class L3ModificationInstruction implements Instruction { |
46 | */ | 41 | */ |
47 | public static final class ModIPInstruction extends L3ModificationInstruction { | 42 | public static final class ModIPInstruction extends L3ModificationInstruction { |
48 | 43 | ||
49 | - private final SubType subtype; | 44 | + private final L3SubType subtype; |
50 | private final IPAddress ip; | 45 | private final IPAddress ip; |
51 | 46 | ||
52 | - public ModIPInstruction(SubType subType, IPAddress addr) { | 47 | + public ModIPInstruction(L3SubType subType, IPAddress addr) { |
53 | this.subtype = subType; | 48 | this.subtype = subType; |
54 | this.ip = addr; | 49 | this.ip = addr; |
55 | } | 50 | } |
56 | 51 | ||
57 | @Override | 52 | @Override |
58 | - public SubType subtype() { | 53 | + public L3SubType subtype() { |
59 | return this.subtype; | 54 | return this.subtype; |
60 | } | 55 | } |
61 | 56 | ||
... | @@ -64,26 +59,4 @@ public abstract class L3ModificationInstruction implements Instruction { | ... | @@ -64,26 +59,4 @@ public abstract class L3ModificationInstruction implements Instruction { |
64 | } | 59 | } |
65 | 60 | ||
66 | } | 61 | } |
67 | - | ||
68 | - /** | ||
69 | - * Represents a L3 proto modification instruction. | ||
70 | - */ | ||
71 | - public static final class ModIPProtoInstruction extends L3ModificationInstruction { | ||
72 | - | ||
73 | - public final Byte proto; | ||
74 | - | ||
75 | - public ModIPProtoInstruction(Byte proto) { | ||
76 | - this.proto = proto; | ||
77 | - } | ||
78 | - | ||
79 | - @Override | ||
80 | - public SubType subtype() { | ||
81 | - return L3SubType.L3_PROTO; | ||
82 | - } | ||
83 | - | ||
84 | - public short proto() { | ||
85 | - return this.proto; | ||
86 | - } | ||
87 | - | ||
88 | - } | ||
89 | } | 62 | } | ... | ... |
... | @@ -2,6 +2,10 @@ package org.onlab.onos.provider.of.flow.impl; | ... | @@ -2,6 +2,10 @@ package org.onlab.onos.provider.of.flow.impl; |
2 | 2 | ||
3 | import static org.slf4j.LoggerFactory.getLogger; | 3 | import static org.slf4j.LoggerFactory.getLogger; |
4 | 4 | ||
5 | +import java.util.Collections; | ||
6 | +import java.util.LinkedList; | ||
7 | +import java.util.List; | ||
8 | + | ||
5 | import org.apache.felix.scr.annotations.Activate; | 9 | import org.apache.felix.scr.annotations.Activate; |
6 | import org.apache.felix.scr.annotations.Component; | 10 | import org.apache.felix.scr.annotations.Component; |
7 | import org.apache.felix.scr.annotations.Deactivate; | 11 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -13,10 +17,41 @@ import org.onlab.onos.net.flow.FlowRule; | ... | @@ -13,10 +17,41 @@ import org.onlab.onos.net.flow.FlowRule; |
13 | import org.onlab.onos.net.flow.FlowRuleProvider; | 17 | import org.onlab.onos.net.flow.FlowRuleProvider; |
14 | import org.onlab.onos.net.flow.FlowRuleProviderRegistry; | 18 | import org.onlab.onos.net.flow.FlowRuleProviderRegistry; |
15 | import org.onlab.onos.net.flow.FlowRuleProviderService; | 19 | import org.onlab.onos.net.flow.FlowRuleProviderService; |
20 | +import org.onlab.onos.net.flow.criteria.Criteria.EthCriterion; | ||
21 | +import org.onlab.onos.net.flow.criteria.Criteria.EthTypeCriterion; | ||
22 | +import org.onlab.onos.net.flow.criteria.Criteria.IPCriterion; | ||
23 | +import org.onlab.onos.net.flow.criteria.Criteria.IPProtocolCriterion; | ||
24 | +import org.onlab.onos.net.flow.criteria.Criteria.PortCriterion; | ||
25 | +import org.onlab.onos.net.flow.criteria.Criteria.VlanIdCriterion; | ||
26 | +import org.onlab.onos.net.flow.criteria.Criteria.VlanPcpCriterion; | ||
27 | +import org.onlab.onos.net.flow.criteria.Criterion; | ||
28 | +import org.onlab.onos.net.flow.instructions.Instruction; | ||
29 | +import org.onlab.onos.net.flow.instructions.L2ModificationInstruction; | ||
30 | +import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; | ||
31 | +import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction; | ||
32 | +import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction; | ||
33 | +import org.onlab.onos.net.flow.instructions.L3ModificationInstruction; | ||
34 | +import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; | ||
16 | import org.onlab.onos.net.provider.AbstractProvider; | 35 | import org.onlab.onos.net.provider.AbstractProvider; |
17 | import org.onlab.onos.net.provider.ProviderId; | 36 | import org.onlab.onos.net.provider.ProviderId; |
18 | import org.onlab.onos.net.topology.TopologyService; | 37 | import org.onlab.onos.net.topology.TopologyService; |
38 | +import org.onlab.onos.of.controller.Dpid; | ||
19 | import org.onlab.onos.of.controller.OpenFlowController; | 39 | import org.onlab.onos.of.controller.OpenFlowController; |
40 | +import org.onlab.onos.of.controller.OpenFlowSwitch; | ||
41 | +import org.projectfloodlight.openflow.protocol.OFFactory; | ||
42 | +import org.projectfloodlight.openflow.protocol.OFFlowMod; | ||
43 | +import org.projectfloodlight.openflow.protocol.OFFlowModFlags; | ||
44 | +import org.projectfloodlight.openflow.protocol.action.OFAction; | ||
45 | +import org.projectfloodlight.openflow.protocol.match.Match; | ||
46 | +import org.projectfloodlight.openflow.protocol.match.MatchField; | ||
47 | +import org.projectfloodlight.openflow.types.EthType; | ||
48 | +import org.projectfloodlight.openflow.types.IPv4Address; | ||
49 | +import org.projectfloodlight.openflow.types.IpProtocol; | ||
50 | +import org.projectfloodlight.openflow.types.MacAddress; | ||
51 | +import org.projectfloodlight.openflow.types.OFPort; | ||
52 | +import org.projectfloodlight.openflow.types.OFVlanVidMatch; | ||
53 | +import org.projectfloodlight.openflow.types.VlanPcp; | ||
54 | +import org.projectfloodlight.openflow.types.VlanVid; | ||
20 | import org.slf4j.Logger; | 55 | import org.slf4j.Logger; |
21 | 56 | ||
22 | /** | 57 | /** |
... | @@ -61,8 +96,172 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr | ... | @@ -61,8 +96,172 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr |
61 | } | 96 | } |
62 | @Override | 97 | @Override |
63 | public void applyFlowRule(FlowRule... flowRules) { | 98 | public void applyFlowRule(FlowRule... flowRules) { |
64 | - // TODO Auto-generated method stub | 99 | + for (int i = 0; i < flowRules.length; i++) { |
100 | + applyRule(flowRules[i]); | ||
101 | + } | ||
102 | + | ||
103 | + } | ||
104 | + | ||
105 | + private void applyRule(FlowRule flowRule) { | ||
106 | + OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri())); | ||
107 | + Match match = buildMatch(flowRule.selector().criteria(), sw.factory()); | ||
108 | + List<OFAction> actions = | ||
109 | + buildActions(flowRule.treatment().instructions(), sw.factory()); | ||
110 | + | ||
111 | + //TODO: what to do without bufferid? do we assume that there will be a pktout as well? | ||
112 | + OFFlowMod fm = sw.factory().buildFlowModify() | ||
113 | + .setActions(actions) | ||
114 | + .setMatch(match) | ||
115 | + .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) | ||
116 | + .setIdleTimeout(10) | ||
117 | + .setHardTimeout(10) | ||
118 | + .setPriority(flowRule.priority()) | ||
119 | + .build(); | ||
120 | + | ||
121 | + sw.sendMsg(fm); | ||
122 | + | ||
123 | + } | ||
124 | + | ||
125 | + private List<OFAction> buildActions(List<Instruction> instructions, OFFactory factory) { | ||
126 | + List<OFAction> acts = new LinkedList<>(); | ||
127 | + for (Instruction i : instructions) { | ||
128 | + switch (i.type()) { | ||
129 | + case DROP: | ||
130 | + log.warn("Saw drop action; assigning drop action"); | ||
131 | + return acts; | ||
132 | + case L2MODIFICATION: | ||
133 | + acts.add(buildL2Modification(i, factory)); | ||
134 | + case L3MODIFICATION: | ||
135 | + acts.add(buildL3Modification(i, factory)); | ||
136 | + case OUTPUT: | ||
137 | + break; | ||
138 | + case GROUP: | ||
139 | + default: | ||
140 | + log.warn("Instruction type {} not yet implemented.", i.type()); | ||
141 | + } | ||
142 | + } | ||
143 | + | ||
144 | + return acts; | ||
145 | + } | ||
146 | + | ||
147 | + private OFAction buildL3Modification(Instruction i, OFFactory factory) { | ||
148 | + L3ModificationInstruction l3m = (L3ModificationInstruction) i; | ||
149 | + ModIPInstruction ip; | ||
150 | + switch (l3m.subtype()) { | ||
151 | + case L3_DST: | ||
152 | + ip = (ModIPInstruction) i; | ||
153 | + return factory.actions().setNwDst(IPv4Address.of(ip.ip().toInt())); | ||
154 | + case L3_SRC: | ||
155 | + ip = (ModIPInstruction) i; | ||
156 | + return factory.actions().setNwSrc(IPv4Address.of(ip.ip().toInt())); | ||
157 | + default: | ||
158 | + log.warn("Unimplemented action type {}.", l3m.subtype()); | ||
159 | + break; | ||
160 | + } | ||
161 | + return null; | ||
162 | + } | ||
163 | + | ||
164 | + private OFAction buildL2Modification(Instruction i, OFFactory factory) { | ||
165 | + L2ModificationInstruction l2m = (L2ModificationInstruction) i; | ||
166 | + ModEtherInstruction eth; | ||
167 | + switch (l2m.subtype()) { | ||
168 | + case L2_DST: | ||
169 | + eth = (ModEtherInstruction) l2m; | ||
170 | + return factory.actions().setDlDst(MacAddress.of(eth.mac().toLong())); | ||
171 | + case L2_SRC: | ||
172 | + eth = (ModEtherInstruction) l2m; | ||
173 | + return factory.actions().setDlSrc(MacAddress.of(eth.mac().toLong())); | ||
174 | + case VLAN_ID: | ||
175 | + ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m; | ||
176 | + return factory.actions().setVlanVid(VlanVid.ofVlan(vlanId.vlanId.toShort())); | ||
177 | + case VLAN_PCP: | ||
178 | + ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m; | ||
179 | + return factory.actions().setVlanPcp(VlanPcp.of(vlanPcp.vlanPcp())); | ||
180 | + default: | ||
181 | + log.warn("Unimplemented action type {}.", l2m.subtype()); | ||
182 | + break; | ||
183 | + } | ||
184 | + return null; | ||
185 | + } | ||
65 | 186 | ||
187 | + private Match buildMatch(List<Criterion> criteria, OFFactory factory) { | ||
188 | + Match.Builder mBuilder = factory.buildMatch(); | ||
189 | + EthCriterion eth; | ||
190 | + IPCriterion ip; | ||
191 | + for (Criterion c : criteria) { | ||
192 | + switch (c.type()) { | ||
193 | + case IN_PORT: | ||
194 | + PortCriterion inport = (PortCriterion) c; | ||
195 | + mBuilder.setExact(MatchField.IN_PORT, OFPort.of((int) inport.port().toLong())); | ||
196 | + break; | ||
197 | + case ETH_SRC: | ||
198 | + eth = (EthCriterion) c; | ||
199 | + mBuilder.setExact(MatchField.ETH_SRC, MacAddress.of(eth.mac().toLong())); | ||
200 | + break; | ||
201 | + case ETH_DST: | ||
202 | + eth = (EthCriterion) c; | ||
203 | + mBuilder.setExact(MatchField.ETH_DST, MacAddress.of(eth.mac().toLong())); | ||
204 | + break; | ||
205 | + case ETH_TYPE: | ||
206 | + EthTypeCriterion ethType = (EthTypeCriterion) c; | ||
207 | + mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType())); | ||
208 | + case IPV4_DST: | ||
209 | + ip = (IPCriterion) c; | ||
210 | + mBuilder.setExact(MatchField.IPV4_DST, IPv4Address.of(ip.ip().toString())); | ||
211 | + break; | ||
212 | + case IPV4_SRC: | ||
213 | + ip = (IPCriterion) c; | ||
214 | + mBuilder.setExact(MatchField.IPV4_SRC, IPv4Address.of(ip.ip().toString())); | ||
215 | + break; | ||
216 | + case IP_PROTO: | ||
217 | + IPProtocolCriterion p = (IPProtocolCriterion) c; | ||
218 | + mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol())); | ||
219 | + break; | ||
220 | + case VLAN_PCP: | ||
221 | + VlanPcpCriterion vpcp = (VlanPcpCriterion) c; | ||
222 | + mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority())); | ||
223 | + break; | ||
224 | + case VLAN_VID: | ||
225 | + VlanIdCriterion vid = (VlanIdCriterion) c; | ||
226 | + mBuilder.setExact(MatchField.VLAN_VID, | ||
227 | + OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort()))); | ||
228 | + break; | ||
229 | + case ARP_OP: | ||
230 | + case ARP_SHA: | ||
231 | + case ARP_SPA: | ||
232 | + case ARP_THA: | ||
233 | + case ARP_TPA: | ||
234 | + case ICMPV4_CODE: | ||
235 | + case ICMPV4_TYPE: | ||
236 | + case ICMPV6_CODE: | ||
237 | + case ICMPV6_TYPE: | ||
238 | + case IN_PHY_PORT: | ||
239 | + case IPV6_DST: | ||
240 | + case IPV6_EXTHDR: | ||
241 | + case IPV6_FLABEL: | ||
242 | + case IPV6_ND_SLL: | ||
243 | + case IPV6_ND_TARGET: | ||
244 | + case IPV6_ND_TLL: | ||
245 | + case IPV6_SRC: | ||
246 | + case IP_DSCP: | ||
247 | + case IP_ECN: | ||
248 | + case METADATA: | ||
249 | + case MPLS_BOS: | ||
250 | + case MPLS_LABEL: | ||
251 | + case MPLS_TC: | ||
252 | + case PBB_ISID: | ||
253 | + case SCTP_DST: | ||
254 | + case SCTP_SRC: | ||
255 | + case TCP_DST: | ||
256 | + case TCP_SRC: | ||
257 | + case TUNNEL_ID: | ||
258 | + case UDP_DST: | ||
259 | + case UDP_SRC: | ||
260 | + default: | ||
261 | + log.warn("Action type {} not yet implemented.", c.type()); | ||
262 | + } | ||
263 | + } | ||
264 | + return mBuilder.build(); | ||
66 | } | 265 | } |
67 | 266 | ||
68 | @Override | 267 | @Override | ... | ... |
-
Please register or login to post a comment