Search in sources :

Example 11 with CommandMessage

use of org.openkilda.messaging.command.CommandMessage 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)

Example 12 with CommandMessage

use of org.openkilda.messaging.command.CommandMessage in project open-kilda by telstra.

the class CacheTopologyTest method flowShouldBeReroutedWhenIslDies.

@Ignore
@Test
public void flowShouldBeReroutedWhenIslDies() throws Exception {
    final String destSwitchId = "destSwitch";
    final String flowId = "flowId";
    sendData(sw);
    SwitchInfoData destSwitch = new SwitchInfoData(destSwitchId, SwitchState.ACTIVATED, StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY);
    sendData(destSwitch);
    List<PathNode> path = ImmutableList.of(new PathNode(sw.getSwitchId(), 0, 0), new PathNode(destSwitch.getSwitchId(), 0, 1));
    IslInfoData isl = new IslInfoData(0L, path, 0L, IslChangeType.DISCOVERED, 0L);
    sendData(isl);
    FlowInfoData flowData = buildFlowInfoData(flowId, sw.getSwitchId(), destSwitchId, path);
    sendData(flowData);
    // mark isl as failed
    flowConsumer.clear();
    isl.setState(IslChangeType.FAILED);
    sendData(isl);
    // we are expecting that flow should be rerouted
    ConsumerRecord<String, String> record = flowConsumer.pollMessage();
    assertNotNull(record);
    CommandMessage message = objectMapper.readValue(record.value(), CommandMessage.class);
    assertNotNull(message);
    FlowRerouteRequest command = (FlowRerouteRequest) message.getData();
    assertTrue(command.getPayload().getFlowId().equals(flowId));
}
Also used : FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) PathNode(org.openkilda.messaging.info.event.PathNode) CommandMessage(org.openkilda.messaging.command.CommandMessage) AbstractStormTest(org.openkilda.wfm.AbstractStormTest)

Example 13 with CommandMessage

use of org.openkilda.messaging.command.CommandMessage in project open-kilda by telstra.

the class CacheTopologyTest method cacheReceivesInfoDataBeforeNetworkDump.

@Test
public void cacheReceivesInfoDataBeforeNetworkDump() throws Exception {
    System.out.println("Cache receives InfoData before NetworkDump Test");
    sendClearState();
    waitDumpRequest();
    // Send switchUpdate info to not initialized bolt
    sendData(sw);
    // Bolt must fail that tuple
    sendNetworkDumpRequest();
    NetworkDump networkDump = getNetworkDump(ctrlConsumer.pollMessage());
    assertTrue(CollectionUtils.isEmpty(networkDump.getSwitches()));
    // Init bolt with dump from TE
    sendNetworkDump(dump);
    // Check if SwitchInfoData is ok
    sendNetworkDumpRequest();
    networkDump = getNetworkDump(ctrlConsumer.pollMessage());
    assertFalse(CollectionUtils.isEmpty(networkDump.getSwitches()));
    Set<String> flowIds = new HashSet<>(Arrays.asList(firstFlowId, secondFlowId));
    ConsumerRecord<String, String> firstRecord = flowConsumer.pollMessage();
    assertNotNull(firstRecord);
    assertNotNull(firstRecord.value());
    CommandMessage commandMessage = objectMapper.readValue(firstRecord.value(), CommandMessage.class);
    FlowRestoreRequest commandData = (FlowRestoreRequest) commandMessage.getData();
    assertNotNull(commandData);
    assertTrue(flowIds.contains(commandData.getPayload().getLeft().getFlowId()));
    ConsumerRecord<String, String> secondRecord = flowConsumer.pollMessage();
    assertNotNull(secondRecord);
    assertNotNull(secondRecord.value());
    commandMessage = objectMapper.readValue(secondRecord.value(), CommandMessage.class);
    commandData = (FlowRestoreRequest) commandMessage.getData();
    assertNotNull(commandData);
    assertTrue(flowIds.contains(commandData.getPayload().getLeft().getFlowId()));
}
Also used : NetworkDump(org.openkilda.messaging.ctrl.state.NetworkDump) FlowRestoreRequest(org.openkilda.messaging.command.flow.FlowRestoreRequest) HashSet(java.util.HashSet) CommandMessage(org.openkilda.messaging.command.CommandMessage) AbstractStormTest(org.openkilda.wfm.AbstractStormTest)

Example 14 with CommandMessage

use of org.openkilda.messaging.command.CommandMessage in project open-kilda by telstra.

the class CacheTopologyTest method flowShouldBeReroutedWhenSwitchGoesDown.

@Test
public void flowShouldBeReroutedWhenSwitchGoesDown() throws Exception {
    sendData(sw);
    SwitchInfoData dstSwitch = new SwitchInfoData();
    dstSwitch.setState(SwitchState.ACTIVATED);
    dstSwitch.setSwitchId("dstSwitch");
    List<PathNode> path = ImmutableList.of(new PathNode(sw.getSwitchId(), 0, 0), new PathNode(dstSwitch.getSwitchId(), 0, 1));
    // create inactive flow
    firstFlow.getLeft().setFlowPath(new PathInfoData(0L, path));
    firstFlow.getRight().setFlowPath(new PathInfoData(0L, Collections.emptyList()));
    firstFlow.getLeft().setState(FlowState.DOWN);
    sendFlowUpdate(firstFlow);
    // create active flow
    secondFlow.getLeft().setFlowPath(new PathInfoData(0L, path));
    secondFlow.getRight().setFlowPath(new PathInfoData(0L, Collections.emptyList()));
    secondFlow.getLeft().setState(FlowState.UP);
    sendFlowUpdate(secondFlow);
    flowConsumer.clear();
    sw.setState(SwitchState.REMOVED);
    sendData(sw);
    // active flow should be rerouted
    ConsumerRecord<String, String> record = flowConsumer.pollMessage();
    assertNotNull(record);
    CommandMessage message = objectMapper.readValue(record.value(), CommandMessage.class);
    assertNotNull(message);
    FlowRerouteRequest command = (FlowRerouteRequest) message.getData();
    assertTrue(command.getPayload().getFlowId().equals(secondFlowId));
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) PathNode(org.openkilda.messaging.info.event.PathNode) CommandMessage(org.openkilda.messaging.command.CommandMessage) AbstractStormTest(org.openkilda.wfm.AbstractStormTest)

Example 15 with CommandMessage

use of org.openkilda.messaging.command.CommandMessage in project open-kilda by telstra.

the class OFELinkBoltTest method cacheRequestCheck.

/**
 * Part of warm mechanism checks. That test verifies doTick sends init message to FL and
 * second tick does nothing.
 */
@Test
public void cacheRequestCheck() throws IOException {
    // do Tick and verify that bolt send message with cache request to right topic
    Tuple tuple = new TupleImpl(context, new Values(""), TASK_ID_BOLT, STREAM_ID_INPUT);
    bolt.doTick(tuple);
    bolt.doTick(tuple);
    ArgumentCaptor<String> captorStreamId = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<List<Tuple>> captorAnchor = ArgumentCaptor.forClass((Class) List.class);
    ArgumentCaptor<Values> captorTuple = ArgumentCaptor.forClass(Values.class);
    Mockito.verify(outputDelegate, only()).emit(captorStreamId.capture(), captorAnchor.capture(), captorTuple.capture());
    assertEquals(config.getKafkaSpeakerTopic(), captorStreamId.getValue());
    Values values = captorTuple.getValue();
    String payload = (String) values.get(1);
    CommandMessage commandMessage = objectMapper.readValue(payload, CommandMessage.class);
    assertTrue(commandMessage.getData() instanceof NetworkCommandData);
}
Also used : Values(org.apache.storm.tuple.Values) List(java.util.List) NetworkCommandData(org.openkilda.messaging.command.discovery.NetworkCommandData) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple) CommandMessage(org.openkilda.messaging.command.CommandMessage) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Aggregations

CommandMessage (org.openkilda.messaging.command.CommandMessage)70 Message (org.openkilda.messaging.Message)36 InfoMessage (org.openkilda.messaging.info.InfoMessage)32 Test (org.junit.Test)19 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)18 Values (org.apache.storm.tuple.Values)11 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)11 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)8 Flow (org.openkilda.messaging.model.Flow)8 IOException (java.io.IOException)7 CommandData (org.openkilda.messaging.command.CommandData)7 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)7 HashSet (java.util.HashSet)6 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)6 CommandWithReplyToMessage (org.openkilda.messaging.command.CommandWithReplyToMessage)5 NetworkCommandData (org.openkilda.messaging.command.discovery.NetworkCommandData)5 InstallOneSwitchFlow (org.openkilda.messaging.command.flow.InstallOneSwitchFlow)5 FlowDeleteRequest (org.openkilda.messaging.command.flow.FlowDeleteRequest)4 FlowPathRequest (org.openkilda.messaging.command.flow.FlowPathRequest)4 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)4