Open Kilda Java Documentation
SimpleSwitch.java
Go to the documentation of this file.
1 /* Copyright 2018 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.pce.model;
17 
19 
20 import java.util.HashMap;
21 import java.util.HashSet;
22 import java.util.Map;
23 import java.util.Objects;
24 import java.util.Set;
25 
30 public class SimpleSwitch implements Comparable<SimpleSwitch> {
31 
35  public final SwitchId dpid;
36 
43  public final Map<SwitchId, Set<SimpleIsl>> outbound;
44 
48  private SimpleSwitch() {
49  this(new SwitchId("00"));
50  }
51 
53  this.dpid = dpid;
54  this.outbound = new HashMap<>();
55  }
56 
58  outbound.computeIfAbsent(isl.getDstDpid(), newSet -> new HashSet<>()).add(isl);
59  return this;
60  }
61 
62  @Override
63  public int compareTo(SimpleSwitch other) {
64  return dpid != null
65  ? dpid.toString().compareTo(other.dpid.toString())
66  : (other.dpid == null) ? 0 : -1;
67  }
68 
69  @Override
70  public boolean equals(Object o) {
71  if (this == o) {
72  return true;
73  }
74  if (!(o instanceof SimpleSwitch)) {
75  return false;
76  }
77  SimpleSwitch that = (SimpleSwitch) o;
78  return Objects.equals(dpid, that.dpid)
79  && Objects.equals(outbound, that.outbound);
80  }
81 
82  @Override
83  public int hashCode() {
84 
85  return Objects.hash(dpid, outbound);
86  }
87 
88  @Override
89  public String toString() {
90  String result = "\n\tdpid='" + dpid + '\'' + ", outbound=";
91  for (SwitchId dst : outbound.keySet()) {
92  result += "\n\t\tdestination: " + dst + ", isls(" + outbound.get(dst).size() + "): " + outbound.get(dst);
93  }
94  return result;
95  }
96 }
list result
Definition: plan-d.py:72
final Map< SwitchId, Set< SimpleIsl > > outbound
int compareTo(SimpleSwitch other)
SimpleSwitch addOutbound(SimpleIsl isl)