2 * Copyright © 2015 Red Hat, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.ovsdb.openstack.netvirt.sfc.workaround.services;
11 import com.google.common.collect.Lists;
12 import java.math.BigInteger;
13 import java.util.ArrayList;
14 import java.util.List;
15 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
16 import org.opendaylight.ovsdb.openstack.netvirt.providers.ConfigInterface;
17 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
18 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
19 import org.opendaylight.ovsdb.openstack.netvirt.sfc.ISfcClassifierService;
20 import org.opendaylight.ovsdb.openstack.netvirt.sfc.NshUtils;
21 import org.opendaylight.ovsdb.utils.mdsal.openflow.ActionUtils;
22 import org.opendaylight.ovsdb.utils.mdsal.openflow.FlowUtils;
23 import org.opendaylight.ovsdb.utils.mdsal.openflow.InstructionUtils;
24 import org.opendaylight.ovsdb.utils.mdsal.openflow.MatchUtils;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.acl.access.list.entries.ace.Matches;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.acl.access.list.entries.ace.matches.ace.type.AceEth;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIp;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv4;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxRegCaseBuilder;
49 import org.osgi.framework.BundleContext;
50 import org.osgi.framework.ServiceReference;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
54 public class SfcClassifierService extends AbstractServiceInstance implements ConfigInterface, ISfcClassifierService {
55 private static final Logger LOG = LoggerFactory.getLogger(SfcClassifierService.class);
56 private static final short TABLE_0 = 0;
57 private static final short UDP_SHORT = 17;
58 static int cookieIndex = 0;
61 FLOW_INGRESSCLASS(1), FLOW_SFINGRESS(2), FLOW_SFEGRESS(3), FLOW_SFARP(4),
62 FLOW_EGRESSCLASSUNUSED(5), FLOW_EGRESSCLASS(6), FLOW_EGRESSCLASSBYPASS(7), FLOW_SFCTABLE(8);
71 private BigInteger getCookie(FlowID flowID) {
72 String cookieString = String.format("1110%02d%010d", flowID.value, cookieIndex++);
73 return new BigInteger(cookieString, 16);
76 public SfcClassifierService(Service service) {
80 public SfcClassifierService() {
81 super(Service.SFC_CLASSIFIER);
85 public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
86 super.setDependencies(bundleContext.getServiceReference(ISfcClassifierService.class.getName()), this);
90 public void setDependencies(Object impl) {}
93 public void programIngressClassifier(long dataPathId, String ruleName, Matches matches,
94 NshUtils nshHeader, long vxGpeOfPort, boolean write) {
95 NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dataPathId);
96 FlowBuilder flowBuilder = new FlowBuilder();
98 MatchBuilder matchBuilder = buildMatch(matches);
99 MatchUtils.addNxRegMatch(matchBuilder,
100 MatchUtils.RegMatch.of(FlowUtils.REG_FIELD, FlowUtils.REG_VALUE_FROM_LOCAL));
101 MatchUtils.addNxRegMatch(matchBuilder,
102 MatchUtils.RegMatch.of(FlowUtils.REG_FIELD, FlowUtils.REG_VALUE_FROM_LOCAL));
103 flowBuilder.setMatch(matchBuilder.build());
105 String flowId = "sfcIngressClass_" + ruleName;// + "_" + nshHeader.getNshNsp();
106 flowBuilder.setId(new FlowId(flowId));
107 FlowKey key = new FlowKey(new FlowId(flowId));
108 flowBuilder.setBarrier(true);
109 flowBuilder.setTableId(getTable());
110 flowBuilder.setKey(key);
111 flowBuilder.setFlowName(flowId);
112 flowBuilder.setHardTimeout(0);
113 flowBuilder.setIdleTimeout(0);
114 flowBuilder.setCookie(new FlowCookie(getCookie(FlowID.FLOW_INGRESSCLASS)));
117 ActionBuilder ab = new ActionBuilder();
118 List<Action> actionList = new ArrayList<>();
120 ab.setAction(ActionUtils.nxMoveTunIdtoNshc2());
121 ab.setOrder(actionList.size());
122 ab.setKey(new ActionKey(actionList.size()));
123 actionList.add(ab.build());
125 getNshAction(nshHeader, actionList);
127 ab.setAction(ActionUtils.outputAction(FlowUtils.getNodeConnectorId(dataPathId, vxGpeOfPort)));
128 ab.setOrder(actionList.size());
129 ab.setKey(new ActionKey(actionList.size()));
130 actionList.add(ab.build());
132 ApplyActionsBuilder aab = new ApplyActionsBuilder();
133 aab.setAction(actionList);
135 InstructionBuilder ib = new InstructionBuilder();
136 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
138 ib.setKey(new InstructionKey(0));
139 List<Instruction> instructions = Lists.newArrayList();
140 instructions.add(ib.build());
142 InstructionsBuilder isb = new InstructionsBuilder();
143 isb.setInstruction(instructions);
144 flowBuilder.setInstructions(isb.build());
145 writeFlow(flowBuilder, nodeBuilder);
147 removeFlow(flowBuilder, nodeBuilder);
152 public void programSfcTable(long dataPathId, long vxGpeOfPort, short goToTableId, boolean write) {
153 NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dataPathId);
154 FlowBuilder flowBuilder = new FlowBuilder();
156 MatchBuilder matchBuilder = new MatchBuilder();
157 MatchUtils.createInPortMatch(matchBuilder, dataPathId, vxGpeOfPort);
158 flowBuilder.setMatch(matchBuilder.build());
160 String flowId = "sfcTable_" + vxGpeOfPort;
161 flowBuilder.setId(new FlowId(flowId));
162 FlowKey key = new FlowKey(new FlowId(flowId));
163 flowBuilder.setBarrier(true);
164 flowBuilder.setTableId(TABLE_0);
165 flowBuilder.setKey(key);
166 flowBuilder.setFlowName(flowId);
167 flowBuilder.setHardTimeout(0);
168 flowBuilder.setIdleTimeout(0);
169 flowBuilder.setPriority(1000);
170 flowBuilder.setCookie(new FlowCookie(getCookie(FlowID.FLOW_SFCTABLE)));
171 flowBuilder.setCookieMask(new FlowCookie(getCookie(FlowID.FLOW_SFCTABLE)));
174 InstructionsBuilder isb = new InstructionsBuilder();
175 List<Instruction> instructions = Lists.newArrayList();
176 InstructionBuilder ib =
177 InstructionUtils.createGotoTableInstructions(new InstructionBuilder(), goToTableId);
179 ib.setKey(new InstructionKey(0));
180 instructions.add(ib.build());
182 isb.setInstruction(instructions);
183 flowBuilder.setInstructions(isb.build());
184 writeFlow(flowBuilder, nodeBuilder);
186 removeFlow(flowBuilder, nodeBuilder);
191 public void programEgressClassifier1(long dataPathId, long vxGpeOfPort, long nsp, short nsi,
192 int tunnelOfPort, int tunnelId, short gotoTableId, boolean write) {
193 NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dataPathId);
194 FlowBuilder flowBuilder = new FlowBuilder();
196 MatchBuilder matchBuilder = new MatchBuilder();
197 MatchUtils.createInPortMatch(matchBuilder, dataPathId, vxGpeOfPort);
198 MatchUtils.addNxNspMatch(matchBuilder, nsp);
199 MatchUtils.addNxNsiMatch(matchBuilder, nsi);
200 flowBuilder.setMatch(matchBuilder.build());
202 String flowId = "sfcEgressClass1_" + vxGpeOfPort;
203 flowBuilder.setId(new FlowId(flowId));
204 FlowKey key = new FlowKey(new FlowId(flowId));
205 flowBuilder.setBarrier(true);
206 flowBuilder.setTableId(TABLE_0);
207 flowBuilder.setKey(key);
208 flowBuilder.setFlowName(flowId);
209 flowBuilder.setHardTimeout(0);
210 flowBuilder.setIdleTimeout(0);
211 flowBuilder.setCookie(new FlowCookie(getCookie(FlowID.FLOW_EGRESSCLASSUNUSED)));
212 flowBuilder.setCookieMask(new FlowCookie(getCookie(FlowID.FLOW_EGRESSCLASSUNUSED)));
215 InstructionsBuilder isb = new InstructionsBuilder();
216 List<Instruction> instructions = Lists.newArrayList();
217 InstructionBuilder ib = new InstructionBuilder();
219 /*List<Action> actionList = Lists.newArrayList();
221 ActionBuilder ab = new ActionBuilder();
222 ab.setAction(ActionUtils.nxMoveNshc2ToTunId());
224 ab.setKey(new ActionKey(0));
225 actionList.add(ab.build());
227 ApplyActionsBuilder aab = new ApplyActionsBuilder();
228 aab.setAction(actionList);
229 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
231 ib.setOrder(instructions.size());
232 ib.setKey(new InstructionKey(instructions.size()));
233 instructions.add(ib.build());*/
235 ib = InstructionUtils.createGotoTableInstructions(new InstructionBuilder(), getTable());
236 ib.setOrder(instructions.size());
237 ib.setKey(new InstructionKey(instructions.size()));
238 instructions.add(ib.build());
240 isb.setInstruction(instructions);
241 flowBuilder.setInstructions(isb.build());
242 writeFlow(flowBuilder, nodeBuilder);
244 removeFlow(flowBuilder, nodeBuilder);
249 public void programEgressClassifier(long dataPathId, long vxGpeOfPort, long nsp, short nsi,
250 long sfOfPort, int tunnelId, boolean write) {
251 NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dataPathId);
252 FlowBuilder flowBuilder = new FlowBuilder();
254 MatchBuilder matchBuilder = new MatchBuilder();
255 MatchUtils.createInPortMatch(matchBuilder, dataPathId, vxGpeOfPort);
256 MatchUtils.addNxNspMatch(matchBuilder, nsp);
257 MatchUtils.addNxNsiMatch(matchBuilder, nsi);
258 flowBuilder.setMatch(matchBuilder.build());
260 String flowId = "sfcEgressClass_" + nsp + "_" + + nsi + "_" + vxGpeOfPort;
261 flowBuilder.setId(new FlowId(flowId));
262 FlowKey key = new FlowKey(new FlowId(flowId));
263 flowBuilder.setBarrier(true);
264 flowBuilder.setTableId(TABLE_0);
265 flowBuilder.setKey(key);
266 flowBuilder.setFlowName(flowId);
267 flowBuilder.setHardTimeout(0);
268 flowBuilder.setIdleTimeout(0);
269 flowBuilder.setCookie(new FlowCookie(getCookie(FlowID.FLOW_EGRESSCLASS)));
270 flowBuilder.setCookieMask(new FlowCookie(getCookie(FlowID.FLOW_EGRESSCLASS)));
273 InstructionsBuilder isb = new InstructionsBuilder();
274 List<Instruction> instructions = Lists.newArrayList();
275 List<Action> actionList = Lists.newArrayList();
277 ActionBuilder ab = new ActionBuilder();
280 ActionUtils.nxLoadRegAction(new DstNxRegCaseBuilder().setNxReg(FlowUtils.REG_FIELD).build(),
281 BigInteger.valueOf(FlowUtils.REG_VALUE_FROM_LOCAL)));
282 ab.setOrder(actionList.size());
283 ab.setKey(new ActionKey(actionList.size()));
284 actionList.add(ab.build());
286 ab.setAction(ActionUtils.nxMoveNshc2ToTunId());
287 ab.setOrder(actionList.size());
288 ab.setKey(new ActionKey(actionList.size()));
289 actionList.add(ab.build());
291 ab.setAction(ActionUtils.nxResubmitAction((int)sfOfPort, TABLE_0));
292 ab.setOrder(actionList.size());
293 ab.setKey(new ActionKey(actionList.size()));
294 actionList.add(ab.build());
296 ApplyActionsBuilder aab = new ApplyActionsBuilder();
297 aab.setAction(actionList);
298 InstructionBuilder ib = new InstructionBuilder();
299 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
302 ib.setKey(new InstructionKey(0));
303 instructions.add(ib.build());
305 isb.setInstruction(instructions);
306 flowBuilder.setInstructions(isb.build());
307 writeFlow(flowBuilder, nodeBuilder);
309 removeFlow(flowBuilder, nodeBuilder);
314 public void programEgressClassifierBypass(long dataPathId, long vxGpeOfPort, long nsp, short nsi,
315 long sfOfPort, int tunnelId, boolean write) {
316 NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dataPathId);
317 FlowBuilder flowBuilder = new FlowBuilder();
319 MatchBuilder matchBuilder = new MatchBuilder();
320 MatchUtils.createInPortMatch(matchBuilder, dataPathId, sfOfPort);
321 MatchUtils.addNxRegMatch(matchBuilder,
322 MatchUtils.RegMatch.of(FlowUtils.REG_FIELD, FlowUtils.REG_VALUE_FROM_LOCAL));
323 MatchUtils.addNxNspMatch(matchBuilder, nsp);
324 MatchUtils.addNxNsiMatch(matchBuilder, nsi);
325 flowBuilder.setMatch(matchBuilder.build());
327 String flowId = "sfcEgressClassBypass_" + nsp + "_" + + nsi + "_" + sfOfPort;
328 flowBuilder.setId(new FlowId(flowId));
329 FlowKey key = new FlowKey(new FlowId(flowId));
330 flowBuilder.setBarrier(true);
331 flowBuilder.setTableId(TABLE_0);
332 flowBuilder.setKey(key);
333 flowBuilder.setFlowName(flowId);
334 flowBuilder.setHardTimeout(0);
335 flowBuilder.setIdleTimeout(0);
336 flowBuilder.setCookie(new FlowCookie(getCookie(FlowID.FLOW_EGRESSCLASSBYPASS)));
337 flowBuilder.setCookieMask(new FlowCookie(getCookie(FlowID.FLOW_EGRESSCLASSBYPASS)));
338 flowBuilder.setPriority(40000); //Needs to be above default priority of 32768
341 InstructionsBuilder isb = new InstructionsBuilder();
342 List<Instruction> instructions = Lists.newArrayList();
344 InstructionBuilder ib;
345 ib = this.getMutablePipelineInstructionBuilder();
347 ib.setKey(new InstructionKey(0));
348 instructions.add(ib.build());
350 isb.setInstruction(instructions);
351 flowBuilder.setInstructions(isb.build());
352 writeFlow(flowBuilder, nodeBuilder);
354 removeFlow(flowBuilder, nodeBuilder);
358 // packet from sf to sff that need to go out local
360 public void program_sfEgress(long dataPathId, int dstPort, boolean write) {
361 NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dataPathId);
362 FlowBuilder flowBuilder = new FlowBuilder();
364 MatchBuilder matchBuilder = new MatchBuilder();
365 MatchUtils.createIpProtocolMatch(matchBuilder, UDP_SHORT);
366 MatchUtils.addLayer4Match(matchBuilder, UDP_SHORT, 0, dstPort);
367 MatchUtils.addNxRegMatch(matchBuilder,
368 MatchUtils.RegMatch.of(FlowUtils.REG_FIELD, FlowUtils.REG_VALUE_FROM_LOCAL));
369 flowBuilder.setMatch(matchBuilder.build());
371 String flowId = "sfEgress_" + dstPort;
372 flowBuilder.setId(new FlowId(flowId));
373 FlowKey key = new FlowKey(new FlowId(flowId));
374 flowBuilder.setBarrier(true);
375 flowBuilder.setTableId(getTable());
376 flowBuilder.setKey(key);
377 flowBuilder.setFlowName(flowId);
378 flowBuilder.setHardTimeout(0);
379 flowBuilder.setIdleTimeout(0);
380 flowBuilder.setCookie(new FlowCookie(getCookie(FlowID.FLOW_SFEGRESS)));
381 flowBuilder.setCookieMask(new FlowCookie(getCookie(FlowID.FLOW_SFEGRESS)));
384 InstructionBuilder ib = new InstructionBuilder();
385 InstructionsBuilder isb = new InstructionsBuilder();
386 List<Instruction> instructions = Lists.newArrayList();
387 InstructionUtils.createLocalInstructions(ib, dataPathId);
389 ib.setKey(new InstructionKey(0));
390 instructions.add(ib.build());
392 isb.setInstruction(instructions);
393 flowBuilder.setInstructions(isb.build());
394 writeFlow(flowBuilder, nodeBuilder);
396 removeFlow(flowBuilder, nodeBuilder);
400 // looped back sff to sf packets
402 public void program_sfIngress(long dataPathId, int dstPort, long sfOfPort,
403 String ipAddress, String sfDplName, boolean write) {
404 NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dataPathId);
405 FlowBuilder flowBuilder = new FlowBuilder();
407 MatchBuilder matchBuilder = new MatchBuilder();
408 MatchUtils.createIpProtocolMatch(matchBuilder, UDP_SHORT);
409 Ipv4Prefix ipCidr = MatchUtils.iPv4PrefixFromIPv4Address(ipAddress);
410 MatchUtils.createDstL3IPv4Match(matchBuilder, new Ipv4Prefix(ipCidr));
411 MatchUtils.addLayer4Match(matchBuilder, UDP_SHORT, 0, dstPort);
412 flowBuilder.setMatch(matchBuilder.build());
414 String flowId = "sfIngress_" + dstPort + "_" + ipAddress;
415 flowBuilder.setId(new FlowId(flowId));
416 FlowKey key = new FlowKey(new FlowId(flowId));
417 flowBuilder.setBarrier(true);
418 flowBuilder.setTableId(TABLE_0);
419 flowBuilder.setKey(key);
420 flowBuilder.setFlowName(flowId);
421 flowBuilder.setHardTimeout(0);
422 flowBuilder.setIdleTimeout(0);
423 flowBuilder.setCookie(new FlowCookie(getCookie(FlowID.FLOW_SFINGRESS)));
424 flowBuilder.setCookieMask(new FlowCookie(getCookie(FlowID.FLOW_SFINGRESS)));
427 InstructionBuilder ib = new InstructionBuilder();
428 InstructionsBuilder isb = new InstructionsBuilder();
429 List<Instruction> instructions = Lists.newArrayList();
430 InstructionUtils.createOutputPortInstructions(ib, dataPathId, sfOfPort);
433 ib.setKey(new InstructionKey(0));
434 instructions.add(ib.build());
436 isb.setInstruction(instructions);
437 flowBuilder.setInstructions(isb.build());
438 writeFlow(flowBuilder, nodeBuilder);
440 removeFlow(flowBuilder, nodeBuilder);
445 public void programStaticArpEntry(long dataPathId, long ofPort, String macAddressStr,
446 String ipAddress, boolean write) {
447 NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dataPathId);
448 FlowBuilder flowBuilder = new FlowBuilder();
450 MacAddress macAddress = new MacAddress(macAddressStr);
452 MatchBuilder matchBuilder = new MatchBuilder();
453 MatchUtils.createInPortReservedMatch(matchBuilder, dataPathId, OutputPortValues.LOCAL.toString());
454 MatchUtils.createEtherTypeMatch(matchBuilder, new EtherType(Constants.ARP_ETHERTYPE));
455 MatchUtils.createArpDstIpv4Match(matchBuilder, MatchUtils.iPv4PrefixFromIPv4Address(ipAddress));
456 flowBuilder.setMatch(matchBuilder.build());
458 String flowId = "ArpResponder_" + ipAddress;
459 flowBuilder.setId(new FlowId(flowId));
460 FlowKey key = new FlowKey(new FlowId(flowId));
461 flowBuilder.setBarrier(true);
462 flowBuilder.setTableId(TABLE_0);
463 flowBuilder.setKey(key);
464 flowBuilder.setPriority(1024);
465 flowBuilder.setFlowName(flowId);
466 flowBuilder.setHardTimeout(0);
467 flowBuilder.setIdleTimeout(0);
468 flowBuilder.setCookie(new FlowCookie(getCookie(FlowID.FLOW_SFARP)));
469 flowBuilder.setCookieMask(new FlowCookie(getCookie(FlowID.FLOW_SFARP)));
472 InstructionBuilder ib = new InstructionBuilder();
473 InstructionsBuilder isb = new InstructionsBuilder();
474 List<Instruction> instructions = Lists.newArrayList();
475 ApplyActionsBuilder aab = new ApplyActionsBuilder();
476 ActionBuilder ab = new ActionBuilder();
477 List<Action> actionList = Lists.newArrayList();
479 // Move Eth Src to Eth Dst
480 ab.setAction(ActionUtils.nxMoveEthSrcToEthDstAction());
482 ab.setKey(new ActionKey(0));
483 actionList.add(ab.build());
486 ab.setAction(ActionUtils.setDlSrcAction(new MacAddress(macAddress)));
488 ab.setKey(new ActionKey(1));
489 actionList.add(ab.build());
492 ab.setAction(ActionUtils.nxLoadArpOpAction(BigInteger.valueOf(FlowUtils.ARP_OP_REPLY)));
494 ab.setKey(new ActionKey(2));
495 actionList.add(ab.build());
497 // Move ARP SHA to ARP THA
498 ab.setAction(ActionUtils.nxMoveArpShaToArpThaAction());
500 ab.setKey(new ActionKey(3));
501 actionList.add(ab.build());
503 // Move ARP SPA to ARP TPA
504 ab.setAction(ActionUtils.nxMoveArpSpaToArpTpaAction());
506 ab.setKey(new ActionKey(4));
507 actionList.add(ab.build());
509 // Load Mac to ARP SHA
510 ab.setAction(ActionUtils.nxLoadArpShaAction(macAddress));
512 ab.setKey(new ActionKey(5));
513 actionList.add(ab.build());
515 // Load IP to ARP SPA
516 ab.setAction(ActionUtils.nxLoadArpSpaAction(ipAddress));
518 ab.setKey(new ActionKey(6));
519 actionList.add(ab.build());
522 ab.setAction(ActionUtils.outputAction(
523 FlowUtils.getSpecialNodeConnectorId(dataPathId, OutputPortValues.INPORT.toString())));
525 ab.setKey(new ActionKey(7));
526 actionList.add(ab.build());
528 // Create Apply Actions Instruction
529 aab.setAction(actionList);
530 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
532 ib.setKey(new InstructionKey(0));
533 instructions.add(ib.build());
535 isb.setInstruction(instructions);
536 flowBuilder.setInstructions(isb.build());
537 writeFlow(flowBuilder, nodeBuilder);
539 removeFlow(flowBuilder, nodeBuilder);
543 private List<Action> getNshAction(NshUtils header, List<Action> actionList) {
544 // Build the Actions to Add the NSH Header
545 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action nshC1Load =
546 ActionUtils.nxLoadNshc1RegAction(header.getNshMetaC1());
547 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action nshC2Load =
548 ActionUtils.nxLoadNshc2RegAction(header.getNshMetaC2());
549 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action nspLoad =
550 ActionUtils.nxSetNspAction(header.getNshNsp());
551 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action nsiLoad =
552 ActionUtils.nxSetNsiAction(header.getNshNsi());
553 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadChainTunVnid =
554 ActionUtils.nxLoadTunIdAction(BigInteger.valueOf(header.getNshNsp()), false);
555 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action loadChainTunDest =
556 ActionUtils.nxLoadTunIPv4Action(header.getNshTunIpDst().getValue(), false);
558 int count = actionList.size();
559 actionList.add(new ActionBuilder()
560 .setKey(new ActionKey(count)).setOrder(count++).setAction(nshC1Load).build());
561 //actionList.add(new ActionBuilder()
562 // .setKey(new ActionKey(count)).setOrder(count++).setAction(nshC2Load).build());
563 actionList.add(new ActionBuilder()
564 .setKey(new ActionKey(count)).setOrder(count++).setAction(nspLoad).build());
565 actionList.add(new ActionBuilder()
566 .setKey(new ActionKey(count)).setOrder(count++).setAction(nsiLoad).build());
567 actionList.add(new ActionBuilder()
568 .setKey(new ActionKey(count)).setOrder(count++).setAction(loadChainTunDest).build());
569 actionList.add(new ActionBuilder()
570 .setKey(new ActionKey(count)).setOrder(count).setAction(loadChainTunVnid).build());
574 public MatchBuilder buildMatch(Matches matches) {
575 MatchBuilder matchBuilder = new MatchBuilder();
577 if (matches.getAceType() instanceof AceIp) {
578 AceIp aceIp = (AceIp)matches.getAceType();
579 if (aceIp.getAceIpVersion() instanceof AceIpv4) {
580 //AceIpv4 aceIpv4 = (AceIpv4) aceIp.getAceIpVersion();
581 //MatchUtils.createSrcL3IPv4Match(matchBuilder, aceIpv4.getSourceIpv4Network());
582 //MatchUtils.createDstL3IPv4Match(matchBuilder, aceIpv4.getDestinationIpv4Network());
583 MatchUtils.createIpProtocolMatch(matchBuilder, aceIp.getProtocol());
584 MatchUtils.addLayer4Match(matchBuilder, aceIp.getProtocol().intValue(), 0,
585 aceIp.getDestinationPortRange().getLowerPort().getValue());
587 MatchUtils.createIpProtocolMatch(matchBuilder, aceIp.getProtocol());
588 MatchUtils.addLayer4Match(matchBuilder, aceIp.getProtocol().intValue(), 0,
589 aceIp.getDestinationPortRange().getLowerPort().getValue());
591 } else if (matches.getAceType() instanceof AceEth) {
592 AceEth aceEth = (AceEth) matches.getAceType();
593 MatchUtils.createEthSrcMatch(matchBuilder, new MacAddress(aceEth.getSourceMacAddress().getValue()));
594 MatchUtils.createDestEthMatch(matchBuilder, new MacAddress(aceEth.getDestinationMacAddress().getValue()),
595 new MacAddress(aceEth.getDestinationMacAddressMask().getValue()));
598 LOG.info("buildMatch: {}", matchBuilder.build());