blob: 8c6fbe8d492f4b51e35ef53612a6473345e310a7 [file] [log] [blame]
sangho27462c62015-05-14 00:39:53 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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.segmentrouting;
18
sangho27462c62015-05-14 00:39:53 -070019import java.util.List;
sangho4a5c42a2015-05-20 22:16:38 -070020import java.util.Objects;
sangho27462c62015-05-14 00:39:53 -070021
22import static com.google.common.base.Preconditions.checkNotNull;
23
24/**
25 * Tunnel class.
26 */
27public class DefaultTunnel implements Tunnel {
28
sangho4a5c42a2015-05-20 22:16:38 -070029 private final String id;
sangho27462c62015-05-14 00:39:53 -070030 private final List<Integer> labelIds;
sangho27462c62015-05-14 00:39:53 -070031
32 private int groupId;
sangho4a5c42a2015-05-20 22:16:38 -070033 private boolean allowedToRemoveGroup;
sangho27462c62015-05-14 00:39:53 -070034
35 /**
36 * Creates a Tunnel reference.
37 *
38 * @param tid Tunnel ID
39 * @param labelIds Label stack of the tunnel
40 */
41 public DefaultTunnel(String tid, List<Integer> labelIds) {
sangho4a5c42a2015-05-20 22:16:38 -070042 this.id = checkNotNull(tid);
43 this.labelIds = labelIds;
44 //TODO: need to register the class in Kryo for this
45 //this.labelIds = Collections.unmodifiableList(labelIds);
sangho27462c62015-05-14 00:39:53 -070046 this.groupId = -1;
47 }
48
49 /**
50 * Creates a new DefaultTunnel reference using the tunnel reference.
51 *
52 * @param tunnel DefaultTunnel reference
53 */
54 public DefaultTunnel(DefaultTunnel tunnel) {
sangho4a5c42a2015-05-20 22:16:38 -070055 this.id = tunnel.id;
sangho27462c62015-05-14 00:39:53 -070056 this.labelIds = tunnel.labelIds;
sangho27462c62015-05-14 00:39:53 -070057 this.groupId = tunnel.groupId;
58 }
59
60 @Override
61 public String id() {
sangho4a5c42a2015-05-20 22:16:38 -070062 return this.id;
sangho27462c62015-05-14 00:39:53 -070063 }
64
65 @Override
66 public List<Integer> labelIds() {
67 return this.labelIds;
68 }
69
70 @Override
sangho27462c62015-05-14 00:39:53 -070071 public int groupId() {
72 return this.groupId;
73 }
74
75 @Override
sangho4a5c42a2015-05-20 22:16:38 -070076 public void setGroupId(int id) {
77 this.groupId = id;
sangho27462c62015-05-14 00:39:53 -070078 }
79
sangho4a5c42a2015-05-20 22:16:38 -070080 @Override
81 public boolean equals(Object o) {
82 if (this == o) {
83 return true;
sangho27462c62015-05-14 00:39:53 -070084 }
sangho4a5c42a2015-05-20 22:16:38 -070085
86 if (o instanceof DefaultTunnel) {
87 DefaultTunnel tunnel = (DefaultTunnel) o;
88 // We compare only the tunnel paths.
89 if (tunnel.labelIds.equals(this.labelIds)) {
90 return true;
sangho27462c62015-05-14 00:39:53 -070091 }
sangho27462c62015-05-14 00:39:53 -070092 }
93
sangho4a5c42a2015-05-20 22:16:38 -070094 return false;
sangho27462c62015-05-14 00:39:53 -070095 }
96
sangho4a5c42a2015-05-20 22:16:38 -070097 @Override
98 public int hashCode() {
99 return Objects.hash(labelIds);
100 }
101
102 @Override
103 public boolean isAllowedToRemoveGroup() {
104 return this.allowedToRemoveGroup;
105 }
106
107 @Override
108 public void allowToRemoveGroup(boolean b) {
109 this.allowedToRemoveGroup = b;
110 }
sangho27462c62015-05-14 00:39:53 -0700111}