use of org.openkilda.model.FlowTransitEncapsulation in project open-kilda by telstra.
the class RecordHandler method doModifyGroupRequest.
private void doModifyGroupRequest(CommandMessage message) {
SwitchId switchId = ((ModifyGroupRequest) message.getData()).getSwitchId();
MirrorConfig mirrorConfig = ((ModifyGroupRequest) message.getData()).getMirrorConfig();
FlowTransitEncapsulation encapsulation = ((ModifyGroupRequest) message.getData()).getEncapsulation();
SwitchId egressSwitchId = ((ModifyGroupRequest) message.getData()).getEgressSwitchId();
FlowTransitData flowTransitData = null;
if (encapsulation != null) {
flowTransitData = FlowTransitData.builder().ingressSwitchId(switchId).egressSwitchId(egressSwitchId).encapsulation(encapsulation).build();
}
logger.debug("Modify group '{}' for switch '{}'", mirrorConfig.getGroupId().intValue(), switchId);
handleSpeakerCommand(new GroupModifyCommand(new MessageContext(message), switchId, mirrorConfig, flowTransitData));
ModifyGroupResponse response = new ModifyGroupResponse(switchId, mirrorConfig.getGroupId().intValue());
String correlationId = message.getCorrelationId();
InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), correlationId);
getKafkaProducer().sendMessageAndTrack(context.getKafkaSwitchManagerTopic(), correlationId, infoMessage);
}
use of org.openkilda.model.FlowTransitEncapsulation in project open-kilda by telstra.
the class PersistenceDataAdapterTest method shouldProvideCorrectVlanEncapsulation.
@Test
public void shouldProvideCorrectVlanEncapsulation() {
PathId pathId = new PathId("path1");
Set<PathId> pathIds = Sets.newHashSet(pathId);
TransitVlan transitVlan = TransitVlan.builder().flowId("flowId").pathId(pathId).vlan(8).build();
when(transitVlanRepository.findByPathId(pathId, null)).thenReturn(Collections.singletonList(transitVlan));
adapter = PersistenceDataAdapter.builder().pathIds(pathIds).persistenceManager(persistenceManager).build();
FlowTransitEncapsulation actual = adapter.getTransitEncapsulation(pathId, null);
assertEquals(FlowEncapsulationType.TRANSIT_VLAN, actual.getType());
assertEquals(transitVlan.getVlan(), actual.getId().intValue());
adapter.getTransitEncapsulation(pathId, null);
verify(transitVlanRepository).findByPathId(pathId, null);
verifyNoMoreInteractions(transitVlanRepository);
verifyNoInteractions(vxlanRepository);
}
use of org.openkilda.model.FlowTransitEncapsulation in project open-kilda by telstra.
the class PingServiceTest method testWrapUnwrapCycleVlan.
@Test
public void testWrapUnwrapCycleVlan() throws Exception {
Ping ping = new Ping(new NetworkEndpoint(new SwitchId(dpIdAlpha.getLong()), 8), new NetworkEndpoint(new SwitchId(dpIdBeta.getLong()), 9), new FlowTransitEncapsulation(2, FlowEncapsulationType.TRANSIT_VLAN), 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 decoded = new Ethernet().deserialize(wrapped, 0, wrapped.length);
Assert.assertTrue(decoded instanceof Ethernet);
PingWiredView parsed = pingService.unwrapData(dpIdBeta, (Ethernet) decoded);
Assert.assertNotNull(parsed);
Assert.assertArrayEquals(payload, parsed.getPayload());
Assert.assertEquals(ping.getTransitEncapsulation().getId(), parsed.getVlanStack().get(0));
}
use of org.openkilda.model.FlowTransitEncapsulation in project open-kilda by telstra.
the class PingResponseCommandTest method success.
@Test
public void success() throws Exception {
final PingService realPingService = new PingService();
moduleContext.addService(PingService.class, realPingService);
final ISwitchManager realSwitchManager = new SwitchManager();
moduleContext.addService(ISwitchManager.class, realSwitchManager);
InputService inputService = createMock(InputService.class);
moduleContext.addService(InputService.class, inputService);
inputService.addTranslator(eq(OFType.PACKET_IN), anyObject());
replayAll();
final DatapathId dpIdBeta = DatapathId.of(0x0000fffe000002L);
final Ping ping = new Ping(new NetworkEndpoint(new SwitchId(dpIdBeta.getLong()), 8), new NetworkEndpoint(new SwitchId(dpId.getLong()), 9), new FlowTransitEncapsulation(2, FlowEncapsulationType.TRANSIT_VLAN), 3);
final PingData payload = PingData.of(ping);
moduleContext.addConfigParam(new PathVerificationService(), "hmac256-secret", "secret");
realPingService.setup(moduleContext);
byte[] signedPayload = realPingService.getSignature().sign(payload);
byte[] wireData = realPingService.wrapData(ping, signedPayload).serialize();
OFFactory ofFactory = new OFFactoryVer13();
OFPacketIn message = ofFactory.buildPacketIn().setReason(OFPacketInReason.ACTION).setXid(1L).setCookie(PingService.OF_CATCH_RULE_COOKIE).setData(wireData).build();
FloodlightContext metadata = new FloodlightContext();
IPacket decodedEthernet = new Ethernet().deserialize(wireData, 0, wireData.length);
Assert.assertTrue(decodedEthernet instanceof Ethernet);
IFloodlightProviderService.bcStore.put(metadata, IFloodlightProviderService.CONTEXT_PI_PAYLOAD, (Ethernet) decodedEthernet);
OfInput input = new OfInput(iofSwitch, message, metadata);
final PingResponseCommand command = makeCommand(input);
command.call();
final List<Message> replies = kafkaMessageCatcher.getValues();
Assert.assertEquals(1, replies.size());
InfoMessage response = (InfoMessage) replies.get(0);
PingResponse pingResponse = (PingResponse) response.getData();
Assert.assertNull(pingResponse.getError());
Assert.assertNotNull(pingResponse.getMeters());
Assert.assertEquals(payload.getPingId(), pingResponse.getPingId());
}
use of org.openkilda.model.FlowTransitEncapsulation in project open-kilda by telstra.
the class RuleManagerImpl method buildFlowRulesForSwitch.
/**
* Builds command data only for switches present in the map. Silently skips all others.
*/
private List<SpeakerData> buildFlowRulesForSwitch(SwitchId switchId, FlowPath flowPath, DataAdapter adapter) {
List<SpeakerData> result = new ArrayList<>();
Flow flow = adapter.getFlow(flowPath.getPathId());
Switch sw = adapter.getSwitch(switchId);
PathId oppositePathId = flow.getOppositePathId(flowPath.getPathId()).orElse(null);
FlowTransitEncapsulation encapsulation = adapter.getTransitEncapsulation(flowPath.getPathId(), oppositePathId);
if (switchId.equals(flowPath.getSrcSwitchId()) && !flow.isProtectedPath(flowPath.getPathId())) {
// TODO filter out equal shared rules from the result list
result.addAll(buildIngressCommands(sw, flowPath, flow, encapsulation, new HashSet<>(), adapter.getSwitchProperties(switchId), adapter.getFeatureToggles()));
}
if (!flowPath.isOneSwitchFlow()) {
if (switchId.equals(flowPath.getDestSwitchId())) {
result.addAll(buildEgressCommands(sw, flowPath, flow, encapsulation));
}
for (int i = 1; i < flowPath.getSegments().size(); i++) {
PathSegment firstSegment = flowPath.getSegments().get(i - 1);
PathSegment secondSegment = flowPath.getSegments().get(i);
if (switchId.equals(firstSegment.getDestSwitchId()) && switchId.equals(secondSegment.getSrcSwitchId())) {
result.addAll(buildTransitCommands(sw, flowPath, encapsulation, firstSegment, secondSegment));
break;
}
}
if (flow.isLooped() && sw.getSwitchId().equals(flow.getLoopSwitchId()) && !flow.isProtectedPath(flowPath.getPathId())) {
result.addAll(buildTransitLoopCommands(sw, flowPath, flow, encapsulation));
}
}
return result;
}
Aggregations