2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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
8 package org.opendaylight.vpnservice.mdsalutil;
10 import java.math.BigInteger;
11 import java.net.InetAddress;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCaseBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.pbb.action._case.PopPbbActionBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.add.group.input.buckets.bucket.action.action.NxActionResubmitRpcAddGroupCaseBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.resubmit.grouping.NxResubmitBuilder;
57 public enum ActionType {
60 public Action buildAction(ActionInfo actionInfo) {
61 long groupId = Long.parseLong(actionInfo.getActionValues()[0]);
63 return new ActionBuilder().setAction(
64 new GroupActionCaseBuilder().setGroupAction(
65 new GroupActionBuilder().setGroupId(groupId).build()).build())
66 .setKey(new ActionKey(actionInfo.getActionKey())).build();
72 public Action buildAction(ActionInfo actionInfo) {
73 String[] actionValues = actionInfo.getActionValues();
74 String port = actionValues[0];
77 if (actionValues.length == 2) {
78 maxLength = Integer.valueOf(actionValues[1]);
81 return new ActionBuilder().setAction(
82 new OutputActionCaseBuilder().setOutputAction(
83 new OutputActionBuilder().setMaxLength(Integer.valueOf(maxLength))
84 .setOutputNodeConnector(new Uri(port)).build()).build())
85 .setKey(new ActionKey(actionInfo.getActionKey())).build();
91 public Action buildAction(ActionInfo actionInfo) {
92 return new ActionBuilder().setAction(
93 new PopMplsActionCaseBuilder().setPopMplsAction(
94 new PopMplsActionBuilder().setEthernetType(
95 Integer.valueOf(NwConstants.ETHTYPE_IPV4)).build()).build())
97 .setKey(new ActionKey(actionInfo.getActionKey())).build();
103 public Action buildAction(ActionInfo actionInfo) {
104 return new ActionBuilder()
105 .setAction(new PopPbbActionCaseBuilder().setPopPbbAction(new PopPbbActionBuilder().build()).build())
106 .setKey(new ActionKey(actionInfo.getActionKey())).build();
112 public Action buildAction(ActionInfo actionInfo) {
113 return new ActionBuilder().setAction(
114 new PopVlanActionCaseBuilder().setPopVlanAction(new PopVlanActionBuilder().build()).build())
115 .setKey(new ActionKey(actionInfo.getActionKey())).build();
121 public Action buildAction(ActionInfo actionInfo) {
122 return new ActionBuilder().setAction(new PushMplsActionCaseBuilder().setPushMplsAction(
123 new PushMplsActionBuilder().setEthernetType(
124 Integer.valueOf(NwConstants.ETHTYPE_MPLS_UC)).build()).build())
125 .setKey(new ActionKey(actionInfo.getActionKey())).build();
131 public Action buildAction(ActionInfo actionInfo) {
132 return new ActionBuilder().setAction(
133 new PushPbbActionCaseBuilder().setPushPbbAction(
134 new PushPbbActionBuilder()
135 .setEthernetType(Integer.valueOf(NwConstants.ETHTYPE_PBB)).build()).build())
136 .setKey(new ActionKey(actionInfo.getActionKey())).build();
142 public Action buildAction(ActionInfo actionInfo) {
143 return new ActionBuilder().setAction(
144 new PushVlanActionCaseBuilder().setPushVlanAction(
145 new PushVlanActionBuilder().setEthernetType(
146 Integer.valueOf(NwConstants.ETHTYPE_802_1Q)).build()).build())
147 .setKey(new ActionKey(actionInfo.getActionKey())).build();
151 set_field_mpls_label {
153 public Action buildAction(ActionInfo actionInfo) {
154 String[] actionValues = actionInfo.getActionValues();
155 long label = Long.valueOf(actionValues[0]);
157 return new ActionBuilder().setAction(
158 new SetFieldCaseBuilder().setSetField(new SetFieldBuilder().setProtocolMatchFields(
159 new ProtocolMatchFieldsBuilder().setMplsLabel(label).build()).build())
160 .build()).setKey(new ActionKey(actionInfo.getActionKey())).build();
166 public Action buildAction(ActionInfo actionInfo) {
167 String[] actionValues = actionInfo.getActionValues();
168 long label = Long.valueOf(actionValues[0]);
170 return new ActionBuilder().setAction(
171 new SetFieldCaseBuilder().setSetField(
172 new SetFieldBuilder().setProtocolMatchFields(
173 new ProtocolMatchFieldsBuilder().setPbb(
174 new PbbBuilder().setPbbIsid(label).build()).build()).build())
175 .build()).setKey(new ActionKey(actionInfo.getActionKey())).build();
181 public Action buildAction(ActionInfo actionInfo) {
182 String[] actionValues = actionInfo.getActionValues();
183 int vlanId = Integer.valueOf(actionValues[0]);
185 return new ActionBuilder().setAction(
186 new SetFieldCaseBuilder().setSetField(
187 new SetFieldBuilder().setVlanMatch(
188 new VlanMatchBuilder().setVlanId(
189 new VlanIdBuilder().setVlanId(new VlanId(vlanId))
190 .setVlanIdPresent(true).build()).build()).build()).build())
191 .setKey(new ActionKey(actionInfo.getActionKey())).build();
195 set_field_tunnel_id {
197 public Action buildAction(ActionInfo actionInfo) {
198 BigInteger [] actionValues = actionInfo.getBigActionValues();
199 if (actionValues.length == 2) {
200 return new ActionBuilder().setAction(
201 new SetFieldCaseBuilder().setSetField(
202 new SetFieldBuilder()
203 .setTunnel(new TunnelBuilder().setTunnelId(actionValues[0])
204 .setTunnelMask(actionValues[1]).build()).build())
206 .setKey(new ActionKey(actionInfo.getActionKey())).build();
208 return new ActionBuilder().setAction(
209 new SetFieldCaseBuilder().setSetField(
210 new SetFieldBuilder()
211 .setTunnel(new TunnelBuilder().setTunnelId(actionValues[0])
214 .setKey(new ActionKey(actionInfo.getActionKey())).build();
224 public Action buildAction(ActionInfo actionInfo) {
225 String[] actionValues = actionInfo.getActionValues();
226 MacAddress mac = new MacAddress(actionValues[0]);
228 return new ActionBuilder().setAction(
229 new SetFieldCaseBuilder().setSetField(
230 new SetFieldBuilder().setEthernetMatch(
231 new EthernetMatchBuilder().setEthernetDestination(
232 new EthernetDestinationBuilder().setAddress(mac).build()).build())
233 .build()).build()).setKey(new ActionKey(actionInfo.getActionKey())).build();
242 public Action buildAction(ActionInfo actionInfo) {
243 return new ActionBuilder().setAction(
244 new SetFieldCaseBuilder().setSetField(
245 new SetFieldBuilder().setIpMatch(
246 new IpMatchBuilder().setIpProtocol((short) 17).build()).
247 build()).build()).setKey(new ActionKey(actionInfo.getActionKey())).build();
254 public Action buildAction(ActionInfo actionInfo) {
255 ActionBuilder ab = new ActionBuilder();
256 OutputActionBuilder output = new OutputActionBuilder();
257 output.setMaxLength(0xffff);
258 Uri value = new Uri(OutputPortValues.CONTROLLER.toString());
259 output.setOutputNodeConnector(value);
260 ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
261 ab.setKey(new ActionKey(actionInfo.getActionKey()));
266 set_destination_port_field {
269 public Action buildAction(ActionInfo actionInfo) {
270 String[] actionValues = actionInfo.getActionValues();
271 Integer portNumber = new Integer(actionValues[0]);
273 return new ActionBuilder().setAction(
274 new SetFieldCaseBuilder().setSetField(
275 new SetFieldBuilder().setLayer4Match(
276 new UdpMatchBuilder().setUdpDestinationPort(
277 new PortNumber(portNumber)).build())
278 .build()).build()).setKey(new ActionKey(actionInfo.getActionKey())).build();
283 set_source_port_field {
286 public Action buildAction(ActionInfo actionInfo) {
287 String[] actionValues = actionInfo.getActionValues();
288 Integer portNumber = new Integer(actionValues[0]);
290 return new ActionBuilder().setAction(
291 new SetFieldCaseBuilder().setSetField(
292 new SetFieldBuilder().setLayer4Match(
293 new UdpMatchBuilder().setUdpSourcePort(
294 new PortNumber(portNumber)).build())
295 .build()).build()).setKey(new ActionKey(actionInfo.getActionKey())).build();
303 public Action buildAction(ActionInfo actionInfo) {
304 String[] actionValues = actionInfo.getActionValues();
305 InetAddress sourceIp = null;
307 sourceIp = InetAddress.getByName(actionValues[0]);
308 } catch (Exception e){
311 return new ActionBuilder().setAction(
312 new SetFieldCaseBuilder().setSetField(
313 new SetFieldBuilder().setLayer3Match(
314 new Ipv4MatchBuilder().setIpv4Source(
315 new Ipv4Prefix(sourceIp.getHostAddress())).build()).
316 build()).build()).setKey(new ActionKey(actionInfo.getActionKey())).build();
324 public Action buildAction(ActionInfo actionInfo) {
325 String[] actionValues = actionInfo.getActionValues();
326 InetAddress sourceIp = null;
328 sourceIp = InetAddress.getByName(actionValues[0]);
329 } catch (Exception e){
332 return new ActionBuilder().setAction(
333 new SetFieldCaseBuilder().setSetField(
334 new SetFieldBuilder().setLayer3Match(
335 new Ipv4MatchBuilder().setIpv4Destination(
336 new Ipv4Prefix(sourceIp.getHostAddress())).build()).
337 build()).build()).setKey(new ActionKey(actionInfo.getActionKey())).build();
345 public Action buildAction(ActionInfo actionInfo) {
346 String[] actionValues = actionInfo.getActionValues();
347 MacAddress mac = new MacAddress(actionValues[0]);
349 return new ActionBuilder().setAction(
350 new SetFieldCaseBuilder().setSetField(
351 new SetFieldBuilder().setEthernetMatch(
352 new EthernetMatchBuilder().setEthernetSource(
353 new EthernetSourceBuilder().setAddress(mac).build()).build())
354 .build()).build()).setKey(new ActionKey(actionInfo.getActionKey())).build();
362 public Action buildAction(ActionInfo actionInfo) {
363 DropActionBuilder dab = new DropActionBuilder();
364 DropAction dropAction = dab.build();
365 ActionBuilder ab = new ActionBuilder();
366 ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
367 ab.setKey(new ActionKey(actionInfo.getActionKey())).build();
375 public Action buildAction(ActionInfo actionInfo) {
376 String[] actionValues = actionInfo.getActionValues();
377 NxResubmitBuilder nxarsb = new NxResubmitBuilder();
378 nxarsb.setTable(Short.parseShort(actionValues[0]));
379 ActionBuilder ab = new ActionBuilder();
380 ab.setAction(new NxActionResubmitRpcAddGroupCaseBuilder().setNxResubmit(nxarsb.build()).build());
381 ab.setKey(new ActionKey(actionInfo.getActionKey()));
389 public Action buildAction(ActionInfo actionInfo) {
390 ActionBuilder ab = new ActionBuilder();
395 private static final int RADIX_HEX = 16;
396 public abstract Action buildAction(ActionInfo actionInfo);