fix npe when calculating mask hash
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / util / HashUtil.java
1 /*
2  * Copyright (c) 2015 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
9 package org.opendaylight.openflowplugin.impl.util;
10
11 import java.math.BigInteger;
12 import java.util.StringTokenizer;
13 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
14 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
15 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpVersion;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddress;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddress;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestination;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSource;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetType;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6Match;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFields;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagMatch;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4Match;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.Pbb;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
52
53 /**
54  * Created by Martin Bobak <mbobak@cisco.com> on 8.4.2015.
55  */
56 public final class HashUtil {
57
58     private static final Logger LOG = LoggerFactory.getLogger(HashUtil.class);
59     private static final int BASE_16 = 16;
60     private static final int BASE_10 = 10;
61     private static final int IPV6_TOKENS_COUNT = 8;
62     public static final String IPV6_TOKEN = ":0000";
63
64     private HashUtil() {
65
66         throw new IllegalStateException("This class should not be instantiated.");
67     }
68
69     public static int calculateEthernetMatchHash(EthernetMatch ethernetMatch) {
70         int hash = 0;
71
72         EthernetType ethernetType = ethernetMatch.getEthernetType();
73         if (null != ethernetType) {
74             hash += ethernetType.getType().getValue();
75         }
76
77         EthernetDestination ethernetDestination = ethernetMatch.getEthernetDestination();
78         if (null != ethernetDestination) {
79             hash += calculateEthernetDestinationHash(ethernetDestination);
80         }
81
82         EthernetSource ethernetSource = ethernetMatch.getEthernetSource();
83         if (null != ethernetSource) {
84             hash += calculateEthenetSourceHash(ethernetSource);
85         }
86
87         return hash;
88     }
89
90     public static int calculateEthenetSourceHash(EthernetSource ethernetSource) {
91         int hash = calculateMacAddressHash(ethernetSource.getAddress());
92         hash += calculateMacAddressHash(ethernetSource.getMask());
93         return hash;
94     }
95
96     public static int calculateEthernetDestinationHash(EthernetDestination ethernetDestination) {
97         int hash = calculateMacAddressHash(ethernetDestination.getAddress());
98         hash += calculateMacAddressHash(ethernetDestination.getMask());
99         return hash;
100     }
101
102     public static int calculateMacAddressHash(MacAddress macAddress) {
103
104         int hash = 0;
105         if (null != macAddress) {
106             StringTokenizer stringTokenizer = new StringTokenizer(macAddress.getValue(), ":");
107             hash = parseTokens(stringTokenizer, BASE_16);
108         }
109         LOG.trace("Calculated hash {} for mac {}", hash, macAddress);
110         return hash;
111     }
112
113     public static int calculateMatchHash(final Match match, DeviceContext deviceContext) {
114         int hash = 0;
115         int subHash = 0;
116         int base = 0;
117         if (null != match) {
118             if (null != match.getEthernetMatch()) {
119                 hash = 1 << base;
120                 subHash += calculateEthernetMatchHash(match.getEthernetMatch());
121             }
122             base++;
123             if (null != match.getIcmpv4Match()) {
124                 hash = 1 << base;
125                 subHash += calculateIcmpV4MatchHash(match.getIcmpv4Match());
126             }
127             base++;
128             if (null != match.getIcmpv6Match()) {
129                 hash = 1 << base;
130                 subHash += calculateIcmpV6MatchHash(match.getIcmpv6Match());
131             }
132             base++;
133             if (null != match.getInPhyPort()) {
134                 hash = 1 << base;
135                 subHash += calculateNodeConnectorIdHash(match.getInPhyPort(), deviceContext);
136             }
137             base++;
138             if (null != match.getInPort()) {
139                 hash = 1 << base;
140                 subHash += calculateNodeConnectorIdHash(match.getInPort(), deviceContext);
141             }
142             base++;
143             if (null != match.getIpMatch()) {
144                 hash = 1 << base;
145                 subHash += calculateIpMatchHash(match.getIpMatch());
146             }
147             base++;
148             if (null != match.getLayer3Match()) {
149                 hash = 1 << base;
150                 subHash += calculateLayer3MatchHash(match.getLayer3Match());
151             }
152             base++;
153             if (null != match.getLayer4Match()) {
154                 hash = 1 << base;
155                 subHash += calculateLayer4MatchHash(match.getLayer4Match());
156             }
157             base++;
158             if (null != match.getIcmpv6Match()) {
159                 hash = 1 << base;
160                 subHash += calculateIcmpv6MatchHash(match.getIcmpv6Match());
161             }
162             base++;
163             if (null != match.getMetadata()) {
164                 hash = 1 << base;
165                 subHash += calculateMetadataHash(match.getMetadata());
166             }
167             base++;
168             if (null != match.getProtocolMatchFields()) {
169                 hash = 1 << base;
170                 subHash += calculateProtocolMatchFieldsHash(match.getProtocolMatchFields());
171             }
172             base++;
173             if (null != match.getTcpFlagMatch()) {
174                 hash = 1 << base;
175                 subHash += calculateTcpFlagMatch(match.getTcpFlagMatch());
176             }
177             base++;
178             if (null != match.getVlanMatch()) {
179                 hash = 1 << base;
180                 subHash += calculateVlanMatchHash(match.getVlanMatch());
181             }
182             base++;
183             if (null != match.getTunnel()) {
184                 hash = 1 << base;
185                 subHash += calculateTunnelHash(match.getTunnel());
186             }
187         }
188         return hash + subHash;
189     }
190
191     private static int calculateTunnelHash(final Tunnel tunnel) {
192         int hash = 0;
193         BigInteger tunnelId = tunnel.getTunnelId();
194         if (null != tunnelId) {
195             hash += tunnelId.intValue();
196         }
197
198         BigInteger tunnelMask = tunnel.getTunnelMask();
199         if (null != tunnelMask) {
200             hash += tunnelMask.intValue();
201         }
202         return hash;
203     }
204
205     private static int calculateVlanMatchHash(final VlanMatch vlanMatch) {
206         int hash = 0;
207
208         VlanId vlanId = vlanMatch.getVlanId();
209         if (null != vlanId) {
210             hash += vlanId.getVlanId().getValue().intValue();
211         }
212
213         VlanPcp vlanPcp = vlanMatch.getVlanPcp();
214         if (null != vlanPcp) {
215             hash += vlanPcp.getValue().shortValue();
216         }
217
218         return hash;
219     }
220
221     private static int calculateTcpFlagMatch(final TcpFlagMatch tcpFlagMatch) {
222         int hash = tcpFlagMatch.getTcpFlag().intValue();
223         return hash;
224     }
225
226     private static int calculateProtocolMatchFieldsHash(final ProtocolMatchFields protocolMatchFields) {
227         int hash = 0;
228         Short mplsBos = protocolMatchFields.getMplsBos();
229         if (null != mplsBos) {
230             hash += mplsBos.intValue();
231         }
232         Short mplsTc = protocolMatchFields.getMplsTc();
233         if (null != mplsTc) {
234             hash += mplsTc.intValue();
235         }
236         Pbb pbb = protocolMatchFields.getPbb();
237         if (null != pbb) {
238             if (null != pbb.getPbbIsid()) {
239                 hash += pbb.getPbbIsid().intValue();
240             }
241             if (null != pbb.getPbbMask()) {
242                 hash += pbb.getPbbMask().intValue();
243             }
244         }
245         Long mplsLabel = protocolMatchFields.getMplsLabel();
246         if (null != mplsLabel) {
247             hash += mplsLabel.intValue();
248         }
249         return hash;
250     }
251
252     private static int calculateMetadataHash(final Metadata metadata) {
253         int hash = metadata.getMetadata().intValue();
254         if (null != metadata.getMetadataMask()) {
255             hash += metadata.getMetadataMask().intValue();
256         }
257         return hash;
258     }
259
260     private static int calculateIcmpv6MatchHash(final Icmpv6Match icmpv6Match) {
261         int hash = icmpv6Match.getIcmpv6Code().intValue();
262         hash += icmpv6Match.getIcmpv6Type().intValue();
263         return hash;
264     }
265
266     private static int calculateLayer4MatchHash(final Layer4Match layer4Match) {
267         int hash = 0;
268         if (layer4Match instanceof SctpMatch) {
269             hash += calculateSctpMatchHash((SctpMatch) layer4Match);
270         }
271
272         if (layer4Match instanceof TcpMatch) {
273             hash += calculateTcpMatchHash((TcpMatch) layer4Match);
274         }
275         if (layer4Match instanceof UdpMatch) {
276             hash += calculateUdpMatchHash((UdpMatch) layer4Match);
277         }
278         return hash;
279     }
280
281     private static int calculateUdpMatchHash(final UdpMatch layer4Match) {
282         int hash = 0;
283         return hash;
284     }
285
286     private static int calculateTcpMatchHash(final TcpMatch layer4Match) {
287         int hash = 0;
288         PortNumber sourcePort = layer4Match.getTcpSourcePort();
289         if (null != sourcePort) {
290             hash += sourcePort.getValue().intValue();
291         }
292
293         PortNumber destinationPort = layer4Match.getTcpDestinationPort();
294         if (null != destinationPort) {
295             hash += destinationPort.getValue().intValue();
296         }
297         return hash;
298     }
299
300     private static int calculateSctpMatchHash(final SctpMatch layer4Match) {
301         int hash = 0;
302
303         PortNumber portNumber = layer4Match.getSctpDestinationPort();
304         if (null != portNumber) {
305             hash += portNumber.getValue().intValue();
306         }
307
308         PortNumber sourcePort = layer4Match.getSctpSourcePort();
309         if (null != sourcePort) {
310             hash += sourcePort.getValue().intValue();
311         }
312         return hash;
313     }
314
315     private static int calculateLayer3MatchHash(final Layer3Match layer3Match) {
316         int hash = 0;
317         if (layer3Match instanceof ArpMatch) {
318             hash += calculateArpMatchHash((ArpMatch) layer3Match);
319         }
320         if (layer3Match instanceof Ipv4Match) {
321             hash += calculateIpv4MatchHash((Ipv4Match) layer3Match);
322         }
323         if (layer3Match instanceof Ipv6Match) {
324             hash += calculateIpv6MatchHash((Ipv6Match) layer3Match);
325
326         }
327         if (layer3Match instanceof TunnelIpv4Match) {
328             hash += calculateTunnelIpv4Hash((TunnelIpv4Match) layer3Match);
329         }
330         return hash;
331     }
332
333     private static int calculateTunnelIpv4Hash(final TunnelIpv4Match layer3Match) {
334         Ipv4Prefix tunnelIpv4Destination = layer3Match.getTunnelIpv4Destination();
335         int hash = calculateIpv4PrefixHash(tunnelIpv4Destination);
336         Ipv4Prefix tunnelIpv4Source = layer3Match.getTunnelIpv4Source();
337         hash += calculateIpv4PrefixHash(tunnelIpv4Source);
338         return hash;
339     }
340
341     private static int calculateIpv6MatchHash(final Ipv6Match layer3Match) {
342         int hash = 0;
343         Ipv6Prefix ipv6Destination = layer3Match.getIpv6Destination();
344         if (null != ipv6Destination) {
345             hash += calculateIpv6PrefixHash(ipv6Destination);
346         }
347
348         if (null != layer3Match.getIpv6Source()) {
349             hash += calculateIpv6PrefixHash(layer3Match.getIpv6Source());
350         }
351
352         if (null != layer3Match.getIpv6ExtHeader()) {
353             hash += layer3Match.getIpv6ExtHeader().getIpv6Exthdr();
354             hash += layer3Match.getIpv6ExtHeader().getIpv6ExthdrMask();
355         }
356
357         if (null != layer3Match.getIpv6NdSll()) {
358             hash += calculateMacAddressHash(layer3Match.getIpv6NdSll());
359         }
360         if (null != layer3Match.getIpv6NdTll()) {
361             hash += calculateMacAddressHash(layer3Match.getIpv6NdTll());
362         }
363         if (null != layer3Match.getIpv6NdTarget()){
364             hash += calculateIpv6AddressHash(layer3Match.getIpv6NdTarget());
365         }
366         return hash;
367     }
368
369
370     public static int calculateIpv6PrefixHash(final Ipv6Prefix ipv6Prefix) {
371
372         StringTokenizer stringTokenizer = getStringTokenizerWithFullAddressString(ipv6Prefix.getValue());
373
374         int hash = parseTokens(stringTokenizer, BASE_16);
375         return hash;
376     }
377     public static int calculateIpv6AddressHash(final Ipv6Address ipv6Address) {
378
379         StringTokenizer stringTokenizer = getStringTokenizerWithFullAddressString(ipv6Address.getValue());
380
381         int hash = parseTokens(stringTokenizer, BASE_16);
382         return hash;
383     }
384
385     private static StringTokenizer getStringTokenizerWithFullAddressString(String value) {
386         String ipv6Value = value.replace("::", ":0000:");
387         StringTokenizer stringTokenizer = new StringTokenizer(ipv6Value, ":");
388
389         int delta = IPV6_TOKENS_COUNT - stringTokenizer.countTokens();
390
391         StringBuffer additions = new StringBuffer();
392
393         if (delta > 0) {
394             while (delta > 0) {
395                 additions.append(IPV6_TOKEN);
396                 delta--;
397             }
398             if (ipv6Value.contains("/")) {
399                 ipv6Value = ipv6Value.replace("/", additions.toString() + "/");
400             } else {
401                 ipv6Value += additions.toString();
402             }
403             stringTokenizer = new StringTokenizer(ipv6Value, ":");
404         }
405         return stringTokenizer;
406     }
407
408     private static int calculateStopperBasedOnMaskValue(final Ipv6Prefix ipv6Prefix, int bitsBase) {
409         double maskValue = extractMask(ipv6Prefix);
410         double bitCount = maskValue / bitsBase;
411         return (int) Math.ceil(bitCount);
412     }
413
414     private static int extractMask(final Ipv6Prefix ipv6Prefix) {
415         StringTokenizer maskTokenizer = new StringTokenizer(ipv6Prefix.getValue(), "/");
416         int mask = 0;
417         if (maskTokenizer.countTokens() > 1) {
418             maskTokenizer.nextToken();
419             mask = Integer.parseInt(maskTokenizer.nextToken());
420         }
421         return mask;
422     }
423
424     private static int parseTokens(final StringTokenizer stringTokenizer, int base) {
425         return parseTokens(stringTokenizer, 0, base);
426     }
427
428     private static int parseTokens(final StringTokenizer stringTokenizer, int stopper, int base) {
429         int hash = 0;
430         if (stringTokenizer.countTokens() > 0) {
431             int step = 0;
432             while (stringTokenizer.hasMoreTokens()) {
433                 String token = stringTokenizer.nextToken();
434                 step++;
435
436                 if (token.equals("")) {
437                     token = "0";
438                 }
439
440                 if (token.contains("/")) {
441                     StringTokenizer tokenizer = new StringTokenizer(token, "/");
442                     hash = hash ^ parseTokens(tokenizer, stopper, base);
443                 } else {
444                     hash = hash ^ ((Integer.parseInt(token, base) * step) + step);
445                     if (stopper > 0 && step == stopper) {
446                         break;
447                     }
448                 }
449             }
450         }
451         return hash;
452     }
453
454     private static int calculateIpv4MatchHash(final Ipv4Match layer3Match) {
455         int hash = 0;
456         Ipv4Prefix ipv4Destination = layer3Match.getIpv4Destination();
457         if (null != ipv4Destination) {
458             hash += calculateIpv4PrefixHash(ipv4Destination);
459         }
460
461         Ipv4Prefix ipv4Source = layer3Match.getIpv4Source();
462
463         if (null != ipv4Source) {
464             hash += calculateIpv4PrefixHash(ipv4Source);
465         }
466
467         //TODO : add calculation of hashes for augmentations
468         return hash;
469     }
470
471     private static int calculateArpMatchHash(final ArpMatch layer3Match) {
472         int hash = 0;
473         Integer arpOp = layer3Match.getArpOp();
474         if (null != arpOp) {
475             hash += arpOp.intValue();
476         }
477         ArpSourceHardwareAddress arpSourceHardwareAddress = layer3Match.getArpSourceHardwareAddress();
478         if (null != arpSourceHardwareAddress) {
479             hash += calculateMacAddressHash(arpSourceHardwareAddress.getAddress());
480             hash += calculateMacAddressHash(arpSourceHardwareAddress.getMask());
481         }
482
483         Ipv4Prefix sourceTransportAddress = layer3Match.getArpSourceTransportAddress();
484         if (null != sourceTransportAddress) {
485             hash += calculateIpv4PrefixHash(sourceTransportAddress);
486         }
487
488         ArpTargetHardwareAddress arpTargetHardwareAddress = layer3Match.getArpTargetHardwareAddress();
489         if (null != arpTargetHardwareAddress) {
490             hash += calculateMacAddressHash(arpTargetHardwareAddress.getAddress());
491             hash += calculateMacAddressHash(arpTargetHardwareAddress.getMask());
492         }
493
494         Ipv4Prefix targetTransportAddress = layer3Match.getArpTargetTransportAddress();
495         if (null != targetTransportAddress) {
496             hash += calculateIpv4PrefixHash(targetTransportAddress);
497         }
498
499         return hash;
500     }
501
502     public static int calculateIpv4PrefixHash(final Ipv4Prefix ipv4Prefix) {
503         int hash = 0;
504         StringTokenizer prefixAsArray = new StringTokenizer(ipv4Prefix.getValue(), "/");
505         if (prefixAsArray.countTokens() == 2) {
506             String address = prefixAsArray.nextToken();
507             Integer mask = Integer.parseInt(prefixAsArray.nextToken());
508             int numberOfAddressPartsToUse = (int) Math.ceil(mask.doubleValue() / 8);
509             hash += calculateIpAdressHash(address, numberOfAddressPartsToUse, BASE_10);
510             hash += mask.shortValue();
511         }
512         return hash;
513     }
514
515
516     private static int calculateIpAdressHash(final String address, int numberOfParts, int base) {
517         StringTokenizer stringTokenizer = new StringTokenizer(address, ".");
518         int hash = parseTokens(stringTokenizer, numberOfParts, base);
519         return hash;
520     }
521
522     private static int calculateIpMatchHash(final IpMatch ipMatch) {
523         int hash = 0;
524         Short ipEcn = ipMatch.getIpEcn();
525         if (null != ipEcn) {
526             hash += ipEcn.shortValue();
527         }
528         Short ipProtocol = ipMatch.getIpProtocol();
529         if (null != ipProtocol) {
530             hash += ipProtocol;
531         }
532
533         Short ipDscp = ipMatch.getIpDscp().getValue();
534         if (null != ipDscp) {
535             hash += ipDscp;
536         }
537
538         IpVersion ipVersion = ipMatch.getIpProto();
539         if (null != ipVersion) {
540             hash += ipVersion.getIntValue();
541         }
542         return hash;
543     }
544
545     private static int calculateNodeConnectorIdHash(final NodeConnectorId inPhyPort, DeviceContext deviceContext) {
546         int hash = 0;
547         short version = deviceContext.getDeviceState().getVersion();
548         Long portFromLogicalName = OpenflowPortsUtil.getPortFromLogicalName(OpenflowVersion.get(version), inPhyPort.getValue());
549         hash += portFromLogicalName.intValue();
550         return hash;
551     }
552
553     private static int calculateIcmpV6MatchHash(final Icmpv6Match icmpv6Match) {
554         int hash = 0;
555         if (null != icmpv6Match.getIcmpv6Code()) {
556             hash += icmpv6Match.getIcmpv6Code();
557         }
558         if (null != icmpv6Match.getIcmpv6Type()) {
559             hash += icmpv6Match.getIcmpv6Type();
560         }
561         return hash;
562     }
563
564     public static int calculateIcmpV4MatchHash(final Icmpv4Match icmpv4Match) {
565         int hash = 0;
566         if (null != icmpv4Match.getIcmpv4Code()) {
567             hash += icmpv4Match.getIcmpv4Code();
568         }
569         if (null != icmpv4Match.getIcmpv4Type()) {
570             hash += icmpv4Match.getIcmpv4Type();
571         }
572         return hash;
573     }
574
575
576 }