e9f56f6a0301798b963fe9fb567c34076a640a44
[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 cfi in PushVlanAction.", (Integer) 1, ((PushVlanActionCase) innerAction).getPushVlanAction()
276                             .getCfi().getValue());
277                     assertEquals("Wrong value of pcp in PushVlanAction.", (Integer) 7,
278                             ((PushVlanActionCase) innerAction).getPushVlanAction().getPcp());
279                     assertEquals("Wrong value of tag in PushVlanAction.", (Integer) 0x8100,
280                             ((PushVlanActionCase) innerAction).getPushVlanAction().getTag());
281                     assertEquals("Wrong value of vlad ID in PushVlanAction.", (Integer) 4095,
282                             ((PushVlanActionCase) innerAction).getPushVlanAction().getVlanId().getValue());
283                 } else if (innerAction instanceof SetDlDstActionCase) {
284                     assertEquals("Wrong MAC destination address in SetDlDstAction.", "ff:ee:dd:cc:bb:aa",
285                             ((SetDlDstActionCase) innerAction).getSetDlDstAction().getAddress().getValue());
286                 } else if (innerAction instanceof SetDlSrcActionCase) {
287                     assertEquals("Wrong MAC source address in SetDlDstAction.", "ff:ee:dd:cc:bb:aa",
288                             ((SetDlSrcActionCase) innerAction).getSetDlSrcAction().getAddress().getValue());
289                 } else if (innerAction instanceof SetDlTypeActionCase) {
290                     assertEquals("Wrong data link type in SetDlTypeAction.", 513,
291                             (long) ((SetDlTypeActionCase) innerAction).getSetDlTypeAction().getDlType().getValue());
292                 } else if (innerAction instanceof SetNextHopActionCase) {
293                     Address address = ((SetNextHopActionCase) innerAction).getSetNextHopAction().getAddress();
294                     boolean ipv4AddressFound = false;
295                     if (address instanceof Ipv4) {
296                         ipv4AddressFound = true;
297                         assertEquals("Wrong IP address type in SetNextHopAction.", "192.168.100.100", ((Ipv4) address)
298                                 .getIpv4Address().getValue());
299                     }
300                     assertTrue("Ipv4 address wasn't found.", ipv4AddressFound);
301                 } else if (innerAction instanceof SetNwTosActionCase) {
302                     assertEquals("Wrong TOS in SetNwTosAction.", (Integer) 63, ((SetNwTosActionCase) innerAction).getSetNwTosAction().getTos());
303                 } else if (innerAction instanceof SetNwDstActionCase) {
304                     Address address = ((SetNwDstActionCase) innerAction).getSetNwDstAction().getAddress();
305                     boolean ipv4AddressFound = false;
306                     if (address instanceof Ipv4) {
307                         ipv4AddressFound = true;
308                         assertEquals("Wrong IP address type in SetNwDstAction.", "192.168.100.101", ((Ipv4) address)
309                                 .getIpv4Address().getValue());
310                     }
311                     assertTrue("Ipv4 address wasn't found.", ipv4AddressFound);
312                 } else if (innerAction instanceof SetNwSrcActionCase) {
313                     Address address = ((SetNwSrcActionCase) innerAction).getSetNwSrcAction().getAddress();
314                     boolean ipv4AddressFound = false;
315                     if (address instanceof Ipv4) {
316                         ipv4AddressFound = true;
317                         assertEquals("Wrong IP address type in SetNwSrcAction.", "192.168.100.102", ((Ipv4) address)
318                                 .getIpv4Address().getValue());
319                     }
320                     assertTrue("Ipv4 address wasn't found.", ipv4AddressFound);
321                 } else if (innerAction instanceof SetTpDstActionCase) {
322                     assertEquals("Port number is incorrect in SetTpDstAction.", (Integer) 65534,
323                             ((SetTpDstActionCase) innerAction).getSetTpDstAction().getPort().getValue());
324                 } else if (innerAction instanceof SetTpSrcActionCase) {
325                     assertEquals("Port number is incorrect in SetTpSrcAction.", (Integer) 65535,
326                             ((SetTpSrcActionCase) innerAction).getSetTpSrcAction().getPort().getValue());
327                 } else if (innerAction instanceof SetVlanCfiActionCase) {
328                     assertEquals("Vlan cfi number is incorrect in SetVlanCfiAction.", (Integer) 1,
329                             ((SetVlanCfiActionCase) innerAction).getSetVlanCfiAction().getVlanCfi().getValue());
330                 } else if (innerAction instanceof SetVlanIdActionCase) {
331                     assertEquals("Vlan id number is incorrect in SetVlanIdAction.", (Integer) 4095,
332                             ((SetVlanIdActionCase) innerAction).getSetVlanIdAction().getVlanId().getValue());
333                 } else if (innerAction instanceof SetVlanPcpActionCase) {
334                     assertEquals("Vlan pcp number is incorrect in SetVlanPcpAction.", new Short((short) 7),
335                             ((SetVlanPcpActionCase) innerAction).getSetVlanPcpAction().getVlanPcp().getValue());
336                 }
337             }
338         }
339         assertEquals("Incorrrect number of action " + cl.getName() + ".", 1, numOfFoundActions);
340
341     }
342
343     private Flow prepareSalFlowCommon() {
344         Flow salFlow = new Flow();
345         salFlow.setId(9223372036854775807L);
346         salFlow.setHardTimeout((short) 32765);
347         salFlow.setIdleTimeout((short) 32766);
348         salFlow.setPriority((short) 32767);
349         salFlow.setActions(prepareSalActions());
350         salFlow.setMatch(new Match());
351
352         return salFlow;
353     }
354
355     private Flow prepareSalMatch(Flow salFlow, MtchType mt) throws ConstructionException {
356         Match salMatch = new Match();
357         switch (mt) {
358         case arp:
359             salMatch.setField(MatchType.DL_TYPE, ETHERNET_ARP);
360             salMatch.setField(MatchType.NW_SRC, InetAddresses.forString("192.168.100.100"));
361             salMatch.setField(MatchType.NW_DST, InetAddresses.forString("192.168.100.101"));
362             salMatch.setField(MatchType.DL_SRC, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
363             salMatch.setField(MatchType.DL_DST, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
364             break;
365         case ipv4:
366             salMatch.setField(MatchType.DL_TYPE, (short) 0xffff);
367             salMatch.setField(MatchType.NW_SRC, InetAddresses.forString("192.168.100.102"));
368             salMatch.setField(MatchType.NW_DST, InetAddresses.forString("192.168.100.103"));
369             break;
370         case ipv6:
371             salMatch.setField(MatchType.DL_TYPE, (short) 0xffff);
372             salMatch.setField(MatchType.NW_SRC, InetAddresses.forString("2001:0db8:85a3:0000:0000:8a2e:0370:7335"));
373             salMatch.setField(MatchType.NW_DST, InetAddresses.forString("2001:0db8:85a3:0000:0000:8a2e:0370:7336"));
374             break;
375         case other:
376             Node node = new Node(NodeIDType.OPENFLOW, 12345L);
377             NodeConnector port = new NodeConnector(NodeConnectorIDType.OPENFLOW, Short.valueOf((short)10), node);
378             salMatch.setField(MatchType.IN_PORT, port);
379             salMatch.setField(MatchType.DL_SRC, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
380             salMatch.setField(MatchType.DL_DST, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
381             salMatch.setField(MatchType.DL_VLAN, (short) 0xfff);
382             salMatch.setField(MatchType.DL_VLAN_PR, (byte) 0x7);
383             salMatch.setField(MatchType.NW_TOS, (byte) 0x3f);
384             break;
385         case untagged:
386             salMatch.setField(MatchType.DL_SRC, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
387             salMatch.setField(MatchType.DL_DST, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
388             salMatch.setField(MatchType.DL_VLAN, MatchType.DL_VLAN_NONE);
389             salMatch.setField(MatchType.NW_TOS, (byte) 0x3f);
390             break;
391         case sctp:
392             salMatch.setField(MatchType.NW_PROTO, CRUDP);
393             salMatch.setField(MatchType.TP_SRC, (short) 0xffff);
394             salMatch.setField(MatchType.TP_DST, (short) 0xfffe);
395             break;
396         case tcp:
397             salMatch.setField(MatchType.NW_PROTO, TCP);
398             salMatch.setField(MatchType.TP_SRC, (short) 0xabcd);
399             salMatch.setField(MatchType.TP_DST, (short) 0xdcba);
400             break;
401         case udp:
402             salMatch.setField(MatchType.NW_PROTO, UDP);
403             salMatch.setField(MatchType.TP_SRC, (short) 0xcdef);
404             salMatch.setField(MatchType.TP_DST, (short) 0xfedc);
405             break;
406         default:
407             break;
408
409         }
410
411         salFlow.setMatch(salMatch);
412         return salFlow;
413     }
414
415     private List<Action> prepareSalActions() {
416         List<Action> salActions = new ArrayList<>();
417         salActions.add(new Flood());
418         salActions.add(new FloodAll());
419         salActions.add(new HwPath());
420         salActions.add(new Loopback());
421         // salActions.add(new Output //TODO: mapping is missing
422         salActions.add(new PopVlan());
423         salActions.add(new PushVlan(0x8100, 7, 1, 4095));
424         salActions.add(new SetDlDst(new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa}));
425         salActions.add(new SetDlSrc(new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa}));
426         salActions.add(new SetDlType(513));
427         salActions.add(new SetNextHop(InetAddresses.forString("192.168.100.100")));
428         salActions.add(new SetNwDst(InetAddresses.forString("192.168.100.101")));
429         salActions.add(new SetNwSrc(InetAddresses.forString("192.168.100.102")));
430         salActions.add(new SetNwTos(63));
431         salActions.add(new SetTpDst(65534));
432         salActions.add(new SetTpSrc(65535));
433         salActions.add(new SetVlanCfi(1));
434         salActions.add(new SetVlanId(4095));
435         salActions.add(new SetVlanPcp(7));
436         salActions.add(new SwPath());
437
438         return salActions;
439     }
440
441 }