Merge "Enforce checkstyle in countermanager module"
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / matches / MatchEthernetType.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.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
15
16 /**
17  * Ethernet type match.
18  */
19 public class MatchEthernetType extends MatchInfoHelper<EthernetMatch, EthernetMatchBuilder> {
20     public static final MatchEthernetType IPV4 = new MatchEthernetType(0x0800L);
21     public static final MatchEthernetType ARP = new MatchEthernetType(0x0806L);
22     public static final MatchEthernetType RARP = new MatchEthernetType(0x8035L);
23     public static final MatchEthernetType IPV6 = new MatchEthernetType(0x86DDL);
24     public static final MatchEthernetType MPLS_UNICAST = new MatchEthernetType(0x8847L);
25     public static final MatchEthernetType MPLS_MULTICAST = new MatchEthernetType(0x8848L);
26
27     private final long type;
28
29     public MatchEthernetType(long type) {
30         this.type = type;
31     }
32
33     @Override
34     protected void applyValue(MatchBuilder matchBuilder, EthernetMatch value) {
35         matchBuilder.setEthernetMatch(value);
36     }
37
38     @Override
39     protected void populateBuilder(EthernetMatchBuilder builder) {
40         builder.setEthernetType(new EthernetTypeBuilder().setType(new EtherType(type)).build());
41     }
42
43     public long getType() {
44         return type;
45     }
46
47     @Override
48     public boolean equals(Object o) {
49         if (this == o) return true;
50         if (o == null || getClass() != o.getClass()) return false;
51         if (!super.equals(o)) return false;
52
53         MatchEthernetType that = (MatchEthernetType) o;
54
55         return type == that.type;
56     }
57
58     @Override
59     public int hashCode() {
60         int result = super.hashCode();
61         result = 31 * result + (int) (type ^ (type >>> 32));
62         return result;
63     }
64 }