Search in sources :

Example 1 with FlowEntry

use of org.openkilda.messaging.info.rule.FlowEntry in project open-kilda by telstra.

the class RecordHandler method doDumpRulesRequest.

private void doDumpRulesRequest(final CommandMessage message) {
    DumpRulesRequest request = (DumpRulesRequest) message.getData();
    final String switchId = request.getSwitchId();
    logger.debug("Loading installed rules for switch {}", switchId);
    OFFlowStatsReply reply = context.getSwitchManager().dumpFlowTable(DatapathId.of(switchId));
    List<FlowEntry> flows = reply.getEntries().stream().map(OFFlowStatsConverter::toFlowEntry).collect(Collectors.toList());
    SwitchFlowEntries response = SwitchFlowEntries.builder().switchId(switchId).flowEntries(flows).build();
    InfoMessage infoMessage = new InfoMessage(response, message.getTimestamp(), message.getCorrelationId());
    context.getKafkaProducer().postMessage(TOPO_ENG_TOPIC, infoMessage);
}
Also used : DumpRulesRequest(org.openkilda.messaging.command.switches.DumpRulesRequest) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) InfoMessage(org.openkilda.messaging.info.InfoMessage) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry)

Example 2 with FlowEntry

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);
    }
}
Also used : OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) OfFlowStatsMapper(org.openkilda.floodlight.converter.OfFlowStatsMapper) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) FlowCommandErrorData(org.openkilda.messaging.error.rule.FlowCommandErrorData) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 3 with FlowEntry

use of org.openkilda.messaging.info.rule.FlowEntry in project open-kilda by telstra.

the class CommandBuilderImplTest method shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithStringOutPort.

@Test
public void shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithStringOutPort() {
    Long cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue();
    String inPort = "1";
    String inVlan = "10";
    String outPort = "in_port";
    FlowEntry flowEntry = buildFlowEntry(cookie, inPort, inVlan, outPort, null, false, null, null);
    RemoveFlow removeFlow = commandBuilder.buildRemoveFlowWithoutMeterFromFlowEntry(SWITCH_ID_A, flowEntry);
    assertEquals(cookie, removeFlow.getCookie());
    DeleteRulesCriteria criteria = removeFlow.getCriteria();
    assertEquals(cookie, criteria.getCookie());
    assertEquals(Integer.valueOf(inPort), criteria.getInPort());
    assertEquals(Integer.valueOf(inVlan), criteria.getEncapsulationId());
    assertNull(criteria.getOutPort());
    assertNull(criteria.getMetadataValue());
    assertNull(criteria.getMetadataMask());
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) Test(org.junit.Test)

Example 4 with FlowEntry

use of org.openkilda.messaging.info.rule.FlowEntry in project open-kilda by telstra.

the class CommandBuilderImplTest method shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithVxlanEncapsulationIngress.

@Test
public void shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithVxlanEncapsulationIngress() {
    Long cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue();
    String inPort = "1";
    String outPort = "2";
    String tunnelId = "10";
    String metadataValue = "0x15";
    String metadataMask = "0xFF";
    FlowEntry flowEntry = buildFlowEntry(cookie, inPort, null, outPort, tunnelId, true, metadataValue, metadataMask);
    RemoveFlow removeFlow = commandBuilder.buildRemoveFlowWithoutMeterFromFlowEntry(SWITCH_ID_A, flowEntry);
    assertEquals(cookie, removeFlow.getCookie());
    DeleteRulesCriteria criteria = removeFlow.getCriteria();
    assertEquals(cookie, criteria.getCookie());
    assertEquals(Integer.valueOf(inPort), criteria.getInPort());
    assertNull(criteria.getEncapsulationId());
    assertEquals(Integer.valueOf(outPort), criteria.getOutPort());
    assertEquals(Long.decode(metadataValue), criteria.getMetadataValue());
    assertEquals(Long.decode(metadataMask), criteria.getMetadataMask());
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) Test(org.junit.Test)

Example 5 with FlowEntry

use of org.openkilda.messaging.info.rule.FlowEntry in project open-kilda by telstra.

the class CommandBuilderImplTest method shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithVxlanEncapsulationTransitAndEgress.

@Test
public void shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithVxlanEncapsulationTransitAndEgress() {
    Long cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue();
    String inPort = "1";
    String outPort = "2";
    String tunnelId = "10";
    FlowEntry flowEntry = buildFlowEntry(cookie, inPort, null, outPort, tunnelId, false, null, null);
    RemoveFlow removeFlow = commandBuilder.buildRemoveFlowWithoutMeterFromFlowEntry(SWITCH_ID_A, flowEntry);
    assertEquals(cookie, removeFlow.getCookie());
    DeleteRulesCriteria criteria = removeFlow.getCriteria();
    assertEquals(cookie, criteria.getCookie());
    assertEquals(Integer.valueOf(inPort), criteria.getInPort());
    assertEquals(Integer.valueOf(tunnelId), criteria.getEncapsulationId());
    assertEquals(Integer.valueOf(outPort), criteria.getOutPort());
    assertNull(criteria.getMetadataValue());
    assertNull(criteria.getMetadataMask());
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) Test(org.junit.Test)

Aggregations

FlowEntry (org.openkilda.messaging.info.rule.FlowEntry)13 Test (org.junit.Test)6 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)6 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)4 DeleteRulesCriteria (org.openkilda.messaging.command.switches.DeleteRulesCriteria)4 InfoMessage (org.openkilda.messaging.info.InfoMessage)3 SwitchId (org.openkilda.model.SwitchId)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Before (org.junit.Before)2 CommandData (org.openkilda.messaging.command.CommandData)2 DumpGroupsForFlowHsRequest (org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest)2 DumpMetersForFlowHsRequest (org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest)2 DumpRulesForFlowHsRequest (org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest)2 InfoData (org.openkilda.messaging.info.InfoData)2 SwitchFlowEntries (org.openkilda.messaging.info.rule.SwitchFlowEntries)2 Flow (org.openkilda.model.Flow)2 YFlow (org.openkilda.model.YFlow)2 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1