blob: 1561382b5270cf856b8701913e36a66dc31d56da [file] [log] [blame]
Carolina Fernandezad893432016-07-18 11:11:34 +02001/*
2 * Copyright 2016-present 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.sdxl2;
18
19import com.google.common.base.MoreObjects;
20
21import java.util.Objects;
22
23/**
24 * Abstraction of a L2 Virtual Circuit.
25 * Note the circuit is expressed as a composition of two SDX-L2 Connection Points.
26 */
27public class VirtualCircuit {
28
29 private final String name;
30 private final SdxL2ConnectionPoint sdxl2cplhs;
31 private final SdxL2ConnectionPoint sdxl2cprhs;
32
33 /**
34 * Creates a new Virtual Circuit.
35 *
36 * @param sdxl2cplhs left hand side of the virtual circuit
37 * @param sdxl2cprhs right hand side of the virtual circuit
38 */
39 public VirtualCircuit(SdxL2ConnectionPoint sdxl2cplhs, SdxL2ConnectionPoint sdxl2cprhs) {
40 this.name = sdxl2cplhs.name() + "-" + sdxl2cprhs.name();
41 this.sdxl2cplhs = sdxl2cplhs;
42 this.sdxl2cprhs = sdxl2cprhs;
43 }
44
45 /**
46 * Returns the left hand side of the Virtual Circuit.
47 *
48 * @return SDX-L2 Connection Point
49 */
50 public SdxL2ConnectionPoint lhs() {
51 return sdxl2cplhs;
52 }
53
54 /**
55 * Returns the right hand side of the Virtual Circuit.
56 *
57 * @return SDX-L2 Connection Point
58 */
59 public SdxL2ConnectionPoint rhs() {
60 return sdxl2cprhs;
61 }
62
63 @Override
64 public int hashCode() {
65 return Objects.hash(name, sdxl2cplhs, sdxl2cprhs);
66 }
67
68 @Override
69 public boolean equals(Object obj) {
70 if (this == obj) {
71 return true;
72 }
73 if (obj instanceof VirtualCircuit) {
74 final VirtualCircuit other = (VirtualCircuit) obj;
75 return (Objects.equals(this.sdxl2cplhs, other.sdxl2cplhs) &&
76 Objects.equals(this.sdxl2cprhs, other.sdxl2cprhs)) ||
77 (Objects.equals(this.sdxl2cplhs, other.sdxl2cprhs) &&
78 Objects.equals(this.sdxl2cprhs, other.sdxl2cplhs));
79 }
80 return false;
81 }
82
83 @Override
84 public String toString() {
85 return MoreObjects.toStringHelper(this)
86 .add("name", name)
87 .add("lhs", sdxl2cplhs)
88 .add("rhs", sdxl2cprhs)
89 .toString();
90 }
91}