Search in sources :

Example 6 with OFMeterMod

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

the class SwitchManager method deleteMeter.

public long deleteMeter(IOFSwitch sw, final DatapathId dpid, final long meterId) throws OFInstallException {
    logger.debug("deleting meter {} from switch {}", meterId, dpid);
    OFFactory ofFactory = sw.getOFFactory();
    OFMeterMod.Builder meterDeleteBuilder = ofFactory.buildMeterMod().setMeterId(meterId).setCommand(OFMeterModCommand.DELETE);
    if (sw.getOFFactory().getVersion().compareTo(OF_13) > 0) {
        meterDeleteBuilder.setBands(emptyList());
    } else {
        meterDeleteBuilder.setMeters(emptyList());
    }
    OFMeterMod meterDelete = meterDeleteBuilder.build();
    return pushFlow(sw, "--DeleteMeter--", meterDelete);
}
Also used : OFMeterMod(org.projectfloodlight.openflow.protocol.OFMeterMod) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory)

Example 7 with OFMeterMod

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

the class ReplaceInstallFlowTest method runTest.

/**
 * Runs test case.
 *
 * @param value       data string from json resource file
 * @param flowCommand OFFlowAdd instance to compare result with
 * @throws InterruptedException if test was interrupted during run
 */
private void runTest(final String value, final OFFlowAdd flowCommand, final OFMeterMod meterCommand, final OFFlowAdd reverseFlowCommand, final OFMeterMod reverseMeterCommand) throws InterruptedException {
    // construct kafka message
    ConsumerRecord<String, String> record = new ConsumerRecord<>("", 0, 0, "", value);
    // create parser instance
    ConsumerContext kafkaContext = new ConsumerContext(context, collector);
    RecordHandler parseRecord = new RecordHandler(kafkaContext, record, new MeterPool());
    // init test mocks
    Capture<OFFlowAdd> flowAddCapture = flowCommand == null ? null : newCapture(CaptureType.ALL);
    Capture<OFMeterMod> meterAddCapture = meterCommand == null ? null : newCapture(CaptureType.ALL);
    prepareMocks(flowAddCapture, meterAddCapture, reverseFlowCommand != null, reverseMeterCommand != null);
    // run parser and wait for termination or timeout
    parseRecordExecutor.execute(parseRecord);
    parseRecordExecutor.shutdown();
    parseRecordExecutor.awaitTermination(10, TimeUnit.SECONDS);
    // verify results
    if (meterCommand != null) {
        assertEquals(meterCommand, meterAddCapture.getValues().get(0));
        if (reverseMeterCommand != null) {
            assertEquals(reverseMeterCommand, meterAddCapture.getValues().get(1));
        }
    }
    if (flowCommand != null) {
        assertEquals(flowCommand, flowAddCapture.getValues().get(0));
        if (reverseFlowCommand != null) {
            assertEquals(reverseFlowCommand, flowAddCapture.getValues().get(1));
        }
    }
}
Also used : MeterPool(org.openkilda.floodlight.switchmanager.MeterPool) OFMeterMod(org.projectfloodlight.openflow.protocol.OFMeterMod) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) OFFlowAdd(org.projectfloodlight.openflow.protocol.OFFlowAdd)

Example 8 with OFMeterMod

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

the class ReplaceInstallFlowTest method installIngressNoneFlow.

@Test
public void installIngressNoneFlow() throws IOException, InterruptedException {
    String value = Resources.toString(getClass().getResource("/install_ingress_none_flow.json"), Charsets.UTF_8);
    InstallIngressFlow data = (InstallIngressFlow) prepareData(value);
    OFMeterMod meterCommand = scheme.installMeter(data.getBandwidth(), 1024, data.getMeterId());
    OFFlowAdd flowCommand = scheme.ingressNoneFlowMod(data.getInputPort(), data.getOutputPort(), data.getTransitVlanId(), data.getMeterId(), 123L);
    runTest(value, flowCommand, meterCommand, null, null);
}
Also used : InstallIngressFlow(org.openkilda.messaging.command.flow.InstallIngressFlow) OFMeterMod(org.projectfloodlight.openflow.protocol.OFMeterMod) OFFlowAdd(org.projectfloodlight.openflow.protocol.OFFlowAdd) Test(org.junit.Test)

Example 9 with OFMeterMod

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

the class ReplaceInstallFlowTest method installOneSwitchPopFlow.

@Test
public void installOneSwitchPopFlow() throws IOException, InterruptedException {
    String value = Resources.toString(getClass().getResource("/install_one_switch_pop_flow.json"), Charsets.UTF_8);
    InstallOneSwitchFlow data = (InstallOneSwitchFlow) prepareData(value);
    OFMeterMod meterCommand = scheme.installMeter(data.getBandwidth(), 1024, data.getMeterId());
    OFFlowAdd flowCommand = scheme.oneSwitchPopFlowMod(data.getInputPort(), data.getOutputPort(), data.getInputVlanId(), data.getMeterId(), 123L);
    runTest(value, flowCommand, meterCommand, null, null);
}
Also used : InstallOneSwitchFlow(org.openkilda.messaging.command.flow.InstallOneSwitchFlow) OFMeterMod(org.projectfloodlight.openflow.protocol.OFMeterMod) OFFlowAdd(org.projectfloodlight.openflow.protocol.OFFlowAdd) Test(org.junit.Test)

Example 10 with OFMeterMod

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

the class ReplaceInstallFlowTest method installIngressPopFlow.

@Test
public void installIngressPopFlow() throws IOException, InterruptedException {
    String value = Resources.toString(getClass().getResource("/install_ingress_pop_flow.json"), Charsets.UTF_8);
    InstallIngressFlow data = (InstallIngressFlow) prepareData(value);
    OFMeterMod meterCommand = scheme.installMeter(data.getBandwidth(), 1024, data.getMeterId());
    OFFlowAdd flowCommand = scheme.ingressPopFlowMod(data.getInputPort(), data.getOutputPort(), data.getInputVlanId(), data.getTransitVlanId(), data.getMeterId(), 123L);
    runTest(value, flowCommand, meterCommand, null, null);
}
Also used : InstallIngressFlow(org.openkilda.messaging.command.flow.InstallIngressFlow) OFMeterMod(org.projectfloodlight.openflow.protocol.OFMeterMod) OFFlowAdd(org.projectfloodlight.openflow.protocol.OFFlowAdd) Test(org.junit.Test)

Aggregations

OFMeterMod (org.projectfloodlight.openflow.protocol.OFMeterMod)12 Test (org.junit.Test)9 OFFlowAdd (org.projectfloodlight.openflow.protocol.OFFlowAdd)9 InstallIngressFlow (org.openkilda.messaging.command.flow.InstallIngressFlow)4 InstallOneSwitchFlow (org.openkilda.messaging.command.flow.InstallOneSwitchFlow)4 OFFactory (org.projectfloodlight.openflow.protocol.OFFactory)2 HashSet (java.util.HashSet)1 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)1 MeterPool (org.openkilda.floodlight.switchmanager.MeterPool)1 OFMeterFlags (org.projectfloodlight.openflow.protocol.OFMeterFlags)1 OFMeterBandDrop (org.projectfloodlight.openflow.protocol.meterband.OFMeterBandDrop)1