Search in sources :

Example 1 with ImmutablePair

use of org.openkilda.messaging.model.ImmutablePair in project open-kilda by telstra.

the class CacheBolt method emitRestoreCommands.

private void emitRestoreCommands(Set<ImmutablePair<Flow, Flow>> flows, Tuple tuple) {
    if (flows != null) {
        ResourceCache resourceCache = new ResourceCache();
        for (ImmutablePair<Flow, Flow> flow : flows) {
            resourceCache.allocateFlow(flow);
        }
        for (ImmutablePair<Flow, Flow> flow : flows) {
            try {
                FlowRestoreRequest request = new FlowRestoreRequest(flowCache.buildFlow(flow.getLeft(), new ImmutablePair<>(null, null), resourceCache));
                resourceCache.deallocateFlow(flow);
                Values values = new Values(Utils.MAPPER.writeValueAsString(new CommandMessage(request, System.currentTimeMillis(), UUID.randomUUID().toString(), Destination.WFM)));
                outputCollector.emit(StreamType.WFM_DUMP.toString(), tuple, values);
                logger.info("Flow {} restore command message sent", flow.getLeft().getFlowId());
            } catch (JsonProcessingException exception) {
                logger.error("Could not format flow restore request by flow={}", flow, exception);
            }
        }
    }
}
Also used : ImmutablePair(org.openkilda.messaging.model.ImmutablePair) Values(org.apache.storm.tuple.Values) FlowRestoreRequest(org.openkilda.messaging.command.flow.FlowRestoreRequest) ResourceCache(org.openkilda.pce.cache.ResourceCache) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Flow(org.openkilda.messaging.model.Flow) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 2 with ImmutablePair

use of org.openkilda.messaging.model.ImmutablePair in project open-kilda by telstra.

the class CacheTopologyTest method buildFlowInfoData.

private FlowInfoData buildFlowInfoData(String flowId, String srcSwitch, String dstSwitch, List<PathNode> path) {
    Flow flow = new Flow();
    flow.setFlowId(flowId);
    flow.setSourceSwitch(srcSwitch);
    flow.setDestinationSwitch(dstSwitch);
    flow.setState(FlowState.UP);
    PathInfoData pathInfoData = new PathInfoData(0L, path);
    flow.setFlowPath(pathInfoData);
    ImmutablePair<Flow, Flow> immutablePair = new ImmutablePair<>(flow, flow);
    return new FlowInfoData(flowId, immutablePair, FlowOperation.CREATE, UUID.randomUUID().toString());
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) ImmutablePair(org.openkilda.messaging.model.ImmutablePair) Flow(org.openkilda.messaging.model.Flow)

Example 3 with ImmutablePair

use of org.openkilda.messaging.model.ImmutablePair in project open-kilda by telstra.

the class FlowCrudSteps method eachFlowIsCreatedAndStoredInTopologyEngine.

@Then("^each flow is created and stored in TopologyEngine$")
public void eachFlowIsCreatedAndStoredInTopologyEngine() {
    List<Flow> expextedFlows = flows.stream().map(flow -> new Flow(flow.getId(), flow.getMaximumBandwidth(), flow.isIgnoreBandwidth(), 0, flow.getId(), null, flow.getSource().getSwitchId(), flow.getDestination().getSwitchId(), flow.getSource().getPortId(), flow.getDestination().getPortId(), flow.getSource().getVlanId(), flow.getDestination().getVlanId(), 0, 0, null, null)).collect(toList());
    for (Flow expectedFlow : expextedFlows) {
        ImmutablePair<Flow, Flow> flowPair = Failsafe.with(retryPolicy.abortIf(Objects::nonNull)).get(() -> topologyEngineService.getFlow(expectedFlow.getFlowId()));
        assertNotNull(format("The flow '%s' is missing.", expectedFlow.getFlowId()), flowPair);
        assertThat(format("The flow '%s' is different.", expectedFlow.getFlowId()), flowPair.getLeft(), is(equalTo(expectedFlow)));
    }
}
Also used : RangeSet(com.google.common.collect.RangeSet) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) Assert.assertThat(org.junit.Assert.assertThat) Given(cucumber.api.java.en.Given) NorthboundService(org.openkilda.atdd.staging.service.northbound.NorthboundService) FloodlightService(org.openkilda.atdd.staging.service.floodlight.FloodlightService) Then(cucumber.api.java.en.Then) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) Matchers.reflectEquals(com.nitorcreations.Matchers.reflectEquals) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) ImmutablePair(org.openkilda.messaging.model.ImmutablePair) Collections.emptyList(java.util.Collections.emptyList) Range(com.google.common.collect.Range) TopologyChecker(org.openkilda.atdd.staging.steps.helpers.TopologyChecker) FlowEndpointPayload(org.openkilda.messaging.payload.flow.FlowEndpointPayload) RetryPolicy(net.jodah.failsafe.RetryPolicy) UUID(java.util.UUID) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) TopologyEngineService(org.openkilda.atdd.staging.service.topology.TopologyEngineService) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) ContiguousSet(com.google.common.collect.ContiguousSet) Switch(org.openkilda.atdd.staging.model.topology.TopologyDefinition.Switch) TreeRangeSet(com.google.common.collect.TreeRangeSet) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) DiscreteDomain(com.google.common.collect.DiscreteDomain) And(cucumber.api.java.en.And) Flow(org.openkilda.messaging.model.Flow) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Failsafe(net.jodah.failsafe.Failsafe) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) Assert.assertNull(org.junit.Assert.assertNull) OutPort(org.openkilda.atdd.staging.model.topology.TopologyDefinition.OutPort) En(cucumber.api.java8.En) FlowState(org.openkilda.messaging.payload.flow.FlowState) VisibleForTesting(com.google.common.annotations.VisibleForTesting) When(cucumber.api.java.en.When) TopologyDefinition(org.openkilda.atdd.staging.model.topology.TopologyDefinition) Objects(java.util.Objects) Flow(org.openkilda.messaging.model.Flow) Then(cucumber.api.java.en.Then)

Example 4 with ImmutablePair

use of org.openkilda.messaging.model.ImmutablePair in project open-kilda by telstra.

the class StormTopologyLCM method allStormTopologiesInTheSameState.

/**
 * We compare old inner state of cache bolt and OFELinkBolt with new state after reload
 * topologies.
 */
@And("^all storm topologies in the same state$")
public void allStormTopologiesInTheSameState() throws Throwable {
    DumpStateManager actualSateDumpsFromBolts = kafkaUtils.getStateDumpsFromBolts();
    // CacheBolt part
    Set<ImmutablePair<Flow, Flow>> actualCacheBoltFlows = actualSateDumpsFromBolts.getCacheBoltState().getFlowDump().getFlows();
    Set<ImmutablePair<Flow, Flow>> expectedCacheBoltFlows = expectedStateDumpsFromBolts.getCacheBoltState().getFlowDump().getFlows();
    assertTrue(CollectionUtils.isEqualCollection(actualCacheBoltFlows, expectedCacheBoltFlows));
    // OFELinkBolt
    OFELinkBoltState actualOfeLinkBoltState = actualSateDumpsFromBolts.getOfeLinkBoltState();
    OFELinkBoltState expectedOfeLinkBoltState = expectedStateDumpsFromBolts.getOfeLinkBoltState();
    assertTrue(CollectionUtils.isEqualCollection(expectedOfeLinkBoltState.getDiscovery(), actualOfeLinkBoltState.getDiscovery()));
}
Also used : DumpStateManager(org.openkilda.messaging.ctrl.state.visitor.DumpStateManager) OFELinkBoltState(org.openkilda.messaging.ctrl.state.OFELinkBoltState) ImmutablePair(org.openkilda.messaging.model.ImmutablePair) And(cucumber.api.java.en.And)

Example 5 with ImmutablePair

use of org.openkilda.messaging.model.ImmutablePair in project open-kilda by telstra.

the class FlowCache method buildFlow.

/**
 * Builds new forward and reverse flow pair.
 *
 * @param flow  source flow
 * @param path  flow path
 * @param cache resource cache
 * @return new forward and reverse flow pair
 */
public ImmutablePair<Flow, Flow> buildFlow(final ImmutablePair<Flow, Flow> flow, ImmutablePair<PathInfoData, PathInfoData> path, ResourceCache cache) {
    String timestamp = Utils.getIsoTimestamp();
    int cookie = cache.allocateCookie((int) flow.getLeft().getCookie());
    Flow forward = new Flow(flow.getLeft().getFlowId(), flow.getLeft().getBandwidth(), false, cookie | ResourceCache.FORWARD_FLOW_COOKIE_MASK, flow.getLeft().getDescription(), timestamp, flow.getLeft().getSourceSwitch(), flow.getLeft().getDestinationSwitch(), flow.getLeft().getSourcePort(), flow.getLeft().getDestinationPort(), flow.getLeft().getSourceVlan(), flow.getLeft().getDestinationVlan(), cache.allocateMeterId(flow.getLeft().getSourceSwitch(), flow.getLeft().getMeterId()), cache.allocateVlanId(flow.getLeft().getTransitVlan()), path.getLeft(), FlowState.ALLOCATED);
    Flow reverse = new Flow(flow.getRight().getFlowId(), flow.getRight().getBandwidth(), false, cookie | ResourceCache.REVERSE_FLOW_COOKIE_MASK, flow.getRight().getDescription(), timestamp, flow.getRight().getSourceSwitch(), flow.getRight().getDestinationSwitch(), flow.getRight().getSourcePort(), flow.getRight().getDestinationPort(), flow.getRight().getSourceVlan(), flow.getRight().getDestinationVlan(), cache.allocateMeterId(flow.getRight().getSourceSwitch(), flow.getRight().getMeterId()), cache.allocateVlanId(flow.getRight().getTransitVlan()), path.getRight(), FlowState.ALLOCATED);
    return new ImmutablePair<>(forward, reverse);
}
Also used : ImmutablePair(org.openkilda.messaging.model.ImmutablePair) Flow(org.openkilda.messaging.model.Flow)

Aggregations

ImmutablePair (org.openkilda.messaging.model.ImmutablePair)12 Flow (org.openkilda.messaging.model.Flow)7 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)5 And (cucumber.api.java.en.And)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 Test (org.junit.Test)2 CacheException (org.openkilda.messaging.error.CacheException)2 PathNode (org.openkilda.messaging.info.event.PathNode)2 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ContiguousSet (com.google.common.collect.ContiguousSet)1 DiscreteDomain (com.google.common.collect.DiscreteDomain)1 Range (com.google.common.collect.Range)1 RangeSet (com.google.common.collect.RangeSet)1 TreeRangeSet (com.google.common.collect.TreeRangeSet)1 MutableNetwork (com.google.common.graph.MutableNetwork)1