Search in sources :

Example 1 with SpeakerData

use of org.openkilda.rulemanager.SpeakerData in project open-kilda by telstra.

the class SpeakerWorkerService method handleTimeout.

/**
 * Handles operation timeout.
 * @param key operation identifier.
 */
public void handleTimeout(@NonNull String key) throws PipelineException {
    SpeakerRequest failedRequest = keyToRequest.remove(key);
    if (failedRequest instanceof FlowSegmentRequest) {
        FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) failedRequest;
        SpeakerFlowSegmentResponse response = FlowErrorResponse.errorBuilder().commandId(flowSegmentRequest.getCommandId()).switchId(flowSegmentRequest.getSwitchId()).metadata(flowSegmentRequest.getMetadata()).errorCode(ErrorCode.OPERATION_TIMED_OUT).messageContext(flowSegmentRequest.getMessageContext()).build();
        carrier.sendResponse(key, response);
    } else if (failedRequest instanceof BaseSpeakerCommandsRequest) {
        BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) failedRequest;
        SpeakerCommandResponse response = SpeakerCommandResponse.builder().commandId(speakerCommandsRequest.getCommandId()).switchId(speakerCommandsRequest.getSwitchId()).messageContext(speakerCommandsRequest.getMessageContext()).success(false).failedCommandIds(speakerCommandsRequest.getCommands().stream().map(command -> {
            if (command instanceof FlowCommand) {
                return ((FlowCommand) command).getData();
            }
            if (command instanceof MeterCommand) {
                return ((MeterCommand) command).getData();
            }
            return ((GroupCommand) command).getData();
        }).collect(Collectors.toMap(SpeakerData::getUuid, error -> "Operation is timed out"))).build();
        carrier.sendResponse(key, response);
    }
}
Also used : GroupCommand(org.openkilda.floodlight.api.request.rulemanager.GroupCommand) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) FlowCommand(org.openkilda.floodlight.api.request.rulemanager.FlowCommand) MeterCommand(org.openkilda.floodlight.api.request.rulemanager.MeterCommand) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) SpeakerRequest(org.openkilda.floodlight.api.request.SpeakerRequest) BaseSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest) SpeakerData(org.openkilda.rulemanager.SpeakerData)

Example 2 with SpeakerData

use of org.openkilda.rulemanager.SpeakerData in project open-kilda by telstra.

the class Server42FlowRttOutputVxlanRuleGeneratorTest method testOutputRule.

private void testOutputRule(Switch sw, Action expectedPopVxlan, boolean copyField) {
    List<SpeakerData> commands = generator.generateCommands(sw);
    assertEquals(1, commands.size());
    FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
    assertEquals(sw.getSwitchId(), flowCommandData.getSwitchId());
    assertEquals(sw.getOfVersion(), flowCommandData.getOfVersion().toString());
    assertTrue(flowCommandData.getDependsOn().isEmpty());
    assertEquals(new Cookie(SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE), flowCommandData.getCookie());
    assertEquals(OfTable.INPUT, flowCommandData.getTable());
    assertEquals(SERVER_42_FLOW_RTT_OUTPUT_VXLAN_PRIORITY, flowCommandData.getPriority());
    Set<FieldMatch> expectedMatch = Sets.newHashSet(FieldMatch.builder().field(Field.ETH_DST).value(sw.getSwitchId().toMacAddressAsLong()).build(), FieldMatch.builder().field(Field.ETH_TYPE).value(EthType.IPv4).build(), FieldMatch.builder().field(Field.IP_PROTO).value(IpProto.UDP).build(), FieldMatch.builder().field(Field.UDP_SRC).value(SERVER_42_FLOW_RTT_REVERSE_UDP_VXLAN_PORT).build(), FieldMatch.builder().field(Field.UDP_DST).value(VXLAN_UDP_DST).build());
    assertEquals(expectedMatch, flowCommandData.getMatch());
    List<Action> expectedApplyActions = Lists.newArrayList(expectedPopVxlan, new PushVlanAction(), SetFieldAction.builder().field(Field.VLAN_VID).value(Utils.SERVER_42_VLAN).build(), SetFieldAction.builder().field(Field.ETH_SRC).value(sw.getSwitchId().toMacAddressAsLong()).build(), SetFieldAction.builder().field(Field.ETH_DST).value(Utils.SERVER_42_MAC_ADDRESS.toLong()).build(), SetFieldAction.builder().field(Field.UDP_SRC).value(SERVER_42_FLOW_RTT_REVERSE_UDP_PORT).build());
    if (copyField) {
        expectedApplyActions.add(CopyFieldAction.builder().oxmSrcHeader(OpenFlowOxms.NOVIFLOW_TX_TIMESTAMP).oxmDstHeader(OpenFlowOxms.NOVIFLOW_UDP_PAYLOAD_OFFSET).srcOffset(0).dstOffset(NOVIFLOW_TIMESTAMP_SIZE_IN_BITS).numberOfBits(NOVIFLOW_TIMESTAMP_SIZE_IN_BITS).build());
    }
    expectedApplyActions.add(new PortOutAction(new PortNumber(Utils.SERVER_42_PORT)));
    Instructions expectedInstructions = Instructions.builder().applyActions(expectedApplyActions).build();
    assertEquals(expectedInstructions, flowCommandData.getInstructions());
}
Also used : Cookie(org.openkilda.model.cookie.Cookie) Action(org.openkilda.rulemanager.action.Action) PopVxlanAction(org.openkilda.rulemanager.action.PopVxlanAction) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) CopyFieldAction(org.openkilda.rulemanager.action.noviflow.CopyFieldAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) Instructions(org.openkilda.rulemanager.Instructions) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData)

Example 3 with SpeakerData

use of org.openkilda.rulemanager.SpeakerData in project open-kilda by telstra.

the class Server42FlowRttVxlanTurningRuleGeneratorTest method testOutputRule.

private void testOutputRule(Switch sw, ActionType expectedSwapFieldType) {
    List<SpeakerData> commands = generator.generateCommands(sw);
    assertEquals(1, commands.size());
    FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
    assertEquals(sw.getSwitchId(), flowCommandData.getSwitchId());
    assertEquals(sw.getOfVersion(), flowCommandData.getOfVersion().toString());
    assertTrue(flowCommandData.getDependsOn().isEmpty());
    assertEquals(new Cookie(SERVER_42_FLOW_RTT_VXLAN_TURNING_COOKIE), flowCommandData.getCookie());
    assertEquals(OfTable.INPUT, flowCommandData.getTable());
    assertEquals(SERVER_42_FLOW_RTT_VXLAN_TURNING_PRIORITY, flowCommandData.getPriority());
    Set<FieldMatch> expectedMatch = Sets.newHashSet(FieldMatch.builder().field(Field.ETH_DST).value(sw.getSwitchId().toMacAddressAsLong()).build(), FieldMatch.builder().field(Field.ETH_TYPE).value(EthType.IPv4).build(), FieldMatch.builder().field(Field.IP_PROTO).value(IpProto.UDP).build(), FieldMatch.builder().field(Field.UDP_SRC).value(SERVER_42_FLOW_RTT_FORWARD_UDP_PORT).build(), FieldMatch.builder().field(Field.UDP_DST).value(VXLAN_UDP_DST).build());
    assertEquals(expectedMatch, flowCommandData.getMatch());
    List<Action> expectedApplyActions = Lists.newArrayList(SetFieldAction.builder().field(Field.UDP_SRC).value(SERVER_42_FLOW_RTT_REVERSE_UDP_VXLAN_PORT).build(), SwapFieldAction.builder().type(expectedSwapFieldType).numberOfBits(MAC_ADDRESS_SIZE_IN_BITS).srcOffset(0).dstOffset(0).oxmSrcHeader(OpenFlowOxms.ETH_SRC).oxmDstHeader(OpenFlowOxms.ETH_DST).build(), new PortOutAction(new PortNumber(SpecialPortType.IN_PORT)));
    Instructions expectedInstructions = Instructions.builder().applyActions(expectedApplyActions).build();
    assertEquals(expectedInstructions, flowCommandData.getInstructions());
}
Also used : Cookie(org.openkilda.model.cookie.Cookie) Action(org.openkilda.rulemanager.action.Action) SwapFieldAction(org.openkilda.rulemanager.action.SwapFieldAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) Instructions(org.openkilda.rulemanager.Instructions) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData)

Example 4 with SpeakerData

use of org.openkilda.rulemanager.SpeakerData in project open-kilda by telstra.

the class Server42IslRttOutputRuleGeneratorTest method server42IslRttOutputRuleGeneratorTest.

@Test
public void server42IslRttOutputRuleGeneratorTest() {
    Switch sw = buildSwitch("OF_13", Sets.newHashSet(NOVIFLOW_COPY_FIELD));
    List<SpeakerData> commands = generator.generateCommands(sw);
    assertEquals(1, commands.size());
    FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
    assertEquals(sw.getSwitchId(), flowCommandData.getSwitchId());
    assertEquals(sw.getOfVersion(), flowCommandData.getOfVersion().toString());
    assertTrue(flowCommandData.getDependsOn().isEmpty());
    assertEquals(new Cookie(SERVER_42_ISL_RTT_OUTPUT_COOKIE), flowCommandData.getCookie());
    assertEquals(OfTable.INPUT, flowCommandData.getTable());
    assertEquals(SERVER_42_ISL_RTT_OUTPUT_PRIORITY, flowCommandData.getPriority());
    Set<FieldMatch> expectedMatch = Sets.newHashSet(FieldMatch.builder().field(Field.ETH_DST).value(MAC_ADDRESS.toLong()).build(), FieldMatch.builder().field(Field.ETH_TYPE).value(EthType.IPv4).build(), FieldMatch.builder().field(Field.IP_PROTO).value(IpProto.UDP).build(), FieldMatch.builder().field(Field.UDP_SRC).value(SERVER_42_ISL_RTT_REVERSE_UDP_PORT).build());
    assertEquals(expectedMatch, flowCommandData.getMatch());
    List<Action> expectedApplyActions = Lists.newArrayList(new PushVlanAction(), SetFieldAction.builder().field(Field.VLAN_VID).value(Utils.SERVER_42_VLAN).build(), SetFieldAction.builder().field(Field.ETH_SRC).value(sw.getSwitchId().toMacAddressAsLong()).build(), SetFieldAction.builder().field(Field.ETH_DST).value(Utils.SERVER_42_MAC_ADDRESS.toLong()).build(), new PortOutAction(new PortNumber(Utils.SERVER_42_PORT)));
    Instructions expectedInstructions = Instructions.builder().applyActions(expectedApplyActions).build();
    assertEquals(expectedInstructions, flowCommandData.getInstructions());
}
Also used : Cookie(org.openkilda.model.cookie.Cookie) Action(org.openkilda.rulemanager.action.Action) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) Instructions(org.openkilda.rulemanager.Instructions) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Utils.buildSwitch(org.openkilda.rulemanager.Utils.buildSwitch) Switch(org.openkilda.model.Switch) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Test(org.junit.Test)

Example 5 with SpeakerData

use of org.openkilda.rulemanager.SpeakerData in project open-kilda by telstra.

the class BfdCatchRuleGeneratorTest method shouldBuildCorrectRuleForOf13.

@Test
public void shouldBuildCorrectRuleForOf13() {
    Switch sw = buildSwitch("OF_13", Sets.newHashSet(BFD));
    BfdCatchRuleGenerator generator = new BfdCatchRuleGenerator();
    List<SpeakerData> commands = generator.generateCommands(sw);
    assertEquals(1, commands.size());
    FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
    assertEquals(sw.getSwitchId(), flowCommandData.getSwitchId());
    assertEquals(sw.getOfVersion(), flowCommandData.getOfVersion().toString());
    assertTrue(flowCommandData.getDependsOn().isEmpty());
    assertEquals(new Cookie(CATCH_BFD_RULE_COOKIE), flowCommandData.getCookie());
    assertEquals(OfTable.INPUT, flowCommandData.getTable());
    assertEquals(CATCH_BFD_RULE_PRIORITY, flowCommandData.getPriority());
    FieldMatch ethDstMatch = getMatchByField(Field.ETH_DST, flowCommandData.getMatch());
    assertEquals(sw.getSwitchId().toLong(), ethDstMatch.getValue());
    assertFalse(ethDstMatch.isMasked());
    FieldMatch ethTypeMatch = getMatchByField(Field.ETH_TYPE, flowCommandData.getMatch());
    assertEquals(EthType.IPv4, ethTypeMatch.getValue());
    assertFalse(ethTypeMatch.isMasked());
    FieldMatch ipProtoMatch = getMatchByField(Field.IP_PROTO, flowCommandData.getMatch());
    assertEquals(IpProto.UDP, ipProtoMatch.getValue());
    assertFalse(ipProtoMatch.isMasked());
    FieldMatch udpDstMatch = getMatchByField(Field.UDP_DST, flowCommandData.getMatch());
    assertEquals(Constants.BDF_DEFAULT_PORT, udpDstMatch.getValue());
    assertFalse(udpDstMatch.isMasked());
    Instructions instructions = flowCommandData.getInstructions();
    assertEquals(1, instructions.getApplyActions().size());
    Action action = instructions.getApplyActions().get(0);
    assertTrue(action instanceof PortOutAction);
    PortOutAction portOutAction = (PortOutAction) action;
    assertEquals(SpecialPortType.LOCAL, portOutAction.getPortNumber().getPortType());
}
Also used : Cookie(org.openkilda.model.cookie.Cookie) Action(org.openkilda.rulemanager.action.Action) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Utils.buildSwitch(org.openkilda.rulemanager.Utils.buildSwitch) Switch(org.openkilda.model.Switch) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) Instructions(org.openkilda.rulemanager.Instructions) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Test(org.junit.Test)

Aggregations

SpeakerData (org.openkilda.rulemanager.SpeakerData)119 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)115 Test (org.junit.Test)96 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)71 Action (org.openkilda.rulemanager.action.Action)65 SetFieldAction (org.openkilda.rulemanager.action.SetFieldAction)60 Flow (org.openkilda.model.Flow)54 PushVlanAction (org.openkilda.rulemanager.action.PushVlanAction)52 FieldMatch (org.openkilda.rulemanager.match.FieldMatch)49 PortNumber (org.openkilda.rulemanager.ProtoConstants.PortNumber)48 PopVlanAction (org.openkilda.rulemanager.action.PopVlanAction)47 MeterSpeakerData (org.openkilda.rulemanager.MeterSpeakerData)38 GroupSpeakerData (org.openkilda.rulemanager.GroupSpeakerData)30 PopVxlanAction (org.openkilda.rulemanager.action.PopVxlanAction)30 Instructions (org.openkilda.rulemanager.Instructions)28 FlowPath (org.openkilda.model.FlowPath)27 GroupAction (org.openkilda.rulemanager.action.GroupAction)22 PushVxlanAction (org.openkilda.rulemanager.action.PushVxlanAction)21 Switch (org.openkilda.model.Switch)19 Utils.buildSwitch (org.openkilda.rulemanager.Utils.buildSwitch)19