blob: 3a03feb16db4cafb41b3424818c6d73c6b23c5d0 [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
Carmelo Cascone4c289b72019-01-22 15:30:45 -080019import com.google.common.annotations.Beta;
Carmelo Cascone58136812018-07-19 03:40:16 +020020import com.google.common.base.Objects;
21import org.onosproject.net.PortNumber;
22
23import static com.google.common.base.Preconditions.checkNotNull;
24import static java.lang.String.format;
25
26/**
27 * Representation of a packet replica used for multicast or cloning process in a
28 * protocol-independent packet replication engine.
29 * <p>
30 * Each replica is uniquely identified inside a given multicast group or clone
31 * session by the pair (egress port, instance ID).
32 */
Carmelo Cascone4c289b72019-01-22 15:30:45 -080033@Beta
34public final class PiPreReplica {
Carmelo Cascone58136812018-07-19 03:40:16 +020035
36 private final PortNumber egressPort;
Carmelo Cascone03ae0ac2018-10-11 08:31:59 -070037 private final int instanceId;
Carmelo Cascone58136812018-07-19 03:40:16 +020038
39 /**
40 * Returns a new PRE packet replica for the given egress port and instance
41 * ID.
42 *
43 * @param egressPort egress port
44 * @param instanceId instance ID
45 */
Carmelo Cascone03ae0ac2018-10-11 08:31:59 -070046 public PiPreReplica(PortNumber egressPort, int instanceId) {
Carmelo Cascone58136812018-07-19 03:40:16 +020047 this.egressPort = checkNotNull(egressPort);
48 this.instanceId = instanceId;
49 }
50
51 /**
52 * Returns the egress port of this replica.
53 *
54 * @return egress port
55 */
56 public PortNumber egressPort() {
57 return egressPort;
58 }
59
60 /**
61 * Returns the instance ID of this replica.
62 *
63 * @return instance ID
64 */
Carmelo Cascone03ae0ac2018-10-11 08:31:59 -070065 public int instanceId() {
Carmelo Cascone58136812018-07-19 03:40:16 +020066 return instanceId;
67 }
68
69 @Override
70 public int hashCode() {
71 return Objects.hashCode(egressPort, instanceId);
72 }
73
74 @Override
75 public boolean equals(Object obj) {
76 if (this == obj) {
77 return true;
78 }
79 if (obj == null || getClass() != obj.getClass()) {
80 return false;
81 }
82 final PiPreReplica other = (PiPreReplica) obj;
83 return Objects.equal(this.egressPort, other.egressPort)
84 && Objects.equal(this.instanceId, other.instanceId);
85 }
86
87 @Override
88 public String toString() {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080089 return format("%s:0x%s", egressPort, Integer.toHexString(instanceId));
Carmelo Cascone58136812018-07-19 03:40:16 +020090 }
91}