Search in sources :

Example 16 with Dpid

use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.

the class OpenFlowRuleProvider method applyRule.

private void applyRule(FlowRule flowRule) {
    Dpid dpid = Dpid.dpid(flowRule.deviceId().uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    if (sw == null) {
        return;
    }
    sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(), Optional.empty(), Optional.of(driverService)).buildFlowAdd());
    recordEvent(dpid);
}
Also used : Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch)

Example 17 with Dpid

use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.

the class OpenFlowRuleProvider method executeBatch.

@Override
public void executeBatch(FlowRuleBatchOperation batch) {
    checkNotNull(batch);
    Dpid dpid = Dpid.dpid(batch.deviceId().uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    // If switch no longer exists, simply return.
    if (sw == null) {
        Set<FlowRule> failures = ImmutableSet.copyOf(Lists.transform(batch.getOperations(), e -> e.target()));
        providerService.batchOperationCompleted(batch.id(), new CompletedBatchOperation(false, failures, batch.deviceId()));
        return;
    }
    pendingBatches.put(batch.id(), new InternalCacheEntry(batch));
    // Build a batch of flow mods - to reduce the number i/o asked to the SO
    Set<OFFlowMod> mods = Sets.newHashSet();
    OFFlowMod mod;
    for (FlowRuleBatchEntry fbe : batch.getOperations()) {
        FlowModBuilder builder = FlowModBuilder.builder(fbe.target(), sw.factory(), Optional.of(batch.id()), Optional.of(driverService));
        switch(fbe.operator()) {
            case ADD:
                mod = builder.buildFlowAdd();
                break;
            case REMOVE:
                mod = builder.buildFlowDel();
                break;
            case MODIFY:
                mod = builder.buildFlowMod();
                break;
            default:
                log.error("Unsupported batch operation {}; skipping flowmod {}", fbe.operator(), fbe);
                continue;
        }
        mods.add(mod);
    }
    // Build a list to mantain the order
    List<OFMessage> modsTosend = Lists.newArrayList(mods);
    OFBarrierRequest.Builder builder = sw.factory().buildBarrierRequest().setXid(batch.id());
    // Adds finally the barrier request
    modsTosend.add(builder.build());
    sw.sendMsg(modsTosend);
    // Take into account also the barrier request
    recordEvents(dpid, (batch.getOperations().size() + 1));
}
Also used : FlowRuleBatchOperation(org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) U64(org.projectfloodlight.openflow.types.U64) OFStatsReply(org.projectfloodlight.openflow.protocol.OFStatsReply) DefaultTableStatisticsEntry(org.onosproject.net.flow.DefaultTableStatisticsEntry) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultLoad(org.onosproject.net.statistic.DefaultLoad) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData) DriverService(org.onosproject.net.driver.DriverService) POLL_FREQUENCY_DEFAULT(org.onosproject.provider.of.flow.impl.OsgiPropertyConstants.POLL_FREQUENCY_DEFAULT) Unpooled(io.netty.buffer.Unpooled) FlowRuleProviderRegistry(org.onosproject.net.flow.FlowRuleProviderRegistry) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) Map(java.util.Map) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) POLL_FREQUENCY(org.onosproject.provider.of.flow.impl.OsgiPropertyConstants.POLL_FREQUENCY) Driver(org.onosproject.net.driver.Driver) Dpid(org.onosproject.openflow.controller.Dpid) ADAPTIVE_FLOW_SAMPLING_DEFAULT(org.onosproject.provider.of.flow.impl.OsgiPropertyConstants.ADAPTIVE_FLOW_SAMPLING_DEFAULT) Tools.get(org.onlab.util.Tools.get) ImmutableSet(com.google.common.collect.ImmutableSet) IndexTableId(org.onosproject.net.flow.IndexTableId) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) OFBadRequestCode(org.projectfloodlight.openflow.protocol.OFBadRequestCode) FlowEntryBuilder(org.onosproject.provider.of.flow.util.FlowEntryBuilder) OFBadMatchErrorMsg(org.projectfloodlight.openflow.protocol.errormsg.OFBadMatchErrorMsg) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) OpenFlowEventListener(org.onosproject.openflow.controller.OpenFlowEventListener) OFBadRequestErrorMsg(org.projectfloodlight.openflow.protocol.errormsg.OFBadRequestErrorMsg) OFFlowModFailedErrorMsg(org.projectfloodlight.openflow.protocol.errormsg.OFFlowModFailedErrorMsg) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) ADAPTIVE_FLOW_SAMPLING(org.onosproject.provider.of.flow.impl.OsgiPropertyConstants.ADAPTIVE_FLOW_SAMPLING) Objects(java.util.Objects) List(java.util.List) FlowRuleProvider(org.onosproject.net.flow.FlowRuleProvider) FlowRule(org.onosproject.net.flow.FlowRule) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) DeviceId(org.onosproject.net.DeviceId) OFType(org.projectfloodlight.openflow.protocol.OFType) Dictionary(java.util.Dictionary) OFVersion(org.projectfloodlight.openflow.protocol.OFVersion) OFPortStatus(org.projectfloodlight.openflow.protocol.OFPortStatus) OpenFlowSwitchListener(org.onosproject.openflow.controller.OpenFlowSwitchListener) ComponentContext(org.osgi.service.component.ComponentContext) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) OFFlowLightweightStatsReply(org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsReply) POLL_STATS_PERIODICALLY_DEFAULT(org.onosproject.provider.of.flow.impl.OsgiPropertyConstants.POLL_STATS_PERIODICALLY_DEFAULT) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) ByteBuf(io.netty.buffer.ByteBuf) OFFlowRemoved(org.projectfloodlight.openflow.protocol.OFFlowRemoved) OFCapabilities(org.projectfloodlight.openflow.protocol.OFCapabilities) OFTableStatsReply(org.projectfloodlight.openflow.protocol.OFTableStatsReply) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Activate(org.osgi.service.component.annotations.Activate) OFErrorMsg(org.projectfloodlight.openflow.protocol.OFErrorMsg) OFBarrierRequest(org.projectfloodlight.openflow.protocol.OFBarrierRequest) OFBadActionErrorMsg(org.projectfloodlight.openflow.protocol.errormsg.OFBadActionErrorMsg) OFBadInstructionErrorMsg(org.projectfloodlight.openflow.protocol.errormsg.OFBadInstructionErrorMsg) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) AbstractProvider(org.onosproject.net.provider.AbstractProvider) RemovalNotification(com.google.common.cache.RemovalNotification) Logger(org.slf4j.Logger) OFStatsType(org.projectfloodlight.openflow.protocol.OFStatsType) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) RoleState(org.onosproject.openflow.controller.RoleState) ProviderId(org.onosproject.net.provider.ProviderId) Maps(com.google.common.collect.Maps) OpenFlowController(org.onosproject.openflow.controller.OpenFlowController) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) DriverHandler(org.onosproject.net.driver.DriverHandler) POLL_STATS_PERIODICALLY(org.onosproject.provider.of.flow.impl.OsgiPropertyConstants.POLL_STATS_PERIODICALLY) RemovalCause(com.google.common.cache.RemovalCause) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) OFTableStatsEntry(org.projectfloodlight.openflow.protocol.OFTableStatsEntry) FlowRuleProviderService(org.onosproject.net.flow.FlowRuleProviderService) U16(org.projectfloodlight.openflow.types.U16) Cache(com.google.common.cache.Cache) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) Dpid(org.onosproject.openflow.controller.Dpid) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) OFBarrierRequest(org.projectfloodlight.openflow.protocol.OFBarrierRequest) FlowRule(org.onosproject.net.flow.FlowRule) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod)

Example 18 with Dpid

use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.

the class OpenFlowDeviceProvider method changePortState.

@Override
public void changePortState(DeviceId deviceId, PortNumber portNumber, boolean enable) {
    final Dpid dpid = dpid(deviceId.uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    if (sw == null || !sw.isConnected()) {
        LOG.error("Failed to change portState on device {}", deviceId);
        return;
    }
    OFPortMod.Builder pmb = sw.factory().buildPortMod();
    OFPort port = OFPort.of((int) portNumber.toLong());
    pmb.setPortNo(port);
    Set<OFPortConfig> portConfig = EnumSet.noneOf(OFPortConfig.class);
    if (!enable) {
        portConfig.add(OFPortConfig.PORT_DOWN);
    }
    pmb.setConfig(portConfig);
    Set<OFPortConfig> portMask = EnumSet.noneOf(OFPortConfig.class);
    portMask.add(OFPortConfig.PORT_DOWN);
    pmb.setMask(portMask);
    pmb.setAdvertise(0x0);
    for (OFPortDesc pd : sw.getPorts()) {
        if (pd.getPortNo().equals(port)) {
            pmb.setHwAddr(pd.getHwAddr());
            break;
        }
    }
    sw.sendMsg(Collections.singletonList(pmb.build()));
}
Also used : OFPortMod(org.projectfloodlight.openflow.protocol.OFPortMod) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) OFPort(org.projectfloodlight.openflow.types.OFPort) OFPortConfig(org.projectfloodlight.openflow.protocol.OFPortConfig)

Example 19 with Dpid

use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.

the class OpenFlowDeviceProvider method triggerDisconnect.

@Override
public void triggerDisconnect(DeviceId deviceId) {
    Dpid dpid = dpid(deviceId.uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    if (sw != null) {
        LOG.debug("Forcing disconnect for device {}", deviceId);
        // TODO: Further consolidate clean-up on device disconnect
        listener.switchRemoved(dpid);
        sw.disconnectSwitch();
    }
}
Also used : Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch)

Example 20 with Dpid

use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.

the class OpenFlowGroupProvider method performGroupOperation.

@Override
public void performGroupOperation(DeviceId deviceId, GroupOperations groupOps) {
    final Dpid dpid = Dpid.dpid(deviceId.uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    for (GroupOperation groupOperation : groupOps.operations()) {
        if (sw == null) {
            log.error("SW {} is not found", dpid);
            return;
        }
        switch(groupOperation.groupType()) {
            case SELECT:
            case INDIRECT:
            case ALL:
            case FAILOVER:
                break;
            case CLONE:
            default:
                log.warn("Group type {} not supported, ignoring operation [{}]", groupOperation.groupType(), groupOperation);
                // Next groupOperation.
                continue;
        }
        final Long groupModXid = XID_COUNTER.getAndIncrement();
        GroupModBuilder builder = null;
        if (driverService == null) {
            builder = GroupModBuilder.builder(groupOperation.buckets(), groupOperation.groupId(), groupOperation.groupType(), sw.factory(), Optional.of(groupModXid));
        } else {
            builder = GroupModBuilder.builder(groupOperation.buckets(), groupOperation.groupId(), groupOperation.groupType(), sw.factory(), Optional.of(groupModXid), Optional.of(driverService));
        }
        OFGroupMod groupMod = null;
        switch(groupOperation.opType()) {
            case ADD:
                groupMod = builder.buildGroupAdd();
                break;
            case MODIFY:
                groupMod = builder.buildGroupMod();
                break;
            case DELETE:
                groupMod = builder.buildGroupDel();
                break;
            default:
                log.error("Unsupported Group operation");
                return;
        }
        sw.sendMsg(groupMod);
        GroupId groudId = new GroupId(groupMod.getGroup().getGroupNumber());
        pendingGroupOperations.put(groudId, groupOperation);
        pendingXidMaps.put(groudId, groupModXid);
    }
}
Also used : OFGroupMod(org.projectfloodlight.openflow.protocol.OFGroupMod) Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) AtomicLong(java.util.concurrent.atomic.AtomicLong) GroupOperation(org.onosproject.net.group.GroupOperation) GroupId(org.onosproject.core.GroupId)

Aggregations

Dpid (org.onosproject.openflow.controller.Dpid)22 OpenFlowSwitch (org.onosproject.openflow.controller.OpenFlowSwitch)17 OpenFlowController (org.onosproject.openflow.controller.OpenFlowController)5 DeviceId (org.onosproject.net.DeviceId)4 GroupId (org.onosproject.core.GroupId)3 OFPortDesc (org.projectfloodlight.openflow.protocol.OFPortDesc)3 ByteBuf (io.netty.buffer.ByteBuf)2 DefaultDriverData (org.onosproject.net.driver.DefaultDriverData)2 DefaultDriverHandler (org.onosproject.net.driver.DefaultDriverHandler)2 Driver (org.onosproject.net.driver.Driver)2 DriverHandler (org.onosproject.net.driver.DriverHandler)2 GroupBuckets (org.onosproject.net.group.GroupBuckets)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 RemovalCause (com.google.common.cache.RemovalCause)1 RemovalNotification (com.google.common.cache.RemovalNotification)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1