Open Kilda Java Documentation
FlowValidatorTest.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.wfm.topology.flow.validation;
17 
22 
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 
26 public class FlowValidatorTest {
27  private FlowValidator target = new FlowValidator(flowCache);
28 
29  private static final FlowCache flowCache = new FlowCache();
30  private static final SwitchId SRC_SWITCH = new SwitchId("00:00:00:00:00:00:00:01");
31  private static final int SRC_PORT = 1;
32  private static final int SRC_VLAN = 1;
33  private static final SwitchId DST_SWITCH = new SwitchId("00:00:00:00:00:00:00:02");
34  private static final int DST_PORT = 5;
35  private static final int DST_VLAN = 5;
36 
37  @BeforeClass
38  public static void initCache() {
39  Flow flow = new Flow();
40  flow.setFlowId("1");
41  flow.setSourceSwitch(SRC_SWITCH);
42  flow.setSourcePort(SRC_PORT);
43  flow.setSourceVlan(SRC_VLAN);
44 
45  flow.setDestinationSwitch(DST_SWITCH);
46  flow.setDestinationPort(DST_PORT);
47  flow.setDestinationVlan(DST_VLAN);
48  flowCache.pushFlow(new ImmutablePair<>(flow, flow));
49  }
50 
51  @Test(expected = FlowValidationException.class)
53  Flow flow = new Flow();
54  flow.setSourceSwitch(SRC_SWITCH);
55  flow.setSourcePort(SRC_PORT);
56  flow.setSourceVlan(0);
57 
58  target.checkFlowForEndpointConflicts(flow);
59  }
60 
61  @Test(expected = FlowValidationException.class)
63  Flow flow = new Flow();
64  flow.setSourceSwitch(SRC_SWITCH);
65  flow.setSourcePort(SRC_PORT);
66  flow.setSourceVlan(SRC_VLAN);
67 
68  target.checkFlowForEndpointConflicts(flow);
69  }
70 
71  @Test
73  Flow flow = new Flow();
74  flow.setSourceSwitch(SRC_SWITCH);
75  flow.setSourcePort(SRC_PORT);
76  flow.setSourceVlan(SRC_VLAN + 1);
77 
78  target.checkFlowForEndpointConflicts(flow);
79  }
80 
81  @Test(expected = FlowValidationException.class)
83  Flow flow = new Flow();
84  flow.setSourceSwitch(SRC_SWITCH);
85  flow.setSourcePort(SRC_PORT);
86  flow.setSourceVlan(SRC_VLAN + 1);
87  flow.setDestinationSwitch(DST_SWITCH);
88  flow.setDestinationPort(DST_PORT);
89  flow.setDestinationVlan(0);
90 
91  target.checkFlowForEndpointConflicts(flow);
92  }
93 
94  @Test(expected = FlowValidationException.class)
96  Flow flow = new Flow();
97  flow.setSourceSwitch(SRC_SWITCH);
98  flow.setSourcePort(SRC_PORT);
99  flow.setSourceVlan(SRC_VLAN + 1);
100  flow.setDestinationSwitch(DST_SWITCH);
101  flow.setDestinationPort(DST_PORT);
102  flow.setDestinationVlan(DST_VLAN);
103 
104  target.checkFlowForEndpointConflicts(flow);
105  }
106 
107  @Test
109  Flow flow = new Flow();
110  flow.setSourceSwitch(SRC_SWITCH);
111  flow.setSourcePort(SRC_PORT);
112  flow.setSourceVlan(SRC_VLAN + 1);
113  flow.setDestinationSwitch(DST_SWITCH);
114  flow.setDestinationPort(DST_PORT);
115  flow.setDestinationVlan(DST_VLAN + 1);
116 
117  target.checkFlowForEndpointConflicts(flow);
118  }
119 
120  @Test(expected = FlowValidationException.class)
122  Flow flow = new Flow();
123  flow.setBandwidth(-1);
124 
125  target.checkBandwidth(flow);
126  }
127 }
void pushFlow(ImmutablePair< Flow, Flow > flow)
Definition: FlowCache.java:106