sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.segmentrouting; |
| 18 | |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 19 | import java.util.List; |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 20 | import java.util.Objects; |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 21 | |
| 22 | import static com.google.common.base.Preconditions.checkNotNull; |
| 23 | |
| 24 | /** |
| 25 | * Tunnel class. |
| 26 | */ |
| 27 | public class DefaultTunnel implements Tunnel { |
| 28 | |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 29 | private final String id; |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 30 | private final List<Integer> labelIds; |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 31 | |
| 32 | private int groupId; |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 33 | private boolean allowedToRemoveGroup; |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 34 | |
| 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) { |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 42 | 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); |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 46 | 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) { |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 55 | this.id = tunnel.id; |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 56 | this.labelIds = tunnel.labelIds; |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 57 | this.groupId = tunnel.groupId; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public String id() { |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 62 | return this.id; |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public List<Integer> labelIds() { |
| 67 | return this.labelIds; |
| 68 | } |
| 69 | |
| 70 | @Override |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 71 | public int groupId() { |
| 72 | return this.groupId; |
| 73 | } |
| 74 | |
| 75 | @Override |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 76 | public void setGroupId(int id) { |
| 77 | this.groupId = id; |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 78 | } |
| 79 | |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 80 | @Override |
| 81 | public boolean equals(Object o) { |
| 82 | if (this == o) { |
| 83 | return true; |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 84 | } |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 85 | |
| 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; |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 91 | } |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 92 | } |
| 93 | |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 94 | return false; |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 95 | } |
| 96 | |
sangho | 0b2b6d1 | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 97 | @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 | } |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 111 | } |