2 * Copyright (C) 2014 Red Hat, Inc.
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
8 * Authors : Madhu Venugopal, Dave Tucker
10 package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services;
12 import java.math.BigInteger;
13 import java.net.InetAddress;
14 import java.util.List;
16 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
17 import org.opendaylight.ovsdb.openstack.netvirt.api.ArpProvider;
18 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
19 import org.opendaylight.ovsdb.openstack.netvirt.api.RoutingProvider;
20 import org.opendaylight.ovsdb.openstack.netvirt.api.Status;
21 import org.opendaylight.ovsdb.openstack.netvirt.api.StatusCode;
22 import org.opendaylight.ovsdb.openstack.netvirt.providers.ConfigInterface;
23 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
24 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.OF13Provider;
25 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
26 import org.opendaylight.ovsdb.utils.mdsal.openflow.ActionUtils;
27 import org.opendaylight.ovsdb.utils.mdsal.openflow.MatchUtils;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
43 //import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
47 import com.google.common.collect.Lists;
48 import org.osgi.framework.BundleContext;
49 import org.osgi.framework.ServiceReference;
51 public class ArpResponderService extends AbstractServiceInstance implements ArpProvider, ConfigInterface {
52 public ArpResponderService() {
53 super(Service.ARP_RESPONDER);
56 public ArpResponderService(Service service) {
61 public Status programStaticArpEntry(Long dpid, String segmentationId, String macAddressStr,
62 InetAddress ipAddress, Action action) {
64 String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpid;
65 MacAddress macAddress = new MacAddress(macAddressStr);
67 MatchBuilder matchBuilder = new MatchBuilder();
68 NodeBuilder nodeBuilder = OF13Provider.createNodeBuilder(nodeName);
70 // Instructions List Stores Individual Instructions
71 InstructionsBuilder isb = new InstructionsBuilder();
72 List<Instruction> instructions = Lists.newArrayList();
73 InstructionBuilder ib = new InstructionBuilder();
74 ApplyActionsBuilder aab = new ApplyActionsBuilder();
75 ActionBuilder ab = new ActionBuilder();
76 List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionList = Lists.newArrayList();
78 MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId));
79 MatchUtils.createEtherTypeMatch(matchBuilder, new EtherType(Constants.ARP_ETHERTYPE));
80 MatchUtils.createArpDstIpv4Match(matchBuilder, MatchUtils.iPv4PrefixFromIPv4Address(ipAddress.getHostAddress()));
82 // Move Eth Src to Eth Dst
83 ab.setAction(ActionUtils.nxMoveEthSrcToEthDstAction());
85 ab.setKey(new ActionKey(0));
86 actionList.add(ab.build());
89 ab.setAction(ActionUtils.setDlSrcAction(new MacAddress(macAddress)));
91 ab.setKey(new ActionKey(1));
92 actionList.add(ab.build());
95 ab.setAction(ActionUtils.nxLoadArpOpAction(BigInteger.valueOf(0x02L)));
97 ab.setKey(new ActionKey(2));
98 actionList.add(ab.build());
100 // Move ARP SHA to ARP THA
101 ab.setAction(ActionUtils.nxMoveArpShaToArpThaAction());
103 ab.setKey(new ActionKey(3));
104 actionList.add(ab.build());
106 // Move ARP SPA to ARP TPA
107 ab.setAction(ActionUtils.nxMoveArpSpaToArpTpaAction());
109 ab.setKey(new ActionKey(4));
110 actionList.add(ab.build());
112 // Load Mac to ARP SHA
113 ab.setAction(ActionUtils.nxLoadArpShaAction(macAddress));
115 ab.setKey(new ActionKey(5));
116 actionList.add(ab.build());
118 // Load IP to ARP SPA
119 ab.setAction(ActionUtils.nxLoadArpSpaAction(ipAddress.getHostAddress()));
121 ab.setKey(new ActionKey(6));
122 actionList.add(ab.build());
125 ab.setAction(ActionUtils.outputAction(new NodeConnectorId(nodeName + ":INPORT")));
127 ab.setKey(new ActionKey(7));
128 actionList.add(ab.build());
130 // Create Apply Actions Instruction
131 aab.setAction(actionList);
132 ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
134 ib.setKey(new InstructionKey(0));
135 instructions.add(ib.build());
137 FlowBuilder flowBuilder = new FlowBuilder();
138 flowBuilder.setMatch(matchBuilder.build());
139 flowBuilder.setInstructions(isb.setInstruction(instructions).build());
141 String flowId = "ArpResponder_" + segmentationId + "_" + ipAddress.getHostAddress();
142 flowBuilder.setId(new FlowId(flowId));
143 FlowKey key = new FlowKey(new FlowId(flowId));
144 flowBuilder.setBarrier(true);
145 flowBuilder.setTableId(this.getTable());
146 flowBuilder.setKey(key);
147 flowBuilder.setPriority(1024);
148 flowBuilder.setFlowName(flowId);
149 flowBuilder.setHardTimeout(0);
150 flowBuilder.setIdleTimeout(0);
152 if (action.equals(Action.ADD)) {
153 writeFlow(flowBuilder, nodeBuilder);
155 removeFlow(flowBuilder, nodeBuilder);
158 // ToDo: WriteFlow/RemoveFlow should return something we can use to check success
159 return new Status(StatusCode.SUCCESS);
163 public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
164 super.setOrchestrator(bundleContext.getServiceReference(ArpProvider.class.getName()), this);
168 public void setDependencies(Object impl) {}