Search in sources :

Example 1 with OFInstructionWriteActions

use of org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions in project open-kilda by telstra.

the class OfFlowPresenceVerifier method isInstructionsEquals.

private boolean isInstructionsEquals(List<OFInstruction> expectedSeq, List<OFInstruction> actualSeq) {
    if (expectedSeq.size() != actualSeq.size()) {
        return false;
    }
    Map<Class<?>, OFInstruction> expectedMap = sequenceToMapByTypes(expectedSeq);
    Map<Class<?>, OFInstruction> actualMap = sequenceToMapByTypes(actualSeq);
    boolean result = true;
    for (Map.Entry<Class<?>, OFInstruction> entry : expectedMap.entrySet()) {
        OFInstruction expected = entry.getValue();
        OFInstruction actual = actualMap.get(entry.getKey());
        if (actual == null) {
            result = false;
        } else if (expected instanceof OFInstructionApplyActions) {
            result = isApplyActionsInstructionEquals((OFInstructionApplyActions) expected, (OFInstructionApplyActions) actual);
        } else if (expected instanceof OFInstructionWriteActions) {
            result = isWriteActionsInstructionEquals((OFInstructionWriteActions) expected, (OFInstructionWriteActions) actual);
        } else if (!Objects.equals(expected, actual)) {
            result = false;
        }
        if (!result) {
            break;
        }
    }
    return result;
}
Also used : OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) OFInstructionWriteActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with OFInstructionWriteActions

use of org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions in project open-kilda by telstra.

the class OfInstructionsConverter method convertToRuleManagerInstructions.

/**
 * Convert instructions.
 */
public Instructions convertToRuleManagerInstructions(List<OFInstruction> ofInstructions) {
    InstructionsBuilder builder = Instructions.builder();
    for (OFInstruction ofInstruction : ofInstructions) {
        if (ofInstruction instanceof OFInstructionApplyActions) {
            List<OFAction> ofActions = ((OFInstructionApplyActions) ofInstruction).getActions();
            List<Action> actions = ofActions.stream().map(this::convertToRuleManagerAction).collect(Collectors.toList());
            builder.applyActions(actions);
        } else if (ofInstruction instanceof OFInstructionWriteActions) {
            List<OFAction> ofActions = ((OFInstructionWriteActions) ofInstruction).getActions();
            Set<Action> actions = ofActions.stream().map(this::convertToRuleManagerAction).collect(Collectors.toSet());
            builder.writeActions(actions);
        } else if (ofInstruction instanceof OFInstructionMeter) {
            final long meterId = ((OFInstructionMeter) ofInstruction).getMeterId();
            builder.goToMeter(new MeterId(meterId));
        } else if (ofInstruction instanceof OFInstructionGotoTable) {
            final short tableId = ((OFInstructionGotoTable) ofInstruction).getTableId().getValue();
            builder.goToTable(OfTable.fromInt(tableId));
        } else if (ofInstruction instanceof OFInstructionWriteMetadata) {
            final long metadata = ((OFInstructionWriteMetadata) ofInstruction).getMetadata().getValue();
            final long metadataMask = ((OFInstructionWriteMetadata) ofInstruction).getMetadataMask().getValue();
            builder.writeMetadata(new OfMetadata(metadata, metadataMask));
        }
    }
    return builder.build();
}
Also used : OFInstructionMeter(org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter) MeterAction(org.openkilda.rulemanager.action.MeterAction) SwapFieldAction(org.openkilda.rulemanager.action.SwapFieldAction) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) GroupAction(org.openkilda.rulemanager.action.GroupAction) CopyFieldAction(org.openkilda.rulemanager.action.noviflow.CopyFieldAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) Action(org.openkilda.rulemanager.action.Action) PushVxlanAction(org.openkilda.rulemanager.action.PushVxlanAction) PopVxlanAction(org.openkilda.rulemanager.action.PopVxlanAction) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) Set(java.util.Set) OFInstructionGotoTable(org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) OFInstructionWriteMetadata(org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata) InstructionsBuilder(org.openkilda.rulemanager.Instructions.InstructionsBuilder) MeterId(org.openkilda.model.MeterId) OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) OfMetadata(org.openkilda.rulemanager.OfMetadata) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) List(java.util.List) ArrayList(java.util.ArrayList) OFInstructionWriteActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions)

Aggregations

OFInstruction (org.projectfloodlight.openflow.protocol.instruction.OFInstruction)2 OFInstructionApplyActions (org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions)2 OFInstructionWriteActions (org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 MeterId (org.openkilda.model.MeterId)1 InstructionsBuilder (org.openkilda.rulemanager.Instructions.InstructionsBuilder)1 OfMetadata (org.openkilda.rulemanager.OfMetadata)1 Action (org.openkilda.rulemanager.action.Action)1 GroupAction (org.openkilda.rulemanager.action.GroupAction)1 MeterAction (org.openkilda.rulemanager.action.MeterAction)1 PopVlanAction (org.openkilda.rulemanager.action.PopVlanAction)1 PopVxlanAction (org.openkilda.rulemanager.action.PopVxlanAction)1 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)1 PushVlanAction (org.openkilda.rulemanager.action.PushVlanAction)1 PushVxlanAction (org.openkilda.rulemanager.action.PushVxlanAction)1 SetFieldAction (org.openkilda.rulemanager.action.SetFieldAction)1