use of org.openkilda.messaging.info.event.IslInfoData 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));
}
use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.
the class IslStatsBoltTest method getIslInfoData.
@Test
public void getIslInfoData() throws Exception {
Object data = statsBolt.getIslInfoData(statsBolt.getInfoData(message));
assertThat(data, instanceOf(IslInfoData.class));
assertEquals(data, islInfoData);
thrown.expect(Exception.class);
thrown.expectMessage(containsString("is not an IslInfoData"));
PortInfoData portData = new PortInfoData();
InfoMessage badMessage = new InfoMessage(portData, TIMESTAMP, CORRELATION, null);
data = statsBolt.getIslInfoData(statsBolt.getIslInfoData(badMessage.getData()));
}
use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.
the class PathVerificationService method handlePacketIn.
private IListener.Command handlePacketIn(IOFSwitch sw, OFPacketIn pkt, FloodlightContext context) {
long time = System.currentTimeMillis();
logger.debug("packet_in {} received from {}", pkt.getXid(), sw.getId());
VerificationPacket verificationPacket = null;
Ethernet eth = IFloodlightProviderService.bcStore.get(context, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
try {
verificationPacket = deserialize(eth);
} catch (Exception exception) {
logger.error("Deserialization failure: {}, exception: {}", exception.getMessage(), exception);
return Command.CONTINUE;
}
try {
OFPort inPort = pkt.getVersion().compareTo(OFVersion.OF_12) < 0 ? pkt.getInPort() : pkt.getMatch().get(MatchField.IN_PORT);
ByteBuffer portBB = ByteBuffer.wrap(verificationPacket.getPortId().getValue());
portBB.position(1);
OFPort remotePort = OFPort.of(portBB.getShort());
long timestamp = 0;
int pathOrdinal = 10;
IOFSwitch remoteSwitch = null;
boolean signed = false;
for (LLDPTLV lldptlv : verificationPacket.getOptionalTLVList()) {
if (lldptlv.getType() == 127 && lldptlv.getLength() == 12 && lldptlv.getValue()[0] == 0x0 && lldptlv.getValue()[1] == 0x26 && lldptlv.getValue()[2] == (byte) 0xe1 && lldptlv.getValue()[3] == 0x0) {
ByteBuffer dpidBB = ByteBuffer.wrap(lldptlv.getValue());
remoteSwitch = switchService.getSwitch(DatapathId.of(dpidBB.getLong(4)));
} else if (lldptlv.getType() == 127 && lldptlv.getLength() == 12 && lldptlv.getValue()[0] == 0x0 && lldptlv.getValue()[1] == 0x26 && lldptlv.getValue()[2] == (byte) 0xe1 && lldptlv.getValue()[3] == 0x01) {
ByteBuffer tsBB = ByteBuffer.wrap(lldptlv.getValue());
/* skip OpenFlow OUI (4 bytes above) */
long swLatency = sw.getLatency().getValue();
timestamp = tsBB.getLong(4);
/* include the RX switch latency to "subtract" it */
timestamp = timestamp + swLatency;
} else if (lldptlv.getType() == 127 && lldptlv.getLength() == 8 && lldptlv.getValue()[0] == 0x0 && lldptlv.getValue()[1] == 0x26 && lldptlv.getValue()[2] == (byte) 0xe1 && lldptlv.getValue()[3] == 0x02) {
ByteBuffer typeBB = ByteBuffer.wrap(lldptlv.getValue());
pathOrdinal = typeBB.getInt(4);
} else if (lldptlv.getType() == 127 && lldptlv.getValue()[0] == 0x0 && lldptlv.getValue()[1] == 0x26 && lldptlv.getValue()[2] == (byte) 0xe1 && lldptlv.getValue()[3] == 0x03) {
ByteBuffer bb = ByteBuffer.wrap(lldptlv.getValue());
bb.position(4);
byte[] tokenArray = new byte[lldptlv.getLength() - 4];
bb.get(tokenArray, 0, tokenArray.length);
String token = new String(tokenArray);
try {
DecodedJWT jwt = verifier.verify(token);
signed = true;
} catch (JWTVerificationException e) {
logger.error("Packet verification failed", e);
return Command.STOP;
}
}
}
if (remoteSwitch == null) {
return Command.STOP;
}
if (!signed) {
logger.warn("verification packet without sign");
return Command.STOP;
}
U64 latency = (timestamp != 0 && (time - timestamp) > 0) ? U64.of(time - timestamp) : U64.ZERO;
logger.debug("link discovered: {}-{} ===( {} ms )===> {}-{}", remoteSwitch.getId(), remotePort, latency.getValue(), sw.getId(), inPort);
// this verification packet was sent from remote switch/port to received switch/port
// so the link direction is from remote switch/port to received switch/port
List<PathNode> nodes = Arrays.asList(new PathNode(remoteSwitch.getId().toString(), remotePort.getPortNumber(), 0, latency.getValue()), new PathNode(sw.getId().toString(), inPort.getPortNumber(), 1));
OFPortDesc port = sw.getPort(inPort);
long speed = Integer.MAX_VALUE;
if (port.getVersion().compareTo(OFVersion.OF_13) > 0) {
for (OFPortDescProp prop : port.getProperties()) {
if (prop.getType() == 0x0) {
speed = ((OFPortDescPropEthernet) prop).getCurrSpeed();
}
}
} else {
speed = port.getCurrSpeed();
}
IslInfoData path = new IslInfoData(latency.getValue(), nodes, speed, IslChangeType.DISCOVERED, getAvailableBandwidth(speed));
Message message = new InfoMessage(path, System.currentTimeMillis(), "system", null);
final String json = MAPPER.writeValueAsString(message);
logger.debug("about to send {}", json);
producer.send(new ProducerRecord<>(TOPIC, json));
logger.debug("packet_in processed for {}-{}", sw.getId(), inPort);
} catch (JsonProcessingException exception) {
logger.error("could not create json for path packet_in: {}", exception.getMessage(), exception);
} catch (UnsupportedOperationException exception) {
logger.error("could not parse packet_in message: {}", exception.getMessage(), exception);
} catch (Exception exception) {
logger.error("unknown error during packet_in message processing: {}", exception.getMessage(), exception);
throw exception;
}
return Command.STOP;
}
use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.
the class KafkaMessageConsumer method receive.
/**
* Receives messages from WorkFlowManager queue.
*
* @param record the message object instance
*/
@KafkaListener(topics = "kilda-test")
public void receive(final String record) {
logger.debug("message received: {}", record);
try {
Message message = MAPPER.readValue(record, Message.class);
if (message.getDestination() == null || Destination.TOPOLOGY_ENGINE.equals(message.getDestination())) {
if (message instanceof CommandMessage) {
CommandData data = ((CommandMessage) message).getData();
if (data instanceof FlowCreateRequest) {
FlowPayload payload = ((FlowCreateRequest) data).getPayload();
logger.debug("FlowCreateRequest: {}", payload);
Set<CommandMessage> commands = flowService.createFlow(payload, message.getCorrelationId());
for (CommandMessage response : commands) {
kafkaMessageProducer.send(topic, response);
}
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else if (data instanceof FlowDeleteRequest) {
FlowIdStatusPayload payload = ((FlowDeleteRequest) data).getPayload();
logger.debug("FlowDeleteRequest: {}", payload);
Set<CommandMessage> commands = flowService.deleteFlow(payload, message.getCorrelationId());
for (CommandMessage response : commands) {
kafkaMessageProducer.send(topic, response);
}
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else if (data instanceof FlowUpdateRequest) {
FlowPayload payload = ((FlowUpdateRequest) data).getPayload();
logger.debug("FlowUpdateRequest: {}", payload);
Set<CommandMessage> commands = flowService.updateFlow(payload, message.getCorrelationId());
for (CommandMessage response : commands) {
kafkaMessageProducer.send(topic, response);
}
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else if (data instanceof FlowGetRequest) {
FlowIdStatusPayload payload = ((FlowGetRequest) data).getPayload();
logger.debug("FlowGetRequest: {}", payload);
InfoMessage response = flowService.getFlow(payload, message.getCorrelationId());
kafkaMessageProducer.send(topic, response);
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else if (data instanceof FlowsGetRequest) {
FlowIdStatusPayload payload = ((FlowsGetRequest) data).getPayload();
logger.debug("FlowsGetRequest: {}", payload);
InfoMessage response = flowService.getFlows(payload, message.getCorrelationId());
kafkaMessageProducer.send(topic, response);
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else if (data instanceof FlowPathRequest) {
FlowIdStatusPayload payload = ((FlowPathRequest) data).getPayload();
logger.debug("FlowPathRequest: {}", payload);
InfoMessage response = flowService.pathFlow(payload, message.getCorrelationId());
kafkaMessageProducer.send(topic, response);
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else {
logger.error("Unexpected command message data type: {}", data);
}
} else if (message instanceof InfoMessage) {
InfoData data = ((InfoMessage) message).getData();
if (data instanceof SwitchInfoData) {
SwitchInfoData payload = (SwitchInfoData) data;
switch(payload.getState()) {
case ADDED:
switchService.add(payload);
break;
case ACTIVATED:
switchService.activate(payload);
break;
case DEACTIVATED:
switchService.deactivate(payload);
break;
case REMOVED:
switchService.remove(payload);
break;
case CHANGED:
default:
break;
}
} else if (data instanceof IslInfoData) {
IslInfoData payload = (IslInfoData) data;
islService.discoverLink(payload);
} else {
logger.debug("Unexpected info message data type: {}", data);
}
}
} else {
logger.debug("Skip message: {}", message);
}
} catch (IOException exception) {
logger.error("Could not deserialize message: {}", record, exception);
}
}
use of org.openkilda.messaging.info.event.IslInfoData in project open-kilda by telstra.
the class DiscoveryMechanismSteps method checkDiscoveredLinks.
@Then("^all provided links should be detected")
public void checkDiscoveredLinks() {
List<IslInfoData> discoveredLinks = topologyEngineService.getActiveLinks();
List<TopologyDefinition.Isl> expectedLinks = topologyDefinition.getIslsForActiveSwitches();
if (CollectionUtils.isEmpty(discoveredLinks) && expectedLinks.isEmpty()) {
scenario.write("There are no links discovered as expected");
return;
}
assertThat("Discovered links don't match expected", discoveredLinks, containsInAnyOrder(expectedLinks.stream().flatMap(link -> {
// in kilda we have forward and reverse isl, that's why we have to divide into 2
Isl pairedLink = Isl.factory(link.getDstSwitch(), link.getDstPort(), link.getSrcSwitch(), link.getSrcPort(), link.getMaxBandwidth());
return Stream.of(link, pairedLink);
}).map(IslMatcher::new).collect(toList())));
}
Aggregations