use of org.openkilda.model.FlowTransitEncapsulation in project open-kilda by telstra.
the class EgressFlowSegmentCommandJsonTest method makeRequest.
@Override
protected EgressFlowSegmentRequest makeRequest() {
SwitchId swId = new SwitchId(1);
EgressFlowSegmentRequestFactory factory = new EgressFlowSegmentRequestFactory(new MessageContext(), new FlowSegmentMetadata("egress-flow-segment-install-request", new Cookie(2), false), new FlowEndpoint(swId, 3, 4), new FlowEndpoint(new SwitchId(swId.toLong() + 1), 6, 7), 9, new FlowTransitEncapsulation(10, FlowEncapsulationType.TRANSIT_VLAN), MirrorConfig.builder().build());
return makeRequest(factory);
}
use of org.openkilda.model.FlowTransitEncapsulation in project open-kilda by telstra.
the class PingServiceTest method testWrapUnwrapCycleVxlan.
@Test
public void testWrapUnwrapCycleVxlan() throws Exception {
Ping ping = new Ping(new NetworkEndpoint(new SwitchId(dpIdAlpha.getLong()), 8), new NetworkEndpoint(new SwitchId(dpIdBeta.getLong()), 9), new FlowTransitEncapsulation(2, FlowEncapsulationType.VXLAN), 3);
moduleContext.getServiceImpl(InputService.class).addTranslator(eq(OFType.PACKET_IN), anyObject(PingInputTranslator.class));
replayAll();
pingService.setup(moduleContext);
byte[] payload = new byte[] { 0x31, 0x32, 0x33, 0x34, 0x35 };
byte[] wrapped = pingService.wrapData(ping, payload).serialize();
IPacket ethernet = new Ethernet().deserialize(wrapped, 0, wrapped.length);
Assert.assertTrue(ethernet instanceof Ethernet);
IPacket ipv4 = ethernet.getPayload();
Assert.assertTrue(ipv4 instanceof IPv4);
IPacket udp = ipv4.getPayload();
Assert.assertTrue(udp instanceof UDP);
Assert.assertEquals(((UDP) udp).getSourcePort(), TransportPort.of(SwitchManager.STUB_VXLAN_UDP_SRC));
Assert.assertEquals(((UDP) udp).getDestinationPort(), TransportPort.of(SwitchManager.VXLAN_UDP_DST));
byte[] udpPayload = udp.getPayload().serialize();
Vxlan vxlan = (Vxlan) new Vxlan().deserialize(udpPayload, 0, udpPayload.length);
Assert.assertEquals((int) ping.getTransitEncapsulation().getId(), vxlan.getVni());
byte[] vxlanPayload = vxlan.getPayload().serialize();
IPacket decoded = new Ethernet().deserialize(vxlanPayload, 0, vxlanPayload.length);
Assert.assertTrue(decoded instanceof Ethernet);
PingWiredView parsed = pingService.unwrapData(dpIdBeta, (Ethernet) decoded);
Assert.assertNotNull(parsed);
Assert.assertArrayEquals(payload, parsed.getPayload());
Assert.assertTrue(parsed.getVlanStack().isEmpty());
}
use of org.openkilda.model.FlowTransitEncapsulation in project open-kilda by telstra.
the class UniFlowPingResponseTest method serializeLoop.
@Test
public void serializeLoop() throws Exception {
NetworkEndpoint endpointAlpha = new NetworkEndpoint(new SwitchId("ff:fe:00:00:00:00:00:01"), 8);
NetworkEndpoint endpointBeta = new NetworkEndpoint(new SwitchId("ff:fe:00:00:00:00:00:02"), 10);
UniFlowPingResponse origin = new UniFlowPingResponse(new Ping(endpointBeta, endpointAlpha, new FlowTransitEncapsulation(4, FlowEncapsulationType.TRANSIT_VLAN), 5), new PingMeters(3L, 2L, 1L), null);
InfoMessage wrapper = new InfoMessage(origin, System.currentTimeMillis(), getClass().getSimpleName());
serializer.serialize(wrapper);
InfoMessage decodedWrapper = (InfoMessage) serializer.deserialize();
InfoData decoded = decodedWrapper.getData();
Assert.assertEquals(String.format("%s object have been mangled in serialisation/deserialization loop", origin.getClass().getName()), origin, decoded);
}
use of org.openkilda.model.FlowTransitEncapsulation in project open-kilda by telstra.
the class CommandBuilderImpl method buildGroupInstallContexts.
@Override
public List<GroupInstallContext> buildGroupInstallContexts(SwitchId switchId, List<Integer> groupIds) {
List<GroupInstallContext> groupInstallContexts = new ArrayList<>();
Map<PathId, MirrorGroup> mirrorGroups = new HashMap<>();
groupIds.stream().map(GroupId::new).map(mirrorGroupRepository::findByGroupId).flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty)).forEach(mirrorGroup -> mirrorGroups.put(mirrorGroup.getPathId(), mirrorGroup));
flowPathRepository.findBySegmentDestSwitch(switchId).forEach(flowPath -> {
if (mirrorGroups.containsKey(flowPath.getPathId())) {
PathSegment segment = flowPath.getSegments().stream().filter(pathSegment -> pathSegment.getDestSwitchId().equals(switchId)).findAny().orElseThrow(() -> new IllegalStateException(format("PathSegment not found, path %s, switch %s", flowPath, switchId)));
Flow flow = flowPath.getFlow();
if (segment.getDestSwitchId().equals(flowPath.getDestSwitchId())) {
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, flow.getDestSwitchId(), flow.getDestPort());
groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).build());
log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
}
}
});
flowPathRepository.findByEndpointSwitch(switchId).forEach(flowPath -> {
if (mirrorGroups.containsKey(flowPath.getPathId())) {
Flow flow = getFlow(flowPath);
if (flowPath.isOneSwitchFlow()) {
SwitchId swId = flowPath.isForward() ? flow.getDestSwitchId() : flow.getSrcSwitchId();
int port = flowPath.isForward() ? flow.getDestPort() : flow.getSrcPort();
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, swId, port);
groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).build());
log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
} else if (flowPath.getSrcSwitchId().equals(switchId)) {
if (flowPath.getSegments().isEmpty()) {
log.warn("Output port was not found for mirror config");
} else {
PathSegment foundIngressSegment = flowPath.getSegments().get(0);
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, foundIngressSegment.getSrcSwitchId(), foundIngressSegment.getSrcPort());
EncapsulationResources encapsulation = getEncapsulationResources(flowPath, flow);
groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).encapsulation(new FlowTransitEncapsulation(encapsulation.getTransitEncapsulationId(), encapsulation.getEncapsulationType())).egressSwitchId(flowPath.getDestSwitchId()).build());
log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
}
}
}
});
return groupInstallContexts;
}
use of org.openkilda.model.FlowTransitEncapsulation in project open-kilda by telstra.
the class FlowFetcher method handleOnDemandYFlowRequest.
private void handleOnDemandYFlowRequest(Tuple input) throws PipelineException {
log.debug("Handle on demand ping request");
YFlowPingRequest request = pullOnDemandYFlowRequest(input);
Optional<YFlow> optionalYFlow = yFlowRepository.findById(request.getYFlowId());
if (!optionalYFlow.isPresent()) {
emitOnDemandYFlowResponse(input, request, format("YFlow %s does not exist", request.getYFlowId()));
return;
}
YFlow yFlow = optionalYFlow.get();
Set<YSubFlow> subFlows = yFlow.getSubFlows();
if (subFlows.isEmpty()) {
emitOnDemandYFlowResponse(input, request, format("YFlow %s has no sub flows", request.getYFlowId()));
return;
}
GroupId groupId = new GroupId(subFlows.size() * DIRECTION_COUNT_PER_FLOW);
List<PingContext> subFlowPingRequests = new ArrayList<>();
for (YSubFlow subFlow : subFlows) {
Flow flow = subFlow.getFlow();
// Load paths to use in PingProducer
flow.getPaths();
flowRepository.detach(flow);
Optional<FlowTransitEncapsulation> transitEncapsulation = getTransitEncapsulation(flow);
if (transitEncapsulation.isPresent()) {
subFlowPingRequests.add(PingContext.builder().group(groupId).kind(Kinds.ON_DEMAND_Y_FLOW).flow(flow).yFlowId(yFlow.getYFlowId()).transitEncapsulation(transitEncapsulation.get()).timeout(request.getTimeout()).build());
} else {
emitOnDemandYFlowResponse(input, request, format("Encapsulation resource not found for sub flow %s of YFlow %s", subFlow.getSubFlowId(), yFlow.getYFlowId()));
return;
}
}
CommandContext commandContext = pullContext(input);
for (PingContext pingContext : subFlowPingRequests) {
emit(input, pingContext, commandContext);
}
}
Aggregations