hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.odtn.utils.tapi; |
| 18 | |
| 19 | import java.util.Objects; |
| 20 | import java.util.UUID; |
| 21 | |
| 22 | import org.slf4j.Logger; |
| 23 | |
| 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | import static org.slf4j.LoggerFactory.getLogger; |
| 26 | |
| 27 | /** |
| 28 | * TAPI Cep reference class. |
| 29 | * <p> |
| 30 | * TAPI reference class should be used in ODTN ServiceApplication |
| 31 | * in order to make independent ServiceApplication implementation from DCS. |
| 32 | */ |
| 33 | public final class TapiCepRef { |
| 34 | |
| 35 | protected final Logger log = getLogger(getClass()); |
| 36 | |
| 37 | private final UUID topologyId; |
| 38 | private final UUID nodeId; |
| 39 | private final UUID nepId; |
| 40 | private final UUID cepId; |
| 41 | |
| 42 | private TapiCepRef(String topologyId, String nodeId, String nepId, String cepId) { |
| 43 | this.topologyId = UUID.fromString(topologyId); |
| 44 | this.nodeId = UUID.fromString(nodeId); |
| 45 | this.nepId = UUID.fromString(nepId); |
| 46 | this.cepId = UUID.fromString(cepId); |
| 47 | } |
| 48 | |
| 49 | public static TapiCepRef create(String topologyId, String nodeId, String nepId, String cepId) { |
| 50 | return new TapiCepRef(topologyId, nodeId, nepId, cepId); |
| 51 | } |
| 52 | |
| 53 | public static TapiCepRef create(TapiNepRef nepRef, String cepId) { |
| 54 | return new TapiCepRef(nepRef.getTopologyId(), nepRef.getNodeId(), nepRef.getNepId(), cepId); |
| 55 | } |
| 56 | |
| 57 | public String getTopologyId() { |
| 58 | return topologyId.toString(); |
| 59 | } |
| 60 | |
| 61 | public String getNodeId() { |
| 62 | return nodeId.toString(); |
| 63 | } |
| 64 | |
| 65 | public String getNepId() { |
| 66 | return nepId.toString(); |
| 67 | } |
| 68 | |
| 69 | public String getCepId() { |
| 70 | return cepId.toString(); |
| 71 | } |
| 72 | |
| 73 | public TapiNepRef getNepRef() { |
| 74 | return new TapiNepRef(topologyId.toString(), nodeId.toString(), nepId.toString()); |
| 75 | } |
| 76 | |
| 77 | public String toString() { |
| 78 | return toStringHelper(getClass()) |
| 79 | .add("topologyId", topologyId) |
| 80 | .add("nodeId", nodeId) |
| 81 | .add("nepId", nepId) |
| 82 | .add("cepId", cepId) |
| 83 | .toString(); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public boolean equals(Object o) { |
| 88 | if (this == o) { |
| 89 | return true; |
| 90 | } |
| 91 | if (!(o instanceof TapiCepRef)) { |
| 92 | return false; |
| 93 | } |
| 94 | TapiCepRef that = (TapiCepRef) o; |
| 95 | return Objects.equals(topologyId, that.topologyId) && |
| 96 | Objects.equals(nodeId, that.nodeId) && |
| 97 | Objects.equals(nepId, that.nepId) && |
| 98 | Objects.equals(cepId, that.cepId); |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public int hashCode() { |
| 103 | return Objects.hash(topologyId, nodeId, nepId, cepId); |
| 104 | } |
| 105 | } |