use of org.openkilda.messaging.info.rule.FlowEntry in project open-kilda by telstra.
the class SwitchSyncServiceImplTest method setUp.
@Before
public void setUp() {
RepositoryFactory repositoryFactory = Mockito.mock(RepositoryFactory.class);
FlowRepository flowRepository = Mockito.mock(FlowRepository.class);
FlowPathRepository flowPathRepository = Mockito.mock(FlowPathRepository.class);
TransitVlanRepository transitVlanRepository = Mockito.mock(TransitVlanRepository.class);
when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
when(repositoryFactory.createTransitVlanRepository()).thenReturn(transitVlanRepository);
when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
Properties configProps = new Properties();
configProps.setProperty("flow.meter-id.max", "40");
configProps.setProperty("flow.vlan.max", "50");
PropertiesBasedConfigurationProvider configurationProvider = new PropertiesBasedConfigurationProvider(configProps);
FlowResourcesConfig flowResourcesConfig = configurationProvider.getConfiguration(FlowResourcesConfig.class);
service = new SwitchSyncServiceImpl(carrier, persistenceManager, flowResourcesConfig);
service.commandBuilder = commandBuilder;
request = SwitchValidateRequest.builder().switchId(SWITCH_ID).performSync(true).build();
flowEntry = new FlowEntry(new FlowSegmentCookie(FlowPathDirection.FORWARD, 7).getValue(), 0, 0, 0, 0, "", 0, 0, 0, 0, null, null, null);
InstallIngressFlow installingRule = new InstallIngressFlow(UUID.randomUUID(), FLOW_ID, flowEntry.getCookie(), SWITCH_ID, 1, 2, 50, 0, 60, FlowEncapsulationType.TRANSIT_VLAN, OutputVlanType.POP, 10L, 100L, EGRESS_SWITCH_ID, false, false, false, null);
when(commandBuilder.buildCommandsToSyncMissingRules(eq(SWITCH_ID), any())).thenReturn(singletonList(installingRule));
missingRules = singletonList(flowEntry.getCookie());
excessRules = emptyList();
misconfiguredRules = emptyList();
excessMeters = emptyList();
}
use of org.openkilda.messaging.info.rule.FlowEntry in project open-kilda by telstra.
the class RecordHandler method processDumpRulesRequest.
private void processDumpRulesRequest(SwitchId switchId, java.util.function.Consumer<MessageData> sender) {
try {
logger.debug("Loading installed rules for switch {}", switchId);
List<OFFlowStatsEntry> flowEntries = context.getSwitchManager().dumpFlowTable(DatapathId.of(switchId.toLong()));
List<FlowEntry> flows = flowEntries.stream().map(OfFlowStatsMapper.INSTANCE::toFlowEntry).collect(Collectors.toList());
SwitchFlowEntries response = SwitchFlowEntries.builder().switchId(switchId).flowEntries(flows).build();
sender.accept(response);
} catch (SwitchOperationException e) {
logger.error("Dumping of rules on switch '{}' was unsuccessful: {}", switchId, e.getMessage());
ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription("The switch was not found when requesting a rules dump.").buildData();
sender.accept(errorData);
}
}
use of org.openkilda.messaging.info.rule.FlowEntry in project open-kilda by telstra.
the class IOFSwitchConverter method buildSwitchInfoDataExtended.
/**
* Transforms {@link IOFSwitch} to object that is used throughout kilda in all components.
* @param sw switch data.
* @param eventType switch state.
* @param flowStats installed flows.
* @return converted switch.
*/
public static SwitchInfoExtendedData buildSwitchInfoDataExtended(IOFSwitch sw, SwitchState eventType, OFFlowStatsReply flowStats) {
SwitchInfoData switchInfoData = buildSwitchInfoData(sw, eventType);
List<FlowEntry> flows = flowStats.getEntries().stream().map(OFFlowStatsConverter::toFlowEntry).collect(Collectors.toList());
return new SwitchInfoExtendedData(switchInfoData, flows);
}
use of org.openkilda.messaging.info.rule.FlowEntry in project open-kilda by telstra.
the class YFlowSwitchFlowEntriesBuilder method getFlowEntries.
/**
* Construct a set of {@link FlowEntry} that corresponds to the builder's y-flow.
*/
public Map<SwitchId, Collection<FlowEntry>> getFlowEntries() {
MultiValuedMap<SwitchId, FlowEntry> flowEntries = new ArrayListValuedHashMap<>();
yFlow.getSubFlows().forEach(subFlow -> {
Flow flow = subFlow.getFlow();
SwitchFlowEntriesBuilder builder = new SwitchFlowEntriesBuilder(flow);
int forwardTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getForwardPathId()).orElseThrow(IllegalStateException::new);
int reverseTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getReversePathId()).orElseThrow(IllegalStateException::new);
Integer protectedForwardTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getProtectedForwardPathId()).orElse(null);
Integer protectedReverseTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getProtectedReversePathId()).orElse(null);
builder.getSwitchFlowEntries(forwardTransitEncId, reverseTransitEncId, protectedForwardTransitEncId, protectedReverseTransitEncId).forEach(entries -> flowEntries.putAll(entries.getSwitchId(), entries.getFlowEntries()));
FlowPath forwardPath = flow.getForwardPath();
PathSegment firstSegment = forwardPath.getSegments().get(0);
FlowSegmentCookie forwardCookie = forwardPath.getCookie().toBuilder().yFlow(true).build();
boolean isVxlan = flow.getEncapsulationType() == VXLAN;
flowEntries.put(forwardPath.getSrcSwitchId(), builder.getFlowEntry(forwardCookie.getValue(), flow.getSrcPort(), flow.getSrcVlan(), null, firstSegment.getSrcPort(), isVxlan ? null : forwardTransitEncId, isVxlan ? forwardTransitEncId : null, yFlow.getSharedEndpointMeterId().getValue()));
if (!yFlow.getYPoint().equals(flow.getSrcSwitchId())) {
FlowPath reversePath = flow.getReversePath();
FlowSegmentCookie reverseCookie = reversePath.getCookie().toBuilder().yFlow(true).build();
List<PathSegment> reverseSegments = reversePath.getSegments();
for (int i = 0; i < reverseSegments.size() - 1; i++) {
PathSegment nsegment = reverseSegments.get(i);
PathSegment n1segment = reverseSegments.get(i + 1);
if (nsegment.getDestSwitchId().equals(yFlow.getYPoint())) {
flowEntries.put(yFlow.getYPoint(), builder.getFlowEntry(reverseCookie.getValue(), n1segment.getSrcPort(), isVxlan ? null : reverseTransitEncId, isVxlan ? reverseTransitEncId : null, nsegment.getDestPort(), null, null, yFlow.getMeterId().getValue()));
}
}
}
if (yFlow.isAllocateProtectedPath() && yFlow.getProtectedPathYPoint() != null && !yFlow.getProtectedPathYPoint().equals(flow.getSrcSwitchId())) {
FlowPath reversePath = flow.getProtectedReversePath();
FlowSegmentCookie reverseCookie = reversePath.getCookie().toBuilder().yFlow(true).build();
List<PathSegment> reverseSegments = reversePath.getSegments();
for (int i = 0; i < reverseSegments.size() - 1; i++) {
PathSegment nsegment = reverseSegments.get(i);
PathSegment n1segment = reverseSegments.get(i + 1);
if (nsegment.getDestSwitchId().equals(yFlow.getProtectedPathYPoint())) {
flowEntries.put(yFlow.getProtectedPathYPoint(), builder.getFlowEntry(reverseCookie.getValue(), n1segment.getSrcPort(), isVxlan ? null : reverseTransitEncId, isVxlan ? reverseTransitEncId : null, nsegment.getDestPort(), null, null, yFlow.getProtectedPathMeterId().getValue()));
}
}
}
});
return flowEntries.asMap();
}
use of org.openkilda.messaging.info.rule.FlowEntry in project open-kilda by telstra.
the class OfFlowStatsMapperTest method testFlowEntry.
@Test
public void testFlowEntry() {
OFFlowStatsEntry ofEntry = buildFlowStatsEntry();
FlowEntry entry = OfFlowStatsMapper.INSTANCE.toFlowEntry(ofEntry);
assertEquals(tableId, entry.getTableId());
assertEquals(cookie, entry.getCookie());
assertEquals(packetCount, entry.getPacketCount());
assertEquals(byteCount, entry.getByteCount());
assertEquals(durationSec, entry.getDurationSeconds());
assertEquals(durationNsec, entry.getDurationNanoSeconds());
assertEquals(hardTimeout, entry.getHardTimeout());
assertEquals(idleTimeout, entry.getIdleTimeout());
assertEquals(priority, entry.getPriority());
assertEquals(String.valueOf(vlanVid.getVlan()), entry.getMatch().getVlanVid());
assertEquals(ethType.toString(), entry.getMatch().getEthType());
assertEquals(ethDst.toString(), entry.getMatch().getEthDst());
assertEquals(port.toString(), entry.getMatch().getInPort());
assertEquals(ipProto.toString(), entry.getMatch().getIpProto());
assertEquals(udpSrc.toString(), entry.getMatch().getUdpSrc());
assertEquals(udpDst.toString(), entry.getMatch().getUdpDst());
FlowSetFieldAction flowSetEthSrcAction = new FlowSetFieldAction("eth_src", MAC_ADDRESS_1);
FlowSetFieldAction flowSetEthDstAction = new FlowSetFieldAction("eth_dst", MAC_ADDRESS_2);
FlowCopyFieldAction flowCopyFieldAction = FlowCopyFieldAction.builder().bits(String.valueOf(bits)).srcOffset(String.valueOf(srcOffset)).dstOffset(String.valueOf(dstOffset)).srcOxm(String.valueOf(oxmSrcHeader)).dstOxm(String.valueOf(oxmDstHeader)).build();
FlowSwapFieldAction flowSwapFieldAction = FlowSwapFieldAction.builder().bits(String.valueOf(bits)).srcOffset(String.valueOf(srcOffset)).dstOffset(String.valueOf(dstOffset)).srcOxm(String.valueOf(oxmSrcHeader)).dstOxm(String.valueOf(oxmDstHeader)).build();
FlowApplyActions applyActions = new FlowApplyActions(port.toString(), Lists.newArrayList(flowSetEthSrcAction, flowSetEthDstAction), ethType.toString(), null, null, null, group.toString(), flowCopyFieldAction, flowSwapFieldAction);
FlowInstructions instructions = new FlowInstructions(applyActions, null, meterId, goToTable.getValue());
assertEquals(instructions, entry.getInstructions());
}
Aggregations