Search in sources :

Example 1 with CopyFieldAction

use of org.openkilda.rulemanager.action.noviflow.CopyFieldAction in project open-kilda by telstra.

the class RoundTripLatencyRuleGeneratorTest method shouldBuildCorrectRuleForOf13.

@Test
public void shouldBuildCorrectRuleForOf13() {
    Switch sw = buildSwitch("OF_13", Sets.newHashSet(NOVIFLOW_COPY_FIELD));
    RoundTripLatencyRuleGenerator generator = RoundTripLatencyRuleGenerator.builder().config(config).build();
    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(ROUND_TRIP_LATENCY_RULE_COOKIE), flowCommandData.getCookie());
    assertEquals(OfTable.INPUT, flowCommandData.getTable());
    assertEquals(ROUND_TRIP_LATENCY_RULE_PRIORITY, flowCommandData.getPriority());
    FieldMatch ethSrcMatch = getMatchByField(Field.ETH_SRC, flowCommandData.getMatch());
    assertEquals(sw.getSwitchId().toLong(), ethSrcMatch.getValue());
    assertFalse(ethSrcMatch.isMasked());
    FieldMatch ethDstMatch = getMatchByField(Field.ETH_DST, flowCommandData.getMatch());
    assertEquals(new SwitchId(config.getDiscoveryBcastPacketDst()).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.LATENCY_PACKET_UDP_PORT, udpDstMatch.getValue());
    assertFalse(udpDstMatch.isMasked());
    Instructions instructions = flowCommandData.getInstructions();
    assertEquals(2, instructions.getApplyActions().size());
    Action first = instructions.getApplyActions().get(0);
    assertTrue(first instanceof CopyFieldAction);
    CopyFieldAction copyFieldAction = (CopyFieldAction) first;
    assertEquals(ROUND_TRIP_LATENCY_TIMESTAMP_SIZE, copyFieldAction.getNumberOfBits());
    assertEquals(0, copyFieldAction.getSrcOffset());
    assertEquals(ROUND_TRIP_LATENCY_T1_OFFSET, copyFieldAction.getDstOffset());
    assertEquals(NOVIFLOW_RX_TIMESTAMP, copyFieldAction.getOxmSrcHeader());
    assertEquals(NOVIFLOW_PACKET_OFFSET, copyFieldAction.getOxmDstHeader());
    Action second = instructions.getApplyActions().get(1);
    assertTrue(second instanceof PortOutAction);
    PortOutAction portOutAction = (PortOutAction) second;
    assertEquals(SpecialPortType.CONTROLLER, portOutAction.getPortNumber().getPortType());
}
Also used : Cookie(org.openkilda.model.cookie.Cookie) CopyFieldAction(org.openkilda.rulemanager.action.noviflow.CopyFieldAction) Action(org.openkilda.rulemanager.action.Action) CopyFieldAction(org.openkilda.rulemanager.action.noviflow.CopyFieldAction) 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) SwitchId(org.openkilda.model.SwitchId) Instructions(org.openkilda.rulemanager.Instructions) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) RoundTripLatencyRuleGenerator(org.openkilda.rulemanager.factory.generator.service.noviflow.RoundTripLatencyRuleGenerator) Test(org.junit.Test)

Example 2 with CopyFieldAction

use of org.openkilda.rulemanager.action.noviflow.CopyFieldAction in project open-kilda by telstra.

the class FlowEntryConverter method addAction.

private void addAction(FlowApplyActionsBuilder builder, Action action) {
    switch(action.getType()) {
        case GROUP:
            GroupAction groupAction = (GroupAction) action;
            builder.group(String.valueOf(groupAction.getGroupId().getValue()));
            return;
        case PORT_OUT:
            PortOutAction portOutAction = (PortOutAction) action;
            builder.flowOutput(portOutAction.getPortNumber().toString());
            return;
        case POP_VLAN:
            builder.popVlan("");
            return;
        case PUSH_VLAN:
            builder.pushVlan("");
            return;
        case POP_VXLAN_NOVIFLOW:
        case POP_VXLAN_OVS:
            // todo handle pop vxlan
            return;
        case PUSH_VXLAN_NOVIFLOW:
        case PUSH_VXLAN_OVS:
            PushVxlanAction pushVxlanAction = (PushVxlanAction) action;
            builder.pushVxlan(String.valueOf(pushVxlanAction.getVni()));
            return;
        case METER:
            MeterAction meterAction = (MeterAction) action;
            builder.meter(String.valueOf(meterAction.getMeterId().getValue()));
            return;
        case NOVI_COPY_FIELD:
            CopyFieldAction copyFieldAction = (CopyFieldAction) action;
            builder.copyFieldAction(FlowCopyFieldAction.builder().bits(String.valueOf(copyFieldAction.getNumberOfBits())).srcOffset(String.valueOf(copyFieldAction.getSrcOffset())).dstOffset(String.valueOf(copyFieldAction.getDstOffset())).srcOxm(copyFieldAction.getOxmSrcHeader().toString()).dstOxm(copyFieldAction.getOxmDstHeader().toString()).build());
            return;
        case NOVI_SWAP_FIELD:
        case KILDA_SWAP_FIELD:
            SwapFieldAction swapFieldAction = (SwapFieldAction) action;
            builder.swapFieldAction(FlowSwapFieldAction.builder().bits(String.valueOf(swapFieldAction.getNumberOfBits())).srcOffset(String.valueOf(swapFieldAction.getSrcOffset())).dstOffset(String.valueOf(swapFieldAction.getDstOffset())).srcOxm(swapFieldAction.getOxmSrcHeader().toString()).dstOxm(swapFieldAction.getOxmDstHeader().toString()).build());
            return;
        case SET_FIELD:
            SetFieldAction setFieldAction = (SetFieldAction) action;
            builder.setFieldAction(FlowSetFieldAction.builder().fieldName(setFieldAction.getField().toString()).fieldValue(String.valueOf(setFieldAction.getValue())).build());
            return;
        default:
            throw new IllegalStateException(format("Unknown action type %s", action.getType()));
    }
}
Also used : GroupAction(org.openkilda.rulemanager.action.GroupAction) FlowCopyFieldAction(org.openkilda.messaging.info.rule.FlowCopyFieldAction) CopyFieldAction(org.openkilda.rulemanager.action.noviflow.CopyFieldAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) MeterAction(org.openkilda.rulemanager.action.MeterAction) SwapFieldAction(org.openkilda.rulemanager.action.SwapFieldAction) FlowSwapFieldAction(org.openkilda.messaging.info.rule.FlowSwapFieldAction) PushVxlanAction(org.openkilda.rulemanager.action.PushVxlanAction) FlowSetFieldAction(org.openkilda.messaging.info.rule.FlowSetFieldAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction)

Aggregations

PortOutAction (org.openkilda.rulemanager.action.PortOutAction)2 CopyFieldAction (org.openkilda.rulemanager.action.noviflow.CopyFieldAction)2 Test (org.junit.Test)1 FlowCopyFieldAction (org.openkilda.messaging.info.rule.FlowCopyFieldAction)1 FlowSetFieldAction (org.openkilda.messaging.info.rule.FlowSetFieldAction)1 FlowSwapFieldAction (org.openkilda.messaging.info.rule.FlowSwapFieldAction)1 Switch (org.openkilda.model.Switch)1 SwitchId (org.openkilda.model.SwitchId)1 Cookie (org.openkilda.model.cookie.Cookie)1 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)1 Instructions (org.openkilda.rulemanager.Instructions)1 SpeakerData (org.openkilda.rulemanager.SpeakerData)1 Utils.buildSwitch (org.openkilda.rulemanager.Utils.buildSwitch)1 Action (org.openkilda.rulemanager.action.Action)1 GroupAction (org.openkilda.rulemanager.action.GroupAction)1 MeterAction (org.openkilda.rulemanager.action.MeterAction)1 PushVxlanAction (org.openkilda.rulemanager.action.PushVxlanAction)1 SetFieldAction (org.openkilda.rulemanager.action.SetFieldAction)1 SwapFieldAction (org.openkilda.rulemanager.action.SwapFieldAction)1 RoundTripLatencyRuleGenerator (org.openkilda.rulemanager.factory.generator.service.noviflow.RoundTripLatencyRuleGenerator)1