From 3ee047a21cbd0754dabaab6d01708d5c20be80fd Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 5 Feb 2024 17:29:34 +0100 Subject: [PATCH] Decompose RPC implementation classes RpcContextImpl registers a multitude of RPC services when it becomes active. We really want to make that registration atomic -- which is something we can do with RpcProviderService.registerRpcImplementations(). This patch splits up our implementation classes to individual RPCs and then uses a single call to register them in one go. For bonus points we get rid of the horrible java.lang.IllegalAccessError throws and correctly report RPC unavailability (because we do not register those RPCs). We also ditch OpendaylightDirectStatisticsServiceProvider and its associated *LayerDirectStatisticsProviderInitializer, as they can be cleanly bound without per-request lookups. JIRA: OPNFLWPLUG-1125 Change-Id: I80ade2f9f51fc765c0d685f544e5b102061d033c Signed-off-by: Robert Varga --- .../impl/rpc/RpcContextImpl.java | 419 +++++++++++------- .../impl/services/AbstractService.java | 10 +- .../impl/services/EchoService.java | 29 -- ...EchoServiceImpl.java => SendEchoImpl.java} | 34 +- .../impl/services/sal/AbstractDeviceRpc.java | 21 + .../impl/services/sal/AbstractFlowRpc.java | 28 ++ .../impl/services/sal/AbstractGroupRpc.java | 29 ++ .../impl/services/sal/AbstractMeterRpc.java | 29 ++ .../services/sal/AddBundleMessagesImpl.java | 88 ++++ .../impl/services/sal/AddFlowImpl.java | 100 +++++ .../impl/services/sal/AddFlowsBatchImpl.java | 72 +++ .../impl/services/sal/AddGroupImpl.java | 61 +++ .../impl/services/sal/AddGroupsBatchImpl.java | 74 ++++ .../impl/services/sal/AddMeterImpl.java | 59 +++ .../impl/services/sal/AddMetersBatchImpl.java | 74 ++++ .../impl/services/sal/ControlBundleImpl.java | 50 +++ .../services/sal/ProcessFlatBatchImpl.java | 161 +++++++ .../impl/services/sal/RemoveFlowImpl.java | 90 ++++ .../services/sal/RemoveFlowsBatchImpl.java | 72 +++ .../impl/services/sal/RemoveGroupImpl.java | 64 +++ .../services/sal/RemoveGroupsBatchImpl.java | 74 ++++ .../impl/services/sal/RemoveMeterImpl.java | 61 +++ .../services/sal/RemoveMetersBatchImpl.java | 74 ++++ .../sal/SalAsyncConfigServiceImpl.java | 49 -- .../services/sal/SalBundleServiceImpl.java | 124 ------ .../services/sal/SalFlatBatchServiceImpl.java | 208 --------- .../impl/services/sal/SalFlowServiceImpl.java | 330 -------------- .../sal/SalFlowsBatchServiceImpl.java | 166 ------- .../services/sal/SalGroupServiceImpl.java | 167 ------- .../sal/SalGroupsBatchServiceImpl.java | 166 ------- .../services/sal/SalMeterServiceImpl.java | 156 ------- .../sal/SalMetersBatchServiceImpl.java | 172 ------- ...nServiceImpl.java => SendBarrierImpl.java} | 11 +- ...iceImpl.java => SendExperimenterImpl.java} | 27 +- ...ava => SendExperimenterMpRequestImpl.java} | 15 +- ...figServiceImpl.java => SetConfigImpl.java} | 24 +- ...rviceImpl.java => TransmitPacketImpl.java} | 14 +- .../impl/services/sal/UpdateFlowImpl.java | 173 ++++++++ .../services/sal/UpdateFlowsBatchImpl.java | 76 ++++ .../impl/services/sal/UpdateGroupImpl.java | 68 +++ .../services/sal/UpdateGroupsBatchImpl.java | 85 ++++ .../impl/services/sal/UpdateMeterImpl.java | 63 +++ .../services/sal/UpdateMetersBatchImpl.java | 84 ++++ ...rtServiceImpl.java => UpdatePortImpl.java} | 21 +- ...eServiceImpl.java => UpdateTableImpl.java} | 20 +- .../services/singlelayer/GetAsyncImpl.java | 45 ++ ...ncConfigService.java => SetAsyncImpl.java} | 16 +- .../SingleLayerGetAsyncConfigService.java | 31 -- .../AggregateFlowsInTableService.java | 18 +- .../services/AllGroupsStatsService.java | 7 +- ...tisticsFromFlowTableForGivenMatchImpl.java | 38 ++ .../services/GetAllGroupStatisticsImpl.java | 39 ++ .../GetAllMeterConfigStatisticsImpl.java | 41 ++ .../services/GetAllMeterStatisticsImpl.java | 40 ++ .../GetAllNodeConnectorsStatisticsImpl.java | 40 ++ ...etAllQueuesStatisticsFromAllPortsImpl.java | 39 ++ ...tAllQueuesStatisticsFromGivenPortImpl.java | 39 ++ ....java => GetFlowTablesStatisticsImpl.java} | 77 ++-- .../services/GetGroupDescriptionImpl.java | 40 ++ .../services/GetGroupFeaturesImpl.java | 39 ++ .../services/GetGroupStatisticsImpl.java | 37 ++ .../services/GetMeterFeaturesImpl.java | 39 ++ .../services/GetMeterStatisticsImpl.java | 39 ++ ...va => GetNodeConnectorStatisticsImpl.java} | 19 +- .../GetQueueStatisticsFromGivenPortImpl.java | 39 ++ ...OpendaylightFlowStatisticsServiceImpl.java | 134 ------ ...pendaylightGroupStatisticsServiceImpl.java | 72 --- ...pendaylightMeterStatisticsServiceImpl.java | 75 ---- ...pendaylightQueueStatisticsServiceImpl.java | 57 --- .../statistics/services/PortStatsService.java | 21 +- ...tatisticsFromFlowTableForAllFlowsImpl.java | 43 ++ ...GetAllFlowStatisticsFromFlowTableImpl.java | 42 ++ ...lFlowsStatisticsFromAllFlowTablesImpl.java | 42 ++ .../GetFlowStatisticsFromFlowTableImpl.java | 42 ++ ...ightFlowStatisticsServiceDelegateImpl.java | 101 ----- .../AbstractDirectStatisticsService.java | 15 +- ...ce.java => AbstractGetFlowStatistics.java} | 21 +- ...e.java => AbstractGetGroupStatistics.java} | 27 +- ...e.java => AbstractGetMeterStatistics.java} | 21 +- ...> AbstractGetNodeConnectorStatistics.java} | 21 +- ...e.java => AbstractGetQueueStatistics.java} | 23 +- ...endaylightDirectStatisticsServiceImpl.java | 91 ---- ...rvice.java => MultiGetFlowStatistics.java} | 26 +- ...vice.java => MultiGetGroupStatistics.java} | 19 +- ...vice.java => MultiGetMeterStatistics.java} | 20 +- ...a => MultiGetNodeConnectorStatistics.java} | 27 +- ...vice.java => MultiGetQueueStatistics.java} | 48 +- ...erDirectStatisticsProviderInitializer.java | 53 --- ...vice.java => SingleGetFlowStatistics.java} | 24 +- ...ice.java => SingleGetGroupStatistics.java} | 22 +- ...ice.java => SingleGetMeterStatistics.java} | 22 +- ... => SingleGetNodeConnectorStatistics.java} | 26 +- ...ice.java => SingleGetQueueStatistics.java} | 22 +- ...erDirectStatisticsProviderInitializer.java | 54 --- .../openflowplugin/impl/util/BarrierUtil.java | 38 +- .../impl/rpc/RpcContextImplTest.java | 16 +- ...ServiceTest.java => SendEchoImplTest.java} | 12 +- ...est.java => ProcessFlatBatchImplTest.java} | 275 ++++++------ .../sal/SalAsyncConfigServiceImplTest.java | 60 ++- .../sal/SalBundleServiceImplTest.java | 107 ++--- .../services/sal/SalEchoServiceImplTest.java | 44 +- .../services/sal/SalFlowServiceImplTest.java | 80 ++-- .../sal/SalFlowsBatchServiceImplTest.java | 283 ++++++------ .../services/sal/SalGroupServiceImplTest.java | 47 +- .../sal/SalGroupsBatchServiceImplTest.java | 242 +++++----- .../services/sal/SalMeterServiceImplTest.java | 55 +-- .../sal/SalMetersBatchServiceImplTest.java | 240 +++++----- ...ImplTest.java => SendBarrierImplTest.java} | 25 +- ...est.java => SendExperimenterImplTest.java} | 50 +-- ...=> SendExperimenterMpRequestImplTest.java} | 22 +- ...ceImplTest.java => SetConfigImplTest.java} | 23 +- ...lTest.java => TransmitPacketImplTest.java} | 43 +- ...eImplTest.java => UpdatePortImplTest.java} | 48 +- ...ImplTest.java => UpdateTableImplTest.java} | 13 +- ...a => GetFlowTablesStatisticsImplTest.java} | 65 ++- ...aylightFlowStatisticsServiceImpl1Test.java | 91 ---- ...aylightFlowStatisticsServiceImpl2Test.java | 62 ++- ...aylightFlowStatisticsServiceImpl3Test.java | 90 ---- ...aylightGroupStatisticsServiceImplTest.java | 186 ++++---- ...aylightMeterStatisticsServiceImplTest.java | 99 +++-- ...daylightPortStatisticsServiceImplTest.java | 57 ++- ...aylightQueueStatisticsServiceImplTest.java | 76 ++-- .../AbstractCompatibleStatServiceTest.java | 47 +- ...FlowStatisticsServiceDelegateImplTest.java | 123 +++-- ...ylightDirectStatisticsServiceImplTest.java | 179 -------- .../FlowDirectStatisticsServiceTest.java | 4 +- .../GroupDirectStatisticsServiceTest.java | 4 +- .../MeterDirectStatisticsServiceTest.java | 8 +- ...eConnectorDirectStatisticsServiceTest.java | 8 +- .../QueueDirectStatisticsServiceTest.java | 25 +- .../FlowDirectStatisticsServiceTest.java | 4 +- .../GroupDirectStatisticsServiceTest.java | 4 +- .../MeterDirectStatisticsServiceTest.java | 4 +- ...eConnectorDirectStatisticsServiceTest.java | 8 +- .../QueueDirectStatisticsServiceTest.java | 57 +-- .../impl/util/BarrierUtilTest.java | 40 +- 136 files changed, 4388 insertions(+), 4501 deletions(-) delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/EchoService.java rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/{sal/SalEchoServiceImpl.java => SendEchoImpl.java} (68%) create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AbstractDeviceRpc.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AbstractFlowRpc.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AbstractGroupRpc.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AbstractMeterRpc.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddBundleMessagesImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddFlowImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddFlowsBatchImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddGroupImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddGroupsBatchImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddMeterImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddMetersBatchImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/ControlBundleImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/ProcessFlatBatchImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveFlowImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveFlowsBatchImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveGroupImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveGroupsBatchImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveMeterImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveMetersBatchImpl.java delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalAsyncConfigServiceImpl.java delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalBundleServiceImpl.java delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlatBatchServiceImpl.java delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowServiceImpl.java delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowsBatchServiceImpl.java delete mode 100755 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupServiceImpl.java delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupsBatchServiceImpl.java delete mode 100755 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalMeterServiceImpl.java delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalMetersBatchServiceImpl.java rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/{FlowCapableTransactionServiceImpl.java => SendBarrierImpl.java} (76%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/{SalExperimenterMessageServiceImpl.java => SendExperimenterImpl.java} (81%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/{SalExperimenterMpMessageServiceImpl.java => SendExperimenterMpRequestImpl.java} (77%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/{NodeConfigServiceImpl.java => SetConfigImpl.java} (67%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/{PacketProcessingServiceImpl.java => TransmitPacketImpl.java} (78%) create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateFlowImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateFlowsBatchImpl.java create mode 100755 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateGroupImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateGroupsBatchImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateMeterImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateMetersBatchImpl.java rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/{SalPortServiceImpl.java => UpdatePortImpl.java} (82%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/{SalTableServiceImpl.java => UpdateTableImpl.java} (72%) create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/singlelayer/GetAsyncImpl.java rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/singlelayer/{SingleLayerSetAsyncConfigService.java => SetAsyncImpl.java} (69%) delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/singlelayer/SingleLayerGetAsyncConfigService.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAggregateFlowStatisticsFromFlowTableForGivenMatchImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllGroupStatisticsImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllMeterConfigStatisticsImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllMeterStatisticsImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllNodeConnectorsStatisticsImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllQueuesStatisticsFromAllPortsImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllQueuesStatisticsFromGivenPortImpl.java rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/{OpendaylightFlowTableStatisticsServiceImpl.java => GetFlowTablesStatisticsImpl.java} (58%) create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetGroupDescriptionImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetGroupFeaturesImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetGroupStatisticsImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetMeterFeaturesImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetMeterStatisticsImpl.java rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/{OpendaylightPortStatisticsServiceImpl.java => GetNodeConnectorStatisticsImpl.java} (66%) create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetQueueStatisticsFromGivenPortImpl.java delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl.java delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightGroupStatisticsServiceImpl.java delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightMeterStatisticsServiceImpl.java delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightQueueStatisticsServiceImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GetAggregateFlowStatisticsFromFlowTableForAllFlowsImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GetAllFlowStatisticsFromFlowTableImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GetAllFlowsStatisticsFromAllFlowTablesImpl.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GetFlowStatisticsFromFlowTableImpl.java delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/OpendaylightFlowStatisticsServiceDelegateImpl.java rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/{AbstractFlowDirectStatisticsService.java => AbstractGetFlowStatistics.java} (79%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/{AbstractGroupDirectStatisticsService.java => AbstractGetGroupStatistics.java} (57%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/{AbstractMeterDirectStatisticsService.java => AbstractGetMeterStatistics.java} (60%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/{AbstractPortDirectStatisticsService.java => AbstractGetNodeConnectorStatistics.java} (63%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/{AbstractQueueDirectStatisticsService.java => AbstractGetQueueStatistics.java} (61%) delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/OpendaylightDirectStatisticsServiceImpl.java rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/{FlowDirectStatisticsService.java => MultiGetFlowStatistics.java} (81%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/{GroupDirectStatisticsService.java => MultiGetGroupStatistics.java} (79%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/{MeterDirectStatisticsService.java => MultiGetMeterStatistics.java} (79%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/{PortDirectStatisticsService.java => MultiGetNodeConnectorStatistics.java} (81%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/{QueueDirectStatisticsService.java => MultiGetQueueStatistics.java} (68%) delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiLayerDirectStatisticsProviderInitializer.java rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/{FlowDirectStatisticsService.java => SingleGetFlowStatistics.java} (78%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/{GroupDirectStatisticsService.java => SingleGetGroupStatistics.java} (76%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/{MeterDirectStatisticsService.java => SingleGetMeterStatistics.java} (77%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/{PortDirectStatisticsService.java => SingleGetNodeConnectorStatistics.java} (72%) rename openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/{QueueDirectStatisticsService.java => SingleGetQueueStatistics.java} (76%) delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleLayerDirectStatisticsProviderInitializer.java rename openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/{EchoServiceTest.java => SendEchoImplTest.java} (84%) rename openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/{SalFlatBatchServiceImplTest.java => ProcessFlatBatchImplTest.java} (74%) rename openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/{FlowCapableTransactionServiceImplTest.java => SendBarrierImplTest.java} (61%) rename openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/{SalExperimenterMessageServiceImplTest.java => SendExperimenterImplTest.java} (58%) rename openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/{SalExperimenterMpMessageServiceImplTest.java => SendExperimenterMpRequestImplTest.java} (56%) rename openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/{NodeConfigServiceImplTest.java => SetConfigImplTest.java} (72%) rename openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/{PacketProcessingServiceImplTest.java => TransmitPacketImplTest.java} (64%) rename openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/{SalPortServiceImplTest.java => UpdatePortImplTest.java} (53%) rename openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/{SalTableServiceImplTest.java => UpdateTableImplTest.java} (94%) rename openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/{OpendaylightFlowTableStatisticsServiceImplTest.java => GetFlowTablesStatisticsImplTest.java} (60%) delete mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl1Test.java delete mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl3Test.java delete mode 100644 openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/OpendaylightDirectStatisticsServiceImplTest.java diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java index 8f42fab389..face6e9616 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java @@ -7,13 +7,10 @@ */ package org.opendaylight.openflowplugin.impl.rpc; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterators; +import com.google.common.collect.ImmutableClassToInstanceMap; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; +import java.util.Set; import java.util.concurrent.Semaphore; import java.util.concurrent.atomic.AtomicLong; import org.eclipse.jdt.annotation.NonNull; @@ -29,60 +26,114 @@ import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext; import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy; import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider; import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProviderFactory; -import org.opendaylight.openflowplugin.impl.services.sal.FlowCapableTransactionServiceImpl; -import org.opendaylight.openflowplugin.impl.services.sal.NodeConfigServiceImpl; -import org.opendaylight.openflowplugin.impl.services.sal.PacketProcessingServiceImpl; -import org.opendaylight.openflowplugin.impl.services.sal.SalAsyncConfigServiceImpl; -import org.opendaylight.openflowplugin.impl.services.sal.SalBundleServiceImpl; -import org.opendaylight.openflowplugin.impl.services.sal.SalEchoServiceImpl; -import org.opendaylight.openflowplugin.impl.services.sal.SalExperimenterMessageServiceImpl; -import org.opendaylight.openflowplugin.impl.services.sal.SalExperimenterMpMessageServiceImpl; -import org.opendaylight.openflowplugin.impl.services.sal.SalFlatBatchServiceImpl; -import org.opendaylight.openflowplugin.impl.services.sal.SalFlowServiceImpl; -import org.opendaylight.openflowplugin.impl.services.sal.SalFlowsBatchServiceImpl; -import org.opendaylight.openflowplugin.impl.services.sal.SalGroupServiceImpl; -import org.opendaylight.openflowplugin.impl.services.sal.SalGroupsBatchServiceImpl; -import org.opendaylight.openflowplugin.impl.services.sal.SalMeterServiceImpl; -import org.opendaylight.openflowplugin.impl.services.sal.SalMetersBatchServiceImpl; -import org.opendaylight.openflowplugin.impl.services.sal.SalPortServiceImpl; -import org.opendaylight.openflowplugin.impl.services.sal.SalTableServiceImpl; -import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightFlowStatisticsServiceImpl; -import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightFlowTableStatisticsServiceImpl; -import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightGroupStatisticsServiceImpl; -import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightMeterStatisticsServiceImpl; -import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightPortStatisticsServiceImpl; -import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightQueueStatisticsServiceImpl; -import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.OpendaylightFlowStatisticsServiceDelegateImpl; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.OpendaylightDirectStatisticsServiceImpl; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.multilayer.MultiLayerDirectStatisticsProviderInitializer; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.singlelayer.SingleLayerDirectStatisticsProviderInitializer; +import org.opendaylight.openflowplugin.impl.services.SendEchoImpl; +import org.opendaylight.openflowplugin.impl.services.sal.AddBundleMessagesImpl; +import org.opendaylight.openflowplugin.impl.services.sal.AddFlowImpl; +import org.opendaylight.openflowplugin.impl.services.sal.AddFlowsBatchImpl; +import org.opendaylight.openflowplugin.impl.services.sal.AddGroupImpl; +import org.opendaylight.openflowplugin.impl.services.sal.AddGroupsBatchImpl; +import org.opendaylight.openflowplugin.impl.services.sal.AddMeterImpl; +import org.opendaylight.openflowplugin.impl.services.sal.AddMetersBatchImpl; +import org.opendaylight.openflowplugin.impl.services.sal.ControlBundleImpl; +import org.opendaylight.openflowplugin.impl.services.sal.ProcessFlatBatchImpl; +import org.opendaylight.openflowplugin.impl.services.sal.RemoveFlowImpl; +import org.opendaylight.openflowplugin.impl.services.sal.RemoveFlowsBatchImpl; +import org.opendaylight.openflowplugin.impl.services.sal.RemoveGroupImpl; +import org.opendaylight.openflowplugin.impl.services.sal.RemoveGroupsBatchImpl; +import org.opendaylight.openflowplugin.impl.services.sal.RemoveMeterImpl; +import org.opendaylight.openflowplugin.impl.services.sal.RemoveMetersBatchImpl; +import org.opendaylight.openflowplugin.impl.services.sal.SendBarrierImpl; +import org.opendaylight.openflowplugin.impl.services.sal.SendExperimenterImpl; +import org.opendaylight.openflowplugin.impl.services.sal.SendExperimenterMpRequestImpl; +import org.opendaylight.openflowplugin.impl.services.sal.SetConfigImpl; +import org.opendaylight.openflowplugin.impl.services.sal.TransmitPacketImpl; +import org.opendaylight.openflowplugin.impl.services.sal.UpdateFlowImpl; +import org.opendaylight.openflowplugin.impl.services.sal.UpdateFlowsBatchImpl; +import org.opendaylight.openflowplugin.impl.services.sal.UpdateGroupImpl; +import org.opendaylight.openflowplugin.impl.services.sal.UpdateGroupsBatchImpl; +import org.opendaylight.openflowplugin.impl.services.sal.UpdateMeterImpl; +import org.opendaylight.openflowplugin.impl.services.sal.UpdateMetersBatchImpl; +import org.opendaylight.openflowplugin.impl.services.sal.UpdatePortImpl; +import org.opendaylight.openflowplugin.impl.services.sal.UpdateTableImpl; +import org.opendaylight.openflowplugin.impl.services.singlelayer.GetAsyncImpl; +import org.opendaylight.openflowplugin.impl.services.singlelayer.SetAsyncImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.GetAggregateFlowStatisticsFromFlowTableForGivenMatchImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.GetAllGroupStatisticsImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.GetAllMeterConfigStatisticsImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.GetAllMeterStatisticsImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.GetAllNodeConnectorsStatisticsImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.GetAllQueuesStatisticsFromAllPortsImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.GetAllQueuesStatisticsFromGivenPortImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.GetFlowTablesStatisticsImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.GetGroupDescriptionImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.GetGroupFeaturesImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.GetGroupStatisticsImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.GetMeterFeaturesImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.GetMeterStatisticsImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.GetNodeConnectorStatisticsImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.GetQueueStatisticsFromGivenPortImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.GetAggregateFlowStatisticsFromFlowTableForAllFlowsImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.GetAllFlowStatisticsFromFlowTableImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.GetAllFlowsStatisticsFromAllFlowTablesImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.compatibility.GetFlowStatisticsFromFlowTableImpl; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.multilayer.MultiGetFlowStatistics; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.multilayer.MultiGetGroupStatistics; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.multilayer.MultiGetMeterStatistics; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.multilayer.MultiGetNodeConnectorStatistics; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.multilayer.MultiGetQueueStatistics; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.singlelayer.SingleGetFlowStatistics; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.singlelayer.SingleGetGroupStatistics; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.singlelayer.SingleGetMeterStatistics; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.singlelayer.SingleGetNodeConnectorStatistics; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.singlelayer.SingleGetQueueStatistics; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; -import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SalAsyncConfigService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.OpendaylightDirectStatisticsService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SalEchoService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SalExperimenterMessageService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SalExperimenterMpMessageService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.SalFlatBatchService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsync; +import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SetAsync; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetGroupStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetQueueStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEcho; +import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequest; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlows; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTables; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroup; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroup; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroup; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescription; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeatures; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.SalBundleService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.SalPortService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService; -import org.opendaylight.yangtools.concepts.ObjectRegistration; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.AddBundleMessages; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.ControlBundle; +import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacket; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPorts; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTable; +import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.RpcService; +import org.opendaylight.yangtools.yang.binding.Rpc; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -93,10 +144,6 @@ final class RpcContextImpl implements RpcContext { private final MessageSpy messageSpy; private final Semaphore tracker; private final boolean isStatisticsRpcEnabled; - - // TODO: add private Sal salBroker - private final ConcurrentMap, ObjectRegistration> rpcRegistrations = - new ConcurrentHashMap<>(); private final KeyedInstanceIdentifier nodeInstanceIdentifier; private final DeviceInfo deviceInfo; private final DeviceContext deviceContext; @@ -105,6 +152,7 @@ final class RpcContextImpl implements RpcContext { private final NotificationPublishService notificationPublishService; private ContextChainMastershipWatcher contextChainMastershipWatcher = null; + private Registration rpcRegistration; RpcContextImpl(@NonNull final RpcProviderService rpcProviderRegistry, final int maxRequests, @@ -125,18 +173,9 @@ final class RpcContextImpl implements RpcContext { tracker = new Semaphore(maxRequests, true); } - private void registerRpcServiceImplementation(final Class serviceClass, - final S serviceInstance) { - if (!rpcRegistrations.containsKey(serviceClass)) { - final ObjectRegistration routedRpcReg = rpcProviderRegistry.registerRpcImplementation(serviceClass, - serviceInstance, ImmutableSet.of(nodeInstanceIdentifier)); - rpcRegistrations.put(serviceClass, routedRpcReg); - if (LOG.isDebugEnabled()) { - LOG.debug("Registration of service {} for device {}.", - serviceClass.getSimpleName(), - nodeInstanceIdentifier.getKey().getId().getValue()); - } - } + @Override + public ServiceGroupIdentifier getIdentifier() { + return deviceInfo.getServiceIdentifier(); } @Override @@ -145,15 +184,10 @@ final class RpcContextImpl implements RpcContext { } private void unregisterRPCs() { - for (var iterator = Iterators.consumingIterator(rpcRegistrations.entrySet().iterator()); iterator.hasNext(); ) { - final var rpcRegistration = iterator.next().getValue(); + if (rpcRegistration != null) { + LOG.debug("Closing RPC registrations for device {}.", nodeInstanceIdentifier.getKey().getId().getValue()); rpcRegistration.close(); - - if (LOG.isDebugEnabled()) { - LOG.debug("Closing RPC Registration of service {} for device {}.", - rpcRegistration.getInstance().getClass().getSimpleName(), - nodeInstanceIdentifier.getKey().getId().getValue()); - } + rpcRegistration = null; } } @@ -185,11 +219,6 @@ final class RpcContextImpl implements RpcContext { }; } - @VisibleForTesting - boolean isEmptyRpcRegistrations() { - return rpcRegistrations.isEmpty(); - } - @Override public DeviceInfo getDeviceInfo() { return deviceInfo; @@ -208,94 +237,176 @@ final class RpcContextImpl implements RpcContext { @Override public void instantiateServiceInstance() { - // TODO: Use multipart writer provider from device context - final var multipartWriterProvider = MultipartWriterProviderFactory.createDefaultProvider(deviceContext); + // flow-capable-transaction.yang + final var sendBarrier = new SendBarrierImpl(this, deviceContext); + + // sal-experimenter-message.yang + final var sendExperimenter = new SendExperimenterImpl(this, deviceContext, extensionConverterProvider); - // create service instances - final var salFlowService = new SalFlowServiceImpl(this, deviceContext, convertorExecutor); - final var flowCapableTransactionService = new FlowCapableTransactionServiceImpl(this, deviceContext); - final var salAsyncConfigService = new SalAsyncConfigServiceImpl(this, deviceContext); - final var salGroupService = new SalGroupServiceImpl(this, deviceContext, convertorExecutor); - final var salMeterService = new SalMeterServiceImpl(this, deviceContext, convertorExecutor); - final var flowStatisticsService = OpendaylightFlowStatisticsServiceImpl.createWithOook(this, deviceContext, - convertorExecutor); + // sal-flow.yang + final var addFlow = new AddFlowImpl(this, deviceContext, convertorExecutor); + final var removeFlow = new RemoveFlowImpl(this, deviceContext, convertorExecutor); + final var updateFlow = new UpdateFlowImpl(this, deviceContext, convertorExecutor); - // register routed service instances - registerRpcServiceImplementation(SalEchoService.class, new SalEchoServiceImpl(this, deviceContext)); - registerRpcServiceImplementation(SalFlowService.class, salFlowService); - registerRpcServiceImplementation(FlowCapableTransactionService.class, flowCapableTransactionService); - registerRpcServiceImplementation(SalAsyncConfigService.class, salAsyncConfigService); - registerRpcServiceImplementation(SalMeterService.class, salMeterService); - registerRpcServiceImplementation(SalGroupService.class, salGroupService); - registerRpcServiceImplementation(SalTableService.class, - new SalTableServiceImpl(this, deviceContext, convertorExecutor, multipartWriterProvider)); - registerRpcServiceImplementation(SalPortService.class, - new SalPortServiceImpl(this, deviceContext, convertorExecutor)); - registerRpcServiceImplementation(PacketProcessingService.class, - new PacketProcessingServiceImpl(this, deviceContext, convertorExecutor)); - registerRpcServiceImplementation(NodeConfigService.class, new NodeConfigServiceImpl(this, deviceContext)); - registerRpcServiceImplementation(OpendaylightFlowStatisticsService.class, flowStatisticsService); + // sal-group.yang + final var addGroup = new AddGroupImpl(this, deviceContext, convertorExecutor); + final var removeGroup = new RemoveGroupImpl(this, deviceContext, convertorExecutor); + final var updateGroup = new UpdateGroupImpl(this, deviceContext, convertorExecutor); - // register direct statistics gathering services - registerRpcServiceImplementation(OpendaylightDirectStatisticsService.class, - new OpendaylightDirectStatisticsServiceImpl(deviceContext.canUseSingleLayerSerialization() - ? SingleLayerDirectStatisticsProviderInitializer.createProvider(this, deviceContext, convertorExecutor, - multipartWriterProvider) - : MultiLayerDirectStatisticsProviderInitializer.createProvider(this, deviceContext, convertorExecutor, - multipartWriterProvider))); + // sal-meter.yang + final var addMeter = new AddMeterImpl(this, deviceContext, convertorExecutor); + final var removeMeter = new RemoveMeterImpl(this, deviceContext, convertorExecutor); + final var updateMeter = new UpdateMeterImpl(this, deviceContext, convertorExecutor); - // register flat batch services - registerRpcServiceImplementation(SalFlatBatchService.class, new SalFlatBatchServiceImpl( - new SalFlowsBatchServiceImpl(salFlowService, flowCapableTransactionService), - new SalGroupsBatchServiceImpl(salGroupService, flowCapableTransactionService), - new SalMetersBatchServiceImpl(salMeterService, flowCapableTransactionService))); + // FIXME: Use multipart writer provider from device context + final var multipartWriterProvider = MultipartWriterProviderFactory.createDefaultProvider(deviceContext); - // register experimenter services - registerRpcServiceImplementation(SalExperimenterMessageService.class, - new SalExperimenterMessageServiceImpl(this, deviceContext, extensionConverterProvider)); - registerRpcServiceImplementation(SalExperimenterMpMessageService.class, - new SalExperimenterMpMessageServiceImpl(this, deviceContext, extensionConverterProvider)); + final var singleLayer = deviceContext.canUseSingleLayerSerialization(); - //register onf extension bundles - registerRpcServiceImplementation(SalBundleService.class, new SalBundleServiceImpl( - new SalExperimenterMessageServiceImpl(this, deviceContext, extensionConverterProvider))); + final var builder = ImmutableClassToInstanceMap.>builder() + .put(SendBarrier.class, sendBarrier) + // node-config.yang + .put(SetConfig.class, new SetConfigImpl(this, deviceContext)) + // packet-processing.yang + .put(TransmitPacket.class, new TransmitPacketImpl(this, deviceContext, convertorExecutor)) + // sal-async-config.yang + .put(GetAsync.class, new GetAsyncImpl(this, deviceContext)) + .put(SetAsync.class, new SetAsyncImpl(this, deviceContext)) + // sal-echo.yang + .put(SendEcho.class, new SendEchoImpl(this, deviceContext)) + .put(SendExperimenter.class, sendExperimenter) + // sal-bundle.yang (ONF extension?) + .put(ControlBundle.class, new ControlBundleImpl(sendExperimenter)) + .put(AddBundleMessages.class, new AddBundleMessagesImpl(sendExperimenter)) + // sal-experimenter-mp-message.yang + .put(SendExperimenterMpRequest.class, new SendExperimenterMpRequestImpl(this, deviceContext, + extensionConverterProvider)) + .put(AddFlow.class, addFlow) + .put(RemoveFlow.class, removeFlow) + .put(UpdateFlow.class, updateFlow) + .put(AddGroup.class, addGroup) + .put(RemoveGroup.class, removeGroup) + .put(UpdateGroup.class, updateGroup) + .put(AddMeter.class, addMeter) + .put(RemoveMeter.class, removeMeter) + .put(UpdateMeter.class, updateMeter) + // sal-port.yang + .put(UpdatePort.class, new UpdatePortImpl(this, deviceContext, convertorExecutor)) + // sal-flat-batch.yang + .put(ProcessFlatBatch.class, new ProcessFlatBatchImpl( + // sal-flows-batch.yang + // FIXME: register these? + new AddFlowsBatchImpl(addFlow, sendBarrier), + new RemoveFlowsBatchImpl(removeFlow, sendBarrier), + new UpdateFlowsBatchImpl(updateFlow, sendBarrier), + // sal-groups-batch.yang + // FIXME: register these? + new AddGroupsBatchImpl(addGroup, sendBarrier), + new RemoveGroupsBatchImpl(removeGroup, sendBarrier), + new UpdateGroupsBatchImpl(updateGroup, sendBarrier), + // sal-meters-batch.yang + // FIXME: register these? + new AddMetersBatchImpl(addMeter, sendBarrier), + new RemoveMetersBatchImpl(removeMeter, sendBarrier), + new UpdateMetersBatchImpl(updateMeter, sendBarrier))) + // sal-table.yang + .put(UpdateTable.class, new UpdateTableImpl(this, deviceContext, convertorExecutor, + multipartWriterProvider)) + // opendaylight-flow-statistics.yang + .put(GetAggregateFlowStatisticsFromFlowTableForGivenMatch.class, + new GetAggregateFlowStatisticsFromFlowTableForGivenMatchImpl(this, deviceContext, convertorExecutor)) + // opendaylight-direct-statistics.yang + .put(GetFlowStatistics.class, singleLayer + ? new SingleGetFlowStatistics(this, deviceContext, convertorExecutor, multipartWriterProvider) + : new MultiGetFlowStatistics(this, deviceContext, convertorExecutor, multipartWriterProvider)) + .put(GetGroupStatistics.class, singleLayer + ? new SingleGetGroupStatistics(this, deviceContext, convertorExecutor, multipartWriterProvider) + : new MultiGetGroupStatistics(this, deviceContext, convertorExecutor, multipartWriterProvider)) + .put(GetQueueStatistics.class, singleLayer + ? new SingleGetQueueStatistics(this, deviceContext, convertorExecutor, multipartWriterProvider) + : new MultiGetQueueStatistics(this, deviceContext, convertorExecutor, multipartWriterProvider)) + .put(GetMeterStatistics.class, singleLayer + ? new SingleGetMeterStatistics(this, deviceContext, convertorExecutor, multipartWriterProvider) + : new MultiGetMeterStatistics(this, deviceContext, convertorExecutor, multipartWriterProvider)) + .put(GetNodeConnectorStatistics.class, singleLayer + ? new SingleGetNodeConnectorStatistics(this, deviceContext, convertorExecutor, multipartWriterProvider) + : new MultiGetNodeConnectorStatistics(this, deviceContext, convertorExecutor, multipartWriterProvider)); // Support deprecated statistic related services for backward compatibility. The only exception from deprecation // is the aggregated flow statistic with match criteria input. if (isStatisticsRpcEnabled && !deviceContext.canUseSingleLayerSerialization()) { final var compatibilityXidSeed = new AtomicLong(); + // FIXME: why is this separate? + final var statsCompatXidSeed = new AtomicLong(); - // attach delegate to flow statistics service (to cover all but aggregated stats with match filter input) - final var flowStatisticsDelegate = new OpendaylightFlowStatisticsServiceDelegateImpl(this, deviceContext, - notificationPublishService, new AtomicLong(), convertorExecutor); - flowStatisticsService.setDelegate(flowStatisticsDelegate); + builder + // Legacy RPCs + .put(GetAggregateFlowStatisticsFromFlowTableForAllFlows.class, + new GetAggregateFlowStatisticsFromFlowTableForAllFlowsImpl(this, deviceContext, convertorExecutor, + statsCompatXidSeed, notificationPublishService)) + .put(GetAllFlowStatisticsFromFlowTable.class, + new GetAllFlowStatisticsFromFlowTableImpl(this, deviceContext, convertorExecutor, + statsCompatXidSeed, notificationPublishService)) + .put(GetAllFlowsStatisticsFromAllFlowTables.class, + new GetAllFlowsStatisticsFromAllFlowTablesImpl(this, deviceContext, convertorExecutor, + statsCompatXidSeed, notificationPublishService)) + .put(GetFlowStatisticsFromFlowTable.class, + new GetFlowStatisticsFromFlowTableImpl(this, deviceContext, convertorExecutor, statsCompatXidSeed, + notificationPublishService)) - // register all statistics (deprecated) services - registerRpcServiceImplementation(OpendaylightFlowTableStatisticsService.class, - new OpendaylightFlowTableStatisticsServiceImpl(this, deviceContext, - compatibilityXidSeed, notificationPublishService)); - registerRpcServiceImplementation(OpendaylightGroupStatisticsService.class, - new OpendaylightGroupStatisticsServiceImpl(this, deviceContext, - compatibilityXidSeed, notificationPublishService, convertorExecutor)); - registerRpcServiceImplementation(OpendaylightMeterStatisticsService.class, - new OpendaylightMeterStatisticsServiceImpl(this, deviceContext, - compatibilityXidSeed, notificationPublishService, convertorExecutor)); - registerRpcServiceImplementation(OpendaylightQueueStatisticsService.class, - new OpendaylightQueueStatisticsServiceImpl(this, deviceContext, - compatibilityXidSeed, notificationPublishService)); - registerRpcServiceImplementation(OpendaylightPortStatisticsService.class, - new OpendaylightPortStatisticsServiceImpl(this, deviceContext, - compatibilityXidSeed, notificationPublishService)); + // register all statistics (deprecated) services + .put(GetFlowTablesStatistics.class, + new GetFlowTablesStatisticsImpl(this, deviceContext, compatibilityXidSeed, + notificationPublishService)) + .put(org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatistics.class, + new GetGroupStatisticsImpl(this, deviceContext, compatibilityXidSeed, notificationPublishService, + convertorExecutor)) + .put(GetAllGroupStatistics.class, + new GetAllGroupStatisticsImpl(this, deviceContext, compatibilityXidSeed, notificationPublishService, + convertorExecutor)) + .put(GetGroupDescription.class, + new GetGroupDescriptionImpl(this, deviceContext, compatibilityXidSeed, notificationPublishService, + convertorExecutor)) + .put(GetGroupFeatures.class, + new GetGroupFeaturesImpl(this, deviceContext, compatibilityXidSeed, notificationPublishService, + convertorExecutor)) + .put(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatistics.class, + new GetMeterStatisticsImpl(this, deviceContext, compatibilityXidSeed, notificationPublishService, + convertorExecutor)) + .put(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111 + .GetAllMeterStatistics.class, + new GetAllMeterStatisticsImpl(this, deviceContext, compatibilityXidSeed, notificationPublishService, + convertorExecutor)) + .put(GetAllMeterConfigStatistics.class, + new GetAllMeterConfigStatisticsImpl(this, deviceContext, compatibilityXidSeed, + notificationPublishService, convertorExecutor)) + .put(GetMeterFeatures.class, + new GetMeterFeaturesImpl(this, deviceContext, compatibilityXidSeed, notificationPublishService, + convertorExecutor)) + .put(GetQueueStatisticsFromGivenPort.class, + new GetQueueStatisticsFromGivenPortImpl(this, deviceContext, compatibilityXidSeed, + notificationPublishService)) + .put(GetAllQueuesStatisticsFromAllPorts.class, + new GetAllQueuesStatisticsFromAllPortsImpl(this, deviceContext, compatibilityXidSeed, + notificationPublishService)) + .put(GetAllQueuesStatisticsFromGivenPort.class, + new GetAllQueuesStatisticsFromGivenPortImpl(this, deviceContext, compatibilityXidSeed, + notificationPublishService)) + .put(org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214 + .GetNodeConnectorStatistics.class, + new GetNodeConnectorStatisticsImpl(this, deviceContext, compatibilityXidSeed, + notificationPublishService)) + .put(GetAllNodeConnectorsStatistics.class, + new GetAllNodeConnectorsStatisticsImpl(this, deviceContext, compatibilityXidSeed, + notificationPublishService)); } + rpcRegistration = rpcProviderRegistry.registerRpcImplementations(builder.build(), + Set.of(nodeInstanceIdentifier)); + final var local = contextChainMastershipWatcher; if (local != null) { local.onMasterRoleAcquired(deviceInfo, ContextChainMastershipState.RPC_REGISTRATION); } } - - @Override - public ServiceGroupIdentifier getIdentifier() { - return deviceInfo.getServiceIdentifier(); - } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/AbstractService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/AbstractService.java index 2324783238..ac9e580a58 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/AbstractService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/AbstractService.java @@ -55,9 +55,9 @@ public abstract class AbstractService { this.requestContextStack = requestContextStack; this.deviceContext = deviceContext; - this.datapathId = deviceInfo.getDatapathId(); - this.version = deviceInfo.getVersion(); - this.messageSpy = deviceContext.getMessageSpy(); + datapathId = deviceInfo.getDatapathId(); + version = deviceInfo.getVersion(); + messageSpy = deviceContext.getMessageSpy(); } public boolean canUseSingleLayerSerialization() { @@ -109,11 +109,11 @@ public abstract class AbstractService { protected abstract FutureCallback createCallback(RequestContext context, Class requestType); - public ListenableFuture> handleServiceCall(@NonNull final I input) { + public @NonNull ListenableFuture> handleServiceCall(@NonNull final I input) { return handleServiceCall(input, null); } - public ListenableFuture> handleServiceCall(@NonNull final I input, + public @NonNull ListenableFuture> handleServiceCall(@NonNull final I input, @Nullable final Function isComplete) { requireNonNull(input); diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/EchoService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/EchoService.java deleted file mode 100644 index 8951e2b4de..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/EchoService.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl.services; - -import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.openflowplugin.api.openflow.device.Xid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; - -public class EchoService extends AbstractSimpleService { - public EchoService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) { - super(requestContextStack, deviceContext, EchoOutput.class); - } - - @Override - protected OfHeader buildRequest(final Xid xid, final EchoInputBuilder input) { - return input - .setXid(xid.getValue()) - .setVersion(getVersion()) - .build(); - } -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalEchoServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SendEchoImpl.java similarity index 68% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalEchoServiceImpl.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SendEchoImpl.java index a857d4f5bc..9482519f26 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalEchoServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SendEchoImpl.java @@ -5,7 +5,7 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.impl.services.sal; +package org.opendaylight.openflowplugin.impl.services; import static java.util.Objects.requireNonNull; @@ -14,33 +14,25 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.openflowplugin.impl.services.EchoService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SalEchoService; +import org.opendaylight.openflowplugin.api.openflow.device.Xid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEcho; import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -public final class SalEchoServiceImpl implements SalEchoService { - private final EchoService echoService; - - public SalEchoServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) { - echoService = new EchoService(requestContextStack, deviceContext); +public final class SendEchoImpl extends AbstractSimpleService implements SendEcho { + public SendEchoImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) { + super(requestContextStack, deviceContext, EchoOutput.class); } @Override - public ListenableFuture> sendEcho(final SendEchoInput sendEchoInput) { - final EchoInputBuilder echoInputBld = new EchoInputBuilder() - .setData(sendEchoInput.getData()); - return transform(echoService.handleServiceCall(echoInputBld)); - } - - private static ListenableFuture> - transform(final ListenableFuture> rpcResultListenableFuture) { - return Futures.transform(rpcResultListenableFuture, input -> { + public ListenableFuture> invoke(final SendEchoInput sendEchoInput) { + return Futures.transform(handleServiceCall(new EchoInputBuilder().setData(sendEchoInput.getData())), input -> { requireNonNull(input, "echoOutput value is never expected to be NULL"); final RpcResult rpcOutput; if (input.isSuccessful()) { @@ -56,4 +48,12 @@ public final class SalEchoServiceImpl implements SalEchoService { return rpcOutput; }, MoreExecutors.directExecutor()); } + + @Override + protected OfHeader buildRequest(final Xid xid, final EchoInputBuilder input) { + return input + .setXid(xid.getValue()) + .setVersion(getVersion()) + .build(); + } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AbstractDeviceRpc.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AbstractDeviceRpc.java new file mode 100644 index 0000000000..fb8b5b8b32 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AbstractDeviceRpc.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import static java.util.Objects.requireNonNull; + +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; + +abstract class AbstractDeviceRpc { + final @NonNull DeviceContext deviceContext; + + AbstractDeviceRpc(final DeviceContext deviceContext) { + this.deviceContext = requireNonNull(deviceContext); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AbstractFlowRpc.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AbstractFlowRpc.java new file mode 100644 index 0000000000..69a46cc755 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AbstractFlowRpc.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerFlowService; +import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerFlowService; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yangtools.yang.binding.RpcOutput; + +abstract class AbstractFlowRpc extends AbstractDeviceRpc { + final @NonNull MultiLayerFlowService multi; + final @NonNull SingleLayerFlowService single; + + AbstractFlowRpc(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor, final Class output) { + super(deviceContext); + multi = new MultiLayerFlowService<>(requestContextStack, deviceContext, output, convertorExecutor); + single = new SingleLayerFlowService<>(requestContextStack, deviceContext, output); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AbstractGroupRpc.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AbstractGroupRpc.java new file mode 100644 index 0000000000..c9e51cddba --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AbstractGroupRpc.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerGroupService; +import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerGroupService; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group; +import org.opendaylight.yangtools.yang.binding.RpcOutput; + +abstract class AbstractGroupRpc extends AbstractDeviceRpc { + final @NonNull MultiLayerGroupService multi; + final @NonNull SingleLayerGroupService single; + + AbstractGroupRpc(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor, final Class output) { + super(deviceContext); + multi = new MultiLayerGroupService<>(requestContextStack, deviceContext, output, convertorExecutor); + single = new SingleLayerGroupService<>(requestContextStack, deviceContext, output); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AbstractMeterRpc.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AbstractMeterRpc.java new file mode 100644 index 0000000000..1aec754d4a --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AbstractMeterRpc.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerMeterService; +import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerMeterService; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter; +import org.opendaylight.yangtools.yang.binding.RpcOutput; + +abstract class AbstractMeterRpc extends AbstractDeviceRpc { + final @NonNull MultiLayerMeterService multi; + final @NonNull SingleLayerMeterService single; + + AbstractMeterRpc(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor, final Class output) { + super(deviceContext); + multi = new MultiLayerMeterService<>(requestContextStack, deviceContext, output, convertorExecutor); + single = new SingleLayerMeterService<>(requestContextStack, deviceContext, output); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddBundleMessagesImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddBundleMessagesImpl.java new file mode 100644 index 0000000000..16109ecf1a --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddBundleMessagesImpl.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import com.google.common.util.concurrent.SettableFuture; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenterInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenterOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.AddBundleMessages; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.AddBundleMessagesInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.AddBundleMessagesOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleAddMessageSalBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.bundle.add.message.sal.SalAddMessageDataBuilder; +import org.opendaylight.yangtools.yang.common.ErrorTag; +import org.opendaylight.yangtools.yang.common.ErrorType; +import org.opendaylight.yangtools.yang.common.RpcError; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; + +public final class AddBundleMessagesImpl implements AddBundleMessages { + private final SendExperimenter sendExperimenter; + + public AddBundleMessagesImpl(final SendExperimenter sendExperimenter) { + this.sendExperimenter = requireNonNull(sendExperimenter); + } + + @Override + public ListenableFuture> invoke(final AddBundleMessagesInput input) { + final var partialResults = new ArrayList>>(); + final var experimenterInputBuilder = new SendExperimenterInputBuilder() + .setNode(input.getNode()); + final var bundleAddMessageBuilder = new BundleAddMessageSalBuilder(); + final var dataBuilder = new SalAddMessageDataBuilder() + .setNode(input.getNode()) + .setBundleId(input.getBundleId()) + .setFlags(input.getFlags()) + .setBundleProperty(input.getBundleProperty()); + for (var message : input.nonnullMessages().getMessage()) { + dataBuilder.setBundleInnerMessage(message.getBundleInnerMessage()); + experimenterInputBuilder.setExperimenterMessageOfChoice( + bundleAddMessageBuilder.setSalAddMessageData(dataBuilder.build()).build()); + partialResults.add(sendExperimenter.invoke(experimenterInputBuilder.build())); + } + + final var result = SettableFuture.>create(); + Futures.addCallback(Futures.successfulAsList(partialResults),new FutureCallback<>() { + @Override + public void onSuccess(final List> results) { + final var errors = new ArrayList(); + final RpcResultBuilder rpcResultBuilder; + for (var res : results) { + if (res == null) { + // FIXME: this should never happen + errors.add(RpcResultBuilder.newError(ErrorType.APPLICATION, + new ErrorTag("BundleExtensionService"), "RpcResult is null.")); + } else if (!res.isSuccessful()) { + errors.addAll(res.getErrors()); + } + } + if (errors.isEmpty()) { + rpcResultBuilder = RpcResultBuilder.success(); + } else { + rpcResultBuilder = RpcResultBuilder.failed().withRpcErrors(errors); + } + result.set(rpcResultBuilder.build()); + } + + @Override + public void onFailure(final Throwable throwable) { + result.set(RpcResultBuilder.failed().build()); + } + }, MoreExecutors.directExecutor()); + return result; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddFlowImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddFlowImpl.java new file mode 100644 index 0000000000..b8aca0cbfc --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddFlowImpl.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2024 PANTHEON.tech, s.r.o. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import org.opendaylight.openflowplugin.api.openflow.FlowGroupStatus; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry; +import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor; +import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey; +import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory; +import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory; +import org.opendaylight.openflowplugin.impl.util.ErrorUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.Uint8; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class AddFlowImpl extends AbstractFlowRpc implements AddFlow { + private static final Logger LOG = LoggerFactory.getLogger(AddFlowImpl.class); + + public AddFlowImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor) { + super(requestContextStack, deviceContext, convertorExecutor, AddFlowOutput.class); + } + + @Override + public ListenableFuture> invoke(final AddFlowInput input) { + final var flowRegistryKey = FlowRegistryKeyFactory.create(deviceContext.getDeviceInfo().getVersion(), input); + final var future = single.canUseSingleLayerSerialization() ? single.handleServiceCall(input) + : multi.processFlowModInputBuilders(multi.toFlowModInputs(input)); + Futures.addCallback(future, new AddFlowCallback(input, flowRegistryKey), + MoreExecutors.directExecutor()); + return future; + } + + private final class AddFlowCallback implements FutureCallback> { + private final AddFlowInput input; + private final FlowRegistryKey flowRegistryKey; + + private AddFlowCallback(final AddFlowInput input, final FlowRegistryKey flowRegistryKey) { + this.input = input; + this.flowRegistryKey = flowRegistryKey; + } + + @Override + public void onSuccess(final RpcResult rpcResult) { + if (!rpcResult.isSuccessful()) { + if (LOG.isDebugEnabled()) { + LOG.debug("Flow add failed for flow={}, errors={}", input, + ErrorUtil.errorsToString(rpcResult.getErrors())); + } + return; + } + + final DeviceFlowRegistry flowRegistry = deviceContext.getDeviceFlowRegistry(); + final FlowDescriptor flowDescriptor; + final FlowRef flowRef = input.getFlowRef(); + if (flowRef != null) { + final Uint8 tableId = input.getTableId(); + final FlowId flowId = flowRef.getValue().firstKeyOf(Flow.class).getId(); + flowDescriptor = FlowDescriptorFactory.create(tableId, flowId); + + // FIXME: this looks like an atomic operation + flowRegistry.appendHistoryFlow(flowId, tableId, FlowGroupStatus.ADDED); + flowRegistry.storeDescriptor(flowRegistryKey, flowDescriptor); + } else { + // FIXME: this looks like an atomic operation + flowRegistry.store(flowRegistryKey); + flowDescriptor = flowRegistry.retrieveDescriptor(flowRegistryKey); + } + + if (LOG.isDebugEnabled()) { + LOG.debug("Flow add with id={} finished without error", flowDescriptor.getFlowId().getValue()); + } + } + + @Override + public void onFailure(final Throwable throwable) { + LOG.warn("Service call for adding flow={} failed", input, throwable); + } + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddFlowsBatchImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddFlowsBatchImpl.java new file mode 100644 index 0000000000..176a3aa450 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddFlowsBatchImpl.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import org.opendaylight.openflowplugin.impl.util.BarrierUtil; +import org.opendaylight.openflowplugin.impl.util.FlowUtil; +import org.opendaylight.openflowplugin.impl.util.PathUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.BatchFlowInputGrouping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class AddFlowsBatchImpl implements AddFlowsBatch { + private static final Logger LOG = LoggerFactory.getLogger(AddFlowsBatchImpl.class); + + private final AddFlow addFlow; + private final SendBarrier sendBarrier; + + public AddFlowsBatchImpl(final AddFlow addFlow, final SendBarrier sendBarrier) { + this.addFlow = requireNonNull(addFlow); + this.sendBarrier = requireNonNull(sendBarrier); + } + + @Override + public ListenableFuture> invoke(final AddFlowsBatchInput input) { + final var flows = input.nonnullBatchAddFlows().values(); + if (LOG.isTraceEnabled()) { + LOG.trace("Adding flows @ {} : {}", PathUtil.extractNodeId(input.getNode()), flows.size()); + } + + final var resultsLot = flows.stream() + .map(batchFlow -> addFlow.invoke(new AddFlowInputBuilder(batchFlow) + .setFlowRef(createFlowRef(input.getNode(), batchFlow)) + .setNode(input.getNode()) + .build())) + .toList(); + + final var commonResult = Futures.transform(Futures.successfulAsList(resultsLot), + FlowUtil.createCumulatingFunction(flows), MoreExecutors.directExecutor()); + final var addFlowsBulkFuture = Futures.transform(commonResult, FlowUtil.FLOW_ADD_TRANSFORM, + MoreExecutors.directExecutor()); + return input.getBarrierAfter() + ? BarrierUtil.chainBarrier(addFlowsBulkFuture, input.getNode(), sendBarrier, + FlowUtil.FLOW_ADD_COMPOSING_TRANSFORM) + : addFlowsBulkFuture; + } + + private static FlowRef createFlowRef(final NodeRef nodeRef, final BatchFlowInputGrouping batchFlow) { + return FlowUtil.buildFlowPath((InstanceIdentifier) nodeRef.getValue(), + batchFlow.getTableId(), batchFlow.getFlowId()); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddGroupImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddGroupImpl.java new file mode 100644 index 0000000000..bcfbfaefe0 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddGroupImpl.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2024 PANTHEON.tech, s.r.o. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import org.opendaylight.openflowplugin.api.openflow.FlowGroupStatus; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.impl.util.ErrorUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroup; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class AddGroupImpl extends AbstractGroupRpc implements AddGroup { + private static final Logger LOG = LoggerFactory.getLogger(AddGroupImpl.class); + + public AddGroupImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor) { + super(requestContextStack, deviceContext, convertorExecutor, AddGroupOutput.class); + } + + @Override + public ListenableFuture> invoke(final AddGroupInput input) { + final var resultFuture = single.canUseSingleLayerSerialization() ? single.handleServiceCall(input) + : multi.handleServiceCall(input); + Futures.addCallback(resultFuture, new FutureCallback<>() { + @Override + public void onSuccess(final RpcResult result) { + if (result.isSuccessful()) { + LOG.debug("adding group successful {}", input.getGroupId()); + deviceContext.getDeviceGroupRegistry().appendHistoryGroup(input.getGroupId(), input.getGroupType(), + FlowGroupStatus.ADDED); + } else if (LOG.isDebugEnabled()) { + LOG.debug("Group add with id={} failed, errors={}", input.getGroupId().getValue(), + ErrorUtil.errorsToString(result.getErrors())); + } + } + + @Override + public void onFailure(final Throwable throwable) { + LOG.warn("Service call for adding group={} failed", + input.getGroupId().getValue(), + throwable); + } + }, MoreExecutors.directExecutor()); + return resultFuture; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddGroupsBatchImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddGroupsBatchImpl.java new file mode 100644 index 0000000000..155bc11674 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddGroupsBatchImpl.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import java.util.stream.Collectors; +import org.opendaylight.openflowplugin.impl.util.BarrierUtil; +import org.opendaylight.openflowplugin.impl.util.GroupUtil; +import org.opendaylight.openflowplugin.impl.util.PathUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroup; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class AddGroupsBatchImpl implements AddGroupsBatch { + private static final Logger LOG = LoggerFactory.getLogger(AddGroupsBatchImpl.class); + + private final AddGroup addGroup; + private final SendBarrier sendBarrier; + + public AddGroupsBatchImpl(final AddGroup addGroup, final SendBarrier sendBarrier) { + this.addGroup = requireNonNull(addGroup); + this.sendBarrier = requireNonNull(sendBarrier); + } + + @Override + public ListenableFuture> invoke(final AddGroupsBatchInput input) { + final var groups = input.nonnullBatchAddGroups().values(); + if (LOG.isTraceEnabled()) { + LOG.trace("Adding groups @ {} : {}", PathUtil.extractNodeId(input.getNode()), groups.size()); + } + + final var resultsLot = groups.stream() + .map(group -> addGroup.invoke(new AddGroupInputBuilder(group) + .setGroupRef(createGroupRef(input.getNode(), group)) + .setNode(input.getNode()) + .build())) + .collect(Collectors.toList()); + + final var commonResult = Futures.transform(Futures.allAsList(resultsLot), + GroupUtil.createCumulatingFunction(groups), MoreExecutors.directExecutor()); + + final var addGroupsBulkFuture = Futures.transform(commonResult, GroupUtil.GROUP_ADD_TRANSFORM, + MoreExecutors.directExecutor()); + + return input.getBarrierAfter() + ? BarrierUtil.chainBarrier(addGroupsBulkFuture, input.getNode(), sendBarrier, + GroupUtil.GROUP_ADD_COMPOSING_TRANSFORM) + : addGroupsBulkFuture; + } + + private static GroupRef createGroupRef(final NodeRef nodeRef, final Group batchGroup) { + return GroupUtil.buildGroupPath((InstanceIdentifier) nodeRef.getValue(), batchGroup.getGroupId()); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddMeterImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddMeterImpl.java new file mode 100644 index 0000000000..dba51cb814 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddMeterImpl.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2024 PANTHEON.tech, s.r.o. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.impl.util.ErrorUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class AddMeterImpl extends AbstractMeterRpc implements AddMeter { + private static final Logger LOG = LoggerFactory.getLogger(AddMeterImpl.class); + + public AddMeterImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor) { + super(requestContextStack, deviceContext, convertorExecutor, AddMeterOutput.class); + } + + @Override + public ListenableFuture> invoke(final AddMeterInput input) { + final var resultFuture = single.canUseSingleLayerSerialization() ? single.handleServiceCall(input) + : multi.handleServiceCall(input); + + Futures.addCallback(resultFuture, new FutureCallback<>() { + @Override + public void onSuccess(final RpcResult result) { + if (result.isSuccessful()) { + if (LOG.isDebugEnabled()) { + LOG.debug("Meter add with id={} finished without error", input.getMeterId()); + } + } else if (LOG.isDebugEnabled()) { + LOG.debug("Meter add with id={} failed, errors={}", input.getMeterId(), + ErrorUtil.errorsToString(result.getErrors())); + } + } + + @Override + public void onFailure(final Throwable throwable) { + LOG.warn("Service call for adding meter={} failed", input.getMeterId(), throwable); + } + }, MoreExecutors.directExecutor()); + return resultFuture; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddMetersBatchImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddMetersBatchImpl.java new file mode 100644 index 0000000000..0f24176706 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/AddMetersBatchImpl.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import java.util.stream.Collectors; +import org.opendaylight.openflowplugin.impl.util.BarrierUtil; +import org.opendaylight.openflowplugin.impl.util.MeterUtil; +import org.opendaylight.openflowplugin.impl.util.PathUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchOutput; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class AddMetersBatchImpl implements AddMetersBatch { + private static final Logger LOG = LoggerFactory.getLogger(AddMetersBatchImpl.class); + + private final AddMeter addMeter; + private final SendBarrier sendBarrier; + + public AddMetersBatchImpl(final AddMeter addMeter, final SendBarrier sendBarrier) { + this.addMeter = requireNonNull(addMeter); + this.sendBarrier = requireNonNull(sendBarrier); + } + + @Override + public ListenableFuture> invoke(final AddMetersBatchInput input) { + final var meters = input.nonnullBatchAddMeters().values(); + if (LOG.isTraceEnabled()) { + LOG.trace("Adding meters @ {} : {}", PathUtil.extractNodeId(input.getNode()), meters.size()); + } + + final var resultsLot = meters.stream() + .map(meter -> addMeter.invoke(new AddMeterInputBuilder(meter) + .setMeterRef(createMeterRef(input.getNode(), meter)) + .setNode(input.getNode()) + .build())) + .collect(Collectors.toList()); + + final var commonResult = Futures.transform(Futures.allAsList(resultsLot), + MeterUtil.createCumulativeFunction(meters), MoreExecutors.directExecutor()); + + final var addMetersBulkFuture = Futures.transform(commonResult, MeterUtil.METER_ADD_TRANSFORM, + MoreExecutors.directExecutor()); + + return input.getBarrierAfter() + ? BarrierUtil.chainBarrier(addMetersBulkFuture, input.getNode(), sendBarrier, + MeterUtil.METER_ADD_COMPOSING_TRANSFORM) + : addMetersBulkFuture; + } + + private static MeterRef createMeterRef(final NodeRef nodeRef, final Meter batchMeter) { + return MeterUtil.buildMeterPath((InstanceIdentifier) nodeRef.getValue(), batchMeter.getMeterId()); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/ControlBundleImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/ControlBundleImpl.java new file mode 100644 index 0000000000..9cd50cd4da --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/ControlBundleImpl.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved. + * Copyright (c) 2024 PANTHEON.tech, s.r.o. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenterInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.ControlBundle; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.ControlBundleInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.ControlBundleOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControlSalBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.bundle.control.sal.SalControlDataBuilder; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class ControlBundleImpl implements ControlBundle { + private static final Logger LOG = LoggerFactory.getLogger(ControlBundleImpl.class); + + private final SendExperimenter sendExperimenter; + + public ControlBundleImpl(final SendExperimenter sendExperimenter) { + this.sendExperimenter = requireNonNull(sendExperimenter); + } + + @Override + public ListenableFuture> invoke(final ControlBundleInput input) { + LOG.debug("Control message for device {} and bundle type {}", input.getNode(), input.getType()); + return Futures.transform(sendExperimenter.invoke(new SendExperimenterInputBuilder() + .setNode(input.getNode()) + .setExperimenterMessageOfChoice(new BundleControlSalBuilder() + .setSalControlData(new SalControlDataBuilder(input).build()) + .build()) + .build()), result -> + result.isSuccessful() ? RpcResultBuilder.success().build() + : RpcResultBuilder.failed().build(), + MoreExecutors.directExecutor()); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/ProcessFlatBatchImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/ProcessFlatBatchImpl.java new file mode 100644 index 0000000000..48d1d99e4f --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/ProcessFlatBatchImpl.java @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import static java.util.Objects.requireNonNull; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep; +import org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob; +import org.opendaylight.openflowplugin.impl.services.batch.FlatBatchFlowAdapters; +import org.opendaylight.openflowplugin.impl.services.batch.FlatBatchGroupAdapters; +import org.opendaylight.openflowplugin.impl.services.batch.FlatBatchMeterAdapters; +import org.opendaylight.openflowplugin.impl.util.FlatBatchUtil; +import org.opendaylight.openflowplugin.impl.util.PathUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatch; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class ProcessFlatBatchImpl implements ProcessFlatBatch { + private static final Logger LOG = LoggerFactory.getLogger(ProcessFlatBatchImpl.class); + + private final AddFlowsBatch addFlowsBatch; + private final RemoveFlowsBatch removeFlowsBatch; + private final UpdateFlowsBatch updateFlowsBatch; + private final AddGroupsBatch addGroupsBatch; + private final RemoveGroupsBatch removeGroupsBatch; + private final UpdateGroupsBatch updateGroupsBatch; + private final AddMetersBatch addMetersBatch; + private final RemoveMetersBatch removeMetersBatch; + private final UpdateMetersBatch updateMetersBatch; + + public ProcessFlatBatchImpl(final AddFlowsBatch addFlowsBatch, final RemoveFlowsBatch removeFlowsBatch, + final UpdateFlowsBatch updateFlowsBatch, final AddGroupsBatch addGroupsBatch, + final RemoveGroupsBatch removeGroupsBatch, final UpdateGroupsBatch updateGroupsBatch, + final AddMetersBatch addMetersBatch, final RemoveMetersBatch removeMetersBatch, + final UpdateMetersBatch updateMetersBatch) { + this.addFlowsBatch = requireNonNull(addFlowsBatch); + this.removeFlowsBatch = requireNonNull(removeFlowsBatch); + this.updateFlowsBatch = requireNonNull(updateFlowsBatch); + this.addGroupsBatch = requireNonNull(addGroupsBatch); + this.removeGroupsBatch = requireNonNull(removeGroupsBatch); + this.updateGroupsBatch = requireNonNull(updateGroupsBatch); + this.addMetersBatch = requireNonNull(addMetersBatch); + this.removeMetersBatch = requireNonNull(removeMetersBatch); + this.updateMetersBatch = requireNonNull(updateMetersBatch); + } + + @Override + public ListenableFuture> invoke(final ProcessFlatBatchInput input) { + final var batch = input.nonnullBatch().values(); + if (LOG.isTraceEnabled()) { + LOG.trace("processing flat batch @ {} : {}", PathUtil.extractNodeId(input.getNode()).getValue(), + batch.size()); + } + + // create plan + final var batchPlan = FlatBatchUtil.assembleBatchPlan(batch); + // add barriers where needed + FlatBatchUtil.markBarriersWhereNeeded(batchPlan); + // prepare chain elements + final var batchChainElements = prepareBatchChain(batchPlan, input.getNode(), input.getExitOnFirstError()); + // execute plan with barriers and collect outputs chain correspondingly, collect results + return executeBatchPlan(batchChainElements); + } + + @VisibleForTesting + static ListenableFuture> executeBatchPlan( + final List batchJobsChain) { + BatchStepJob batchJob; + final var firedJobs = new ArrayList>>(); + var chainSummaryResult = FlatBatchUtil.createEmptyRpcBatchResultFuture(true); + + for (int i = 0; i < batchJobsChain.size(); i++) { + batchJob = batchJobsChain.get(i); + // wire actual job with chain + firedJobs.add(Futures.transformAsync(chainSummaryResult, batchJob.getStepFunction(), + MoreExecutors.directExecutor())); + // if barrier after actual job is needed or it is the last job -> merge fired job results with chain result + if (batchJob.getPlanStep().isBarrierAfter() || i == batchJobsChain.size() - 1) { + firedJobs.add(0, chainSummaryResult); + chainSummaryResult = FlatBatchUtil.mergeJobsResultsFutures(firedJobs); + firedJobs.clear(); + } + } + return chainSummaryResult; + } + + @VisibleForTesting + List prepareBatchChain(final List batchPlan, final NodeRef node, + final boolean exitOnFirstError) { + // create batch API calls based on plan steps + final var chainJobs = new ArrayList(); + int stepOffset = 0; + for (final BatchPlanStep planStep : batchPlan) { + final int currentOffset = stepOffset; + chainJobs.add(new BatchStepJob(planStep, chainInput -> { + if (exitOnFirstError && !chainInput.isSuccessful()) { + LOG.debug("error on flat batch chain occurred -> skipping step {}", planStep.getStepType()); + return FlatBatchUtil.createEmptyRpcBatchResultFuture(false); + } + LOG.trace("batch progressing on step type {}, previous steps result: {}", planStep.getStepType(), + chainInput.isSuccessful()); + return getChainOutput(node, planStep, currentOffset); + })); + stepOffset += planStep.getTaskBag().size(); + } + + return chainJobs; + } + + private ListenableFuture> getChainOutput(final NodeRef node, + final BatchPlanStep planStep, final int currentOffset) { + return switch (planStep.getStepType()) { + case FLOW_ADD -> FlatBatchFlowAdapters.convertFlowBatchFutureForChain( + addFlowsBatch.invoke(FlatBatchFlowAdapters.adaptFlatBatchAddFlow(planStep, node)), currentOffset); + case FLOW_REMOVE -> FlatBatchFlowAdapters.convertFlowBatchFutureForChain( + removeFlowsBatch.invoke(FlatBatchFlowAdapters.adaptFlatBatchRemoveFlow(planStep, node)), currentOffset); + case FLOW_UPDATE -> FlatBatchFlowAdapters.convertFlowBatchFutureForChain( + updateFlowsBatch.invoke(FlatBatchFlowAdapters.adaptFlatBatchUpdateFlow(planStep, node)), currentOffset); + case GROUP_ADD -> FlatBatchGroupAdapters.convertGroupBatchFutureForChain( + addGroupsBatch.invoke(FlatBatchGroupAdapters.adaptFlatBatchAddGroup(planStep, node)), currentOffset); + case GROUP_REMOVE -> FlatBatchGroupAdapters.convertGroupBatchFutureForChain( + removeGroupsBatch.invoke(FlatBatchGroupAdapters.adaptFlatBatchRemoveGroup(planStep, node)), + currentOffset); + case GROUP_UPDATE -> FlatBatchGroupAdapters.convertGroupBatchFutureForChain( + updateGroupsBatch.invoke(FlatBatchGroupAdapters.adaptFlatBatchUpdateGroup(planStep, node)), + currentOffset); + case METER_ADD -> FlatBatchMeterAdapters.convertMeterBatchFutureForChain( + addMetersBatch.invoke(FlatBatchMeterAdapters.adaptFlatBatchAddMeter(planStep, node)), currentOffset); + case METER_REMOVE -> FlatBatchMeterAdapters.convertMeterBatchFutureForChain( + removeMetersBatch.invoke(FlatBatchMeterAdapters.adaptFlatBatchRemoveMeter(planStep, node)), + currentOffset); + case METER_UPDATE -> FlatBatchMeterAdapters.convertMeterBatchFutureForChain( + updateMetersBatch.invoke(FlatBatchMeterAdapters.adaptFlatBatchUpdateMeter(planStep, node)), + currentOffset); + }; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveFlowImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveFlowImpl.java new file mode 100644 index 0000000000..15e52ef4d9 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveFlowImpl.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2024 PANTHEON.tech, s.r.o. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import org.opendaylight.openflowplugin.api.openflow.FlowGroupStatus; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry; +import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory; +import org.opendaylight.openflowplugin.impl.util.ErrorUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.Uint8; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class RemoveFlowImpl extends AbstractFlowRpc implements RemoveFlow { + private static final Logger LOG = LoggerFactory.getLogger(RemoveFlowImpl.class); + + public RemoveFlowImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor) { + super(requestContextStack, deviceContext, convertorExecutor, RemoveFlowOutput.class); + } + + @Override + public ListenableFuture> invoke(final RemoveFlowInput input) { + final var future = single.canUseSingleLayerSerialization() ? single.handleServiceCall(input) + : multi.processFlowModInputBuilders(multi.toFlowModInputs(input)); + + Futures.addCallback(future, new RemoveFlowCallback(input), MoreExecutors.directExecutor()); + return future; + } + + private final class RemoveFlowCallback implements FutureCallback> { + private static final Uint8 OFPTT_ALL = Uint8.MAX_VALUE; + + private final RemoveFlowInput input; + + private RemoveFlowCallback(final RemoveFlowInput input) { + this.input = input; + } + + @Override + public void onSuccess(final RpcResult result) { + if (result.isSuccessful()) { + if (LOG.isDebugEnabled()) { + LOG.debug("Flow remove finished without error for flow={}", input); + } + final DeviceFlowRegistry flowRegistry = deviceContext.getDeviceFlowRegistry(); + if (input.getTableId() != null && !input.getTableId().equals(OFPTT_ALL)) { + var flowRegistryKey = + FlowRegistryKeyFactory.create(deviceContext.getDeviceInfo().getVersion(), input); + flowRegistry.addMark(flowRegistryKey); + + final FlowRef flowRef = input.getFlowRef(); + if (flowRef != null) { + final FlowId flowId = flowRef.getValue().firstKeyOf(Flow.class).getId(); + flowRegistry.appendHistoryFlow(flowId, input.getTableId(), FlowGroupStatus.REMOVED); + } + } else { + flowRegistry.clearFlowRegistry(); + } + } else if (LOG.isDebugEnabled()) { + LOG.debug("Flow remove failed for flow={}, errors={}", input, + ErrorUtil.errorsToString(result.getErrors())); + } + } + + @Override + public void onFailure(final Throwable throwable) { + LOG.warn("Service call for removing flow={} failed", input, throwable); + } + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveFlowsBatchImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveFlowsBatchImpl.java new file mode 100644 index 0000000000..2f8eb115a1 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveFlowsBatchImpl.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import org.opendaylight.openflowplugin.impl.util.BarrierUtil; +import org.opendaylight.openflowplugin.impl.util.FlowUtil; +import org.opendaylight.openflowplugin.impl.util.PathUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.BatchFlowInputGrouping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class RemoveFlowsBatchImpl implements RemoveFlowsBatch { + private static final Logger LOG = LoggerFactory.getLogger(RemoveFlowsBatchImpl.class); + + private final RemoveFlow removeFlow; + private final SendBarrier sendBarrier; + + public RemoveFlowsBatchImpl(final RemoveFlow removeFlow, final SendBarrier sendBarrier) { + this.removeFlow = requireNonNull(removeFlow); + this.sendBarrier = requireNonNull(sendBarrier); + } + + @Override + public ListenableFuture> invoke(final RemoveFlowsBatchInput input) { + final var flows = input.nonnullBatchRemoveFlows().values(); + if (LOG.isTraceEnabled()) { + LOG.trace("Removing flows @ {} : {}", PathUtil.extractNodeId(input.getNode()), flows.size()); + } + + final var resultsLot = flows.stream() + .map(batchFlow -> removeFlow.invoke(new RemoveFlowInputBuilder(batchFlow) + .setFlowRef(createFlowRef(input.getNode(), batchFlow)) + .setNode(input.getNode()) + .build())) + .toList(); + + final var commonResult = Futures.transform(Futures.successfulAsList(resultsLot), + FlowUtil.createCumulatingFunction(flows), MoreExecutors.directExecutor()); + final var removeFlowsBulkFuture = Futures.transform(commonResult, FlowUtil.FLOW_REMOVE_TRANSFORM, + MoreExecutors.directExecutor()); + return input.getBarrierAfter() + ? BarrierUtil.chainBarrier(removeFlowsBulkFuture, input.getNode(), sendBarrier, + FlowUtil.FLOW_REMOVE_COMPOSING_TRANSFORM) + : removeFlowsBulkFuture; + } + + private static FlowRef createFlowRef(final NodeRef nodeRef, final BatchFlowInputGrouping batchFlow) { + return FlowUtil.buildFlowPath((InstanceIdentifier) nodeRef.getValue(), + batchFlow.getTableId(), batchFlow.getFlowId()); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveGroupImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveGroupImpl.java new file mode 100644 index 0000000000..1b92c38aa8 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveGroupImpl.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2024 PANTHEON.tech, s.r.o. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import org.opendaylight.openflowplugin.api.openflow.FlowGroupStatus; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.impl.util.ErrorUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroup; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class RemoveGroupImpl extends AbstractGroupRpc + implements RemoveGroup { + private static final Logger LOG = LoggerFactory.getLogger(RemoveGroupImpl.class); + + public RemoveGroupImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor) { + super(requestContextStack, deviceContext, convertorExecutor, RemoveGroupOutput.class); + } + + @Override + public ListenableFuture> invoke(final RemoveGroupInput input) { + final var resultFuture = single.canUseSingleLayerSerialization() ? single.handleServiceCall(input) + : multi.handleServiceCall(input); + + Futures.addCallback(resultFuture, new FutureCallback<>() { + @Override + public void onSuccess(final RpcResult result) { + if (result.isSuccessful()) { + if (LOG.isDebugEnabled()) { + LOG.debug("Group remove with id={} finished without error", input.getGroupId().getValue()); + deviceContext.getDeviceGroupRegistry().appendHistoryGroup(input.getGroupId(), + input.getGroupType(), FlowGroupStatus.REMOVED); + } + } else { + LOG.warn("Group remove with id={} failed, errors={}", input.getGroupId().getValue(), + ErrorUtil.errorsToString(result.getErrors())); + LOG.debug("Group input={}", input); + } + } + + @Override + public void onFailure(final Throwable throwable) { + LOG.warn("Service call for removing group={} failed", input.getGroupId().getValue(), throwable); + } + }, MoreExecutors.directExecutor()); + return resultFuture; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveGroupsBatchImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveGroupsBatchImpl.java new file mode 100644 index 0000000000..8ac935298f --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveGroupsBatchImpl.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import java.util.stream.Collectors; +import org.opendaylight.openflowplugin.impl.util.BarrierUtil; +import org.opendaylight.openflowplugin.impl.util.GroupUtil; +import org.opendaylight.openflowplugin.impl.util.PathUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroup; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class RemoveGroupsBatchImpl implements RemoveGroupsBatch { + private static final Logger LOG = LoggerFactory.getLogger(RemoveGroupsBatchImpl.class); + + private final RemoveGroup removeGroup; + private final SendBarrier sendBarrier; + + public RemoveGroupsBatchImpl(final RemoveGroup removeGroup, final SendBarrier sendBarrier) { + this.removeGroup = requireNonNull(removeGroup); + this.sendBarrier = requireNonNull(sendBarrier); + } + + @Override + public ListenableFuture> invoke(final RemoveGroupsBatchInput input) { + final var groups = input.nonnullBatchRemoveGroups().values(); + if (LOG.isTraceEnabled()) { + LOG.trace("Removing groups @ {} : {}", PathUtil.extractNodeId(input.getNode()), groups.size()); + } + + final var resultsLot = groups.stream() + .map(addGroup -> removeGroup.invoke(new RemoveGroupInputBuilder(addGroup) + .setGroupRef(createGroupRef(input.getNode(), addGroup)) + .setNode(input.getNode()) + .build())) + .collect(Collectors.toList()); + + final var commonResult = Futures.transform(Futures.allAsList(resultsLot), + GroupUtil.createCumulatingFunction(groups), MoreExecutors.directExecutor()); + + final var removeGroupsBulkFuture = Futures.transform(commonResult, GroupUtil.GROUP_REMOVE_TRANSFORM, + MoreExecutors.directExecutor()); + + return input.getBarrierAfter() + ? BarrierUtil.chainBarrier(removeGroupsBulkFuture, input.getNode(), sendBarrier, + GroupUtil.GROUP_REMOVE_COMPOSING_TRANSFORM) + : removeGroupsBulkFuture; + } + + private static GroupRef createGroupRef(final NodeRef nodeRef, final Group batchGroup) { + return GroupUtil.buildGroupPath((InstanceIdentifier) nodeRef.getValue(), batchGroup.getGroupId()); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveMeterImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveMeterImpl.java new file mode 100644 index 0000000000..c6087d1bfc --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveMeterImpl.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2024 PANTHEON.tech, s.r.o. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.impl.util.ErrorUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class RemoveMeterImpl extends AbstractMeterRpc + implements RemoveMeter { + private static final Logger LOG = LoggerFactory.getLogger(RemoveMeterImpl.class); + + public RemoveMeterImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor) { + super(requestContextStack, deviceContext, convertorExecutor, RemoveMeterOutput.class); + } + + @Override + public ListenableFuture> invoke(final RemoveMeterInput input) { + final var resultFuture = single.canUseSingleLayerSerialization() ? single.handleServiceCall(input) + : multi.handleServiceCall(input); + + Futures.addCallback(resultFuture, new FutureCallback<>() { + @Override + public void onSuccess(final RpcResult result) { + if (result.isSuccessful()) { + if (LOG.isDebugEnabled()) { + LOG.debug("Meter remove with id={} finished without error", input.getMeterId()); + } + } else { + LOG.warn("Meter remove with id={} failed, errors={}", input.getMeterId(), + ErrorUtil.errorsToString(result.getErrors())); + LOG.debug("Meter input={}", input); + } + } + + @Override + public void onFailure(final Throwable throwable) { + LOG.warn("Service call for removing meter={} failed", input.getMeterId(), throwable); + } + }, MoreExecutors.directExecutor()); + return resultFuture; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveMetersBatchImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveMetersBatchImpl.java new file mode 100644 index 0000000000..8789691207 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/RemoveMetersBatchImpl.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import java.util.stream.Collectors; +import org.opendaylight.openflowplugin.impl.util.BarrierUtil; +import org.opendaylight.openflowplugin.impl.util.MeterUtil; +import org.opendaylight.openflowplugin.impl.util.PathUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchOutput; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class RemoveMetersBatchImpl implements RemoveMetersBatch { + private static final Logger LOG = LoggerFactory.getLogger(RemoveMetersBatchImpl.class); + + private final RemoveMeter removeMeter; + private final SendBarrier sendBarrier; + + public RemoveMetersBatchImpl(final RemoveMeter removeMeter, final SendBarrier sendBarrier) { + this.removeMeter = requireNonNull(removeMeter); + this.sendBarrier = requireNonNull(sendBarrier); + } + + @Override + public ListenableFuture> invoke(final RemoveMetersBatchInput input) { + final var meters = input.nonnullBatchRemoveMeters().values(); + if (LOG.isTraceEnabled()) { + LOG.trace("Removing meters @ {} : {}", PathUtil.extractNodeId(input.getNode()), meters.size()); + } + + final var resultsLot = meters.stream() + .map(meter -> removeMeter.invoke(new RemoveMeterInputBuilder(meter) + .setMeterRef(createMeterRef(input.getNode(), meter)) + .setNode(input.getNode()) + .build())) + .collect(Collectors.toList()); + + final var commonResult = Futures.transform(Futures.allAsList(resultsLot), + MeterUtil.createCumulativeFunction(meters), MoreExecutors.directExecutor()); + + final var removeMetersBulkFuture = Futures.transform(commonResult, MeterUtil.METER_REMOVE_TRANSFORM, + MoreExecutors.directExecutor()); + + return input.getBarrierAfter() + ? BarrierUtil.chainBarrier(removeMetersBulkFuture, input.getNode(), sendBarrier, + MeterUtil.METER_REMOVE_COMPOSING_TRANSFORM) + : removeMetersBulkFuture; + } + + private static MeterRef createMeterRef(final NodeRef nodeRef, final Meter batchMeter) { + return MeterUtil.buildMeterPath((InstanceIdentifier) nodeRef.getValue(), batchMeter.getMeterId()); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalAsyncConfigServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalAsyncConfigServiceImpl.java deleted file mode 100644 index bc9f7217c2..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalAsyncConfigServiceImpl.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl.services.sal; - -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.MoreExecutors; -import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerGetAsyncConfigService; -import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerSetAsyncConfigService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SalAsyncConfigService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SetAsyncInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SetAsyncOutput; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.RpcResultBuilder; - -public class SalAsyncConfigServiceImpl implements SalAsyncConfigService { - - private final SingleLayerSetAsyncConfigService setAsyncConfigService; - private final SingleLayerGetAsyncConfigService getAsyncConfigService; - - public SalAsyncConfigServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) { - setAsyncConfigService = new SingleLayerSetAsyncConfigService(requestContextStack, deviceContext); - getAsyncConfigService = new SingleLayerGetAsyncConfigService(requestContextStack, deviceContext); - } - - @Override - public ListenableFuture> setAsync(final SetAsyncInput input) { - return setAsyncConfigService.handleServiceCall(input); - } - - @Override - public ListenableFuture> getAsync(final GetAsyncInput input) { - return Futures.transform(getAsyncConfigService.handleServiceCall(input), result -> - result != null && result.isSuccessful() - ? RpcResultBuilder.success(new GetAsyncOutputBuilder(result.getResult()).build()).build() - : RpcResultBuilder.failed().build(), - MoreExecutors.directExecutor()); - } -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalBundleServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalBundleServiceImpl.java deleted file mode 100644 index 25a88e5b0b..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalBundleServiceImpl.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl.services.sal; - -import static java.util.Objects.requireNonNull; - -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.MoreExecutors; -import com.google.common.util.concurrent.SettableFuture; -import java.util.ArrayList; -import java.util.List; -import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SalExperimenterMessageService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenterInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenterOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.AddBundleMessagesInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.AddBundleMessagesOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.ControlBundleInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.ControlBundleOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.SalBundleService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.add.bundle.messages.input.messages.Message; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleAddMessageSalBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControlSalBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.bundle.add.message.sal.SalAddMessageDataBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.bundle.control.sal.SalControlDataBuilder; -import org.opendaylight.yangtools.yang.common.ErrorTag; -import org.opendaylight.yangtools.yang.common.ErrorType; -import org.opendaylight.yangtools.yang.common.RpcError; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Simple bundle extension service. - */ -public class SalBundleServiceImpl implements SalBundleService { - private static final Logger LOG = LoggerFactory.getLogger(SalBundleServiceImpl.class); - - private final SalExperimenterMessageService experimenterMessageService; - - public SalBundleServiceImpl(final SalExperimenterMessageService experimenterMessageService) { - this.experimenterMessageService = requireNonNull(experimenterMessageService, - "SalExperimenterMessageService can not be null!"); - } - - @Override - public ListenableFuture> controlBundle(final ControlBundleInput input) { - LOG.debug("Control message for device {} and bundle type {}", input.getNode(), input.getType()); - final SendExperimenterInputBuilder experimenterInputBuilder = new SendExperimenterInputBuilder(); - experimenterInputBuilder.setNode(input.getNode()); - experimenterInputBuilder.setExperimenterMessageOfChoice( - new BundleControlSalBuilder().setSalControlData(new SalControlDataBuilder(input).build()).build()); - return Futures.transform(experimenterMessageService.sendExperimenter( - experimenterInputBuilder.build()), sendExperimenterOutputRpcResult -> { - if (sendExperimenterOutputRpcResult.isSuccessful()) { - return RpcResultBuilder.success().build(); - } else { - return RpcResultBuilder.failed().build(); - } - }, MoreExecutors.directExecutor()); - } - - @Override - public ListenableFuture> addBundleMessages(final AddBundleMessagesInput input) { - final List>> partialResults = new ArrayList<>(); - final SendExperimenterInputBuilder experimenterInputBuilder = new SendExperimenterInputBuilder(); - final BundleAddMessageSalBuilder bundleAddMessageBuilder = new BundleAddMessageSalBuilder(); - final SalAddMessageDataBuilder dataBuilder = new SalAddMessageDataBuilder(); - experimenterInputBuilder.setNode(input.getNode()); - dataBuilder.setNode(input.getNode()); - dataBuilder.setBundleId(input.getBundleId()); - dataBuilder.setFlags(input.getFlags()); - dataBuilder.setBundleProperty(input.getBundleProperty()); - for (Message message : input.getMessages().getMessage()) { - dataBuilder.setBundleInnerMessage(message.getBundleInnerMessage()); - experimenterInputBuilder.setExperimenterMessageOfChoice( - bundleAddMessageBuilder.setSalAddMessageData(dataBuilder.build()).build()); - partialResults.add(experimenterMessageService.sendExperimenter(experimenterInputBuilder.build())); - } - return processResults(partialResults); - } - - private static ListenableFuture> processResults( - final List>> partialResults) { - final SettableFuture> result = SettableFuture.create(); - Futures.addCallback(Futures.successfulAsList(partialResults),new FutureCallback< - List>>() { - @Override - public void onSuccess(final List> results) { - final ArrayList errors = new ArrayList<>(); - final RpcResultBuilder rpcResultBuilder; - for (RpcResult res : results) { - if (res == null) { - // FIXME: this should never happen - errors.add(RpcResultBuilder.newError(ErrorType.APPLICATION, - new ErrorTag("BundleExtensionService"), "RpcResult is null.")); - } else if (!res.isSuccessful()) { - errors.addAll(res.getErrors()); - } - } - if (errors.isEmpty()) { - rpcResultBuilder = RpcResultBuilder.success(); - } else { - rpcResultBuilder = RpcResultBuilder.failed().withRpcErrors(errors); - } - result.set(rpcResultBuilder.build()); - } - - @Override - public void onFailure(final Throwable throwable) { - RpcResultBuilder rpcResultBuilder = RpcResultBuilder.failed(); - result.set(rpcResultBuilder.build()); - } - }, MoreExecutors.directExecutor()); - return result; - } -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlatBatchServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlatBatchServiceImpl.java deleted file mode 100644 index 3f760e6b72..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlatBatchServiceImpl.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl.services.sal; - -import static java.util.Objects.requireNonNull; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.MoreExecutors; -import java.util.ArrayList; -import java.util.List; -import org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep; -import org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob; -import org.opendaylight.openflowplugin.impl.services.batch.FlatBatchFlowAdapters; -import org.opendaylight.openflowplugin.impl.services.batch.FlatBatchGroupAdapters; -import org.opendaylight.openflowplugin.impl.services.batch.FlatBatchMeterAdapters; -import org.opendaylight.openflowplugin.impl.util.FlatBatchUtil; -import org.opendaylight.openflowplugin.impl.util.PathUtil; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.SalFlatBatchService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.SalFlowsBatchService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.SalGroupsBatchService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.SalMetersBatchService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchOutput; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Default implementation of {@link SalFlowsBatchService} - delegates work to {@link SalFlowService}. - */ -public class SalFlatBatchServiceImpl implements SalFlatBatchService { - private static final Logger LOG = LoggerFactory.getLogger(SalFlatBatchServiceImpl.class); - - private final SalFlowsBatchService salFlowService; - private final SalGroupsBatchService salGroupService; - private final SalMetersBatchService salMeterService; - - public SalFlatBatchServiceImpl(final SalFlowsBatchService salFlowBatchService, - final SalGroupsBatchService salGroupsBatchService, - final SalMetersBatchService salMetersBatchService) { - salFlowService = requireNonNull(salFlowBatchService, "delegate flow service must not be null"); - salGroupService = requireNonNull(salGroupsBatchService, "delegate group service must not be null"); - salMeterService = requireNonNull(salMetersBatchService, "delegate meter service must not be null"); - } - - @Override - public ListenableFuture> processFlatBatch(final ProcessFlatBatchInput input) { - LOG.trace("processing flat batch @ {} : {}", - PathUtil.extractNodeId(input.getNode()).getValue(), - input.getBatch().size()); - // create plan - final List batchPlan = FlatBatchUtil.assembleBatchPlan(input.nonnullBatch().values()); - // add barriers where needed - FlatBatchUtil.markBarriersWhereNeeded(batchPlan); - // prepare chain elements - final List batchChainElements = - prepareBatchChain(batchPlan, input.getNode(), input.getExitOnFirstError()); - // execute plan with barriers and collect outputs chain correspondingly, collect results - return executeBatchPlan(batchChainElements); - } - - @VisibleForTesting - ListenableFuture> executeBatchPlan(final List batchJobsChain) { - BatchStepJob batchJob; - final List>> firedJobs = new ArrayList<>(); - ListenableFuture> chainSummaryResult = - FlatBatchUtil.createEmptyRpcBatchResultFuture(true); - - for (int i = 0; i < batchJobsChain.size(); i++) { - batchJob = batchJobsChain.get(i); - // wire actual job with chain - firedJobs.add(Futures.transformAsync(chainSummaryResult, batchJob.getStepFunction(), - MoreExecutors.directExecutor())); - // if barrier after actual job is needed or it is the last job -> merge fired job results with chain result - if (batchJob.getPlanStep().isBarrierAfter() || i == batchJobsChain.size() - 1) { - firedJobs.add(0, chainSummaryResult); - chainSummaryResult = FlatBatchUtil.mergeJobsResultsFutures(firedJobs); - firedJobs.clear(); - } - } - return chainSummaryResult; - } - - @VisibleForTesting - List prepareBatchChain(final List batchPlan, - final NodeRef node, - final boolean exitOnFirstError) { - // create batch API calls based on plan steps - final List chainJobs = new ArrayList<>(); - int stepOffset = 0; - for (final BatchPlanStep planStep : batchPlan) { - final int currentOffset = stepOffset; - chainJobs.add(new BatchStepJob(planStep, chainInput -> { - if (exitOnFirstError && !chainInput.isSuccessful()) { - LOG.debug("error on flat batch chain occurred -> skipping step {}", planStep.getStepType()); - return FlatBatchUtil.createEmptyRpcBatchResultFuture(false); - } - LOG.trace("batch progressing on step type {}, previous steps result: {}", planStep.getStepType(), - chainInput.isSuccessful()); - return getChainOutput(node, planStep, currentOffset); - })); - stepOffset += planStep.getTaskBag().size(); - } - - return chainJobs; - } - - private ListenableFuture> getChainOutput(final NodeRef node, - final BatchPlanStep planStep, - final int currentOffset) { - return switch (planStep.getStepType()) { - case FLOW_ADD -> { - final AddFlowsBatchInput addFlowsBatchInput = - FlatBatchFlowAdapters.adaptFlatBatchAddFlow(planStep, node); - final ListenableFuture> resultAddFlowFuture = - salFlowService.addFlowsBatch(addFlowsBatchInput); - yield FlatBatchFlowAdapters.convertFlowBatchFutureForChain(resultAddFlowFuture, currentOffset); - } - case FLOW_REMOVE -> { - final RemoveFlowsBatchInput removeFlowsBatchInput = - FlatBatchFlowAdapters.adaptFlatBatchRemoveFlow(planStep, node); - final ListenableFuture> resultRemoveFlowFuture = - salFlowService.removeFlowsBatch(removeFlowsBatchInput); - yield FlatBatchFlowAdapters.convertFlowBatchFutureForChain(resultRemoveFlowFuture, currentOffset); - } - case FLOW_UPDATE -> { - final UpdateFlowsBatchInput updateFlowsBatchInput = - FlatBatchFlowAdapters.adaptFlatBatchUpdateFlow(planStep, node); - final ListenableFuture> resultUpdateFlowFuture = - salFlowService.updateFlowsBatch(updateFlowsBatchInput); - yield FlatBatchFlowAdapters.convertFlowBatchFutureForChain(resultUpdateFlowFuture, currentOffset); - } - case GROUP_ADD -> { - final AddGroupsBatchInput addGroupsBatchInput = - FlatBatchGroupAdapters.adaptFlatBatchAddGroup(planStep, node); - final ListenableFuture> resultAddGroupFuture = - salGroupService.addGroupsBatch(addGroupsBatchInput); - yield FlatBatchGroupAdapters.convertGroupBatchFutureForChain(resultAddGroupFuture, currentOffset); - } - case GROUP_REMOVE -> { - final RemoveGroupsBatchInput removeGroupsBatchInput = - FlatBatchGroupAdapters.adaptFlatBatchRemoveGroup(planStep, node); - final ListenableFuture> resultRemoveGroupFuture = - salGroupService.removeGroupsBatch(removeGroupsBatchInput); - yield FlatBatchGroupAdapters.convertGroupBatchFutureForChain(resultRemoveGroupFuture, currentOffset); - } - case GROUP_UPDATE -> { - final UpdateGroupsBatchInput updateGroupsBatchInput = - FlatBatchGroupAdapters.adaptFlatBatchUpdateGroup(planStep, node); - final ListenableFuture> resultUpdateGroupFuture = - salGroupService.updateGroupsBatch(updateGroupsBatchInput); - yield FlatBatchGroupAdapters.convertGroupBatchFutureForChain(resultUpdateGroupFuture, currentOffset); - } - case METER_ADD -> { - final AddMetersBatchInput addMetersBatchInput = - FlatBatchMeterAdapters.adaptFlatBatchAddMeter(planStep, node); - final ListenableFuture> resultAddMeterFuture = - salMeterService.addMetersBatch(addMetersBatchInput); - yield FlatBatchMeterAdapters.convertMeterBatchFutureForChain(resultAddMeterFuture, currentOffset); - } - case METER_REMOVE -> { - final RemoveMetersBatchInput removeMetersBatchInput = - FlatBatchMeterAdapters.adaptFlatBatchRemoveMeter(planStep, node); - final ListenableFuture> resultRemoveMeterFuture = - salMeterService.removeMetersBatch(removeMetersBatchInput); - yield FlatBatchMeterAdapters.convertMeterBatchFutureForChain(resultRemoveMeterFuture, currentOffset); - } - case METER_UPDATE -> { - final UpdateMetersBatchInput updateMetersBatchInput = - FlatBatchMeterAdapters.adaptFlatBatchUpdateMeter(planStep, node); - final ListenableFuture> resultUpdateMeterFuture = - salMeterService.updateMetersBatch(updateMetersBatchInput); - yield FlatBatchMeterAdapters.convertMeterBatchFutureForChain(resultUpdateMeterFuture, currentOffset); - } - default -> { - LOG.warn("Unsupported plan-step type occurred: {} -> OMITTING", planStep.getStepType()); - yield FlatBatchUtil.createEmptyRpcBatchResultFuture(true); - } - }; - } -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowServiceImpl.java deleted file mode 100644 index 6542234329..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowServiceImpl.java +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl.services.sal; - -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.MoreExecutors; -import com.google.common.util.concurrent.SettableFuture; -import java.util.ArrayList; -import java.util.List; -import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.openflowplugin.api.openflow.FlowGroupStatus; -import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry; -import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor; -import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey; -import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory; -import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory; -import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerFlowService; -import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerFlowService; -import org.opendaylight.openflowplugin.impl.util.ErrorUtil; -import org.opendaylight.openflowplugin.impl.util.FlowCreatorUtil; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder; -import org.opendaylight.yangtools.yang.common.ErrorType; -import org.opendaylight.yangtools.yang.common.RpcError; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -import org.opendaylight.yangtools.yang.common.Uint8; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SalFlowServiceImpl implements SalFlowService { - private static final Logger LOG = LoggerFactory.getLogger(SalFlowServiceImpl.class); - private static final Uint8 OFPTT_ALL = Uint8.MAX_VALUE; - - private final MultiLayerFlowService flowUpdate; - private final MultiLayerFlowService flowAdd; - private final MultiLayerFlowService flowRemove; - private final SingleLayerFlowService flowAddMessage; - private final SingleLayerFlowService flowUpdateMessage; - private final SingleLayerFlowService flowRemoveMessage; - private final DeviceContext deviceContext; - - public SalFlowServiceImpl(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor) { - this.deviceContext = deviceContext; - flowRemove = new MultiLayerFlowService<>(requestContextStack, - deviceContext, - RemoveFlowOutput.class, - convertorExecutor); - flowAdd = new MultiLayerFlowService<>(requestContextStack, - deviceContext, - AddFlowOutput.class, - convertorExecutor); - flowUpdate = new MultiLayerFlowService<>(requestContextStack, - deviceContext, - UpdateFlowOutput.class, - convertorExecutor); - flowAddMessage = new SingleLayerFlowService<>(requestContextStack, deviceContext, AddFlowOutput.class); - flowUpdateMessage = new SingleLayerFlowService<>(requestContextStack, deviceContext, UpdateFlowOutput.class); - flowRemoveMessage = new SingleLayerFlowService<>(requestContextStack, deviceContext, RemoveFlowOutput.class); - } - - @Override - public ListenableFuture> addFlow(final AddFlowInput input) { - final FlowRegistryKey flowRegistryKey = - FlowRegistryKeyFactory.create(deviceContext.getDeviceInfo().getVersion(), input); - final ListenableFuture> future; - if (flowAddMessage.canUseSingleLayerSerialization()) { - future = flowAddMessage.handleServiceCall(input); - Futures.addCallback(future, new AddFlowCallback(input, flowRegistryKey), - MoreExecutors.directExecutor()); - } else { - future = flowAdd.processFlowModInputBuilders(flowAdd.toFlowModInputs(input)); - Futures.addCallback(future, new AddFlowCallback(input, flowRegistryKey), - MoreExecutors.directExecutor()); - - } - return future; - } - - @Override - public ListenableFuture> removeFlow(final RemoveFlowInput input) { - final ListenableFuture> future; - if (flowRemoveMessage.canUseSingleLayerSerialization()) { - future = flowRemoveMessage.handleServiceCall(input); - Futures.addCallback(future, new RemoveFlowCallback(input), MoreExecutors.directExecutor()); - - } else { - future = flowRemove.processFlowModInputBuilders(flowRemove.toFlowModInputs(input)); - Futures.addCallback(future, new RemoveFlowCallback(input), MoreExecutors.directExecutor()); - } - - return future; - } - - @Override - public ListenableFuture> updateFlow(final UpdateFlowInput input) { - final UpdatedFlow updated = input.getUpdatedFlow(); - final OriginalFlow original = input.getOriginalFlow(); - final List allFlowMods = new ArrayList<>(); - final List ofFlowModInputs; - - ListenableFuture> future; - if (flowUpdateMessage.canUseSingleLayerSerialization()) { - - if (!FlowCreatorUtil.canModifyFlow(original, updated, flowUpdateMessage.getVersion())) { - final SettableFuture> objectSettableFuture = SettableFuture.create(); - - final ListenableFuture>> listListenableFuture = - Futures.successfulAsList(flowUpdateMessage.handleServiceCall(input.getOriginalFlow()), - flowUpdateMessage.handleServiceCall(input.getUpdatedFlow())); - - Futures.addCallback(listListenableFuture, new FutureCallback>>() { - @Override - public void onSuccess(final List> results) { - final ArrayList errors = new ArrayList<>(); - for (RpcResult flowModResult : results) { - if (flowModResult == null) { - errors.add(RpcResultBuilder.newError( - ErrorType.PROTOCOL, OFConstants.APPLICATION_TAG, - "unexpected flowMod result (null) occurred")); - } else if (!flowModResult.isSuccessful()) { - errors.addAll(flowModResult.getErrors()); - } - } - - final RpcResultBuilder rpcResultBuilder; - if (errors.isEmpty()) { - rpcResultBuilder = RpcResultBuilder.success(); - } else { - rpcResultBuilder = RpcResultBuilder.failed().withRpcErrors(errors); - } - - objectSettableFuture.set(rpcResultBuilder.build()); - } - - @Override - public void onFailure(final Throwable throwable) { - RpcResultBuilder rpcResultBuilder = RpcResultBuilder.failed(); - objectSettableFuture.set(rpcResultBuilder.build()); - } - }, MoreExecutors.directExecutor()); - - future = objectSettableFuture; - } else { - future = flowUpdateMessage.handleServiceCall(input.getUpdatedFlow()); - } - } else { - if (!FlowCreatorUtil.canModifyFlow(original, updated, flowUpdate.getVersion())) { - // We would need to remove original and add updated. - - // remove flow - final RemoveFlowInputBuilder removeflow = new RemoveFlowInputBuilder(original); - final List ofFlowRemoveInput = flowUpdate.toFlowModInputs(removeflow.build()); - // remove flow should be the first - allFlowMods.addAll(ofFlowRemoveInput); - final AddFlowInputBuilder addFlowInputBuilder = new AddFlowInputBuilder(updated); - ofFlowModInputs = flowUpdate.toFlowModInputs(addFlowInputBuilder.build()); - } else { - ofFlowModInputs = flowUpdate.toFlowModInputs(updated); - } - - allFlowMods.addAll(ofFlowModInputs); - - future = flowUpdate.processFlowModInputBuilders(allFlowMods); - } - - Futures.addCallback(future, new UpdateFlowCallback(input), MoreExecutors.directExecutor()); - return future; - } - - private final class AddFlowCallback implements FutureCallback> { - private final AddFlowInput input; - private final FlowRegistryKey flowRegistryKey; - - private AddFlowCallback(final AddFlowInput input, final FlowRegistryKey flowRegistryKey) { - this.input = input; - this.flowRegistryKey = flowRegistryKey; - } - - @Override - public void onSuccess(final RpcResult rpcResult) { - if (!rpcResult.isSuccessful()) { - if (LOG.isDebugEnabled()) { - LOG.debug("Flow add failed for flow={}, errors={}", input, - ErrorUtil.errorsToString(rpcResult.getErrors())); - } - return; - } - - final DeviceFlowRegistry flowRegistry = deviceContext.getDeviceFlowRegistry(); - final FlowDescriptor flowDescriptor; - final FlowRef flowRef = input.getFlowRef(); - if (flowRef != null) { - final Uint8 tableId = input.getTableId(); - final FlowId flowId = flowRef.getValue().firstKeyOf(Flow.class).getId(); - flowDescriptor = FlowDescriptorFactory.create(tableId, flowId); - - // FIXME: this looks like an atomic operation - flowRegistry.appendHistoryFlow(flowId, tableId, FlowGroupStatus.ADDED); - flowRegistry.storeDescriptor(flowRegistryKey, flowDescriptor); - } else { - // FIXME: this looks like an atomic operation - flowRegistry.store(flowRegistryKey); - flowDescriptor = flowRegistry.retrieveDescriptor(flowRegistryKey); - } - - if (LOG.isDebugEnabled()) { - LOG.debug("Flow add with id={} finished without error", flowDescriptor.getFlowId().getValue()); - } - } - - @Override - public void onFailure(final Throwable throwable) { - LOG.warn("Service call for adding flow={} failed", input, throwable); - } - } - - private final class RemoveFlowCallback implements FutureCallback> { - private final RemoveFlowInput input; - - private RemoveFlowCallback(final RemoveFlowInput input) { - this.input = input; - } - - @Override - public void onSuccess(final RpcResult result) { - if (result.isSuccessful()) { - if (LOG.isDebugEnabled()) { - LOG.debug("Flow remove finished without error for flow={}", input); - } - final DeviceFlowRegistry flowRegistry = deviceContext.getDeviceFlowRegistry(); - if (input.getTableId() != null && !input.getTableId().equals(OFPTT_ALL)) { - FlowRegistryKey flowRegistryKey = - FlowRegistryKeyFactory.create(deviceContext.getDeviceInfo().getVersion(), input); - flowRegistry.addMark(flowRegistryKey); - - final FlowRef flowRef = input.getFlowRef(); - if (flowRef != null) { - final FlowId flowId = flowRef.getValue().firstKeyOf(Flow.class).getId(); - flowRegistry.appendHistoryFlow(flowId, input.getTableId(), FlowGroupStatus.REMOVED); - } - } else { - flowRegistry.clearFlowRegistry(); - } - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("Flow remove failed for flow={}, errors={}", input, - ErrorUtil.errorsToString(result.getErrors())); - } - } - } - - @Override - public void onFailure(final Throwable throwable) { - LOG.warn("Service call for removing flow={} failed", input, throwable); - } - } - - private final class UpdateFlowCallback implements FutureCallback> { - private final UpdateFlowInput input; - - private UpdateFlowCallback(final UpdateFlowInput input) { - this.input = input; - } - - @Override - public void onSuccess(final RpcResult updateFlowOutputRpcResult) { - final DeviceFlowRegistry deviceFlowRegistry = deviceContext.getDeviceFlowRegistry(); - final UpdatedFlow updated = input.getUpdatedFlow(); - final OriginalFlow original = input.getOriginalFlow(); - final FlowRegistryKey origFlowRegistryKey = - FlowRegistryKeyFactory.create(deviceContext.getDeviceInfo().getVersion(), original); - final FlowRegistryKey updatedFlowRegistryKey = - FlowRegistryKeyFactory.create(deviceContext.getDeviceInfo().getVersion(), updated); - final FlowDescriptor origFlowDescriptor = deviceFlowRegistry.retrieveDescriptor(origFlowRegistryKey); - - final boolean isUpdate = origFlowDescriptor != null; - final FlowDescriptor updatedFlowDescriptor; - final FlowRef flowRef = input.getFlowRef(); - if (flowRef != null) { - final Uint8 tableId = updated.getTableId(); - final FlowId flowId = flowRef.getValue().firstKeyOf(Flow.class).getId(); - // FIXME: this does not look right, we probably want better integration - deviceFlowRegistry.appendHistoryFlow(flowId, tableId, FlowGroupStatus.MODIFIED); - - updatedFlowDescriptor = FlowDescriptorFactory.create(tableId, flowId); - } else if (isUpdate) { - updatedFlowDescriptor = origFlowDescriptor; - } else { - deviceFlowRegistry.store(updatedFlowRegistryKey); - updatedFlowDescriptor = deviceFlowRegistry.retrieveDescriptor(updatedFlowRegistryKey); - } - - if (isUpdate) { - deviceFlowRegistry.addMark(origFlowRegistryKey); - deviceFlowRegistry.storeDescriptor(updatedFlowRegistryKey, updatedFlowDescriptor); - } - } - - @Override - public void onFailure(final Throwable throwable) { - LOG.warn("Service call for updating flow={} failed", input, throwable); - } - } -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowsBatchServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowsBatchServiceImpl.java deleted file mode 100644 index eee91f5b6b..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowsBatchServiceImpl.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl.services.sal; - -import static java.util.Objects.requireNonNull; - -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.MoreExecutors; -import java.util.ArrayList; -import java.util.List; -import org.opendaylight.openflowplugin.impl.util.BarrierUtil; -import org.opendaylight.openflowplugin.impl.util.FlowUtil; -import org.opendaylight.openflowplugin.impl.util.PathUtil; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlowBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.BatchFlowInputGrouping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.BatchFlowInputUpdateGrouping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.SalFlowsBatchService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.batch.flow.output.list.grouping.BatchFailedFlowsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.update.flows.batch.input.BatchUpdateFlows; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Default implementation of {@link SalFlowsBatchService} - delegates work to {@link SalFlowService}. - */ -public class SalFlowsBatchServiceImpl implements SalFlowsBatchService { - private static final Logger LOG = LoggerFactory.getLogger(SalFlowsBatchServiceImpl.class); - - private final SalFlowService salFlowService; - private final FlowCapableTransactionService transactionService; - - public SalFlowsBatchServiceImpl(final SalFlowService salFlowService, - final FlowCapableTransactionService transactionService) { - this.salFlowService = requireNonNull(salFlowService, "delegate flow service must not be null"); - this.transactionService = requireNonNull(transactionService, "delegate transaction service must not be null"); - } - - @Override - public ListenableFuture> removeFlowsBatch(final RemoveFlowsBatchInput input) { - LOG.trace("Removing flows @ {} : {}", - PathUtil.extractNodeId(input.getNode()), - input.getBatchRemoveFlows().size()); - final ArrayList>> resultsLot = new ArrayList<>(); - for (BatchFlowInputGrouping batchFlow : input.nonnullBatchRemoveFlows().values()) { - final RemoveFlowInput removeFlowInput = new RemoveFlowInputBuilder(batchFlow) - .setFlowRef(createFlowRef(input.getNode(), batchFlow)) - .setNode(input.getNode()) - .build(); - resultsLot.add(salFlowService.removeFlow(removeFlowInput)); - } - - final ListenableFuture>> commonResult = - Futures.transform(Futures.successfulAsList(resultsLot), - FlowUtil.createCumulatingFunction(input.nonnullBatchRemoveFlows().values()), - MoreExecutors.directExecutor()); - - ListenableFuture> removeFlowsBulkFuture = - Futures.transform(commonResult, FlowUtil.FLOW_REMOVE_TRANSFORM, MoreExecutors.directExecutor()); - - if (input.getBarrierAfter()) { - removeFlowsBulkFuture = BarrierUtil.chainBarrier(removeFlowsBulkFuture, input.getNode(), - transactionService, FlowUtil.FLOW_REMOVE_COMPOSING_TRANSFORM); - } - - return removeFlowsBulkFuture; - } - - @Override - public ListenableFuture> addFlowsBatch(final AddFlowsBatchInput input) { - LOG.trace("Adding flows @ {} : {}", PathUtil.extractNodeId(input.getNode()), input.getBatchAddFlows().size()); - final ArrayList>> resultsLot = new ArrayList<>(); - for (BatchFlowInputGrouping batchFlow : input.nonnullBatchAddFlows().values()) { - final AddFlowInput addFlowInput = new AddFlowInputBuilder(batchFlow) - .setFlowRef(createFlowRef(input.getNode(), batchFlow)) - .setNode(input.getNode()) - .build(); - resultsLot.add(salFlowService.addFlow(addFlowInput)); - } - - final ListenableFuture>> commonResult = - Futures.transform(Futures.successfulAsList(resultsLot), - FlowUtil.createCumulatingFunction(input.nonnullBatchAddFlows().values()), - MoreExecutors.directExecutor()); - - ListenableFuture> addFlowsBulkFuture = - Futures.transform(commonResult, FlowUtil.FLOW_ADD_TRANSFORM, MoreExecutors.directExecutor()); - - if (input.getBarrierAfter()) { - addFlowsBulkFuture = BarrierUtil.chainBarrier(addFlowsBulkFuture, input.getNode(), - transactionService, FlowUtil.FLOW_ADD_COMPOSING_TRANSFORM); - } - - return addFlowsBulkFuture; - } - - private static FlowRef createFlowRef(final NodeRef nodeRef, final BatchFlowInputGrouping batchFlow) { - return FlowUtil.buildFlowPath((InstanceIdentifier) nodeRef.getValue(), - batchFlow.getTableId(), batchFlow.getFlowId()); - } - - private static FlowRef createFlowRef(final NodeRef nodeRef, final BatchFlowInputUpdateGrouping batchFlow) { - return FlowUtil.buildFlowPath((InstanceIdentifier) nodeRef.getValue(), - batchFlow.getOriginalBatchedFlow().getTableId(), batchFlow.getFlowId()); - } - - @Override - public ListenableFuture> updateFlowsBatch(final UpdateFlowsBatchInput input) { - LOG.trace("Updating flows @ {} : {}", - PathUtil.extractNodeId(input.getNode()), - input.getBatchUpdateFlows().size()); - final ArrayList>> resultsLot = new ArrayList<>(); - for (BatchUpdateFlows batchFlow : input.nonnullBatchUpdateFlows().values()) { - final UpdateFlowInput updateFlowInput = new UpdateFlowInputBuilder(input) - .setOriginalFlow(new OriginalFlowBuilder(batchFlow.getOriginalBatchedFlow()).build()) - .setUpdatedFlow(new UpdatedFlowBuilder(batchFlow.getUpdatedBatchedFlow()).build()) - .setFlowRef(createFlowRef(input.getNode(), batchFlow)) - .setNode(input.getNode()) - .build(); - resultsLot.add(salFlowService.updateFlow(updateFlowInput)); - } - - final ListenableFuture>> commonResult = - Futures.transform(Futures.successfulAsList(resultsLot), - FlowUtil.createCumulatingFunction(input.nonnullBatchUpdateFlows().values()), - MoreExecutors.directExecutor()); - - ListenableFuture> updateFlowsBulkFuture = - Futures.transform(commonResult, FlowUtil.FLOW_UPDATE_TRANSFORM, MoreExecutors.directExecutor()); - - if (input.getBarrierAfter()) { - updateFlowsBulkFuture = BarrierUtil.chainBarrier(updateFlowsBulkFuture, input.getNode(), - transactionService, FlowUtil.FLOW_UPDATE_COMPOSING_TRANSFORM); - } - - return updateFlowsBulkFuture; - } -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupServiceImpl.java deleted file mode 100755 index f4568db897..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupServiceImpl.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl.services.sal; - -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.MoreExecutors; -import org.opendaylight.openflowplugin.api.openflow.FlowGroupStatus; -import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerGroupService; -import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerGroupService; -import org.opendaylight.openflowplugin.impl.util.ErrorUtil; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroup; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SalGroupServiceImpl implements SalGroupService { - private static final Logger LOG = LoggerFactory.getLogger(SalGroupServiceImpl.class); - private final MultiLayerGroupService addGroup; - private final MultiLayerGroupService updateGroup; - private final MultiLayerGroupService removeGroup; - private final SingleLayerGroupService addGroupMessage; - private final SingleLayerGroupService updateGroupMessage; - private final SingleLayerGroupService removeGroupMessage; - - private final DeviceContext deviceContext; - - public SalGroupServiceImpl(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor) { - this.deviceContext = deviceContext; - addGroup = new MultiLayerGroupService<>(requestContextStack, - deviceContext, - AddGroupOutput.class, - convertorExecutor); - - updateGroup = new MultiLayerGroupService<>(requestContextStack, - deviceContext, - UpdateGroupOutput.class, - convertorExecutor); - - removeGroup = new MultiLayerGroupService<>(requestContextStack, - deviceContext, - RemoveGroupOutput.class, - convertorExecutor); - - addGroupMessage = new SingleLayerGroupService<>(requestContextStack, deviceContext, AddGroupOutput.class); - updateGroupMessage = new SingleLayerGroupService<>(requestContextStack, deviceContext, UpdateGroupOutput.class); - removeGroupMessage = new SingleLayerGroupService<>(requestContextStack, deviceContext, RemoveGroupOutput.class); - } - - @Override - public ListenableFuture> addGroup(final AddGroupInput input) { - final ListenableFuture> resultFuture = - addGroupMessage.canUseSingleLayerSerialization() - ? addGroupMessage.handleServiceCall(input) - : addGroup.handleServiceCall(input); - Futures.addCallback(resultFuture, new FutureCallback>() { - @Override - public void onSuccess(final RpcResult result) { - if (result.isSuccessful()) { - LOG.debug("adding group successful {}", input.getGroupId()); - deviceContext.getDeviceGroupRegistry().appendHistoryGroup(input.getGroupId(), input.getGroupType(), - FlowGroupStatus.ADDED); - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("Group add with id={} failed, errors={}", input.getGroupId().getValue(), - ErrorUtil.errorsToString(result.getErrors())); - } - } - } - - @Override - public void onFailure(final Throwable throwable) { - LOG.warn("Service call for adding group={} failed", - input.getGroupId().getValue(), - throwable); - } - }, MoreExecutors.directExecutor()); - return resultFuture; - } - - - @Override - public ListenableFuture> updateGroup(final UpdateGroupInput input) { - final ListenableFuture> resultFuture = - updateGroupMessage.canUseSingleLayerSerialization() - ? updateGroupMessage.handleServiceCall(input.getUpdatedGroup()) - : updateGroup.handleServiceCall(input.getUpdatedGroup()); - - Futures.addCallback(resultFuture, new FutureCallback>() { - @Override - public void onSuccess(final RpcResult result) { - if (result.isSuccessful()) { - UpdatedGroup updatedGroup = input.getUpdatedGroup(); - deviceContext.getDeviceGroupRegistry().appendHistoryGroup( - updatedGroup.getGroupId(), updatedGroup.getGroupType(), FlowGroupStatus.MODIFIED); - if (LOG.isDebugEnabled()) { - LOG.debug("Group update with original id={} finished without error", - input.getOriginalGroup().getGroupId().getValue()); - } - } else { - LOG.warn("Group update with original id={} failed, errors={}", - input.getOriginalGroup().getGroupId(), ErrorUtil.errorsToString(result.getErrors())); - LOG.debug("Group input={}", input.getUpdatedGroup()); - } - } - - @Override - public void onFailure(final Throwable throwable) { - LOG.warn("Service call for updating group={} failed", - input.getOriginalGroup().getGroupId(), throwable); - } - }, MoreExecutors.directExecutor()); - return resultFuture; - } - - @Override - public ListenableFuture> removeGroup(final RemoveGroupInput input) { - final ListenableFuture> resultFuture = - removeGroupMessage.canUseSingleLayerSerialization() - ? removeGroupMessage.handleServiceCall(input) - : removeGroup.handleServiceCall(input); - - Futures.addCallback(resultFuture, new FutureCallback>() { - @Override - public void onSuccess(final RpcResult result) { - if (result.isSuccessful()) { - if (LOG.isDebugEnabled()) { - LOG.debug("Group remove with id={} finished without error", input.getGroupId().getValue()); - deviceContext.getDeviceGroupRegistry().appendHistoryGroup(input.getGroupId(), - input.getGroupType(), FlowGroupStatus.REMOVED); - } - } else { - LOG.warn("Group remove with id={} failed, errors={}", input.getGroupId().getValue(), - ErrorUtil.errorsToString(result.getErrors())); - LOG.debug("Group input={}", input); - } - } - - @Override - public void onFailure(final Throwable throwable) { - LOG.warn("Service call for removing group={} failed", - input.getGroupId().getValue(), throwable); - } - }, MoreExecutors.directExecutor()); - return resultFuture; - } - -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupsBatchServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupsBatchServiceImpl.java deleted file mode 100644 index 6c22005b73..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupsBatchServiceImpl.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl.services.sal; - -import static java.util.Objects.requireNonNull; - -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.MoreExecutors; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import org.opendaylight.openflowplugin.impl.util.BarrierUtil; -import org.opendaylight.openflowplugin.impl.util.GroupUtil; -import org.opendaylight.openflowplugin.impl.util.PathUtil; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.OriginalGroupBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroupBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupRef; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.BatchGroupInputUpdateGrouping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.SalGroupsBatchService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.add.groups.batch.input.BatchAddGroups; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.batch.group.output.list.grouping.BatchFailedGroupsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.remove.groups.batch.input.BatchRemoveGroups; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.update.groups.batch.input.BatchUpdateGroups; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Default implementation of {@link SalGroupsBatchService} - delegates work to {@link SalGroupService}. - */ -public class SalGroupsBatchServiceImpl implements SalGroupsBatchService { - private static final Logger LOG = LoggerFactory.getLogger(SalGroupsBatchServiceImpl.class); - - private final SalGroupService salGroupService; - private final FlowCapableTransactionService transactionService; - - public SalGroupsBatchServiceImpl(final SalGroupService salGroupService, - final FlowCapableTransactionService transactionService) { - this.salGroupService = requireNonNull(salGroupService); - this.transactionService = requireNonNull(transactionService); - } - - @Override - public ListenableFuture> updateGroupsBatch(final UpdateGroupsBatchInput input) { - final List batchUpdateGroups = input.getBatchUpdateGroups(); - LOG.trace("Updating groups @ {} : {}", PathUtil.extractNodeId(input.getNode()), batchUpdateGroups.size()); - - final ArrayList>> resultsLot = new ArrayList<>(); - for (BatchUpdateGroups batchGroup : batchUpdateGroups) { - final UpdateGroupInput updateGroupInput = new UpdateGroupInputBuilder(input) - .setOriginalGroup(new OriginalGroupBuilder(batchGroup.getOriginalBatchedGroup()).build()) - .setUpdatedGroup(new UpdatedGroupBuilder(batchGroup.getUpdatedBatchedGroup()).build()) - .setGroupRef(createGroupRef(input.getNode(), batchGroup)).setNode(input.getNode()).build(); - resultsLot.add(salGroupService.updateGroup(updateGroupInput)); - } - - final Iterable groups = batchUpdateGroups.stream() - .map(BatchGroupInputUpdateGrouping::getUpdatedBatchedGroup).collect(Collectors.toList()); - - final ListenableFuture>> commonResult = Futures - .transform(Futures.allAsList(resultsLot), - GroupUtil.createCumulatingFunction(groups, batchUpdateGroups.size()), - MoreExecutors.directExecutor()); - - ListenableFuture> updateGroupsBulkFuture = Futures - .transform(commonResult, GroupUtil.GROUP_UPDATE_TRANSFORM, MoreExecutors.directExecutor()); - - if (input.getBarrierAfter()) { - updateGroupsBulkFuture = BarrierUtil - .chainBarrier(updateGroupsBulkFuture, input.getNode(), transactionService, - GroupUtil.GROUP_UPDATE_COMPOSING_TRANSFORM); - } - - return updateGroupsBulkFuture; - } - - @Override - public ListenableFuture> addGroupsBatch(final AddGroupsBatchInput input) { - LOG.trace("Adding groups @ {} : {}", PathUtil.extractNodeId(input.getNode()), input.getBatchAddGroups().size()); - final ArrayList>> resultsLot = new ArrayList<>(); - for (BatchAddGroups addGroup : input.nonnullBatchAddGroups().values()) { - final AddGroupInput addGroupInput = new AddGroupInputBuilder(addGroup) - .setGroupRef(createGroupRef(input.getNode(), addGroup)).setNode(input.getNode()).build(); - resultsLot.add(salGroupService.addGroup(addGroupInput)); - } - - final ListenableFuture>> commonResult = Futures - .transform(Futures.allAsList(resultsLot), - GroupUtil.createCumulatingFunction(input.nonnullBatchAddGroups().values()), - MoreExecutors.directExecutor()); - - ListenableFuture> addGroupsBulkFuture = Futures - .transform(commonResult, GroupUtil.GROUP_ADD_TRANSFORM, MoreExecutors.directExecutor()); - - if (input.getBarrierAfter()) { - addGroupsBulkFuture = BarrierUtil.chainBarrier(addGroupsBulkFuture, input.getNode(), transactionService, - GroupUtil.GROUP_ADD_COMPOSING_TRANSFORM); - } - - return addGroupsBulkFuture; - } - - @Override - public ListenableFuture> removeGroupsBatch(final RemoveGroupsBatchInput input) { - LOG.trace("Removing groups @ {} : {}", PathUtil.extractNodeId(input.getNode()), - input.getBatchRemoveGroups().size()); - final ArrayList>> resultsLot = new ArrayList<>(); - for (BatchRemoveGroups addGroup : input.nonnullBatchRemoveGroups().values()) { - final RemoveGroupInput removeGroupInput = new RemoveGroupInputBuilder(addGroup) - .setGroupRef(createGroupRef(input.getNode(), addGroup)).setNode(input.getNode()).build(); - resultsLot.add(salGroupService.removeGroup(removeGroupInput)); - } - - final ListenableFuture>> commonResult = Futures - .transform(Futures.allAsList(resultsLot), - GroupUtil.createCumulatingFunction(input.nonnullBatchRemoveGroups().values()), - MoreExecutors.directExecutor()); - - ListenableFuture> removeGroupsBulkFuture = Futures - .transform(commonResult, GroupUtil.GROUP_REMOVE_TRANSFORM, MoreExecutors.directExecutor()); - - if (input.getBarrierAfter()) { - removeGroupsBulkFuture = BarrierUtil - .chainBarrier(removeGroupsBulkFuture, input.getNode(), transactionService, - GroupUtil.GROUP_REMOVE_COMPOSING_TRANSFORM); - } - - return removeGroupsBulkFuture; - } - - private static GroupRef createGroupRef(final NodeRef nodeRef, final Group batchGroup) { - return GroupUtil.buildGroupPath((InstanceIdentifier) nodeRef.getValue(), batchGroup.getGroupId()); - } - - private static GroupRef createGroupRef(final NodeRef nodeRef, final BatchUpdateGroups batchGroup) { - return GroupUtil.buildGroupPath((InstanceIdentifier) nodeRef.getValue(), - batchGroup.getUpdatedBatchedGroup().getGroupId()); - } -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalMeterServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalMeterServiceImpl.java deleted file mode 100755 index 9bf7f3d43d..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalMeterServiceImpl.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl.services.sal; - -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.MoreExecutors; -import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerMeterService; -import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerMeterService; -import org.opendaylight.openflowplugin.impl.util.ErrorUtil; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SalMeterServiceImpl implements SalMeterService { - private static final Logger LOG = LoggerFactory.getLogger(SalMeterServiceImpl.class); - private final MultiLayerMeterService addMeter; - private final MultiLayerMeterService updateMeter; - private final MultiLayerMeterService removeMeter; - private final SingleLayerMeterService addMeterMessage; - private final SingleLayerMeterService updateMeterMessage; - private final SingleLayerMeterService removeMeterMessage; - - private final DeviceContext deviceContext; - - public SalMeterServiceImpl(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor) { - this.deviceContext = deviceContext; - addMeter = new MultiLayerMeterService<>(requestContextStack, - deviceContext, - AddMeterOutput.class, - convertorExecutor); - - updateMeter = new MultiLayerMeterService<>(requestContextStack, - deviceContext, - UpdateMeterOutput.class, - convertorExecutor); - - removeMeter = new MultiLayerMeterService<>(requestContextStack, - deviceContext, - RemoveMeterOutput.class, - convertorExecutor); - - addMeterMessage = new SingleLayerMeterService<>(requestContextStack, deviceContext, AddMeterOutput.class); - updateMeterMessage = new SingleLayerMeterService<>(requestContextStack, deviceContext, UpdateMeterOutput.class); - removeMeterMessage = new SingleLayerMeterService<>(requestContextStack, deviceContext, RemoveMeterOutput.class); - } - - @Override - public ListenableFuture> addMeter(final AddMeterInput input) { - final ListenableFuture> resultFuture = - addMeterMessage.canUseSingleLayerSerialization() - ? addMeterMessage.handleServiceCall(input) - : addMeter.handleServiceCall(input); - - Futures.addCallback(resultFuture, new FutureCallback>() { - @Override - public void onSuccess(RpcResult result) { - if (result.isSuccessful()) { - if (LOG.isDebugEnabled()) { - LOG.debug("Meter add with id={} finished without error", input.getMeterId()); - } - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("Meter add with id={} failed, errors={}", input.getMeterId(), - ErrorUtil.errorsToString(result.getErrors())); - } - } - } - - @Override - public void onFailure(Throwable throwable) { - LOG.warn("Service call for adding meter={} failed", input.getMeterId(), throwable); - } - }, MoreExecutors.directExecutor()); - return resultFuture; - } - - @Override - public ListenableFuture> updateMeter(final UpdateMeterInput input) { - final ListenableFuture> resultFuture = - updateMeterMessage.canUseSingleLayerSerialization() - ? updateMeterMessage.handleServiceCall(input.getUpdatedMeter()) - : updateMeter.handleServiceCall(input.getUpdatedMeter()); - - Futures.addCallback(resultFuture, new FutureCallback>() { - @Override - public void onSuccess(RpcResult result) { - if (result.isSuccessful()) { - if (LOG.isDebugEnabled()) { - LOG.debug("Meter update with id={} finished without error", - input.getOriginalMeter().getMeterId()); - } - } else { - LOG.warn("Meter update with id={} failed, errors={}", input.getOriginalMeter().getMeterId(), - ErrorUtil.errorsToString(result.getErrors())); - LOG.debug("Meter input={}", input.getUpdatedMeter()); - } - } - - @Override - public void onFailure(Throwable throwable) { - LOG.warn("Service call for updating meter={} failed", - input.getOriginalMeter().getMeterId(), throwable); - } - }, MoreExecutors.directExecutor()); - return resultFuture; - } - - @Override - public ListenableFuture> removeMeter(final RemoveMeterInput input) { - final ListenableFuture> resultFuture = - removeMeterMessage.canUseSingleLayerSerialization() - ? removeMeterMessage.handleServiceCall(input) - : removeMeter.handleServiceCall(input); - - Futures.addCallback(resultFuture, new FutureCallback>() { - @Override - public void onSuccess(RpcResult result) { - if (result.isSuccessful()) { - if (LOG.isDebugEnabled()) { - LOG.debug("Meter remove with id={} finished without error", input.getMeterId()); - } - } else { - LOG.warn("Meter remove with id={} failed, errors={}", input.getMeterId(), - ErrorUtil.errorsToString(result.getErrors())); - LOG.debug("Meter input={}", input); - } - } - - @Override - public void onFailure(Throwable throwable) { - LOG.warn("Service call for removing meter={} failed", input.getMeterId(), throwable); - } - }, MoreExecutors.directExecutor()); - return resultFuture; - } -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalMetersBatchServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalMetersBatchServiceImpl.java deleted file mode 100644 index bfeb225e13..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalMetersBatchServiceImpl.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl.services.sal; - -import static java.util.Objects.requireNonNull; - -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.MoreExecutors; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import org.opendaylight.openflowplugin.impl.util.BarrierUtil; -import org.opendaylight.openflowplugin.impl.util.MeterUtil; -import org.opendaylight.openflowplugin.impl.util.PathUtil; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.OriginalMeterBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeterBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterRef; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.BatchMeterInputUpdateGrouping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.SalMetersBatchService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.add.meters.batch.input.BatchAddMeters; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.batch.meter.output.list.grouping.BatchFailedMetersOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.remove.meters.batch.input.BatchRemoveMeters; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.update.meters.batch.input.BatchUpdateMeters; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Default implementation of {@link SalMetersBatchService} - delegates work to {@link SalMeterService}. - */ -public class SalMetersBatchServiceImpl implements SalMetersBatchService { - private static final Logger LOG = LoggerFactory.getLogger(SalMetersBatchServiceImpl.class); - - private final SalMeterService salMeterService; - private final FlowCapableTransactionService transactionService; - - public SalMetersBatchServiceImpl(final SalMeterService salMeterService, - final FlowCapableTransactionService transactionService) { - this.salMeterService = requireNonNull(salMeterService); - this.transactionService = requireNonNull(transactionService); - } - - @Override - public ListenableFuture> updateMetersBatch(final UpdateMetersBatchInput input) { - final List batchUpdateMeters = input.getBatchUpdateMeters(); - LOG.trace("Updating meters @ {} : {}", PathUtil.extractNodeId(input.getNode()), batchUpdateMeters.size()); - - final ArrayList>> resultsLot = new ArrayList<>(); - for (BatchUpdateMeters batchMeter : batchUpdateMeters) { - final UpdateMeterInput updateMeterInput = new UpdateMeterInputBuilder(input) - .setOriginalMeter(new OriginalMeterBuilder(batchMeter.getOriginalBatchedMeter()).build()) - .setUpdatedMeter(new UpdatedMeterBuilder(batchMeter.getUpdatedBatchedMeter()).build()) - .setMeterRef(createMeterRef(input.getNode(), batchMeter)) - .setNode(input.getNode()) - .build(); - resultsLot.add(salMeterService.updateMeter(updateMeterInput)); - } - - final Iterable meters = batchUpdateMeters.stream() - .map(BatchMeterInputUpdateGrouping::getUpdatedBatchedMeter) - .collect(Collectors.toList()); - - final ListenableFuture>> commonResult = - Futures.transform(Futures.allAsList(resultsLot), - MeterUtil.createCumulativeFunction(meters, batchUpdateMeters.size()), - MoreExecutors.directExecutor()); - - ListenableFuture> updateMetersBulkFuture = - Futures.transform(commonResult, MeterUtil.METER_UPDATE_TRANSFORM, MoreExecutors.directExecutor()); - - if (input.getBarrierAfter()) { - updateMetersBulkFuture = BarrierUtil.chainBarrier(updateMetersBulkFuture, input.getNode(), - transactionService, MeterUtil.METER_UPDATE_COMPOSING_TRANSFORM); - } - - return updateMetersBulkFuture; - } - - @Override - public ListenableFuture> addMetersBatch(final AddMetersBatchInput input) { - LOG.trace("Adding meters @ {} : {}", PathUtil.extractNodeId(input.getNode()), input.getBatchAddMeters().size()); - final ArrayList>> resultsLot = new ArrayList<>(); - for (BatchAddMeters addMeter : input.nonnullBatchAddMeters().values()) { - final AddMeterInput addMeterInput = new AddMeterInputBuilder(addMeter) - .setMeterRef(createMeterRef(input.getNode(), addMeter)) - .setNode(input.getNode()) - .build(); - resultsLot.add(salMeterService.addMeter(addMeterInput)); - } - - final ListenableFuture>> commonResult = - Futures.transform(Futures.allAsList(resultsLot), - MeterUtil.createCumulativeFunction(input.nonnullBatchAddMeters().values()), - MoreExecutors.directExecutor()); - - ListenableFuture> addMetersBulkFuture = - Futures.transform(commonResult, MeterUtil.METER_ADD_TRANSFORM, MoreExecutors.directExecutor()); - - if (input.getBarrierAfter()) { - addMetersBulkFuture = BarrierUtil.chainBarrier(addMetersBulkFuture, input.getNode(), - transactionService, MeterUtil.METER_ADD_COMPOSING_TRANSFORM); - } - - return addMetersBulkFuture; - } - - @Override - public ListenableFuture> removeMetersBatch(final RemoveMetersBatchInput input) { - LOG.trace("Removing meters @ {} : {}", - PathUtil.extractNodeId(input.getNode()), - input.getBatchRemoveMeters().size()); - final ArrayList>> resultsLot = new ArrayList<>(); - for (BatchRemoveMeters addMeter : input.nonnullBatchRemoveMeters().values()) { - final RemoveMeterInput removeMeterInput = new RemoveMeterInputBuilder(addMeter) - .setMeterRef(createMeterRef(input.getNode(), addMeter)) - .setNode(input.getNode()) - .build(); - resultsLot.add(salMeterService.removeMeter(removeMeterInput)); - } - - final ListenableFuture>> commonResult = - Futures.transform(Futures.allAsList(resultsLot), - MeterUtil.createCumulativeFunction(input.nonnullBatchRemoveMeters().values()), - MoreExecutors.directExecutor()); - - ListenableFuture> removeMetersBulkFuture = - Futures.transform(commonResult, MeterUtil.METER_REMOVE_TRANSFORM, MoreExecutors.directExecutor()); - - if (input.getBarrierAfter()) { - removeMetersBulkFuture = BarrierUtil.chainBarrier(removeMetersBulkFuture, input.getNode(), - transactionService, MeterUtil.METER_REMOVE_COMPOSING_TRANSFORM); - } - - return removeMetersBulkFuture; - } - - private static MeterRef createMeterRef(final NodeRef nodeRef, final Meter batchMeter) { - return MeterUtil.buildMeterPath((InstanceIdentifier) nodeRef.getValue(), batchMeter.getMeterId()); - } - - private static MeterRef createMeterRef(final NodeRef nodeRef, final BatchUpdateMeters batchMeter) { - return MeterUtil.buildMeterPath((InstanceIdentifier) nodeRef.getValue(), - batchMeter.getUpdatedBatchedMeter().getMeterId()); - } -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/FlowCapableTransactionServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SendBarrierImpl.java similarity index 76% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/FlowCapableTransactionServiceImpl.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SendBarrierImpl.java index 4d74c1327d..e286185217 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/FlowCapableTransactionServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SendBarrierImpl.java @@ -12,22 +12,21 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.impl.services.AbstractSimpleService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yangtools.yang.common.RpcResult; -public class FlowCapableTransactionServiceImpl extends AbstractSimpleService - implements FlowCapableTransactionService { - public FlowCapableTransactionServiceImpl(final RequestContextStack requestContextStack, - final DeviceContext deviceContext) { +public final class SendBarrierImpl extends AbstractSimpleService + implements SendBarrier { + public SendBarrierImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) { super(requestContextStack, deviceContext, SendBarrierOutput.class); } @Override - public ListenableFuture> sendBarrier(final SendBarrierInput input) { + public ListenableFuture> invoke(final SendBarrierInput input) { return handleServiceCall(input); } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalExperimenterMessageServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SendExperimenterImpl.java similarity index 81% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalExperimenterMessageServiceImpl.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SendExperimenterImpl.java index ba18b4b510..04ac1e6b9e 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalExperimenterMessageServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SendExperimenterImpl.java @@ -22,7 +22,7 @@ import org.opendaylight.openflowplugin.extension.api.exception.ConversionExcepti import org.opendaylight.openflowplugin.extension.api.exception.ConverterNotFoundException; import org.opendaylight.openflowplugin.impl.services.AbstractSimpleService; import org.opendaylight.openflowplugin.impl.services.util.ServiceException; -import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SalExperimenterMessageService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenter; import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenterOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder; @@ -33,20 +33,24 @@ import org.opendaylight.yangtools.yang.common.RpcResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class SalExperimenterMessageServiceImpl extends AbstractSimpleService implements SalExperimenterMessageService { - private static final Logger LOG = LoggerFactory.getLogger(SalExperimenterMessageServiceImpl.class); +public final class SendExperimenterImpl extends AbstractSimpleService + implements SendExperimenter { + private static final Logger LOG = LoggerFactory.getLogger(SendExperimenterImpl.class); private final ExtensionConverterProvider extensionConverterProvider; - public SalExperimenterMessageServiceImpl(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ExtensionConverterProvider extensionConverterProvider) { + public SendExperimenterImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ExtensionConverterProvider extensionConverterProvider) { super(requestContextStack, deviceContext, SendExperimenterOutput.class); this.extensionConverterProvider = extensionConverterProvider; } @Override - protected OfHeader buildRequest(Xid xid, SendExperimenterInput input) throws ServiceException { + public ListenableFuture> invoke(final SendExperimenterInput input) { + return handleServiceCall(input); + } + + @Override + protected OfHeader buildRequest(final Xid xid, final SendExperimenterInput input) throws ServiceException { final TypeVersionKey key = new TypeVersionKey(input.getExperimenterMessageOfChoice().implementedInterface(), getVersion()); final ConverterMessageToOFJava> sendExperimenter(SendExperimenterInput input) { - return handleServiceCall(input); - } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalExperimenterMpMessageServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SendExperimenterMpRequestImpl.java similarity index 77% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalExperimenterMpMessageServiceImpl.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SendExperimenterMpRequestImpl.java index a7b45e567a..627a6f3f18 100755 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalExperimenterMpMessageServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SendExperimenterMpRequestImpl.java @@ -5,7 +5,6 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.openflowplugin.impl.services.sal; import com.google.common.util.concurrent.ListenableFuture; @@ -14,27 +13,27 @@ import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider; import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerExperimenterMultipartService; import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerExperimenterMultipartService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SalExperimenterMpMessageService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequest; import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestOutput; import org.opendaylight.yangtools.yang.common.RpcResult; -public class SalExperimenterMpMessageServiceImpl implements SalExperimenterMpMessageService { +public final class SendExperimenterMpRequestImpl implements SendExperimenterMpRequest { private final MultiLayerExperimenterMultipartService multiLayerService; private final SingleLayerExperimenterMultipartService singleLayerService; - public SalExperimenterMpMessageServiceImpl(final RequestContextStack requestContextStack, + public SendExperimenterMpRequestImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, final ExtensionConverterProvider extensionConverterProvider) { - this.singleLayerService = new SingleLayerExperimenterMultipartService(requestContextStack, deviceContext, + singleLayerService = new SingleLayerExperimenterMultipartService(requestContextStack, deviceContext, extensionConverterProvider); - this.multiLayerService = new MultiLayerExperimenterMultipartService(requestContextStack, deviceContext, + multiLayerService = new MultiLayerExperimenterMultipartService(requestContextStack, deviceContext, extensionConverterProvider); } @Override - public ListenableFuture> - sendExperimenterMpRequest(SendExperimenterMpRequestInput input) { + public ListenableFuture> invoke( + final SendExperimenterMpRequestInput input) { return singleLayerService.canUseSingleLayerSerialization() ? singleLayerService.handleAndReply(input) : multiLayerService.handleAndReply(input); diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/NodeConfigServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SetConfigImpl.java similarity index 67% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/NodeConfigServiceImpl.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SetConfigImpl.java index 890c80d2a7..dfd22f4458 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/NodeConfigServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SetConfigImpl.java @@ -12,7 +12,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.impl.services.AbstractSimpleService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfig; import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag; @@ -20,26 +20,24 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInputBuilder; import org.opendaylight.yangtools.yang.common.RpcResult; -public final class NodeConfigServiceImpl extends AbstractSimpleService - implements NodeConfigService { - public NodeConfigServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) { +public final class SetConfigImpl extends AbstractSimpleService implements SetConfig { + public SetConfigImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) { super(requestContextStack, deviceContext, SetConfigOutput.class); } @Override - public ListenableFuture> setConfig(final SetConfigInput input) { + public ListenableFuture> invoke(final SetConfigInput input) { return handleServiceCall(input); } @Override protected OfHeader buildRequest(final Xid xid, final SetConfigInput input) { - SetConfigInputBuilder builder = new SetConfigInputBuilder(); - SwitchConfigFlag flag = SwitchConfigFlag.valueOf(input.getFlag()); - - builder.setXid(xid.getValue()); - builder.setFlags(flag); - builder.setMissSendLen(input.getMissSearchLength()); - builder.setVersion(getVersion()); - return builder.build(); + return new SetConfigInputBuilder() + .setXid(xid.getValue()) + // FIXME: this conversion relies on Binding's Java names -- i.e. different from SwitchConfigFlag.forName()! + .setFlags(SwitchConfigFlag.valueOf(input.getFlag())) + .setMissSendLen(input.getMissSearchLength()) + .setVersion(getVersion()) + .build(); } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/PacketProcessingServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/TransmitPacketImpl.java similarity index 78% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/PacketProcessingServiceImpl.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/TransmitPacketImpl.java index bc7e5bdf25..77b368854e 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/PacketProcessingServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/TransmitPacketImpl.java @@ -18,25 +18,23 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PacketOutC import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.XidConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacket; import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketOutput; import org.opendaylight.yangtools.yang.common.RpcResult; -public final class PacketProcessingServiceImpl extends AbstractSimpleService - implements PacketProcessingService { - +public final class TransmitPacketImpl extends AbstractSimpleService + implements TransmitPacket { private final ConvertorExecutor convertorExecutor; - public PacketProcessingServiceImpl(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor) { + public TransmitPacketImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor) { super(requestContextStack, deviceContext, TransmitPacketOutput.class); this.convertorExecutor = convertorExecutor; } @Override - public ListenableFuture> transmitPacket(final TransmitPacketInput input) { + public ListenableFuture> invoke(final TransmitPacketInput input) { return handleServiceCall(input); } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateFlowImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateFlowImpl.java new file mode 100644 index 0000000000..03cf8c0447 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateFlowImpl.java @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2024 PANTHEON.tech, s.r.o. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import com.google.common.util.concurrent.SettableFuture; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.api.openflow.FlowGroupStatus; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry; +import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor; +import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey; +import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory; +import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory; +import org.opendaylight.openflowplugin.impl.util.FlowCreatorUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder; +import org.opendaylight.yangtools.yang.common.ErrorType; +import org.opendaylight.yangtools.yang.common.RpcError; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.opendaylight.yangtools.yang.common.Uint8; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class UpdateFlowImpl extends AbstractFlowRpc implements UpdateFlow { + private static final Logger LOG = LoggerFactory.getLogger(UpdateFlowImpl.class); + + public UpdateFlowImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor) { + super(requestContextStack, deviceContext, convertorExecutor, UpdateFlowOutput.class); + } + + @Override + public ListenableFuture> invoke(final UpdateFlowInput input) { + final var updated = input.getUpdatedFlow(); + final var original = input.getOriginalFlow(); + final var allFlowMods = new ArrayList(); + final List ofFlowModInputs; + + ListenableFuture> future; + if (single.canUseSingleLayerSerialization()) { + + if (!FlowCreatorUtil.canModifyFlow(original, updated, single.getVersion())) { + final var objectSettableFuture = SettableFuture.>create(); + final var listListenableFuture = Futures.successfulAsList( + single.handleServiceCall(input.getOriginalFlow()), + single.handleServiceCall(input.getUpdatedFlow())); + + Futures.addCallback(listListenableFuture, new FutureCallback<>() { + @Override + public void onSuccess(final List> results) { + final var errors = new ArrayList(); + for (var flowModResult : results) { + if (flowModResult == null) { + errors.add(RpcResultBuilder.newError( + ErrorType.PROTOCOL, OFConstants.APPLICATION_TAG, + "unexpected flowMod result (null) occurred")); + } else if (!flowModResult.isSuccessful()) { + errors.addAll(flowModResult.getErrors()); + } + } + + final var rpcResultBuilder = errors.isEmpty() ? RpcResultBuilder.success() + : RpcResultBuilder.failed().withRpcErrors(errors); + + objectSettableFuture.set(rpcResultBuilder.build()); + } + + @Override + public void onFailure(final Throwable throwable) { + objectSettableFuture.set(RpcResultBuilder.failed().build()); + } + }, MoreExecutors.directExecutor()); + + future = objectSettableFuture; + } else { + future = single.handleServiceCall(input.getUpdatedFlow()); + } + } else { + if (!FlowCreatorUtil.canModifyFlow(original, updated, multi.getVersion())) { + // We would need to remove original and add updated. + + // remove flow + final RemoveFlowInputBuilder removeflow = new RemoveFlowInputBuilder(original); + final List ofFlowRemoveInput = multi.toFlowModInputs(removeflow.build()); + // remove flow should be the first + allFlowMods.addAll(ofFlowRemoveInput); + final AddFlowInputBuilder addFlowInputBuilder = new AddFlowInputBuilder(updated); + ofFlowModInputs = multi.toFlowModInputs(addFlowInputBuilder.build()); + } else { + ofFlowModInputs = multi.toFlowModInputs(updated); + } + + allFlowMods.addAll(ofFlowModInputs); + + future = multi.processFlowModInputBuilders(allFlowMods); + } + + Futures.addCallback(future, new UpdateFlowCallback(input), MoreExecutors.directExecutor()); + return future; + } + + + private final class UpdateFlowCallback implements FutureCallback> { + private final UpdateFlowInput input; + + private UpdateFlowCallback(final UpdateFlowInput input) { + this.input = input; + } + + @Override + public void onSuccess(final RpcResult updateFlowOutputRpcResult) { + final DeviceFlowRegistry deviceFlowRegistry = deviceContext.getDeviceFlowRegistry(); + final UpdatedFlow updated = input.getUpdatedFlow(); + final OriginalFlow original = input.getOriginalFlow(); + final FlowRegistryKey origFlowRegistryKey = + FlowRegistryKeyFactory.create(deviceContext.getDeviceInfo().getVersion(), original); + final FlowRegistryKey updatedFlowRegistryKey = + FlowRegistryKeyFactory.create(deviceContext.getDeviceInfo().getVersion(), updated); + final FlowDescriptor origFlowDescriptor = deviceFlowRegistry.retrieveDescriptor(origFlowRegistryKey); + + final boolean isUpdate = origFlowDescriptor != null; + final FlowDescriptor updatedFlowDescriptor; + final FlowRef flowRef = input.getFlowRef(); + if (flowRef != null) { + final Uint8 tableId = updated.getTableId(); + final FlowId flowId = flowRef.getValue().firstKeyOf(Flow.class).getId(); + // FIXME: this does not look right, we probably want better integration + deviceFlowRegistry.appendHistoryFlow(flowId, tableId, FlowGroupStatus.MODIFIED); + + updatedFlowDescriptor = FlowDescriptorFactory.create(tableId, flowId); + } else if (isUpdate) { + updatedFlowDescriptor = origFlowDescriptor; + } else { + deviceFlowRegistry.store(updatedFlowRegistryKey); + updatedFlowDescriptor = deviceFlowRegistry.retrieveDescriptor(updatedFlowRegistryKey); + } + + if (isUpdate) { + deviceFlowRegistry.addMark(origFlowRegistryKey); + deviceFlowRegistry.storeDescriptor(updatedFlowRegistryKey, updatedFlowDescriptor); + } + } + + @Override + public void onFailure(final Throwable throwable) { + LOG.warn("Service call for updating flow={} failed", input, throwable); + } + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateFlowsBatchImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateFlowsBatchImpl.java new file mode 100644 index 0000000000..6d6a7a697c --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateFlowsBatchImpl.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import org.opendaylight.openflowplugin.impl.util.BarrierUtil; +import org.opendaylight.openflowplugin.impl.util.FlowUtil; +import org.opendaylight.openflowplugin.impl.util.PathUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlowBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.BatchFlowInputUpdateGrouping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class UpdateFlowsBatchImpl implements UpdateFlowsBatch { + private static final Logger LOG = LoggerFactory.getLogger(UpdateFlowsBatchImpl.class); + + private final UpdateFlow updateFlow; + private final SendBarrier sendBarrier; + + public UpdateFlowsBatchImpl(final UpdateFlow updateFlow, final SendBarrier sendBarrier) { + this.updateFlow = requireNonNull(updateFlow); + this.sendBarrier = requireNonNull(sendBarrier); + } + + @Override + public ListenableFuture> invoke(final UpdateFlowsBatchInput input) { + final var flows = input.nonnullBatchUpdateFlows().values(); + if (LOG.isTraceEnabled()) { + LOG.trace("Updating flows @ {} : {}", PathUtil.extractNodeId(input.getNode()), flows.size()); + } + + final var resultsLot = flows.stream() + .map(batchFlow -> updateFlow.invoke(new UpdateFlowInputBuilder(input) + .setOriginalFlow(new OriginalFlowBuilder(batchFlow.getOriginalBatchedFlow()).build()) + .setUpdatedFlow(new UpdatedFlowBuilder(batchFlow.getUpdatedBatchedFlow()).build()) + .setFlowRef(createFlowRef(input.getNode(), batchFlow)) + .setNode(input.getNode()) + .build())) + .toList(); + + final var commonResult = Futures.transform(Futures.successfulAsList(resultsLot), + FlowUtil.createCumulatingFunction(flows), MoreExecutors.directExecutor()); + final var updateFlowsBulkFuture = Futures.transform(commonResult, FlowUtil.FLOW_UPDATE_TRANSFORM, + MoreExecutors.directExecutor()); + return input.getBarrierAfter() + ? BarrierUtil.chainBarrier(updateFlowsBulkFuture, input.getNode(), sendBarrier, + FlowUtil.FLOW_UPDATE_COMPOSING_TRANSFORM) + : updateFlowsBulkFuture; + } + + private static FlowRef createFlowRef(final NodeRef nodeRef, final BatchFlowInputUpdateGrouping batchFlow) { + return FlowUtil.buildFlowPath((InstanceIdentifier) nodeRef.getValue(), + batchFlow.getOriginalBatchedFlow().getTableId(), batchFlow.getFlowId()); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateGroupImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateGroupImpl.java new file mode 100755 index 0000000000..67dee548e1 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateGroupImpl.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2024 PANTHEON.tech, s.r.o. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import org.opendaylight.openflowplugin.api.openflow.FlowGroupStatus; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.impl.util.ErrorUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroup; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroup; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class UpdateGroupImpl extends AbstractGroupRpc implements UpdateGroup { + private static final Logger LOG = LoggerFactory.getLogger(UpdateGroupImpl.class); + + public UpdateGroupImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor) { + super(requestContextStack, deviceContext, convertorExecutor, UpdateGroupOutput.class); + } + + @Override + public ListenableFuture> invoke(final UpdateGroupInput input) { + final var resultFuture = single.canUseSingleLayerSerialization() + ? single.handleServiceCall(input.getUpdatedGroup()) + : multi.handleServiceCall(input.getUpdatedGroup()); + + Futures.addCallback(resultFuture, new FutureCallback<>() { + @Override + public void onSuccess(final RpcResult result) { + if (result.isSuccessful()) { + UpdatedGroup updatedGroup = input.getUpdatedGroup(); + deviceContext.getDeviceGroupRegistry().appendHistoryGroup( + updatedGroup.getGroupId(), updatedGroup.getGroupType(), FlowGroupStatus.MODIFIED); + if (LOG.isDebugEnabled()) { + LOG.debug("Group update with original id={} finished without error", + input.getOriginalGroup().getGroupId().getValue()); + } + } else { + LOG.warn("Group update with original id={} failed, errors={}", + input.getOriginalGroup().getGroupId(), ErrorUtil.errorsToString(result.getErrors())); + LOG.debug("Group input={}", input.getUpdatedGroup()); + } + } + + @Override + public void onFailure(final Throwable throwable) { + LOG.warn("Service call for updating group={} failed", input.getOriginalGroup().getGroupId(), throwable); + } + }, MoreExecutors.directExecutor()); + return resultFuture; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateGroupsBatchImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateGroupsBatchImpl.java new file mode 100644 index 0000000000..8b32e3a0e6 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateGroupsBatchImpl.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import java.util.stream.Collectors; +import org.opendaylight.openflowplugin.impl.util.BarrierUtil; +import org.opendaylight.openflowplugin.impl.util.GroupUtil; +import org.opendaylight.openflowplugin.impl.util.PathUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroup; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.OriginalGroupBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroupBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.BatchGroupInputUpdateGrouping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.update.groups.batch.input.BatchUpdateGroups; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class UpdateGroupsBatchImpl implements UpdateGroupsBatch { + private static final Logger LOG = LoggerFactory.getLogger(UpdateGroupsBatchImpl.class); + + private final UpdateGroup updateGroup; + private final SendBarrier sendBarrier; + + public UpdateGroupsBatchImpl(final UpdateGroup updateGroup, final SendBarrier sendBarrier) { + this.updateGroup = requireNonNull(updateGroup); + this.sendBarrier = requireNonNull(sendBarrier); + } + + @Override + public ListenableFuture> invoke(final UpdateGroupsBatchInput input) { + final var batchUpdateGroups = input.nonnullBatchUpdateGroups(); + if (LOG.isTraceEnabled()) { + LOG.trace("Updating groups @ {} : {}", PathUtil.extractNodeId(input.getNode()), batchUpdateGroups.size()); + } + + final var resultsLot = batchUpdateGroups.stream() + .map(batchGroup -> updateGroup.invoke(new UpdateGroupInputBuilder(input) + .setOriginalGroup(new OriginalGroupBuilder(batchGroup.getOriginalBatchedGroup()).build()) + .setUpdatedGroup(new UpdatedGroupBuilder(batchGroup.getUpdatedBatchedGroup()).build()) + .setGroupRef(createGroupRef(input.getNode(), batchGroup)) + .setNode(input.getNode()) + .build())) + .collect(Collectors.toList()); + + final var groups = batchUpdateGroups.stream() + .map(BatchGroupInputUpdateGrouping::getUpdatedBatchedGroup) + .collect(Collectors.toList()); + + final var commonResult = Futures.transform(Futures.allAsList(resultsLot), + GroupUtil.createCumulatingFunction(groups, batchUpdateGroups.size()), + MoreExecutors.directExecutor()); + + final var updateGroupsBulkFuture = Futures.transform(commonResult, GroupUtil.GROUP_UPDATE_TRANSFORM, + MoreExecutors.directExecutor()); + + return input.getBarrierAfter() + ? BarrierUtil.chainBarrier(updateGroupsBulkFuture, input.getNode(), sendBarrier, + GroupUtil.GROUP_UPDATE_COMPOSING_TRANSFORM) + : updateGroupsBulkFuture; + } + + private static GroupRef createGroupRef(final NodeRef nodeRef, final BatchUpdateGroups batchGroup) { + return GroupUtil.buildGroupPath((InstanceIdentifier) nodeRef.getValue(), + batchGroup.getUpdatedBatchedGroup().getGroupId()); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateMeterImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateMeterImpl.java new file mode 100644 index 0000000000..4e1399ab64 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateMeterImpl.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2024 PANTHEON.tech, s.r.o. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.impl.util.ErrorUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class UpdateMeterImpl extends AbstractMeterRpc implements UpdateMeter { + private static final Logger LOG = LoggerFactory.getLogger(UpdateMeterImpl.class); + + public UpdateMeterImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor) { + super(requestContextStack, deviceContext, convertorExecutor, UpdateMeterOutput.class); + } + + @Override + public ListenableFuture> invoke(final UpdateMeterInput input) { + final var resultFuture = single.canUseSingleLayerSerialization() + ? single.handleServiceCall(input.getUpdatedMeter()) + : multi.handleServiceCall(input.getUpdatedMeter()); + + Futures.addCallback(resultFuture, new FutureCallback<>() { + @Override + public void onSuccess(final RpcResult result) { + if (result.isSuccessful()) { + if (LOG.isDebugEnabled()) { + LOG.debug("Meter update with id={} finished without error", + input.getOriginalMeter().getMeterId()); + } + } else { + LOG.warn("Meter update with id={} failed, errors={}", input.getOriginalMeter().getMeterId(), + ErrorUtil.errorsToString(result.getErrors())); + LOG.debug("Meter input={}", input.getUpdatedMeter()); + } + } + + @Override + public void onFailure(final Throwable throwable) { + LOG.warn("Service call for updating meter={} failed", input.getOriginalMeter().getMeterId(), throwable); + } + }, MoreExecutors.directExecutor()); + return resultFuture; + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateMetersBatchImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateMetersBatchImpl.java new file mode 100644 index 0000000000..04d622a70f --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateMetersBatchImpl.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.sal; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import java.util.stream.Collectors; +import org.opendaylight.openflowplugin.impl.util.BarrierUtil; +import org.opendaylight.openflowplugin.impl.util.MeterUtil; +import org.opendaylight.openflowplugin.impl.util.PathUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.OriginalMeterBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeterBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.BatchMeterInputUpdateGrouping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.update.meters.batch.input.BatchUpdateMeters; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class UpdateMetersBatchImpl implements UpdateMetersBatch { + private static final Logger LOG = LoggerFactory.getLogger(UpdateMetersBatchImpl.class); + + private final UpdateMeter updateMeter; + private final SendBarrier sendBarrier; + + public UpdateMetersBatchImpl(final UpdateMeter updateMeter, final SendBarrier sendBarrier) { + this.updateMeter = requireNonNull(updateMeter); + this.sendBarrier = requireNonNull(sendBarrier); + } + + @Override + public ListenableFuture> invoke(final UpdateMetersBatchInput input) { + final var batchUpdateMeters = input.nonnullBatchUpdateMeters(); + if (LOG.isTraceEnabled()) { + LOG.trace("Updating meters @ {} : {}", PathUtil.extractNodeId(input.getNode()), batchUpdateMeters.size()); + } + + final var resultsLot = batchUpdateMeters.stream() + .map(batchMeter -> updateMeter.invoke(new UpdateMeterInputBuilder(input) + .setOriginalMeter(new OriginalMeterBuilder(batchMeter.getOriginalBatchedMeter()).build()) + .setUpdatedMeter(new UpdatedMeterBuilder(batchMeter.getUpdatedBatchedMeter()).build()) + .setMeterRef(createMeterRef(input.getNode(), batchMeter)) + .setNode(input.getNode()) + .build())) + .collect(Collectors.toList()); + + final var meters = batchUpdateMeters.stream() + .map(BatchMeterInputUpdateGrouping::getUpdatedBatchedMeter) + .collect(Collectors.toList()); + + final var commonResult = Futures.transform(Futures.allAsList(resultsLot), + MeterUtil.createCumulativeFunction(meters, batchUpdateMeters.size()), MoreExecutors.directExecutor()); + + final var updateMetersBulkFuture = Futures.transform(commonResult, MeterUtil.METER_UPDATE_TRANSFORM, + MoreExecutors.directExecutor()); + + return input.getBarrierAfter() + ? BarrierUtil.chainBarrier(updateMetersBulkFuture, input.getNode(), sendBarrier, + MeterUtil.METER_UPDATE_COMPOSING_TRANSFORM) + : updateMetersBulkFuture; + } + + private static MeterRef createMeterRef(final NodeRef nodeRef, final BatchUpdateMeters batchMeter) { + return MeterUtil.buildMeterPath((InstanceIdentifier) nodeRef.getValue(), + batchMeter.getUpdatedBatchedMeter().getMeterId()); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalPortServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdatePortImpl.java similarity index 82% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalPortServiceImpl.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdatePortImpl.java index d6e149ceb5..828ec24abb 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalPortServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdatePortImpl.java @@ -21,18 +21,18 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.p import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.SalPortService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePort; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput; import org.opendaylight.yangtools.yang.common.RpcResult; -public final class SalPortServiceImpl - extends AbstractSimpleService implements SalPortService { +public final class UpdatePortImpl extends AbstractSimpleService + implements UpdatePort { private final ConvertorExecutor convertorExecutor; private final VersionConvertorData data; private final SingleLayerPortService portMessage; - public SalPortServiceImpl(final RequestContextStack requestContextStack, + public UpdatePortImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor) { super(requestContextStack, deviceContext, UpdatePortOutput.class); @@ -42,7 +42,7 @@ public final class SalPortServiceImpl } @Override - public ListenableFuture> updatePort(final UpdatePortInput input) { + public ListenableFuture> invoke(final UpdatePortInput input) { return portMessage.canUseSingleLayerSerialization() ? portMessage.handleServiceCall(getPortFromInput(input)) : handleServiceCall(input); @@ -50,14 +50,11 @@ public final class SalPortServiceImpl @Override protected OfHeader buildRequest(final Xid xid, final UpdatePortInput input) { - final Optional ofPortModInput = convertorExecutor - .convert(getPortFromInput(input), data); + final Optional ofPortModInput = convertorExecutor.convert(getPortFromInput(input), data); - final PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput - .orElse(PortConvertor.defaultResult(getVersion()))) - .setXid(xid.getValue()); - - return mdInput.build(); + return new PortModInputBuilder(ofPortModInput.orElse(PortConvertor.defaultResult(getVersion()))) + .setXid(xid.getValue()) + .build(); } private static Port getPortFromInput(final UpdatePortInput input) { diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalTableServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateTableImpl.java similarity index 72% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalTableServiceImpl.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateTableImpl.java index bdc0bb89cc..2a886861bf 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalTableServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateTableImpl.java @@ -14,31 +14,27 @@ import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerTableMultipartService; import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerTableMultipartService; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; -import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput; import org.opendaylight.yangtools.yang.common.RpcResult; -public final class SalTableServiceImpl implements SalTableService { - +public final class UpdateTableImpl implements UpdateTable { private final SingleLayerTableMultipartService singleLayerService; private final MultiLayerTableMultipartService multiLayerService; - public SalTableServiceImpl(final RequestContextStack requestContextStack, + public UpdateTableImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor, final MultipartWriterProvider multipartWriterProvider) { - singleLayerService = new SingleLayerTableMultipartService(requestContextStack, - deviceContext, - multipartWriterProvider); - multiLayerService = new MultiLayerTableMultipartService(requestContextStack, - deviceContext, - convertorExecutor, - multipartWriterProvider); + singleLayerService = new SingleLayerTableMultipartService(requestContextStack, deviceContext, + multipartWriterProvider); + multiLayerService = new MultiLayerTableMultipartService(requestContextStack, deviceContext, convertorExecutor, + multipartWriterProvider); } @Override - public ListenableFuture> updateTable(final UpdateTableInput input) { + public ListenableFuture> invoke(final UpdateTableInput input) { return singleLayerService.canUseSingleLayerSerialization() ? singleLayerService.handleAndReply(input) : multiLayerService.handleAndReply(input); diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/singlelayer/GetAsyncImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/singlelayer/GetAsyncImpl.java new file mode 100644 index 0000000000..a0883d7721 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/singlelayer/GetAsyncImpl.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.services.singlelayer; + +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.api.openflow.device.Xid; +import org.opendaylight.openflowplugin.impl.services.AbstractSimpleService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.AsyncConfigMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsync; +import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; + +public final class GetAsyncImpl extends AbstractSimpleService implements GetAsync { + public GetAsyncImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) { + super(requestContextStack, deviceContext, AsyncConfigMessage.class); + } + + @Override + public ListenableFuture> invoke(final GetAsyncInput input) { + return Futures.transform(handleServiceCall(input), result -> + result != null && result.isSuccessful() + ? RpcResultBuilder.success(new GetAsyncOutputBuilder(result.getResult()).build()).build() + : RpcResultBuilder.failed().build(), + MoreExecutors.directExecutor()); + } + + @Override + protected OfHeader buildRequest(final Xid xid, final GetAsyncInput input) { + return new GetAsyncInputBuilder().setVersion(getVersion()).setXid(xid.getValue()).build(); + } +} \ No newline at end of file diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/singlelayer/SingleLayerSetAsyncConfigService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/singlelayer/SetAsyncImpl.java similarity index 69% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/singlelayer/SingleLayerSetAsyncConfigService.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/singlelayer/SetAsyncImpl.java index bbfc248cb8..fef9146617 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/singlelayer/SingleLayerSetAsyncConfigService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/singlelayer/SetAsyncImpl.java @@ -5,27 +5,33 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.openflowplugin.impl.services.singlelayer; +import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.impl.services.AbstractSimpleService; import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.AsyncConfigMessageBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SetAsync; import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SetAsyncInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SetAsyncOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; +import org.opendaylight.yangtools.yang.common.RpcResult; -public class SingleLayerSetAsyncConfigService extends AbstractSimpleService { - - public SingleLayerSetAsyncConfigService(final RequestContextStack requestContextStack, +public final class SetAsyncImpl extends AbstractSimpleService implements SetAsync { + public SetAsyncImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) { super(requestContextStack, deviceContext, SetAsyncOutput.class); } @Override - protected OfHeader buildRequest(Xid xid, SetAsyncInput input) { + public ListenableFuture> invoke(final SetAsyncInput input) { + return handleServiceCall(input); + } + + @Override + protected OfHeader buildRequest(final Xid xid, final SetAsyncInput input) { return new AsyncConfigMessageBuilder(input) .setVersion(getVersion()) .setXid(xid.getValue()) diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/singlelayer/SingleLayerGetAsyncConfigService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/singlelayer/SingleLayerGetAsyncConfigService.java deleted file mode 100644 index 1e89489b2d..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/singlelayer/SingleLayerGetAsyncConfigService.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.openflowplugin.impl.services.singlelayer; - -import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.openflowplugin.api.openflow.device.Xid; -import org.opendaylight.openflowplugin.impl.services.AbstractSimpleService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.AsyncConfigMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; - -public class SingleLayerGetAsyncConfigService extends AbstractSimpleService { - - public SingleLayerGetAsyncConfigService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext) { - super(requestContextStack, deviceContext, AsyncConfigMessage.class); - } - - @Override - protected OfHeader buildRequest(Xid xid, GetAsyncInput input) { - return new GetAsyncInputBuilder().setVersion(getVersion()).setXid(xid.getValue()).build(); - } -} \ No newline at end of file diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AggregateFlowsInTableService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AggregateFlowsInTableService.java index 2a586862b7..db0356abbe 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AggregateFlowsInTableService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AggregateFlowsInTableService.java @@ -40,25 +40,13 @@ public final class AggregateFlowsInTableService extends AbstractCompatibleStatService { - - final TranslatorLibrary translatorLibrary; - - public static AggregateFlowsInTableService createWithOook(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final AtomicLong compatibilityXidSeed) { - return new AggregateFlowsInTableService(requestContextStack, - deviceContext, - compatibilityXidSeed, - deviceContext.oook()); - } + private final TranslatorLibrary translatorLibrary; public AggregateFlowsInTableService(final RequestContextStack requestContextStack, final DeviceContext deviceContext, - final AtomicLong compatibilityXidSeed, - final TranslatorLibrary translatorLibrary) { + final AtomicLong compatibilityXidSeed) { super(requestContextStack, deviceContext, compatibilityXidSeed); - - this.translatorLibrary = translatorLibrary; + translatorLibrary = deviceContext.oook(); } @Override diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AllGroupsStatsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AllGroupsStatsService.java index 075d5facb7..e05369237b 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AllGroupsStatsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/AllGroupsStatsService.java @@ -43,7 +43,6 @@ final class AllGroupsStatsService extends private final ConvertorExecutor convertorExecutor; - AllGroupsStatsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext, final AtomicLong compatibilityXidSeed, final ConvertorExecutor convertorExecutor) { super(requestContextStack, deviceContext, compatibilityXidSeed); @@ -71,9 +70,7 @@ final class AllGroupsStatsService extends @Override public GroupStatisticsUpdated transformToNotification(final List result, final TransactionId emulatedTxId) { - return GroupStatisticsToNotificationTransformer.transformToNotification(result, - getDeviceInfo(), - emulatedTxId, - convertorExecutor); + return GroupStatisticsToNotificationTransformer.transformToNotification(result, getDeviceInfo(), emulatedTxId, + convertorExecutor); } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAggregateFlowStatisticsFromFlowTableForGivenMatchImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAggregateFlowStatisticsFromFlowTableForGivenMatchImpl.java new file mode 100644 index 0000000000..3bd13bf26d --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAggregateFlowStatisticsFromFlowTableForGivenMatchImpl.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services; + +import com.google.common.util.concurrent.ListenableFuture; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerAggregateFlowMultipartService; +import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerAggregateFlowMultipartService; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +public final class GetAggregateFlowStatisticsFromFlowTableForGivenMatchImpl + implements GetAggregateFlowStatisticsFromFlowTableForGivenMatch { + private final SingleLayerAggregateFlowMultipartService single; + private final MultiLayerAggregateFlowMultipartService multi; + + public GetAggregateFlowStatisticsFromFlowTableForGivenMatchImpl(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor) { + single = new SingleLayerAggregateFlowMultipartService(requestContextStack, deviceContext); + multi = new MultiLayerAggregateFlowMultipartService(requestContextStack, deviceContext, + convertorExecutor, deviceContext.oook()); + } + + @Override + public ListenableFuture> invoke( + final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) { + return single.canUseSingleLayerSerialization() ? single.handleAndReply(input) : multi.handleAndReply(input); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllGroupStatisticsImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllGroupStatisticsImpl.java new file mode 100644 index 0000000000..c12e538e0a --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllGroupStatisticsImpl.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.atomic.AtomicLong; +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@Deprecated +public final class GetAllGroupStatisticsImpl implements GetAllGroupStatistics { + private final NotificationPublishService notificationPublishService; + private final @NonNull AllGroupsStatsService allGroups; + + public GetAllGroupStatisticsImpl(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final AtomicLong compatibilityXidSeed, + final NotificationPublishService notificationPublishService, final ConvertorExecutor convertorExecutor) { + this.notificationPublishService = notificationPublishService; + allGroups = new AllGroupsStatsService(requestContextStack, deviceContext, compatibilityXidSeed, + convertorExecutor); + } + + @Override + public ListenableFuture> invoke(final GetAllGroupStatisticsInput input) { + return allGroups.handleAndNotify(input, notificationPublishService); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllMeterConfigStatisticsImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllMeterConfigStatisticsImpl.java new file mode 100644 index 0000000000..af5cecfa4d --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllMeterConfigStatisticsImpl.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.atomic.AtomicLong; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@Deprecated +public final class GetAllMeterConfigStatisticsImpl implements GetAllMeterConfigStatistics { + private final NotificationPublishService notificationPublishService; + private final AllMeterConfigStatsService allMeterConfig; + + public GetAllMeterConfigStatisticsImpl(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final AtomicLong compatibilityXidSeed, + final NotificationPublishService notificationPublishService, final ConvertorExecutor convertorExecutor) { + allMeterConfig = new AllMeterConfigStatsService(requestContextStack, deviceContext, compatibilityXidSeed, + convertorExecutor); + this.notificationPublishService = requireNonNull(notificationPublishService); + } + + @Override + public ListenableFuture> invoke( + final GetAllMeterConfigStatisticsInput input) { + return allMeterConfig.handleAndNotify(input, notificationPublishService); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllMeterStatisticsImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllMeterStatisticsImpl.java new file mode 100644 index 0000000000..a4449c37e8 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllMeterStatisticsImpl.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.atomic.AtomicLong; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@Deprecated +public final class GetAllMeterStatisticsImpl implements GetAllMeterStatistics { + private final NotificationPublishService notificationPublishService; + private final AllMeterStatsService allMeterStats; + + public GetAllMeterStatisticsImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final AtomicLong compatibilityXidSeed, final NotificationPublishService notificationPublishService, + final ConvertorExecutor convertorExecutor) { + allMeterStats = new AllMeterStatsService(requestContextStack, deviceContext, compatibilityXidSeed, + convertorExecutor); + this.notificationPublishService = requireNonNull(notificationPublishService); + } + + @Override + public ListenableFuture> invoke(final GetAllMeterStatisticsInput input) { + return allMeterStats.handleAndNotify(input, notificationPublishService); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllNodeConnectorsStatisticsImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllNodeConnectorsStatisticsImpl.java new file mode 100644 index 0000000000..750710c0e2 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllNodeConnectorsStatisticsImpl.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.atomic.AtomicLong; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@Deprecated +public final class GetAllNodeConnectorsStatisticsImpl implements GetAllNodeConnectorsStatistics { + private final AllPortStatsService allPortStats; + private final NotificationPublishService notificationPublishService; + + public GetAllNodeConnectorsStatisticsImpl(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, + final AtomicLong compatibilityXidSeed, + final NotificationPublishService notificationPublishService) { + allPortStats = new AllPortStatsService(requestContextStack, deviceContext, compatibilityXidSeed); + this.notificationPublishService = requireNonNull(notificationPublishService); + } + + @Override + public ListenableFuture> invoke( + final GetAllNodeConnectorsStatisticsInput input) { + return allPortStats.handleAndNotify(input, notificationPublishService); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllQueuesStatisticsFromAllPortsImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllQueuesStatisticsFromAllPortsImpl.java new file mode 100644 index 0000000000..5c03b09621 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllQueuesStatisticsFromAllPortsImpl.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.atomic.AtomicLong; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPorts; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@Deprecated +public final class GetAllQueuesStatisticsFromAllPortsImpl implements GetAllQueuesStatisticsFromAllPorts { + private final NotificationPublishService notificationPublishService; + private final AllQueuesAllPortsService allQueuesAllPorts; + + public GetAllQueuesStatisticsFromAllPortsImpl(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final AtomicLong compatibilityXidSeed, + final NotificationPublishService notificationPublishService) { + allQueuesAllPorts = new AllQueuesAllPortsService(requestContextStack, deviceContext, compatibilityXidSeed); + this.notificationPublishService = requireNonNull(notificationPublishService); + } + + @Override + public ListenableFuture> invoke( + final GetAllQueuesStatisticsFromAllPortsInput input) { + return allQueuesAllPorts.handleAndNotify(input, notificationPublishService); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllQueuesStatisticsFromGivenPortImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllQueuesStatisticsFromGivenPortImpl.java new file mode 100644 index 0000000000..356705773c --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetAllQueuesStatisticsFromGivenPortImpl.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.atomic.AtomicLong; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@Deprecated +public final class GetAllQueuesStatisticsFromGivenPortImpl implements GetAllQueuesStatisticsFromGivenPort { + private final NotificationPublishService notificationPublishService; + private final AllQueuesOnePortService allQueuesOnePort; + + public GetAllQueuesStatisticsFromGivenPortImpl(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final AtomicLong compatibilityXidSeed, + final NotificationPublishService notificationPublishService) { + allQueuesOnePort = new AllQueuesOnePortService(requestContextStack, deviceContext, compatibilityXidSeed); + this.notificationPublishService = requireNonNull(notificationPublishService); + } + + @Override + public ListenableFuture> invoke( + final GetAllQueuesStatisticsFromGivenPortInput input) { + return allQueuesOnePort.handleAndNotify(input, notificationPublishService); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowTableStatisticsServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetFlowTablesStatisticsImpl.java similarity index 58% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowTableStatisticsServiceImpl.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetFlowTablesStatisticsImpl.java index fbd7825ed0..b89d412145 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowTableStatisticsServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetFlowTablesStatisticsImpl.java @@ -7,6 +7,8 @@ */ package org.opendaylight.openflowplugin.impl.statistics.services; +import static java.util.Objects.requireNonNull; + import com.google.common.util.concurrent.ListenableFuture; import java.util.List; import java.util.concurrent.atomic.AtomicLong; @@ -20,21 +22,18 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types. import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatistics; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStats; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId; @@ -42,44 +41,35 @@ import org.opendaylight.yangtools.yang.binding.util.BindingMap; import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.common.RpcResult; -public final class OpendaylightFlowTableStatisticsServiceImpl extends - AbstractCompatibleStatService implements - OpendaylightFlowTableStatisticsService { - +@Deprecated +public final class GetFlowTablesStatisticsImpl + extends AbstractCompatibleStatService + implements GetFlowTablesStatistics { private final NotificationPublishService notificationPublishService; - public OpendaylightFlowTableStatisticsServiceImpl(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final AtomicLong compatibilityXidSeed, - final NotificationPublishService notificationPublishService) { + public GetFlowTablesStatisticsImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final AtomicLong compatibilityXidSeed, final NotificationPublishService notificationPublishService) { super(requestContextStack, deviceContext, compatibilityXidSeed); - this.notificationPublishService = notificationPublishService; + this.notificationPublishService = requireNonNull(notificationPublishService); } @Override - public ListenableFuture> getFlowTablesStatistics( - final GetFlowTablesStatisticsInput input) { + public ListenableFuture> invoke(final GetFlowTablesStatisticsInput input) { return handleAndNotify(input, notificationPublishService); } @Override protected OfHeader buildRequest(final Xid xid, final GetFlowTablesStatisticsInput input) { - // Create multipart request body for fetch all the group stats - final MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = - new MultipartRequestTableCaseBuilder(); - final MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder(); - multipartRequestTableBuilder.setEmpty(Empty.value()); - multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build()); - // Set request body to main multipart request - final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader( - MultipartType.OFPMPTABLE, xid.getValue(), getVersion()); - - mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build()); - - return mprInput.build(); + return RequestInputUtils.createMultipartHeader(MultipartType.OFPMPTABLE, xid.getValue(), getVersion()) + // Create multipart request body for fetch all the group stats + .setMultipartRequestBody(new MultipartRequestTableCaseBuilder() + .setMultipartRequestTable(new MultipartRequestTableBuilder() + .setEmpty(Empty.value()) + .build()) + .build()) + .build(); } @Override @@ -90,24 +80,23 @@ public final class OpendaylightFlowTableStatisticsServiceImpl extends @Override public FlowTableStatisticsUpdate transformToNotification(final List mpReplyList, final TransactionId emulatedTxId) { - FlowTableStatisticsUpdateBuilder notification = new FlowTableStatisticsUpdateBuilder(); - notification.setId(getDeviceInfo().getNodeId()); - notification.setMoreReplies(Boolean.FALSE); - notification.setTransactionId(emulatedTxId); + final var notification = new FlowTableStatisticsUpdateBuilder() + .setId(getDeviceInfo().getNodeId()) + .setMoreReplies(Boolean.FALSE) + .setTransactionId(emulatedTxId); final var salFlowStats = BindingMap.orderedBuilder(); - for (MultipartReply mpReply : mpReplyList) { - MultipartReplyTableCase caseBody = (MultipartReplyTableCase) mpReply.getMultipartReplyBody(); - MultipartReplyTable replyBody = caseBody.getMultipartReplyTable(); + for (var mpReply : mpReplyList) { + final var caseBody = (MultipartReplyTableCase) mpReply.getMultipartReplyBody(); //TODO: Duplicate code: look at MultiReplyTranslatorUtil method translateTable - for (TableStats swTableStats : replyBody.nonnullTableStats()) { - FlowTableAndStatisticsMapBuilder statisticsBuilder = new FlowTableAndStatisticsMapBuilder(); - statisticsBuilder.setActiveFlows(new Counter32(swTableStats.getActiveCount())); - statisticsBuilder.setPacketsLookedUp(new Counter64(swTableStats.getLookupCount())); - statisticsBuilder.setPacketsMatched(new Counter64(swTableStats.getMatchedCount())); - statisticsBuilder.setTableId(new TableId(swTableStats.getTableId())); - salFlowStats.add(statisticsBuilder.build()); + for (var swTableStats : caseBody.getMultipartReplyTable().nonnullTableStats()) { + salFlowStats.add(new FlowTableAndStatisticsMapBuilder() + .setActiveFlows(new Counter32(swTableStats.getActiveCount())) + .setPacketsLookedUp(new Counter64(swTableStats.getLookupCount())) + .setPacketsMatched(new Counter64(swTableStats.getMatchedCount())) + .setTableId(new TableId(swTableStats.getTableId())) + .build()); } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetGroupDescriptionImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetGroupDescriptionImpl.java new file mode 100644 index 0000000000..8e3fd1236b --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetGroupDescriptionImpl.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.atomic.AtomicLong; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescription; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@Deprecated +public final class GetGroupDescriptionImpl implements GetGroupDescription { + private final GroupDescriptionService groupDesc; + private final NotificationPublishService notificationPublishService; + + public GetGroupDescriptionImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final AtomicLong compatibilityXidSeed, final NotificationPublishService notificationPublishService, + final ConvertorExecutor convertorExecutor) { + groupDesc = new GroupDescriptionService(requestContextStack, deviceContext, compatibilityXidSeed, + convertorExecutor); + this.notificationPublishService = requireNonNull(notificationPublishService); + } + + @Override + public ListenableFuture> invoke(final GetGroupDescriptionInput input) { + return groupDesc.handleAndNotify(input, notificationPublishService); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetGroupFeaturesImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetGroupFeaturesImpl.java new file mode 100644 index 0000000000..454ceb12a7 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetGroupFeaturesImpl.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.atomic.AtomicLong; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@Deprecated +public final class GetGroupFeaturesImpl implements GetGroupFeatures { + private final GroupFeaturesService groupFeat; + private final NotificationPublishService notificationPublishService; + + public GetGroupFeaturesImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final AtomicLong compatibilityXidSeed, final NotificationPublishService notificationPublishService, + final ConvertorExecutor convertorExecutor) { + groupFeat = new GroupFeaturesService(requestContextStack, deviceContext, compatibilityXidSeed); + this.notificationPublishService = requireNonNull(notificationPublishService); + } + + @Override + public ListenableFuture> invoke(final GetGroupFeaturesInput input) { + return groupFeat.handleAndNotify(input, notificationPublishService); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetGroupStatisticsImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetGroupStatisticsImpl.java new file mode 100644 index 0000000000..336d8da3f8 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetGroupStatisticsImpl.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.atomic.AtomicLong; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@Deprecated +public final class GetGroupStatisticsImpl implements GetGroupStatistics { + private final GroupStatsService groupStats; + private final NotificationPublishService notificationPublishService; + + public GetGroupStatisticsImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final AtomicLong compatibilityXidSeed, final NotificationPublishService notificationPublishService, + final ConvertorExecutor convertorExecutor) { + this.notificationPublishService = notificationPublishService; + groupStats = new GroupStatsService(requestContextStack, deviceContext, compatibilityXidSeed, convertorExecutor); + } + + @Override + public ListenableFuture> invoke(final GetGroupStatisticsInput input) { + return groupStats.handleAndNotify(input, notificationPublishService); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetMeterFeaturesImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetMeterFeaturesImpl.java new file mode 100644 index 0000000000..8c99035dac --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetMeterFeaturesImpl.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.atomic.AtomicLong; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@Deprecated +public final class GetMeterFeaturesImpl implements GetMeterFeatures { + private final NotificationPublishService notificationPublishService; + private final MeterFeaturesService meterFeatures; + + public GetMeterFeaturesImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final AtomicLong compatibilityXidSeed, final NotificationPublishService notificationPublishService, + final ConvertorExecutor convertorExecutor) { + meterFeatures = new MeterFeaturesService(requestContextStack, deviceContext, compatibilityXidSeed); + this.notificationPublishService = requireNonNull(notificationPublishService); + } + + @Override + public ListenableFuture> invoke(final GetMeterFeaturesInput input) { + return meterFeatures.handleAndNotify(input, notificationPublishService); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetMeterStatisticsImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetMeterStatisticsImpl.java new file mode 100644 index 0000000000..3549e740b7 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetMeterStatisticsImpl.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.atomic.AtomicLong; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@Deprecated +public final class GetMeterStatisticsImpl implements GetMeterStatistics { + private final NotificationPublishService notificationPublishService; + private final MeterStatsService meterStats; + + public GetMeterStatisticsImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final AtomicLong compatibilityXidSeed, final NotificationPublishService notificationPublishService, + final ConvertorExecutor convertorExecutor) { + meterStats = new MeterStatsService(requestContextStack, deviceContext, compatibilityXidSeed, convertorExecutor); + this.notificationPublishService = requireNonNull(notificationPublishService); + } + + @Override + public ListenableFuture> invoke(final GetMeterStatisticsInput input) { + return meterStats.handleAndNotify(input, notificationPublishService); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightPortStatisticsServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetNodeConnectorStatisticsImpl.java similarity index 66% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightPortStatisticsServiceImpl.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetNodeConnectorStatisticsImpl.java index 2199c612da..edb421da91 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightPortStatisticsServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetNodeConnectorStatisticsImpl.java @@ -12,35 +12,26 @@ import java.util.concurrent.atomic.AtomicLong; import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatistics; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService; import org.opendaylight.yangtools.yang.common.RpcResult; -public class OpendaylightPortStatisticsServiceImpl implements OpendaylightPortStatisticsService { - private final AllPortStatsService allPortStats; +@Deprecated +public final class GetNodeConnectorStatisticsImpl implements GetNodeConnectorStatistics { private final PortStatsService portStats; private final NotificationPublishService notificationPublishService; - public OpendaylightPortStatisticsServiceImpl(final RequestContextStack requestContextStack, + public GetNodeConnectorStatisticsImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, final AtomicLong compatibilityXidSeed, final NotificationPublishService notificationPublishService) { this.notificationPublishService = notificationPublishService; - allPortStats = new AllPortStatsService(requestContextStack, deviceContext, compatibilityXidSeed); portStats = new PortStatsService(requestContextStack, deviceContext, compatibilityXidSeed); } @Override - public ListenableFuture> getAllNodeConnectorsStatistics( - final GetAllNodeConnectorsStatisticsInput input) { - return allPortStats.handleAndNotify(input, notificationPublishService); - } - - @Override - public ListenableFuture> getNodeConnectorStatistics( + public ListenableFuture> invoke( final GetNodeConnectorStatisticsInput input) { return portStats.handleAndNotify(input, notificationPublishService); } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetQueueStatisticsFromGivenPortImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetQueueStatisticsFromGivenPortImpl.java new file mode 100644 index 0000000000..624d5fee91 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/GetQueueStatisticsFromGivenPortImpl.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.atomic.AtomicLong; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@Deprecated +public final class GetQueueStatisticsFromGivenPortImpl implements GetQueueStatisticsFromGivenPort { + private final OneQueueOnePortService oneQueueOnePort; + private final NotificationPublishService notificationPublishService; + + public GetQueueStatisticsFromGivenPortImpl(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final AtomicLong compatibilityXidSeed, + final NotificationPublishService notificationPublishService) { + oneQueueOnePort = new OneQueueOnePortService(requestContextStack, deviceContext, compatibilityXidSeed); + this.notificationPublishService = requireNonNull(notificationPublishService); + } + + @Override + public ListenableFuture> invoke( + final GetQueueStatisticsFromGivenPortInput input) { + return oneQueueOnePort.handleAndNotify(input, notificationPublishService); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl.java deleted file mode 100644 index f6f9878fae..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl.statistics.services; - -import com.google.common.util.concurrent.ListenableFuture; -import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary; -import org.opendaylight.openflowplugin.api.openflow.statistics.compatibility.Delegator; -import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerAggregateFlowMultipartService; -import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerAggregateFlowMultipartService; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService; -import org.opendaylight.yangtools.yang.common.RpcResult; - -public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowStatisticsService, - Delegator { - - private final SingleLayerAggregateFlowMultipartService singleLayerService; - private final MultiLayerAggregateFlowMultipartService multiLayerService; - private OpendaylightFlowStatisticsService delegate; - - public static OpendaylightFlowStatisticsServiceImpl createWithOook(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor) { - return new OpendaylightFlowStatisticsServiceImpl(requestContextStack, - deviceContext, - deviceContext.oook(), - convertorExecutor); - } - - public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final TranslatorLibrary translatorLibrary, - final ConvertorExecutor convertorExecutor) { - singleLayerService = new SingleLayerAggregateFlowMultipartService(requestContextStack, deviceContext); - multiLayerService = new MultiLayerAggregateFlowMultipartService(requestContextStack, deviceContext, - convertorExecutor, translatorLibrary); - } - - @Override - public void setDelegate(OpendaylightFlowStatisticsService delegate) { - this.delegate = delegate; - } - - /** - * Get aggregate statistics. - * - * @deprecated provided for Be-release as backward compatibility relic. - */ - @Override - @Deprecated - public ListenableFuture> - getAggregateFlowStatisticsFromFlowTableForAllFlows( - final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) { - if (delegate != null) { - return delegate.getAggregateFlowStatisticsFromFlowTableForAllFlows(input); - } else { - throw new IllegalAccessError("no delegate available - service is currently out of order"); - } - } - - @Override - public ListenableFuture> - getAggregateFlowStatisticsFromFlowTableForGivenMatch( - final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) { - return singleLayerService.canUseSingleLayerSerialization() - ? singleLayerService.handleAndReply(input) - : multiLayerService.handleAndReply(input); - } - - /** - * Get flow statistics. - * - * @deprecated provided for Be-release as backward compatibility relic. - */ - @Override - @Deprecated - public ListenableFuture> getAllFlowStatisticsFromFlowTable( - final GetAllFlowStatisticsFromFlowTableInput input) { - if (delegate != null) { - return delegate.getAllFlowStatisticsFromFlowTable(input); - } else { - throw new IllegalAccessError("no delegate available - service is currently out of order"); - } - } - - /** - * Get flow statistics. - * - * @deprecated provided for Be-release as backward compatibility relic. - */ - @Override - @Deprecated - public ListenableFuture> - getAllFlowsStatisticsFromAllFlowTables(final GetAllFlowsStatisticsFromAllFlowTablesInput input) { - if (delegate != null) { - return delegate.getAllFlowsStatisticsFromAllFlowTables(input); - } else { - throw new IllegalAccessError("no delegate available - service is currently out of order"); - } - } - - /** - * Get flow statistics. - * - * @deprecated provided for Be-release as backward compatibility relic. - */ - @Override - @Deprecated - public ListenableFuture> getFlowStatisticsFromFlowTable( - final GetFlowStatisticsFromFlowTableInput input) { - if (delegate != null) { - return delegate.getFlowStatisticsFromFlowTable(input); - } else { - throw new IllegalAccessError("no delegate available - service is currently out of order"); - } - } -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightGroupStatisticsServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightGroupStatisticsServiceImpl.java deleted file mode 100644 index 1f56925a9a..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightGroupStatisticsServiceImpl.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl.statistics.services; - -import com.google.common.util.concurrent.ListenableFuture; -import java.util.concurrent.atomic.AtomicLong; -import org.opendaylight.mdsal.binding.api.NotificationPublishService; -import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService; -import org.opendaylight.yangtools.yang.common.RpcResult; - -public class OpendaylightGroupStatisticsServiceImpl implements OpendaylightGroupStatisticsService { - private final AllGroupsStatsService allGroups; - private final GroupDescriptionService groupDesc; - private final GroupFeaturesService groupFeat; - private final GroupStatsService groupStats; - private final NotificationPublishService notificationPublishService; - - public OpendaylightGroupStatisticsServiceImpl(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final AtomicLong compatibilityXidSeed, - final NotificationPublishService notificationPublishService, - final ConvertorExecutor convertorExecutor) { - this.notificationPublishService = notificationPublishService; - allGroups = - new AllGroupsStatsService(requestContextStack, deviceContext, compatibilityXidSeed, convertorExecutor); - groupDesc = new GroupDescriptionService(requestContextStack, - deviceContext, - compatibilityXidSeed, - convertorExecutor); - groupFeat = new GroupFeaturesService(requestContextStack, deviceContext, compatibilityXidSeed); - groupStats = new GroupStatsService(requestContextStack, deviceContext, compatibilityXidSeed, convertorExecutor); - } - - @Override - public ListenableFuture> getAllGroupStatistics( - final GetAllGroupStatisticsInput input) { - return allGroups.handleAndNotify(input, notificationPublishService); - } - - @Override - public ListenableFuture> getGroupDescription( - final GetGroupDescriptionInput input) { - return groupDesc.handleAndNotify(input, notificationPublishService); - } - - @Override - public ListenableFuture> getGroupFeatures(final GetGroupFeaturesInput input) { - return groupFeat.handleAndNotify(input, notificationPublishService); - } - - @Override - public ListenableFuture> getGroupStatistics( - final GetGroupStatisticsInput input) { - return groupStats.handleAndNotify(input, notificationPublishService); - } -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightMeterStatisticsServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightMeterStatisticsServiceImpl.java deleted file mode 100644 index 981b50d5a0..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightMeterStatisticsServiceImpl.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl.statistics.services; - -import com.google.common.util.concurrent.ListenableFuture; -import java.util.concurrent.atomic.AtomicLong; -import org.opendaylight.mdsal.binding.api.NotificationPublishService; -import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService; -import org.opendaylight.yangtools.yang.common.RpcResult; - -public class OpendaylightMeterStatisticsServiceImpl implements OpendaylightMeterStatisticsService { - private final AllMeterConfigStatsService allMeterConfig; - private final AllMeterStatsService allMeterStats; - private final MeterFeaturesService meterFeatures; - private final MeterStatsService meterStats; - private final NotificationPublishService notificationPublishService; - - public OpendaylightMeterStatisticsServiceImpl(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final AtomicLong compatibilityXidSeed, - final NotificationPublishService notificationPublishService, - final ConvertorExecutor convertorExecutor) { - this.notificationPublishService = notificationPublishService; - - allMeterConfig = new AllMeterConfigStatsService(requestContextStack, - deviceContext, - compatibilityXidSeed, - convertorExecutor); - allMeterStats = new AllMeterStatsService(requestContextStack, - deviceContext, - compatibilityXidSeed, - convertorExecutor); - meterFeatures = new MeterFeaturesService(requestContextStack, deviceContext, compatibilityXidSeed); - meterStats = new MeterStatsService(requestContextStack, deviceContext, compatibilityXidSeed, convertorExecutor); - } - - @Override - public ListenableFuture> getAllMeterConfigStatistics( - final GetAllMeterConfigStatisticsInput input) { - return allMeterConfig.handleAndNotify(input, notificationPublishService); - } - - @Override - public ListenableFuture> getAllMeterStatistics( - final GetAllMeterStatisticsInput input) { - return allMeterStats.handleAndNotify(input, notificationPublishService); - } - - @Override - public ListenableFuture> getMeterFeatures(final GetMeterFeaturesInput input) { - return meterFeatures.handleAndNotify(input, notificationPublishService); - } - - @Override - public ListenableFuture> getMeterStatistics( - final GetMeterStatisticsInput input) { - return meterStats.handleAndNotify(input, notificationPublishService); - } -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightQueueStatisticsServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightQueueStatisticsServiceImpl.java deleted file mode 100644 index d04aef97d2..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightQueueStatisticsServiceImpl.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl.statistics.services; - -import com.google.common.util.concurrent.ListenableFuture; -import java.util.concurrent.atomic.AtomicLong; -import org.opendaylight.mdsal.binding.api.NotificationPublishService; -import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsService; -import org.opendaylight.yangtools.yang.common.RpcResult; - -public class OpendaylightQueueStatisticsServiceImpl implements OpendaylightQueueStatisticsService { - private final AllQueuesAllPortsService allQueuesAllPorts; - private final AllQueuesOnePortService allQueuesOnePort; - private final OneQueueOnePortService oneQueueOnePort; - private final NotificationPublishService notificationPublishService; - - public OpendaylightQueueStatisticsServiceImpl(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final AtomicLong compatibilityXidSeed, - final NotificationPublishService notificationPublishService) { - this.notificationPublishService = notificationPublishService; - allQueuesAllPorts = new AllQueuesAllPortsService(requestContextStack, deviceContext, compatibilityXidSeed); - allQueuesOnePort = new AllQueuesOnePortService(requestContextStack, deviceContext, compatibilityXidSeed); - oneQueueOnePort = new OneQueueOnePortService(requestContextStack, deviceContext, compatibilityXidSeed); - } - - @Override - public ListenableFuture> getAllQueuesStatisticsFromAllPorts( - final GetAllQueuesStatisticsFromAllPortsInput input) { - return allQueuesAllPorts.handleAndNotify(input, notificationPublishService); - } - - @Override - public ListenableFuture> getAllQueuesStatisticsFromGivenPort( - final GetAllQueuesStatisticsFromGivenPortInput input) { - return allQueuesOnePort.handleAndNotify(input, notificationPublishService); - } - - @Override - public ListenableFuture> getQueueStatisticsFromGivenPort( - final GetQueueStatisticsFromGivenPortInput input) { - return oneQueueOnePort.handleAndNotify(input, notificationPublishService); - } -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/PortStatsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/PortStatsService.java index a4bdf4666c..8c4832935c 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/PortStatsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/PortStatsService.java @@ -33,20 +33,15 @@ import org.opendaylight.yangtools.yang.common.Uint8; final class PortStatsService extends AbstractCompatibleStatService { - - PortStatsService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final AtomicLong compatibilityXidSeed) { + PortStatsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final AtomicLong compatibilityXidSeed) { super(requestContextStack, deviceContext, compatibilityXidSeed); } @Override - protected OfHeader buildRequest(final Xid xid, - final GetNodeConnectorStatisticsInput input) { - MultipartRequestPortStatsCaseBuilder caseBuilder = - new MultipartRequestPortStatsCaseBuilder(); - MultipartRequestPortStatsBuilder mprPortStatsBuilder = - new MultipartRequestPortStatsBuilder(); + protected OfHeader buildRequest(final Xid xid, final GetNodeConnectorStatisticsInput input) { + MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder(); + MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder(); // Set specific port final Uint8 version = getVersion(); mprPortStatsBuilder @@ -70,9 +65,7 @@ final class PortStatsService extends AbstractCompatibleStatService result, final TransactionId emulatedTxId) { - return NodeConnectorStatisticsToNotificationTransformer.transformToNotification(result, - getDeviceInfo(), - getOfVersion(), - emulatedTxId); + return NodeConnectorStatisticsToNotificationTransformer.transformToNotification(result, getDeviceInfo(), + getOfVersion(), emulatedTxId); } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GetAggregateFlowStatisticsFromFlowTableForAllFlowsImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GetAggregateFlowStatisticsFromFlowTableForAllFlowsImpl.java new file mode 100644 index 0000000000..4ce460cd7b --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GetAggregateFlowStatisticsFromFlowTableForAllFlowsImpl.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services.compatibility; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.atomic.AtomicLong; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.impl.statistics.services.AggregateFlowsInTableService; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlows; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@Deprecated +public final class GetAggregateFlowStatisticsFromFlowTableForAllFlowsImpl + implements GetAggregateFlowStatisticsFromFlowTableForAllFlows { + private final AggregateFlowsInTableService aggregateFlowsInTable; + private final NotificationPublishService notificationService; + + public GetAggregateFlowStatisticsFromFlowTableForAllFlowsImpl(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor, + final AtomicLong compatibilityXidSeed, final NotificationPublishService notificationService) { + aggregateFlowsInTable = new AggregateFlowsInTableService(requestContextStack, deviceContext, + compatibilityXidSeed); + this.notificationService = requireNonNull(notificationService); + } + + @Override + public ListenableFuture> invoke( + final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) { + return aggregateFlowsInTable.handleAndNotify(input, notificationService); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GetAllFlowStatisticsFromFlowTableImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GetAllFlowStatisticsFromFlowTableImpl.java new file mode 100644 index 0000000000..a2e351dfc3 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GetAllFlowStatisticsFromFlowTableImpl.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services.compatibility; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.atomic.AtomicLong; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.impl.statistics.services.AllFlowsInTableService; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@Deprecated +public final class GetAllFlowStatisticsFromFlowTableImpl implements GetAllFlowStatisticsFromFlowTable { + private final AllFlowsInTableService allFlowsInTable; + private final NotificationPublishService notificationService; + + public GetAllFlowStatisticsFromFlowTableImpl(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor, + final AtomicLong compatibilityXidSeed, final NotificationPublishService notificationService) { + allFlowsInTable = new AllFlowsInTableService(requestContextStack, deviceContext, compatibilityXidSeed, + convertorExecutor); + this.notificationService = requireNonNull(notificationService); + } + + @Override + public ListenableFuture> invoke( + final GetAllFlowStatisticsFromFlowTableInput input) { + return allFlowsInTable.handleAndNotify(input, notificationService); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GetAllFlowsStatisticsFromAllFlowTablesImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GetAllFlowsStatisticsFromAllFlowTablesImpl.java new file mode 100644 index 0000000000..0740f81802 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GetAllFlowsStatisticsFromAllFlowTablesImpl.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services.compatibility; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.atomic.AtomicLong; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.impl.statistics.services.AllFlowsInAllTablesService; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTables; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@Deprecated +public final class GetAllFlowsStatisticsFromAllFlowTablesImpl implements GetAllFlowsStatisticsFromAllFlowTables { + private final NotificationPublishService notificationService; + private final AllFlowsInAllTablesService allFlowsInAllTables; + + public GetAllFlowsStatisticsFromAllFlowTablesImpl(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor, + final AtomicLong compatibilityXidSeed, final NotificationPublishService notificationService) { + allFlowsInAllTables = new AllFlowsInAllTablesService(requestContextStack, deviceContext, compatibilityXidSeed, + convertorExecutor); + this.notificationService = requireNonNull(notificationService); + } + + @Override + public ListenableFuture> invoke( + final GetAllFlowsStatisticsFromAllFlowTablesInput input) { + return allFlowsInAllTables.handleAndNotify(input, notificationService); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GetFlowStatisticsFromFlowTableImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GetFlowStatisticsFromFlowTableImpl.java new file mode 100644 index 0000000000..901d3609b3 --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/GetFlowStatisticsFromFlowTableImpl.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowplugin.impl.statistics.services.compatibility; + +import static java.util.Objects.requireNonNull; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.atomic.AtomicLong; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; +import org.opendaylight.openflowplugin.impl.statistics.services.FlowsInTableService; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@Deprecated +public final class GetFlowStatisticsFromFlowTableImpl implements GetFlowStatisticsFromFlowTable { + private final FlowsInTableService flowsInTable; + private final NotificationPublishService notificationService; + + public GetFlowStatisticsFromFlowTableImpl(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor, + final AtomicLong compatibilityXidSeed, final NotificationPublishService notificationService) { + flowsInTable = new FlowsInTableService(requestContextStack, deviceContext, compatibilityXidSeed, + convertorExecutor); + this.notificationService = requireNonNull(notificationService); + } + + @Override + public ListenableFuture> invoke( + final GetFlowStatisticsFromFlowTableInput input) { + return flowsInTable.handleAndNotify(input, notificationService); + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/OpendaylightFlowStatisticsServiceDelegateImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/OpendaylightFlowStatisticsServiceDelegateImpl.java deleted file mode 100644 index ff9bbee23c..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/OpendaylightFlowStatisticsServiceDelegateImpl.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl.statistics.services.compatibility; - -import com.google.common.util.concurrent.ListenableFuture; -import java.util.concurrent.atomic.AtomicLong; -import org.opendaylight.mdsal.binding.api.NotificationPublishService; -import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.openflowplugin.impl.statistics.services.AggregateFlowsInTableService; -import org.opendaylight.openflowplugin.impl.statistics.services.AllFlowsInAllTablesService; -import org.opendaylight.openflowplugin.impl.statistics.services.AllFlowsInTableService; -import org.opendaylight.openflowplugin.impl.statistics.services.FlowsInTableService; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class OpendaylightFlowStatisticsServiceDelegateImpl implements OpendaylightFlowStatisticsService { - - private static final Logger LOG = LoggerFactory.getLogger(OpendaylightFlowStatisticsServiceDelegateImpl.class); - - private final AggregateFlowsInTableService aggregateFlowsInTable; - private final AllFlowsInAllTablesService allFlowsInAllTables; - private final AllFlowsInTableService allFlowsInTable; - private final FlowsInTableService flowsInTable; - private final NotificationPublishService notificationService; - - public OpendaylightFlowStatisticsServiceDelegateImpl(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final NotificationPublishService notificationService, - final AtomicLong compatibilityXidSeed, - final ConvertorExecutor convertorExecutor) { - this.notificationService = notificationService; - aggregateFlowsInTable = - AggregateFlowsInTableService.createWithOook(requestContextStack, deviceContext, compatibilityXidSeed); - allFlowsInAllTables = new AllFlowsInAllTablesService(requestContextStack, - deviceContext, - compatibilityXidSeed, - convertorExecutor); - allFlowsInTable = - new AllFlowsInTableService(requestContextStack, deviceContext, compatibilityXidSeed, convertorExecutor); - flowsInTable = - new FlowsInTableService(requestContextStack, deviceContext, compatibilityXidSeed, convertorExecutor); - } - - /** - * Get statistics for the given match. - * - * @deprecated this is the only method with real implementation provided, in delegate it makes no sense. - */ - @Override - @Deprecated - public ListenableFuture> - getAggregateFlowStatisticsFromFlowTableForGivenMatch( - final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) { - throw new IllegalAccessError("unsupported by backward compatibility delegate service " - + "- this rpc is always provided by default service implementation"); - } - - @Override - public ListenableFuture> - getAggregateFlowStatisticsFromFlowTableForAllFlows( - final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) { - return aggregateFlowsInTable.handleAndNotify(input, notificationService); - } - - @Override - public ListenableFuture> getAllFlowStatisticsFromFlowTable( - final GetAllFlowStatisticsFromFlowTableInput input) { - return allFlowsInTable.handleAndNotify(input, notificationService); - } - - @Override - public ListenableFuture> - getAllFlowsStatisticsFromAllFlowTables(final GetAllFlowsStatisticsFromAllFlowTablesInput input) { - return allFlowsInAllTables.handleAndNotify(input, notificationService); - } - - @Override - public ListenableFuture> getFlowStatisticsFromFlowTable( - final GetFlowStatisticsFromFlowTableInput input) { - return flowsInTable.handleAndNotify(input, notificationService); - } -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractDirectStatisticsService.java index af5e68e613..c7b02a5ec8 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractDirectStatisticsService.java @@ -68,17 +68,12 @@ abstract class AbstractDirectStatisticsService> handleAndReply(final I input) { - final ListenableFuture>> rpcReply = handleServiceCall(input); - ListenableFuture> rpcResult = Futures.transform(rpcReply, - this::transformResult, - MoreExecutors.directExecutor()); - - if (Boolean.TRUE.equals(input.getStoreStats())) { - rpcResult = Futures.transform(rpcResult, this::storeResult, MoreExecutors.directExecutor()); - } + final ListenableFuture> handleAndReply(final I input) { + final var rpcResult = Futures.transform(handleServiceCall(input), this::transformResult, + MoreExecutors.directExecutor()); - return rpcResult; + return Boolean.TRUE.equals(input.getStoreStats()) + ? Futures.transform(rpcResult, this::storeResult, MoreExecutors.directExecutor()) : rpcResult; } private RpcResult transformResult(final RpcResult> input) { diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractFlowDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGetFlowStatistics.java similarity index 79% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractFlowDirectStatisticsService.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGetFlowStatistics.java index aa1bb6f3a1..574a545600 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractFlowDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGetFlowStatistics.java @@ -7,12 +7,14 @@ */ package org.opendaylight.openflowplugin.impl.statistics.services.direct; +import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey; import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatistics; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId; @@ -22,20 +24,25 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.f import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; +import org.opendaylight.yangtools.yang.common.RpcResult; /** * The Flow direct statistics service. */ -public abstract class AbstractFlowDirectStatisticsService - extends AbstractDirectStatisticsService { - - protected AbstractFlowDirectStatisticsService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { +public abstract class AbstractGetFlowStatistics + extends AbstractDirectStatisticsService + implements GetFlowStatistics { + protected AbstractGetFlowStatistics(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor, + final MultipartWriterProvider statisticsWriterProvider) { super(MultipartType.OFPMPFLOW, requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider); } + @Override + public final ListenableFuture> invoke(final GetFlowStatisticsInput input) { + return handleAndReply(input); + } + /** * Get flow ID from #{@link org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry} or * create alien ID. diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGroupDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGetGroupStatistics.java similarity index 57% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGroupDirectStatisticsService.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGetGroupStatistics.java index 08f753a46a..bc563a2385 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGroupDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGetGroupStatistics.java @@ -5,32 +5,35 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.openflowplugin.impl.statistics.services.direct; +import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetGroupStatistics; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetGroupStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetGroupStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; +import org.opendaylight.yangtools.yang.common.RpcResult; /** * The Group direct statistics service. */ -public abstract class AbstractGroupDirectStatisticsService - extends AbstractDirectStatisticsService { +public abstract class AbstractGetGroupStatistics + extends AbstractDirectStatisticsService + implements GetGroupStatistics { + protected AbstractGetGroupStatistics(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor, + final MultipartWriterProvider statisticsWriterProvider) { + super(MultipartType.OFPMPGROUP, requestContextStack, deviceContext, convertorExecutor, + statisticsWriterProvider); + } - protected AbstractGroupDirectStatisticsService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { - super(MultipartType.OFPMPGROUP, - requestContextStack, - deviceContext, - convertorExecutor, - statisticsWriterProvider); + @Override + public final ListenableFuture> invoke(final GetGroupStatisticsInput input) { + return handleAndReply(input); } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractMeterDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGetMeterStatistics.java similarity index 60% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractMeterDirectStatisticsService.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGetMeterStatistics.java index 4b94417cb9..5936a37681 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractMeterDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGetMeterStatistics.java @@ -5,30 +5,35 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.openflowplugin.impl.statistics.services.direct; +import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatistics; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; +import org.opendaylight.yangtools.yang.common.RpcResult; /** * The Meter direct statistics service. */ -public abstract class AbstractMeterDirectStatisticsService extends - AbstractDirectStatisticsService { - - public AbstractMeterDirectStatisticsService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { +public abstract class AbstractGetMeterStatistics + extends AbstractDirectStatisticsService + implements GetMeterStatistics { + protected AbstractGetMeterStatistics(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor, + final MultipartWriterProvider statisticsWriterProvider) { super(MultipartType.OFPMPMETER, requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider); } + @Override + public final ListenableFuture> invoke(final GetMeterStatisticsInput input) { + return handleAndReply(input); + } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractPortDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGetNodeConnectorStatistics.java similarity index 63% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractPortDirectStatisticsService.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGetNodeConnectorStatistics.java index 3b5dd725df..f7b0c397d4 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractPortDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGetNodeConnectorStatistics.java @@ -8,25 +8,27 @@ package org.opendaylight.openflowplugin.impl.statistics.services.direct; +import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatistics; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; +import org.opendaylight.yangtools.yang.common.RpcResult; /** * The Node connector direct statistics service. */ -public abstract class AbstractPortDirectStatisticsService - extends AbstractDirectStatisticsService { - - public AbstractPortDirectStatisticsService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { +public abstract class AbstractGetNodeConnectorStatistics + extends AbstractDirectStatisticsService + implements GetNodeConnectorStatistics { + protected AbstractGetNodeConnectorStatistics(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor, + final MultipartWriterProvider statisticsWriterProvider) { super(MultipartType.OFPMPPORTSTATS, requestContextStack, deviceContext, @@ -34,4 +36,9 @@ public abstract class AbstractPortDirectStatisticsService statisticsWriterProvider); } + @Override + public final ListenableFuture> invoke( + final GetNodeConnectorStatisticsInput input) { + return handleAndReply(input); + } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractQueueDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGetQueueStatistics.java similarity index 61% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractQueueDirectStatisticsService.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGetQueueStatistics.java index 67edb3eec6..561dcd6de7 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractQueueDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractGetQueueStatistics.java @@ -8,26 +8,33 @@ package org.opendaylight.openflowplugin.impl.statistics.services.direct; +import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetQueueStatistics; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetQueueStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetQueueStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; +import org.opendaylight.yangtools.yang.common.RpcResult; /** * The Queue direct statistics service. */ -public abstract class AbstractQueueDirectStatisticsService - extends AbstractDirectStatisticsService { - - public AbstractQueueDirectStatisticsService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { +public abstract class AbstractGetQueueStatistics + extends AbstractDirectStatisticsService + implements GetQueueStatistics { + protected AbstractGetQueueStatistics(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor, + final MultipartWriterProvider statisticsWriterProvider) { super(MultipartType.OFPMPQUEUE, requestContextStack, deviceContext, convertorExecutor, - statisticsWriterProvider); + statisticsWriterProvider); + } + + @Override + public final ListenableFuture> invoke(final GetQueueStatisticsInput input) { + return handleAndReply(input); } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/OpendaylightDirectStatisticsServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/OpendaylightDirectStatisticsServiceImpl.java deleted file mode 100644 index 5b4ef7879e..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/OpendaylightDirectStatisticsServiceImpl.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.openflowplugin.impl.statistics.services.direct; - -import com.google.common.util.concurrent.ListenableFuture; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetGroupStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetGroupStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetQueueStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetQueueStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.OpendaylightDirectStatisticsService; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.common.ErrorType; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.RpcResultBuilder; - -/** - * The Opendaylight direct statistics service. - * This service handles RPC requests, sends them to registered handlers and returns their replies. - */ -public class OpendaylightDirectStatisticsServiceImpl implements OpendaylightDirectStatisticsService { - private final OpendaylightDirectStatisticsServiceProvider provider; - - /** - * Instantiates a new Opendaylight direct statistics service. - * - * @param provider the openflow direct statistics service provider - */ - public OpendaylightDirectStatisticsServiceImpl(final OpendaylightDirectStatisticsServiceProvider provider) { - this.provider = provider; - } - - @Override - @SuppressWarnings("unchecked") - public ListenableFuture> getGroupStatistics(GetGroupStatisticsInput input) { - return provider.lookup(AbstractGroupDirectStatisticsService.class) - .map(service -> service.handleAndReply(input)) - .orElse(missingImplementation(AbstractGroupDirectStatisticsService.class)); - } - - @Override - @SuppressWarnings("unchecked") - public ListenableFuture> getQueueStatistics(GetQueueStatisticsInput input) { - return provider.lookup(AbstractQueueDirectStatisticsService.class) - .map(service -> service.handleAndReply(input)) - .orElse(missingImplementation(AbstractQueueDirectStatisticsService.class)); - } - - @Override - @SuppressWarnings("unchecked") - public ListenableFuture> getFlowStatistics(GetFlowStatisticsInput input) { - return provider.lookup(AbstractFlowDirectStatisticsService.class) - .map(service -> service.handleAndReply(input)) - .orElse(missingImplementation(AbstractFlowDirectStatisticsService.class)); - } - - @Override - @SuppressWarnings("unchecked") - public ListenableFuture> getMeterStatistics(GetMeterStatisticsInput input) { - return provider.lookup(AbstractMeterDirectStatisticsService.class) - .map(service -> service.handleAndReply(input)) - .orElse(missingImplementation(AbstractMeterDirectStatisticsService.class)); - } - - @Override - @SuppressWarnings("unchecked") - public ListenableFuture> - getNodeConnectorStatistics(GetNodeConnectorStatisticsInput input) { - return provider.lookup(AbstractPortDirectStatisticsService.class) - .map(service -> service.handleAndReply(input)) - .orElse(missingImplementation(AbstractPortDirectStatisticsService.class)); - } - - private static ListenableFuture> missingImplementation(Class service) { - return RpcResultBuilder.failed().withError( - ErrorType.APPLICATION, - String.format("No implementation found for direct statistics service %s.", service.getCanonicalName())) - .buildFuture(); - } -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/FlowDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiGetFlowStatistics.java similarity index 81% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/FlowDirectStatisticsService.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiGetFlowStatistics.java index 0d9f471e98..8e5fa4cec7 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/FlowDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiGetFlowStatistics.java @@ -17,7 +17,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.extension.api.path.MatchPath; import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; import org.opendaylight.openflowplugin.impl.services.util.RequestInputUtils; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractFlowDirectStatisticsService; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractGetFlowStatistics; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.FlowStatsResponseConvertorData; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchInjector; @@ -30,18 +30,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.f import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder; import org.opendaylight.yangtools.yang.common.Uint32; -public final class FlowDirectStatisticsService extends AbstractFlowDirectStatisticsService { +public final class MultiGetFlowStatistics extends AbstractGetFlowStatistics { private final FlowStatsResponseConvertorData data; - public FlowDirectStatisticsService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { + public MultiGetFlowStatistics(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor, final MultipartWriterProvider statisticsWriterProvider) { super(requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider); data = new FlowStatsResponseConvertorData(getVersion()); data.setDatapathId(getDatapathId()); @@ -50,21 +47,20 @@ public final class FlowDirectStatisticsService extends AbstractFlowDirectStatist @Override protected GetFlowStatisticsOutput buildReply(final List input, final boolean success) { - final List statsList = new ArrayList<>(); + final var statsList = new ArrayList(); if (success) { - for (final MultipartReply mpReply : input) { - final MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) mpReply.getMultipartReplyBody(); - final MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow(); + for (var mpReply : input) { + final var caseBody = (MultipartReplyFlowCase) mpReply.getMultipartReplyBody(); + final var replyBody = caseBody.getMultipartReplyFlow(); final Optional> statsListPart = getConvertorExecutor().convert( replyBody.getFlowStats(), data); statsListPart.ifPresent(flowAndStatisticsMapLists -> { - for (final FlowAndStatisticsMapList part : flowAndStatisticsMapLists) { - final FlowId flowId = new FlowId(generateFlowId(part).getValue()); + for (var part : flowAndStatisticsMapLists) { statsList.add(new FlowAndStatisticsMapListBuilder(part) - .setFlowId(flowId) - .build()); + .setFlowId(new FlowId(generateFlowId(part).getValue())) + .build()); } }); } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/GroupDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiGetGroupStatistics.java similarity index 79% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/GroupDirectStatisticsService.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiGetGroupStatistics.java index 3b25b34056..f1b8d5396c 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/GroupDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiGetGroupStatistics.java @@ -15,7 +15,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; import org.opendaylight.openflowplugin.impl.services.util.RequestInputUtils; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractGroupDirectStatisticsService; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractGetGroupStatistics; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetGroupStatisticsInput; @@ -27,18 +27,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.MultipartReplyGroup; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder; import org.opendaylight.yangtools.yang.binding.util.BindingMap; -public final class GroupDirectStatisticsService extends AbstractGroupDirectStatisticsService { +public final class MultiGetGroupStatistics extends AbstractGetGroupStatistics { private final VersionConvertorData data; - public GroupDirectStatisticsService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { + public MultiGetGroupStatistics(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor, final MultipartWriterProvider statisticsWriterProvider) { super(requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider); data = new VersionConvertorData(getVersion()); } @@ -50,9 +47,9 @@ public final class GroupDirectStatisticsService extends AbstractGroupDirectStati } final var groupStats = BindingMap.orderedBuilder(); - for (final MultipartReply mpReply : input) { - final MultipartReplyGroupCase caseBody = (MultipartReplyGroupCase) mpReply.getMultipartReplyBody(); - final MultipartReplyGroup replyBody = caseBody.getMultipartReplyGroup(); + for (var mpReply : input) { + final var caseBody = (MultipartReplyGroupCase) mpReply.getMultipartReplyBody(); + final var replyBody = caseBody.getMultipartReplyGroup(); final Optional> groupStatsList = getConvertorExecutor().convert( replyBody.getGroupStats(), data); @@ -66,7 +63,7 @@ public final class GroupDirectStatisticsService extends AbstractGroupDirectStati @Override protected OfHeader buildRequest(final Xid xid, final GetGroupStatisticsInput input) { - final MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder(); + final var mprGroupBuild = new MultipartRequestGroupBuilder(); if (input.getGroupId() != null) { mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue())); diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MeterDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiGetMeterStatistics.java similarity index 79% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MeterDirectStatisticsService.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiGetMeterStatistics.java index 0355afc508..9b0f037db2 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MeterDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiGetMeterStatistics.java @@ -15,7 +15,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; import org.opendaylight.openflowplugin.impl.services.util.RequestInputUtils; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractMeterDirectStatisticsService; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractGetMeterStatistics; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatisticsInput; @@ -27,19 +27,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeter; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder; import org.opendaylight.yangtools.yang.binding.util.BindingMap; -public class MeterDirectStatisticsService extends AbstractMeterDirectStatisticsService { - +public final class MultiGetMeterStatistics extends AbstractGetMeterStatistics { private final VersionConvertorData data; - public MeterDirectStatisticsService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { + public MultiGetMeterStatistics(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor, final MultipartWriterProvider statisticsWriterProvider) { super(requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider); data = new VersionConvertorData(getVersion()); } @@ -49,9 +45,9 @@ public class MeterDirectStatisticsService extends AbstractMeterDirectStatisticsS final var meterStats = BindingMap.orderedBuilder(); if (success) { - for (final MultipartReply mpReply : input) { - final MultipartReplyMeterCase caseBody = (MultipartReplyMeterCase) mpReply.getMultipartReplyBody(); - final MultipartReplyMeter replyBody = caseBody.getMultipartReplyMeter(); + for (var mpReply : input) { + final var caseBody = (MultipartReplyMeterCase) mpReply.getMultipartReplyBody(); + final var replyBody = caseBody.getMultipartReplyMeter(); final Optional> meterStatsList = getConvertorExecutor().convert(replyBody.getMeterStats(), data); meterStatsList.ifPresent(meterStats::addAll); @@ -65,7 +61,7 @@ public class MeterDirectStatisticsService extends AbstractMeterDirectStatisticsS @Override protected OfHeader buildRequest(final Xid xid, final GetMeterStatisticsInput input) { - final MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder(); + final var mprMeterBuild = new MultipartRequestMeterBuilder(); if (input.getMeterId() != null) { mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue())); diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/PortDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiGetNodeConnectorStatistics.java similarity index 81% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/PortDirectStatisticsService.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiGetNodeConnectorStatistics.java index 07f744df12..5d46d36f44 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/PortDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiGetNodeConnectorStatistics.java @@ -14,7 +14,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; import org.opendaylight.openflowplugin.impl.services.util.RequestInputUtils; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractPortDirectStatisticsService; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractGetNodeConnectorStatistics; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32; @@ -27,8 +27,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev1 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStats; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.multipart.reply.port.stats.PortStats; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap; @@ -36,12 +34,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.n import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMapKey; import org.opendaylight.yangtools.yang.binding.util.BindingMap; -public class PortDirectStatisticsService extends AbstractPortDirectStatisticsService { - - public PortDirectStatisticsService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { +public final class MultiGetNodeConnectorStatistics extends AbstractGetNodeConnectorStatistics { + public MultiGetNodeConnectorStatistics(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor, + final MultipartWriterProvider statisticsWriterProvider) { super(requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider); } @@ -53,13 +49,12 @@ public class PortDirectStatisticsService extends AbstractPortDirectStatisticsSer final var nodeConnectorStatisticsAndPortNumberMap = BindingMap.orderedBuilder(); - for (final MultipartReply mpReply : input) { - final MultipartReplyPortStatsCase caseBody = - (MultipartReplyPortStatsCase) mpReply.getMultipartReplyBody(); - final MultipartReplyPortStats replyBody = caseBody.getMultipartReplyPortStats(); + for (var mpReply : input) { + final var caseBody = (MultipartReplyPortStatsCase) mpReply.getMultipartReplyBody(); + final var replyBody = caseBody.getMultipartReplyPortStats(); - for (final PortStats portStats : replyBody.nonnullPortStats()) { - final DurationBuilder durationBuilder = new DurationBuilder(); + for (var portStats : replyBody.nonnullPortStats()) { + final var durationBuilder = new DurationBuilder(); if (portStats.getDurationSec() != null) { durationBuilder.setSecond(new Counter32(portStats.getDurationSec())); } @@ -97,7 +92,7 @@ public class PortDirectStatisticsService extends AbstractPortDirectStatisticsSer @Override protected OfHeader buildRequest(final Xid xid, final GetNodeConnectorStatisticsInput input) { - final MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder(); + final var mprPortStatsBuilder = new MultipartRequestPortStatsBuilder(); if (input.getNodeConnectorId() != null) { mprPortStatsBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(getOfVersion(), diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/QueueDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiGetQueueStatistics.java similarity index 68% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/QueueDirectStatisticsService.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiGetQueueStatistics.java index 9ca85adbb9..9c7057bd32 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/QueueDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiGetQueueStatistics.java @@ -15,7 +15,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; import org.opendaylight.openflowplugin.impl.services.util.RequestInputUtils; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractQueueDirectStatisticsService; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractGetQueueStatistics; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32; @@ -24,13 +24,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511 import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetQueueStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetQueueStatisticsOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.queue.rev130925.QueueId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.duration.DurationBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.MultipartReplyQueue; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.multipart.reply.queue.QueueStats; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.queue.id.and.statistics.map.QueueIdAndStatisticsMap; @@ -38,12 +35,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216. import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.queue.id.and.statistics.map.QueueIdAndStatisticsMapKey; import org.opendaylight.yangtools.yang.binding.util.BindingMap; -public class QueueDirectStatisticsService extends AbstractQueueDirectStatisticsService { - - public QueueDirectStatisticsService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { +public final class MultiGetQueueStatistics extends AbstractGetQueueStatistics { + public MultiGetQueueStatistics(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor, final MultipartWriterProvider statisticsWriterProvider) { super(requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider); } @@ -56,28 +50,23 @@ public class QueueDirectStatisticsService extends AbstractQueueDirectStatisticsS final var queueIdAndStatisticsMap = BindingMap.orderedBuilder(); - for (final MultipartReply mpReply : input) { - final MultipartReplyQueueCase caseBody = (MultipartReplyQueueCase) mpReply.getMultipartReplyBody(); - final MultipartReplyQueue replyBody = caseBody.getMultipartReplyQueue(); - - for (final QueueStats queueStats : replyBody.nonnullQueueStats()) { - final DurationBuilder durationBuilder = new DurationBuilder() - .setSecond(new Counter32(queueStats.getDurationSec())) - .setNanosecond(new Counter32(queueStats.getDurationNsec())); - - final QueueId queueId = new QueueId(queueStats.getQueueId()); - final NodeConnectorId nodeConnectorId = InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo( - getDatapathId(), queueStats.getPortNo(), getOfVersion()); + for (var mpReply : input) { + final var caseBody = (MultipartReplyQueueCase) mpReply.getMultipartReplyBody(); + final var replyBody = caseBody.getMultipartReplyQueue(); - final QueueIdAndStatisticsMapBuilder statsBuilder = new QueueIdAndStatisticsMapBuilder() - .setNodeConnectorId(nodeConnectorId) - .setQueueId(queueId) + for (var queueStats : replyBody.nonnullQueueStats()) { + queueIdAndStatisticsMap.add(new QueueIdAndStatisticsMapBuilder() + .setNodeConnectorId(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo( + getDatapathId(), queueStats.getPortNo(), getOfVersion())) + .setQueueId(new QueueId(queueStats.getQueueId())) .setTransmissionErrors(new Counter64(queueStats.getTxErrors())) .setTransmittedBytes(new Counter64(queueStats.getTxBytes())) .setTransmittedPackets(new Counter64(queueStats.getTxPackets())) - .setDuration(durationBuilder.build()); - - queueIdAndStatisticsMap.add(statsBuilder.build()); + .setDuration(new DurationBuilder() + .setSecond(new Counter32(queueStats.getDurationSec())) + .setNanosecond(new Counter32(queueStats.getDurationNsec())) + .build()) + .build()); } } @@ -88,8 +77,7 @@ public class QueueDirectStatisticsService extends AbstractQueueDirectStatisticsS @Override protected OfHeader buildRequest(final Xid xid, final GetQueueStatisticsInput input) { - final MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder(); - + final var mprQueueBuilder = new MultipartRequestQueueBuilder(); if (input.getQueueId() != null) { mprQueueBuilder.setQueueId(input.getQueueId().getValue()); } else { diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiLayerDirectStatisticsProviderInitializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiLayerDirectStatisticsProviderInitializer.java deleted file mode 100644 index b5e22d3492..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MultiLayerDirectStatisticsProviderInitializer.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.openflowplugin.impl.statistics.services.direct.multilayer; - -import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractFlowDirectStatisticsService; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractGroupDirectStatisticsService; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractMeterDirectStatisticsService; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractPortDirectStatisticsService; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractQueueDirectStatisticsService; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.OpendaylightDirectStatisticsServiceProvider; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; - -/** - * Utility class for instantiating - * #{@link org.opendaylight.openflowplugin.impl.statistics.services.direct.OpendaylightDirectStatisticsServiceProvider} - * with all multi-layer services already in. - */ -public final class MultiLayerDirectStatisticsProviderInitializer { - - private MultiLayerDirectStatisticsProviderInitializer() { - } - - public static OpendaylightDirectStatisticsServiceProvider createProvider( - final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { - - final OpendaylightDirectStatisticsServiceProvider provider = new OpendaylightDirectStatisticsServiceProvider(); - - provider.register(AbstractFlowDirectStatisticsService.class, new FlowDirectStatisticsService( - requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider)); - provider.register(AbstractGroupDirectStatisticsService.class, new GroupDirectStatisticsService( - requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider)); - provider.register(AbstractMeterDirectStatisticsService.class, new MeterDirectStatisticsService( - requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider)); - provider.register(AbstractPortDirectStatisticsService.class, new PortDirectStatisticsService( - requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider)); - provider.register(AbstractQueueDirectStatisticsService.class, new QueueDirectStatisticsService( - requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider)); - - return provider; - } -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/FlowDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleGetFlowStatistics.java similarity index 78% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/FlowDirectStatisticsService.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleGetFlowStatistics.java index 1b12b0b54b..e5b5ad3f87 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/FlowDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleGetFlowStatistics.java @@ -14,7 +14,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractFlowDirectStatisticsService; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractGetFlowStatistics; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput; @@ -28,29 +28,22 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.M import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequestBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; -public class FlowDirectStatisticsService extends AbstractFlowDirectStatisticsService { - - public FlowDirectStatisticsService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { +public final class SingleGetFlowStatistics extends AbstractGetFlowStatistics { + public SingleGetFlowStatistics(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor, final MultipartWriterProvider statisticsWriterProvider) { super(requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider); } @Override protected GetFlowStatisticsOutput buildReply(final List input, final boolean success) { return new GetFlowStatisticsOutputBuilder() - .setFlowAndStatisticsMapList(input - .stream() + .setFlowAndStatisticsMapList(input.stream() .flatMap(multipartReply -> ((MultipartReplyFlowStats) multipartReply.getMultipartReplyBody()) .nonnullFlowAndStatisticsMapList() .stream()) - .map(flowAndStatisticsMapList -> { - final FlowId flowId = new FlowId(generateFlowId(flowAndStatisticsMapList)); - return new FlowAndStatisticsMapListBuilder(flowAndStatisticsMapList) - .setFlowId(flowId) - .build(); - }) + .map(flowAndStatisticsMapList -> new FlowAndStatisticsMapListBuilder(flowAndStatisticsMapList) + .setFlowId(new FlowId(generateFlowId(flowAndStatisticsMapList))) + .build()) .collect(Collectors.toList())) .build(); } @@ -66,5 +59,4 @@ public class FlowDirectStatisticsService extends AbstractFlowDirectStatisticsSer .build()) .build(); } - } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/GroupDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleGetGroupStatistics.java similarity index 76% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/GroupDirectStatisticsService.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleGetGroupStatistics.java index fedf26f693..ced476cdb3 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/GroupDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleGetGroupStatistics.java @@ -12,7 +12,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractGroupDirectStatisticsService; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractGetGroupStatistics; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetGroupStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetGroupStatisticsOutput; @@ -24,24 +24,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.M import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yangtools.yang.binding.util.BindingMap; -public class GroupDirectStatisticsService extends AbstractGroupDirectStatisticsService { - - public GroupDirectStatisticsService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { +public final class SingleGetGroupStatistics extends AbstractGetGroupStatistics { + public SingleGetGroupStatistics(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor, final MultipartWriterProvider statisticsWriterProvider) { super(requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider); } @Override protected GetGroupStatisticsOutput buildReply(final List input, final boolean success) { - final var map = input.stream() - .flatMap(multipartReply -> ((MultipartReplyGroupStats) multipartReply.getMultipartReplyBody()) - .nonnullGroupStats().values().stream()) - .collect(BindingMap.toOrderedMap()); - return new GetGroupStatisticsOutputBuilder() - .setGroupStats(map) + .setGroupStats(input.stream() + .flatMap(multipartReply -> ((MultipartReplyGroupStats) multipartReply.getMultipartReplyBody()) + .nonnullGroupStats().values().stream()) + .collect(BindingMap.toOrderedMap())) .build(); } @@ -56,5 +51,4 @@ public class GroupDirectStatisticsService extends AbstractGroupDirectStatisticsS .build()) .build(); } - } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/MeterDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleGetMeterStatistics.java similarity index 77% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/MeterDirectStatisticsService.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleGetMeterStatistics.java index 2f9539d678..e5061c1452 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/MeterDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleGetMeterStatistics.java @@ -12,7 +12,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractMeterDirectStatisticsService; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractGetMeterStatistics; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatisticsOutput; @@ -24,24 +24,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.M import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yangtools.yang.binding.util.BindingMap; -public class MeterDirectStatisticsService extends AbstractMeterDirectStatisticsService { - - public MeterDirectStatisticsService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { +public final class SingleGetMeterStatistics extends AbstractGetMeterStatistics { + public SingleGetMeterStatistics(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor, final MultipartWriterProvider statisticsWriterProvider) { super(requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider); } @Override protected GetMeterStatisticsOutput buildReply(final List input, final boolean success) { - final var map = input.stream() - .flatMap(multipartReply -> ((MultipartReplyMeterStats) multipartReply.getMultipartReplyBody()) - .nonnullMeterStats().values().stream()) - .collect(BindingMap.toOrderedMap()); - return new GetMeterStatisticsOutputBuilder() - .setMeterStats(map) + .setMeterStats(input.stream() + .flatMap(multipartReply -> ((MultipartReplyMeterStats) multipartReply.getMultipartReplyBody()) + .nonnullMeterStats().values().stream()) + .collect(BindingMap.toOrderedMap())) .build(); } @@ -56,5 +51,4 @@ public class MeterDirectStatisticsService extends AbstractMeterDirectStatisticsS .build()) .build(); } - } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/PortDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleGetNodeConnectorStatistics.java similarity index 72% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/PortDirectStatisticsService.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleGetNodeConnectorStatistics.java index 092230311d..858aa6ee6e 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/PortDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleGetNodeConnectorStatistics.java @@ -12,7 +12,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractPortDirectStatisticsService; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractGetNodeConnectorStatistics; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsOutput; @@ -24,30 +24,25 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.m import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.multipart.request.multipart.request.body.MultipartRequestPortStatsBuilder; import org.opendaylight.yangtools.yang.binding.util.BindingMap; -public class PortDirectStatisticsService extends AbstractPortDirectStatisticsService { - - public PortDirectStatisticsService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { +public final class SingleGetNodeConnectorStatistics extends AbstractGetNodeConnectorStatistics { + public SingleGetNodeConnectorStatistics(final RequestContextStack requestContextStack, + final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor, + final MultipartWriterProvider statisticsWriterProvider) { super(requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider); } @Override protected GetNodeConnectorStatisticsOutput buildReply(final List input, final boolean success) { - final var map = input.stream() - .flatMap(multipartReply -> ((MultipartReplyPortStats) multipartReply.getMultipartReplyBody()) - .nonnullNodeConnectorStatisticsAndPortNumberMap().values().stream()) - .collect(BindingMap.toOrderedMap()); - return new GetNodeConnectorStatisticsOutputBuilder() - .setNodeConnectorStatisticsAndPortNumberMap(map) + .setNodeConnectorStatisticsAndPortNumberMap(input.stream() + .flatMap(multipartReply -> ((MultipartReplyPortStats) multipartReply.getMultipartReplyBody()) + .nonnullNodeConnectorStatisticsAndPortNumberMap().values().stream()) + .collect(BindingMap.toOrderedMap())) .build(); } @Override - protected OfHeader buildRequest(final Xid xid, - final GetNodeConnectorStatisticsInput input) { + protected OfHeader buildRequest(final Xid xid, final GetNodeConnectorStatisticsInput input) { return new MultipartRequestBuilder() .setXid(xid.getValue()) .setVersion(getVersion()) @@ -57,5 +52,4 @@ public class PortDirectStatisticsService extends AbstractPortDirectStatisticsSer .build()) .build(); } - } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/QueueDirectStatisticsService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleGetQueueStatistics.java similarity index 76% rename from openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/QueueDirectStatisticsService.java rename to openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleGetQueueStatistics.java index 3be717b393..5a954e2d7a 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/QueueDirectStatisticsService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleGetQueueStatistics.java @@ -12,7 +12,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractQueueDirectStatisticsService; +import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractGetQueueStatistics; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetQueueStatisticsInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetQueueStatisticsOutput; @@ -24,24 +24,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216. import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.multipart.request.multipart.request.body.MultipartRequestQueueStatsBuilder; import org.opendaylight.yangtools.yang.binding.util.BindingMap; -public class QueueDirectStatisticsService extends AbstractQueueDirectStatisticsService { - public QueueDirectStatisticsService(final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { +public final class SingleGetQueueStatistics extends AbstractGetQueueStatistics { + public SingleGetQueueStatistics(final RequestContextStack requestContextStack, final DeviceContext deviceContext, + final ConvertorExecutor convertorExecutor, final MultipartWriterProvider statisticsWriterProvider) { super(requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider); } @Override protected GetQueueStatisticsOutput buildReply(final List input, final boolean success) { - final var map = input.stream() - .flatMap(multipartReply -> ((MultipartReplyQueueStats) multipartReply.getMultipartReplyBody()) - .nonnullQueueIdAndStatisticsMap().values() - .stream()) - .collect(BindingMap.toOrderedMap()); - return new GetQueueStatisticsOutputBuilder() - .setQueueIdAndStatisticsMap(map) + .setQueueIdAndStatisticsMap(input.stream() + .flatMap(multipartReply -> ((MultipartReplyQueueStats) multipartReply.getMultipartReplyBody()) + .nonnullQueueIdAndStatisticsMap().values() + .stream()) + .collect(BindingMap.toOrderedMap())) .build(); } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleLayerDirectStatisticsProviderInitializer.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleLayerDirectStatisticsProviderInitializer.java deleted file mode 100644 index 5bee4bc170..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/SingleLayerDirectStatisticsProviderInitializer.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.openflowplugin.impl.statistics.services.direct.singlelayer; - -import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; -import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; -import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractFlowDirectStatisticsService; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractGroupDirectStatisticsService; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractMeterDirectStatisticsService; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractPortDirectStatisticsService; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.AbstractQueueDirectStatisticsService; -import org.opendaylight.openflowplugin.impl.statistics.services.direct.OpendaylightDirectStatisticsServiceProvider; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; - -/** - * Utility class for instantiating - * #{@link org.opendaylight.openflowplugin.impl.statistics.services.direct.OpendaylightDirectStatisticsServiceProvider} - * with all multi-layer services already in. - */ -public final class SingleLayerDirectStatisticsProviderInitializer { - - private SingleLayerDirectStatisticsProviderInitializer() { - } - - public static OpendaylightDirectStatisticsServiceProvider createProvider( - final RequestContextStack requestContextStack, - final DeviceContext deviceContext, - final ConvertorExecutor convertorExecutor, - final MultipartWriterProvider statisticsWriterProvider) { - - final OpendaylightDirectStatisticsServiceProvider provider = new OpendaylightDirectStatisticsServiceProvider(); - - provider.register(AbstractFlowDirectStatisticsService.class, new FlowDirectStatisticsService( - requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider)); - provider.register(AbstractGroupDirectStatisticsService.class, new GroupDirectStatisticsService( - requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider)); - provider.register(AbstractMeterDirectStatisticsService.class, new MeterDirectStatisticsService( - requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider)); - provider.register(AbstractPortDirectStatisticsService.class, new PortDirectStatisticsService( - requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider)); - provider.register(AbstractQueueDirectStatisticsService.class, new QueueDirectStatisticsService( - requestContextStack, deviceContext, convertorExecutor, statisticsWriterProvider)); - - return provider; - } - -} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/BarrierUtil.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/BarrierUtil.java index 4f580bd5fb..62c14b9190 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/BarrierUtil.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/BarrierUtil.java @@ -7,6 +7,7 @@ */ package org.opendaylight.openflowplugin.impl.util; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; @@ -14,6 +15,7 @@ import com.google.common.util.concurrent.MoreExecutors; import org.apache.commons.lang3.tuple.MutablePair; import org.apache.commons.lang3.tuple.Pair; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierOutput; @@ -35,30 +37,25 @@ public final class BarrierUtil { * @param type of input future * @param input future to chain barrier to * @param nodeRef target device - * @param transactionService barrier service + * @param sendBarrier barrier service * @param compositeTransform composite transform * @return future holding both results (input and of the barrier) */ - public static ListenableFuture> chainBarrier( - final ListenableFuture> input, final NodeRef nodeRef, - final FlowCapableTransactionService transactionService, + public static ListenableFuture> chainBarrier(final ListenableFuture> input, + final NodeRef nodeRef, final SendBarrier sendBarrier, final Function, RpcResult>, RpcResult> compositeTransform) { - final MutablePair, RpcResult> resultPair = new MutablePair<>(); + final var resultPair = new MutablePair, RpcResult>(); // store input result and append barrier - final ListenableFuture> barrierResult = Futures.transformAsync(input, - interInput -> { - resultPair.setLeft(interInput); - final SendBarrierInput barrierInput = createSendBarrierInput(nodeRef); - return transactionService.sendBarrier(barrierInput); - }, MoreExecutors.directExecutor()); + final var barrierResult = Futures.transformAsync(input, interInput -> { + resultPair.setLeft(interInput); + return sendBarrier.invoke(createSendBarrierInput(nodeRef)); + }, MoreExecutors.directExecutor()); // store barrier result and return initiated pair - final ListenableFuture, RpcResult>> compositeResult = Futures.transform( - barrierResult, - input1 -> { - resultPair.setRight(input1); - return resultPair; - }, MoreExecutors.directExecutor()); + final var compositeResult = Futures.transform(barrierResult, input1 -> { + resultPair.setRight(input1); + return resultPair; + }, MoreExecutors.directExecutor()); // append assembling transform to barrier result return Futures.transform(compositeResult, compositeTransform, MoreExecutors.directExecutor()); } @@ -69,9 +66,8 @@ public final class BarrierUtil { * @param nodeRef rpc routing context * @return input for {@link FlowCapableTransactionService#sendBarrier(SendBarrierInput)} */ - public static SendBarrierInput createSendBarrierInput(final NodeRef nodeRef) { - return new SendBarrierInputBuilder() - .setNode(nodeRef) - .build(); + @VisibleForTesting + static SendBarrierInput createSendBarrierInput(final NodeRef nodeRef) { + return new SendBarrierInputBuilder().setNode(nodeRef).build(); } } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImplTest.java index 23ed67ac0c..ae5d8f54cb 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImplTest.java @@ -7,18 +7,21 @@ */ package org.opendaylight.openflowplugin.impl.rpc; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import com.google.common.collect.ClassToInstanceMap; import java.util.Set; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.opendaylight.mdsal.binding.api.NotificationPublishService; @@ -37,6 +40,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.N import org.opendaylight.yangtools.concepts.ObjectRegistration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.Rpc; import org.opendaylight.yangtools.yang.binding.RpcService; import org.opendaylight.yangtools.yang.common.Uint32; import org.opendaylight.yangtools.yang.common.Uint8; @@ -63,6 +67,8 @@ public class RpcContextImplTest { private ExtensionConverterProvider extensionConverterProvider; @Mock private ConvertorExecutor convertorExecutor; + @Captor + private ArgumentCaptor>> captor; private KeyedInstanceIdentifier nodeInstanceIdentifier; private RpcContextImpl rpcContext; @@ -153,12 +159,14 @@ public class RpcContextImplTest { @Test public void testInstantiateServiceInstance() { - when(rpcProviderRegistry.registerRpcImplementation(any(), any(RpcService.class), + when(rpcProviderRegistry.registerRpcImplementations(any(), eq(Set.of(nodeInstanceIdentifier)))).thenReturn(registration); rpcContext.instantiateServiceInstance(); - verify(rpcProviderRegistry, times(21)).registerRpcImplementation(any(), any(RpcService.class), - eq(Set.of(nodeInstanceIdentifier))); + verify(rpcProviderRegistry).registerRpcImplementations(captor.capture(), eq(Set.of(nodeInstanceIdentifier))); + + final var map = captor.getValue(); + assertEquals(46, map.size()); } } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/EchoServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SendEchoImplTest.java similarity index 84% rename from openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/EchoServiceTest.java rename to openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SendEchoImplTest.java index 6eaec2b7be..c823e4b9f7 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/EchoServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SendEchoImplTest.java @@ -20,28 +20,28 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yangtools.yang.common.Uint32; -public class EchoServiceTest extends ServiceMocking { - +public class SendEchoImplTest extends ServiceMocking { private static final Uint32 DUMMY_XID_VALUE = Uint32.valueOf(100); private static final byte[] DUMMY_DATA = "DUMMY DATA".getBytes(); - EchoService echoService; + + private SendEchoImpl sendEcho; @Override public void setup() { - echoService = new EchoService(mockedRequestContextStack, mockedDeviceContext); + sendEcho = new SendEchoImpl(mockedRequestContextStack, mockedDeviceContext); } @Test public void testSendEcho() { EchoInputBuilder sendEchoInput = new EchoInputBuilder(); - echoService.handleServiceCall(sendEchoInput); + sendEcho.handleServiceCall(sendEchoInput); verify(mockedRequestContextStack).createRequestContext(); } @Test public void testBuildRequest() { EchoInputBuilder sendEchoInput = new EchoInputBuilder().setData(DUMMY_DATA); - final OfHeader request = this.echoService.buildRequest(new Xid(DUMMY_XID_VALUE), sendEchoInput); + final OfHeader request = sendEcho.buildRequest(new Xid(DUMMY_XID_VALUE), sendEchoInput); assertEquals(DUMMY_XID_VALUE, request.getXid()); assertTrue(request instanceof EchoInput); final byte[] data = ((EchoInput) request).getData(); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlatBatchServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/ProcessFlatBatchImplTest.java similarity index 74% rename from openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlatBatchServiceImplTest.java rename to openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/ProcessFlatBatchImplTest.java index 64bf758e65..54074092a4 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlatBatchServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/ProcessFlatBatchImplTest.java @@ -7,6 +7,17 @@ */ package org.opendaylight.openflowplugin.impl.services.sal; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.inOrder; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + import com.google.common.collect.Lists; import com.google.common.util.concurrent.AsyncFunction; import com.google.common.util.concurrent.ListenableFuture; @@ -14,18 +25,13 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.Future; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; -import org.mockito.ArgumentMatchers; import org.mockito.Captor; -import org.mockito.InOrder; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep; import org.opendaylight.openflowplugin.impl.services.batch.BatchStepJob; @@ -63,18 +69,22 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev16032 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.output.BatchFailure; import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.output.BatchFailureBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatch; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatch; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.SalFlowsBatchService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatch; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.batch.flow.output.list.grouping.BatchFailedFlowsOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatch; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatch; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.SalGroupsBatchService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatch; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.batch.group.input.update.grouping.OriginalBatchedGroupBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.batch.group.input.update.grouping.UpdatedBatchedGroupBuilder; @@ -84,9 +94,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatch; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatch; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.SalMetersBatchService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatch; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.batch.meter.input.update.grouping.OriginalBatchedMeterBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.batch.meter.input.update.grouping.UpdatedBatchedMeterBuilder; @@ -102,57 +114,68 @@ import org.opendaylight.yangtools.yang.common.Uint32; * Test for {@link org.opendaylight.openflowplugin.impl.services.sal.SalFlatBatchServiceImpl}. */ @RunWith(MockitoJUnitRunner.class) -public class SalFlatBatchServiceImplTest { - +public class ProcessFlatBatchImplTest { private static final NodeId NODE_ID = new NodeId("ut-node-id"); private static final InstanceIdentifier NODE_II = InstanceIdentifier.create(Nodes.class) .child(Node.class, new NodeKey(NODE_ID)); private static final NodeRef NODE_REF = new NodeRef(NODE_II); @Mock - private SalFlowsBatchService salFlowsBatchService; + private AddFlowsBatch addFlowsBatch; + @Mock + private RemoveFlowsBatch removeFlowsBatch; + @Mock + private UpdateFlowsBatch updateFlowsBatch; + @Mock + private AddGroupsBatch addGroupsBatch; + @Mock + private RemoveGroupsBatch removeGroupsBatch; + @Mock + private UpdateGroupsBatch updateGroupsBatch; @Mock - private SalGroupsBatchService salGroupsBatchService; + private AddMetersBatch addMetersBatch; @Mock - private SalMetersBatchService salMetersBatchService; + private RemoveMetersBatch removeMetersBatch; + @Mock + private UpdateMetersBatch updateMetersBatch; @Captor private ArgumentCaptor addFlowsBatchInputCpt; - private SalFlatBatchServiceImpl salFlatBatchService; + private ProcessFlatBatchImpl processFlatBatch; @Before public void setUp() { - salFlatBatchService = - new SalFlatBatchServiceImpl(salFlowsBatchService, salGroupsBatchService, salMetersBatchService); - + processFlatBatch = new ProcessFlatBatchImpl(addFlowsBatch, removeFlowsBatch, updateFlowsBatch, addGroupsBatch, + removeGroupsBatch, updateGroupsBatch, addMetersBatch, removeMetersBatch, updateMetersBatch); } @After public void tearDown() { - Mockito.verifyNoMoreInteractions(salFlowsBatchService, salGroupsBatchService, salMetersBatchService); + verifyNoMoreInteractions(addFlowsBatch, removeFlowsBatch, updateFlowsBatch, addGroupsBatch, + removeGroupsBatch, updateGroupsBatch, addMetersBatch, removeMetersBatch, updateMetersBatch); } @Test public void testProcessFlatBatch_allSuccessFinished() throws Exception { - Mockito.when(salFlowsBatchService.addFlowsBatch(ArgumentMatchers.any())) + when(addFlowsBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new AddFlowsBatchOutputBuilder().build()).buildFuture()); - Mockito.when(salFlowsBatchService.removeFlowsBatch(ArgumentMatchers.any())) + when(removeFlowsBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new RemoveFlowsBatchOutputBuilder().build()).buildFuture()); - Mockito.when(salFlowsBatchService.updateFlowsBatch(ArgumentMatchers.any())) + when(updateFlowsBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new UpdateFlowsBatchOutputBuilder().build()).buildFuture()); - Mockito.when(salGroupsBatchService.addGroupsBatch(ArgumentMatchers.any())) + when(addGroupsBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new AddGroupsBatchOutputBuilder().build()).buildFuture()); - Mockito.when(salGroupsBatchService.removeGroupsBatch(ArgumentMatchers.any())) + when(removeGroupsBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new RemoveGroupsBatchOutputBuilder().build()).buildFuture()); - Mockito.when(salGroupsBatchService.updateGroupsBatch(ArgumentMatchers.any())) + when(updateGroupsBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new UpdateGroupsBatchOutputBuilder().build()).buildFuture()); - Mockito.when(salMetersBatchService.addMetersBatch(ArgumentMatchers.any())) + when(addMetersBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new AddMetersBatchOutputBuilder().build()).buildFuture()); - Mockito.when(salMetersBatchService.removeMetersBatch(ArgumentMatchers.any())) + when(removeMetersBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new RemoveMetersBatchOutputBuilder().build()).buildFuture()); - Mockito.when(salMetersBatchService.updateMetersBatch(ArgumentMatchers.any())) + when(updateMetersBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new UpdateMetersBatchOutputBuilder().build()).buildFuture()); @@ -174,26 +197,26 @@ public class SalFlatBatchServiceImplTest { .setExitOnFirstError(true) .build(); - final Future> rpcResultFuture = - salFlatBatchService.processFlatBatch(batchInput); - Assert.assertTrue(rpcResultFuture.isDone()); - final RpcResult rpcResult = rpcResultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - Assert.assertTrue(rpcResult.getErrors().isEmpty()); - Assert.assertTrue(rpcResult.getResult().nonnullBatchFailure().isEmpty()); - - final InOrder inOrder = Mockito.inOrder(salFlowsBatchService, salGroupsBatchService, salMetersBatchService); - inOrder.verify(salFlowsBatchService).addFlowsBatch(ArgumentMatchers.any()); - inOrder.verify(salFlowsBatchService).removeFlowsBatch(ArgumentMatchers.any()); - inOrder.verify(salFlowsBatchService).updateFlowsBatch(ArgumentMatchers.any()); - - inOrder.verify(salGroupsBatchService).addGroupsBatch(ArgumentMatchers.any()); - inOrder.verify(salGroupsBatchService).removeGroupsBatch(ArgumentMatchers.any()); - inOrder.verify(salGroupsBatchService).updateGroupsBatch(ArgumentMatchers.any()); - - inOrder.verify(salMetersBatchService).addMetersBatch(ArgumentMatchers.any()); - inOrder.verify(salMetersBatchService).removeMetersBatch(ArgumentMatchers.any()); - inOrder.verify(salMetersBatchService).updateMetersBatch(ArgumentMatchers.any()); + final var rpcResultFuture = processFlatBatch.invoke(batchInput); + assertTrue(rpcResultFuture.isDone()); + final var rpcResult = rpcResultFuture.get(); + assertTrue(rpcResult.isSuccessful()); + assertTrue(rpcResult.getErrors().isEmpty()); + assertTrue(rpcResult.getResult().nonnullBatchFailure().isEmpty()); + + final var inOrder = inOrder(addFlowsBatch, removeFlowsBatch, updateFlowsBatch, addGroupsBatch, + removeGroupsBatch, updateGroupsBatch, addMetersBatch, removeMetersBatch, updateMetersBatch); + inOrder.verify(addFlowsBatch).invoke(any()); + inOrder.verify(removeFlowsBatch).invoke(any()); + inOrder.verify(updateFlowsBatch).invoke(any()); + + inOrder.verify(addGroupsBatch).invoke(any()); + inOrder.verify(removeGroupsBatch).invoke(any()); + inOrder.verify(updateGroupsBatch).invoke(any()); + + inOrder.verify(addMetersBatch).invoke(any()); + inOrder.verify(removeMetersBatch).invoke(any()); + inOrder.verify(updateMetersBatch).invoke(any()); } @Test @@ -219,21 +242,20 @@ public class SalFlatBatchServiceImplTest { .setExitOnFirstError(true) .build(); - final Future> rpcResultFuture = - salFlatBatchService.processFlatBatch(batchInput); - Assert.assertTrue(rpcResultFuture.isDone()); - final RpcResult rpcResult = rpcResultFuture.get(); - Assert.assertFalse(rpcResult.isSuccessful()); - Assert.assertEquals(1, rpcResult.getErrors().size()); - Assert.assertEquals(1, rpcResult.getResult().nonnullBatchFailure().size()); - Assert.assertEquals(3, rpcResult.getResult().nonnullBatchFailure().values().iterator().next() + final var rpcResultFuture = processFlatBatch.invoke(batchInput); + assertTrue(rpcResultFuture.isDone()); + final var rpcResult = rpcResultFuture.get(); + assertFalse(rpcResult.isSuccessful()); + assertEquals(1, rpcResult.getErrors().size()); + assertEquals(1, rpcResult.getResult().nonnullBatchFailure().size()); + assertEquals(3, rpcResult.getResult().nonnullBatchFailure().values().iterator().next() .getBatchOrder().intValue()); - final InOrder inOrder = Mockito.inOrder(salFlowsBatchService, salGroupsBatchService, salMetersBatchService); - inOrder.verify(salFlowsBatchService).addFlowsBatch(ArgumentMatchers.any()); - inOrder.verify(salFlowsBatchService).removeFlowsBatch(ArgumentMatchers.any()); - inOrder.verify(salFlowsBatchService).updateFlowsBatch(ArgumentMatchers.any()); - inOrder.verify(salGroupsBatchService).addGroupsBatch(ArgumentMatchers.any()); + final var inOrder = inOrder(addFlowsBatch, removeFlowsBatch, updateFlowsBatch, addGroupsBatch); + inOrder.verify(addFlowsBatch).invoke(any()); + inOrder.verify(removeFlowsBatch).invoke(any()); + inOrder.verify(updateFlowsBatch).invoke(any()); + inOrder.verify(addGroupsBatch).invoke(any()); } @Test @@ -259,34 +281,34 @@ public class SalFlatBatchServiceImplTest { .setExitOnFirstError(false) .build(); - final Future> rpcResultFuture = - salFlatBatchService.processFlatBatch(batchInput); - Assert.assertTrue(rpcResultFuture.isDone()); + final var rpcResultFuture = processFlatBatch.invoke(batchInput); + assertTrue(rpcResultFuture.isDone()); final RpcResult rpcResult = rpcResultFuture.get(); - Assert.assertFalse(rpcResult.isSuccessful()); - Assert.assertEquals(1, rpcResult.getErrors().size()); - Assert.assertEquals(1, rpcResult.getResult().nonnullBatchFailure().size()); - Assert.assertEquals(3, rpcResult.getResult().nonnullBatchFailure().values().iterator().next() + assertFalse(rpcResult.isSuccessful()); + assertEquals(1, rpcResult.getErrors().size()); + assertEquals(1, rpcResult.getResult().nonnullBatchFailure().size()); + assertEquals(3, rpcResult.getResult().nonnullBatchFailure().values().iterator().next() .getBatchOrder().intValue()); - final InOrder inOrder = Mockito.inOrder(salFlowsBatchService, salGroupsBatchService, salMetersBatchService); - inOrder.verify(salFlowsBatchService).addFlowsBatch(ArgumentMatchers.any()); - inOrder.verify(salFlowsBatchService).removeFlowsBatch(ArgumentMatchers.any()); - inOrder.verify(salFlowsBatchService).updateFlowsBatch(ArgumentMatchers.any()); + final var inOrder = inOrder(addFlowsBatch, removeFlowsBatch, updateFlowsBatch, addGroupsBatch, + removeGroupsBatch, updateGroupsBatch, addMetersBatch, removeMetersBatch, updateMetersBatch); + inOrder.verify(addFlowsBatch).invoke(any()); + inOrder.verify(removeFlowsBatch).invoke(any()); + inOrder.verify(updateFlowsBatch).invoke(any()); - inOrder.verify(salGroupsBatchService).addGroupsBatch(ArgumentMatchers.any()); - inOrder.verify(salGroupsBatchService).removeGroupsBatch(ArgumentMatchers.any()); - inOrder.verify(salGroupsBatchService).updateGroupsBatch(ArgumentMatchers.any()); + inOrder.verify(addGroupsBatch).invoke(any()); + inOrder.verify(removeGroupsBatch).invoke(any()); + inOrder.verify(updateGroupsBatch).invoke(any()); - inOrder.verify(salMetersBatchService).addMetersBatch(ArgumentMatchers.any()); - inOrder.verify(salMetersBatchService).removeMetersBatch(ArgumentMatchers.any()); - inOrder.verify(salMetersBatchService).updateMetersBatch(ArgumentMatchers.any()); + inOrder.verify(addMetersBatch).invoke(any()); + inOrder.verify(removeMetersBatch).invoke(any()); + inOrder.verify(updateMetersBatch).invoke(any()); } private void prepareFirstFailingMockService() { - Mockito.when(salFlowsBatchService.addFlowsBatch(ArgumentMatchers.any())) + when(addFlowsBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new AddFlowsBatchOutputBuilder().build()).buildFuture()); - Mockito.when(salFlowsBatchService.removeFlowsBatch(ArgumentMatchers.any())) + when(removeFlowsBatch.invoke(any())) .thenReturn(RpcResultBuilder.failed() .withResult(new RemoveFlowsBatchOutputBuilder() .setBatchFailedFlowsOutput(BindingMap.ordered( @@ -297,21 +319,21 @@ public class SalFlatBatchServiceImplTest { .build()) .withError(ErrorType.APPLICATION, "ut-firstFlowAddError") .buildFuture()); - Mockito.when(salFlowsBatchService.updateFlowsBatch(ArgumentMatchers.any())) + when(updateFlowsBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new UpdateFlowsBatchOutputBuilder().build()).buildFuture()); - Mockito.when(salGroupsBatchService.addGroupsBatch(ArgumentMatchers.any())) + when(addGroupsBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new AddGroupsBatchOutputBuilder().build()).buildFuture()); - Mockito.when(salGroupsBatchService.removeGroupsBatch(ArgumentMatchers.any())) + when(removeGroupsBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new RemoveGroupsBatchOutputBuilder().build()).buildFuture()); - Mockito.when(salGroupsBatchService.updateGroupsBatch(ArgumentMatchers.any())) + when(updateGroupsBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new UpdateGroupsBatchOutputBuilder().build()).buildFuture()); - Mockito.when(salMetersBatchService.addMetersBatch(ArgumentMatchers.any())) + when(addMetersBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new AddMetersBatchOutputBuilder().build()).buildFuture()); - Mockito.when(salMetersBatchService.removeMetersBatch(ArgumentMatchers.any())) + when(removeMetersBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new RemoveMetersBatchOutputBuilder().build()).buildFuture()); - Mockito.when(salMetersBatchService.updateMetersBatch(ArgumentMatchers.any())) + when(updateMetersBatch.invoke(any())) .thenReturn(RpcResultBuilder.success(new UpdateMetersBatchOutputBuilder().build()).buildFuture()); } @@ -448,20 +470,20 @@ public class SalFlatBatchServiceImplTest { @Test public void testExecuteBatchPlan() throws Exception { - BatchStepJob batchStepJob1 = Mockito.mock(BatchStepJob.class); - BatchStepJob batchStepJob2 = Mockito.mock(BatchStepJob.class); + BatchStepJob batchStepJob1 = mock(BatchStepJob.class); + BatchStepJob batchStepJob2 = mock(BatchStepJob.class); AsyncFunction, RpcResult> function1 = - Mockito.mock(AsyncFunction.class); + mock(AsyncFunction.class); AsyncFunction, RpcResult> function2 = - Mockito.mock(AsyncFunction.class); - Mockito.when(batchStepJob1.getStepFunction()).thenReturn(function1); - Mockito.when(batchStepJob2.getStepFunction()).thenReturn(function2); + mock(AsyncFunction.class); + when(batchStepJob1.getStepFunction()).thenReturn(function1); + when(batchStepJob2.getStepFunction()).thenReturn(function2); BatchPlanStep batchPlanStep1 = new BatchPlanStep(BatchStepType.GROUP_ADD); batchPlanStep1.setBarrierAfter(true); BatchPlanStep batchPlanStep2 = new BatchPlanStep(BatchStepType.FLOW_ADD); batchPlanStep1.setBarrierAfter(false); - Mockito.when(batchStepJob1.getPlanStep()).thenReturn(batchPlanStep1); - Mockito.when(batchStepJob2.getPlanStep()).thenReturn(batchPlanStep2); + when(batchStepJob1.getPlanStep()).thenReturn(batchPlanStep1); + when(batchStepJob2.getPlanStep()).thenReturn(batchPlanStep2); final ListenableFuture> succeededChainOutput = FlatBatchUtil.createEmptyRpcBatchResultFuture(true); @@ -472,24 +494,21 @@ public class SalFlatBatchServiceImplTest { createFlowBatchFailure(Uint16.ONE, "f2"))) .buildFuture(); - Mockito.when(batchStepJob1.getStepFunction().apply(ArgumentMatchers.any())) - .thenReturn(succeededChainOutput); - Mockito.when(batchStepJob2.getStepFunction().apply(ArgumentMatchers.any())) - .thenReturn(failedChainOutput); + when(batchStepJob1.getStepFunction().apply(any())).thenReturn(succeededChainOutput); + when(batchStepJob2.getStepFunction().apply(any())).thenReturn(failedChainOutput); final List batchChainElements = Lists.newArrayList(batchStepJob1, batchStepJob2); - final Future> rpcResultFuture = - salFlatBatchService.executeBatchPlan(batchChainElements); + final var rpcResultFuture = processFlatBatch.executeBatchPlan(batchChainElements); - Assert.assertTrue(rpcResultFuture.isDone()); - final RpcResult rpcResult = rpcResultFuture.get(); - Assert.assertFalse(rpcResult.isSuccessful()); - Assert.assertEquals(1, rpcResult.getErrors().size()); - Assert.assertEquals(2, rpcResult.getResult().nonnullBatchFailure().size()); + assertTrue(rpcResultFuture.isDone()); + final var rpcResult = rpcResultFuture.get(); + assertFalse(rpcResult.isSuccessful()); + assertEquals(1, rpcResult.getErrors().size()); + assertEquals(2, rpcResult.getResult().nonnullBatchFailure().size()); Iterator iterator = rpcResult.getResult().nonnullBatchFailure().values().iterator(); //Moving iterator two get second element iterator.next(); - Assert.assertEquals("f2", + assertEquals("f2", ((FlatBatchFailureFlowIdCase) iterator.next().getBatchItemIdChoice()) .getFlowId().getValue()); } @@ -523,24 +542,23 @@ public class SalFlatBatchServiceImplTest { batchPlanStep.getTaskBag().addAll(Lists.newArrayList(flatBatchAddFlow_1, flatBatchAddFlow_2)); final List batchPlan = Lists.newArrayList(batchPlanStep); - final List batchChain = salFlatBatchService.prepareBatchChain(batchPlan, NODE_REF, true); + final List batchChain = processFlatBatch.prepareBatchChain(batchPlan, NODE_REF, true); - Assert.assertEquals(1, batchChain.size()); + assertEquals(1, batchChain.size()); - Mockito.when(salFlowsBatchService.addFlowsBatch(ArgumentMatchers.any())) + when(addFlowsBatch.invoke(any())) .thenReturn(RpcResultBuilder .success(new AddFlowsBatchOutputBuilder().build()) .buildFuture()); - final Future> rpcResultFuture = - salFlatBatchService.executeBatchPlan(batchChain); - Assert.assertTrue(rpcResultFuture.isDone()); - final RpcResult rpcResult = rpcResultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - Assert.assertEquals(0, rpcResult.getErrors().size()); - Assert.assertEquals(0, rpcResult.getResult().nonnullBatchFailure().size()); + final var rpcResultFuture = processFlatBatch.executeBatchPlan(batchChain); + assertTrue(rpcResultFuture.isDone()); + final var rpcResult = rpcResultFuture.get(); + assertTrue(rpcResult.isSuccessful()); + assertEquals(0, rpcResult.getErrors().size()); + assertEquals(0, rpcResult.getResult().nonnullBatchFailure().size()); - Mockito.verify(salFlowsBatchService).addFlowsBatch(ArgumentMatchers.any()); + verify(addFlowsBatch).invoke(any()); } @Test @@ -558,11 +576,11 @@ public class SalFlatBatchServiceImplTest { final List batchPlan = Lists.newArrayList(batchPlanStep, batchPlanStep); - final List batchChain = salFlatBatchService.prepareBatchChain(batchPlan, NODE_REF, true); + final List batchChain = processFlatBatch.prepareBatchChain(batchPlan, NODE_REF, true); - Assert.assertEquals(2, batchChain.size()); + assertEquals(2, batchChain.size()); - Mockito.when(salFlowsBatchService.addFlowsBatch(ArgumentMatchers.any())) + when(addFlowsBatch.invoke(any())) .thenReturn(RpcResultBuilder .failed() .withResult(new AddFlowsBatchOutputBuilder() @@ -579,15 +597,14 @@ public class SalFlatBatchServiceImplTest { .withError(ErrorType.APPLICATION, "ut-addFlowBatchError") .buildFuture()); - final Future> rpcResultFuture = - salFlatBatchService.executeBatchPlan(batchChain); - Assert.assertTrue(rpcResultFuture.isDone()); - final RpcResult rpcResult = rpcResultFuture.get(); - Assert.assertFalse(rpcResult.isSuccessful()); - Assert.assertEquals(2, rpcResult.getErrors().size()); - Assert.assertEquals(4, rpcResult.getResult().getBatchFailure().size()); + final var rpcResultFuture = processFlatBatch.executeBatchPlan(batchChain); + assertTrue(rpcResultFuture.isDone()); + final var rpcResult = rpcResultFuture.get(); + assertFalse(rpcResult.isSuccessful()); + assertEquals(2, rpcResult.getErrors().size()); + assertEquals(4, rpcResult.getResult().getBatchFailure().size()); - Mockito.verify(salFlowsBatchService, Mockito.times(2)).addFlowsBatch(addFlowsBatchInputCpt.capture()); - Assert.assertEquals(2, addFlowsBatchInputCpt.getValue().getBatchAddFlows().size()); + verify(addFlowsBatch, times(2)).invoke(addFlowsBatchInputCpt.capture()); + assertEquals(2, addFlowsBatchInputCpt.getValue().nonnullBatchAddFlows().size()); } } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalAsyncConfigServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalAsyncConfigServiceImplTest.java index 0380e7b5e5..1c8797cc3d 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalAsyncConfigServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalAsyncConfigServiceImplTest.java @@ -7,26 +7,23 @@ */ package org.opendaylight.openflowplugin.impl.services.sal; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import java.util.concurrent.Future; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import org.opendaylight.openflowplugin.impl.services.ServiceMocking; +import org.opendaylight.openflowplugin.impl.services.singlelayer.GetAsyncImpl; +import org.opendaylight.openflowplugin.impl.services.singlelayer.SetAsyncImpl; import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.GetAsyncOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SetAsyncInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.SetAsyncOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput; -import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; /** @@ -34,45 +31,38 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder; */ @RunWith(MockitoJUnitRunner.class) public class SalAsyncConfigServiceImplTest extends ServiceMocking { - - private SalAsyncConfigServiceImpl salAsyncConfigService; - - @Override - public void setup() { - salAsyncConfigService = new SalAsyncConfigServiceImpl( - mockedRequestContextStack, mockedDeviceContext); - } - @Test public void testSetAsync() throws Exception { - final SetAsyncInput setAsyncInput = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol + final var setAsync = new SetAsyncImpl(mockedRequestContextStack, mockedDeviceContext); + + final var setAsyncInput = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol .rev130731.SetAsyncInputBuilder().build(); - final RpcResult replyRpcResult = RpcResultBuilder.success(setAsyncInput).build(); - final ListenableFuture> replyFuture = Futures.immediateFuture(replyRpcResult); - Mockito.when(mockedRequestContext.getFuture()).thenReturn(replyFuture); + final var replyRpcResult = RpcResultBuilder.success(setAsyncInput).build(); + final var replyFuture = Futures.immediateFuture(replyRpcResult); + when(mockedRequestContext.getFuture()).thenReturn(replyFuture); - final ListenableFuture> setAsyncResult = - salAsyncConfigService.setAsync(new SetAsyncInputBuilder().build()); + final var setAsyncResult = setAsync.invoke(new SetAsyncInputBuilder().build()); - Assert.assertNotNull(setAsyncResult); - Assert.assertTrue(setAsyncResult.isDone()); - Assert.assertTrue(setAsyncResult.get().isSuccessful()); + assertNotNull(setAsyncResult); + assertTrue(setAsyncResult.isDone()); + assertTrue(setAsyncResult.get().isSuccessful()); verify(mockedRequestContextStack).createRequestContext(); } @Test public void testGetAsyncTest() throws Exception { - final GetAsyncOutput getAsyncOutput = new GetAsyncOutputBuilder().build(); - final RpcResult replyRpcResult = RpcResultBuilder.success(getAsyncOutput).build(); - final ListenableFuture> replyFuture = Futures.immediateFuture(replyRpcResult); - Mockito.when(mockedRequestContext.getFuture()).thenReturn(replyFuture); + final var getAsync = new GetAsyncImpl(mockedRequestContextStack, mockedDeviceContext); + + final var getAsyncOutput = new GetAsyncOutputBuilder().build(); + final var replyRpcResult = RpcResultBuilder.success(getAsyncOutput).build(); + final var replyFuture = Futures.immediateFuture(replyRpcResult); + when(mockedRequestContext.getFuture()).thenReturn(replyFuture); - final Future> getAsyncResult = - salAsyncConfigService.getAsync(new GetAsyncInputBuilder().build()); + final var getAsyncResult = getAsync.invoke(new GetAsyncInputBuilder().build()); - Assert.assertNotNull(getAsyncResult); - Assert.assertTrue(getAsyncResult.isDone()); - Assert.assertTrue(getAsyncResult.get().isSuccessful()); + assertNotNull(getAsyncResult); + assertTrue(getAsyncResult.isDone()); + assertTrue(getAsyncResult.get().isSuccessful()); verify(mockedRequestContextStack).createRequestContext(); verify(mockedOutboundQueue).commitEntry(eq(ServiceMocking.DUMMY_XID_VALUE), any(), any()); } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalBundleServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalBundleServiceImplTest.java index 1f944d7afd..f0c03097e9 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalBundleServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalBundleServiceImplTest.java @@ -8,29 +8,24 @@ package org.opendaylight.openflowplugin.impl.services.sal; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.google.common.util.concurrent.SettableFuture; -import java.util.ArrayList; import java.util.List; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SalExperimenterMessageService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenter; import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenterInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.AddBundleMessagesInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.AddBundleMessagesInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.ControlBundleInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.ControlBundleInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.SalBundleService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.add.bundle.messages.input.Messages; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.add.bundle.messages.input.MessagesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.add.bundle.messages.input.messages.Message; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.add.bundle.messages.input.messages.MessageBuilder; @@ -54,97 +49,79 @@ import org.opendaylight.yangtools.yang.common.Uint32; @RunWith(MockitoJUnitRunner.class) public class SalBundleServiceImplTest { - private static final NodeRef NODE_REF = new NodeRef(InstanceIdentifier.create(Nodes.class) .child(Node.class, new NodeKey(new NodeId("openflow:1")))); private static final BundleId BUNDLE_ID = new BundleId(Uint32.ONE); private static final BundleFlags BUNDLE_FLAGS = new BundleFlags(true, false); - private SalBundleService service; @Mock - private SalExperimenterMessageService experimenterMessageService; + private SendExperimenter sendExperimenter; @Mock private List properties; - @Before - public void setUp() { - service = new SalBundleServiceImpl(experimenterMessageService); - } - @Test public void testControlBundle() { - final ControlBundleInput input = new ControlBundleInputBuilder() + final var service = new ControlBundleImpl(sendExperimenter); + + final var input = new ControlBundleInputBuilder() .setNode(NODE_REF) .setBundleId(BUNDLE_ID) .setFlags(BUNDLE_FLAGS) .setType(BundleControlType.ONFBCTOPENREQUEST) .setBundleProperty(properties) .build(); - final SendExperimenterInputBuilder experimenterBuilder = new SendExperimenterInputBuilder(); - experimenterBuilder.setNode(NODE_REF); - experimenterBuilder.setExperimenterMessageOfChoice(new BundleControlSalBuilder() + when(sendExperimenter.invoke(any())).thenReturn(SettableFuture.create()); + service.invoke(input); + verify(sendExperimenter).invoke(new SendExperimenterInputBuilder() + .setNode(NODE_REF) + .setExperimenterMessageOfChoice(new BundleControlSalBuilder() .setSalControlData(new SalControlDataBuilder(input).build()) - .build()); - Mockito.when(experimenterMessageService.sendExperimenter(any())).thenReturn(SettableFuture.create()); - service.controlBundle(input); - Mockito.verify(experimenterMessageService).sendExperimenter(experimenterBuilder.build()); + .build()) + .build()); } @Test public void testAddBundleMessages() { - final List innerMessages = createMessages(); - final Messages messages = new MessagesBuilder().setMessage(innerMessages).build(); - final AddBundleMessagesInput input = new AddBundleMessagesInputBuilder() + final var service = new AddBundleMessagesImpl(sendExperimenter); + + final var innerMessages = createMessages(); + final var messages = new MessagesBuilder().setMessage(innerMessages).build(); + final var input = new AddBundleMessagesInputBuilder() .setNode(NODE_REF) .setBundleId(BUNDLE_ID) .setFlags(BUNDLE_FLAGS) .setBundleProperty(properties) .setMessages(messages) .build(); - final SalAddMessageDataBuilder dataBuilder = new SalAddMessageDataBuilder(); + final var dataBuilder = new SalAddMessageDataBuilder(); dataBuilder.setBundleId(BUNDLE_ID).setFlags(BUNDLE_FLAGS).setBundleProperty(properties); - final BundleAddMessageSalBuilder addMessageBuilder = new BundleAddMessageSalBuilder(); - final SendExperimenterInputBuilder experimenterBuilder = new SendExperimenterInputBuilder() + final var addMessageBuilder = new BundleAddMessageSalBuilder(); + final var experimenterBuilder = new SendExperimenterInputBuilder() .setNode(NODE_REF); - Mockito.when(experimenterMessageService.sendExperimenter(any())).thenReturn(SettableFuture.create()); - service.addBundleMessages(input); - for (Message msg : innerMessages) { - Mockito.verify(experimenterMessageService) - .sendExperimenter(experimenterBuilder - .setExperimenterMessageOfChoice(addMessageBuilder - .setSalAddMessageData( - dataBuilder.setNode(NODE_REF).setBundleInnerMessage( - msg.getBundleInnerMessage()) - .build()) - .build()).build()); + when(sendExperimenter.invoke(any())).thenReturn(SettableFuture.create()); + service.invoke(input); + for (var msg : innerMessages) { + verify(sendExperimenter).invoke(experimenterBuilder + .setExperimenterMessageOfChoice(addMessageBuilder + .setSalAddMessageData( + dataBuilder.setNode(NODE_REF).setBundleInnerMessage( + msg.getBundleInnerMessage()) + .build()) + .build()) + .build()); } } private static List createMessages() { - List messages = new ArrayList<>(); - messages.add( - new MessageBuilder().setNode(NODE_REF).setBundleInnerMessage(new BundleAddFlowCaseBuilder().build()) - .build()); - messages.add( - new MessageBuilder().setNode(NODE_REF).setBundleInnerMessage(new BundleUpdateFlowCaseBuilder().build()) - .build()); - messages.add( - new MessageBuilder().setNode(NODE_REF).setBundleInnerMessage(new BundleRemoveFlowCaseBuilder().build()) - .build()); - messages.add( - new MessageBuilder().setNode(NODE_REF).setBundleInnerMessage(new BundleAddGroupCaseBuilder().build()) - .build()); - messages.add( - new MessageBuilder().setNode(NODE_REF).setBundleInnerMessage(new BundleUpdateGroupCaseBuilder().build()) - .build()); - messages.add( - new MessageBuilder().setNode(NODE_REF).setBundleInnerMessage(new BundleRemoveGroupCaseBuilder().build()) - .build()); - messages.add( - new MessageBuilder().setNode(NODE_REF).setBundleInnerMessage(new BundleUpdatePortCaseBuilder().build()) - .build()); - return messages; + final var builder = new MessageBuilder().setNode(NODE_REF); + return List.of( + builder.setBundleInnerMessage(new BundleAddFlowCaseBuilder().build()).build(), + builder.setBundleInnerMessage(new BundleUpdateFlowCaseBuilder().build()).build(), + builder.setBundleInnerMessage(new BundleRemoveFlowCaseBuilder().build()).build(), + builder.setBundleInnerMessage(new BundleAddGroupCaseBuilder().build()).build(), + builder.setBundleInnerMessage(new BundleUpdateGroupCaseBuilder().build()).build(), + builder.setBundleInnerMessage(new BundleRemoveGroupCaseBuilder().build()).build(), + builder.setBundleInnerMessage(new BundleUpdatePortCaseBuilder().build()).build()); } - } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalEchoServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalEchoServiceImplTest.java index 44e0271a8c..1b33802068 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalEchoServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalEchoServiceImplTest.java @@ -7,53 +7,45 @@ */ package org.opendaylight.openflowplugin.impl.services.sal; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import java.util.concurrent.Future; -import org.junit.Assert; import org.junit.Test; -import org.mockito.Mockito; +import org.opendaylight.openflowplugin.impl.services.SendEchoImpl; import org.opendaylight.openflowplugin.impl.services.ServiceMocking; -import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder; -import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.opendaylight.yangtools.yang.common.Uint32; public class SalEchoServiceImplTest extends ServiceMocking { - private static final byte[] DUMMY_DATA = "DUMMY DATA".getBytes(); - SalEchoServiceImpl salEchoService; + + private SendEchoImpl salEchoService; @Override protected void setup() { - salEchoService = new SalEchoServiceImpl(mockedRequestContextStack, mockedDeviceContext); + salEchoService = new SendEchoImpl(mockedRequestContextStack, mockedDeviceContext); } @Test public void testSendEcho() throws Exception { - final EchoOutput echoOut = new EchoOutputBuilder() - .setData(DUMMY_DATA) - .build(); - final RpcResult replyRpcResult = RpcResultBuilder.success(echoOut).build(); - final ListenableFuture> replyFt = Futures.immediateFuture(replyRpcResult); - Mockito.when(mockedRequestContext.getFuture()).thenReturn(replyFt); - SendEchoInput sendEchoInput = new SendEchoInputBuilder() - .setData(DUMMY_DATA) - .build(); - - final Future> echoOutput = salEchoService.sendEcho(sendEchoInput); - - Assert.assertNotNull(echoOutput); - Assert.assertTrue(echoOutput.isDone()); - Assert.assertTrue(echoOutput.get().isSuccessful()); + final var echoOut = new EchoOutputBuilder().setData(DUMMY_DATA).build(); + final var replyRpcResult = RpcResultBuilder.success(echoOut).build(); + final var replyFt = Futures.immediateFuture(replyRpcResult); + when(mockedRequestContext.getFuture()).thenReturn(replyFt); + final var sendEchoInput = new SendEchoInputBuilder().setData(DUMMY_DATA).build(); + + final var echoOutput = salEchoService.invoke(sendEchoInput); + + assertNotNull(echoOutput); + assertTrue(echoOutput.isDone()); + assertTrue(echoOutput.get().isSuccessful()); verify(mockedRequestContextStack).createRequestContext(); verify(mockedOutboundQueue).commitEntry(eq(Uint32.valueOf(2121)), any(), any()); } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowServiceImplTest.java index ebf4475a5f..9a32c10df6 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowServiceImplTest.java @@ -7,18 +7,20 @@ */ package org.opendaylight.openflowplugin.impl.services.sal; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import junit.framework.TestCase; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue; @@ -32,7 +34,6 @@ import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry; import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId; @@ -42,10 +43,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.ta import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlowBuilder; @@ -71,18 +70,17 @@ import org.opendaylight.yangtools.yang.common.Uint64; import org.opendaylight.yangtools.yang.common.Uint8; @RunWith(MockitoJUnitRunner.StrictStubs.class) -public class SalFlowServiceImplTest extends TestCase { - +public class SalFlowServiceImplTest { private static final Uint64 DUMMY_DATAPATH_ID = Uint64.valueOf(444); private static final String DUMMY_NODE_ID = "dummyNodeID"; private static final String DUMMY_FLOW_ID = "dummyFlowID"; private static final Uint8 DUMMY_TABLE_ID = Uint8.ZERO; - private static final KeyedInstanceIdentifier NODE_II - = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(DUMMY_NODE_ID))); + private static final KeyedInstanceIdentifier NODE_II = + InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(DUMMY_NODE_ID))); - private static final KeyedInstanceIdentifier TABLE_II - = NODE_II.augmentation(FlowCapableNode.class).child(Table.class, new TableKey(DUMMY_TABLE_ID)); + private static final KeyedInstanceIdentifier TABLE_II = + NODE_II.augmentation(FlowCapableNode.class).child(Table.class, new TableKey(DUMMY_TABLE_ID)); private final NodeRef noderef = new NodeRef(NODE_II); @@ -132,13 +130,31 @@ public class SalFlowServiceImplTest extends TestCase { when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo); } - private SalFlowServiceImpl mockSalFlowService(final Uint8 version) { + private AddFlowImpl mockAddFlow(final Uint8 version) { + when(mockedFeatures.getVersion()).thenReturn(version); + when(mockedFeaturesOutput.getVersion()).thenReturn(version); + when(mockedDeviceInfo.getVersion()).thenReturn(version); + + final var convertorManager = ConvertorManagerFactory.createDefaultManager(); + return new AddFlowImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager); + } + + private RemoveFlowImpl mockRemoveFlow(final Uint8 version) { + when(mockedFeatures.getVersion()).thenReturn(version); + when(mockedFeaturesOutput.getVersion()).thenReturn(version); + when(mockedDeviceInfo.getVersion()).thenReturn(version); + + final var convertorManager = ConvertorManagerFactory.createDefaultManager(); + return new RemoveFlowImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager); + } + + private UpdateFlowImpl mockUpdateFlow(final Uint8 version) { when(mockedFeatures.getVersion()).thenReturn(version); when(mockedFeaturesOutput.getVersion()).thenReturn(version); when(mockedDeviceInfo.getVersion()).thenReturn(version); - final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager(); - return new SalFlowServiceImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager); + final var convertorManager = ConvertorManagerFactory.createDefaultManager(); + return new UpdateFlowImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager); } @Test @@ -164,14 +180,13 @@ public class SalFlowServiceImplTest extends TestCase { .setNode(noderef) .build(); - Mockito.doReturn(Futures.>immediateFailedFuture(new Exception("ut-failed-response"))) + doReturn(Futures.>immediateFailedFuture(new Exception("ut-failed-response"))) .when(requestContext).getFuture(); - final Future> rpcResultFuture = - mockSalFlowService(version).addFlow(mockedAddFlowInput); + final var rpcResultFuture = mockAddFlow(version).invoke(mockedAddFlowInput); assertNotNull(rpcResultFuture); - final RpcResult addFlowOutputRpcResult = rpcResultFuture.get(); + final var addFlowOutputRpcResult = rpcResultFuture.get(); assertNotNull(addFlowOutputRpcResult); assertFalse(addFlowOutputRpcResult.isSuccessful()); } @@ -193,14 +208,13 @@ public class SalFlowServiceImplTest extends TestCase { .setNode(noderef) .build(); - Mockito.doReturn(Futures.>immediateFailedFuture(new Exception("ut-failed-response"))) + doReturn(Futures.>immediateFailedFuture(new Exception("ut-failed-response"))) .when(requestContext).getFuture(); - final Future> rpcResultFuture = - mockSalFlowService(version).removeFlow(mockedRemoveFlowInput); + final var rpcResultFuture = mockRemoveFlow(version).invoke(mockedRemoveFlowInput); assertNotNull(rpcResultFuture); - final RpcResult removeFlowOutputRpcResult = rpcResultFuture.get(); + final var removeFlowOutputRpcResult = rpcResultFuture.get(); assertNotNull(removeFlowOutputRpcResult); assertFalse(removeFlowOutputRpcResult.isSuccessful()); } @@ -217,9 +231,9 @@ public class SalFlowServiceImplTest extends TestCase { .setTableId(Uint8.ONE) .setNode(noderef) .build(); - SalFlowServiceImpl salFlowService = mockSalFlowService(version); + var addFlow = mockAddFlow(version); - verifyOutput(salFlowService.addFlow(mockedAddFlowInput)); + verifyOutput(addFlow.invoke(mockedAddFlowInput)); } @Test @@ -241,8 +255,8 @@ public class SalFlowServiceImplTest extends TestCase { .setNode(noderef) .build(); - SalFlowServiceImpl salFlowService = mockSalFlowService(version); - verifyOutput(salFlowService.removeFlow(mockedRemoveFlowInput)); + final var removeFlow = mockRemoveFlow(version); + verifyOutput(removeFlow.invoke(mockedRemoveFlowInput)); } @Test @@ -276,7 +290,7 @@ public class SalFlowServiceImplTest extends TestCase { when(mockedUpdateFlowInput1.getUpdatedFlow()).thenReturn(mockedUpdateFlow1); FlowRef mockedFlowRef = mock(FlowRef.class); - Mockito.doReturn(TABLE_II.child(Flow.class, + doReturn(TABLE_II.child(Flow.class, new FlowKey(new FlowId(DUMMY_FLOW_ID)))).when(mockedFlowRef).getValue(); when(mockedUpdateFlowInput.getFlowRef()).thenReturn(mockedFlowRef); when(mockedUpdateFlowInput1.getFlowRef()).thenReturn(mockedFlowRef); @@ -295,15 +309,15 @@ public class SalFlowServiceImplTest extends TestCase { when(mockedUpdateFlowInput.getOriginalFlow()).thenReturn(mockedOriginalFlow); when(mockedUpdateFlowInput1.getOriginalFlow()).thenReturn(mockedOriginalFlow1); - SalFlowServiceImpl salFlowService = mockSalFlowService(version); - verifyOutput(salFlowService.updateFlow(mockedUpdateFlowInput)); - verifyOutput(salFlowService.updateFlow(mockedUpdateFlowInput1)); + final var updateFlow = mockUpdateFlow(version); + verifyOutput(updateFlow.invoke(mockedUpdateFlowInput)); + verifyOutput(updateFlow.invoke(mockedUpdateFlowInput1)); } - private static void verifyOutput(final Future> rpcResultFuture) + private static void verifyOutput(final ListenableFuture> rpcResultFuture) throws ExecutionException, InterruptedException { assertNotNull(rpcResultFuture); - final RpcResult addFlowOutputRpcResult = rpcResultFuture.get(); + final var addFlowOutputRpcResult = rpcResultFuture.get(); assertNotNull(addFlowOutputRpcResult); assertTrue(addFlowOutputRpcResult.isSuccessful()); } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowsBatchServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowsBatchServiceImplTest.java index 5825acd5a0..41ddafa012 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowsBatchServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalFlowsBatchServiceImplTest.java @@ -5,52 +5,48 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.openflowplugin.impl.services.sal; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.Future; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.inOrder; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; -import org.mockito.ArgumentMatchers; import org.mockito.Captor; -import org.mockito.InOrder; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.RemoveFlowsBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.add.flows.batch.input.BatchAddFlows; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.add.flows.batch.input.BatchAddFlowsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.batch.flow.input.update.grouping.OriginalBatchedFlowBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.batch.flow.input.update.grouping.UpdatedBatchedFlowBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.batch.flow.output.list.grouping.BatchFailedFlowsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.remove.flows.batch.input.BatchRemoveFlows; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.remove.flows.batch.input.BatchRemoveFlowsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.update.flows.batch.input.BatchUpdateFlows; @@ -63,30 +59,30 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.N import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.util.BindingMap; import org.opendaylight.yangtools.yang.common.ErrorType; -import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.opendaylight.yangtools.yang.common.Uint16; import org.opendaylight.yangtools.yang.common.Uint8; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Test for {@link org.opendaylight.openflowplugin.impl.services.sal.SalFlowsBatchServiceImpl}. */ @RunWith(MockitoJUnitRunner.class) public class SalFlowsBatchServiceImplTest { - - private static final Logger LOG = LoggerFactory.getLogger(SalFlowsBatchServiceImplTest.class); - public static final NodeId NODE_ID = new NodeId("ut-dummy-node"); public static final NodeKey NODE_KEY = new NodeKey(NODE_ID); - public static final NodeRef NODE_REF = - new NodeRef(InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY)); + public static final NodeRef NODE_REF = new NodeRef( + InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY)); + public static final String FLOW_ID_VALUE_1 = "ut-dummy-flow1"; + public static final String FLOW_ID_VALUE_2 = "ut-dummy-flow2"; @Mock - private SalFlowService salFlowService; + private AddFlow addFlow; @Mock - private FlowCapableTransactionService transactionService; + private RemoveFlow removeFlow; + @Mock + private UpdateFlow updateFlow; + @Mock + private SendBarrier sendBarrier; @Captor private ArgumentCaptor removeFlowInputCpt; @Captor @@ -94,95 +90,96 @@ public class SalFlowsBatchServiceImplTest { @Captor private ArgumentCaptor addFlowInputCpt; - private SalFlowsBatchServiceImpl salFlowsBatchService; - public static final String FLOW_ID_VALUE_1 = "ut-dummy-flow1"; - public static final String FLOW_ID_VALUE_2 = "ut-dummy-flow2"; + private AddFlowsBatchImpl addFlowsBatch; + private RemoveFlowsBatchImpl removeFlowsBatch; + private UpdateFlowsBatchImpl updateFlowsBatch; @Before public void setUp() { - salFlowsBatchService = new SalFlowsBatchServiceImpl(salFlowService, transactionService); + addFlowsBatch = new AddFlowsBatchImpl(addFlow, sendBarrier); + removeFlowsBatch = new RemoveFlowsBatchImpl(removeFlow, sendBarrier); + updateFlowsBatch = new UpdateFlowsBatchImpl(updateFlow, sendBarrier); - Mockito.when(transactionService.sendBarrier(ArgumentMatchers.any())) - .thenReturn(RpcResultBuilder.success().buildFuture()); + when(sendBarrier.invoke(any())).thenReturn(RpcResultBuilder.success().buildFuture()); } @After public void tearDown() { - Mockito.verifyNoMoreInteractions(salFlowService, transactionService); + verifyNoMoreInteractions(addFlow, removeFlow, updateFlow, sendBarrier); } @Test public void testRemoveFlowsBatch_success() throws Exception { - Mockito.when(salFlowService.removeFlow(ArgumentMatchers.any())) + when(removeFlow.invoke(any())) .thenReturn(RpcResultBuilder.success(new RemoveFlowOutputBuilder().build()) .buildFuture()); - final String flow1IdValue = "ut-dummy-flow1"; - final String flow2IdValue = "ut-dummy-flow2"; - final BatchRemoveFlows batchFlow1 = createEmptyBatchRemoveFlow(flow1IdValue, 42); - final BatchRemoveFlows batchFlow2 = createEmptyBatchRemoveFlow(flow2IdValue, 43); + final var flow1IdValue = "ut-dummy-flow1"; + final var flow2IdValue = "ut-dummy-flow2"; + final var batchFlow1 = createEmptyBatchRemoveFlow(flow1IdValue, 42); + final var batchFlow2 = createEmptyBatchRemoveFlow(flow2IdValue, 43); - final RemoveFlowsBatchInput input = new RemoveFlowsBatchInputBuilder() + final var input = new RemoveFlowsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) .setBatchRemoveFlows(BindingMap.ordered(batchFlow1, batchFlow2)) .build(); - final Future> resultFuture = salFlowsBatchService.removeFlowsBatch(input); + final var resultFuture = removeFlowsBatch.invoke(input); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResult = resultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - final RemoveFlowsBatchOutput result = rpcResult.getResult(); - Assert.assertEquals(0, result.nonnullBatchFailedFlowsOutput().size()); + assertTrue(resultFuture.isDone()); + final var rpcResult = resultFuture.get(); + assertTrue(rpcResult.isSuccessful()); + final var result = rpcResult.getResult(); + assertEquals(0, result.nonnullBatchFailedFlowsOutput().size()); - final InOrder inOrder = Mockito.inOrder(salFlowService, transactionService); + final var inOrder = inOrder(removeFlow, sendBarrier); - inOrder.verify(salFlowService, Mockito.times(2)).removeFlow(removeFlowInputCpt.capture()); - final List allValues = removeFlowInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42, allValues.get(0).getPriority().longValue()); - Assert.assertEquals(43, allValues.get(1).getPriority().longValue()); + inOrder.verify(removeFlow, times(2)).invoke(removeFlowInputCpt.capture()); + final var allValues = removeFlowInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42, allValues.get(0).getPriority().longValue()); + assertEquals(43, allValues.get(1).getPriority().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } @Test public void testRemoveFlowsBatch_failed() throws Exception { - Mockito.when(salFlowService.removeFlow(ArgumentMatchers.any())) + when(removeFlow.invoke(any())) .thenReturn(RpcResultBuilder.failed() .withError(ErrorType.APPLICATION, "flow-remove-fail-1") .buildFuture()); - final BatchRemoveFlows batchFlow1 = createEmptyBatchRemoveFlow(FLOW_ID_VALUE_1, 42); - final BatchRemoveFlows batchFlow2 = createEmptyBatchRemoveFlow(FLOW_ID_VALUE_2, 43); + final var batchFlow1 = createEmptyBatchRemoveFlow(FLOW_ID_VALUE_1, 42); + final var batchFlow2 = createEmptyBatchRemoveFlow(FLOW_ID_VALUE_2, 43); - final RemoveFlowsBatchInput input = new RemoveFlowsBatchInputBuilder() + final var input = new RemoveFlowsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) .setBatchRemoveFlows(BindingMap.ordered(batchFlow1, batchFlow2)) .build(); - final Future> resultFuture = salFlowsBatchService.removeFlowsBatch(input); + final var resultFuture = removeFlowsBatch.invoke(input); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResult = resultFuture.get(); - Assert.assertFalse(rpcResult.isSuccessful()); - final RemoveFlowsBatchOutput result = rpcResult.getResult(); - Iterator iterator = result.nonnullBatchFailedFlowsOutput().values().iterator(); - Assert.assertEquals(2, result.nonnullBatchFailedFlowsOutput().size()); - Assert.assertEquals(FLOW_ID_VALUE_1, iterator.next().getFlowId().getValue()); - Assert.assertEquals(FLOW_ID_VALUE_2, iterator.next().getFlowId().getValue()); + assertTrue(resultFuture.isDone()); + final var rpcResult = resultFuture.get(); + assertFalse(rpcResult.isSuccessful()); + final var result = rpcResult.getResult(); + var iterator = result.nonnullBatchFailedFlowsOutput().values().iterator(); + assertEquals(2, result.nonnullBatchFailedFlowsOutput().size()); + assertEquals(FLOW_ID_VALUE_1, iterator.next().getFlowId().getValue()); + assertEquals(FLOW_ID_VALUE_2, iterator.next().getFlowId().getValue()); - final InOrder inOrder = Mockito.inOrder(salFlowService, transactionService); + final var inOrder = inOrder(removeFlow, sendBarrier); - inOrder.verify(salFlowService, Mockito.times(2)).removeFlow(removeFlowInputCpt.capture()); - final List allValues = removeFlowInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42, allValues.get(0).getPriority().longValue()); - Assert.assertEquals(43, allValues.get(1).getPriority().longValue()); + inOrder.verify(removeFlow, times(2)).invoke(removeFlowInputCpt.capture()); + final var allValues = removeFlowInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42, allValues.get(0).getPriority().longValue()); + assertEquals(43, allValues.get(1).getPriority().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } private static BatchAddFlows createEmptyBatchAddFlow(final String flowIdValue, final int priority) { @@ -204,8 +201,8 @@ public class SalFlowsBatchServiceImplTest { } private static BatchUpdateFlows createEmptyBatchUpdateFlow(final String flowIdValue, final int priority) { - final BatchAddFlows emptyOriginalFlow = createEmptyBatchAddFlow(flowIdValue, priority); - final BatchAddFlows emptyUpdatedFlow = createEmptyBatchAddFlow(flowIdValue, priority + 1); + final var emptyOriginalFlow = createEmptyBatchAddFlow(flowIdValue, priority); + final var emptyUpdatedFlow = createEmptyBatchAddFlow(flowIdValue, priority + 1); return new BatchUpdateFlowsBuilder() .setFlowId(new FlowId(flowIdValue)) .setOriginalBatchedFlow(new OriginalBatchedFlowBuilder(emptyOriginalFlow).build()) @@ -215,10 +212,10 @@ public class SalFlowsBatchServiceImplTest { @Test public void testAddFlowsBatch_success() throws Exception { - Mockito.when(salFlowService.addFlow(ArgumentMatchers.any())) + when(addFlow.invoke(any())) .thenReturn(RpcResultBuilder.success(new AddFlowOutputBuilder().build()).buildFuture()); - final AddFlowsBatchInput input = new AddFlowsBatchInputBuilder() + final var input = new AddFlowsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) .setBatchAddFlows(BindingMap.ordered( @@ -226,30 +223,30 @@ public class SalFlowsBatchServiceImplTest { createEmptyBatchAddFlow("ut-dummy-flow2", 43))) .build(); - final Future> resultFuture = salFlowsBatchService.addFlowsBatch(input); + final var resultFuture = addFlowsBatch.invoke(input); - Assert.assertTrue(resultFuture.isDone()); - Assert.assertTrue(resultFuture.get().isSuccessful()); + assertTrue(resultFuture.isDone()); + assertTrue(resultFuture.get().isSuccessful()); - final InOrder inOrder = Mockito.inOrder(salFlowService, transactionService); + final var inOrder = inOrder(addFlow, sendBarrier); - inOrder.verify(salFlowService, Mockito.times(2)).addFlow(addFlowInputCpt.capture()); - final List allValues = addFlowInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42, allValues.get(0).getPriority().longValue()); - Assert.assertEquals(43, allValues.get(1).getPriority().longValue()); + inOrder.verify(addFlow, times(2)).invoke(addFlowInputCpt.capture()); + final var allValues = addFlowInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42, allValues.get(0).getPriority().longValue()); + assertEquals(43, allValues.get(1).getPriority().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } @Test public void testAddFlowsBatch_failed() throws Exception { - Mockito.when(salFlowService.addFlow(ArgumentMatchers.any())) + when(addFlow.invoke(any())) .thenReturn(RpcResultBuilder .failed().withError(ErrorType.APPLICATION, "ut-groupAddError") .buildFuture()); - final AddFlowsBatchInput input = new AddFlowsBatchInputBuilder() + final var input = new AddFlowsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) .setBatchAddFlows(BindingMap.ordered( @@ -257,34 +254,36 @@ public class SalFlowsBatchServiceImplTest { createEmptyBatchAddFlow(FLOW_ID_VALUE_2, 43))) .build(); - final Future> resultFuture = salFlowsBatchService.addFlowsBatch(input); - Iterator iterator = resultFuture.get().getResult().nonnullBatchFailedFlowsOutput() - .values().iterator(); + final var resultFuture = addFlowsBatch.invoke(input); + + assertTrue(resultFuture.isDone()); + + final var result = resultFuture.get(); + assertFalse(result.isSuccessful()); + assertEquals(2, result.getResult().nonnullBatchFailedFlowsOutput().size()); - Assert.assertTrue(resultFuture.isDone()); - Assert.assertFalse(resultFuture.get().isSuccessful()); - Assert.assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedFlowsOutput().size()); - Assert.assertEquals(FLOW_ID_VALUE_1, iterator.next().getFlowId().getValue()); - Assert.assertEquals(FLOW_ID_VALUE_2, iterator.next().getFlowId().getValue()); - Assert.assertEquals(2, resultFuture.get().getErrors().size()); + final var iterator = result.getResult().nonnullBatchFailedFlowsOutput().values().iterator(); + assertEquals(FLOW_ID_VALUE_1, iterator.next().getFlowId().getValue()); + assertEquals(FLOW_ID_VALUE_2, iterator.next().getFlowId().getValue()); + assertEquals(2, resultFuture.get().getErrors().size()); - final InOrder inOrder = Mockito.inOrder(salFlowService, transactionService); + final var inOrder = inOrder(addFlow, sendBarrier); - inOrder.verify(salFlowService, Mockito.times(2)).addFlow(addFlowInputCpt.capture()); - final List allValues = addFlowInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42, allValues.get(0).getPriority().longValue()); - Assert.assertEquals(43, allValues.get(1).getPriority().longValue()); + inOrder.verify(addFlow, times(2)).invoke(addFlowInputCpt.capture()); + final var allValues = addFlowInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42, allValues.get(0).getPriority().longValue()); + assertEquals(43, allValues.get(1).getPriority().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } @Test public void testUpdateFlowsBatch_success() throws Exception { - Mockito.when(salFlowService.updateFlow(ArgumentMatchers.any())) + when(updateFlow.invoke(any())) .thenReturn(RpcResultBuilder.success(new UpdateFlowOutputBuilder().build()).buildFuture()); - final UpdateFlowsBatchInput input = new UpdateFlowsBatchInputBuilder() + final var input = new UpdateFlowsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) .setBatchUpdateFlows(BindingMap.ordered( @@ -292,32 +291,32 @@ public class SalFlowsBatchServiceImplTest { createEmptyBatchUpdateFlow(FLOW_ID_VALUE_2, 44))) .build(); - final Future> resultFuture = salFlowsBatchService.updateFlowsBatch(input); + final var resultFuture = updateFlowsBatch.invoke(input); - Assert.assertTrue(resultFuture.isDone()); - Assert.assertTrue(resultFuture.get().isSuccessful()); + assertTrue(resultFuture.isDone()); + assertTrue(resultFuture.get().isSuccessful()); - final InOrder inOrder = Mockito.inOrder(salFlowService, transactionService); + final var inOrder = inOrder(updateFlow, sendBarrier); - inOrder.verify(salFlowService, Mockito.times(2)).updateFlow(updateFlowInputCpt.capture()); - final List allValues = updateFlowInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42, allValues.get(0).getOriginalFlow().getPriority().longValue()); - Assert.assertEquals(43, allValues.get(0).getUpdatedFlow().getPriority().longValue()); - Assert.assertEquals(44, allValues.get(1).getOriginalFlow().getPriority().longValue()); - Assert.assertEquals(45, allValues.get(1).getUpdatedFlow().getPriority().longValue()); + inOrder.verify(updateFlow, times(2)).invoke(updateFlowInputCpt.capture()); + final var allValues = updateFlowInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42, allValues.get(0).getOriginalFlow().getPriority().longValue()); + assertEquals(43, allValues.get(0).getUpdatedFlow().getPriority().longValue()); + assertEquals(44, allValues.get(1).getOriginalFlow().getPriority().longValue()); + assertEquals(45, allValues.get(1).getUpdatedFlow().getPriority().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } @Test public void testUpdateFlowsBatch_failure() throws Exception { - Mockito.when(salFlowService.updateFlow(ArgumentMatchers.any())) + when(updateFlow.invoke(any())) .thenReturn(RpcResultBuilder.failed() .withError(ErrorType.APPLICATION, "ut-flowUpdateError") .buildFuture()); - final UpdateFlowsBatchInput input = new UpdateFlowsBatchInputBuilder() + final var input = new UpdateFlowsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) .setBatchUpdateFlows(BindingMap.ordered( @@ -325,27 +324,25 @@ public class SalFlowsBatchServiceImplTest { createEmptyBatchUpdateFlow(FLOW_ID_VALUE_2, 44))) .build(); - final Future> resultFuture = salFlowsBatchService.updateFlowsBatch(input); - Iterator iterator = resultFuture.get().getResult().nonnullBatchFailedFlowsOutput() - .values().iterator(); - - Assert.assertTrue(resultFuture.isDone()); - Assert.assertFalse(resultFuture.get().isSuccessful()); - Assert.assertFalse(resultFuture.get().isSuccessful()); - Assert.assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedFlowsOutput().size()); - Assert.assertEquals(FLOW_ID_VALUE_1, iterator.next().getFlowId().getValue()); - Assert.assertEquals(FLOW_ID_VALUE_2, iterator.next().getFlowId().getValue()); - Assert.assertEquals(2, resultFuture.get().getErrors().size()); - - final InOrder inOrder = Mockito.inOrder(salFlowService, transactionService); - inOrder.verify(salFlowService, Mockito.times(2)).updateFlow(updateFlowInputCpt.capture()); - final List allValues = updateFlowInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42, allValues.get(0).getOriginalFlow().getPriority().longValue()); - Assert.assertEquals(43, allValues.get(0).getUpdatedFlow().getPriority().longValue()); - Assert.assertEquals(44, allValues.get(1).getOriginalFlow().getPriority().longValue()); - Assert.assertEquals(45, allValues.get(1).getUpdatedFlow().getPriority().longValue()); - - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + final var resultFuture = updateFlowsBatch.invoke(input); + assertTrue(resultFuture.isDone()); + final var result = resultFuture.get(); + assertFalse(result.isSuccessful()); + assertEquals(2, result.getResult().nonnullBatchFailedFlowsOutput().size()); + final var iterator = resultFuture.get().getResult().nonnullBatchFailedFlowsOutput().values().iterator(); + assertEquals(FLOW_ID_VALUE_1, iterator.next().getFlowId().getValue()); + assertEquals(FLOW_ID_VALUE_2, iterator.next().getFlowId().getValue()); + assertEquals(2, resultFuture.get().getErrors().size()); + + final var inOrder = inOrder(updateFlow, sendBarrier); + inOrder.verify(updateFlow, times(2)).invoke(updateFlowInputCpt.capture()); + final var allValues = updateFlowInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42, allValues.get(0).getOriginalFlow().getPriority().longValue()); + assertEquals(43, allValues.get(0).getUpdatedFlow().getPriority().longValue()); + assertEquals(44, allValues.get(1).getOriginalFlow().getPriority().longValue()); + assertEquals(45, allValues.get(1).getUpdatedFlow().getPriority().longValue()); + + inOrder.verify(sendBarrier).invoke(any()); } } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupServiceImplTest.java index 7911459f5d..a5078f4f57 100755 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupServiceImplTest.java @@ -13,20 +13,14 @@ import org.junit.Test; import org.mockito.Mock; import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry; import org.opendaylight.openflowplugin.impl.services.ServiceMocking; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.OriginalGroup; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.OriginalGroupBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroup; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroupBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; @@ -39,22 +33,25 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; import org.opendaylight.yangtools.yang.common.Uint32; public class SalGroupServiceImplTest extends ServiceMocking { - private static final Uint32 DUMMY_GROUP_ID = Uint32.valueOf(15); - private static final - KeyedInstanceIdentifier NODE_II = InstanceIdentifier.create(Nodes.class).child(Node.class, - new NodeKey(new NodeId(DUMMY_NODE_ID))); - NodeRef noderef = new NodeRef(NODE_II); + private static final KeyedInstanceIdentifier NODE_II = + InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(DUMMY_NODE_ID))); + + private final NodeRef noderef = new NodeRef(NODE_II); @Mock - DeviceGroupRegistry mockedDeviceGroupRegistry; + private DeviceGroupRegistry mockedDeviceGroupRegistry; - SalGroupServiceImpl salGroupService; + private AddGroupImpl addGroup; + private RemoveGroupImpl removeGroup; + private UpdateGroupImpl updateGroup; @Override protected void setup() { - final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager(); - salGroupService = new SalGroupServiceImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager); + final var convertorManager = ConvertorManagerFactory.createDefaultManager(); + addGroup = new AddGroupImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager); + removeGroup = new RemoveGroupImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager); + updateGroup = new UpdateGroupImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager); } @Test @@ -63,12 +60,12 @@ public class SalGroupServiceImplTest extends ServiceMocking { } private void addGroup() { - final GroupId dummyGroupId = new GroupId(DUMMY_GROUP_ID); - AddGroupInput addGroupInput = new AddGroupInputBuilder().setGroupId(dummyGroupId).setNode(noderef).build(); + final var dummyGroupId = new GroupId(DUMMY_GROUP_ID); + final var addGroupInput = new AddGroupInputBuilder().setGroupId(dummyGroupId).setNode(noderef).build(); this.mockSuccessfulFuture(); - salGroupService.addGroup(addGroupInput); + addGroup.invoke(addGroupInput); verify(mockedRequestContextStack).createRequestContext(); } @@ -84,13 +81,13 @@ public class SalGroupServiceImplTest extends ServiceMocking { } private void updateGroup() { - final UpdatedGroup updatedGroup = new UpdatedGroupBuilder().setGroupId(new GroupId(DUMMY_GROUP_ID)).build(); - final OriginalGroup originalGroup = new OriginalGroupBuilder().setGroupId(new GroupId(DUMMY_GROUP_ID)).build(); - final UpdateGroupInput updateGroupInput = + final var updatedGroup = new UpdatedGroupBuilder().setGroupId(new GroupId(DUMMY_GROUP_ID)).build(); + final var originalGroup = new OriginalGroupBuilder().setGroupId(new GroupId(DUMMY_GROUP_ID)).build(); + final var updateGroupInput = new UpdateGroupInputBuilder().setUpdatedGroup(updatedGroup).setOriginalGroup(originalGroup).build(); this.mockSuccessfulFuture(); - salGroupService.updateGroup(updateGroupInput); + updateGroup.invoke(updateGroupInput); verify(mockedRequestContextStack).createRequestContext(); } @@ -106,10 +103,10 @@ public class SalGroupServiceImplTest extends ServiceMocking { } private void removeGroup() { - final GroupId dummyGroupId = new GroupId(DUMMY_GROUP_ID); - RemoveGroupInput removeGroupInput = new RemoveGroupInputBuilder().setGroupId(dummyGroupId).build(); + final var dummyGroupId = new GroupId(DUMMY_GROUP_ID); + final var removeGroupInput = new RemoveGroupInputBuilder().setGroupId(dummyGroupId).build(); this.mockSuccessfulFuture(); - salGroupService.removeGroup(removeGroupInput); + removeGroup.invoke(removeGroupInput); verify(mockedRequestContextStack).createRequestContext(); } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupsBatchServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupsBatchServiceImplTest.java index a1bcdf19c9..e95c842173 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupsBatchServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalGroupsBatchServiceImplTest.java @@ -5,52 +5,48 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.openflowplugin.impl.services.sal; -import com.google.common.collect.Lists; -import java.util.Iterator; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.inOrder; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + import java.util.List; -import java.util.concurrent.Future; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; -import org.mockito.ArgumentMatchers; import org.mockito.Captor; -import org.mockito.InOrder; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroup; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroup; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroup; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.AddGroupsBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.UpdateGroupsBatchOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.add.groups.batch.input.BatchAddGroups; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.add.groups.batch.input.BatchAddGroupsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.batch.group.input.update.grouping.OriginalBatchedGroupBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.batch.group.input.update.grouping.UpdatedBatchedGroupBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.batch.group.output.list.grouping.BatchFailedGroupsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.remove.groups.batch.input.BatchRemoveGroups; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.remove.groups.batch.input.BatchRemoveGroupsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.update.groups.batch.input.BatchUpdateGroups; @@ -63,7 +59,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.N import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.util.BindingMap; import org.opendaylight.yangtools.yang.common.ErrorType; -import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.opendaylight.yangtools.yang.common.Uint32; @@ -72,16 +67,19 @@ import org.opendaylight.yangtools.yang.common.Uint32; */ @RunWith(MockitoJUnitRunner.class) public class SalGroupsBatchServiceImplTest { - public static final NodeId NODE_ID = new NodeId("ut-dummy-node"); public static final NodeKey NODE_KEY = new NodeKey(NODE_ID); public static final NodeRef NODE_REF = new NodeRef(InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY)); @Mock - private SalGroupService salGroupService; + private AddGroup addGroup; + @Mock + private RemoveGroup removeGroup; @Mock - private FlowCapableTransactionService transactionService; + private UpdateGroup updateGroup; + @Mock + private SendBarrier sendBarrier; @Captor private ArgumentCaptor removeGroupInputCpt; @Captor @@ -89,98 +87,100 @@ public class SalGroupsBatchServiceImplTest { @Captor private ArgumentCaptor addGroupInputCpt; - private SalGroupsBatchServiceImpl salGroupsBatchService; - + private AddGroupsBatchImpl addGroupsBatch; + private RemoveGroupsBatchImpl removeGroupsBatch; + private UpdateGroupsBatchImpl updateGroupsBatch; @Before public void setUp() { - salGroupsBatchService = new SalGroupsBatchServiceImpl(salGroupService, transactionService); + addGroupsBatch = new AddGroupsBatchImpl(addGroup, sendBarrier); + removeGroupsBatch = new RemoveGroupsBatchImpl(removeGroup, sendBarrier); + updateGroupsBatch = new UpdateGroupsBatchImpl(updateGroup, sendBarrier); - Mockito.when(transactionService.sendBarrier(ArgumentMatchers.any())) - .thenReturn(RpcResultBuilder.success().buildFuture()); + when(sendBarrier.invoke(any())).thenReturn(RpcResultBuilder.success().buildFuture()); } @After public void tearDown() { - Mockito.verifyNoMoreInteractions(salGroupService, transactionService); + verifyNoMoreInteractions(addGroup, removeGroup, updateGroup, sendBarrier); } @Test public void testUpdateGroupsBatch_success() throws Exception { - Mockito.when(salGroupService.updateGroup(Mockito.any())) + when(updateGroup.invoke(any())) .thenReturn(RpcResultBuilder.success(new UpdateGroupOutputBuilder().build()).buildFuture()); - final UpdateGroupsBatchInput input = new UpdateGroupsBatchInputBuilder() + final var input = new UpdateGroupsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) - .setBatchUpdateGroups(Lists.newArrayList( + .setBatchUpdateGroups(List.of( createEmptyBatchUpdateGroup(42L), createEmptyBatchUpdateGroup(44L))) .build(); - final Future> resultFuture = salGroupsBatchService.updateGroupsBatch(input); + final var resultFuture = updateGroupsBatch.invoke(input); - Assert.assertTrue(resultFuture.isDone()); - Assert.assertTrue(resultFuture.get().isSuccessful()); + assertTrue(resultFuture.isDone()); + assertTrue(resultFuture.get().isSuccessful()); - final InOrder inOrder = Mockito.inOrder(salGroupService, transactionService); - inOrder.verify(salGroupService, Mockito.times(2)).updateGroup(updateGroupInputCpt.capture()); - final List allValues = updateGroupInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42, allValues.get(0).getOriginalGroup().getGroupId().getValue().longValue()); - Assert.assertEquals(43, allValues.get(0).getUpdatedGroup().getGroupId().getValue().longValue()); - Assert.assertEquals(44, allValues.get(1).getOriginalGroup().getGroupId().getValue().longValue()); - Assert.assertEquals(45, allValues.get(1).getUpdatedGroup().getGroupId().getValue().longValue()); + final var inOrder = inOrder(updateGroup, sendBarrier); + inOrder.verify(updateGroup, times(2)).invoke(updateGroupInputCpt.capture()); + final var allValues = updateGroupInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42, allValues.get(0).getOriginalGroup().getGroupId().getValue().longValue()); + assertEquals(43, allValues.get(0).getUpdatedGroup().getGroupId().getValue().longValue()); + assertEquals(44, allValues.get(1).getOriginalGroup().getGroupId().getValue().longValue()); + assertEquals(45, allValues.get(1).getUpdatedGroup().getGroupId().getValue().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } @Test public void testUpdateGroupsBatch_failure() throws Exception { - Mockito.when(salGroupService.updateGroup(Mockito.any())) + when(updateGroup.invoke(any())) .thenReturn(RpcResultBuilder.failed() .withError(ErrorType.APPLICATION, "ur-groupUpdateError") .buildFuture()); - final UpdateGroupsBatchInput input = new UpdateGroupsBatchInputBuilder() + final var input = new UpdateGroupsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) - .setBatchUpdateGroups(Lists.newArrayList( + .setBatchUpdateGroups(List.of( createEmptyBatchUpdateGroup(42L), createEmptyBatchUpdateGroup(44L))) .build(); - final Future> resultFuture = salGroupsBatchService.updateGroupsBatch(input); - Iterator iterator = resultFuture.get().getResult().nonnullBatchFailedGroupsOutput() + final var resultFuture = updateGroupsBatch.invoke(input); + final var iterator = resultFuture.get().getResult().nonnullBatchFailedGroupsOutput() .values().iterator(); - Assert.assertTrue(resultFuture.isDone()); - Assert.assertFalse(resultFuture.get().isSuccessful()); - Assert.assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedGroupsOutput().size()); - Assert.assertEquals(43L, iterator.next().getGroupId().getValue().longValue()); - Assert.assertEquals(45L, iterator.next().getGroupId().getValue().longValue()); - Assert.assertEquals(2, resultFuture.get().getErrors().size()); + assertTrue(resultFuture.isDone()); + assertFalse(resultFuture.get().isSuccessful()); + assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedGroupsOutput().size()); + assertEquals(43L, iterator.next().getGroupId().getValue().longValue()); + assertEquals(45L, iterator.next().getGroupId().getValue().longValue()); + assertEquals(2, resultFuture.get().getErrors().size()); - final InOrder inOrder = Mockito.inOrder(salGroupService, transactionService); - inOrder.verify(salGroupService, Mockito.times(2)).updateGroup(updateGroupInputCpt.capture()); - final List allValues = updateGroupInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42, allValues.get(0).getOriginalGroup().getGroupId().getValue().longValue()); - Assert.assertEquals(43, allValues.get(0).getUpdatedGroup().getGroupId().getValue().longValue()); - Assert.assertEquals(44, allValues.get(1).getOriginalGroup().getGroupId().getValue().longValue()); - Assert.assertEquals(45, allValues.get(1).getUpdatedGroup().getGroupId().getValue().longValue()); + final var inOrder = inOrder(updateGroup, sendBarrier); + inOrder.verify(updateGroup, times(2)).invoke(updateGroupInputCpt.capture()); + final var allValues = updateGroupInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42, allValues.get(0).getOriginalGroup().getGroupId().getValue().longValue()); + assertEquals(43, allValues.get(0).getUpdatedGroup().getGroupId().getValue().longValue()); + assertEquals(44, allValues.get(1).getOriginalGroup().getGroupId().getValue().longValue()); + assertEquals(45, allValues.get(1).getUpdatedGroup().getGroupId().getValue().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } @Test public void testAddGroupsBatch_success() throws Exception { - Mockito.when(salGroupService.addGroup(Mockito.any())) + when(addGroup.invoke(any())) .thenReturn(RpcResultBuilder.success(new AddGroupOutputBuilder().build()).buildFuture()); - final AddGroupsBatchInput input = new AddGroupsBatchInputBuilder() + final var input = new AddGroupsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) .setBatchAddGroups(BindingMap.ordered( @@ -188,29 +188,29 @@ public class SalGroupsBatchServiceImplTest { createEmptyBatchAddGroup(43L))) .build(); - final Future> resultFuture = salGroupsBatchService.addGroupsBatch(input); + final var resultFuture = addGroupsBatch.invoke(input); - Assert.assertTrue(resultFuture.isDone()); - Assert.assertTrue(resultFuture.get().isSuccessful()); + assertTrue(resultFuture.isDone()); + assertTrue(resultFuture.get().isSuccessful()); - final InOrder inOrder = Mockito.inOrder(salGroupService, transactionService); - inOrder.verify(salGroupService, Mockito.times(2)).addGroup(addGroupInputCpt.capture()); - final List allValues = addGroupInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42L, allValues.get(0).getGroupId().getValue().longValue()); - Assert.assertEquals(43L, allValues.get(1).getGroupId().getValue().longValue()); + final var inOrder = inOrder(addGroup, sendBarrier); + inOrder.verify(addGroup, times(2)).invoke(addGroupInputCpt.capture()); + final var allValues = addGroupInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42L, allValues.get(0).getGroupId().getValue().longValue()); + assertEquals(43L, allValues.get(1).getGroupId().getValue().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } @Test public void testAddGroupsBatch_failure() throws Exception { - Mockito.when(salGroupService.addGroup(Mockito.any())) + when(addGroup.invoke(any())) .thenReturn(RpcResultBuilder.failed() .withError(ErrorType.APPLICATION, "ut-groupAddError") .buildFuture()); - final AddGroupsBatchInput input = new AddGroupsBatchInputBuilder() + final var input = new AddGroupsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) .setBatchAddGroups(BindingMap.ordered( @@ -218,34 +218,33 @@ public class SalGroupsBatchServiceImplTest { createEmptyBatchAddGroup(43L))) .build(); - final Future> resultFuture = salGroupsBatchService.addGroupsBatch(input); - Iterator iterator = resultFuture.get().getResult().nonnullBatchFailedGroupsOutput() - .values().iterator(); + final var resultFuture = addGroupsBatch.invoke(input); + final var iterator = resultFuture.get().getResult().nonnullBatchFailedGroupsOutput().values().iterator(); - Assert.assertTrue(resultFuture.isDone()); - Assert.assertFalse(resultFuture.get().isSuccessful()); - Assert.assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedGroupsOutput().size()); - Assert.assertEquals(42L, iterator.next().getGroupId().getValue().longValue()); - Assert.assertEquals(43L, iterator.next().getGroupId().getValue().longValue()); - Assert.assertEquals(2, resultFuture.get().getErrors().size()); + assertTrue(resultFuture.isDone()); + assertFalse(resultFuture.get().isSuccessful()); + assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedGroupsOutput().size()); + assertEquals(42L, iterator.next().getGroupId().getValue().longValue()); + assertEquals(43L, iterator.next().getGroupId().getValue().longValue()); + assertEquals(2, resultFuture.get().getErrors().size()); - final InOrder inOrder = Mockito.inOrder(salGroupService, transactionService); - inOrder.verify(salGroupService, Mockito.times(2)).addGroup(addGroupInputCpt.capture()); - final List allValues = addGroupInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42L, allValues.get(0).getGroupId().getValue().longValue()); - Assert.assertEquals(43L, allValues.get(1).getGroupId().getValue().longValue()); + final var inOrder = inOrder(addGroup, sendBarrier); + inOrder.verify(addGroup, times(2)).invoke(addGroupInputCpt.capture()); + final var allValues = addGroupInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42L, allValues.get(0).getGroupId().getValue().longValue()); + assertEquals(43L, allValues.get(1).getGroupId().getValue().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } @Test public void testRemoveGroupsBatch_success() throws Exception { - Mockito.when(salGroupService.removeGroup(Mockito.any())) + when(removeGroup.invoke(any())) .thenReturn(RpcResultBuilder.success(new RemoveGroupOutputBuilder().build()).buildFuture()); - final RemoveGroupsBatchInput input = new RemoveGroupsBatchInputBuilder() + final var input = new RemoveGroupsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) .setBatchRemoveGroups(BindingMap.ordered( @@ -253,30 +252,30 @@ public class SalGroupsBatchServiceImplTest { createEmptyBatchRemoveGroup(43L))) .build(); - final Future> resultFuture = salGroupsBatchService.removeGroupsBatch(input); + final var resultFuture = removeGroupsBatch.invoke(input); - Assert.assertTrue(resultFuture.isDone()); - Assert.assertTrue(resultFuture.get().isSuccessful()); + assertTrue(resultFuture.isDone()); + assertTrue(resultFuture.get().isSuccessful()); - final InOrder inOrder = Mockito.inOrder(salGroupService, transactionService); + final var inOrder = inOrder(removeGroup, sendBarrier); - inOrder.verify(salGroupService, Mockito.times(2)).removeGroup(removeGroupInputCpt.capture()); - final List allValues = removeGroupInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42L, allValues.get(0).getGroupId().getValue().longValue()); - Assert.assertEquals(43L, allValues.get(1).getGroupId().getValue().longValue()); + inOrder.verify(removeGroup, times(2)).invoke(removeGroupInputCpt.capture()); + final var allValues = removeGroupInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42L, allValues.get(0).getGroupId().getValue().longValue()); + assertEquals(43L, allValues.get(1).getGroupId().getValue().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } @Test public void testRemoveGroupsBatch_failure() throws Exception { - Mockito.when(salGroupService.removeGroup(Mockito.any())) + when(removeGroup.invoke(any())) .thenReturn(RpcResultBuilder.failed() .withError(ErrorType.APPLICATION, "ut-groupRemoveError") .buildFuture()); - final RemoveGroupsBatchInput input = new RemoveGroupsBatchInputBuilder() + final var input = new RemoveGroupsBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) .setBatchRemoveGroups(BindingMap.ordered( @@ -284,26 +283,25 @@ public class SalGroupsBatchServiceImplTest { createEmptyBatchRemoveGroup(43L))) .build(); - final Future> resultFuture = salGroupsBatchService.removeGroupsBatch(input); - Iterator iterator = resultFuture.get().getResult().nonnullBatchFailedGroupsOutput() - .values().iterator(); + final var resultFuture = removeGroupsBatch.invoke(input); + final var iterator = resultFuture.get().getResult().nonnullBatchFailedGroupsOutput().values().iterator(); - Assert.assertTrue(resultFuture.isDone()); - Assert.assertFalse(resultFuture.get().isSuccessful()); - Assert.assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedGroupsOutput().size()); - Assert.assertEquals(42L, iterator.next().getGroupId().getValue().longValue()); - Assert.assertEquals(43L, iterator.next().getGroupId().getValue().longValue()); - Assert.assertEquals(2, resultFuture.get().getErrors().size()); + assertTrue(resultFuture.isDone()); + assertFalse(resultFuture.get().isSuccessful()); + assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedGroupsOutput().size()); + assertEquals(42L, iterator.next().getGroupId().getValue().longValue()); + assertEquals(43L, iterator.next().getGroupId().getValue().longValue()); + assertEquals(2, resultFuture.get().getErrors().size()); - final InOrder inOrder = Mockito.inOrder(salGroupService, transactionService); + final var inOrder = inOrder(removeGroup, sendBarrier); - inOrder.verify(salGroupService, Mockito.times(2)).removeGroup(removeGroupInputCpt.capture()); - final List allValues = removeGroupInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42L, allValues.get(0).getGroupId().getValue().longValue()); - Assert.assertEquals(43L, allValues.get(1).getGroupId().getValue().longValue()); + inOrder.verify(removeGroup, times(2)).invoke(removeGroupInputCpt.capture()); + final var allValues = removeGroupInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42L, allValues.get(0).getGroupId().getValue().longValue()); + assertEquals(43L, allValues.get(1).getGroupId().getValue().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } private static BatchAddGroups createEmptyBatchAddGroup(final long groupIdValue) { diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalMeterServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalMeterServiceImplTest.java index 59b2f34e36..45e8065787 100755 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalMeterServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalMeterServiceImplTest.java @@ -13,84 +13,57 @@ import org.junit.Test; import org.mockito.Mock; import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry; import org.opendaylight.openflowplugin.impl.services.ServiceMocking; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.OriginalMeter; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.OriginalMeterBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeter; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeterBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId; import org.opendaylight.yangtools.yang.common.Uint32; public class SalMeterServiceImplTest extends ServiceMocking { - private static final Uint32 DUMMY_METER_ID = Uint32.valueOf(15); private static final Uint32 DUMMY_METTER_ID = Uint32.valueOf(2000); @Mock - DeviceMeterRegistry mockedDeviceMeterRegistry; + private DeviceMeterRegistry mockedDeviceMeterRegistry; - SalMeterServiceImpl salMeterService; + private AddMeterImpl addMeter; + private RemoveMeterImpl removeMeter; + private UpdateMeterImpl updateMeter; @Override protected void setup() { - final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager(); - salMeterService = new SalMeterServiceImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager); + final var convertorManager = ConvertorManagerFactory.createDefaultManager(); + addMeter = new AddMeterImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager); + removeMeter = new RemoveMeterImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager); + updateMeter = new UpdateMeterImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager); } @Test public void testAddMeter() { - addMeter(); - } - - - private void addMeter() { - final MeterId dummyMeterId = new MeterId(DUMMY_METER_ID); - AddMeterInput addMeterInput = new AddMeterInputBuilder().setMeterId(dummyMeterId).build(); this.mockSuccessfulFuture(); - salMeterService.addMeter(addMeterInput); + addMeter.invoke(new AddMeterInputBuilder().setMeterId(new MeterId(DUMMY_METER_ID)).build()); verify(mockedRequestContextStack).createRequestContext(); } @Test public void testUpdateMeter() { - updateMeter(); - } - - - private void updateMeter() { - final UpdatedMeter dummyUpdatedMeter = - new UpdatedMeterBuilder().setMeterId(new MeterId(DUMMY_METTER_ID)).build(); - final OriginalMeter dummyOriginalMeter = - new OriginalMeterBuilder().setMeterId(new MeterId(DUMMY_METTER_ID)).build(); - - final UpdateMeterInput updateMeterInput = new UpdateMeterInputBuilder() - .setUpdatedMeter(dummyUpdatedMeter).setOriginalMeter(dummyOriginalMeter).build(); - this.mockSuccessfulFuture(); - salMeterService.updateMeter(updateMeterInput); + updateMeter.invoke(new UpdateMeterInputBuilder() + .setUpdatedMeter(new UpdatedMeterBuilder().setMeterId(new MeterId(DUMMY_METTER_ID)).build()) + .setOriginalMeter(new OriginalMeterBuilder().setMeterId(new MeterId(DUMMY_METTER_ID)).build()) + .build()); verify(mockedRequestContextStack).createRequestContext(); } @Test public void testRemoveMeter() { - removeMeter(); - } - - - private void removeMeter() { - final MeterId dummyMeterId = new MeterId(DUMMY_METER_ID); - RemoveMeterInput removeMeterInput = new RemoveMeterInputBuilder().setMeterId(dummyMeterId).build(); this.mockSuccessfulFuture(); - salMeterService.removeMeter(removeMeterInput); + removeMeter.invoke(new RemoveMeterInputBuilder().setMeterId(new MeterId(DUMMY_METER_ID)).build()); verify(mockedRequestContextStack).createRequestContext(); } } \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalMetersBatchServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalMetersBatchServiceImplTest.java index 1789fcc355..7a2b02f1ac 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalMetersBatchServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalMetersBatchServiceImplTest.java @@ -5,59 +5,53 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.openflowplugin.impl.services.sal; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.inOrder; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; -import com.google.common.collect.Lists; -import java.util.Iterator; import java.util.List; -import java.util.concurrent.Future; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; -import org.mockito.ArgumentMatchers; import org.mockito.Captor; -import org.mockito.InOrder; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeter; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeter; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeter; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.AddMetersBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.RemoveMetersBatchOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.add.meters.batch.input.BatchAddMeters; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.add.meters.batch.input.BatchAddMetersBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.batch.meter.input.update.grouping.OriginalBatchedMeterBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.batch.meter.input.update.grouping.UpdatedBatchedMeterBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.batch.meter.output.list.grouping.BatchFailedMetersOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.remove.meters.batch.input.BatchRemoveMeters; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.remove.meters.batch.input.BatchRemoveMetersBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.update.meters.batch.input.BatchUpdateMeters; @@ -65,7 +59,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.up import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.util.BindingMap; import org.opendaylight.yangtools.yang.common.ErrorType; -import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.opendaylight.yangtools.yang.common.Uint32; @@ -74,16 +67,19 @@ import org.opendaylight.yangtools.yang.common.Uint32; */ @RunWith(MockitoJUnitRunner.class) public class SalMetersBatchServiceImplTest { - public static final NodeId NODE_ID = new NodeId("ut-dummy-node"); public static final NodeKey NODE_KEY = new NodeKey(NODE_ID); public static final NodeRef NODE_REF = new NodeRef(InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY)); @Mock - private SalMeterService salMeterService; + private AddMeter addMeter; + @Mock + private RemoveMeter removeMeter; + @Mock + private UpdateMeter updateMeter; @Mock - private FlowCapableTransactionService transactionService; + private SendBarrier sendBarrier; @Captor private ArgumentCaptor removeMeterInputCpt; @Captor @@ -91,97 +87,99 @@ public class SalMetersBatchServiceImplTest { @Captor private ArgumentCaptor addMeterInputCpt; - private SalMetersBatchServiceImpl salMetersBatchService; + private AddMetersBatchImpl addMetersBatch; + private RemoveMetersBatchImpl removeMetersBatch; + private UpdateMetersBatchImpl updateMetersBatch; @Before public void setUp() { - salMetersBatchService = new SalMetersBatchServiceImpl(salMeterService, transactionService); + addMetersBatch = new AddMetersBatchImpl(addMeter, sendBarrier); + removeMetersBatch = new RemoveMetersBatchImpl(removeMeter, sendBarrier); + updateMetersBatch = new UpdateMetersBatchImpl(updateMeter, sendBarrier); - Mockito.when(transactionService.sendBarrier(any())) - .thenReturn(RpcResultBuilder.success().buildFuture()); + when(sendBarrier.invoke(any())).thenReturn(RpcResultBuilder.success().buildFuture()); } @After public void tearDown() { - Mockito.verifyNoMoreInteractions(salMeterService, transactionService); + verifyNoMoreInteractions(addMeter, removeMeter, updateMeter, sendBarrier); } @Test public void testUpdateMetersBatch_success() throws Exception { - Mockito.when(salMeterService.updateMeter(Mockito.any())) + when(updateMeter.invoke(any())) .thenReturn(RpcResultBuilder.success(new UpdateMeterOutputBuilder().build()).buildFuture()); - final UpdateMetersBatchInput input = new UpdateMetersBatchInputBuilder() + final var input = new UpdateMetersBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) - .setBatchUpdateMeters(Lists.newArrayList( + .setBatchUpdateMeters(List.of( createEmptyBatchUpdateMeter(42L), createEmptyBatchUpdateMeter(44L))) .build(); - final Future> resultFuture = salMetersBatchService.updateMetersBatch(input); + final var resultFuture = updateMetersBatch.invoke(input); - Assert.assertTrue(resultFuture.isDone()); - Assert.assertTrue(resultFuture.get().isSuccessful()); + assertTrue(resultFuture.isDone()); + assertTrue(resultFuture.get().isSuccessful()); - final InOrder inOrder = Mockito.inOrder(salMeterService, transactionService); - inOrder.verify(salMeterService, Mockito.times(2)).updateMeter(updateMeterInputCpt.capture()); - final List allValues = updateMeterInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42, allValues.get(0).getOriginalMeter().getMeterId().getValue().longValue()); - Assert.assertEquals(43, allValues.get(0).getUpdatedMeter().getMeterId().getValue().longValue()); - Assert.assertEquals(44, allValues.get(1).getOriginalMeter().getMeterId().getValue().longValue()); - Assert.assertEquals(45, allValues.get(1).getUpdatedMeter().getMeterId().getValue().longValue()); + final var inOrder = inOrder(updateMeter, sendBarrier); + inOrder.verify(updateMeter, times(2)).invoke(updateMeterInputCpt.capture()); + final var allValues = updateMeterInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42, allValues.get(0).getOriginalMeter().getMeterId().getValue().longValue()); + assertEquals(43, allValues.get(0).getUpdatedMeter().getMeterId().getValue().longValue()); + assertEquals(44, allValues.get(1).getOriginalMeter().getMeterId().getValue().longValue()); + assertEquals(45, allValues.get(1).getUpdatedMeter().getMeterId().getValue().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } @Test public void testUpdateMetersBatch_failure() throws Exception { - Mockito.when(salMeterService.updateMeter(Mockito.any())) + when(updateMeter.invoke(any())) .thenReturn(RpcResultBuilder.failed() .withError(ErrorType.APPLICATION, "ur-groupUpdateError") .buildFuture()); - final UpdateMetersBatchInput input = new UpdateMetersBatchInputBuilder() + final var input = new UpdateMetersBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) - .setBatchUpdateMeters(Lists.newArrayList( + .setBatchUpdateMeters(List.of( createEmptyBatchUpdateMeter(42L), createEmptyBatchUpdateMeter(44L))) .build(); - final Future> resultFuture = salMetersBatchService.updateMetersBatch(input); - Iterator iterator = resultFuture.get().getResult().nonnullBatchFailedMetersOutput() + final var resultFuture = updateMetersBatch.invoke(input); + final var iterator = resultFuture.get().getResult().nonnullBatchFailedMetersOutput() .values().iterator(); - Assert.assertTrue(resultFuture.isDone()); - Assert.assertFalse(resultFuture.get().isSuccessful()); - Assert.assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedMetersOutput().size()); - Assert.assertEquals(43L, iterator.next().getMeterId().getValue().longValue()); - Assert.assertEquals(45L,iterator.next().getMeterId().getValue().longValue()); - Assert.assertEquals(2, resultFuture.get().getErrors().size()); + assertTrue(resultFuture.isDone()); + assertFalse(resultFuture.get().isSuccessful()); + assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedMetersOutput().size()); + assertEquals(43L, iterator.next().getMeterId().getValue().longValue()); + assertEquals(45L,iterator.next().getMeterId().getValue().longValue()); + assertEquals(2, resultFuture.get().getErrors().size()); - final InOrder inOrder = Mockito.inOrder(salMeterService, transactionService); - inOrder.verify(salMeterService, Mockito.times(2)).updateMeter(updateMeterInputCpt.capture()); - final List allValues = updateMeterInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42, allValues.get(0).getOriginalMeter().getMeterId().getValue().longValue()); - Assert.assertEquals(43, allValues.get(0).getUpdatedMeter().getMeterId().getValue().longValue()); - Assert.assertEquals(44, allValues.get(1).getOriginalMeter().getMeterId().getValue().longValue()); - Assert.assertEquals(45, allValues.get(1).getUpdatedMeter().getMeterId().getValue().longValue()); + final var inOrder = inOrder(updateMeter, sendBarrier); + inOrder.verify(updateMeter, times(2)).invoke(updateMeterInputCpt.capture()); + final var allValues = updateMeterInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42, allValues.get(0).getOriginalMeter().getMeterId().getValue().longValue()); + assertEquals(43, allValues.get(0).getUpdatedMeter().getMeterId().getValue().longValue()); + assertEquals(44, allValues.get(1).getOriginalMeter().getMeterId().getValue().longValue()); + assertEquals(45, allValues.get(1).getUpdatedMeter().getMeterId().getValue().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } - @Test public void testAddMetersBatch_success() throws Exception { - Mockito.when(salMeterService.addMeter(Mockito.any())) + when(addMeter.invoke(any())) .thenReturn(RpcResultBuilder.success(new AddMeterOutputBuilder().build()).buildFuture()); - final AddMetersBatchInput input = new AddMetersBatchInputBuilder() + final var input = new AddMetersBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) .setBatchAddMeters(BindingMap.ordered( @@ -189,29 +187,29 @@ public class SalMetersBatchServiceImplTest { createEmptyBatchAddMeter(43L))) .build(); - final Future> resultFuture = salMetersBatchService.addMetersBatch(input); + final var resultFuture = addMetersBatch.invoke(input); - Assert.assertTrue(resultFuture.isDone()); - Assert.assertTrue(resultFuture.get().isSuccessful()); + assertTrue(resultFuture.isDone()); + assertTrue(resultFuture.get().isSuccessful()); - final InOrder inOrder = Mockito.inOrder(salMeterService, transactionService); - inOrder.verify(salMeterService, Mockito.times(2)).addMeter(addMeterInputCpt.capture()); - final List allValues = addMeterInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42L, allValues.get(0).getMeterId().getValue().longValue()); - Assert.assertEquals(43L, allValues.get(1).getMeterId().getValue().longValue()); + final var inOrder = inOrder(addMeter, sendBarrier); + inOrder.verify(addMeter, times(2)).invoke(addMeterInputCpt.capture()); + final var allValues = addMeterInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42L, allValues.get(0).getMeterId().getValue().longValue()); + assertEquals(43L, allValues.get(1).getMeterId().getValue().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } @Test public void testAddMetersBatch_failure() throws Exception { - Mockito.when(salMeterService.addMeter(Mockito.any())) + when(addMeter.invoke(any())) .thenReturn(RpcResultBuilder.failed() .withError(ErrorType.APPLICATION, "ut-groupAddError") .buildFuture()); - final AddMetersBatchInput input = new AddMetersBatchInputBuilder() + final var input = new AddMetersBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) .setBatchAddMeters(BindingMap.ordered( @@ -219,34 +217,33 @@ public class SalMetersBatchServiceImplTest { createEmptyBatchAddMeter(43L))) .build(); - final Future> resultFuture = salMetersBatchService.addMetersBatch(input); - Iterator iterator = resultFuture.get().getResult().nonnullBatchFailedMetersOutput() - .values().iterator(); + final var resultFuture = addMetersBatch.invoke(input); + final var iterator = resultFuture.get().getResult().nonnullBatchFailedMetersOutput().values().iterator(); - Assert.assertTrue(resultFuture.isDone()); - Assert.assertFalse(resultFuture.get().isSuccessful()); - Assert.assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedMetersOutput().size()); - Assert.assertEquals(42L, iterator.next().getMeterId().getValue().longValue()); - Assert.assertEquals(43L,iterator.next().getMeterId().getValue().longValue()); - Assert.assertEquals(2, resultFuture.get().getErrors().size()); + assertTrue(resultFuture.isDone()); + assertFalse(resultFuture.get().isSuccessful()); + assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedMetersOutput().size()); + assertEquals(42L, iterator.next().getMeterId().getValue().longValue()); + assertEquals(43L,iterator.next().getMeterId().getValue().longValue()); + assertEquals(2, resultFuture.get().getErrors().size()); - final InOrder inOrder = Mockito.inOrder(salMeterService, transactionService); - inOrder.verify(salMeterService, Mockito.times(2)).addMeter(addMeterInputCpt.capture()); - final List allValues = addMeterInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42L, allValues.get(0).getMeterId().getValue().longValue()); - Assert.assertEquals(43L, allValues.get(1).getMeterId().getValue().longValue()); + final var inOrder = inOrder(addMeter, sendBarrier); + inOrder.verify(addMeter, times(2)).invoke(addMeterInputCpt.capture()); + final var allValues = addMeterInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42L, allValues.get(0).getMeterId().getValue().longValue()); + assertEquals(43L, allValues.get(1).getMeterId().getValue().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } @Test public void testRemoveMetersBatch_success() throws Exception { - Mockito.when(salMeterService.removeMeter(Mockito.any())) + when(removeMeter.invoke(any())) .thenReturn(RpcResultBuilder.success(new RemoveMeterOutputBuilder().build()).buildFuture()); - final RemoveMetersBatchInput input = new RemoveMetersBatchInputBuilder() + final var input = new RemoveMetersBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) .setBatchRemoveMeters(BindingMap.ordered( @@ -254,30 +251,30 @@ public class SalMetersBatchServiceImplTest { createEmptyBatchRemoveMeter(43L))) .build(); - final Future> resultFuture = salMetersBatchService.removeMetersBatch(input); + final var resultFuture = removeMetersBatch.invoke(input); - Assert.assertTrue(resultFuture.isDone()); - Assert.assertTrue(resultFuture.get().isSuccessful()); + assertTrue(resultFuture.isDone()); + assertTrue(resultFuture.get().isSuccessful()); - final InOrder inOrder = Mockito.inOrder(salMeterService, transactionService); + final var inOrder = inOrder(removeMeter, sendBarrier); - inOrder.verify(salMeterService, Mockito.times(2)).removeMeter(removeMeterInputCpt.capture()); - final List allValues = removeMeterInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42L, allValues.get(0).getMeterId().getValue().longValue()); - Assert.assertEquals(43L, allValues.get(1).getMeterId().getValue().longValue()); + inOrder.verify(removeMeter, times(2)).invoke(removeMeterInputCpt.capture()); + final var allValues = removeMeterInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42L, allValues.get(0).getMeterId().getValue().longValue()); + assertEquals(43L, allValues.get(1).getMeterId().getValue().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } @Test public void testRemoveMetersBatch_failure() throws Exception { - Mockito.when(salMeterService.removeMeter(Mockito.any())) + when(removeMeter.invoke(any())) .thenReturn(RpcResultBuilder.failed() .withError(ErrorType.APPLICATION, "ut-groupRemoveError") .buildFuture()); - final RemoveMetersBatchInput input = new RemoveMetersBatchInputBuilder() + final var input = new RemoveMetersBatchInputBuilder() .setNode(NODE_REF) .setBarrierAfter(true) .setBatchRemoveMeters(BindingMap.ordered( @@ -285,26 +282,25 @@ public class SalMetersBatchServiceImplTest { createEmptyBatchRemoveMeter(43L))) .build(); - final Future> resultFuture = salMetersBatchService.removeMetersBatch(input); - Iterator iterator = resultFuture.get().getResult().nonnullBatchFailedMetersOutput() - .values().iterator(); + final var resultFuture = removeMetersBatch.invoke(input); + final var iterator = resultFuture.get().getResult().nonnullBatchFailedMetersOutput().values().iterator(); - Assert.assertTrue(resultFuture.isDone()); - Assert.assertFalse(resultFuture.get().isSuccessful()); - Assert.assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedMetersOutput().size()); - Assert.assertEquals(42L, iterator.next().getMeterId().getValue().longValue()); - Assert.assertEquals(43L, iterator.next().getMeterId().getValue().longValue()); - Assert.assertEquals(2, resultFuture.get().getErrors().size()); + assertTrue(resultFuture.isDone()); + assertFalse(resultFuture.get().isSuccessful()); + assertEquals(2, resultFuture.get().getResult().nonnullBatchFailedMetersOutput().size()); + assertEquals(42L, iterator.next().getMeterId().getValue().longValue()); + assertEquals(43L, iterator.next().getMeterId().getValue().longValue()); + assertEquals(2, resultFuture.get().getErrors().size()); - final InOrder inOrder = Mockito.inOrder(salMeterService, transactionService); + final var inOrder = inOrder(removeMeter, sendBarrier); - inOrder.verify(salMeterService, Mockito.times(2)).removeMeter(removeMeterInputCpt.capture()); - final List allValues = removeMeterInputCpt.getAllValues(); - Assert.assertEquals(2, allValues.size()); - Assert.assertEquals(42L, allValues.get(0).getMeterId().getValue().longValue()); - Assert.assertEquals(43L, allValues.get(1).getMeterId().getValue().longValue()); + inOrder.verify(removeMeter, times(2)).invoke(removeMeterInputCpt.capture()); + final var allValues = removeMeterInputCpt.getAllValues(); + assertEquals(2, allValues.size()); + assertEquals(42L, allValues.get(0).getMeterId().getValue().longValue()); + assertEquals(43L, allValues.get(1).getMeterId().getValue().longValue()); - inOrder.verify(transactionService).sendBarrier(ArgumentMatchers.any()); + inOrder.verify(sendBarrier).invoke(any()); } private static BatchAddMeters createEmptyBatchAddMeter(final long groupIdValue) { diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/FlowCapableTransactionServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SendBarrierImplTest.java similarity index 61% rename from openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/FlowCapableTransactionServiceImplTest.java rename to openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SendBarrierImplTest.java index 4f07efbaaa..a2c28194e4 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/FlowCapableTransactionServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SendBarrierImplTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.verify; +import org.eclipse.jdt.annotation.NonNull; import org.junit.Test; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.impl.services.ServiceMocking; @@ -18,41 +19,35 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304. import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yangtools.yang.common.Uint32; /** - * Test for {@link FlowCapableTransactionServiceImpl}. + * Test for {@link SendBarrierImpl}. */ -public class FlowCapableTransactionServiceImplTest extends ServiceMocking { - +public class SendBarrierImplTest extends ServiceMocking { private static final Uint32 DUMMY_XID_VALUE = Uint32.valueOf(100); - FlowCapableTransactionServiceImpl flowCapableTransactionService; + + private SendBarrierImpl sendBarrier; @Override protected void setup() { - flowCapableTransactionService = - new FlowCapableTransactionServiceImpl(mockedRequestContextStack, mockedDeviceContext); + sendBarrier = new SendBarrierImpl(mockedRequestContextStack, mockedDeviceContext); } @Test public void testBuildRequest() { - SendBarrierInput sendBarrierInput = buildSendBarrierInput(); - - final OfHeader request = flowCapableTransactionService.buildRequest(new Xid(DUMMY_XID_VALUE), sendBarrierInput); + final var request = sendBarrier.buildRequest(new Xid(DUMMY_XID_VALUE), buildSendBarrierInput()); assertEquals(DUMMY_XID_VALUE, request.getXid()); assertTrue(request instanceof BarrierInput); } @Test public void testSendBarrier() { - SendBarrierInput sendBarrierInput = buildSendBarrierInput(); - flowCapableTransactionService.sendBarrier(sendBarrierInput); + sendBarrier.invoke(buildSendBarrierInput()); verify(mockedRequestContextStack).createRequestContext(); } - private SendBarrierInput buildSendBarrierInput() { - return new SendBarrierInputBuilder() - .setNode(new NodeRef(mockedDeviceInfo.getNodeInstanceIdentifier())).build(); + private @NonNull SendBarrierInput buildSendBarrierInput() { + return new SendBarrierInputBuilder().setNode(new NodeRef(mockedDeviceInfo.getNodeInstanceIdentifier())).build(); } } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalExperimenterMessageServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SendExperimenterImplTest.java similarity index 58% rename from openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalExperimenterMessageServiceImplTest.java rename to openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SendExperimenterImplTest.java index 343582f415..59095ce5be 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalExperimenterMessageServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SendExperimenterImplTest.java @@ -5,18 +5,18 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.openflowplugin.impl.services.sal; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import org.junit.Test; import org.mockito.ArgumentMatchers; import org.mockito.Mock; -import org.mockito.Mockito; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.extension.api.ConverterMessageToOFJava; import org.opendaylight.openflowplugin.extension.api.ExtensionConvertorData; @@ -28,59 +28,57 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.servic import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice; import org.opendaylight.yangtools.yang.common.Uint32; /** - * Test for {@link org.opendaylight.openflowplugin.impl.services.sal.SalExperimenterMessageServiceImpl}. + * Test for {@link SendExperimenterImpl}. */ -public class SalExperimenterMessageServiceImplTest extends ServiceMocking { - +public class SendExperimenterImplTest extends ServiceMocking { private static final Uint32 DUMMY_XID_VALUE = Uint32.valueOf(100); - private SalExperimenterMessageServiceImpl salExperimenterMessageService; + @Mock private ExtensionConverterProvider extensionConverterProvider; @Mock private ConverterMessageToOFJava extensionConverter; + private SendExperimenterImpl sendExperimenter; + @Override protected void setup() { - salExperimenterMessageService = new SalExperimenterMessageServiceImpl(mockedRequestContextStack, - mockedDeviceContext, - extensionConverterProvider); - Mockito.when(extensionConverterProvider.getMessageConverter(ArgumentMatchers.any())) - .thenReturn(extensionConverter); - Mockito.when(extensionConverter.getExperimenterId()).thenReturn(new ExperimenterId(Uint32.valueOf(43))); - Mockito.when(extensionConverter.getType()).thenReturn(Uint32.valueOf(44)); + when(extensionConverterProvider.getMessageConverter(ArgumentMatchers.any())) + .thenReturn(extensionConverter); + when(extensionConverter.getExperimenterId()).thenReturn(new ExperimenterId(Uint32.valueOf(43))); + when(extensionConverter.getType()).thenReturn(Uint32.valueOf(44)); + + sendExperimenter = new SendExperimenterImpl(mockedRequestContextStack, mockedDeviceContext, + extensionConverterProvider); } @Test public void testSendExperimenter() { - SendExperimenterInput sendExperimenterInput = buildSendExperimenterInput(); - salExperimenterMessageService.sendExperimenter(sendExperimenterInput); + sendExperimenter.invoke(buildSendExperimenterInput()); verify(mockedRequestContextStack).createRequestContext(); } @Test public void testBuildRequest() throws Exception { - SendExperimenterInput sendExperimenterInput = buildSendExperimenterInput(); - final OfHeader request = - salExperimenterMessageService.buildRequest(new Xid(DUMMY_XID_VALUE), sendExperimenterInput); + final var sendExperimenterInput = buildSendExperimenterInput(); + final var request = sendExperimenter.buildRequest(new Xid(DUMMY_XID_VALUE), sendExperimenterInput); assertEquals(DUMMY_XID_VALUE, request.getXid()); assertTrue(request instanceof ExperimenterInput); - final ExperimenterInput input = (ExperimenterInput) request; + final var input = (ExperimenterInput) request; assertEquals(43L, input.getExperimenter().getValue().longValue()); assertEquals(44L, input.getExpType().longValue()); - Mockito.verify(extensionConverter).convert(eq(sendExperimenterInput.getExperimenterMessageOfChoice()), - ArgumentMatchers.any(ExtensionConvertorData.class)); + verify(extensionConverter).convert(eq(sendExperimenterInput.getExperimenterMessageOfChoice()), + any(ExtensionConvertorData.class)); } private SendExperimenterInput buildSendExperimenterInput() { - SendExperimenterInputBuilder sendExperimenterInputBld = new SendExperimenterInputBuilder() - .setNode(new NodeRef(mockedDeviceInfo.getNodeInstanceIdentifier())) - .setExperimenterMessageOfChoice(new DummyExperimenter()); - return sendExperimenterInputBld.build(); + return new SendExperimenterInputBuilder() + .setNode(new NodeRef(mockedDeviceInfo.getNodeInstanceIdentifier())) + .setExperimenterMessageOfChoice(new DummyExperimenter()) + .build(); } private static final class DummyExperimenter implements ExperimenterMessageOfChoice { diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalExperimenterMpMessageServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SendExperimenterMpRequestImplTest.java similarity index 56% rename from openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalExperimenterMpMessageServiceImplTest.java rename to openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SendExperimenterMpRequestImplTest.java index 47fcbea795..15b692e07d 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalExperimenterMpMessageServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SendExperimenterMpRequestImplTest.java @@ -5,7 +5,6 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.openflowplugin.impl.services.sal; import static org.mockito.Mockito.verify; @@ -13,32 +12,27 @@ import static org.mockito.Mockito.verify; import java.util.List; import org.junit.Test; import org.opendaylight.openflowplugin.impl.services.ServiceMocking; -import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; -public class SalExperimenterMpMessageServiceImplTest extends ServiceMocking { - private SalExperimenterMpMessageServiceImpl salExperimenterMpMessageService; +public class SendExperimenterMpRequestImplTest extends ServiceMocking { + private SendExperimenterMpRequestImpl sendExperimenterMpRequest; @Override protected void setup() { this.>mockSuccessfulFuture(); - salExperimenterMpMessageService = new SalExperimenterMpMessageServiceImpl( - mockedRequestContextStack, - mockedDeviceContext, - mockedExtensionConverterProvider); + sendExperimenterMpRequest = new SendExperimenterMpRequestImpl(mockedRequestContextStack, mockedDeviceContext, + mockedExtensionConverterProvider); } @Test public void sendExperimenterMpRequest() { - final SendExperimenterMpRequestInput data = new SendExperimenterMpRequestInputBuilder() - .setExperimenterMessageOfChoice(mockExperimenter()) - .setNode(new NodeRef(mockedDeviceInfo.getNodeInstanceIdentifier())) - .build(); - - salExperimenterMpMessageService.sendExperimenterMpRequest(data); + sendExperimenterMpRequest.invoke(new SendExperimenterMpRequestInputBuilder() + .setExperimenterMessageOfChoice(mockExperimenter()) + .setNode(new NodeRef(mockedDeviceInfo.getNodeInstanceIdentifier())) + .build()); verify(mockedRequestContextStack).createRequestContext(); } } \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/NodeConfigServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SetConfigImplTest.java similarity index 72% rename from openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/NodeConfigServiceImplTest.java rename to openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SetConfigImplTest.java index 12d79e5646..df19621333 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/NodeConfigServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SetConfigImplTest.java @@ -17,29 +17,28 @@ import org.opendaylight.openflowplugin.impl.services.ServiceMocking; import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yangtools.yang.common.Uint16; import org.opendaylight.yangtools.yang.common.Uint32; -public class NodeConfigServiceImplTest extends ServiceMocking { - +public class SetConfigImplTest extends ServiceMocking { private static final Uint32 DUMMY_XID_VALUE = Uint32.valueOf(150); private static final SwitchConfigFlag DUMMY_FLAG = SwitchConfigFlag.FRAGNORMAL; private static final String DUMMY_FLAG_STR = "FRAGNORMAL"; private static final Uint16 DUMMY_MISS_SEARCH_LENGTH = Uint16.valueOf(3000); - NodeConfigServiceImpl nodeConfigService; + + private SetConfigImpl setConfig; @Test public void testSetConfig() { - nodeConfigService = new NodeConfigServiceImpl(mockedRequestContextStack, mockedDeviceContext); - nodeConfigService.setConfig(dummyConfigInput()); + setConfig = new SetConfigImpl(mockedRequestContextStack, mockedDeviceContext); + setConfig.invoke(dummyConfigInput()); verify(mockedRequestContextStack).createRequestContext(); } @Test public void testBuildRequest() { - nodeConfigService = new NodeConfigServiceImpl(mockedRequestContextStack, mockedDeviceContext); - final OfHeader request = nodeConfigService.buildRequest(new Xid(DUMMY_XID_VALUE), dummyConfigInput()); + setConfig = new SetConfigImpl(mockedRequestContextStack, mockedDeviceContext); + final var request = setConfig.buildRequest(new Xid(DUMMY_XID_VALUE), dummyConfigInput()); assertTrue(request instanceof org.opendaylight.yang.gen.v1.urn .opendaylight.openflow.protocol.rev130731.SetConfigInput); @@ -51,9 +50,9 @@ public class NodeConfigServiceImplTest extends ServiceMocking { } private static SetConfigInput dummyConfigInput() { - SetConfigInputBuilder setConfigInputBuilder = new SetConfigInputBuilder(); - setConfigInputBuilder.setFlag(DUMMY_FLAG_STR); - setConfigInputBuilder.setMissSearchLength(DUMMY_MISS_SEARCH_LENGTH); - return setConfigInputBuilder.build(); + return new SetConfigInputBuilder() + .setFlag(DUMMY_FLAG_STR) + .setMissSearchLength(DUMMY_MISS_SEARCH_LENGTH) + .build(); } } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/PacketProcessingServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/TransmitPacketImplTest.java similarity index 64% rename from openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/PacketProcessingServiceImplTest.java rename to openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/TransmitPacketImplTest.java index 5107449ce7..ba037b6811 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/PacketProcessingServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/TransmitPacketImplTest.java @@ -16,7 +16,6 @@ import org.junit.Test; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.impl.services.ServiceMocking; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef; @@ -28,7 +27,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.No import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder; @@ -36,56 +34,51 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; import org.opendaylight.yangtools.yang.common.Uint32; /** - * Test for {@link PacketProcessingServiceImpl}. + * Test for {@link TransmitPacketImpl}. */ -public class PacketProcessingServiceImplTest extends ServiceMocking { - +public class TransmitPacketImplTest extends ServiceMocking { private static final Uint32 DUMMY_XID_VALUE = Uint32.valueOf(100); - public static final String ULTIMATE_PAYLOAD = "What do you get when you multiply six by nine?"; + private static final String ULTIMATE_PAYLOAD = "What do you get when you multiply six by nine?"; - private PacketProcessingServiceImpl packetProcessingService; + private TransmitPacketImpl transmitPacket; private KeyedInstanceIdentifier pathToNodeconnector; @Override protected void setup() { - final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager(); - packetProcessingService = - new PacketProcessingServiceImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager); + final var convertorManager = ConvertorManagerFactory.createDefaultManager(); + transmitPacket = new TransmitPacketImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager); pathToNodeconnector = KeyedInstanceIdentifier.create(Nodes.class) - .child(Node.class, new NodeKey(new NodeId("ofp-ut:123"))) - .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId("ofp-ut:123:1"))); + .child(Node.class, new NodeKey(new NodeId("ofp-ut:123"))) + .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId("ofp-ut:123:1"))); } @Test public void testTransmitPacket() { - TransmitPacketInput transmitPacketInput = buildTransmitPacketInput(); - packetProcessingService.transmitPacket(transmitPacketInput); + transmitPacket.invoke(buildTransmitPacketInput()); verify(mockedRequestContextStack).createRequestContext(); } @Test public void testBuildRequest() { - TransmitPacketInput transmitPacketInput = buildTransmitPacketInput(); - - final OfHeader request = packetProcessingService.buildRequest(new Xid(DUMMY_XID_VALUE), transmitPacketInput); + final var request = transmitPacket.buildRequest(new Xid(DUMMY_XID_VALUE), buildTransmitPacketInput()); assertEquals(DUMMY_XID_VALUE, request.getXid()); assertTrue(request instanceof PacketOutInput); - final PacketOutInput input = (PacketOutInput) request; + final var input = (PacketOutInput) request; assertEquals(OFConstants.OFP_NO_BUFFER, input.getBufferId()); assertEquals(1, input.getAction().size()); assertEquals(OutputActionCase.class, input.getAction().get(0).getActionChoice().implementedInterface()); - final OutputActionCase actionChoice = (OutputActionCase) input.getAction().get(0).getActionChoice(); + final var actionChoice = (OutputActionCase) input.getAction().get(0).getActionChoice(); assertEquals(1, actionChoice.getOutputAction().getPort().getValue().intValue()); assertEquals(ULTIMATE_PAYLOAD, new String(input.getData())); } private TransmitPacketInput buildTransmitPacketInput() { - TransmitPacketInputBuilder transmitPacketInputBld = new TransmitPacketInputBuilder() - .setBufferId(OFConstants.OFP_NO_BUFFER) - .setNode(new NodeRef(mockedDeviceInfo.getNodeInstanceIdentifier())) - .setPayload(ULTIMATE_PAYLOAD.getBytes()) - .setEgress(new NodeConnectorRef(pathToNodeconnector)); - return transmitPacketInputBld.build(); + return new TransmitPacketInputBuilder() + .setBufferId(OFConstants.OFP_NO_BUFFER) + .setNode(new NodeRef(mockedDeviceInfo.getNodeInstanceIdentifier())) + .setPayload(ULTIMATE_PAYLOAD.getBytes()) + .setEgress(new NodeConnectorRef(pathToNodeconnector)) + .build(); } } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalPortServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/UpdatePortImplTest.java similarity index 53% rename from openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalPortServiceImplTest.java rename to openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/UpdatePortImplTest.java index e137e0a1f0..118ba7df88 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalPortServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/UpdatePortImplTest.java @@ -7,6 +7,7 @@ */ package org.opendaylight.openflowplugin.impl.services.sal; +import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.verify; import org.junit.Test; @@ -14,61 +15,58 @@ import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.impl.services.ServiceMocking; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.Port; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.PortBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.port.update.UpdatedPort; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.port.update.UpdatedPortBuilder; import org.opendaylight.yangtools.yang.binding.util.BindingMap; import org.opendaylight.yangtools.yang.common.Uint32; @RunWith(MockitoJUnitRunner.class) -public class SalPortServiceImplTest extends ServiceMocking { - +public class UpdatePortImplTest extends ServiceMocking { private static final Uint32 DUMMY_XID = Uint32.valueOf(55L); private static final Uint32 DUMMY_PORT_NUMBER = Uint32.valueOf(66L); private static final String DUMMY_MAC_ADDRESS = "AA:BB:CC:DD:EE:FF"; - SalPortServiceImpl salPortService; + + private UpdatePortImpl updatePort; @Override protected void setup() { - final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager(); - salPortService = new SalPortServiceImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager); + final var convertorManager = ConvertorManagerFactory.createDefaultManager(); + updatePort = new UpdatePortImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager); } @Test public void testUpdatePort() { - salPortService.updatePort(dummyUpdatePortInput()); + updatePort.invoke(dummyUpdatePortInput()); verify(mockedRequestContextStack).createRequestContext(); } @Test public void testBuildRequest() { - final OfHeader ofHeader = salPortService.buildRequest(new Xid(DUMMY_XID), dummyUpdatePortInput()); + assertNotNull(updatePort.buildRequest(new Xid(DUMMY_XID), dummyUpdatePortInput())); } private static UpdatePortInput dummyUpdatePortInput() { - org.opendaylight.yang.gen.v1.urn - .opendaylight.flow.types.port.rev130925.port.mod.port.PortBuilder concretePortBuilder - = new org.opendaylight.yang.gen.v1.urn - .opendaylight.flow.types.port.rev130925.port.mod.port.PortBuilder(); - concretePortBuilder.setConfiguration(new PortConfig(true, true, true, true)); - concretePortBuilder.setAdvertisedFeatures(new PortFeatures(true, true, true, true, true, true, true, true, - true, true, true, true, true, true, true, true)); - concretePortBuilder.setPortNumber(new PortNumberUni(DUMMY_PORT_NUMBER)); - concretePortBuilder.setHardwareAddress(new MacAddress(DUMMY_MAC_ADDRESS)); - concretePortBuilder.setPortModOrder(Uint32.ZERO); - - Port port = new PortBuilder().setPort(BindingMap.of(concretePortBuilder.build())).build(); - UpdatedPort updatePort = new UpdatedPortBuilder().setPort(port).build(); - return new UpdatePortInputBuilder().setUpdatedPort(updatePort).build(); + return new UpdatePortInputBuilder() + .setUpdatedPort(new UpdatedPortBuilder() + .setPort(new PortBuilder() + .setPort(BindingMap.of(new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925 + .port.mod.port.PortBuilder() + .setConfiguration(new PortConfig(true, true, true, true)) + .setAdvertisedFeatures(new PortFeatures(true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true)) + .setPortNumber(new PortNumberUni(DUMMY_PORT_NUMBER)) + .setHardwareAddress(new MacAddress(DUMMY_MAC_ADDRESS)) + .setPortModOrder(Uint32.ZERO) + .build())) + .build()) + .build()) + .build(); } } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalTableServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateTableImplTest.java similarity index 94% rename from openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalTableServiceImplTest.java rename to openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateTableImplTest.java index 95e96ac22a..fadf8be174 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/SalTableServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/sal/UpdateTableImplTest.java @@ -42,13 +42,12 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.opendaylight.yangtools.yang.common.Uint32; import org.opendaylight.yangtools.yang.common.Uint8; -public class SalTableServiceImplTest extends ServiceMocking { - +public class UpdateTableImplTest extends ServiceMocking { @Mock RpcProviderService mockedRpcProviderRegistry; private SettableFuture handleResultFuture; - private SalTableServiceImpl salTableService; + private UpdateTableImpl salTableService; @Override public void setup() { @@ -61,7 +60,7 @@ public class SalTableServiceImplTest extends ServiceMocking { }).when(mockedOutboundQueue).commitEntry(any(Uint32.class), any(), any()); final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager(); - salTableService = new SalTableServiceImpl(mockedRequestContextStack, mockedDeviceContext, + salTableService = new UpdateTableImpl(mockedRequestContextStack, mockedDeviceContext, convertorManager, MultipartWriterProviderFactory.createDefaultProvider(mockedDeviceContext)); } @@ -74,7 +73,7 @@ public class SalTableServiceImplTest extends ServiceMocking { return null; }).when(multiMessageCollector).endCollecting(any()); - final Future> rpcResultFuture = salTableService.updateTable(prepareUpdateTable()); + final Future> rpcResultFuture = salTableService.invoke(prepareUpdateTable()); Assert.assertNotNull(rpcResultFuture); verify(mockedRequestContextStack).createRequestContext(); } @@ -89,7 +88,7 @@ public class SalTableServiceImplTest extends ServiceMocking { return null; }).when(multiMessageCollector).endCollecting(any()); - final Future> rpcResultFuture = salTableService.updateTable(prepareUpdateTable()); + final Future> rpcResultFuture = salTableService.invoke(prepareUpdateTable()); Assert.assertNotNull(rpcResultFuture); verify(mockedRequestContextStack).createRequestContext(); } @@ -117,7 +116,7 @@ public class SalTableServiceImplTest extends ServiceMocking { return null; }).when(multiMessageCollector).endCollecting(any()); - final Future> rpcResultFuture = salTableService.updateTable(prepareUpdateTable()); + final Future> rpcResultFuture = salTableService.invoke(prepareUpdateTable()); Assert.assertNotNull(rpcResultFuture); verify(mockedRequestContextStack).createRequestContext(); } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowTableStatisticsServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/GetFlowTablesStatisticsImplTest.java similarity index 60% rename from openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowTableStatisticsServiceImplTest.java rename to openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/GetFlowTablesStatisticsImplTest.java index 0c33acdf4b..9cbb4b6471 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowTableStatisticsServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/GetFlowTablesStatisticsImplTest.java @@ -7,68 +7,67 @@ */ package org.opendaylight.openflowplugin.impl.statistics.services; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.verify; import com.google.common.util.concurrent.FutureCallback; -import java.util.Collections; -import java.util.concurrent.Future; +import java.util.List; import java.util.concurrent.atomic.AtomicLong; -import org.junit.Assert; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.ArgumentMatchers; import org.mockito.Captor; -import org.mockito.Mockito; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTableBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCase; -import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.opendaylight.yangtools.yang.common.Uint32; import org.opendaylight.yangtools.yang.common.Uint64; import org.opendaylight.yangtools.yang.common.Uint8; /** - * Test for {@link OpendaylightFlowTableStatisticsServiceImpl}. + * Test for {@link GetFlowTablesStatisticsImpl}. */ -public class OpendaylightFlowTableStatisticsServiceImplTest extends AbstractSingleStatsServiceTest { +@Deprecated +public class GetFlowTablesStatisticsImplTest extends AbstractSingleStatsServiceTest { private static final Uint8 TABLE_ID = Uint8.valueOf(123); @Captor private ArgumentCaptor requestInput; - private OpendaylightFlowTableStatisticsServiceImpl flowTableStatisticsService; + private GetFlowTablesStatisticsImpl getFlowTablesStatistics; @Override public void setUp() { - flowTableStatisticsService = new OpendaylightFlowTableStatisticsServiceImpl(rqContextStack, deviceContext, - new AtomicLong(), notificationPublishService); + getFlowTablesStatistics = new GetFlowTablesStatisticsImpl(rqContextStack, deviceContext, new AtomicLong(), + notificationPublishService); } @Test public void testGetFlowTablesStatistics() throws Exception { - Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider) + doAnswer(answerVoidToCallback).when(outboundQueueProvider) .commitEntry(eq(Uint32.valueOf(42)), requestInput.capture(), any(FutureCallback.class)); - GetFlowTablesStatisticsInputBuilder input = new GetFlowTablesStatisticsInputBuilder() + var input = new GetFlowTablesStatisticsInputBuilder() .setNode(createNodeRef("unitProt:123")); - rpcResult = RpcResultBuilder.success(Collections.singletonList( + rpcResult = RpcResultBuilder.success(List.of( new MultipartReplyMessageBuilder() .setVersion(EncodeConstants.OF_VERSION_1_3) .setMultipartReplyBody(new MultipartReplyTableCaseBuilder() .setMultipartReplyTable(new MultipartReplyTableBuilder() - .setTableStats(Collections.singletonList(new TableStatsBuilder() + .setTableStats(List.of(new TableStatsBuilder() .setActiveCount(Uint32.valueOf(31)) .setLookupCount(Uint64.valueOf(32)) .setMatchedCount(Uint64.valueOf(33)) @@ -83,29 +82,27 @@ public class OpendaylightFlowTableStatisticsServiceImplTest extends AbstractSing .build() )).build(); - final Future> resultFuture - = flowTableStatisticsService.getFlowTablesStatistics(input.build()); + final var resultFuture = getFlowTablesStatistics.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResult = resultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPTABLE, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResult = resultFuture.get(); + assertTrue(rpcResult.isSuccessful()); + assertEquals(MultipartType.OFPMPTABLE, requestInput.getValue().getType()); - Mockito.verify(notificationPublishService).offerNotification(ArgumentMatchers.any()); + verify(notificationPublishService).offerNotification(any()); } @Test public void testBuildRequest() { - Xid xid = new Xid(Uint32.valueOf(42L)); - GetFlowTablesStatisticsInputBuilder input = new GetFlowTablesStatisticsInputBuilder() + final var xid = new Xid(Uint32.valueOf(42L)); + final var input = new GetFlowTablesStatisticsInputBuilder() .setNode(createNodeRef("unitProt:123")); - final OfHeader request = flowTableStatisticsService.buildRequest(xid, input.build()); - Assert.assertTrue(request instanceof MultipartRequestInput); - final MultipartRequestInput mpRequest = (MultipartRequestInput) request; - Assert.assertEquals(MultipartType.OFPMPTABLE, mpRequest.getType()); - Assert.assertTrue(mpRequest.getMultipartRequestBody() instanceof MultipartRequestTableCase); - final MultipartRequestTableCase mpRequestBody = - (MultipartRequestTableCase) mpRequest.getMultipartRequestBody(); - Assert.assertNotNull(mpRequestBody.getMultipartRequestTable().getEmpty()); + final var request = getFlowTablesStatistics.buildRequest(xid, input.build()); + assertTrue(request instanceof MultipartRequestInput); + final var mpRequest = (MultipartRequestInput) request; + assertEquals(MultipartType.OFPMPTABLE, mpRequest.getType()); + assertTrue(mpRequest.getMultipartRequestBody() instanceof MultipartRequestTableCase); + final var mpRequestBody = (MultipartRequestTableCase) mpRequest.getMultipartRequestBody(); + assertNotNull(mpRequestBody.getMultipartRequestTable().getEmpty()); } } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl1Test.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl1Test.java deleted file mode 100644 index e3ddf0cf6e..0000000000 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl1Test.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowplugin.impl.statistics.services; - -import java.util.concurrent.Future; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.Uint16; -import org.opendaylight.yangtools.yang.common.Uint32; -import org.opendaylight.yangtools.yang.common.Uint8; - -/** - * Test for {@link OpendaylightFlowStatisticsServiceImpl} - only delegated methods (failing). - */ -public class OpendaylightFlowStatisticsServiceImpl1Test extends AbstractStatsServiceTest { - - @Captor - private ArgumentCaptor requestInput; - - private OpendaylightFlowStatisticsServiceImpl flowStatisticsService; - - @Override - public void setUp() { - final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager(); - flowStatisticsService = - OpendaylightFlowStatisticsServiceImpl.createWithOook(rqContextStack, deviceContext, convertorManager); - - AbstractRequestContext rqContext = new AbstractRequestContext<>(Uint32.valueOf(42)) { - @Override - public void close() { - //NOOP - } - }; - //Mockito.when(rqContextStack.createRequestContext()).thenReturn(rqContext); - } - - @Test(expected = IllegalAccessError.class) - public void testGetAggregateFlowStatisticsFromFlowTableForAllFlows() { - GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder input = - new GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder() - .setNode(createNodeRef("unitProt:123")) - .setTableId(new TableId(Uint8.ONE)); - - flowStatisticsService.getAggregateFlowStatisticsFromFlowTableForAllFlows(input.build()); - } - - @Test(expected = IllegalAccessError.class) - public void testGetAllFlowStatisticsFromFlowTable() { - GetAllFlowStatisticsFromFlowTableInputBuilder input = new GetAllFlowStatisticsFromFlowTableInputBuilder() - .setNode(createNodeRef("unitProt:123")) - .setTableId(new TableId(Uint8.ONE)); - - flowStatisticsService.getAllFlowStatisticsFromFlowTable(input.build()); - } - - @Test(expected = IllegalAccessError.class) - public void testGetAllFlowsStatisticsFromAllFlowTables() { - GetAllFlowsStatisticsFromAllFlowTablesInputBuilder input = - new GetAllFlowsStatisticsFromAllFlowTablesInputBuilder() - .setNode(createNodeRef("unitProt:123")); - - flowStatisticsService.getAllFlowsStatisticsFromAllFlowTables(input.build()); - } - - @Test(expected = IllegalAccessError.class) - public void testGetFlowStatisticsFromFlowTable() { - GetFlowStatisticsFromFlowTableInputBuilder input = new GetFlowStatisticsFromFlowTableInputBuilder() - .setNode(createNodeRef("unitProt:123")) - .setPriority(Uint16.valueOf(5)); - - final Future> resultFuture - = flowStatisticsService.getFlowStatisticsFromFlowTable(input.build()); - } -} \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl2Test.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl2Test.java index f48b3c8e3e..2a1d87c77b 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl2Test.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl2Test.java @@ -5,38 +5,35 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.openflowplugin.impl.statistics.services; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.when; -import com.google.common.util.concurrent.FutureCallback; import java.util.Collections; import java.util.List; -import java.util.concurrent.Future; -import org.junit.Assert; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.stubbing.Answer; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator; import org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatistics; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatisticsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; -import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.opendaylight.yangtools.yang.common.Uint16; import org.opendaylight.yangtools.yang.common.Uint32; @@ -46,7 +43,6 @@ import org.opendaylight.yangtools.yang.common.Uint8; * Test for {@link OpendaylightFlowStatisticsServiceImpl} - only not delegated method. */ public class OpendaylightFlowStatisticsServiceImpl2Test extends AbstractStatsServiceTest { - @Captor private ArgumentCaptor requestInput; @Mock @@ -54,15 +50,15 @@ public class OpendaylightFlowStatisticsServiceImpl2Test extends AbstractStatsSer private AbstractRequestContext> rqContextMp; - private OpendaylightFlowStatisticsServiceImpl flowStatisticsService; - + private GetAggregateFlowStatisticsFromFlowTableForGivenMatchImpl + getAggregateFlowStatisticsFromFlowTableForGivenMatch; @Override public void setUp() { - final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager(); - flowStatisticsService = OpendaylightFlowStatisticsServiceImpl.createWithOook(rqContextStack, - deviceContext, - convertorManager); + final var convertorManager = ConvertorManagerFactory.createDefaultManager(); + getAggregateFlowStatisticsFromFlowTableForGivenMatch = + new GetAggregateFlowStatisticsFromFlowTableForGivenMatchImpl(rqContextStack, deviceContext, + convertorManager); rqContextMp = new AbstractRequestContext<>(Uint32.valueOf(42L)) { @Override @@ -70,42 +66,38 @@ public class OpendaylightFlowStatisticsServiceImpl2Test extends AbstractStatsSer //NOOP } }; - Mockito.when(rqContextStack.>createRequestContext()).thenReturn(rqContextMp); - Mockito.when(translatorLibrary - .lookupTranslator(Mockito.any())) + when(rqContextStack.>createRequestContext()).thenReturn(rqContextMp); + when(translatorLibrary.lookupTranslator(any())) .thenReturn(translator); } @Test public void testGetAggregateFlowStatisticsFromFlowTableForGivenMatch() throws Exception { - Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider) - .commitEntry(eq(Uint32.valueOf(42)), requestInput.capture(), Mockito.any()); - Mockito.doAnswer((Answer) invocation -> { - final MultipartReplyMessageBuilder messageBuilder = new MultipartReplyMessageBuilder() - .setVersion(EncodeConstants.OF_VERSION_1_3); + doAnswer(answerVoidToCallback).when(outboundQueueProvider) + .commitEntry(eq(Uint32.valueOf(42)), requestInput.capture(), any()); + doAnswer((Answer) invocation -> { + final var messageBuilder = new MultipartReplyMessageBuilder().setVersion(EncodeConstants.OF_VERSION_1_3); rqContextMp.setResult(RpcResultBuilder .success(Collections.singletonList(messageBuilder.build())) .build()); return null; - }).when(multiMsgCollector).endCollecting(Mockito.any()); - Mockito.when(translator.translate( - Mockito.any(), same(deviceInfo), isNull()) - ).thenReturn(new AggregatedFlowStatisticsBuilder().build()); + }).when(multiMsgCollector).endCollecting(any()); + when(translator.translate(any(), same(deviceInfo), isNull())) + .thenReturn(new AggregatedFlowStatisticsBuilder().build()); - GetAggregateFlowStatisticsFromFlowTableForGivenMatchInputBuilder input = + final var input = new GetAggregateFlowStatisticsFromFlowTableForGivenMatchInputBuilder() .setNode(createNodeRef("unitProt:123")) .setPriority(Uint16.valueOf(5)) .setTableId(Uint8.ONE); - final Future> resultFuture - = flowStatisticsService.getAggregateFlowStatisticsFromFlowTableForGivenMatch(input.build()); + final var resultFuture = getAggregateFlowStatisticsFromFlowTableForGivenMatch.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResult = resultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - Assert.assertEquals(1, rpcResult.getResult().getAggregatedFlowStatistics().size()); - Assert.assertEquals(MultipartType.OFPMPAGGREGATE, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResult = resultFuture.get(); + assertTrue(rpcResult.isSuccessful()); + assertEquals(1, rpcResult.getResult().getAggregatedFlowStatistics().size()); + assertEquals(MultipartType.OFPMPAGGREGATE, requestInput.getValue().getType()); } } \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl3Test.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl3Test.java deleted file mode 100644 index 3ee63b8acc..0000000000 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightFlowStatisticsServiceImpl3Test.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.openflowplugin.impl.statistics.services; - -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId; -import org.opendaylight.yangtools.yang.common.Uint16; -import org.opendaylight.yangtools.yang.common.Uint8; - -/** - * Test for {@link OpendaylightFlowStatisticsServiceImpl} - only delegated methods. - */ -public class OpendaylightFlowStatisticsServiceImpl3Test extends AbstractStatsServiceTest { - - @Mock - private OpendaylightFlowStatisticsService flowStatisticsDelegate; - - private OpendaylightFlowStatisticsServiceImpl flowStatisticsService; - - @Override - public void setUp() { - final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager(); - flowStatisticsService = - OpendaylightFlowStatisticsServiceImpl.createWithOook(rqContextStack, deviceContext, convertorManager); - flowStatisticsService.setDelegate(flowStatisticsDelegate); - } - - @Test - public void testGetAggregateFlowStatisticsFromFlowTableForAllFlows() { - GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input = - new GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder() - .setNode(createNodeRef("unitProt:123")) - .setTableId(new TableId(Uint8.ONE)) - .build(); - - flowStatisticsService.getAggregateFlowStatisticsFromFlowTableForAllFlows(input); - Mockito.verify(flowStatisticsDelegate).getAggregateFlowStatisticsFromFlowTableForAllFlows(input); - } - - @Test - public void testGetAllFlowStatisticsFromFlowTable() { - GetAllFlowStatisticsFromFlowTableInput input = new GetAllFlowStatisticsFromFlowTableInputBuilder() - .setNode(createNodeRef("unitProt:123")) - .setTableId(new TableId(Uint8.ONE)) - .build(); - - flowStatisticsService.getAllFlowStatisticsFromFlowTable(input); - Mockito.verify(flowStatisticsDelegate).getAllFlowStatisticsFromFlowTable(input); - } - - @Test - public void testGetAllFlowsStatisticsFromAllFlowTables() { - GetAllFlowsStatisticsFromAllFlowTablesInput input = new GetAllFlowsStatisticsFromAllFlowTablesInputBuilder() - .setNode(createNodeRef("unitProt:123")) - .build(); - - flowStatisticsService.getAllFlowsStatisticsFromAllFlowTables(input); - Mockito.verify(flowStatisticsDelegate).getAllFlowsStatisticsFromAllFlowTables(input); - } - - @Test - public void testGetFlowStatisticsFromFlowTable() { - GetFlowStatisticsFromFlowTableInput input = new GetFlowStatisticsFromFlowTableInputBuilder() - .setNode(createNodeRef("unitProt:123")) - .setPriority(Uint16.valueOf(5)) - .build(); - - flowStatisticsService.getFlowStatisticsFromFlowTable(input); - Mockito.verify(flowStatisticsDelegate).getFlowStatisticsFromFlowTable(input); - } -} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightGroupStatisticsServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightGroupStatisticsServiceImplTest.java index 0d61ba0d01..59b560a80e 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightGroupStatisticsServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightGroupStatisticsServiceImplTest.java @@ -7,31 +7,26 @@ */ package org.opendaylight.openflowplugin.impl.statistics.services; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.verify; import com.google.common.util.concurrent.FutureCallback; -import java.util.Collections; -import java.util.concurrent.Future; +import java.util.List; import java.util.concurrent.atomic.AtomicLong; import org.junit.After; -import org.junit.Assert; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.ArgumentMatchers; import org.mockito.Captor; -import org.mockito.Mockito; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupCapabilities; @@ -57,32 +52,39 @@ import org.opendaylight.yangtools.yang.common.Uint16; import org.opendaylight.yangtools.yang.common.Uint32; import org.opendaylight.yangtools.yang.common.Uint64; -/** - * Test for {@link OpendaylightGroupStatisticsServiceImpl}. - */ +@Deprecated public class OpendaylightGroupStatisticsServiceImplTest extends AbstractSingleStatsServiceTest { - private static final org.opendaylight.yang.gen.v1.urn .opendaylight.openflow.common.types.rev130731.GroupId GROUP_ID = new org.opendaylight.yang.gen.v1.urn .opendaylight.openflow.common.types.rev130731.GroupId(Uint32.valueOf(123)); @Captor private ArgumentCaptor requestInput; - private OpendaylightGroupStatisticsServiceImpl groupStatisticsService; + private GetAllGroupStatisticsImpl getAllGroupStatistics; + private GetGroupStatisticsImpl getGroupStatistics; + private GetGroupDescriptionImpl getGroupDescription; + private GetGroupFeaturesImpl getGroupFeatures; @Override public void setUp() { - final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager(); - groupStatisticsService = new OpendaylightGroupStatisticsServiceImpl(rqContextStack, deviceContext, - new AtomicLong(), notificationPublishService, convertorManager); - - Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider) + final var convertorManager = ConvertorManagerFactory.createDefaultManager(); + final var xid = new AtomicLong(); + getAllGroupStatistics = new GetAllGroupStatisticsImpl(rqContextStack, deviceContext, xid, + notificationPublishService, convertorManager); + getGroupStatistics = new GetGroupStatisticsImpl(rqContextStack, deviceContext, xid, notificationPublishService, + convertorManager); + getGroupDescription = new GetGroupDescriptionImpl(rqContextStack, deviceContext, xid, + notificationPublishService, convertorManager); + getGroupFeatures = new GetGroupFeaturesImpl(rqContextStack, deviceContext, xid, notificationPublishService, + convertorManager); + + doAnswer(answerVoidToCallback).when(outboundQueueProvider) .commitEntry(eq(Uint32.valueOf(42)), requestInput.capture(), any(FutureCallback.class)); } @After public void tearDown() { - Mockito.verify(notificationPublishService).offerNotification(ArgumentMatchers.any()); + verify(notificationPublishService).offerNotification(any()); } @Test @@ -92,13 +94,12 @@ public class OpendaylightGroupStatisticsServiceImplTest extends AbstractSingleSt rpcResult = buildGroupStatsResponse(); - final Future> resultFuture - = groupStatisticsService.getAllGroupStatistics(input.build()); + final var resultFuture = getAllGroupStatistics.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResultCompatible = resultFuture.get(); - Assert.assertTrue(rpcResultCompatible.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPGROUP, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResultCompatible = resultFuture.get(); + assertTrue(rpcResultCompatible.isSuccessful()); + assertEquals(MultipartType.OFPMPGROUP, requestInput.getValue().getType()); } @Test @@ -106,32 +107,30 @@ public class OpendaylightGroupStatisticsServiceImplTest extends AbstractSingleSt GetGroupDescriptionInputBuilder input = new GetGroupDescriptionInputBuilder() .setNode(createNodeRef("unitProt:123")); - rpcResult = RpcResultBuilder.success(Collections.singletonList( - new MultipartReplyMessageBuilder() - .setVersion(EncodeConstants.OF_VERSION_1_3) - .setMultipartReplyBody(new MultipartReplyGroupDescCaseBuilder() - .setMultipartReplyGroupDesc(new MultipartReplyGroupDescBuilder() - .setGroupDesc(Collections.singletonList(new GroupDescBuilder() - .setGroupId(GROUP_ID) - .setBucketsList(Collections.singletonList(new BucketsListBuilder() - .setWatchGroup(Uint32.valueOf(51)) - .setWatchPort(new PortNumber(Uint32.valueOf(52))) - .setWeight(Uint16.valueOf(53)) - .build())) - .setType(GroupType.OFPGTALL) - .build())) - .build()) - .build()) - .build() + rpcResult = RpcResultBuilder.success(List.of(new MultipartReplyMessageBuilder() + .setVersion(EncodeConstants.OF_VERSION_1_3) + .setMultipartReplyBody(new MultipartReplyGroupDescCaseBuilder() + .setMultipartReplyGroupDesc(new MultipartReplyGroupDescBuilder() + .setGroupDesc(List.of(new GroupDescBuilder() + .setGroupId(GROUP_ID) + .setBucketsList(List.of(new BucketsListBuilder() + .setWatchGroup(Uint32.valueOf(51)) + .setWatchPort(new PortNumber(Uint32.valueOf(52))) + .setWeight(Uint16.valueOf(53)) + .build())) + .setType(GroupType.OFPGTALL) + .build())) + .build()) + .build()) + .build() )).build(); - final Future> resultFuture - = groupStatisticsService.getGroupDescription(input.build()); + final var resultFuture = getGroupDescription.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResult = resultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPGROUPDESC, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResult = resultFuture.get(); + assertTrue(rpcResult.isSuccessful()); + assertEquals(MultipartType.OFPMPGROUPDESC, requestInput.getValue().getType()); } @Test @@ -139,29 +138,26 @@ public class OpendaylightGroupStatisticsServiceImplTest extends AbstractSingleSt GetGroupFeaturesInputBuilder input = new GetGroupFeaturesInputBuilder() .setNode(createNodeRef("unitProt:123")); - rpcResult = RpcResultBuilder.success(Collections.singletonList( - new MultipartReplyMessageBuilder() - .setVersion(EncodeConstants.OF_VERSION_1_3) - .setMultipartReplyBody(new MultipartReplyGroupFeaturesCaseBuilder() - .setMultipartReplyGroupFeatures(new MultipartReplyGroupFeaturesBuilder() - .setActionsBitmap(Collections.singletonList(new ActionType(true, - false, false, false, false, false, false, false, false, false, false, - false, false, false, false, false, false))) - .setCapabilities(new GroupCapabilities(true, false, false, false)) - .setTypes(new GroupTypes(true, false, false, false)) - .setMaxGroups(Collections.singletonList(Uint32.valueOf(5L))) - .build()) - .build()) - .build() + rpcResult = RpcResultBuilder.success(List.of(new MultipartReplyMessageBuilder() + .setVersion(EncodeConstants.OF_VERSION_1_3) + .setMultipartReplyBody(new MultipartReplyGroupFeaturesCaseBuilder() + .setMultipartReplyGroupFeatures(new MultipartReplyGroupFeaturesBuilder() + .setActionsBitmap(List.of(new ActionType(true, false, false, false, false, false, false, false, + false, false, false, false, false, false, false, false, false))) + .setCapabilities(new GroupCapabilities(true, false, false, false)) + .setTypes(new GroupTypes(true, false, false, false)) + .setMaxGroups(List.of(Uint32.valueOf(5L))) + .build()) + .build()) + .build() )).build(); - final Future> resultFuture - = groupStatisticsService.getGroupFeatures(input.build()); + final var resultFuture = getGroupFeatures.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResult = resultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPGROUPFEATURES, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResult = resultFuture.get(); + assertTrue(rpcResult.isSuccessful()); + assertEquals(MultipartType.OFPMPGROUPFEATURES, requestInput.getValue().getType()); } @Test @@ -172,36 +168,34 @@ public class OpendaylightGroupStatisticsServiceImplTest extends AbstractSingleSt rpcResult = buildGroupStatsResponse(); - final Future> resultFuture - = groupStatisticsService.getGroupStatistics(input.build()); + final var resultFuture = getGroupStatistics.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResult = resultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPGROUP, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResult = resultFuture.get(); + assertTrue(rpcResult.isSuccessful()); + assertEquals(MultipartType.OFPMPGROUP, requestInput.getValue().getType()); } private static RpcResult buildGroupStatsResponse() { - return RpcResultBuilder.success(Collections.singletonList( - new MultipartReplyMessageBuilder() - .setVersion(EncodeConstants.OF_VERSION_1_3) - .setMultipartReplyBody(new MultipartReplyGroupCaseBuilder() - .setMultipartReplyGroup(new MultipartReplyGroupBuilder() - .setGroupStats(Collections.singletonList(new GroupStatsBuilder() - .setByteCount(Uint64.valueOf(21)) - .setPacketCount(Uint64.valueOf(22)) - .setRefCount(Uint32.valueOf(23)) - .setDurationSec(Uint32.valueOf(24)) - .setDurationNsec(Uint32.valueOf(25)) - .setGroupId(GROUP_ID) - .setBucketStats(Collections.singletonList(new BucketStatsBuilder() - .setByteCount(Uint64.valueOf(26)) - .setPacketCount(Uint64.valueOf(27)) - .build())) - .build())) - .build()) - .build()) - .build() + return RpcResultBuilder.success(List.of(new MultipartReplyMessageBuilder() + .setVersion(EncodeConstants.OF_VERSION_1_3) + .setMultipartReplyBody(new MultipartReplyGroupCaseBuilder() + .setMultipartReplyGroup(new MultipartReplyGroupBuilder() + .setGroupStats(List.of(new GroupStatsBuilder() + .setByteCount(Uint64.valueOf(21)) + .setPacketCount(Uint64.valueOf(22)) + .setRefCount(Uint32.valueOf(23)) + .setDurationSec(Uint32.valueOf(24)) + .setDurationNsec(Uint32.valueOf(25)) + .setGroupId(GROUP_ID) + .setBucketStats(List.of(new BucketStatsBuilder() + .setByteCount(Uint64.valueOf(26)) + .setPacketCount(Uint64.valueOf(27)) + .build())) + .build())) + .build()) + .build()) + .build() )).build(); } } \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightMeterStatisticsServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightMeterStatisticsServiceImplTest.java index 9529aa0253..0c2ef404b6 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightMeterStatisticsServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightMeterStatisticsServiceImplTest.java @@ -7,31 +7,27 @@ */ package org.opendaylight.openflowplugin.impl.statistics.services; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.verify; import com.google.common.util.concurrent.FutureCallback; -import java.util.Collections; -import java.util.concurrent.Future; +import java.util.List; import java.util.concurrent.atomic.AtomicLong; import org.junit.After; -import org.junit.Assert; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; import org.mockito.Captor; -import org.mockito.Mockito; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandTypeBitmap; @@ -60,29 +56,40 @@ import org.opendaylight.yangtools.yang.common.Uint8; /** * Test for {@link OpendaylightMeterStatisticsServiceImpl}. */ +@Deprecated public class OpendaylightMeterStatisticsServiceImplTest extends AbstractSingleStatsServiceTest { - private static final org.opendaylight.yang.gen.v1.urn .opendaylight.openflow.common.types.rev130731.MeterId METER_ID = new org.opendaylight.yang.gen.v1.urn .opendaylight.openflow.common.types.rev130731.MeterId(Uint32.valueOf(123)); @Captor private ArgumentCaptor requestInput; - private OpendaylightMeterStatisticsServiceImpl meterStatisticsService; + private GetAllMeterStatisticsImpl getAllMeterStatistics; + private GetMeterStatisticsImpl getMeterStatistics; + private GetAllMeterConfigStatisticsImpl getAllMeterConfigStatistics; + private GetMeterFeaturesImpl getMeterFeatures; @Override public void setUp() { - final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager(); - meterStatisticsService = new OpendaylightMeterStatisticsServiceImpl(rqContextStack, deviceContext, - new AtomicLong(), notificationPublishService, convertorManager); - - Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider) + final var xid = new AtomicLong(); + final var convertorManager = ConvertorManagerFactory.createDefaultManager(); + + getAllMeterStatistics = new GetAllMeterStatisticsImpl(rqContextStack, deviceContext, xid, + notificationPublishService, convertorManager); + getMeterStatistics = new GetMeterStatisticsImpl(rqContextStack, deviceContext, xid, + notificationPublishService, convertorManager); + getAllMeterConfigStatistics = new GetAllMeterConfigStatisticsImpl(rqContextStack, deviceContext, xid, + notificationPublishService, convertorManager); + getMeterFeatures = new GetMeterFeaturesImpl(rqContextStack, deviceContext, xid, + notificationPublishService, convertorManager); + + doAnswer(answerVoidToCallback).when(outboundQueueProvider) .commitEntry(eq(Uint32.valueOf(42)), requestInput.capture(), any(FutureCallback.class)); } @After public void tearDown() { - Mockito.verify(notificationPublishService).offerNotification(ArgumentMatchers.any()); + verify(notificationPublishService).offerNotification(ArgumentMatchers.any()); } @Test @@ -90,15 +97,15 @@ public class OpendaylightMeterStatisticsServiceImplTest extends AbstractSingleSt GetAllMeterConfigStatisticsInputBuilder input = new GetAllMeterConfigStatisticsInputBuilder() .setNode(createNodeRef("unitProt:123")); - rpcResult = RpcResultBuilder.success(Collections.singletonList( + rpcResult = RpcResultBuilder.success(List.of( new MultipartReplyMessageBuilder() .setVersion(EncodeConstants.OF_VERSION_1_3) .setMultipartReplyBody(new MultipartReplyMeterConfigCaseBuilder() .setMultipartReplyMeterConfig(new MultipartReplyMeterConfigBuilder() - .setMeterConfig(Collections.singletonList(new MeterConfigBuilder() + .setMeterConfig(List.of(new MeterConfigBuilder() .setFlags(new MeterFlags(true, false, false, false)) .setMeterId(METER_ID) - .setBands(Collections.singletonList(new BandsBuilder() + .setBands(List.of(new BandsBuilder() .setMeterBand(new MeterBandDropCaseBuilder() .setMeterBandDrop(new MeterBandDropBuilder() .setBurstSize(Uint32.valueOf(61)) @@ -113,13 +120,12 @@ public class OpendaylightMeterStatisticsServiceImplTest extends AbstractSingleSt .build() )).build(); - final Future> resultFuture - = meterStatisticsService.getAllMeterConfigStatistics(input.build()); + final var resultFuture = getAllMeterConfigStatistics.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResult = resultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPMETERCONFIG, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResult = resultFuture.get(); + assertTrue(rpcResult.isSuccessful()); + assertEquals(MultipartType.OFPMPMETERCONFIG, requestInput.getValue().getType()); } @Test @@ -129,13 +135,12 @@ public class OpendaylightMeterStatisticsServiceImplTest extends AbstractSingleSt rpcResult = buildMeterStatisticsReply(); - final Future> resultFuture - = meterStatisticsService.getAllMeterStatistics(input.build()); + final var resultFuture = getAllMeterStatistics.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResult = resultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPMETER, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResult = resultFuture.get(); + assertTrue(rpcResult.isSuccessful()); + assertEquals(MultipartType.OFPMPMETER, requestInput.getValue().getType()); } @Test @@ -143,7 +148,7 @@ public class OpendaylightMeterStatisticsServiceImplTest extends AbstractSingleSt GetMeterFeaturesInputBuilder input = new GetMeterFeaturesInputBuilder() .setNode(createNodeRef("unitProt:123")); - rpcResult = RpcResultBuilder.success(Collections.singletonList( + rpcResult = RpcResultBuilder.success(List.of( new MultipartReplyMessageBuilder() .setVersion(EncodeConstants.OF_VERSION_1_3) .setMultipartReplyBody(new MultipartReplyMeterFeaturesCaseBuilder() @@ -158,13 +163,12 @@ public class OpendaylightMeterStatisticsServiceImplTest extends AbstractSingleSt .build() )).build(); - final Future> resultFuture - = meterStatisticsService.getMeterFeatures(input.build()); + final var resultFuture = getMeterFeatures.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResult = resultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPMETERFEATURES, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResult = resultFuture.get(); + assertTrue(rpcResult.isSuccessful()); + assertEquals(MultipartType.OFPMPMETERFEATURES, requestInput.getValue().getType()); } @Test @@ -175,29 +179,28 @@ public class OpendaylightMeterStatisticsServiceImplTest extends AbstractSingleSt rpcResult = buildMeterStatisticsReply(); - final Future> resultFuture - = meterStatisticsService.getMeterStatistics(input.build()); + final var resultFuture = getMeterStatistics.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResult = resultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPMETER, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResult = resultFuture.get(); + assertTrue(rpcResult.isSuccessful()); + assertEquals(MultipartType.OFPMPMETER, requestInput.getValue().getType()); } protected RpcResult buildMeterStatisticsReply() { - return RpcResultBuilder.success(Collections.singletonList( + return RpcResultBuilder.success(List.of( new MultipartReplyMessageBuilder() .setVersion(EncodeConstants.OF_VERSION_1_3) .setMultipartReplyBody(new MultipartReplyMeterCaseBuilder() .setMultipartReplyMeter(new MultipartReplyMeterBuilder() - .setMeterStats(Collections.singletonList(new MeterStatsBuilder() + .setMeterStats(List.of(new MeterStatsBuilder() .setMeterId(METER_ID) .setByteInCount(Uint64.valueOf(81)) .setDurationSec(Uint32.valueOf(82)) .setDurationNsec(Uint32.valueOf(83)) .setFlowCount(Uint32.valueOf(84)) .setPacketInCount(Uint64.valueOf(85)) - .setMeterBandStats(Collections.singletonList(new MeterBandStatsBuilder() + .setMeterBandStats(List.of(new MeterBandStatsBuilder() .setByteBandCount(Uint64.valueOf(86)) .setPacketBandCount(Uint64.valueOf(87)) .build())) diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightPortStatisticsServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightPortStatisticsServiceImplTest.java index 8a3e846985..65a213d528 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightPortStatisticsServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightPortStatisticsServiceImplTest.java @@ -5,23 +5,22 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.openflowplugin.impl.statistics.services; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.verify; import com.google.common.util.concurrent.FutureCallback; -import java.util.Collections; -import java.util.concurrent.Future; +import java.util.List; import java.util.concurrent.atomic.AtomicLong; import org.junit.After; -import org.junit.Assert; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.ArgumentMatchers; import org.mockito.Captor; -import org.mockito.Mockito; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; @@ -33,7 +32,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutput; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.opendaylight.yangtools.yang.common.Uint32; @@ -42,50 +40,52 @@ import org.opendaylight.yangtools.yang.common.Uint64; /** * Test for {@link OpendaylightPortStatisticsServiceImpl}. */ +@Deprecated public class OpendaylightPortStatisticsServiceImplTest extends AbstractSingleStatsServiceTest { - @Captor private ArgumentCaptor requestInput; - private OpendaylightPortStatisticsServiceImpl portStatisticsService; + private GetAllNodeConnectorsStatisticsImpl getAllNodeConnectorsStatistics; + private GetNodeConnectorStatisticsImpl getNodeConnectorStatistics; @Override public void setUp() { - portStatisticsService = new OpendaylightPortStatisticsServiceImpl(rqContextStack, deviceContext, - new AtomicLong(), notificationPublishService); + final var xid = new AtomicLong(); + getAllNodeConnectorsStatistics = new GetAllNodeConnectorsStatisticsImpl(rqContextStack, deviceContext, xid, + notificationPublishService); + getNodeConnectorStatistics = new GetNodeConnectorStatisticsImpl(rqContextStack, deviceContext, xid, + notificationPublishService); - Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider) + doAnswer(answerVoidToCallback).when(outboundQueueProvider) .commitEntry(eq(Uint32.valueOf(42)), requestInput.capture(), any(FutureCallback.class)); } @After public void tearDown() { - Mockito.verify(notificationPublishService).offerNotification(ArgumentMatchers.any()); + verify(notificationPublishService).offerNotification(any()); } @Test public void testGetAllNodeConnectorsStatistics() throws Exception { - GetAllNodeConnectorsStatisticsInputBuilder input = new GetAllNodeConnectorsStatisticsInputBuilder() - .setNode(createNodeRef("unitProt:123")); + var input = new GetAllNodeConnectorsStatisticsInputBuilder().setNode(createNodeRef("unitProt:123")); rpcResult = buildPortStatisticsReply(); - final Future> resultFuture - = portStatisticsService.getAllNodeConnectorsStatistics(input.build()); + final var resultFuture = getAllNodeConnectorsStatistics.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); + assertTrue(resultFuture.isDone()); final RpcResult rpcResult = resultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPPORTSTATS, requestInput.getValue().getType()); + assertTrue(rpcResult.isSuccessful()); + assertEquals(MultipartType.OFPMPPORTSTATS, requestInput.getValue().getType()); } private static RpcResult buildPortStatisticsReply() { - return RpcResultBuilder.success(Collections.singletonList( + return RpcResultBuilder.success(List.of( new MultipartReplyMessageBuilder() .setVersion(EncodeConstants.OF_VERSION_1_3) .setMultipartReplyBody(new MultipartReplyPortStatsCaseBuilder() .setMultipartReplyPortStats(new MultipartReplyPortStatsBuilder() - .setPortStats(Collections.singletonList(new PortStatsBuilder() + .setPortStats(List.of(new PortStatsBuilder() .setDurationSec(Uint32.valueOf(90)) .setDurationNsec(Uint32.valueOf(91)) .setCollisions(Uint64.valueOf(92)) @@ -110,18 +110,17 @@ public class OpendaylightPortStatisticsServiceImplTest extends AbstractSingleSta @Test public void testGetNodeConnectorStatistics() throws Exception { - GetNodeConnectorStatisticsInputBuilder input = new GetNodeConnectorStatisticsInputBuilder() + var input = new GetNodeConnectorStatisticsInputBuilder() .setNode(createNodeRef("unitProt:123")) .setNodeConnectorId(new NodeConnectorId("unitProt:123:321")); rpcResult = buildPortStatisticsReply(); - final Future> resultFuture - = portStatisticsService.getNodeConnectorStatistics(input.build()); + final var resultFuture = getNodeConnectorStatistics.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResult = resultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPPORTSTATS, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResult = resultFuture.get(); + assertTrue(rpcResult.isSuccessful()); + assertEquals(MultipartType.OFPMPPORTSTATS, requestInput.getValue().getType()); } } \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightQueueStatisticsServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightQueueStatisticsServiceImplTest.java index cea28bc3b1..b1d98468b9 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightQueueStatisticsServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/OpendaylightQueueStatisticsServiceImplTest.java @@ -7,20 +7,20 @@ */ package org.opendaylight.openflowplugin.impl.statistics.services; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.verify; import com.google.common.util.concurrent.FutureCallback; -import java.util.Collections; -import java.util.concurrent.Future; +import java.util.List; import java.util.concurrent.atomic.AtomicLong; import org.junit.After; -import org.junit.Assert; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.ArgumentMatchers; import org.mockito.Captor; -import org.mockito.Mockito; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.queue.rev130925.QueueId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; @@ -31,40 +31,41 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.MultipartReplyQueueBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.multipart.reply.queue.QueueStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutput; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.opendaylight.yangtools.yang.common.Uint32; import org.opendaylight.yangtools.yang.common.Uint64; -/** - * Test for {@link OpendaylightQueueStatisticsServiceImpl}. - */ +@Deprecated public class OpendaylightQueueStatisticsServiceImplTest extends AbstractSingleStatsServiceTest { - @Captor private ArgumentCaptor requestInput; - private OpendaylightQueueStatisticsServiceImpl queueStatisticsService; + private GetAllQueuesStatisticsFromAllPortsImpl getAllQueuesStatisticsFromAllPorts; + private GetAllQueuesStatisticsFromGivenPortImpl getAllQueuesStatisticsFromGivenPort; + private GetQueueStatisticsFromGivenPortImpl getQueueStatisticsFromGivenPort; @Override public void setUp() { - queueStatisticsService = new OpendaylightQueueStatisticsServiceImpl(rqContextStack, deviceContext, - new AtomicLong(), notificationPublishService); + final var xid = new AtomicLong(); + getAllQueuesStatisticsFromAllPorts = new GetAllQueuesStatisticsFromAllPortsImpl(rqContextStack, deviceContext, + xid, notificationPublishService); + getAllQueuesStatisticsFromGivenPort = new GetAllQueuesStatisticsFromGivenPortImpl(rqContextStack, deviceContext, + xid, notificationPublishService); + getQueueStatisticsFromGivenPort = new GetQueueStatisticsFromGivenPortImpl(rqContextStack, deviceContext, + xid, notificationPublishService); } @After public void tearDown() { - Mockito.verify(notificationPublishService).offerNotification(ArgumentMatchers.any()); + verify(notificationPublishService).offerNotification(any()); } @Test public void testGetAllQueuesStatisticsFromAllPorts() throws Exception { - Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider) + doAnswer(answerVoidToCallback).when(outboundQueueProvider) .commitEntry(eq(Uint32.valueOf(42)), requestInput.capture(), any(FutureCallback.class)); GetAllQueuesStatisticsFromAllPortsInputBuilder input = new GetAllQueuesStatisticsFromAllPortsInputBuilder() @@ -72,22 +73,21 @@ public class OpendaylightQueueStatisticsServiceImplTest extends AbstractSingleSt rpcResult = buildQueueStatsReply(); - final Future> resultFuture - = queueStatisticsService.getAllQueuesStatisticsFromAllPorts(input.build()); + final var resultFuture = getAllQueuesStatisticsFromAllPorts.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResult = resultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPQUEUE, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResult = resultFuture.get(); + assertTrue(rpcResult.isSuccessful()); + assertEquals(MultipartType.OFPMPQUEUE, requestInput.getValue().getType()); } protected RpcResult buildQueueStatsReply() { - return RpcResultBuilder.success(Collections.singletonList( + return RpcResultBuilder.success(List.of( new MultipartReplyMessageBuilder() .setVersion(EncodeConstants.OF_VERSION_1_3) .setMultipartReplyBody(new MultipartReplyQueueCaseBuilder() .setMultipartReplyQueue(new MultipartReplyQueueBuilder() - .setQueueStats(Collections.singletonList(new QueueStatsBuilder() + .setQueueStats(List.of(new QueueStatsBuilder() .setDurationSec(Uint32.valueOf(41)) .setDurationNsec(Uint32.valueOf(42)) .setTxBytes(Uint64.valueOf(43)) @@ -104,7 +104,7 @@ public class OpendaylightQueueStatisticsServiceImplTest extends AbstractSingleSt @Test public void testGetAllQueuesStatisticsFromGivenPort() throws Exception { - Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider) + doAnswer(answerVoidToCallback).when(outboundQueueProvider) .commitEntry(eq(Uint32.valueOf(42)), requestInput.capture(), any(FutureCallback.class)); GetAllQueuesStatisticsFromGivenPortInputBuilder input = new GetAllQueuesStatisticsFromGivenPortInputBuilder() @@ -113,18 +113,17 @@ public class OpendaylightQueueStatisticsServiceImplTest extends AbstractSingleSt rpcResult = buildQueueStatsReply(); - final Future> resultFuture - = queueStatisticsService.getAllQueuesStatisticsFromGivenPort(input.build()); + final var resultFuture = getAllQueuesStatisticsFromGivenPort.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResult = resultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPQUEUE, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResult = resultFuture.get(); + assertTrue(rpcResult.isSuccessful()); + assertEquals(MultipartType.OFPMPQUEUE, requestInput.getValue().getType()); } @Test public void testGetQueueStatisticsFromGivenPort() throws Exception { - Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider) + doAnswer(answerVoidToCallback).when(outboundQueueProvider) .commitEntry(eq(Uint32.valueOf(42)), requestInput.capture(), any(FutureCallback.class)); GetQueueStatisticsFromGivenPortInputBuilder input = new GetQueueStatisticsFromGivenPortInputBuilder() @@ -134,12 +133,11 @@ public class OpendaylightQueueStatisticsServiceImplTest extends AbstractSingleSt rpcResult = buildQueueStatsReply(); - final Future> resultFuture - = queueStatisticsService.getQueueStatisticsFromGivenPort(input.build()); + final var resultFuture = getQueueStatisticsFromGivenPort.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResult = resultFuture.get(); - Assert.assertTrue(rpcResult.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPQUEUE, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResult = resultFuture.get(); + assertTrue(rpcResult.isSuccessful()); + assertEquals(MultipartType.OFPMPQUEUE, requestInput.getValue().getType()); } } \ No newline at end of file diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/AbstractCompatibleStatServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/AbstractCompatibleStatServiceTest.java index 6f8cdd7b08..8cebb29587 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/AbstractCompatibleStatServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/AbstractCompatibleStatServiceTest.java @@ -7,19 +7,24 @@ */ package org.opendaylight.openflowplugin.impl.statistics.services.compatibility; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.ListenableFuture; -import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.AtomicLong; -import org.junit.Assert; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.stubbing.Answer; import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; @@ -95,27 +100,27 @@ public class AbstractCompatibleStatServiceTest extends AbstractStatsServiceTest return null; }; - Mockito.lenient().when(featuresOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3); - Mockito.when(rqContextStack.createRequestContext()).thenReturn(rqContext); - Mockito.lenient().when(deviceContext.getDeviceState()).thenReturn(deviceState); - Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo); - Mockito.when(deviceInfo.getNodeId()).thenReturn(NODE_ID); - Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3); - Mockito.doAnswer(closeRequestFutureAnswer).when(multiMsgCollector).endCollecting(null); - Mockito.lenient().doAnswer(closeRequestFutureAnswer).when(multiMsgCollector) + lenient().when(featuresOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3); + when(rqContextStack.createRequestContext()).thenReturn(rqContext); + lenient().when(deviceContext.getDeviceState()).thenReturn(deviceState); + when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo); + when(deviceInfo.getNodeId()).thenReturn(NODE_ID); + when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3); + doAnswer(closeRequestFutureAnswer).when(multiMsgCollector).endCollecting(null); + lenient().doAnswer(closeRequestFutureAnswer).when(multiMsgCollector) .endCollecting(any(EventIdentifier.class)); - Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider) + doAnswer(answerVoidToCallback).when(outboundQueueProvider) .commitEntry(eq(Uint32.valueOf(42)), requestInput.capture(), any(FutureCallback.class)); - Mockito.when(translatorLibrary.lookupTranslator(any(TranslatorKey.class))).thenReturn(translator); + when(translatorLibrary.lookupTranslator(any(TranslatorKey.class))).thenReturn(translator); - service = AggregateFlowsInTableService.createWithOook(rqContextStack, deviceContext, new AtomicLong(20L)); + service = new AggregateFlowsInTableService(rqContextStack, deviceContext, new AtomicLong(20L)); } @Test public void testGetOfVersion() { - Assert.assertEquals(OFConstants.OFP_VERSION_1_3, service.getOfVersion().getVersion()); + assertEquals(OFConstants.OFP_VERSION_1_3, service.getOfVersion().getVersion()); } @Test @@ -126,7 +131,7 @@ public class AbstractCompatibleStatServiceTest extends AbstractStatsServiceTest .setTableId(new TableId(Uint8.ONE)) .build(); - rpcResult = RpcResultBuilder.success(Collections.singletonList( + rpcResult = RpcResultBuilder.success(List.of( new MultipartReplyMessageBuilder() .setVersion(EncodeConstants.OF_VERSION_1_3) .setMultipartReplyBody(new MultipartReplyAggregateCaseBuilder() @@ -144,18 +149,18 @@ public class AbstractCompatibleStatServiceTest extends AbstractStatsServiceTest .setFlowCount(new Counter32(Uint32.valueOf(12))) .setPacketCount(new Counter64(Uint64.valueOf(13))) .build(); - Mockito.when(translator.translate(any(MultipartReply.class), eq(deviceInfo), any())) + when(translator.translate(any(MultipartReply.class), eq(deviceInfo), any())) .thenReturn(aggregatedStats); ListenableFuture> resultFuture = service.handleAndNotify(input, notificationPublishService); - Assert.assertTrue(resultFuture.isDone()); + assertTrue(resultFuture.isDone()); final RpcResult result = resultFuture.get(); - Assert.assertTrue(result.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPAGGREGATE, requestInput.getValue().getType()); - Mockito.verify(notificationPublishService, Mockito.timeout(500)) + assertTrue(result.isSuccessful()); + assertEquals(MultipartType.OFPMPAGGREGATE, requestInput.getValue().getType()); + verify(notificationPublishService, timeout(500)) .offerNotification(any(AggregateFlowStatisticsUpdate.class)); } } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/OpendaylightFlowStatisticsServiceDelegateImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/OpendaylightFlowStatisticsServiceDelegateImplTest.java index 24c0cf7c44..da986a37b0 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/OpendaylightFlowStatisticsServiceDelegateImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/OpendaylightFlowStatisticsServiceDelegateImplTest.java @@ -7,35 +7,32 @@ */ package org.opendaylight.openflowplugin.impl.statistics.services.compatibility; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import com.google.common.util.concurrent.FutureCallback; -import java.util.Collections; -import java.util.concurrent.Future; +import java.util.List; import java.util.concurrent.atomic.AtomicLong; -import org.junit.Assert; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.ArgumentMatchers; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.Mockito; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator; import org.opendaylight.openflowplugin.impl.statistics.services.AbstractSingleStatsServiceTest; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatisticsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder; @@ -66,33 +63,38 @@ import org.opendaylight.yangtools.yang.common.Uint64; import org.opendaylight.yangtools.yang.common.Uint8; /** - * Test for {@link OpendaylightFlowStatisticsServiceDelegateImpl}. + * Test for {@link GetFlowStatisticsFromFlowTableImpl}. * Skipping notification verification. This will be tested in tests of underlying single task oriented services. */ public class OpendaylightFlowStatisticsServiceDelegateImplTest extends AbstractSingleStatsServiceTest { - public static final int NOTIFICATION_WAIT_TIMEOUT_MS = 500; - @Captor - private ArgumentCaptor requestInput; - private OpendaylightFlowStatisticsServiceDelegateImpl flowStatisticsServiceDelegate; @Mock private MessageTranslator translator; + @Captor + private ArgumentCaptor requestInput; + + private GetFlowStatisticsFromFlowTableImpl getFlowStatisticsFromFlowTable; + private GetAllFlowStatisticsFromFlowTableImpl getAllFlowStatisticsFromFlowTable; + private GetAllFlowsStatisticsFromAllFlowTablesImpl getAllFlowsStatisticsFromAllFlowTables; + private GetAggregateFlowStatisticsFromFlowTableForAllFlowsImpl getAggregateFlowStatisticsFromFlowTableForAllFlows; @Override public void setUp() { - final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager(); - flowStatisticsServiceDelegate = new OpendaylightFlowStatisticsServiceDelegateImpl( - rqContextStack, deviceContext, notificationPublishService, new AtomicLong(21), convertorManager); - - Mockito.doAnswer(answerVoidToCallback).when(outboundQueueProvider) + final var convertorManager = ConvertorManagerFactory.createDefaultManager(); + final var xid = new AtomicLong(21); + getFlowStatisticsFromFlowTable = new GetFlowStatisticsFromFlowTableImpl( + rqContextStack, deviceContext, convertorManager, xid, notificationPublishService); + getAllFlowStatisticsFromFlowTable = new GetAllFlowStatisticsFromFlowTableImpl( + rqContextStack, deviceContext, convertorManager, xid, notificationPublishService); + getAllFlowsStatisticsFromAllFlowTables = new GetAllFlowsStatisticsFromAllFlowTablesImpl( + rqContextStack, deviceContext, convertorManager, xid, notificationPublishService); + getAggregateFlowStatisticsFromFlowTableForAllFlows = new GetAggregateFlowStatisticsFromFlowTableForAllFlowsImpl( + rqContextStack, deviceContext, convertorManager, xid, notificationPublishService); + + doAnswer(answerVoidToCallback).when(outboundQueueProvider) .commitEntry(eq(Uint32.valueOf(42)), requestInput.capture(), any(FutureCallback.class)); - Mockito.when(translatorLibrary.lookupTranslator(ArgumentMatchers.any())).thenReturn(translator); - } - - @Test(expected = IllegalAccessError.class) - public void testGetAggregateFlowStatisticsFromFlowTableForGivenMatch() { - flowStatisticsServiceDelegate.getAggregateFlowStatisticsFromFlowTableForGivenMatch(null); + when(translatorLibrary.lookupTranslator(any())).thenReturn(translator); } @Test @@ -102,14 +104,14 @@ public class OpendaylightFlowStatisticsServiceDelegateImplTest extends AbstractS .setNode(createNodeRef("unitProt:123")) .setTableId(new TableId(Uint8.ONE)); - Mockito.when(translator.translate(any(MultipartReply.class), eq(deviceInfo),any())) + when(translator.translate(any(MultipartReply.class), eq(deviceInfo),any())) .thenReturn(new AggregatedFlowStatisticsBuilder() .setByteCount(new Counter64(Uint64.valueOf(50))) .setPacketCount(new Counter64(Uint64.valueOf(51))) .setFlowCount(new Counter32(Uint32.valueOf(52))) .build()); - rpcResult = RpcResultBuilder.success(Collections.singletonList(new MultipartReplyMessageBuilder() + rpcResult = RpcResultBuilder.success(List.of(new MultipartReplyMessageBuilder() .setType(MultipartType.OFPMPAGGREGATE) .setVersion(EncodeConstants.OF_VERSION_1_3) .setFlags(new MultipartRequestFlags(false)) @@ -123,16 +125,14 @@ public class OpendaylightFlowStatisticsServiceDelegateImplTest extends AbstractS .build())) .build(); - final Future> resultFuture - = flowStatisticsServiceDelegate.getAggregateFlowStatisticsFromFlowTableForAllFlows(input.build()); + final var resultFuture = getAggregateFlowStatisticsFromFlowTableForAllFlows.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResultCompatible = - resultFuture.get(); - Assert.assertTrue(rpcResultCompatible.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPAGGREGATE, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResultCompatible = resultFuture.get(); + assertTrue(rpcResultCompatible.isSuccessful()); + assertEquals(MultipartType.OFPMPAGGREGATE, requestInput.getValue().getType()); - Mockito.verify(notificationPublishService, Mockito.timeout(NOTIFICATION_WAIT_TIMEOUT_MS)) + verify(notificationPublishService, timeout(NOTIFICATION_WAIT_TIMEOUT_MS)) .offerNotification(any(Notification.class)); } @@ -144,26 +144,25 @@ public class OpendaylightFlowStatisticsServiceDelegateImplTest extends AbstractS rpcResult = buildFlowStatsReply(); - final Future> resultFuture - = flowStatisticsServiceDelegate.getAllFlowStatisticsFromFlowTable(input.build()); + final var resultFuture = getAllFlowStatisticsFromFlowTable.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResultCompatible = resultFuture.get(); - Assert.assertTrue(rpcResultCompatible.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPFLOW, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResultCompatible = resultFuture.get(); + assertTrue(rpcResultCompatible.isSuccessful()); + assertEquals(MultipartType.OFPMPFLOW, requestInput.getValue().getType()); - Mockito.verify(notificationPublishService, Mockito.timeout(NOTIFICATION_WAIT_TIMEOUT_MS)) + verify(notificationPublishService, timeout(NOTIFICATION_WAIT_TIMEOUT_MS)) .offerNotification(any(Notification.class)); } private static RpcResult buildFlowStatsReply() { - return RpcResultBuilder.success(Collections.singletonList(new MultipartReplyMessageBuilder() + return RpcResultBuilder.success(List.of(new MultipartReplyMessageBuilder() .setType(MultipartType.OFPMPFLOW) .setVersion(EncodeConstants.OF_VERSION_1_3) .setFlags(new MultipartRequestFlags(false)) .setMultipartReplyBody(new MultipartReplyFlowCaseBuilder() .setMultipartReplyFlow(new MultipartReplyFlowBuilder() - .setFlowStats(Collections.singletonList(new FlowStatsBuilder() + .setFlowStats(List.of(new FlowStatsBuilder() .setTableId(Uint8.valueOf(123)) .setDurationSec(Uint32.TEN) .setDurationNsec(Uint32.valueOf(11)) @@ -171,14 +170,14 @@ public class OpendaylightFlowStatisticsServiceDelegateImplTest extends AbstractS .setPacketCount(Uint64.valueOf(13)) .setCookie(Uint64.ZERO) .setPriority(Uint16.valueOf(14)) - .setMatch(new MatchBuilder().setMatchEntry(Collections.emptyList()).build()) + .setMatch(new MatchBuilder().setMatchEntry(List.of()).build()) .setHardTimeout(Uint16.valueOf(15)) .setIdleTimeout(Uint16.valueOf(16)) .setFlags(new FlowModFlags(true, false, false, false, false)) - .setInstruction(Collections.singletonList(new InstructionBuilder() + .setInstruction(List.of(new InstructionBuilder() .setInstructionChoice(new ApplyActionsCaseBuilder() .setApplyActions(new ApplyActionsBuilder() - .setAction(Collections.singletonList(new ActionBuilder() + .setAction(List.of(new ActionBuilder() .setActionChoice(new OutputActionCaseBuilder() .setOutputAction(new OutputActionBuilder() .setMaxLength(Uint16.valueOf(17)) @@ -193,7 +192,7 @@ public class OpendaylightFlowStatisticsServiceDelegateImplTest extends AbstractS .build()) .build()) .build())) - .build(); + .build(); } @Test @@ -204,15 +203,14 @@ public class OpendaylightFlowStatisticsServiceDelegateImplTest extends AbstractS rpcResult = buildFlowStatsReply(); - final Future> resultFuture - = flowStatisticsServiceDelegate.getAllFlowsStatisticsFromAllFlowTables(input.build()); + final var resultFuture = getAllFlowsStatisticsFromAllFlowTables.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResultCompatible = resultFuture.get(); - Assert.assertTrue(rpcResultCompatible.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPFLOW, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResultCompatible = resultFuture.get(); + assertTrue(rpcResultCompatible.isSuccessful()); + assertEquals(MultipartType.OFPMPFLOW, requestInput.getValue().getType()); - Mockito.verify(notificationPublishService, Mockito.timeout(NOTIFICATION_WAIT_TIMEOUT_MS)) + verify(notificationPublishService, timeout(NOTIFICATION_WAIT_TIMEOUT_MS)) .offerNotification(any(Notification.class)); } @@ -226,15 +224,14 @@ public class OpendaylightFlowStatisticsServiceDelegateImplTest extends AbstractS rpcResult = buildFlowStatsReply(); - final Future> resultFuture - = flowStatisticsServiceDelegate.getFlowStatisticsFromFlowTable(input.build()); + final var resultFuture = getFlowStatisticsFromFlowTable.invoke(input.build()); - Assert.assertTrue(resultFuture.isDone()); - final RpcResult rpcResultCompatible = resultFuture.get(); - Assert.assertTrue(rpcResultCompatible.isSuccessful()); - Assert.assertEquals(MultipartType.OFPMPFLOW, requestInput.getValue().getType()); + assertTrue(resultFuture.isDone()); + final var rpcResultCompatible = resultFuture.get(); + assertTrue(rpcResultCompatible.isSuccessful()); + assertEquals(MultipartType.OFPMPFLOW, requestInput.getValue().getType()); - Mockito.verify(notificationPublishService, Mockito.timeout(NOTIFICATION_WAIT_TIMEOUT_MS)) + verify(notificationPublishService, timeout(NOTIFICATION_WAIT_TIMEOUT_MS)) .offerNotification(any(Notification.class)); } } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/OpendaylightDirectStatisticsServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/OpendaylightDirectStatisticsServiceImplTest.java deleted file mode 100644 index 21d1d9010f..0000000000 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/OpendaylightDirectStatisticsServiceImplTest.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.openflowplugin.impl.statistics.services.direct; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetGroupStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetGroupStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetNodeConnectorStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetQueueStatisticsInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetQueueStatisticsOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.OpendaylightDirectStatisticsService; -import org.opendaylight.yangtools.yang.common.RpcError; -import org.opendaylight.yangtools.yang.common.RpcResult; - -@RunWith(MockitoJUnitRunner.class) -public class OpendaylightDirectStatisticsServiceImplTest { - @Mock - AbstractFlowDirectStatisticsService flowDirectStatisticsService; - @Mock - AbstractGroupDirectStatisticsService groupDirectStatisticsService; - @Mock - AbstractMeterDirectStatisticsService meterDirectStatisticsService; - @Mock - AbstractPortDirectStatisticsService nodeConnectorDirectStatisticsService; - @Mock - AbstractQueueDirectStatisticsService queueDirectStatisticsService; - - @Mock - GetGroupStatisticsInput getGroupStatisticsInput; - @Mock - GetQueueStatisticsInput getQueueStatisticsInput; - @Mock - GetFlowStatisticsInput getFlowStatisticsInput; - @Mock - GetMeterStatisticsInput getMeterStatisticsInput; - @Mock - GetNodeConnectorStatisticsInput getNodeConnectorStatisticsInput; - - private OpendaylightDirectStatisticsService service; - private OpendaylightDirectStatisticsService emptyService; - - @Before - public void setUp() { - final OpendaylightDirectStatisticsServiceProvider provider = new OpendaylightDirectStatisticsServiceProvider(); - provider.register(AbstractFlowDirectStatisticsService.class, flowDirectStatisticsService); - provider.register(AbstractGroupDirectStatisticsService.class, groupDirectStatisticsService); - provider.register(AbstractMeterDirectStatisticsService.class, meterDirectStatisticsService); - provider.register(AbstractPortDirectStatisticsService.class, nodeConnectorDirectStatisticsService); - provider.register(AbstractQueueDirectStatisticsService.class, queueDirectStatisticsService); - - service = new OpendaylightDirectStatisticsServiceImpl(provider); - emptyService = new OpendaylightDirectStatisticsServiceImpl(new OpendaylightDirectStatisticsServiceProvider()); - } - - @Test - public void testGetGroupStatistics() { - service.getGroupStatistics(getGroupStatisticsInput); - verify(groupDirectStatisticsService).handleAndReply(getGroupStatisticsInput); - } - - @Test - public void testGetGroupStatisticsFail() throws Exception { - RpcResult result = emptyService - .getGroupStatistics(getGroupStatisticsInput) - .get(); - - assertFalse(result.isSuccessful()); - - for (RpcError error : result.getErrors()) { - assertTrue(error.getMessage().contains(AbstractGroupDirectStatisticsService.class.getSimpleName())); - } - - verify(groupDirectStatisticsService, times(0)).handleAndReply(getGroupStatisticsInput); - } - - @Test - public void testGetQueueStatistics() { - service.getQueueStatistics(getQueueStatisticsInput); - verify(queueDirectStatisticsService).handleAndReply(getQueueStatisticsInput); - } - - @Test - public void testGetQueueStatisticsFail() throws Exception { - RpcResult result = emptyService - .getQueueStatistics(getQueueStatisticsInput) - .get(); - - assertFalse(result.isSuccessful()); - - for (RpcError error : result.getErrors()) { - assertTrue(error.getMessage().contains(AbstractQueueDirectStatisticsService.class.getSimpleName())); - } - - verify(queueDirectStatisticsService, times(0)).handleAndReply(getQueueStatisticsInput); - } - - @Test - public void testGetFlowStatistics() { - service.getFlowStatistics(getFlowStatisticsInput); - verify(flowDirectStatisticsService).handleAndReply(getFlowStatisticsInput); - } - - @Test - public void testGetFlowStatisticsFail() throws Exception { - RpcResult result = emptyService - .getFlowStatistics(getFlowStatisticsInput) - .get(); - - assertFalse(result.isSuccessful()); - - for (RpcError error : result.getErrors()) { - assertTrue(error.getMessage().contains(AbstractFlowDirectStatisticsService.class.getSimpleName())); - } - - verify(flowDirectStatisticsService, times(0)).handleAndReply(getFlowStatisticsInput); - } - - @Test - public void testGetMeterStatistics() { - service.getMeterStatistics(getMeterStatisticsInput); - verify(meterDirectStatisticsService).handleAndReply(getMeterStatisticsInput); - } - - @Test - public void testGetMeterStatisticsFail() throws Exception { - RpcResult result = emptyService - .getMeterStatistics(getMeterStatisticsInput) - .get(); - - assertFalse(result.isSuccessful()); - - for (RpcError error : result.getErrors()) { - assertTrue(error.getMessage().contains(AbstractMeterDirectStatisticsService.class.getSimpleName())); - } - - verify(meterDirectStatisticsService, times(0)).handleAndReply(getMeterStatisticsInput); - } - - @Test - public void testGetNodeConnectorStatistics() { - service.getNodeConnectorStatistics(getNodeConnectorStatisticsInput); - verify(nodeConnectorDirectStatisticsService).handleAndReply(getNodeConnectorStatisticsInput); - } - - @Test - public void testGetNodeConnectorStatisticsFail() throws Exception { - RpcResult result = emptyService - .getNodeConnectorStatistics(getNodeConnectorStatisticsInput) - .get(); - - assertFalse(result.isSuccessful()); - - for (RpcError error : result.getErrors()) { - assertTrue(error.getMessage().contains(AbstractPortDirectStatisticsService.class.getSimpleName())); - } - - verify(nodeConnectorDirectStatisticsService, times(0)).handleAndReply(getNodeConnectorStatisticsInput); - } -} diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/FlowDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/FlowDirectStatisticsServiceTest.java index 994427ed2f..a188891f31 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/FlowDirectStatisticsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/FlowDirectStatisticsServiceTest.java @@ -43,11 +43,11 @@ import org.opendaylight.yangtools.yang.common.Uint8; public class FlowDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest { static final Uint8 TABLE_NO = Uint8.ONE; - private FlowDirectStatisticsService service; + private MultiGetFlowStatistics service; @Override public void setUp() { - service = new FlowDirectStatisticsService(requestContextStack, + service = new MultiGetFlowStatistics(requestContextStack, deviceContext, convertorManager, multipartWriterProvider); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/GroupDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/GroupDirectStatisticsServiceTest.java index 32b455ede7..0df17071bf 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/GroupDirectStatisticsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/GroupDirectStatisticsServiceTest.java @@ -38,11 +38,11 @@ import org.opendaylight.yangtools.yang.common.Uint64; public class GroupDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest { static final Uint32 GROUP_NO = Uint32.ONE; - private GroupDirectStatisticsService service; + private MultiGetGroupStatistics service; @Override public void setUp() { - service = new GroupDirectStatisticsService(requestContextStack, + service = new MultiGetGroupStatistics(requestContextStack, deviceContext, convertorManager, multipartWriterProvider); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MeterDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MeterDirectStatisticsServiceTest.java index 901b01f11d..c0fb584091 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MeterDirectStatisticsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/MeterDirectStatisticsServiceTest.java @@ -38,13 +38,13 @@ import org.opendaylight.yangtools.yang.common.Uint32; import org.opendaylight.yangtools.yang.common.Uint64; public class MeterDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest { - static final Uint32 METER_NO = Uint32.valueOf(1); - private MeterDirectStatisticsService service; + private static final Uint32 METER_NO = Uint32.ONE; + private MultiGetMeterStatistics service; @Override public void setUp() { - service = new MeterDirectStatisticsService(requestContextStack, deviceContext, convertorManager, - multipartWriterProvider); + service = new MultiGetMeterStatistics(requestContextStack, deviceContext, convertorManager, + multipartWriterProvider); } @Override diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/NodeConnectorDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/NodeConnectorDirectStatisticsServiceTest.java index e6e5f962ae..a5c858dc76 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/NodeConnectorDirectStatisticsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/NodeConnectorDirectStatisticsServiceTest.java @@ -38,14 +38,12 @@ import org.opendaylight.yangtools.yang.common.Uint32; import org.opendaylight.yangtools.yang.common.Uint64; public class NodeConnectorDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest { - private PortDirectStatisticsService service; + private MultiGetNodeConnectorStatistics service; @Override public void setUp() { - service = new PortDirectStatisticsService(requestContextStack, - deviceContext, - convertorManager, - multipartWriterProvider); + service = new MultiGetNodeConnectorStatistics(requestContextStack, deviceContext, convertorManager, + multipartWriterProvider); } @Override diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/QueueDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/QueueDirectStatisticsServiceTest.java index 1074bc1917..5b62c7b4d6 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/QueueDirectStatisticsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/multilayer/QueueDirectStatisticsServiceTest.java @@ -41,15 +41,12 @@ import org.opendaylight.yangtools.yang.common.Uint32; import org.opendaylight.yangtools.yang.common.Uint64; public class QueueDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest { - static final Uint32 QUEUE_NO = Uint32.ONE; - private QueueDirectStatisticsService service; + private MultiGetQueueStatistics service; @Override public void setUp() { - service = new QueueDirectStatisticsService(requestContextStack, - deviceContext, - convertorManager, - multipartWriterProvider); + service = new MultiGetQueueStatistics(requestContextStack, deviceContext, convertorManager, + multipartWriterProvider); } @Override @@ -57,7 +54,7 @@ public class QueueDirectStatisticsServiceTest extends AbstractDirectStatisticsSe final GetQueueStatisticsInput input = mock(GetQueueStatisticsInput.class); lenient().when(input.getNode()).thenReturn(createNodeRef(NODE_ID)); - when(input.getQueueId()).thenReturn(new QueueId(QUEUE_NO)); + when(input.getQueueId()).thenReturn(new QueueId(Uint32.ONE)); when(input.getNodeConnectorId()).thenReturn(new NodeConnectorId(NODE_ID + ":" + PORT_NO)); final MultipartRequestQueueCase body = (MultipartRequestQueueCase) ((MultipartRequestInput) service @@ -67,7 +64,7 @@ public class QueueDirectStatisticsServiceTest extends AbstractDirectStatisticsSe final MultipartRequestQueue queue = body.getMultipartRequestQueue(); assertEquals(PORT_NO, queue.getPortNo()); - assertEquals(QUEUE_NO, queue.getQueueId()); + assertEquals(Uint32.ONE, queue.getQueueId()); } @Override @@ -85,7 +82,7 @@ public class QueueDirectStatisticsServiceTest extends AbstractDirectStatisticsSe when(reply.getMultipartReplyBody()).thenReturn(queueCase); when(queueStat.getPortNo()).thenReturn(PORT_NO); - when(queueStat.getQueueId()).thenReturn(QUEUE_NO); + when(queueStat.getQueueId()).thenReturn(Uint32.ONE); when(queueStat.getTxBytes()).thenReturn(Uint64.ONE); when(queueStat.getTxErrors()).thenReturn(Uint64.ONE); when(queueStat.getTxPackets()).thenReturn(Uint64.ONE); @@ -96,16 +93,16 @@ public class QueueDirectStatisticsServiceTest extends AbstractDirectStatisticsSe assertTrue(output.nonnullQueueIdAndStatisticsMap().size() > 0); final QueueIdAndStatisticsMap map = output.nonnullQueueIdAndStatisticsMap().values().iterator().next(); - assertEquals(map.getQueueId().getValue(), QUEUE_NO); + assertEquals(map.getQueueId().getValue(), Uint32.ONE); assertEquals(map.getNodeConnectorId(), nodeConnectorId); } @Test public void testStoreStatisticsBarePortNo() { final QueueIdAndStatisticsMap map = mock(QueueIdAndStatisticsMap.class); - when(map.getQueueId()).thenReturn(new QueueId(QUEUE_NO)); + when(map.getQueueId()).thenReturn(new QueueId(Uint32.ONE)); when(map.getNodeConnectorId()).thenReturn(new NodeConnectorId("1")); - when(map.key()).thenReturn(new QueueIdAndStatisticsMapKey(new NodeConnectorId("1"), new QueueId(QUEUE_NO))); + when(map.key()).thenReturn(new QueueIdAndStatisticsMapKey(new NodeConnectorId("1"), new QueueId(Uint32.ONE))); final Map maps = BindingMap.of(map); final GetQueueStatisticsOutput output = mock(GetQueueStatisticsOutput.class); @@ -118,10 +115,10 @@ public class QueueDirectStatisticsServiceTest extends AbstractDirectStatisticsSe @Override public void testStoreStatistics() { final QueueIdAndStatisticsMap map = mock(QueueIdAndStatisticsMap.class); - when(map.getQueueId()).thenReturn(new QueueId(QUEUE_NO)); + when(map.getQueueId()).thenReturn(new QueueId(Uint32.ONE)); when(map.getNodeConnectorId()).thenReturn(new NodeConnectorId("openflow:1:1")); when(map.key()).thenReturn(new QueueIdAndStatisticsMapKey(new NodeConnectorId("openflow:1:1"), - new QueueId(QUEUE_NO))); + new QueueId(Uint32.ONE))); final Map maps = BindingMap.of(map); final GetQueueStatisticsOutput output = mock(GetQueueStatisticsOutput.class); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/FlowDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/FlowDirectStatisticsServiceTest.java index 7bfadf882c..6f44779e70 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/FlowDirectStatisticsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/FlowDirectStatisticsServiceTest.java @@ -51,12 +51,12 @@ import org.opendaylight.yangtools.yang.common.Uint8; public class FlowDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest { static final Uint8 TABLE_NO = Uint8.ONE; - private FlowDirectStatisticsService service; + private SingleGetFlowStatistics service; @Override public void setUp() { final DeviceFlowRegistry registry = mock(DeviceFlowRegistry.class); - service = new FlowDirectStatisticsService(requestContextStack, + service = new SingleGetFlowStatistics(requestContextStack, deviceContext, convertorManager, multipartWriterProvider); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/GroupDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/GroupDirectStatisticsServiceTest.java index 98cdbc55ab..bad403890d 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/GroupDirectStatisticsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/GroupDirectStatisticsServiceTest.java @@ -31,11 +31,11 @@ import org.opendaylight.yangtools.yang.common.Uint32; public class GroupDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest { static final Uint32 GROUP_NO = Uint32.ONE; - private GroupDirectStatisticsService service; + private SingleGetGroupStatistics service; @Override public void setUp() { - service = new GroupDirectStatisticsService(requestContextStack, + service = new SingleGetGroupStatistics(requestContextStack, deviceContext, convertorManager, multipartWriterProvider); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/MeterDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/MeterDirectStatisticsServiceTest.java index 543d6efaf3..616162fe83 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/MeterDirectStatisticsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/MeterDirectStatisticsServiceTest.java @@ -37,11 +37,11 @@ import org.opendaylight.yangtools.yang.common.Uint64; public class MeterDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest { static final Uint32 METER_NO = Uint32.ONE; - private MeterDirectStatisticsService service; + private SingleGetMeterStatistics service; @Override public void setUp() { - service = new MeterDirectStatisticsService(requestContextStack, + service = new SingleGetMeterStatistics(requestContextStack, deviceContext, convertorManager, multipartWriterProvider); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/NodeConnectorDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/NodeConnectorDirectStatisticsServiceTest.java index f927ad0dd9..6f721a5ef6 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/NodeConnectorDirectStatisticsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/NodeConnectorDirectStatisticsServiceTest.java @@ -29,14 +29,12 @@ import org.opendaylight.yangtools.yang.binding.util.BindingMap; import org.opendaylight.yangtools.yang.common.Uint32; public class NodeConnectorDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest { - private PortDirectStatisticsService service; + private SingleGetNodeConnectorStatistics service; @Override public void setUp() { - service = new PortDirectStatisticsService(requestContextStack, - deviceContext, - convertorManager, - multipartWriterProvider); + service = new SingleGetNodeConnectorStatistics(requestContextStack, deviceContext, convertorManager, + multipartWriterProvider); } @Override diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/QueueDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/QueueDirectStatisticsServiceTest.java index f1c7541b2a..85e07554f9 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/QueueDirectStatisticsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/singlelayer/QueueDirectStatisticsServiceTest.java @@ -27,7 +27,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511 import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetQueueStatisticsOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.queue.rev130925.QueueId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply; import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReplyBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequest; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; @@ -41,65 +40,57 @@ import org.opendaylight.yangtools.yang.common.Uint32; import org.opendaylight.yangtools.yang.common.Uint64; public class QueueDirectStatisticsServiceTest extends AbstractDirectStatisticsServiceTest { - static final Uint32 QUEUE_NO = Uint32.ONE; - private QueueDirectStatisticsService service; + private SingleGetQueueStatistics service; @Override public void setUp() { - service = new QueueDirectStatisticsService(requestContextStack, - deviceContext, - convertorManager, - multipartWriterProvider); + service = new SingleGetQueueStatistics(requestContextStack, deviceContext, convertorManager, + multipartWriterProvider); } @Override public void testBuildRequestBody() { - final GetQueueStatisticsInput input = mock(GetQueueStatisticsInput.class); + final var input = mock(GetQueueStatisticsInput.class); lenient().when(input.getNode()).thenReturn(createNodeRef(NODE_ID)); - when(input.getQueueId()).thenReturn(new QueueId(QUEUE_NO)); + when(input.getQueueId()).thenReturn(new QueueId(Uint32.ONE)); when(input.getNodeConnectorId()).thenReturn(nodeConnectorId); - final MultipartRequestQueueStats body = (MultipartRequestQueueStats) ((MultipartRequest) service + final var body = (MultipartRequestQueueStats) ((MultipartRequest) service .buildRequest(new Xid(Uint32.valueOf(42L)), input)) .getMultipartRequestBody(); assertEquals(nodeConnectorId, body.getNodeConnectorId()); - assertEquals(QUEUE_NO, body.getQueueId().getValue()); + assertEquals(Uint32.ONE, body.getQueueId().getValue()); } @Override public void testBuildReply() { - final QueueIdAndStatisticsMap queueStats = new QueueIdAndStatisticsMapBuilder() - .setQueueId(new QueueId(QUEUE_NO)) - .setNodeConnectorId(new NodeConnectorId(PORT_NO.toString())) - .setTransmittedBytes(new Counter64(Uint64.ONE)) - .setTransmissionErrors(new Counter64(Uint64.ONE)) - .setTransmittedBytes(new Counter64(Uint64.ONE)) - .build(); - - final MultipartReply reply = new MultipartReplyBuilder() - .setMultipartReplyBody(new MultipartReplyQueueStatsBuilder() - .setQueueIdAndStatisticsMap(BindingMap.of(queueStats)) - .build()) - .build(); - - final List input = List.of(reply); - final GetQueueStatisticsOutput output = service.buildReply(input, true); + final var output = service.buildReply(List.of(new MultipartReplyBuilder() + .setMultipartReplyBody(new MultipartReplyQueueStatsBuilder() + .setQueueIdAndStatisticsMap(BindingMap.of(new QueueIdAndStatisticsMapBuilder() + .setQueueId(new QueueId(Uint32.ONE)) + .setNodeConnectorId(new NodeConnectorId(PORT_NO.toString())) + .setTransmittedBytes(new Counter64(Uint64.ONE)) + .setTransmissionErrors(new Counter64(Uint64.ONE)) + .setTransmittedBytes(new Counter64(Uint64.ONE)) + .build())) + .build()) + .build()), true); assertTrue(output.nonnullQueueIdAndStatisticsMap().size() > 0); - final QueueIdAndStatisticsMap map = output.nonnullQueueIdAndStatisticsMap().values().iterator().next(); - assertEquals(map.getQueueId().getValue(), QUEUE_NO); + final var map = output.nonnullQueueIdAndStatisticsMap().values().iterator().next(); + assertEquals(map.getQueueId().getValue(), Uint32.ONE); assertEquals(map.getNodeConnectorId().getValue(), PORT_NO.toString()); } @Test public void testStoreStatisticsBarePortNo() { final QueueIdAndStatisticsMap map = mock(QueueIdAndStatisticsMap.class); - when(map.getQueueId()).thenReturn(new QueueId(QUEUE_NO)); + when(map.getQueueId()).thenReturn(new QueueId(Uint32.ONE)); when(map.getNodeConnectorId()).thenReturn(new NodeConnectorId("1")); when(map.key()).thenReturn( - new QueueIdAndStatisticsMapKey(new NodeConnectorId("1"), new QueueId(QUEUE_NO))); + new QueueIdAndStatisticsMapKey(new NodeConnectorId("1"), new QueueId(Uint32.ONE))); final GetQueueStatisticsOutput output = mock(GetQueueStatisticsOutput.class); Map stats = BindingMap.of(map); @@ -112,10 +103,10 @@ public class QueueDirectStatisticsServiceTest extends AbstractDirectStatisticsSe @Override public void testStoreStatistics() { final QueueIdAndStatisticsMap map = mock(QueueIdAndStatisticsMap.class); - when(map.getQueueId()).thenReturn(new QueueId(QUEUE_NO)); + when(map.getQueueId()).thenReturn(new QueueId(Uint32.ONE)); when(map.getNodeConnectorId()).thenReturn(new NodeConnectorId("openflow:1:1")); when(map.key()).thenReturn( - new QueueIdAndStatisticsMapKey(new NodeConnectorId("openflow:1:1"), new QueueId(QUEUE_NO))); + new QueueIdAndStatisticsMapKey(new NodeConnectorId("openflow:1:1"), new QueueId(Uint32.ONE))); final Map maps = BindingMap.of(map); final GetQueueStatisticsOutput output = mock(GetQueueStatisticsOutput.class); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/BarrierUtilTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/BarrierUtilTest.java index 2ed4f4132c..4a12b0969a 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/BarrierUtilTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/BarrierUtilTest.java @@ -5,24 +5,28 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.openflowplugin.impl.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + import com.google.common.base.Function; import com.google.common.util.concurrent.ListenableFuture; import org.apache.commons.lang3.tuple.Pair; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; -import org.mockito.ArgumentMatchers; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; @@ -39,13 +43,12 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder; */ @RunWith(MockitoJUnitRunner.class) public class BarrierUtilTest { - public static final NodeKey NODE_KEY = new NodeKey(new NodeId("ut-dummy-node")); private static final NodeRef NODE_REF = new NodeRef(InstanceIdentifier.create(Nodes.class) .child(Node.class, NODE_KEY)); @Mock - private FlowCapableTransactionService transactionService; + private SendBarrier sendBarrier; @Mock private Function, RpcResult>, RpcResult> compositeTransform; @Captor @@ -53,13 +56,13 @@ public class BarrierUtilTest { @Before public void setUp() { - Mockito.when(transactionService.sendBarrier(ArgumentMatchers.any())) + when(sendBarrier.invoke(any())) .thenReturn(RpcResultBuilder.success().buildFuture()); } @After public void tearDown() { - Mockito.verifyNoMoreInteractions(transactionService, compositeTransform); + verifyNoMoreInteractions(sendBarrier, compositeTransform); } @Test @@ -67,24 +70,23 @@ public class BarrierUtilTest { final String data = "ut-data1"; final ListenableFuture> input = RpcResultBuilder.success(data).buildFuture(); final ListenableFuture> chainResult = - BarrierUtil.chainBarrier(input, NODE_REF, transactionService, compositeTransform); + BarrierUtil.chainBarrier(input, NODE_REF, sendBarrier, compositeTransform); - Mockito.verify(transactionService).sendBarrier(ArgumentMatchers.any()); - Mockito.verify(compositeTransform).apply(pairCpt.capture()); + verify(sendBarrier).invoke(any()); + verify(compositeTransform).apply(pairCpt.capture()); final Pair, RpcResult> value = pairCpt.getValue(); - Assert.assertTrue(value.getLeft().isSuccessful()); - Assert.assertEquals(data, value.getLeft().getResult()); - Assert.assertTrue(value.getRight().isSuccessful()); - Assert.assertNull(value.getRight().getResult()); - + assertTrue(value.getLeft().isSuccessful()); + assertEquals(data, value.getLeft().getResult()); + assertTrue(value.getRight().isSuccessful()); + assertNull(value.getRight().getResult()); } @Test public void testCreateSendBarrierInput() { final SendBarrierInput barrierInput = BarrierUtil.createSendBarrierInput(NODE_REF); - Assert.assertEquals(NODE_REF, barrierInput.getNode()); - Assert.assertEquals(SendBarrierInput.class, barrierInput.implementedInterface()); + assertEquals(NODE_REF, barrierInput.getNode()); + assertEquals(SendBarrierInput.class, barrierInput.implementedInterface()); } } -- 2.36.6