Search in sources :

Example 41 with DefaultFlowEntry

use of org.onosproject.net.flow.DefaultFlowEntry in project onos by opennetworkinglab.

the class ECFlowRuleStoreTest method testPurgeFlow.

/**
 * Tests purge flow for a device.
 */
@Test
public void testPurgeFlow() {
    FlowEntry flowEntry = new DefaultFlowEntry(flowRule);
    flowStoreImpl.addOrUpdateFlowRule(flowEntry);
    FlowEntry flowEntry1 = new DefaultFlowEntry(flowRule1);
    flowStoreImpl.addOrUpdateFlowRule(flowEntry1);
    assertFlowsOnDevice(deviceId, 2);
    flowStoreImpl.purgeFlowRule(deviceId);
    assertFlowsOnDevice(deviceId, 0);
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Test(org.junit.Test)

Example 42 with DefaultFlowEntry

use of org.onosproject.net.flow.DefaultFlowEntry in project onos by opennetworkinglab.

the class ECFlowRuleStoreTest method testAddFlow.

/**
 * Tests adding a flowrule.
 */
@Test
public void testAddFlow() {
    FlowEntry flowEntry = new DefaultFlowEntry(flowRule);
    FlowRuleOperation op = new FlowRuleOperation(flowRule, FlowRuleOperation.Type.ADD);
    Multimap<DeviceId, FlowRuleBatchEntry> perDeviceBatches = ArrayListMultimap.create();
    perDeviceBatches.put(op.rule().deviceId(), new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, op.rule()));
    FlowRuleBatchOperation b = new FlowRuleBatchOperation(perDeviceBatches.get(deviceId), deviceId, 1);
    flowStoreImpl.storeBatch(b);
    FlowEntry flowEntry1 = flowStoreImpl.getFlowEntry(flowRule);
    assertEquals("PENDING_ADD", flowEntry1.state().toString());
    flowStoreImpl.addOrUpdateFlowRule(flowEntry);
    assertFlowsOnDevice(deviceId, 1);
    FlowEntry flowEntry2 = flowStoreImpl.getFlowEntry(flowRule);
    assertEquals("ADDED", flowEntry2.state().toString());
    assertThat(flowStoreImpl.getTableStatistics(deviceId), notNullValue());
}
Also used : FlowRuleBatchOperation(org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) DeviceId(org.onosproject.net.DeviceId) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowRuleOperation(org.onosproject.net.flow.FlowRuleOperation) Test(org.junit.Test)

Example 43 with DefaultFlowEntry

use of org.onosproject.net.flow.DefaultFlowEntry in project onos by opennetworkinglab.

the class PolatisFlowRuleProgrammable method getFlowEntries.

@Override
public Collection<FlowEntry> getFlowEntries() {
    List<TableEvent> events;
    DeviceId deviceId = handler().data().deviceId();
    ImmutableList.Builder<FlowEntry> connectionsBuilder = ImmutableList.builder();
    try {
        OID[] columnOIDs = { new OID(PORT_PATCH_OID) };
        events = getTable(handler(), columnOIDs);
    } catch (IOException e) {
        log.error("Error reading ports table for device {} exception {}", deviceId, e);
        return connectionsBuilder.build();
    }
    if (events == null) {
        log.error("Error reading ports table for device {}", deviceId);
        return connectionsBuilder.build();
    }
    for (TableEvent event : events) {
        if (event == null) {
            log.error("Error reading event for device {}", deviceId);
            continue;
        }
        VariableBinding[] columns = event.getColumns();
        if (columns == null) {
            log.error("Error reading columns for device {}", deviceId);
            continue;
        }
        VariableBinding patchColumn = columns[0];
        if (patchColumn == null) {
            continue;
        }
        int port = event.getIndex().last();
        int patch = patchColumn.getVariable().toInt();
        if (patch == 0) {
            continue;
        }
        FlowRule flowRule = PolatisOpticalUtility.toFlowRule(this, PortNumber.portNumber(port), PortNumber.portNumber(patch));
        connectionsBuilder.add(new DefaultFlowEntry(flowRule, FlowEntry.FlowEntryState.ADDED));
    }
    return connectionsBuilder.build();
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) DeviceId(org.onosproject.net.DeviceId) ImmutableList(com.google.common.collect.ImmutableList) OID(org.snmp4j.smi.OID) IOException(java.io.IOException) TableEvent(org.snmp4j.util.TableEvent) PolatisOpticalUtility.fromFlowRule(org.onosproject.drivers.polatis.snmp.PolatisOpticalUtility.fromFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowEntry(org.onosproject.net.flow.FlowEntry) VariableBinding(org.snmp4j.smi.VariableBinding)

Example 44 with DefaultFlowEntry

use of org.onosproject.net.flow.DefaultFlowEntry in project onos by opennetworkinglab.

the class PolatisUtility method parseConnections.

/**
 * Returns flow entries representing current cross-connections on a Polatis optical switch.
 *
 * @param behaviour HandlerBehaviour object associated with device being queried
 * @return          Cross-connections as a collection of FlowEntry objects
 */
public static Collection<FlowEntry> parseConnections(HandlerBehaviour behaviour) {
    log.debug("Fetch connections...");
    String reply = netconfGet(behaviour.handler(), getConnectionsFilter());
    final String keyPairMode = String.format("%s.%s", KEY_DATA_CONNS, parseKeyPairCompat(behaviour));
    List<HierarchicalConfiguration> subtrees = configsAt(reply, keyPairMode);
    ImmutableList.Builder<FlowEntry> connectionsBuilder = ImmutableList.builder();
    for (HierarchicalConfiguration connection : subtrees) {
        connectionsBuilder.add(new DefaultFlowEntry(parseConnection(connection, behaviour), FlowEntry.FlowEntryState.ADDED));
    }
    return connectionsBuilder.build();
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) ImmutableList(com.google.common.collect.ImmutableList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Aggregations

DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)44 FlowEntry (org.onosproject.net.flow.FlowEntry)38 FlowRule (org.onosproject.net.flow.FlowRule)31 StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)22 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)21 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)8 DeviceId (org.onosproject.net.DeviceId)7 Collectors (java.util.stream.Collectors)6 Map (java.util.Map)4 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)4 DeviceConnectionCache (org.onosproject.drivers.odtn.impl.DeviceConnectionCache)4 PortNumber (org.onosproject.net.PortNumber)4 DeviceService (org.onosproject.net.device.DeviceService)4 FlowId (org.onosproject.net.flow.FlowId)4 Logger (org.slf4j.Logger)4 ImmutableList (com.google.common.collect.ImmutableList)3 IOException (java.io.IOException)3 Objects (java.util.Objects)3 Set (java.util.Set)3