blob: cd2df4af78f8560be5564d744729e02261408a35 [file] [log] [blame]
Carmelo Cascone9db4d5c2019-04-16 17:36:33 -07001/*
2 * Copyright 2019-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.annotations.Beta;
20import com.google.common.base.MoreObjects;
21import com.google.common.base.Objects;
22import org.onosproject.net.DeviceId;
23
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
27 * Global identifier of a PI clone session entry applied to the packet
28 * replication engine (PRE) of a device, uniquely defined by a device ID, and
29 * session ID.
30 */
31@Beta
32public final class PiCloneSessionEntryHandle extends PiPreEntryHandle {
33
34 private final int sessionId;
35
36 private PiCloneSessionEntryHandle(DeviceId deviceId, int sessionId) {
37 super(deviceId);
38 this.sessionId = sessionId;
39 }
40
41 /**
42 * Creates a new handle for the given device ID and PI clone session ID.
43 *
44 * @param deviceId device ID
45 * @param sessionId clone session ID
46 * @return PI clone session entry handle
47 */
48 public static PiCloneSessionEntryHandle of(DeviceId deviceId,
49 int sessionId) {
50 return new PiCloneSessionEntryHandle(deviceId, sessionId);
51 }
52
53 /**
54 * Creates a new handle for the given device ID and PI clone session entry.
55 *
56 * @param deviceId device ID
57 * @param entry PI clone session entry
58 * @return PI clone session entry handle
59 */
60 public static PiCloneSessionEntryHandle of(DeviceId deviceId,
61 PiCloneSessionEntry entry) {
62 checkNotNull(entry);
63 return new PiCloneSessionEntryHandle(deviceId, entry.sessionId());
64 }
65
66 /**
67 * Returns the clone session ID associated with this handle.
68 *
69 * @return session ID
70 */
71 public int sessionId() {
72 return sessionId;
73 }
74
75 @Override
76 public PiPreEntryType preEntryType() {
77 return PiPreEntryType.CLONE_SESSION;
78 }
79
80 @Override
81 public int hashCode() {
82 return Objects.hashCode(deviceId(), sessionId);
83 }
84
85 @Override
86 public boolean equals(Object o) {
87 if (this == o) {
88 return true;
89 }
90 if (o == null || getClass() != o.getClass()) {
91 return false;
92 }
93 PiCloneSessionEntryHandle that = (PiCloneSessionEntryHandle) o;
94 return Objects.equal(deviceId(), that.deviceId()) &&
95 Objects.equal(sessionId, that.sessionId);
96 }
97
98 @Override
99 public String toString() {
100 return MoreObjects.toStringHelper(this)
101 .add("deviceId", deviceId())
102 .add("sessionId", sessionId)
103 .toString();
104 }
105}