Search in sources :

Example 1 with DeviceContext

use of org.opendaylight.openflowplugin.api.openflow.device.DeviceContext in project openflowplugin by opendaylight.

the class ContextChainHolderImpl method createContextChain.

@VisibleForTesting
void createContextChain(final ConnectionContext connectionContext) {
    final DeviceInfo deviceInfo = connectionContext.getDeviceInfo();
    final DeviceContext deviceContext = deviceManager.createContext(connectionContext);
    deviceContext.registerMastershipWatcher(this);
    LOG.debug("Device" + CONTEXT_CREATED_FOR_CONNECTION, deviceInfo);
    final RpcContext rpcContext = rpcManager.createContext(deviceContext);
    rpcContext.registerMastershipWatcher(this);
    LOG.debug("RPC" + CONTEXT_CREATED_FOR_CONNECTION, deviceInfo);
    final StatisticsContext statisticsContext = statisticsManager.createContext(deviceContext, ownershipChangeListener.isReconciliationFrameworkRegistered());
    statisticsContext.registerMastershipWatcher(this);
    LOG.debug("Statistics" + CONTEXT_CREATED_FOR_CONNECTION, deviceInfo);
    final RoleContext roleContext = roleManager.createContext(deviceContext);
    roleContext.registerMastershipWatcher(this);
    LOG.debug("Role" + CONTEXT_CREATED_FOR_CONNECTION, deviceInfo);
    final ContextChain contextChain = new ContextChainImpl(this, connectionContext, executorService);
    contextChain.registerDeviceRemovedHandler(deviceManager);
    contextChain.registerDeviceRemovedHandler(rpcManager);
    contextChain.registerDeviceRemovedHandler(statisticsManager);
    contextChain.registerDeviceRemovedHandler(roleManager);
    contextChain.registerDeviceRemovedHandler(this);
    contextChain.addContext(deviceContext);
    contextChain.addContext(rpcContext);
    contextChain.addContext(statisticsContext);
    contextChain.addContext(roleContext);
    contextChainMap.put(deviceInfo, contextChain);
    connectingDevices.remove(deviceInfo);
    LOG.debug("Context chain" + CONTEXT_CREATED_FOR_CONNECTION, deviceInfo);
    deviceContext.onPublished();
    contextChain.registerServices(singletonServiceProvider);
}
Also used : RpcContext(org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext) DeviceContext(org.opendaylight.openflowplugin.api.openflow.device.DeviceContext) RoleContext(org.opendaylight.openflowplugin.api.openflow.role.RoleContext) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) StatisticsContext(org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext) ContextChain(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChain) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with DeviceContext

use of org.opendaylight.openflowplugin.api.openflow.device.DeviceContext in project openflowplugin by opendaylight.

the class OF13DeviceInitializer method initializeNodeInformation.

@Override
protected Future<Void> initializeNodeInformation(@Nonnull final DeviceContext deviceContext, final boolean switchFeaturesMandatory, final boolean skipTableFeatures, @Nullable final MultipartWriterProvider multipartWriterProvider, @Nullable final ConvertorExecutor convertorExecutor) {
    final ConnectionContext connectionContext = Preconditions.checkNotNull(deviceContext.getPrimaryConnectionContext());
    final DeviceState deviceState = Preconditions.checkNotNull(deviceContext.getDeviceState());
    final DeviceInfo deviceInfo = Preconditions.checkNotNull(deviceContext.getDeviceInfo());
    final Capabilities capabilities = connectionContext.getFeatures().getCapabilities();
    LOG.debug("Setting capabilities for device {}", deviceInfo);
    DeviceStateUtil.setDeviceStateBasedOnV13Capabilities(deviceState, capabilities);
    // First process description reply, write data to DS and write consequent data if successful
    return Futures.transformAsync(requestMultipart(MultipartType.OFPMPDESC, deviceContext), (AsyncFunction<RpcResult<List<OfHeader>>, Void>) input -> {
        translateAndWriteResult(MultipartType.OFPMPDESC, input.getResult(), deviceContext, multipartWriterProvider, convertorExecutor);
        final List<ListenableFuture<RpcResult<List<OfHeader>>>> futures = new ArrayList<>();
        futures.add(requestAndProcessMultipart(MultipartType.OFPMPMETERFEATURES, deviceContext, skipTableFeatures, multipartWriterProvider, convertorExecutor));
        futures.add(requestAndProcessMultipart(MultipartType.OFPMPGROUPFEATURES, deviceContext, skipTableFeatures, multipartWriterProvider, convertorExecutor));
        futures.add(requestAndProcessMultipart(MultipartType.OFPMPTABLEFEATURES, deviceContext, skipTableFeatures, multipartWriterProvider, convertorExecutor));
        futures.add(requestAndProcessMultipart(MultipartType.OFPMPPORTDESC, deviceContext, skipTableFeatures, multipartWriterProvider, convertorExecutor));
        return Futures.transform(switchFeaturesMandatory ? Futures.allAsList(futures) : Futures.successfulAsList(futures), new Function<List<RpcResult<List<OfHeader>>>, Void>() {

            @Nullable
            @Override
            public Void apply(@Nullable final List<RpcResult<List<OfHeader>>> input) {
                LOG.info("Static node {} successfully finished collecting", deviceContext.getDeviceInfo());
                return null;
            }
        }, MoreExecutors.directExecutor());
    }, MoreExecutors.directExecutor());
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) MultipartWriterProvider(org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ConvertorExecutor(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MeterFeatures(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFeatures) LoggerFactory(org.slf4j.LoggerFactory) MultiLayerMultipartCollectorService(org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerMultipartCollectorService) DeviceState(org.opendaylight.openflowplugin.api.openflow.device.DeviceState) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) DeviceStateUtil(org.opendaylight.openflowplugin.impl.util.DeviceStateUtil) Capabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities) DeviceContext(org.opendaylight.openflowplugin.api.openflow.device.DeviceContext) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) SingleLayerMultipartCollectorService(org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerMultipartCollectorService) ConnectionContext(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext) Function(com.google.common.base.Function) Logger(org.slf4j.Logger) MultipartReplyTranslatorUtil(org.opendaylight.openflowplugin.impl.common.MultipartReplyTranslatorUtil) DeviceInitializationUtil(org.opendaylight.openflowplugin.impl.util.DeviceInitializationUtil) Collectors(java.util.stream.Collectors) FutureCallback(com.google.common.util.concurrent.FutureCallback) Objects(java.util.Objects) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) MultipartType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) Function(com.google.common.base.Function) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) DeviceState(org.opendaylight.openflowplugin.api.openflow.device.DeviceState) Capabilities(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ArrayList(java.util.ArrayList) List(java.util.List) ConnectionContext(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext) Nullable(javax.annotation.Nullable)

Example 3 with DeviceContext

use of org.opendaylight.openflowplugin.api.openflow.device.DeviceContext in project openflowplugin by opendaylight.

the class MultipartReplyTranslatorTest method testTranslateAggregate.

@Test
public void testTranslateAggregate() {
    DeviceContext mockedDeviceContext = mock(DeviceContext.class);
    MultipartReplyMessage multipartReplyMessage = prepareMocks(mockedDeviceContext, prepareMultipartReplyAggregate(), MultipartType.OFPMPAGGREGATE);
    DataContainer result = MultipartReplyTranslatorUtil.translate(multipartReplyMessage, mockedDeviceContext.getDeviceInfo(), CONVERTOR_MANAGER, mockedDeviceContext.oook()).get();
    DataContainer dataObject = validateOutput(result);
    assertTrue(dataObject instanceof AggregateFlowStatistics);
    AggregateFlowStatistics message = (AggregateFlowStatistics) dataObject;
    assertEquals(DUMMY_BYTE_COUNT, message.getByteCount().getValue());
    assertEquals(DUMMY_PACKET_COUNT, message.getPacketCount().getValue());
    assertEquals(DUMMY_FLOW_COUNT, message.getFlowCount().getValue());
}
Also used : DeviceContext(org.opendaylight.openflowplugin.api.openflow.device.DeviceContext) MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) DataContainer(org.opendaylight.yangtools.yang.binding.DataContainer) AggregateFlowStatistics(org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.AggregateFlowStatistics) Test(org.junit.Test)

Example 4 with DeviceContext

use of org.opendaylight.openflowplugin.api.openflow.device.DeviceContext in project openflowplugin by opendaylight.

the class MultipartReplyTranslatorTest method testTranslateGroup.

@Test
public void testTranslateGroup() {
    DeviceContext mockedDeviceContext = mock(DeviceContext.class);
    MultipartReplyMessage multipartReplyMessage = prepareMocks(mockedDeviceContext, prepareMultipartReplyGroup(), MultipartType.OFPMPGROUP);
    DataContainer result = MultipartReplyTranslatorUtil.translate(multipartReplyMessage, mockedDeviceContext.getDeviceInfo(), CONVERTOR_MANAGER, mockedDeviceContext.oook()).get();
    DataContainer dataObject = validateOutput(result);
    assertTrue(dataObject instanceof GroupStatisticsReply);
    GroupStatisticsReply groupStatisticsUpdate = (GroupStatisticsReply) dataObject;
    List<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats> groupStats = groupStatisticsUpdate.getGroupStats();
    assertEquals(1, groupStats.size());
    org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats groupStat = groupStats.get(0);
    assertEquals(DUMMY_BYTE_COUNT, groupStat.getByteCount().getValue());
    assertEquals(DUMMY_DURATION_SEC, groupStat.getDuration().getSecond().getValue());
    assertEquals(DUMMY_DURATION_NSEC, groupStat.getDuration().getNanosecond().getValue());
    assertEquals(DUMMY_GROUP_ID.getValue(), groupStat.getGroupId().getValue());
    assertEquals(DUMMY_PACKET_COUNT, groupStat.getPacketCount().getValue());
    assertEquals(DUMMY_REF_COUNT, groupStat.getRefCount().getValue());
}
Also used : MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) DeviceContext(org.opendaylight.openflowplugin.api.openflow.device.DeviceContext) DataContainer(org.opendaylight.yangtools.yang.binding.DataContainer) GroupStatisticsReply(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupStatisticsReply) Test(org.junit.Test)

Example 5 with DeviceContext

use of org.opendaylight.openflowplugin.api.openflow.device.DeviceContext in project openflowplugin by opendaylight.

the class MultipartReplyTranslatorTest method testTranslateGroupDesc.

@Test
public void testTranslateGroupDesc() {
    DeviceContext mockedDeviceContext = mock(DeviceContext.class);
    MultipartReplyMessage multipartReplyMessage = prepareMocks(mockedDeviceContext, prepareMultipartReplyGroupDesc(), MultipartType.OFPMPGROUPDESC);
    DataContainer result = MultipartReplyTranslatorUtil.translate(multipartReplyMessage, mockedDeviceContext.getDeviceInfo(), CONVERTOR_MANAGER, mockedDeviceContext.oook()).get();
    DataContainer dataObject = validateOutput(result);
    assertTrue(dataObject instanceof GroupDescStatsReply);
    GroupDescStatsReply groupStatistics = (GroupDescStatsReply) dataObject;
    List<GroupDescStats> groupDescStats = groupStatistics.getGroupDescStats();
    assertEquals(1, groupDescStats.size());
    GroupDescStats groupDescStat = groupDescStats.get(0);
    assertEquals(DUMMY_GROUP_ID.getValue(), groupDescStat.getGroupId().getValue());
    assertEquals(DUMMY_GROUPS_TYPE, groupDescStat.getGroupType());
}
Also used : DeviceContext(org.opendaylight.openflowplugin.api.openflow.device.DeviceContext) MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) DataContainer(org.opendaylight.yangtools.yang.binding.DataContainer) GroupDescStatsReply(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupDescStatsReply) GroupDescStats(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats) Test(org.junit.Test)

Aggregations

DeviceContext (org.opendaylight.openflowplugin.api.openflow.device.DeviceContext)10 Test (org.junit.Test)7 MultipartReplyMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage)5 DataContainer (org.opendaylight.yangtools.yang.binding.DataContainer)5 DeviceInfo (org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Function (com.google.common.base.Function)1 Preconditions (com.google.common.base.Preconditions)1 AsyncFunction (com.google.common.util.concurrent.AsyncFunction)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Future (java.util.concurrent.Future)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1