Search in sources :

Example 6 with Match

use of org.projectfloodlight.openflow.protocol.match.Match in project open-kilda by telstra.

the class SwitchManager method simpleDstMatch.

/**
 * A simple Match rule based on destination mac address and mask.
 * TODO: Could be generalized
 *
 * @param dstMac
 * @param dstMask
 * @return
 */
private Match simpleDstMatch(IOFSwitch sw, String dstMac, String dstMask) throws SwitchOperationException {
    Match match = null;
    if (dstMac != null && dstMask != null && dstMac.length() > 0 && dstMask.length() > 0) {
        Builder builder = sw.getOFFactory().buildMatch();
        builder.setMasked(MatchField.ETH_DST, MacAddress.of(dstMac), MacAddress.NO_MASK);
        match = builder.build();
    }
    return match;
}
Also used : Builder(org.projectfloodlight.openflow.protocol.match.Match.Builder) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch)

Example 7 with Match

use of org.projectfloodlight.openflow.protocol.match.Match in project open-kilda by telstra.

the class SwitchManager method installIngressFlow.

/**
 * {@inheritDoc}
 */
@Override
public long installIngressFlow(final DatapathId dpid, final String flowId, final Long cookie, final int inputPort, final int outputPort, final int inputVlanId, final int transitVlanId, final OutputVlanType outputVlanType, final long meterId) throws SwitchOperationException {
    List<OFAction> actionList = new ArrayList<>();
    IOFSwitch sw = lookupSwitch(dpid);
    // build match by input port and input vlan id
    Match match = matchFlow(sw, inputPort, inputVlanId);
    // build meter instruction
    OFInstructionMeter meter = null;
    if (meterId != 0L && !OVS_MANUFACTURER.equals(sw.getSwitchDescription().getManufacturerDescription())) {
        if (sw.getOFFactory().getVersion().compareTo(OF_12) <= 0) {
            actionList.add(legacyMeterAction(sw, meterId));
        } else if (sw.getOFFactory().getVersion().compareTo(OF_15) == 0) {
            actionList.add(sw.getOFFactory().actions().buildMeter().setMeterId(meterId).build());
        } else /* OF_13, OF_14 */
        {
            meter = sw.getOFFactory().instructions().buildMeter().setMeterId(meterId).build();
        }
    }
    // output action based on encap scheme
    actionList.addAll(inputVlanTypeToOFActionList(sw, transitVlanId, outputVlanType));
    // transmit packet from outgoing port
    actionList.add(actionSetOutputPort(sw, outputPort));
    // build instruction with action list
    OFInstructionApplyActions actions = buildInstructionApplyActions(sw, actionList);
    // build FLOW_MOD command with meter
    OFFlowMod flowMod = buildFlowMod(sw, match, meter, actions, cookie & FLOW_COOKIE_MASK, FlowModUtils.PRIORITY_VERY_HIGH);
    return pushFlow(sw, "--InstallIngressFlow--", flowMod);
}
Also used : OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) OFInstructionMeter(org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) ArrayList(java.util.ArrayList) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch)

Example 8 with Match

use of org.projectfloodlight.openflow.protocol.match.Match in project open-kilda by telstra.

the class SwitchManager method installDropFlowCustom.

/**
 * Installs custom drop rule .. ie cookie, priority, match
 *
 * @param dpid datapathId of switch
 * @param dstMac Destination Mac address to match on
 * @param dstMask Destination Mask to match on
 * @param cookie Cookie to use for this rule
 * @param priority Priority of the rule
 * @throws SwitchOperationException
 */
@Override
public void installDropFlowCustom(final DatapathId dpid, String dstMac, String dstMask, final long cookie, final int priority) throws SwitchOperationException {
    IOFSwitch sw = lookupSwitch(dpid);
    Match match = simpleDstMatch(sw, dstMac, dstMask);
    OFFlowMod flowMod = buildFlowMod(sw, match, null, null, cookie, priority);
    String flowName = "--CustomDropRule--" + dpid.toString();
    pushFlow(sw, flowName, flowMod);
}
Also used : OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch)

Example 9 with Match

use of org.projectfloodlight.openflow.protocol.match.Match in project open-kilda by telstra.

the class PathVerificationPacketSignTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    OFPacketOut packetOut = pvs.generateVerificationPacket(sw1, OFPort.of(1));
    ofPacketIn = EasyMock.createMock(OFPacketIn.class);
    context = new FloodlightContext();
    expect(ofPacketIn.getType()).andReturn(OFType.PACKET_IN).anyTimes();
    expect(ofPacketIn.getXid()).andReturn(0L).anyTimes();
    expect(ofPacketIn.getVersion()).andReturn(packetOut.getVersion()).anyTimes();
    Match match = EasyMock.createMock(Match.class);
    expect(match.get(MatchField.IN_PORT)).andReturn(OFPort.of(1)).anyTimes();
    replay(match);
    expect(ofPacketIn.getMatch()).andReturn(match).anyTimes();
    replay(ofPacketIn);
    IPacket expected = new Ethernet().deserialize(packetOut.getData(), 0, packetOut.getData().length);
    context.getStorage().put(IFloodlightProviderService.CONTEXT_PI_PAYLOAD, expected);
    HashMap<DatapathId, IOFSwitch> switches = new HashMap<>();
    switches.put(sw1.getId(), sw1);
    switches.put(sw2.getId(), sw2);
    mockSwitchManager.setSwitches(switches);
    reset(producer);
    pvs.setKafkaProducer(producer);
}
Also used : IPacket(net.floodlightcontroller.packet.IPacket) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) HashMap(java.util.HashMap) Ethernet(net.floodlightcontroller.packet.Ethernet) OFPacketIn(org.projectfloodlight.openflow.protocol.OFPacketIn) DatapathId(org.projectfloodlight.openflow.types.DatapathId) OFPacketOut(org.projectfloodlight.openflow.protocol.OFPacketOut) FloodlightContext(net.floodlightcontroller.core.FloodlightContext) Match(org.projectfloodlight.openflow.protocol.match.Match) Before(org.junit.Before)

Aggregations

Match (org.projectfloodlight.openflow.protocol.match.Match)9 OFVlanVidMatch (org.projectfloodlight.openflow.types.OFVlanVidMatch)8 OFFlowMod (org.projectfloodlight.openflow.protocol.OFFlowMod)6 ArrayList (java.util.ArrayList)5 OFAction (org.projectfloodlight.openflow.protocol.action.OFAction)5 OFInstructionApplyActions (org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions)5 OFInstructionMeter (org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter)2 Builder (org.projectfloodlight.openflow.protocol.match.Match.Builder)2 HashMap (java.util.HashMap)1 FloodlightContext (net.floodlightcontroller.core.FloodlightContext)1 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)1 Ethernet (net.floodlightcontroller.packet.Ethernet)1 IPacket (net.floodlightcontroller.packet.IPacket)1 Before (org.junit.Before)1 OFPacketIn (org.projectfloodlight.openflow.protocol.OFPacketIn)1 OFPacketOut (org.projectfloodlight.openflow.protocol.OFPacketOut)1 DatapathId (org.projectfloodlight.openflow.types.DatapathId)1