9f787b7e391010cee640d6b0582c4e0447ded4c2
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / test / java / org / opendaylight / controller / sal / compatibility / test / TestFromSalConversionsUtils.java
1 /*
2  * Copyright (c) 2013-2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.compatibility.test;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.opendaylight.controller.sal.compatibility.ProtocolConstants.CRUDP;
14 import static org.opendaylight.controller.sal.compatibility.ProtocolConstants.ETHERNET_ARP;
15 import static org.opendaylight.controller.sal.compatibility.ProtocolConstants.TCP;
16 import static org.opendaylight.controller.sal.compatibility.ProtocolConstants.UDP;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.junit.Test;
22 import org.opendaylight.controller.sal.action.Action;
23 import org.opendaylight.controller.sal.action.Flood;
24 import org.opendaylight.controller.sal.action.FloodAll;
25 import org.opendaylight.controller.sal.action.HwPath;
26 import org.opendaylight.controller.sal.action.Loopback;
27 import org.opendaylight.controller.sal.action.PopVlan;
28 import org.opendaylight.controller.sal.action.PushVlan;
29 import org.opendaylight.controller.sal.action.SetDlDst;
30 import org.opendaylight.controller.sal.action.SetDlSrc;
31 import org.opendaylight.controller.sal.action.SetDlType;
32 import org.opendaylight.controller.sal.action.SetNextHop;
33 import org.opendaylight.controller.sal.action.SetNwDst;
34 import org.opendaylight.controller.sal.action.SetNwSrc;
35 import org.opendaylight.controller.sal.action.SetNwTos;
36 import org.opendaylight.controller.sal.action.SetTpDst;
37 import org.opendaylight.controller.sal.action.SetTpSrc;
38 import org.opendaylight.controller.sal.action.SetVlanCfi;
39 import org.opendaylight.controller.sal.action.SetVlanId;
40 import org.opendaylight.controller.sal.action.SetVlanPcp;
41 import org.opendaylight.controller.sal.action.SwPath;
42 import org.opendaylight.controller.sal.compatibility.MDFlowMapping;
43 import org.opendaylight.controller.sal.compatibility.ToSalConversionsUtils;
44 import org.opendaylight.controller.sal.core.ConstructionException;
45 import org.opendaylight.controller.sal.core.Node;
46 import org.opendaylight.controller.sal.core.Node.NodeIDType;
47 import org.opendaylight.controller.sal.core.NodeConnector;
48 import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
49 import org.opendaylight.controller.sal.flowprogrammer.Flow;
50 import org.opendaylight.controller.sal.match.Match;
51 import org.opendaylight.controller.sal.match.MatchType;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodActionCase;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCase;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.HwPathActionCase;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.LoopbackActionCase;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCase;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCase;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCase;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlTypeActionCase;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNextHopActionCase;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCase;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCase;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCase;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanCfiActionCase;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCase;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCase;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCase;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeFlow;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
82
83 import com.google.common.net.InetAddresses;
84
85 public class TestFromSalConversionsUtils {
86     private enum MtchType {
87         other, untagged, ipv4, ipv6, arp, sctp, tcp, udp
88     }
89
90     @Test
91     public void testFromSalConversion() throws ConstructionException {
92
93         Flow salFlow = prepareSalFlowCommon();
94         NodeFlow odNodeFlow = MDFlowMapping.flowAdded(salFlow);
95
96         checkOdFlow(odNodeFlow);
97
98         odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.other));
99         checkOdMatch(odNodeFlow.getMatch(), MtchType.other);
100
101         odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.untagged));
102         checkOdMatch(odNodeFlow.getMatch(), MtchType.untagged);
103
104         odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.arp));
105         checkOdMatch(odNodeFlow.getMatch(), MtchType.arp);
106
107         odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.ipv4));
108         checkOdMatch(odNodeFlow.getMatch(), MtchType.ipv4);
109
110         odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.ipv6));
111         checkOdMatch(odNodeFlow.getMatch(), MtchType.ipv6);
112
113         odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.sctp));
114         checkOdMatch(odNodeFlow.getMatch(), MtchType.sctp);
115
116         odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.tcp));
117         checkOdMatch(odNodeFlow.getMatch(), MtchType.tcp);
118
119         odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.udp));
120         checkOdMatch(odNodeFlow.getMatch(), MtchType.udp);
121     }
122
123     private void checkOdMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match,
124             MtchType mt) {
125         switch (mt) {
126         case arp:
127             assertEquals("Ether type is incorrect.", ETHERNET_ARP, (long) match.getEthernetMatch().getEthernetType()
128                     .getType().getValue());
129             Layer3Match layer3Match = match.getLayer3Match();
130             boolean arpFound = false;
131             if (layer3Match instanceof ArpMatch) {
132                 assertEquals("Source IP address is wrong.", "192.168.100.100", ((ArpMatch) layer3Match)
133                         .getArpSourceTransportAddress().getValue());
134                 assertEquals("Destination IP address is wrong.", "192.168.100.101", ((ArpMatch) layer3Match)
135                         .getArpTargetTransportAddress().getValue());
136                 assertEquals("Source MAC address is wrong.", "ff:ee:dd:cc:bb:aa", ((ArpMatch) layer3Match)
137                         .getArpSourceHardwareAddress().getAddress().getValue());
138                 assertEquals("Destination MAC address is wrong.", "ff:ee:dd:cc:bb:aa", ((ArpMatch) layer3Match)
139                         .getArpTargetHardwareAddress().getAddress().getValue());
140                 arpFound = true;
141             }
142             assertNotNull("Arp wasn't found", arpFound);
143             break;
144         case ipv4:
145             assertEquals("Ether type is incorrect.", 0xffff, (long) match.getEthernetMatch().getEthernetType()
146                     .getType().getValue());
147             boolean ipv4Found = false;
148             layer3Match = match.getLayer3Match();
149             if (layer3Match instanceof Ipv4Match) {
150                 assertEquals("Source IP address is wrong.", "192.168.100.102", ((Ipv4Match) layer3Match)
151                         .getIpv4Source().getValue());
152                 assertEquals("Destination IP address is wrong.", "192.168.100.103", ((Ipv4Match) layer3Match)
153                         .getIpv4Destination().getValue());
154             }
155             assertNotNull("Ipv4 wasn't found", ipv4Found);
156             break;
157         case ipv6:
158             assertEquals("Ether type is incorrect.", 0xffff, (long) match.getEthernetMatch().getEthernetType()
159                     .getType().getValue());
160             boolean ipv6Found = false;
161             layer3Match = match.getLayer3Match();
162             if (layer3Match instanceof Ipv6Match) {
163                 assertEquals("Source IP address is wrong.", "2001:db8:85a3::8a2e:370:7335", ((Ipv6Match) layer3Match)
164                         .getIpv6Source().getValue());
165                 assertEquals("Destination IP address is wrong.", "2001:db8:85a3::8a2e:370:7336",
166                         ((Ipv6Match) layer3Match).getIpv6Destination().getValue());
167             }
168             assertNotNull("Ipv6 wasn't found", ipv6Found);
169             break;
170         case other:
171             assertEquals("Incoming port is wrong.", "openflow:12345:10", match.getInPort().getValue());
172             assertEquals("Source MAC address is wrong.", "ff:ee:dd:cc:bb:aa", match.getEthernetMatch()
173                     .getEthernetSource().getAddress().getValue());
174             assertEquals("Destinatio MAC address is wrong.", "ff:ee:dd:cc:bb:aa", match.getEthernetMatch()
175                     .getEthernetDestination().getAddress().getValue());
176             assertEquals("Vlan ID is not present.", Boolean.TRUE, match.getVlanMatch().getVlanId().isVlanIdPresent());
177             assertEquals("Vlan ID is wrong.", (Integer) 0xfff, match.getVlanMatch().getVlanId().getVlanId().getValue());
178             assertEquals("Vlan ID priority is wrong.", (short) 0x7, (short) match.getVlanMatch().getVlanPcp()
179                     .getValue());
180             assertEquals("DCSP is wrong.", (short) 0x3f, (short) match.getIpMatch().getIpDscp().getValue());
181             break;
182         case untagged:
183             assertEquals("Source MAC address is wrong.", "ff:ee:dd:cc:bb:aa", match.getEthernetMatch()
184                     .getEthernetSource().getAddress().getValue());
185             assertEquals("Destinatio MAC address is wrong.", "ff:ee:dd:cc:bb:aa", match.getEthernetMatch()
186                     .getEthernetDestination().getAddress().getValue());
187             assertEquals("Vlan ID is present.", Boolean.FALSE, match.getVlanMatch().getVlanId().isVlanIdPresent());
188             assertEquals("Vlan ID is wrong.", Integer.valueOf(0), match.getVlanMatch().getVlanId().getVlanId().getValue());
189             assertEquals("DCSP is wrong.", (short) 0x3f, (short) match.getIpMatch().getIpDscp().getValue());
190             break;
191         case sctp:
192             boolean sctpFound = false;
193             assertEquals("Wrong protocol", CRUDP, match.getIpMatch().getIpProtocol().byteValue());
194             Layer4Match layer4Match = match.getLayer4Match();
195             if (layer4Match instanceof SctpMatch) {
196                 assertEquals("Sctp source port is incorrect.", 0xffff, (int) ((SctpMatch) layer4Match)
197                         .getSctpSourcePort().getValue());
198                 assertEquals("Sctp dest port is incorrect.", 0xfffe, (int) ((SctpMatch) layer4Match)
199                         .getSctpDestinationPort().getValue());
200                 sctpFound = true;
201             }
202             assertNotNull("Sctp wasn't found", sctpFound);
203             break;
204         case tcp:
205             boolean tcpFound = false;
206             assertEquals("Wrong protocol", TCP, match.getIpMatch().getIpProtocol().byteValue());
207             layer4Match = match.getLayer4Match();
208             if (layer4Match instanceof TcpMatch) {
209                 assertEquals("Tcp source port is incorrect.", 0xabcd, (int) ((TcpMatch) layer4Match)
210                         .getTcpSourcePort().getValue());
211                 assertEquals("Tcp dest port is incorrect.", 0xdcba, (int) ((TcpMatch) layer4Match)
212                         .getTcpDestinationPort().getValue());
213                 sctpFound = true;
214             }
215             assertNotNull("Tcp wasn't found", tcpFound);
216             break;
217         case udp:
218             boolean udpFound = false;
219             assertEquals("Wrong protocol", UDP, match.getIpMatch().getIpProtocol().byteValue());
220             layer4Match = match.getLayer4Match();
221             if (layer4Match instanceof UdpMatch) {
222                 assertEquals("Udp source port is incorrect.", 0xcdef, (int) ((UdpMatch) layer4Match)
223                         .getUdpSourcePort().getValue());
224                 assertEquals("Udp dest port is incorrect.", 0xfedc, (int) ((UdpMatch) layer4Match)
225                         .getUdpDestinationPort().getValue());
226                 sctpFound = true;
227             }
228             assertNotNull("Udp wasn't found", udpFound);
229             break;
230         }
231
232     }
233
234     private void checkOdFlow(NodeFlow odNodeFlow) {
235         assertEquals("Cookie is incorrect.", 9223372036854775807L, odNodeFlow.getCookie().getValue().longValue());
236         assertEquals("Hard timeout is incorrect.", 32765, odNodeFlow.getHardTimeout().shortValue());
237         assertEquals("Iddle timeout is incorrect.", 32766, odNodeFlow.getIdleTimeout().shortValue());
238         assertEquals("Priority is incorrect.", 32767, odNodeFlow.getPriority().shortValue());
239
240         checkOdActions(ToSalConversionsUtils.getAction(odNodeFlow));
241     }
242
243     private void checkOdActions(
244             List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions) {
245         checkOdAction(actions, FloodActionCase.class);
246         checkOdAction(actions, FloodAllActionCase.class);
247         checkOdAction(actions, HwPathActionCase.class);
248         checkOdAction(actions, LoopbackActionCase.class);
249         checkOdAction(actions, PopVlanActionCase.class);
250         checkOdAction(actions, PushVlanActionCase.class);
251         checkOdAction(actions, SetDlDstActionCase.class);
252         checkOdAction(actions, SetDlSrcActionCase.class);
253         checkOdAction(actions, SetDlTypeActionCase.class);
254         checkOdAction(actions, SetNwTosActionCase.class);
255         checkOdAction(actions, SetNwDstActionCase.class);
256         checkOdAction(actions, SetNwSrcActionCase.class);
257         checkOdAction(actions, SetNextHopActionCase.class);
258         checkOdAction(actions, SetTpDstActionCase.class);
259         checkOdAction(actions, SetTpSrcActionCase.class);
260         checkOdAction(actions, SetVlanCfiActionCase.class);
261         checkOdAction(actions, SetVlanIdActionCase.class);
262         checkOdAction(actions, SetVlanPcpActionCase.class);
263         checkOdAction(actions, SwPathActionCase.class);
264     }
265
266     private void checkOdAction(
267             List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions, Class<?> cl) {
268         int numOfFoundActions = 0;
269         for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action action : actions) {
270             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action innerAction = action
271                     .getAction();
272             if (cl.isInstance(innerAction)) {
273                 numOfFoundActions++;
274                 if (innerAction instanceof PushVlanActionCase) {
275                     assertEquals("Wrong value of tag in PushVlanAction.", (Integer) 0x8100,
276                             ((PushVlanActionCase) innerAction).getPushVlanAction().getEthernetType());
277                 } else if (innerAction instanceof SetDlDstActionCase) {
278                     assertEquals("Wrong MAC destination address in SetDlDstAction.", "ff:ee:dd:cc:bb:aa",
279                             ((SetDlDstActionCase) innerAction).getSetDlDstAction().getAddress().getValue());
280                 } else if (innerAction instanceof SetDlSrcActionCase) {
281                     assertEquals("Wrong MAC source address in SetDlDstAction.", "ff:ee:dd:cc:bb:aa",
282                             ((SetDlSrcActionCase) innerAction).getSetDlSrcAction().getAddress().getValue());
283                 } else if (innerAction instanceof SetDlTypeActionCase) {
284                     assertEquals("Wrong data link type in SetDlTypeAction.", 513,
285                             (long) ((SetDlTypeActionCase) innerAction).getSetDlTypeAction().getDlType().getValue());
286                 } else if (innerAction instanceof SetNextHopActionCase) {
287                     Address address = ((SetNextHopActionCase) innerAction).getSetNextHopAction().getAddress();
288                     boolean ipv4AddressFound = false;
289                     if (address instanceof Ipv4) {
290                         ipv4AddressFound = true;
291                         assertEquals("Wrong IP address type in SetNextHopAction.", "192.168.100.100", ((Ipv4) address)
292                                 .getIpv4Address().getValue());
293                     }
294                     assertTrue("Ipv4 address wasn't found.", ipv4AddressFound);
295                 } else if (innerAction instanceof SetNwTosActionCase) {
296                     assertEquals("Wrong TOS in SetNwTosAction.", (Integer) 63, ((SetNwTosActionCase) innerAction).getSetNwTosAction().getTos());
297                 } else if (innerAction instanceof SetNwDstActionCase) {
298                     Address address = ((SetNwDstActionCase) innerAction).getSetNwDstAction().getAddress();
299                     boolean ipv4AddressFound = false;
300                     if (address instanceof Ipv4) {
301                         ipv4AddressFound = true;
302                         assertEquals("Wrong IP address type in SetNwDstAction.", "192.168.100.101", ((Ipv4) address)
303                                 .getIpv4Address().getValue());
304                     }
305                     assertTrue("Ipv4 address wasn't found.", ipv4AddressFound);
306                 } else if (innerAction instanceof SetNwSrcActionCase) {
307                     Address address = ((SetNwSrcActionCase) innerAction).getSetNwSrcAction().getAddress();
308                     boolean ipv4AddressFound = false;
309                     if (address instanceof Ipv4) {
310                         ipv4AddressFound = true;
311                         assertEquals("Wrong IP address type in SetNwSrcAction.", "192.168.100.102", ((Ipv4) address)
312                                 .getIpv4Address().getValue());
313                     }
314                     assertTrue("Ipv4 address wasn't found.", ipv4AddressFound);
315                 } else if (innerAction instanceof SetTpDstActionCase) {
316                     assertEquals("Port number is incorrect in SetTpDstAction.", (Integer) 65534,
317                             ((SetTpDstActionCase) innerAction).getSetTpDstAction().getPort().getValue());
318                 } else if (innerAction instanceof SetTpSrcActionCase) {
319                     assertEquals("Port number is incorrect in SetTpSrcAction.", (Integer) 65535,
320                             ((SetTpSrcActionCase) innerAction).getSetTpSrcAction().getPort().getValue());
321                 } else if (innerAction instanceof SetVlanCfiActionCase) {
322                     assertEquals("Vlan cfi number is incorrect in SetVlanCfiAction.", (Integer) 1,
323                             ((SetVlanCfiActionCase) innerAction).getSetVlanCfiAction().getVlanCfi().getValue());
324                 } else if (innerAction instanceof SetVlanIdActionCase) {
325                     assertEquals("Vlan id number is incorrect in SetVlanIdAction.", (Integer) 4095,
326                             ((SetVlanIdActionCase) innerAction).getSetVlanIdAction().getVlanId().getValue());
327                 } else if (innerAction instanceof SetVlanPcpActionCase) {
328                     assertEquals("Vlan pcp number is incorrect in SetVlanPcpAction.", new Short((short) 7),
329                             ((SetVlanPcpActionCase) innerAction).getSetVlanPcpAction().getVlanPcp().getValue());
330                 }
331             }
332         }
333         assertEquals("Incorrrect number of action " + cl.getName() + ".", 1, numOfFoundActions);
334
335     }
336
337     private Flow prepareSalFlowCommon() {
338         Flow salFlow = new Flow();
339         salFlow.setId(9223372036854775807L);
340         salFlow.setHardTimeout((short) 32765);
341         salFlow.setIdleTimeout((short) 32766);
342         salFlow.setPriority((short) 32767);
343         salFlow.setActions(prepareSalActions());
344         salFlow.setMatch(new Match());
345
346         return salFlow;
347     }
348
349     private Flow prepareSalMatch(Flow salFlow, MtchType mt) throws ConstructionException {
350         Match salMatch = new Match();
351         switch (mt) {
352         case arp:
353             salMatch.setField(MatchType.DL_TYPE, ETHERNET_ARP);
354             salMatch.setField(MatchType.NW_SRC, InetAddresses.forString("192.168.100.100"));
355             salMatch.setField(MatchType.NW_DST, InetAddresses.forString("192.168.100.101"));
356             salMatch.setField(MatchType.DL_SRC, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
357             salMatch.setField(MatchType.DL_DST, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
358             break;
359         case ipv4:
360             salMatch.setField(MatchType.DL_TYPE, (short) 0xffff);
361             salMatch.setField(MatchType.NW_SRC, InetAddresses.forString("192.168.100.102"));
362             salMatch.setField(MatchType.NW_DST, InetAddresses.forString("192.168.100.103"));
363             break;
364         case ipv6:
365             salMatch.setField(MatchType.DL_TYPE, (short) 0xffff);
366             salMatch.setField(MatchType.NW_SRC, InetAddresses.forString("2001:0db8:85a3:0000:0000:8a2e:0370:7335"));
367             salMatch.setField(MatchType.NW_DST, InetAddresses.forString("2001:0db8:85a3:0000:0000:8a2e:0370:7336"));
368             break;
369         case other:
370             Node node = new Node(NodeIDType.OPENFLOW, 12345L);
371             NodeConnector port = new NodeConnector(NodeConnectorIDType.OPENFLOW, Short.valueOf((short)10), node);
372             salMatch.setField(MatchType.IN_PORT, port);
373             salMatch.setField(MatchType.DL_SRC, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
374             salMatch.setField(MatchType.DL_DST, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
375             salMatch.setField(MatchType.DL_VLAN, (short) 0xfff);
376             salMatch.setField(MatchType.DL_VLAN_PR, (byte) 0x7);
377             salMatch.setField(MatchType.NW_TOS, (byte) 0x3f);
378             break;
379         case untagged:
380             salMatch.setField(MatchType.DL_SRC, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
381             salMatch.setField(MatchType.DL_DST, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
382             salMatch.setField(MatchType.DL_VLAN, MatchType.DL_VLAN_NONE);
383             salMatch.setField(MatchType.NW_TOS, (byte) 0x3f);
384             break;
385         case sctp:
386             salMatch.setField(MatchType.NW_PROTO, CRUDP);
387             salMatch.setField(MatchType.TP_SRC, (short) 0xffff);
388             salMatch.setField(MatchType.TP_DST, (short) 0xfffe);
389             break;
390         case tcp:
391             salMatch.setField(MatchType.NW_PROTO, TCP);
392             salMatch.setField(MatchType.TP_SRC, (short) 0xabcd);
393             salMatch.setField(MatchType.TP_DST, (short) 0xdcba);
394             break;
395         case udp:
396             salMatch.setField(MatchType.NW_PROTO, UDP);
397             salMatch.setField(MatchType.TP_SRC, (short) 0xcdef);
398             salMatch.setField(MatchType.TP_DST, (short) 0xfedc);
399             break;
400         default:
401             break;
402
403         }
404
405         salFlow.setMatch(salMatch);
406         return salFlow;
407     }
408
409     private List<Action> prepareSalActions() {
410         List<Action> salActions = new ArrayList<>();
411         salActions.add(new Flood());
412         salActions.add(new FloodAll());
413         salActions.add(new HwPath());
414         salActions.add(new Loopback());
415         // salActions.add(new Output //TODO: mapping is missing
416         salActions.add(new PopVlan());
417         salActions.add(new PushVlan(0x8100));
418         salActions.add(new SetDlDst(new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa}));
419         salActions.add(new SetDlSrc(new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa}));
420         salActions.add(new SetDlType(513));
421         salActions.add(new SetNextHop(InetAddresses.forString("192.168.100.100")));
422         salActions.add(new SetNwDst(InetAddresses.forString("192.168.100.101")));
423         salActions.add(new SetNwSrc(InetAddresses.forString("192.168.100.102")));
424         salActions.add(new SetNwTos(63));
425         salActions.add(new SetTpDst(65534));
426         salActions.add(new SetTpSrc(65535));
427         salActions.add(new SetVlanCfi(1));
428         salActions.add(new SetVlanId(4095));
429         salActions.add(new SetVlanPcp(7));
430         salActions.add(new SwPath());
431
432         return salActions;
433     }
434
435 }