Merge "Enforce checkstyle in countermanager module"
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / matches / MatchIpProtocol.java
1 /*
2  * Copyright © 2017 Red Hat, Inc. and others.
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.genius.mdsalutil.matches;
9
10 import org.opendaylight.genius.mdsalutil.packet.IPProtocols;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
14
15 /**
16  * IP protocol match.
17  */
18 public class MatchIpProtocol extends MatchInfoHelper<IpMatch, IpMatchBuilder> {
19     public static final MatchIpProtocol TCP = new MatchIpProtocol(IPProtocols.TCP.shortValue());
20     public static final MatchIpProtocol UDP = new MatchIpProtocol(IPProtocols.UDP.shortValue());
21     public static final MatchIpProtocol ICMP = new MatchIpProtocol(IPProtocols.ICMP.shortValue());
22     public static final MatchIpProtocol ICMPV6 = new MatchIpProtocol(IPProtocols.IPV6ICMP.shortValue());
23
24     private final short protocol;
25
26     public MatchIpProtocol(short protocol) {
27         this.protocol = protocol;
28     }
29
30     @Override
31     protected void applyValue(MatchBuilder matchBuilder, IpMatch value) {
32         matchBuilder.setIpMatch(value);
33     }
34
35     @Override
36     protected void populateBuilder(IpMatchBuilder builder) {
37         builder.setIpProtocol(protocol);
38     }
39
40     public short getProtocol() {
41         return protocol;
42     }
43
44     @Override
45     public boolean equals(Object o) {
46         if (this == o) return true;
47         if (o == null || getClass() != o.getClass()) return false;
48         if (!super.equals(o)) return false;
49
50         MatchIpProtocol that = (MatchIpProtocol) o;
51
52         return protocol == that.protocol;
53     }
54
55     @Override
56     public int hashCode() {
57         int result = super.hashCode();
58         result = 31 * result + (int) protocol;
59         return result;
60     }
61 }