Search in sources :

Example 11 with DriverService

use of org.onosproject.net.driver.DriverService in project onos by opennetworkinglab.

the class ExtensionInstructionSerializer method write.

@Override
public void write(Kryo kryo, Output output, Instructions.ExtensionInstructionWrapper object) {
    kryo.writeClassAndObject(output, object.extensionInstruction().type());
    kryo.writeClassAndObject(output, object.deviceId());
    DriverService driverService = DefaultServiceDirectory.getService(DriverService.class);
    // It raises ItemNotFoundException if it failed to find driver
    Driver driver = driverService.getDriver(object.deviceId());
    kryo.writeClassAndObject(output, driver.name());
    kryo.writeClassAndObject(output, object.extensionInstruction().serialize());
}
Also used : Driver(org.onosproject.net.driver.Driver) DriverService(org.onosproject.net.driver.DriverService)

Example 12 with DriverService

use of org.onosproject.net.driver.DriverService in project onos by opennetworkinglab.

the class NetconfSessionMinaImpl method createSubscriptionString.

@Beta
protected String createSubscriptionString(String filterSchema) {
    StringBuilder subscriptionbuffer = new StringBuilder();
    subscriptionbuffer.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n");
    subscriptionbuffer.append("  <create-subscription\n");
    subscriptionbuffer.append("xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n");
    DriverService driverService = directory.get(DriverService.class);
    Driver driver = driverService.getDriver(deviceInfo.getDeviceId());
    if (driver != null) {
        String stream = driver.getProperty(NOTIFICATION_STREAM);
        if (stream != null) {
            subscriptionbuffer.append("    <stream>");
            subscriptionbuffer.append(stream);
            subscriptionbuffer.append("</stream>\n");
        }
    }
    // FIXME Only subtree filtering supported at the moment.
    if (filterSchema != null) {
        subscriptionbuffer.append("    ");
        subscriptionbuffer.append(SUBSCRIPTION_SUBTREE_FILTER_OPEN).append(NEW_LINE);
        subscriptionbuffer.append(filterSchema).append(NEW_LINE);
        subscriptionbuffer.append("    ");
        subscriptionbuffer.append(SUBTREE_FILTER_CLOSE).append(NEW_LINE);
    }
    subscriptionbuffer.append("  </create-subscription>\n");
    subscriptionbuffer.append("</rpc>\n");
    subscriptionbuffer.append(ENDPATTERN);
    return subscriptionbuffer.toString();
}
Also used : Driver(org.onosproject.net.driver.Driver) DriverService(org.onosproject.net.driver.DriverService) Beta(com.google.common.annotations.Beta)

Example 13 with DriverService

use of org.onosproject.net.driver.DriverService in project onos by opennetworkinglab.

the class NetconfSessionMinaImpl method getClientCapabilites.

/**
 * Get the list of the netconf client capabilities from device driver property.
 *
 * @param deviceId the deviceID for which to recover the capabilities from the driver.
 * @return the String list of clientCapability property, or null if it is not configured
 */
public Set<String> getClientCapabilites(DeviceId deviceId) {
    Set<String> capabilities = new LinkedHashSet<>();
    DriverService driverService = directory.get(DriverService.class);
    try {
        Driver driver = driverService.getDriver(deviceId);
        if (driver == null) {
            return capabilities;
        }
        String clientCapabilities = driver.getProperty(NETCONF_CLIENT_CAPABILITY);
        if (clientCapabilities == null) {
            return capabilities;
        }
        String[] textStr = clientCapabilities.split("\\|");
        capabilities.addAll(Arrays.asList(textStr));
        return capabilities;
    } catch (ItemNotFoundException e) {
        log.warn("Driver for device {} currently not available", deviceId);
        return capabilities;
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Driver(org.onosproject.net.driver.Driver) DriverService(org.onosproject.net.driver.DriverService) ItemNotFoundException(org.onlab.util.ItemNotFoundException)

Example 14 with DriverService

use of org.onosproject.net.driver.DriverService 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 15 with DriverService

use of org.onosproject.net.driver.DriverService in project onos by opennetworkinglab.

the class DeviceCodec method encode.

@Override
public ObjectNode encode(Device device, CodecContext context) {
    checkNotNull(device, "Device cannot be null");
    DeviceService service = context.getService(DeviceService.class);
    DriverService driveService = context.getService(DriverService.class);
    ObjectNode result = context.mapper().createObjectNode().put(ID, device.id().toString()).put(TYPE, device.type().name()).put(AVAILABLE, service.isAvailable(device.id())).put(ROLE, service.getRole(device.id()).toString()).put(MFR, device.manufacturer()).put(HW, device.hwVersion()).put(SW, device.swVersion()).put(SERIAL, device.serialNumber()).put(DRIVER, driveService.getDriver(device.id()).name()).put(CHASSIS_ID, device.chassisId().toString()).put(LAST_UPDATE, Long.toString(service.getLastUpdatedInstant(device.id()))).put(HUMAN_READABLE_LAST_UPDATE, service.localStatus(device.id()));
    return annotate(result, device, context);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceService(org.onosproject.net.device.DeviceService) DriverService(org.onosproject.net.driver.DriverService)

Aggregations

DriverService (org.onosproject.net.driver.DriverService)32 DriverHandler (org.onosproject.net.driver.DriverHandler)23 DeviceId (org.onosproject.net.DeviceId)9 DeviceService (org.onosproject.net.device.DeviceService)5 List (java.util.List)3 Set (java.util.Set)3 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)3 VoltOnuConfig (org.onosproject.drivers.fujitsu.behaviour.VoltOnuConfig)3 DefaultDriverData (org.onosproject.net.driver.DefaultDriverData)3 DefaultDriverHandler (org.onosproject.net.driver.DefaultDriverHandler)3 Driver (org.onosproject.net.driver.Driver)3 Beta (com.google.common.annotations.Beta)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Dictionary (java.util.Dictionary)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 ExecutorService (java.util.concurrent.ExecutorService)2