blob: ea7003d73bae1de1804a8b9c2e339b243fde956d [file] [log] [blame]
Carmelo Cascone58136812018-07-19 03:40:16 +02001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.net.pi.runtime;
18
19import com.google.common.base.Objects;
20import org.onosproject.net.PortNumber;
21
22import static com.google.common.base.Preconditions.checkNotNull;
23import static java.lang.String.format;
24
25/**
26 * Representation of a packet replica used for multicast or cloning process in a
27 * protocol-independent packet replication engine.
28 * <p>
29 * Each replica is uniquely identified inside a given multicast group or clone
30 * session by the pair (egress port, instance ID).
31 */
32public class PiPreReplica {
33
34 private final PortNumber egressPort;
35 private final long instanceId;
36
37 /**
38 * Returns a new PRE packet replica for the given egress port and instance
39 * ID.
40 *
41 * @param egressPort egress port
42 * @param instanceId instance ID
43 */
44 public PiPreReplica(PortNumber egressPort, long instanceId) {
45 this.egressPort = checkNotNull(egressPort);
46 this.instanceId = instanceId;
47 }
48
49 /**
50 * Returns the egress port of this replica.
51 *
52 * @return egress port
53 */
54 public PortNumber egressPort() {
55 return egressPort;
56 }
57
58 /**
59 * Returns the instance ID of this replica.
60 *
61 * @return instance ID
62 */
63 public long instanceId() {
64 return instanceId;
65 }
66
67 @Override
68 public int hashCode() {
69 return Objects.hashCode(egressPort, instanceId);
70 }
71
72 @Override
73 public boolean equals(Object obj) {
74 if (this == obj) {
75 return true;
76 }
77 if (obj == null || getClass() != obj.getClass()) {
78 return false;
79 }
80 final PiPreReplica other = (PiPreReplica) obj;
81 return Objects.equal(this.egressPort, other.egressPort)
82 && Objects.equal(this.instanceId, other.instanceId);
83 }
84
85 @Override
86 public String toString() {
87 return format("%s:%d", egressPort, instanceId);
88 }
89}