sangho

(ONOS-684) Added a few new OF actions, which are required for Segment Routing Application

 - MPLS POP (Ethernet type)
 - Dec MPLS TTL
 - Dec NW TTL
 - Copy TTL In
 - Copy TTL Out

Change-Id: I639a1bfff9ba3ae8c372c0a4b36f132cb2610b7b
...@@ -196,6 +196,21 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { ...@@ -196,6 +196,21 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
196 } 196 }
197 197
198 @Override 198 @Override
199 + public Builder decNwTtl() {
200 + return add(Instructions.decNwTtl());
201 + }
202 +
203 + @Override
204 + public Builder copyTtlIn() {
205 + return add(Instructions.copyTtlIn());
206 + }
207 +
208 + @Override
209 + public Builder copyTtlOut() {
210 + return add(Instructions.copyTtlOut());
211 + }
212 +
213 + @Override
199 public Builder pushMpls() { 214 public Builder pushMpls() {
200 return add(Instructions.pushMpls()); 215 return add(Instructions.pushMpls());
201 } 216 }
...@@ -205,6 +220,10 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { ...@@ -205,6 +220,10 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
205 return add(Instructions.popMpls()); 220 return add(Instructions.popMpls());
206 } 221 }
207 222
223 + @Override
224 + public Builder popMpls(short etherType) {
225 + return add(Instructions.popMpls(etherType));
226 + }
208 227
209 @Override 228 @Override
210 public Builder setMpls(Integer mplsLabel) { 229 public Builder setMpls(Integer mplsLabel) {
...@@ -212,6 +231,11 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { ...@@ -212,6 +231,11 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
212 } 231 }
213 232
214 @Override 233 @Override
234 + public Builder decMplsTtl() {
235 + return add(Instructions.decMplsTtl());
236 + }
237 +
238 + @Override
215 public Builder setLambda(short lambda) { 239 public Builder setLambda(short lambda) {
216 return add(Instructions.modL0Lambda(lambda)); 240 return add(Instructions.modL0Lambda(lambda));
217 } 241 }
......
...@@ -119,6 +119,27 @@ public interface TrafficTreatment { ...@@ -119,6 +119,27 @@ public interface TrafficTreatment {
119 public Builder setIpDst(IpAddress addr); 119 public Builder setIpDst(IpAddress addr);
120 120
121 /** 121 /**
122 + * Decrease the TTL in IP header by one.
123 + *
124 + * @return a treatment builder
125 + */
126 + public Builder decNwTtl();
127 +
128 + /**
129 + * Copy the TTL to outer protocol layer.
130 + *
131 + * @return a treatment builder
132 + */
133 + public Builder copyTtlOut();
134 +
135 + /**
136 + * Copy the TTL to inner protocol layer.
137 + *
138 + * @return a treatment builder
139 + */
140 + public Builder copyTtlIn();
141 +
142 + /**
122 * Push MPLS ether type. 143 * Push MPLS ether type.
123 * 144 *
124 * @return a treatment builder. 145 * @return a treatment builder.
...@@ -133,6 +154,14 @@ public interface TrafficTreatment { ...@@ -133,6 +154,14 @@ public interface TrafficTreatment {
133 public Builder popMpls(); 154 public Builder popMpls();
134 155
135 /** 156 /**
157 + * Pops MPLS ether type.
158 + *
159 + * @param ethType Ethernet type to set
160 + * @return a treatment builder.
161 + */
162 + public Builder popMpls(short ethType);
163 +
164 + /**
136 * Sets the mpls label. 165 * Sets the mpls label.
137 * 166 *
138 * @param mplsLabel MPLS label. 167 * @param mplsLabel MPLS label.
...@@ -141,6 +170,13 @@ public interface TrafficTreatment { ...@@ -141,6 +170,13 @@ public interface TrafficTreatment {
141 public Builder setMpls(Integer mplsLabel); 170 public Builder setMpls(Integer mplsLabel);
142 171
143 /** 172 /**
173 + * Decrement MPLS TTL.
174 + *
175 + * @return a treatment builder
176 + */
177 + public Builder decMplsTtl();
178 +
179 + /**
144 * Sets the optical channel ID or lambda. 180 * Sets the optical channel ID or lambda.
145 * 181 *
146 * @param lambda optical channel ID 182 * @param lambda optical channel ID
......
...@@ -28,6 +28,7 @@ import org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType ...@@ -28,6 +28,7 @@ import org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType
28 import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; 28 import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
29 import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType; 29 import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType;
30 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; 30 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
31 +import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction;
31 32
32 import org.onlab.packet.Ethernet; 33 import org.onlab.packet.Ethernet;
33 import org.onlab.packet.IpAddress; 34 import org.onlab.packet.IpAddress;
...@@ -122,6 +123,15 @@ public final class Instructions { ...@@ -122,6 +123,15 @@ public final class Instructions {
122 checkNotNull(mplsLabel, "MPLS label cannot be null"); 123 checkNotNull(mplsLabel, "MPLS label cannot be null");
123 return new ModMplsLabelInstruction(mplsLabel); 124 return new ModMplsLabelInstruction(mplsLabel);
124 } 125 }
126 +
127 + /**
128 + * Creates a MPLS TTL modification.
129 + *
130 + * @return a L2 Modification
131 + */
132 + public static L2ModificationInstruction decMplsTtl() {
133 + return new ModMplsTtlInstruction();
134 + }
125 /** 135 /**
126 * Creates a L3 src modification. 136 * Creates a L3 src modification.
127 * @param addr the ip address to modify to. 137 * @param addr the ip address to modify to.
...@@ -143,6 +153,30 @@ public final class Instructions { ...@@ -143,6 +153,30 @@ public final class Instructions {
143 } 153 }
144 154
145 /** 155 /**
156 + * Creates a L3 TTL modification.
157 + * @return a L3 modification
158 + */
159 + public static L3ModificationInstruction decNwTtl() {
160 + return new ModTtlInstruction(L3SubType.DEC_TTL);
161 + }
162 +
163 + /**
164 + * Creates a L3 TTL modification.
165 + * @return a L3 modification
166 + */
167 + public static L3ModificationInstruction copyTtlOut() {
168 + return new ModTtlInstruction(L3SubType.TTL_OUT);
169 + }
170 +
171 + /**
172 + * Creates a L3 TTL modification.
173 + * @return a L3 modification
174 + */
175 + public static L3ModificationInstruction copyTtlIn() {
176 + return new ModTtlInstruction(L3SubType.TTL_IN);
177 + }
178 +
179 + /**
146 * Creates a mpls header instruction. 180 * Creates a mpls header instruction.
147 * @return a L2 modification. 181 * @return a L2 modification.
148 */ 182 */
...@@ -160,6 +194,18 @@ public final class Instructions { ...@@ -160,6 +194,18 @@ public final class Instructions {
160 new Ethernet().setEtherType(Ethernet.MPLS_UNICAST)); 194 new Ethernet().setEtherType(Ethernet.MPLS_UNICAST));
161 } 195 }
162 196
197 + /**
198 + * Creates a mpls header instruction.
199 + *
200 + * @param etherType Ethernet type to set
201 + * @return a L2 modification.
202 + */
203 + public static Instruction popMpls(Short etherType) {
204 + checkNotNull(etherType, "Ethernet type cannot be null");
205 + return new PushHeaderInstructions(L2SubType.MPLS_POP,
206 + new Ethernet().setEtherType(etherType));
207 + }
208 +
163 /* 209 /*
164 * Output instructions 210 * Output instructions
165 */ 211 */
......
...@@ -65,7 +65,13 @@ public abstract class L2ModificationInstruction implements Instruction { ...@@ -65,7 +65,13 @@ public abstract class L2ModificationInstruction implements Instruction {
65 /** 65 /**
66 * MPLS Pop modification. 66 * MPLS Pop modification.
67 */ 67 */
68 - MPLS_POP 68 + MPLS_POP,
69 +
70 + /**
71 + * MPLS TTL modification.
72 + */
73 + DEC_MPLS_TTL
74 +
69 } 75 }
70 76
71 // TODO: Create factory class 'Instructions' that will have various factory 77 // TODO: Create factory class 'Instructions' that will have various factory
...@@ -322,4 +328,41 @@ public abstract class L2ModificationInstruction implements Instruction { ...@@ -322,4 +328,41 @@ public abstract class L2ModificationInstruction implements Instruction {
322 return false; 328 return false;
323 } 329 }
324 } 330 }
331 +
332 + /**
333 + * Represents a MPLS label modification.
334 + */
335 + public static final class ModMplsTtlInstruction extends
336 + L2ModificationInstruction {
337 +
338 + public ModMplsTtlInstruction() {
339 + }
340 +
341 + @Override
342 + public L2SubType subtype() {
343 + return L2SubType.DEC_MPLS_TTL;
344 + }
345 +
346 + @Override
347 + public String toString() {
348 + return type().toString();
349 + }
350 +
351 + @Override
352 + public int hashCode() {
353 + return Objects.hash(type(), L2SubType.DEC_MPLS_TTL);
354 + }
355 +
356 + @Override
357 + public boolean equals(Object obj) {
358 + if (this == obj) {
359 + return true;
360 + }
361 + if (obj instanceof ModMplsLabelInstruction) {
362 + ModMplsTtlInstruction that = (ModMplsTtlInstruction) obj;
363 + return Objects.equals(this.type(), that.type());
364 + }
365 + return false;
366 + }
367 + }
325 } 368 }
......
...@@ -38,7 +38,22 @@ public abstract class L3ModificationInstruction implements Instruction { ...@@ -38,7 +38,22 @@ public abstract class L3ModificationInstruction implements Instruction {
38 /** 38 /**
39 * Ether dst modification. 39 * Ether dst modification.
40 */ 40 */
41 - IP_DST 41 + IP_DST,
42 +
43 + /**
44 + * Decrease TTL.
45 + */
46 + DEC_TTL,
47 +
48 + /**
49 + * Copy TTL out.
50 + */
51 + TTL_OUT,
52 +
53 + /**
54 + * Copy TTL in.
55 + */
56 + TTL_IN
42 57
43 //TODO: remaining types 58 //TODO: remaining types
44 } 59 }
...@@ -102,6 +117,43 @@ public abstract class L3ModificationInstruction implements Instruction { ...@@ -102,6 +117,43 @@ public abstract class L3ModificationInstruction implements Instruction {
102 } 117 }
103 return false; 118 return false;
104 } 119 }
120 + }
121 +
122 + public static final class ModTtlInstruction extends L3ModificationInstruction {
123 +
124 + private final L3SubType subtype;
125 +
126 + public ModTtlInstruction(L3SubType subtype) {
127 + this.subtype = subtype;
128 + }
129 +
130 + @Override
131 + public L3SubType subtype() {
132 + return this.subtype;
133 + }
105 134
135 + @Override
136 + public String toString() {
137 + return subtype().toString();
138 + }
139 +
140 + @Override
141 + public int hashCode() {
142 + return Objects.hash(type(), subtype());
143 + }
144 +
145 + @Override
146 + public boolean equals(Object obj) {
147 + if (this == obj) {
148 + return true;
149 + }
150 + if (obj instanceof ModIPInstruction) {
151 + ModIPInstruction that = (ModIPInstruction) obj;
152 + return Objects.equals(this.type(), that.type()) &&
153 + Objects.equals(this.subtype(), that.subtype());
154 +
155 + }
156 + return false;
157 + }
106 } 158 }
107 } 159 }
......
...@@ -38,8 +38,14 @@ import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry; ...@@ -38,8 +38,14 @@ import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
38 import org.projectfloodlight.openflow.protocol.OFInstructionType; 38 import org.projectfloodlight.openflow.protocol.OFInstructionType;
39 import org.projectfloodlight.openflow.protocol.action.OFAction; 39 import org.projectfloodlight.openflow.protocol.action.OFAction;
40 import org.projectfloodlight.openflow.protocol.action.OFActionCircuit; 40 import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
41 +import org.projectfloodlight.openflow.protocol.action.OFActionCopyTtlIn;
42 +import org.projectfloodlight.openflow.protocol.action.OFActionCopyTtlOut;
43 +import org.projectfloodlight.openflow.protocol.action.OFActionDecMplsTtl;
44 +import org.projectfloodlight.openflow.protocol.action.OFActionDecNwTtl;
41 import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter; 45 import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
42 import org.projectfloodlight.openflow.protocol.action.OFActionOutput; 46 import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
47 +import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
48 +import org.projectfloodlight.openflow.protocol.action.OFActionPushMpls;
43 import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst; 49 import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
44 import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc; 50 import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
45 import org.projectfloodlight.openflow.protocol.action.OFActionSetField; 51 import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
...@@ -57,6 +63,7 @@ import org.projectfloodlight.openflow.types.IPv4Address; ...@@ -57,6 +63,7 @@ import org.projectfloodlight.openflow.types.IPv4Address;
57 import org.projectfloodlight.openflow.types.IPv6Address; 63 import org.projectfloodlight.openflow.types.IPv6Address;
58 import org.projectfloodlight.openflow.types.Masked; 64 import org.projectfloodlight.openflow.types.Masked;
59 import org.projectfloodlight.openflow.types.OFVlanVidMatch; 65 import org.projectfloodlight.openflow.types.OFVlanVidMatch;
66 +import org.projectfloodlight.openflow.types.U32;
60 import org.projectfloodlight.openflow.types.VlanPcp; 67 import org.projectfloodlight.openflow.types.VlanPcp;
61 import org.slf4j.Logger; 68 import org.slf4j.Logger;
62 69
...@@ -194,12 +201,34 @@ public class FlowEntryBuilder { ...@@ -194,12 +201,34 @@ public class FlowEntryBuilder {
194 OFActionSetField setField = (OFActionSetField) act; 201 OFActionSetField setField = (OFActionSetField) act;
195 handleSetField(builder, setField.getField()); 202 handleSetField(builder, setField.getField());
196 break; 203 break;
204 + case POP_MPLS:
205 + OFActionPopMpls popMpls = (OFActionPopMpls) act;
206 + builder.popMpls((short) popMpls.getEthertype().getValue());
207 + break;
208 + case PUSH_MPLS:
209 + OFActionPushMpls pushMpls = (OFActionPushMpls) act;
210 + builder.pushMpls();
211 + break;
212 + case COPY_TTL_IN:
213 + OFActionCopyTtlIn copyTtlIn = (OFActionCopyTtlIn) act;
214 + builder.copyTtlIn();
215 + break;
216 + case COPY_TTL_OUT:
217 + OFActionCopyTtlOut copyTtlOut = (OFActionCopyTtlOut) act;
218 + builder.copyTtlOut();
219 + break;
220 + case DEC_MPLS_TTL:
221 + OFActionDecMplsTtl decMplsTtl = (OFActionDecMplsTtl) act;
222 + builder.decMplsTtl();
223 + break;
224 + case DEC_NW_TTL:
225 + OFActionDecNwTtl decNwTtl = (OFActionDecNwTtl) act;
226 + builder.decNwTtl();
227 + break;
197 case SET_TP_DST: 228 case SET_TP_DST:
198 case SET_TP_SRC: 229 case SET_TP_SRC:
199 - case POP_MPLS:
200 case POP_PBB: 230 case POP_PBB:
201 case POP_VLAN: 231 case POP_VLAN:
202 - case PUSH_MPLS:
203 case PUSH_PBB: 232 case PUSH_PBB:
204 case PUSH_VLAN: 233 case PUSH_VLAN:
205 case SET_MPLS_LABEL: 234 case SET_MPLS_LABEL:
...@@ -210,10 +239,6 @@ public class FlowEntryBuilder { ...@@ -210,10 +239,6 @@ public class FlowEntryBuilder {
210 case SET_NW_TTL: 239 case SET_NW_TTL:
211 case SET_QUEUE: 240 case SET_QUEUE:
212 case STRIP_VLAN: 241 case STRIP_VLAN:
213 - case COPY_TTL_IN:
214 - case COPY_TTL_OUT:
215 - case DEC_MPLS_TTL:
216 - case DEC_NW_TTL:
217 case ENQUEUE: 242 case ENQUEUE:
218 243
219 case GROUP: 244 case GROUP:
...@@ -259,6 +284,11 @@ public class FlowEntryBuilder { ...@@ -259,6 +284,11 @@ public class FlowEntryBuilder {
259 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm; 284 OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
260 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt())); 285 builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
261 break; 286 break;
287 + case MPLS_LABEL:
288 + @SuppressWarnings("unchecked")
289 + OFOxm<U32> labelId = (OFOxm<U32>) oxm;
290 + builder.setMpls((int) labelId.getValue().getValue());
291 + break;
262 case ARP_OP: 292 case ARP_OP:
263 case ARP_SHA: 293 case ARP_SHA:
264 case ARP_SPA: 294 case ARP_SPA:
...@@ -299,7 +329,6 @@ public class FlowEntryBuilder { ...@@ -299,7 +329,6 @@ public class FlowEntryBuilder {
299 case IP_ECN: 329 case IP_ECN:
300 case IP_PROTO: 330 case IP_PROTO:
301 case METADATA: 331 case METADATA:
302 - case MPLS_LABEL:
303 case MPLS_TC: 332 case MPLS_TC:
304 case OCH_SIGID: 333 case OCH_SIGID:
305 case OCH_SIGID_BASIC: 334 case OCH_SIGID_BASIC:
......
...@@ -241,8 +241,9 @@ public class FlowModBuilderVer13 extends FlowModBuilder { ...@@ -241,8 +241,9 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
241 (ModMplsLabelInstruction) l2m; 241 (ModMplsLabelInstruction) l2m;
242 oxm = factory().oxms().mplsLabel(U32.of(mplsLabel.label() 242 oxm = factory().oxms().mplsLabel(U32.of(mplsLabel.label()
243 .longValue())); 243 .longValue()));
244 -
245 break; 244 break;
245 + case DEC_MPLS_TTL:
246 + return factory().actions().decMplsTtl();
246 default: 247 default:
247 log.warn("Unimplemented action type {}.", l2m.subtype()); 248 log.warn("Unimplemented action type {}.", l2m.subtype());
248 break; 249 break;
...@@ -270,6 +271,12 @@ public class FlowModBuilderVer13 extends FlowModBuilder { ...@@ -270,6 +271,12 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
270 ip4 = ip.ip().getIp4Address(); 271 ip4 = ip.ip().getIp4Address();
271 oxm = factory().oxms().ipv4Src(IPv4Address.of(ip4.toInt())); 272 oxm = factory().oxms().ipv4Src(IPv4Address.of(ip4.toInt()));
272 break; 273 break;
274 + case DEC_TTL:
275 + return factory().actions().decNwTtl();
276 + case TTL_IN:
277 + return factory().actions().copyTtlIn();
278 + case TTL_OUT:
279 + return factory().actions().copyTtlOut();
273 default: 280 default:
274 log.warn("Unimplemented action type {}.", l3m.subtype()); 281 log.warn("Unimplemented action type {}.", l3m.subtype());
275 break; 282 break;
......