Open Kilda Java Documentation
TopologyChecker.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.atdd.staging.helpers;
17 
18 import static java.lang.String.format;
19 import static org.hamcrest.Matchers.equalTo;
20 
28 
29 import org.hamcrest.BaseMatcher;
30 import org.hamcrest.Description;
31 import org.hamcrest.beans.HasPropertyWithValue;
32 
33 public final class TopologyChecker {
34 
42  public static boolean isIslEqual(TopologyDefinition.Isl linkDef, IslInfoData islInfoData) {
43  PathNode discoveredSrcNode = islInfoData.getPath().get(0);
44  PathNode discoveredDstNode = islInfoData.getPath().get(1);
45  return discoveredSrcNode.getSwitchId().equals(linkDef.getSrcSwitch().getDpId())
46  && discoveredSrcNode.getPortNo() == linkDef.getSrcPort()
47  && discoveredDstNode.getSwitchId().equals(linkDef.getDstSwitch().getDpId())
48  && discoveredDstNode.getPortNo() == linkDef.getDstPort();
49  }
50 
51  public static class SwitchMatcher extends HasPropertyWithValue<SwitchInfoData> {
52 
53  private Switch sw;
54 
55  public SwitchMatcher(Switch sw) {
56  super("switchId", equalTo(sw.getDpId()));
57  this.sw = sw;
58  }
59 
60  @Override
61  public void describeTo(Description description) {
62  description.appendValue(format("%s %s", sw.getName(), sw.getDpId()));
63  }
64  }
65 
66  public static class SwitchEntryMatcher extends HasPropertyWithValue<SwitchEntry> {
67 
68  private Switch sw;
69 
70  public SwitchEntryMatcher(Switch sw) {
71  super("switchId", equalTo(sw.getDpId()));
72  this.sw = sw;
73  }
74 
75  @Override
76  public void describeTo(Description description) {
77  description.appendValue(format("%s %s", sw.getName(), sw.getDpId()));
78  }
79  }
80 
81  public static class IslMatcher extends BaseMatcher<IslInfoData> {
82 
83  private Isl isl;
84 
85  public IslMatcher(Isl isl) {
86  this.isl = isl;
87  }
88 
89  @Override
90  public void describeTo(Description description) {
91  description.appendText(format("%s %s-%d => %s %s-%d",
92  isl.getSrcSwitch().getName(), isl.getSrcSwitch().getDpId(), isl.getSrcPort(),
93  isl.getDstSwitch().getName(), isl.getDstSwitch().getDpId(), isl.getDstPort()));
94  }
95 
96  @Override
97  public boolean matches(Object actualValue) {
98  return TopologyChecker.isIslEqual(isl, (IslInfoData) actualValue);
99  }
100  }
101 
102  private TopologyChecker() {
103  }
104 }
static boolean isIslEqual(TopologyDefinition.Isl linkDef, IslInfoData islInfoData)
description
Definition: setup.py:26