Search in sources :

Example 1 with IslInfoData

use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.

the class TestUtils method createTopology.

public static Set<CommandMessage> createTopology(final SwitchService switchService, final IslService islService) {
    Set<CommandMessage> commands = new HashSet<>();
    switchService.add(new SwitchInfoData(srcSwitchId, SwitchEventType.ADDED, address, name, "OVS 1"));
    switchService.add(new SwitchInfoData(firstTransitSwitchId, SwitchEventType.ADDED, address, name, "OVS 2"));
    switchService.add(new SwitchInfoData(secondTransitSwitchId, SwitchEventType.ADDED, address, name, "OVS 1"));
    switchService.add(new SwitchInfoData(dstSwitchId, SwitchEventType.ADDED, address, name, "OVS 2"));
    switchService.activate(new SwitchInfoData(srcSwitchId, SwitchEventType.ACTIVATED, address, name, "OVS 1"));
    switchService.activate(new SwitchInfoData(firstTransitSwitchId, SwitchEventType.ACTIVATED, address, name, "OVS 2"));
    switchService.activate(new SwitchInfoData(secondTransitSwitchId, SwitchEventType.ACTIVATED, address, name, "OVS 1"));
    switchService.activate(new SwitchInfoData(dstSwitchId, SwitchEventType.ACTIVATED, address, name, "OVS 2"));
    PathNode srcNode;
    PathNode dstNode;
    List<PathNode> list;
    srcNode = new PathNode(srcSwitchId, 1, 0);
    dstNode = new PathNode(firstTransitSwitchId, 2, 1);
    list = asList(srcNode, dstNode);
    islService.discoverLink(new IslInfoData(10L, list, portSpeed));
    islService.discoverLink(new IslInfoData(10L, Lists.reverse(list), portSpeed));
    srcNode = new PathNode(firstTransitSwitchId, 1, 0);
    dstNode = new PathNode(secondTransitSwitchId, 2, 1);
    list = asList(srcNode, dstNode);
    islService.discoverLink(new IslInfoData(10L, list, portSpeed));
    islService.discoverLink(new IslInfoData(10L, Lists.reverse(list), portSpeed));
    srcNode = new PathNode(secondTransitSwitchId, 1, 0);
    dstNode = new PathNode(dstSwitchId, 2, 1);
    list = asList(srcNode, dstNode);
    islService.discoverLink(new IslInfoData(10L, list, portSpeed));
    islService.discoverLink(new IslInfoData(10L, Lists.reverse(list), portSpeed));
    commands.add(new CommandMessage(new InstallIngressFlow(0L, flowId, COOKIE, srcSwitchId, DIRECT_INCOMING_PORT, DIRECT_OUTGOING_PORT, INPUT_VLAN_ID, TRANSIT_VLAN_ID, OutputVlanType.REPLACE, 10000L, 0L), METER_ID, DEFAULT_CORRELATION_ID, Destination.WFM));
    commands.add(new CommandMessage(new InstallTransitFlow(0L, flowId, COOKIE, firstTransitSwitchId, DIRECT_INCOMING_PORT, DIRECT_OUTGOING_PORT, TRANSIT_VLAN_ID), 0L, DEFAULT_CORRELATION_ID, Destination.WFM));
    commands.add(new CommandMessage(new InstallTransitFlow(0L, flowId, COOKIE, secondTransitSwitchId, DIRECT_INCOMING_PORT, DIRECT_OUTGOING_PORT, TRANSIT_VLAN_ID), 0L, DEFAULT_CORRELATION_ID, Destination.WFM));
    commands.add(new CommandMessage(new InstallEgressFlow(0L, flowId, COOKIE, dstSwitchId, DIRECT_INCOMING_PORT, DIRECT_OUTGOING_PORT, TRANSIT_VLAN_ID, OUTPUT_VLAN_ID, OutputVlanType.REPLACE), 0L, DEFAULT_CORRELATION_ID, Destination.WFM));
    commands.add(new CommandMessage(new InstallIngressFlow(0L, flowId, COOKIE, srcSwitchId, REVERSE_INGOING_PORT, REVERSE_OUTGOING_PORT, OUTPUT_VLAN_ID, TRANSIT_VLAN_ID, OutputVlanType.REPLACE, 10000L, 0L), METER_ID, DEFAULT_CORRELATION_ID, Destination.WFM));
    commands.add(new CommandMessage(new InstallTransitFlow(0L, flowId, COOKIE, srcSwitchId, REVERSE_INGOING_PORT, REVERSE_OUTGOING_PORT, TRANSIT_VLAN_ID), 0L, DEFAULT_CORRELATION_ID, Destination.WFM));
    commands.add(new CommandMessage(new InstallTransitFlow(0L, flowId, COOKIE, srcSwitchId, REVERSE_INGOING_PORT, REVERSE_OUTGOING_PORT, TRANSIT_VLAN_ID), 0L, DEFAULT_CORRELATION_ID, Destination.WFM));
    commands.add(new CommandMessage(new InstallEgressFlow(0L, flowId, COOKIE, srcSwitchId, REVERSE_INGOING_PORT, REVERSE_OUTGOING_PORT, 2, INPUT_VLAN_ID, OutputVlanType.REPLACE), 0L, DEFAULT_CORRELATION_ID, Destination.WFM));
    return commands;
}
Also used : InstallIngressFlow(org.openkilda.messaging.command.flow.InstallIngressFlow) InstallTransitFlow(org.openkilda.messaging.command.flow.InstallTransitFlow) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) PathNode(org.openkilda.messaging.info.event.PathNode) InstallEgressFlow(org.openkilda.messaging.command.flow.InstallEgressFlow) CommandMessage(org.openkilda.messaging.command.CommandMessage) HashSet(java.util.HashSet)

Example 2 with IslInfoData

use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.

the class IslServiceImplTest method discoverBidirectionalIsl.

@Test
public void discoverBidirectionalIsl() throws Exception {
    PathNode srcNode = new PathNode(srcSwitchId, 1, 0);
    PathNode dstNode = new PathNode(dstSwitchId, 1, 1);
    List<PathNode> list = new ArrayList<>();
    list.add(srcNode);
    list.add(dstNode);
    IslInfoData forwardIsl = new IslInfoData(10L, list, 10000000L);
    IslInfoData reverseIsl = new IslInfoData(20L, Lists.reverse(list), 10000000L);
    islService.discoverLink(forwardIsl);
    islService.discoverLink(reverseIsl);
    Isl isl = islService.getLink(forwardIsl);
    assertNotNull(isl);
    assertEquals(10L, isl.getLatency());
    isl = islService.getLink(reverseIsl);
    assertNotNull(isl);
    assertEquals(20L, isl.getLatency());
}
Also used : Isl(org.openkilda.topology.domain.Isl) ArrayList(java.util.ArrayList) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PathNode(org.openkilda.messaging.info.event.PathNode) Test(org.junit.Test)

Example 3 with IslInfoData

use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.

the class CacheBolt method doWork.

/**
 * {@inheritDoc}
 */
@Override
public void doWork(Tuple tuple) {
    if (CtrlAction.boltHandlerEntrance(this, tuple))
        return;
    logger.trace("State before: {}", state);
    String json = tuple.getString(0);
    String source = tuple.getSourceComponent();
    // TODO: Eliminate the inefficiency introduced through the hack
    try {
        logger.info("Received cache data={}", tuple);
        BaseMessage bm = MAPPER.readValue(json, BaseMessage.class);
        if (bm instanceof InfoMessage) {
            InfoMessage message = (InfoMessage) bm;
            InfoData data = message.getData();
            if (data instanceof NetworkInfoData) {
                logger.debug("Storage content message {}", json);
                handleNetworkDump(data, tuple);
                isReceivedCacheInfo = true;
            } else if (!isReceivedCacheInfo) {
                logger.debug("Cache message fail due bolt not initialized: " + "component={}, stream={}, tuple={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple);
            } else if (data instanceof SwitchInfoData) {
                logger.info("Cache update switch info data: {}", data);
                handleSwitchEvent((SwitchInfoData) data, tuple);
            } else if (data instanceof IslInfoData) {
                logger.info("Cache update isl info data: {}", data);
                handleIslEvent((IslInfoData) data, tuple);
            } else if (data instanceof PortInfoData) {
                logger.info("Cache update port info data: {}", data);
                handlePortEvent((PortInfoData) data, tuple);
            } else if (data instanceof FlowInfoData) {
                logger.info("Cache update flow data: {}", data);
                FlowInfoData flowData = (FlowInfoData) data;
                handleFlowEvent(flowData, tuple);
            } else if (data instanceof NetworkTopologyChange) {
                logger.info("Switch flows reroute request");
                NetworkTopologyChange topologyChange = (NetworkTopologyChange) data;
                handleNetworkTopologyChangeEvent(topologyChange, tuple);
            } else {
                logger.error("Skip undefined info data type {}", json);
            }
        } else {
            logger.error("Skip undefined message type {}", json);
        }
    } catch (CacheException exception) {
        logger.error("Could not process message {}", tuple, exception);
    } catch (IOException exception) {
        logger.error("Could not deserialize message {}", tuple, exception);
    } finally {
        if (isReceivedCacheInfo) {
            outputCollector.ack(tuple);
        } else {
            outputCollector.fail(tuple);
        }
    }
    logger.trace("State after: {}", state);
}
Also used : NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) BaseMessage(org.openkilda.messaging.BaseMessage) CacheException(org.openkilda.messaging.error.CacheException) InfoMessage(org.openkilda.messaging.info.InfoMessage) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) InfoData(org.openkilda.messaging.info.InfoData) FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) IOException(java.io.IOException) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) NetworkTopologyChange(org.openkilda.messaging.info.event.NetworkTopologyChange)

Example 4 with IslInfoData

use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.

the class IslStatsBolt method execute.

@Override
public void execute(Tuple tuple) {
    logger.debug("tuple: " + tuple);
    String json = getJson(tuple);
    try {
        Message message = getMessage(json);
        IslInfoData data = getIslInfoData(getInfoData(message));
        List<Object> results = buildTsdbTuple(data, message.getTimestamp());
        logger.debug("emit: " + results);
        collector.emit(results);
    } catch (IOException e) {
        logger.error("Could not deserialize message={}", json, e);
    } catch (Exception e) {
    // TODO: has to be a cleaner way to do this?
    } finally {
        collector.ack(tuple);
    }
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) IOException(java.io.IOException) IOException(java.io.IOException)

Example 5 with IslInfoData

use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.

the class OFEventWfmTest method basicLinkDiscoveryTest.

/**
 * BasicLinkDiscoveryTest will exercise the basics of Link Discovery test.
 * The key results should show up in a kafka topic, which are dumped to file.
 */
@Test
@Ignore
public void basicLinkDiscoveryTest() throws IOException, ConfigurationException, CmdLineException {
    System.out.println("==> Starting BasicLinkDiscoveryTest");
    OFEventWFMTopology manager = new OFEventWFMTopology(makeLaunchEnvironment());
    TopologyConfig config = manager.getConfig();
    String topo_input_topic = config.getKafkaTopoDiscoTopic();
    Tuple tuple;
    KeyValueState<String, Object> state = new InMemoryKeyValueState<>();
    initMocks(topo_input_topic);
    List<PathNode> nodes = Arrays.asList(new PathNode("sw1", 1, 0, 10L), new PathNode("sw2", 2, 1, 10L));
    InfoData data = new IslInfoData(10L, nodes, 10000L, IslChangeType.DISCOVERED, 9000L);
    String isl_discovered = MAPPER.writeValueAsString(data);
    OFELinkBolt linkBolt = new OFELinkBolt(config);
    linkBolt.prepare(stormConfig(), topologyContext, outputCollector);
    linkBolt.initState(state);
    ArrayList<DiscoveryFilterEntity> skipNodes = new ArrayList<>(1);
    skipNodes.add(new DiscoveryFilterEntity("sw1", "1"));
    CommandMessage islFilterSetup = new CommandMessage(new DiscoveryFilterPopulateData(skipNodes), 1, "discovery-test", Destination.WFM_OF_DISCOVERY);
    String json = MAPPER.writeValueAsString(islFilterSetup);
    tuple = new TupleImpl(topologyContext, Collections.singletonList(json), 4, "message");
    linkBolt.execute(tuple);
    tuple = new TupleImpl(topologyContext, Arrays.asList("sw1", OFEMessageUtils.SWITCH_UP), 0, topo_input_topic);
    linkBolt.execute(tuple);
    tuple = new TupleImpl(topologyContext, Arrays.asList("sw2", OFEMessageUtils.SWITCH_UP), 0, topo_input_topic);
    linkBolt.execute(tuple);
    tuple = new TupleImpl(topologyContext, Arrays.asList("sw1", "1", OFEMessageUtils.PORT_UP), 1, topo_input_topic);
    linkBolt.execute(tuple);
    tuple = new TupleImpl(topologyContext, Arrays.asList("sw1", "2", OFEMessageUtils.PORT_UP), 1, topo_input_topic);
    linkBolt.execute(tuple);
    Tuple tickTuple = new TupleImpl(topologyContext, Collections.emptyList(), 2, Constants.SYSTEM_TICK_STREAM_ID);
    linkBolt.execute(tickTuple);
    tuple = new TupleImpl(topologyContext, Collections.singletonList(isl_discovered), 3, topo_input_topic);
    linkBolt.execute(tuple);
    linkBolt.execute(tickTuple);
    linkBolt.execute(tickTuple);
    // 1 isls, 3 seconds interval, 9 seconds test duration == 3 discovery commands
    // there is only 1 isl each cycle because of isl filter
    // messagesExpected = 3 ;
    // TODO: (crimi) validate is 7 due to merged topics
    messagesExpected = 7;
    messagesReceived = outputCollectorMock.getMessagesCount(config.getKafkaTopoDiscoTopic());
    Assert.assertEquals(messagesExpected, messagesReceived);
    // "isl discovered" x1
    // messagesExpected = 1;
    // TODO: (crimi) validate is 7 due to merged topics
    messagesExpected = 7;
    messagesReceived = outputCollectorMock.getMessagesCount(config.getKafkaTopoDiscoTopic());
    Assert.assertEquals(messagesExpected, messagesReceived);
    linkBolt.execute(tickTuple);
    // no new discovery commands
    // messagesExpected = 3;
    // TODO .. increased from 3 to 7 due to topic changes .. confirm it
    messagesExpected = 7;
    messagesReceived = outputCollectorMock.getMessagesCount(config.getKafkaTopoDiscoTopic());
    Assert.assertEquals(messagesExpected, messagesReceived);
    // +1 discovery fails
    // messagesExpected = 2;
    // TODO .. there should be more or we aren't looking in right place
    messagesExpected = 7;
    messagesReceived = outputCollectorMock.getMessagesCount(config.getKafkaTopoDiscoTopic());
    Assert.assertEquals(messagesExpected, messagesReceived);
}
Also used : OFELinkBolt(org.openkilda.wfm.topology.event.OFELinkBolt) ArrayList(java.util.ArrayList) PathNode(org.openkilda.messaging.info.event.PathNode) InMemoryKeyValueState(org.apache.storm.state.InMemoryKeyValueState) CommandMessage(org.openkilda.messaging.command.CommandMessage) DiscoveryFilterEntity(org.openkilda.messaging.command.discovery.DiscoveryFilterEntity) OFEventWFMTopology(org.openkilda.wfm.topology.event.OFEventWFMTopology) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) InfoData(org.openkilda.messaging.info.InfoData) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) TupleImpl(org.apache.storm.tuple.TupleImpl) TopologyConfig(org.openkilda.wfm.topology.TopologyConfig) Tuple(org.apache.storm.tuple.Tuple) DiscoveryFilterPopulateData(org.openkilda.messaging.command.discovery.DiscoveryFilterPopulateData) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

IslInfoData (org.openkilda.messaging.info.event.IslInfoData)51 PathNode (org.openkilda.messaging.info.event.PathNode)29 Test (org.junit.Test)25 Endpoint (org.openkilda.wfm.share.model.Endpoint)12 SwitchId (org.openkilda.model.SwitchId)10 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)9 Isl (org.openkilda.model.Isl)9 InfoMessage (org.openkilda.messaging.info.InfoMessage)8 ArrayList (java.util.ArrayList)6 When (cucumber.api.java.en.When)5 IOException (java.io.IOException)5 InfoData (org.openkilda.messaging.info.InfoData)5 Switch (org.openkilda.model.Switch)5 Then (cucumber.api.java.en.Then)4 List (java.util.List)4 CommandMessage (org.openkilda.messaging.command.CommandMessage)4 Comparator (java.util.Comparator)3 Collectors (java.util.stream.Collectors)3 Message (org.openkilda.messaging.Message)3 CacheException (org.openkilda.messaging.error.CacheException)3