2 * Copyright © 2017 Red Hat, Inc. and others.
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
8 package org.opendaylight.genius.mdsalutil.matches;
10 import org.opendaylight.genius.mdsalutil.MDSALUtil;
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
17 * IPv4 destination match.
19 public class MatchIpv4Destination extends MatchInfoHelper<Ipv4Match, Ipv4MatchBuilder> {
21 private final Ipv4Prefix prefix;
23 public MatchIpv4Destination(Ipv4Prefix prefix) {
27 public MatchIpv4Destination(long ip, long mask) {
28 this.prefix = new Ipv4Prefix(MDSALUtil.longToIp(ip, mask));
31 public MatchIpv4Destination(String ip, String mask) {
32 this.prefix = new Ipv4Prefix(ip + "/" + mask);
36 protected void applyValue(MatchBuilder matchBuilder, Ipv4Match value) {
37 matchBuilder.setLayer3Match(value);
41 protected void populateBuilder(Ipv4MatchBuilder builder) {
42 builder.setIpv4Destination(prefix);
45 public Ipv4Prefix getPrefix() {
50 public boolean equals(Object other) {
54 if (other == null || getClass() != other.getClass()) {
57 if (!super.equals(other)) {
61 MatchIpv4Destination that = (MatchIpv4Destination) other;
63 return prefix != null ? prefix.equals(that.prefix) : that.prefix == null;
67 public int hashCode() {
68 int result = super.hashCode();
69 result = 31 * result + (prefix != null ? prefix.hashCode() : 0);
74 public String toString() {
75 return "MatchIpv4Destination[" + prefix + "]";