16 package org.openkilda.pce.cache;
18 import static org.junit.Assert.assertEquals;
33 import org.junit.After;
34 import org.junit.Assert;
35 import org.junit.Before;
36 import org.junit.Test;
38 import java.util.ArrayList;
39 import java.util.Arrays;
40 import java.util.Collections;
41 import java.util.HashSet;
42 import java.util.List;
52 private final Flow firstFlow =
new Flow(
"first-flow", 1,
false,
"first-flow",
55 private final Flow secondFlow =
new Flow(
"second-flow", 1,
false,
"second-flow",
58 private final Flow thirdFlow =
new Flow(
"third-flow", 1,
false,
"third-flow",
61 private final Flow fourthFlow =
new Flow(
"fourth-flow", 1,
false,
"fourth-flow",
64 private final Flow fifthFlow =
new Flow(
"fifth-flow", 1,
false,
"fifth-flow",
68 private final Flow noBandwidthFlow =
new Flow(
"no-bandwidth-flow", 0,
true,
"no-bandwidth-flow",
74 buildNetworkTopology(networkCache);
85 flowCache.
getFlow(firstFlow.getFlowId());
93 assertEquals(newFlow, storedFlow);
103 assertEquals(2, forward.getTransitVlan());
104 assertEquals(
ResourceCache.MIN_METER_ID, forward.getMeterId());
105 assertEquals(
path.getLeft(), forward.getFlowPath());
109 assertEquals(3, reverse.getTransitVlan());
110 assertEquals(
ResourceCache.MIN_METER_ID, reverse.getMeterId());
111 assertEquals(
path.getRight(), reverse.getFlowPath());
113 assertEquals(1, flowCache.
dumpFlows().size());
123 assertEquals(2, forward.getTransitVlan());
124 assertEquals(0, forward.getMeterId());
125 assertEquals(
path.getLeft(), forward.getFlowPath());
129 assertEquals(3, reverse.getTransitVlan());
130 assertEquals(0, reverse.getMeterId());
131 assertEquals(
path.getRight(), reverse.getFlowPath());
133 assertEquals(1, flowCache.
dumpFlows().size());
145 for (
int i = 0;
i < 1000;
i++) {
146 thirdFlow.setFlowId(thirdFlow.getFlowId() +
i);
147 fourthFlow.setFlowId(fourthFlow.getFlowId() +
i);
148 fifthFlow.setFlowId(fifthFlow.getFlowId() +
i);
166 throw new AssertionError(String.format(
167 "Expected exception %s is not raised",
CacheException.class.getName()));
172 String callName = String.format(
"%s.createFlow(...) call", flowCache.getClass().getCanonicalName());
174 String.format(
"Detect VlanId leak in %s", callName),
177 String.format(
"Detect cookies leak in %s", callName),
180 String.format(
"Detect meterId leak in %s", callName),
189 assertEquals(newFlow, oldFlow);
190 assertEquals(0, flowCache.
dumpFlows().size());
203 assertEquals(2, flowCache.resourceCache.
getAllVlanIds().size());
204 assertEquals(1, flowCache.resourceCache.
getAllCookies().size());
212 assertEquals(2, flowCache.resourceCache.
getAllVlanIds().size());
213 assertEquals(1, flowCache.resourceCache.
getAllCookies().size());
215 assertEquals(1, flowCache.
dumpFlows().size());
221 assertEquals(newFlow.hashCode(), oldFlow.
hashCode());
222 assertEquals(oldFlow, newFlow);
234 firstFlow.setBandwidth(0);
239 assertEquals(0, newFlow.
left.getMeterId());
240 assertEquals(0, newFlow.
right.getMeterId());
253 throw new AssertionError(String.format(
254 "Expected exception %s is not raised",
CacheException.class.getName()));
259 String callName = String.format(
"%s.createFlow(...) call", flowCache.getClass().getCanonicalName());
261 String.format(
"Detect VlanId leak in %s", callName),
264 String.format(
"Detect cookies leak in %s", callName),
267 String.format(
"Detect meterId leak in %s", callName),
277 assertEquals(
new HashSet<>(Arrays.asList(first, second, third)), flowCache.
dumpFlows());
289 Set<ImmutablePair<Flow, Flow>> affected;
298 assertEquals(
new HashSet<>(Arrays.asList(first, second)), affected);
301 assertEquals(
new HashSet<>(Arrays.asList(first, second, third)), affected);
304 assertEquals(Collections.singleton(first), affected);
309 Set<ImmutablePair<Flow, Flow>> affected;
317 assertEquals(Collections.singleton(first), affected);
320 assertEquals(Collections.singleton(first), affected);
323 assertEquals(
new HashSet<>(Arrays.asList(first, second)), affected);
326 assertEquals(
new HashSet<>(Arrays.asList(first, second)), affected);
331 Set<ImmutablePair<Flow, Flow>> affected;
340 assertEquals(Collections.singleton(first), affected);
344 assertEquals(Collections.singleton(first), affected);
348 assertEquals(
new HashSet<>(Arrays.asList(first, second)), affected);
352 assertEquals(
new HashSet<>(Arrays.asList(first, second)), affected);
357 Map<String, String> affected;
366 assertEquals(Collections.singleton(second.
getLeft().getFlowId()), affected.keySet());
369 assertEquals(
new HashSet<>(Arrays.asList(first.
getLeft().getFlowId(),
370 second.
getLeft().getFlowId(), third.
getLeft().getFlowId())), affected.keySet());
373 assertEquals(Collections.singleton(first.
getLeft().getFlowId()), affected.keySet());
380 System.out.println(
path.toString());
384 List<PathNode> direct =
new ArrayList<>();
416 assertEquals(expectedDirect,
path.getLeft());
418 List<PathNode> reverse =
new ArrayList<>();
450 assertEquals(expectedReverse,
path.getRight());
463 System.out.println(path43);
465 List<PathNode> nodesForward43 =
new ArrayList<>();
469 nodesForward43.add(
node);
473 nodesForward43.add(
node);
477 nodesForward43.add(
node);
481 nodesForward43.add(
node);
487 List<PathNode> nodesReverse43 =
new ArrayList<>();
491 nodesReverse43.add(
node);
495 nodesReverse43.add(
node);
499 nodesReverse43.add(
node);
503 nodesReverse43.add(
node);
509 assertEquals(islForwardPath43, path43.
left);
510 assertEquals(islReversePath43, path43.
right);
515 System.out.println(path23);
517 List<PathNode> nodesForward23 =
new ArrayList<>();
521 nodesForward23.add(
node);
525 nodesForward23.add(
node);
529 nodesForward23.add(node1);
533 nodesForward23.add(node2);
539 List<PathNode> nodesReverse23 =
new ArrayList<>();
543 nodesReverse23.add(node3);
547 nodesReverse23.add(node4);
551 nodesReverse23.add(
node);
555 nodesReverse23.add(
node);
561 assertEquals(islForwardPath23, path23.
left);
562 assertEquals(islReversePath23, path23.
right);
565 new HashSet<>(Arrays.asList(node1, node2)),
566 new HashSet<>(Arrays.asList(node3, node4)));
575 System.out.println(networkCache.
dumpIsls());
581 private void buildNetworkTopology(
NetworkCache networkCache) {
600 Flow flow =
new Flow();
603 flow.setSourceSwitch(
source.getSwitchId());
605 flow.setBandwidth(bandwidth);
void getPathIntersection()
void setIgnoreBandwidth(Boolean ignoreBandwidth)
ImmutablePair< PathInfoData, PathInfoData > getFlowPath(String flowId)
void getFlowsWithAffectedPathByIsl()
void getFlowsWithAffectedPathBySwitch()
static final IslInfoData isl25
PathComputer withNetwork(MutableNetwork< SwitchInfoData, IslInfoData > network)
static final IslInfoData isl45
Map< String, String > getFlowsWithAffectedEndpoint(SwitchId switchId)
IslInfoData createOrUpdateIsl(IslInfoData isl)
IslInfoData createIsl(IslInfoData isl)
static final IslInfoData isl21
ImmutablePair< Flow, Flow > getFlow(String flowId)
static final IslInfoData isl12
ImmutablePair< PathInfoData, PathInfoData > getPath(Flow flow, AvailableNetwork network, Strategy strategy)
SwitchInfoData createSwitch(SwitchInfoData newSwitch)
void createNoBandwidthFlow()
static final IslInfoData isl42
Set< PathNode > getPathIntersection(PathInfoData firstPath, PathInfoData secondPath)
void getFlowsForUpState()
Map< SwitchId, Set< Integer > > getAllocatedMeters()
Set< Integer > getAllocatedVlans()
Set< ImmutablePair< Flow, Flow > > dumpFlows()
static final IslInfoData isl53
static final long REVERSE_FLOW_COOKIE_MASK
static final IslInfoData isl35
ImmutablePair< Flow, Flow > updateFlow(Flow flow, ImmutablePair< PathInfoData, PathInfoData > path)
static final IslInfoData isl52
Set< Integer > getAllMeterIds(SwitchId switchId)
Set< Integer > getAllVlanIds()
void setSeqId(final int seqId)
void updateNoBandwidthFlow()
static final long FORWARD_FLOW_COOKIE_MASK
static final IslInfoData isl24
void getFlowsWithAffectedPathByPort()
void createSingleSwitchFlows()
ImmutablePair< Flow, Flow > deleteFlow(String flowId)
static final SwitchInfoData sw5
List< PathNode > getPath()
void createAlreadyExistentFlow()
static final SwitchInfoData sw4
void getPathWithNoEnoughAvailableBandwidth()
Set< Integer > getAllCookies()
Set< ImmutablePair< Flow, Flow > > getFlowsWithAffectedPath(SwitchId switchId)
static final SwitchInfoData sw3
ImmutablePair< Flow, Flow > createFlow(Flow flow, ImmutablePair< PathInfoData, PathInfoData > path)
Set< Integer > getAllocatedCookies()
static final SwitchInfoData sw2
static final IslInfoData isl14
static final SwitchInfoData sw1
static final IslInfoData isl54
static final IslInfoData isl41
Set< IslInfoData > dumpIsls()
void getNotExistentFlow()