Merge "Strong password check to consider underscore as a special character"
[controller.git] / opendaylight / md-sal / sal-compability / src / main / java / org / opendaylight / controller / sal / compability / FromSalConversionsUtils.java
1 package org.opendaylight.controller.sal.compability;
2
3 import static org.opendaylight.controller.sal.match.MatchType.DL_DST;
4 import static org.opendaylight.controller.sal.match.MatchType.DL_SRC;
5 import static org.opendaylight.controller.sal.match.MatchType.DL_TYPE;
6
7 import java.math.BigInteger;
8 import java.net.Inet4Address;
9 import java.net.Inet6Address;
10 import java.net.InetAddress;
11 import java.util.ArrayList;
12 import java.util.Arrays;
13 import java.util.List;
14
15 import org.opendaylight.controller.sal.action.*;
16 import org.opendaylight.controller.sal.core.NodeConnector;
17 import org.opendaylight.controller.sal.flowprogrammer.Flow;
18 import org.opendaylight.controller.sal.match.Match;
19 import org.opendaylight.controller.sal.match.MatchField;
20 import org.opendaylight.controller.sal.match.MatchType;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.*;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.VlanCfi;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.action.action.*;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.address.Address;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.address.address.Ipv4Builder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.address.address.Ipv6Builder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.flow.Action;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.flow.ActionBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.arp.match.fields.ArpSourceHardwareAddressBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.arp.match.fields.ArpTargetHardwareAddressBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.ethernet.match.fields.EthernetDestinationBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.ethernet.match.fields.EthernetSourceBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.ethernet.match.fields.EthernetTypeBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.*;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._3.match.ArpMatchBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._3.match.Ipv4MatchBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._3.match.Ipv6MatchBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._4.match.SctpMatchBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._4.match.TcpMatchBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.match.layer._4.match.UdpMatchBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev130819.vlan.match.fields.VlanIdBuilder;
48
49 public class FromSalConversionsUtils {
50
51     // source: http://en.wikipedia.org/wiki/Ethertype
52     private static final Short ETHERNET_ARP = new Short((short) 0x0806);
53
54     // source: http://en.wikipedia.org/wiki/List_of_IP_protocol_numbers
55     private static final short TCP = (short) 0x06;
56     private static final short UDP = (short) 0x11;
57     private static final short SCTP = (short) 0x84;
58
59     private FromSalConversionsUtils() {
60
61     }
62
63     public static FlowAdded flowFrom(Flow sourceFlow) {
64         if (sourceFlow != null) {
65             final FlowAddedBuilder targetFlow = new FlowAddedBuilder();
66
67             targetFlow.setHardTimeout(new Integer(sourceFlow.getHardTimeout()));
68             targetFlow.setIdleTimeout(new Integer(sourceFlow.getIdleTimeout()));
69             targetFlow.setPriority(new Integer(sourceFlow.getPriority()));
70             targetFlow.setCookie(new BigInteger(String.valueOf(sourceFlow.getId())));
71
72             List<org.opendaylight.controller.sal.action.Action> sourceActions = sourceFlow.getActions();
73             List<Action> targetActions = new ArrayList<>();
74             for (org.opendaylight.controller.sal.action.Action sourceAction : sourceActions) {
75                 targetActions.add(actionFrom(sourceAction));
76             }
77             targetFlow.setAction(targetActions);
78
79             targetFlow.setMatch(matchFrom(sourceFlow.getMatch()));
80
81             return targetFlow.build();
82         }
83         return null;
84     }
85
86     private static Action actionFrom(org.opendaylight.controller.sal.action.Action sourceAction) {
87
88         ActionBuilder targetActionBuilder = new ActionBuilder();
89         org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.action.Action targetAction = null;
90
91         if (sourceAction instanceof Controller) {
92             targetAction = new ControllerActionBuilder().build();
93         } else if (sourceAction instanceof Drop) {
94             targetAction = new DropActionBuilder().build();
95         } else if (sourceAction instanceof Flood) {
96             targetAction = new FloodActionBuilder().build();
97         } else if (sourceAction instanceof FloodAll) {
98             targetAction = new FloodAllActionBuilder().build();
99         } else if (sourceAction instanceof HwPath) {
100             targetAction = new HwPathActionBuilder().build();
101         } else if (sourceAction instanceof Loopback) {
102             targetAction = new LoopbackActionBuilder().build();
103         } else if (sourceAction instanceof Output) {
104             NodeConnector nodeConnector = ((Output) sourceAction).getPort();
105
106             OutputActionBuilder outputActionBuilder = new OutputActionBuilder();
107             outputActionBuilder.setOutputNodeConnector(nodeConnectorToUri(nodeConnector));
108             targetAction = outputActionBuilder.build();
109
110         } else if (sourceAction instanceof PopVlan) {
111             targetAction = new PopVlanActionBuilder().build();
112         } else if (sourceAction instanceof PushVlan) {
113             PushVlan pushVlan = (PushVlan) sourceAction;
114             PushVlanActionBuilder pushVlanActionBuilder = new PushVlanActionBuilder();
115
116             pushVlanActionBuilder.setCfi(new VlanCfi(pushVlan.getCfi()));
117             pushVlanActionBuilder.setVlanId(new VlanId(pushVlan.getVlanId()));
118             pushVlanActionBuilder.setPcp(pushVlan.getPcp());
119             pushVlanActionBuilder.setTag(pushVlan.getTag());
120             targetAction = pushVlanActionBuilder.build();
121         } else if (sourceAction instanceof SetDlDst) {
122             SetDlDst setDlDst = (SetDlDst) sourceAction;
123             SetDlDstActionBuilder setDlDstActionBuilder = new SetDlDstActionBuilder();
124
125             setDlDstActionBuilder.setAddress(new MacAddress(Arrays.toString(setDlDst.getDlAddress())));
126             targetAction = setDlDstActionBuilder.build();
127         } else if (sourceAction instanceof SetDlSrc) {
128             SetDlSrc setDlSrc = (SetDlSrc) sourceAction;
129             SetDlSrcActionBuilder setDlSrcActionBuilder = new SetDlSrcActionBuilder();
130
131             setDlSrcActionBuilder.setAddress(new MacAddress(Arrays.toString(setDlSrc.getDlAddress())));
132             targetAction = setDlSrcActionBuilder.build();
133         } else if (sourceAction instanceof SetDlType) {
134             SetDlType setDlType = (SetDlType) sourceAction;
135             SetDlTypeActionBuilder setDlTypeActionBuilder = new SetDlTypeActionBuilder();
136
137             setDlTypeActionBuilder.setDlType(new EtherType(new Long(setDlType.getDlType())));
138             targetAction = setDlTypeActionBuilder.build();
139         } else if (sourceAction instanceof SetNextHop) {
140             SetNextHop setNextHop = (SetNextHop) sourceAction;
141             SetNextHopActionBuilder setNextHopActionBuilder = new SetNextHopActionBuilder();
142
143             InetAddress inetAddress = setNextHop.getAddress();
144             setNextHopActionBuilder.setAddress(addressFromAction(inetAddress));
145
146             targetAction = setNextHopActionBuilder.build();
147         } else if (sourceAction instanceof SetNwDst) {
148             SetNwDst setNwDst = (SetNwDst) sourceAction;
149             SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
150
151             InetAddress inetAddress = setNwDst.getAddress();
152             setNwDstActionBuilder.setAddress(addressFromAction(inetAddress));
153
154             targetAction = setNwDstActionBuilder.build();
155         } else if (sourceAction instanceof SetNwSrc) {
156             SetNwSrc setNwSrc = (SetNwSrc) sourceAction;
157             SetNwSrcActionBuilder setNwSrcActionBuilder = new SetNwSrcActionBuilder();
158
159             InetAddress inetAddress = setNwSrc.getAddress();
160             setNwSrcActionBuilder.setAddress(addressFromAction(inetAddress));
161
162             targetAction = setNwSrcActionBuilder.build();
163         } else if (sourceAction instanceof SetNwTos) {
164             SetNwTos setNwTos = (SetNwTos) sourceAction;
165             SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder();
166
167             setNwTosActionBuilder.setTos(setNwTos.getNwTos());
168             targetAction = setNwTosActionBuilder.build();
169         } else if (sourceAction instanceof SetTpDst) {
170             SetTpDst setTpDst = (SetTpDst) sourceAction;
171             SetTpDstActionBuilder setTpDstActionBuilder = new SetTpDstActionBuilder();
172
173             setTpDstActionBuilder.setPort(new PortNumber(setTpDst.getPort()));
174
175             targetAction = setTpDstActionBuilder.build();
176         } else if (sourceAction instanceof SetTpSrc) {
177             SetTpSrc setTpSrc = (SetTpSrc) sourceAction;
178             SetTpSrcActionBuilder setTpSrcActionBuilder = new SetTpSrcActionBuilder();
179
180             setTpSrcActionBuilder.setPort(new PortNumber(setTpSrc.getPort()));
181
182             targetAction = setTpSrcActionBuilder.build();
183         } else if (sourceAction instanceof SetVlanCfi) {
184             SetVlanCfi setVlanCfi = (SetVlanCfi) sourceAction;
185             SetVlanCfiActionBuilder setVlanCfiActionBuilder = new SetVlanCfiActionBuilder();
186
187             setVlanCfiActionBuilder.setVlanCfi(new VlanCfi(setVlanCfi.getCfi()));
188
189             targetAction = setVlanCfiActionBuilder.build();
190         } else if (sourceAction instanceof SetVlanId) {
191             SetVlanId setVlanId = (SetVlanId) sourceAction;
192             SetVlanIdActionBuilder setVlanIdActionBuilder = new SetVlanIdActionBuilder();
193
194             setVlanIdActionBuilder.setVlanId(new VlanId(setVlanId.getVlanId()));
195
196             targetAction = setVlanIdActionBuilder.build();
197         } else if (sourceAction instanceof SetVlanPcp) {
198             SetVlanPcp setVlanPcp = (SetVlanPcp) sourceAction;
199             SetVlanPcpActionBuilder setVlanPcpActionBuilder = new SetVlanPcpActionBuilder();
200
201             setVlanPcpActionBuilder.setVlanPcp(new VlanPcp((short) setVlanPcp.getPcp()));
202
203             targetAction = setVlanPcpActionBuilder.build();
204         } else if (sourceAction instanceof SwPath) {
205             targetAction = new SwPathActionBuilder().build();
206         }
207
208         targetActionBuilder.setAction(targetAction);
209
210         return targetActionBuilder.build();
211     }
212
213     private static Address addressFromAction(InetAddress inetAddress) {
214         byte[] byteInetAddresss = inetAddress.getAddress();
215         if (inetAddress instanceof Inet4Address) {
216             Ipv4Builder ipv4Builder = new Ipv4Builder();
217             ipv4Builder.setIpv4Address(new Ipv4Prefix(Arrays.toString(byteInetAddresss)));
218             return ipv4Builder.build();
219         } else if (inetAddress instanceof Inet6Address) {
220             Ipv6Builder ipv6Builder = new Ipv6Builder();
221             ipv6Builder.setIpv6Address(new Ipv6Prefix(Arrays.toString(byteInetAddresss)));
222             return ipv6Builder.build();
223         }
224         return null;
225     }
226
227     private static List<Uri> nodeConnectorToUri(NodeConnector nodeConnector) {
228         // TODO Define mapping
229         return null;
230     }
231
232     private static org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.flow.Match matchFrom(
233             Match sourceMatch) {
234         if (sourceMatch != null) {
235             org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.flow.MatchBuilder targetBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev130819.flow.MatchBuilder();
236
237             targetBuilder.setEthernetMatch(ethernetMatchFrom(sourceMatch));
238             targetBuilder.setIpMatch(ipMatchFrom(sourceMatch));
239             targetBuilder.setVlanMatch(vlanMatchFrom(sourceMatch));
240             targetBuilder.setLayer3Match(layer3Match(sourceMatch));
241             targetBuilder.setLayer4Match(layer4Match(sourceMatch));
242
243             return targetBuilder.build();
244         }
245         return null;
246
247     }
248
249     private static Layer4Match layer4Match(final Match sourceMatch) {
250         MatchField nwProto = sourceMatch.getField(MatchType.NW_PROTO);
251         Short nwProtocolSource = null;
252         if (nwProto != null && nwProto.getValue() != null) {
253             nwProtocolSource = (Short) (nwProto.getValue());
254         }
255
256         switch (nwProtocolSource) {
257         case TCP:
258             return Layer4MatchAsTcp(sourceMatch);
259         case UDP:
260             return Layer4MatchAsUdp(sourceMatch);
261         case SCTP:
262             return Layer4MatchAsSctp(sourceMatch);
263         }
264         return null;
265     }
266
267     private static Layer4Match Layer4MatchAsSctp(final Match sourceMatch) {
268         SctpMatchBuilder sctpMatchBuilder = new SctpMatchBuilder();
269
270         Integer sourcePort = transportPortFrom(sourceMatch, MatchType.TP_SRC);
271         Integer destinationPort = transportPortFrom(sourceMatch, MatchType.TP_DST);
272
273         if (sourcePort != null) {
274             sctpMatchBuilder.setSctpSourcePort(new PortNumber(sourcePort));
275         }
276         if (destinationPort != null) {
277             sctpMatchBuilder.setSctpDestinationPort(new PortNumber(destinationPort));
278         }
279
280         return sctpMatchBuilder.build();
281     }
282
283     private static Layer4Match Layer4MatchAsUdp(final Match sourceMatch) {
284         UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
285
286         Integer sourcePort = transportPortFrom(sourceMatch, MatchType.TP_SRC);
287         Integer destinationPort = transportPortFrom(sourceMatch, MatchType.TP_DST);
288
289         if (sourcePort != null) {
290             udpMatchBuilder.setUdpSourcePort(new PortNumber(sourcePort));
291         }
292
293         if (destinationPort != null) {
294             udpMatchBuilder.setUdpDestinationPort(new PortNumber(destinationPort));
295         }
296
297         return udpMatchBuilder.build();
298     }
299
300     private static Layer4Match Layer4MatchAsTcp(final Match sourceMatch) {
301         TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
302
303         Integer sourcePort = transportPortFrom(sourceMatch, MatchType.TP_SRC);
304         Integer destinationPort = transportPortFrom(sourceMatch, MatchType.TP_DST);
305
306         if (sourcePort != null) {
307             tcpMatchBuilder.setTcpSourcePort(new PortNumber(sourcePort));
308         }
309         if (destinationPort != null) {
310             tcpMatchBuilder.setTcpDestinationPort(new PortNumber(destinationPort));
311         }
312
313         return tcpMatchBuilder.build();
314     }
315
316     private static Integer transportPortFrom(final Match sourceMatch, final MatchType matchType) {
317         MatchField transportPort = sourceMatch.getField(matchType);
318         if (transportPort != null && transportPort.getValue() != null) {
319             return (Integer) (transportPort.getValue());
320         }
321         return null;
322     }
323
324     private static VlanMatch vlanMatchFrom(final Match sourceMatch) {
325         VlanMatchBuilder vlanMatchBuild = new VlanMatchBuilder();
326
327         MatchField vlan = sourceMatch.getField(MatchType.DL_VLAN);
328         if (vlan != null && vlan.getValue() != null) {
329             VlanIdBuilder vlanIDBuilder = new VlanIdBuilder();
330             vlanIDBuilder.setVlanId(new VlanId((Integer) (vlan.getValue())));
331             vlanMatchBuild.setVlanId(vlanIDBuilder.build());
332         }
333
334         MatchField vlanPriority = sourceMatch.getField(MatchType.DL_VLAN_PR);
335         if (vlanPriority != null && vlanPriority.getValue() != null) {
336             vlanMatchBuild.setVlanPcp(new VlanPcp((Short) (vlanPriority.getValue())));
337         }
338
339         return vlanMatchBuild.build();
340     }
341
342     private static IpMatch ipMatchFrom(final Match sourceMatch) {
343         IpMatchBuilder targetIpMatchBuild = new IpMatchBuilder();
344         MatchField networkTos = sourceMatch.getField(MatchType.NW_TOS);
345         if (networkTos != null && networkTos.getValue() != null) {
346             Dscp dscp = new Dscp((Short) (networkTos.getValue()));
347             targetIpMatchBuild.setIpDscp(dscp);
348         }
349
350         MatchField protocol = sourceMatch.getField(MatchType.NW_PROTO);
351         if (protocol != null && protocol.getValue() != null) {
352             targetIpMatchBuild.setIpProtocol((Short) (protocol.getValue()));
353         }
354
355         return targetIpMatchBuild.build();
356
357     }
358
359     private static EthernetMatch ethernetMatchFrom(final Match sourceMatch) {
360         final EthernetMatchBuilder targetEthMatchBuild = new EthernetMatchBuilder();
361
362         EthernetSourceBuilder ethSourBuild = new EthernetSourceBuilder()
363                 .setAddress(ethernetSourceAddressFrom(sourceMatch));
364         targetEthMatchBuild.setEthernetSource(ethSourBuild.build());
365
366         EthernetDestinationBuilder ethDestBuild = new EthernetDestinationBuilder()
367                 .setAddress(ethernetDestAddressFrom(sourceMatch));
368         targetEthMatchBuild.setEthernetDestination(ethDestBuild.build());
369
370         final MatchField dataLinkType = sourceMatch.getField(MatchType.DL_TYPE);
371         if (dataLinkType != null && dataLinkType.getValue() != null) {
372             EtherType etherType = new EtherType((Long) (dataLinkType.getValue()));
373             EthernetTypeBuilder ethType = new EthernetTypeBuilder().setType(etherType);
374             targetEthMatchBuild.setEthernetType(ethType.build());
375         }
376         return targetEthMatchBuild.build();
377     }
378
379     private static MacAddress ethernetSourceAddressFrom(final Match sourceMatch) {
380         final MatchField dataLinkSource = sourceMatch.getField(DL_SRC);
381         if (dataLinkSource != null && dataLinkSource.getValue() != null) {
382             return new MacAddress(new MacAddress((String) (dataLinkSource.getValue())));
383         }
384         return null;
385
386     }
387
388     private static Layer3Match layer3Match(final Match sourceMatch) {
389         InetAddress inetSourceAddress = null;
390         MatchField netSource = sourceMatch.getField(MatchType.NW_SRC);
391         if (netSource != null && netSource.getValue() != null) {
392             inetSourceAddress = (InetAddress) (netSource.getValue());
393         }
394
395         InetAddress inetDestAddress = null;
396         MatchField netDest = sourceMatch.getField(MatchType.NW_DST);
397         if (netSource != null && netSource.getValue() != null) {
398             inetDestAddress = (InetAddress) (netDest.getValue());
399         }
400
401         if ((inetSourceAddress instanceof Inet4Address) && (inetDestAddress instanceof Inet4Address)) {
402             MatchField dataLinkType = sourceMatch.getField(DL_TYPE);
403             Short dLType = null;
404             if (dataLinkType != null && dataLinkType.getValue() != null) {
405                 dLType = (Short) (dataLinkType.getValue());
406             }
407             if (dLType.equals(ETHERNET_ARP)) {
408                 return setLayer3MatchAsArp(sourceMatch, (Inet4Address) inetSourceAddress,
409                         (Inet4Address) inetDestAddress);
410             } else {
411                 return setLayer3MatchAsIpv4((Inet4Address) inetSourceAddress, (Inet4Address) inetDestAddress);
412             }
413         } else if ((inetSourceAddress instanceof Inet6Address) && (inetDestAddress instanceof Inet6Address)) {
414             return setLayer3MatchAsIpv6((Inet6Address) inetSourceAddress, (Inet6Address) inetDestAddress);
415         }
416
417         return null;
418
419     }
420
421     private static Layer3Match setLayer3MatchAsArp(final Match sourceMatch, final Inet4Address inetSourceAddress,
422             final Inet4Address inetDestAddress) {
423         byte[] inetSourceAddressValue = inetSourceAddress.getAddress();
424         Ipv4Prefix ipv4SourcePrefix = new Ipv4Prefix(Arrays.toString(inetSourceAddressValue));
425
426         byte[] inetDestAddressValue = inetDestAddress.getAddress();
427         Ipv4Prefix ipv4DestPrefix = new Ipv4Prefix(Arrays.toString(inetDestAddressValue));
428
429         ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
430
431         arpMatchBuilder.setArpSourceTransportAddress(ipv4SourcePrefix);
432         arpMatchBuilder.setArpSourceTransportAddress(ipv4DestPrefix);
433
434         ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new ArpSourceHardwareAddressBuilder();
435         arpSourceHardwareAddressBuilder.setAddress(ethernetSourceAddressFrom(sourceMatch));
436         arpMatchBuilder.setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder.build());
437
438         ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new ArpTargetHardwareAddressBuilder();
439         arpTargetHardwareAddressBuilder.setAddress(ethernetDestAddressFrom(sourceMatch));
440         arpMatchBuilder.setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder.build());
441
442         return arpMatchBuilder.build();
443
444     }
445
446     private static MacAddress ethernetDestAddressFrom(final Match sourceMatch) {
447         final MatchField dataLinkDest = sourceMatch.getField(DL_DST);
448         if (dataLinkDest != null && dataLinkDest.getValue() != null) {
449             return new MacAddress((String) (dataLinkDest.getValue()));
450         }
451         return null;
452     }
453
454     private static Layer3Match setLayer3MatchAsIpv4(final Inet4Address inetSourceAddress,
455             final Inet4Address inetDestAddress) {
456         byte[] inetAddressValue = inetSourceAddress.getAddress();
457
458         Ipv4MatchBuilder layer4MatchBuild = new Ipv4MatchBuilder();
459         layer4MatchBuild.setIpv4Source(new Ipv4Prefix(Arrays.toString(inetAddressValue)));
460         return layer4MatchBuild.build();
461
462     }
463
464     private static Layer3Match setLayer3MatchAsIpv6(final Inet6Address inetSourceAddress,
465             final Inet6Address inetDestAddress) {
466         byte[] inetAddressValue = inetSourceAddress.getAddress();
467         Ipv6MatchBuilder layer6MatchBuild = new Ipv6MatchBuilder();
468
469         layer6MatchBuild.setIpv6Source(new Ipv6Prefix(Arrays.toString(inetAddressValue)));
470         return layer6MatchBuild.build();
471     }
472
473 }