From 5543345d32514bfa38292a5080e57b915e39ea1d Mon Sep 17 00:00:00 2001 From: Michal Cmarada Date: Mon, 27 May 2019 13:54:02 +0200 Subject: HC2VPP-411: remove deprecated interface-state - new ietf-interfaces obsoletes interfaces-state container, only interfaces container should be used from now on. Change-Id: Ifb24611a3dca987bdf6b029d32e01d9b1f479fe8 Signed-off-by: Michal Cmarada --- examples/docker/bgp_demo/postman_collection.json | 4 +- examples/docker/mpls_demo/postman_collection.json | 16 +- examples/docker/test/show_interfaces_state.sh | 4 +- l3/api/pom.xml | 6 + l3/api/src/main/yang/ietf-ip@2014-06-16.yang | 742 --------------------- l3/api/src/main/yang/nd-proxy@2017-03-15.yang | 12 - l3/api/src/main/yang/proxy-arp@2018-07-03.yang | 2 +- l3/impl/l3_postman_collection.json | 8 +- .../l3/read/factory/Ipv4StateReaderFactory.java | 24 +- .../l3/read/factory/Ipv6StateReaderFactory.java | 32 +- .../SubInterfaceStateIpv4ReaderFactory.java | 14 +- .../SubInterfaceStateIpv6ReaderFactory.java | 14 +- .../hc2vpp/l3/read/ipv4/Ipv4AddressCustomizer.java | 41 +- .../io/fd/hc2vpp/l3/read/ipv4/Ipv4Customizer.java | 8 +- .../l3/read/ipv4/Ipv4NeighbourCustomizer.java | 14 +- .../SubInterfaceIpv4AddressCustomizer.java | 8 +- .../hc2vpp/l3/read/ipv6/Ipv6AddressCustomizer.java | 28 +- .../io/fd/hc2vpp/l3/read/ipv6/Ipv6Customizer.java | 8 +- .../l3/read/ipv6/Ipv6NeighbourCustomizer.java | 14 +- .../hc2vpp/l3/read/ipv6/nd/NdProxyCustomizer.java | 18 +- .../SubInterfaceIpv6AddressCustomizer.java | 8 +- .../hc2vpp/l3/write/factory/Ipv4WriterFactory.java | 8 +- .../hc2vpp/l3/write/factory/Ipv6WriterFactory.java | 8 +- .../l3/write/ipv4/Ipv4AddressCustomizer.java | 10 +- .../hc2vpp/l3/write/ipv4/Ipv4AddressValidator.java | 8 +- .../io/fd/hc2vpp/l3/write/ipv4/Ipv4Customizer.java | 2 +- .../l3/write/ipv4/Ipv4NeighbourCustomizer.java | 6 +- .../l3/write/ipv4/Ipv4NeighbourValidator.java | 2 +- .../l3/write/ipv6/Ipv6AddressCustomizer.java | 4 +- .../hc2vpp/l3/write/ipv6/Ipv6AddressValidator.java | 2 +- .../io/fd/hc2vpp/l3/write/ipv6/Ipv6Customizer.java | 2 +- .../l3/write/ipv6/Ipv6NeighbourCustomizer.java | 4 +- .../l3/write/ipv6/Ipv6NeighbourValidator.java | 2 +- l3/impl/src/test/java/L3ModulesTest.java | 12 +- .../l3/read/ipv4/Ipv4AddressCustomizerTest.java | 32 +- .../fd/hc2vpp/l3/read/ipv4/Ipv4CustomizerTest.java | 8 +- .../l3/read/ipv4/Ipv4NeighbourCustomizerTest.java | 22 +- .../SubInterfaceIpv4AddressCustomizerTest.java | 26 +- .../SubInterfaceIpv4NeighbourCustomizerTest.java | 18 +- .../l3/read/ipv6/Ipv6AddressCustomizerTest.java | 22 +- .../l3/read/ipv6/Ipv6NeighbourCustomizerTest.java | 22 +- .../SubInterfaceIpv6AddressCustomizerTest.java | 18 +- .../SubInterfaceIpv6NeighbourCustomizerTest.java | 18 +- .../l3/read/ipv6/nd/NdProxyCustomizerTest.java | 26 +- .../l3/write/ipv4/Ipv4AddressCustomizerTest.java | 16 +- .../l3/write/ipv4/Ipv4AddressValidatorTest.java | 14 +- .../l3/write/ipv4/Ipv4NeighbourCustomizerTest.java | 8 +- .../l3/write/ipv4/Ipv4NeighbourValidatorTest.java | 8 +- .../l3/write/ipv6/Ipv6NeighbourCustomizerTest.java | 8 +- .../l3/write/ipv6/Ipv6NeighbourValidatorTest.java | 8 +- .../l3/write/ipv6/nd/NdProxyCustomizerTest.java | 4 +- .../hc2vpp/l3/utils/ip/read/IpAddressReader.java | 6 +- .../hc2vpp/l3/utils/ip/read/IpNeighbourReader.java | 6 +- .../io/fd/hc2vpp/l3/utils/ip/read/IpReader.java | 4 +- mpls/mpls_postman_collection.json | 4 +- .../src/main/yang/interface-nat@2017-08-16.yang | 6 - .../src/main/yang/subinterface-nat@2017-06-15.yang | 6 - .../read/ifc/AbstractInterfaceNatCustomizer.java | 2 +- .../ifc/AbstractSubInterfaceNatCustomizer.java | 4 +- .../hc2vpp/nat/read/ifc/IfcNatReaderFactory.java | 16 +- .../read/ifc/InterfaceInboundNatCustomizer.java | 2 +- .../read/ifc/InterfaceOutboundNatCustomizer.java | 2 +- .../nat/read/ifc/SubIfcNatReaderFactory.java | 24 +- .../read/ifc/SubInterfaceInboundNatCustomizer.java | 4 +- .../ifc/SubInterfaceOutboundNatCustomizer.java | 4 +- .../test/java/io/fd/hc2vpp/nat/NatModuleTest.java | 19 +- .../ifc/InterfaceInboundNatCustomizerTest.java | 12 +- nat/nat_postman_collection.json | 4 +- nsh/nsh_postman_collection.json | 12 +- .../java/io/fd/hc2vpp/routing/RoutingIIds.java | 4 +- .../routing/helpers/SchemaContextTestHelper.java | 2 +- .../hc2vpp/routing/write/PrefixCustomizerTest.java | 6 +- .../write/RouterAdvertisementsCustomizerTest.java | 4 +- .../main/yang/subinterface-span@2017-06-07.yang | 7 - v3po/api/src/main/yang/v3po@2019-05-02.yang | 147 +--- v3po/api/src/main/yang/vpp-pbb@2016-12-14.yang | 2 +- v3po/api/src/main/yang/vpp-vlan@2018-03-19.yang | 40 +- v3po/postman_rest_collection.json | 32 +- v3po/routing_postman_collection.json | 4 +- v3po/span_postman_collection.json | 10 +- .../main/java/io/fd/hc2vpp/v3po/V3poModule.java | 16 +- .../v3po/factory/InterfacesReaderFactory.java | 170 +++++ .../v3po/factory/InterfacesStateReaderFactory.java | 170 ----- .../v3po/factory/InterfacesWriterFactory.java | 60 +- .../SubinterfaceAugmentationReaderFactory.java | 119 ++++ .../SubinterfaceAugmentationWriterFactory.java | 22 +- ...SubinterfaceStateAugmentationReaderFactory.java | 120 ---- .../interfaces/AbstractUnnumberedCustomizer.java | 80 --- .../hc2vpp/v3po/interfaces/AfPacketCustomizer.java | 119 ---- .../hc2vpp/v3po/interfaces/AfPacketValidator.java | 79 --- .../hc2vpp/v3po/interfaces/EthernetCustomizer.java | 90 --- .../hc2vpp/v3po/interfaces/EthernetValidator.java | 48 -- .../fd/hc2vpp/v3po/interfaces/GreCustomizer.java | 147 ---- .../io/fd/hc2vpp/v3po/interfaces/GreValidator.java | 72 -- .../v3po/interfaces/InterconnectionWriteUtils.java | 159 ----- .../v3po/interfaces/InterfaceCustomizer.java | 124 ---- .../interfaces/InterfaceRoutingCustomizer.java | 61 -- .../v3po/interfaces/InterfaceRoutingValidator.java | 118 ---- .../interfaces/InterfaceUnnumberedCustomizer.java | 56 -- .../interfaces/InterfaceUnnumberedValidator.java | 55 -- .../hc2vpp/v3po/interfaces/InterfaceValidator.java | 74 -- .../interfaces/InterfacesStatisticsCustomizer.java | 67 -- .../interfaces/InterfacesStatisticsValidator.java | 55 -- .../io/fd/hc2vpp/v3po/interfaces/L2Customizer.java | 89 --- .../io/fd/hc2vpp/v3po/interfaces/L2Validator.java | 58 -- .../hc2vpp/v3po/interfaces/LoopbackCustomizer.java | 104 --- .../hc2vpp/v3po/interfaces/LoopbackValidator.java | 55 -- .../hc2vpp/v3po/interfaces/RewriteCustomizer.java | 135 ---- .../hc2vpp/v3po/interfaces/RewriteValidator.java | 55 -- .../hc2vpp/v3po/interfaces/RoutingCustomizer.java | 95 --- .../v3po/interfaces/SubInterfaceCustomizer.java | 193 ------ .../v3po/interfaces/SubInterfaceL2Customizer.java | 100 --- .../v3po/interfaces/SubInterfaceL2Validator.java | 58 -- .../interfaces/SubInterfaceRoutingCustomizer.java | 57 -- .../interfaces/SubInterfaceRoutingValidator.java | 110 --- .../SubInterfaceUnnumberedCustomizer.java | 57 -- .../SubInterfaceUnnumberedValidator.java | 55 -- .../v3po/interfaces/SubInterfaceValidator.java | 62 -- .../fd/hc2vpp/v3po/interfaces/TapV2Customizer.java | 227 ------- .../fd/hc2vpp/v3po/interfaces/TapV2Validator.java | 55 -- .../v3po/interfaces/VhostUserCustomizer.java | 169 ----- .../hc2vpp/v3po/interfaces/VhostUserValidator.java | 55 -- .../fd/hc2vpp/v3po/interfaces/VxlanCustomizer.java | 181 ----- .../hc2vpp/v3po/interfaces/VxlanGpeCustomizer.java | 164 ----- .../hc2vpp/v3po/interfaces/VxlanGpeValidator.java | 78 --- .../fd/hc2vpp/v3po/interfaces/VxlanValidator.java | 79 --- .../v3po/interfaces/pbb/PbbRewriteCustomizer.java | 111 --- .../v3po/interfaces/pbb/PbbRewriteValidator.java | 82 --- .../span/MirroredInterfaceCustomizer.java | 118 ---- .../span/MirroredInterfaceValidator.java | 79 --- .../v3po/interfacesstate/AfPacketCustomizer.java | 136 ---- .../v3po/interfacesstate/EthernetCustomizer.java | 105 --- .../hc2vpp/v3po/interfacesstate/GreCustomizer.java | 147 ---- .../interfacesstate/InterconnectionReadUtils.java | 129 ---- .../v3po/interfacesstate/InterfaceCustomizer.java | 173 ----- .../interfacesstate/InterfaceDataTranslator.java | 203 ------ .../InterfaceRoutingCustomizer.java | 88 --- .../InterfaceStatisticsCustomizer.java | 124 ---- .../hc2vpp/v3po/interfacesstate/L2Customizer.java | 119 ---- .../v3po/interfacesstate/RewriteCustomizer.java | 142 ---- .../v3po/interfacesstate/RoutingCustomizer.java | 65 -- .../interfacesstate/SubInterfaceCustomizer.java | 243 ------- .../interfacesstate/SubInterfaceL2Customizer.java | 119 ---- .../SubInterfaceRoutingCustomizer.java | 70 -- .../v3po/interfacesstate/TapV2Customizer.java | 212 ------ .../v3po/interfacesstate/VhostUserCustomizer.java | 167 ----- .../v3po/interfacesstate/VxlanCustomizer.java | 164 ----- .../v3po/interfacesstate/VxlanGpeCustomizer.java | 155 ----- .../cache/InterfaceCacheDumpManager.java | 59 -- .../cache/InterfaceCacheDumpManagerImpl.java | 202 ------ .../cache/InterfaceCacheDumpManagerProvider.java | 38 -- .../cache/InterfaceStatisticsManager.java | 26 - .../cache/InterfaceStatisticsManagerImpl.java | 37 - .../cache/InterfaceStatisticsManagerProvider.java | 27 - .../pbb/PbbRewriteStateCustomizer.java | 57 -- .../span/AbstractMirroredInterfacesCustomizer.java | 114 ---- .../InterfaceMirroredInterfacesCustomizer.java | 78 --- .../SubInterfaceMirroredInterfacesCustomizer.java | 80 --- .../hc2vpp/v3po/l2state/L2FibEntryCustomizer.java | 2 +- .../InterfaceChangeNotificationProducer.java | 10 +- .../io/fd/hc2vpp/v3po/read/AfPacketCustomizer.java | 136 ++++ .../io/fd/hc2vpp/v3po/read/EthernetCustomizer.java | 105 +++ .../java/io/fd/hc2vpp/v3po/read/GreCustomizer.java | 147 ++++ .../hc2vpp/v3po/read/InterconnectionReadUtils.java | 129 ++++ .../fd/hc2vpp/v3po/read/InterfaceCustomizer.java | 173 +++++ .../hc2vpp/v3po/read/InterfaceDataTranslator.java | 203 ++++++ .../v3po/read/InterfaceRoutingCustomizer.java | 88 +++ .../v3po/read/InterfaceStatisticsCustomizer.java | 124 ++++ .../java/io/fd/hc2vpp/v3po/read/L2Customizer.java | 119 ++++ .../io/fd/hc2vpp/v3po/read/RewriteCustomizer.java | 142 ++++ .../io/fd/hc2vpp/v3po/read/RoutingCustomizer.java | 65 ++ .../hc2vpp/v3po/read/SubInterfaceCustomizer.java | 243 +++++++ .../hc2vpp/v3po/read/SubInterfaceL2Customizer.java | 119 ++++ .../v3po/read/SubInterfaceRoutingCustomizer.java | 70 ++ .../io/fd/hc2vpp/v3po/read/TapV2Customizer.java | 212 ++++++ .../fd/hc2vpp/v3po/read/VhostUserCustomizer.java | 167 +++++ .../io/fd/hc2vpp/v3po/read/VxlanCustomizer.java | 164 +++++ .../io/fd/hc2vpp/v3po/read/VxlanGpeCustomizer.java | 155 +++++ .../v3po/read/cache/InterfaceCacheDumpManager.java | 59 ++ .../read/cache/InterfaceCacheDumpManagerImpl.java | 202 ++++++ .../cache/InterfaceCacheDumpManagerProvider.java | 38 ++ .../read/cache/InterfaceStatisticsManager.java | 26 + .../read/cache/InterfaceStatisticsManagerImpl.java | 37 + .../cache/InterfaceStatisticsManagerProvider.java | 27 + .../hc2vpp/v3po/read/pbb/PbbRewriteCustomizer.java | 57 ++ .../span/AbstractMirroredInterfacesCustomizer.java | 114 ++++ .../InterfaceMirroredInterfacesCustomizer.java | 78 +++ .../SubInterfaceMirroredInterfacesCustomizer.java | 80 +++ .../io/fd/hc2vpp/v3po/util/SubInterfaceUtils.java | 5 +- .../v3po/write/AbstractUnnumberedCustomizer.java | 80 +++ .../fd/hc2vpp/v3po/write/AfPacketCustomizer.java | 119 ++++ .../io/fd/hc2vpp/v3po/write/AfPacketValidator.java | 79 +++ .../fd/hc2vpp/v3po/write/EthernetCustomizer.java | 90 +++ .../io/fd/hc2vpp/v3po/write/EthernetValidator.java | 48 ++ .../io/fd/hc2vpp/v3po/write/GreCustomizer.java | 147 ++++ .../java/io/fd/hc2vpp/v3po/write/GreValidator.java | 72 ++ .../v3po/write/InterconnectionWriteUtils.java | 159 +++++ .../fd/hc2vpp/v3po/write/InterfaceCustomizer.java | 124 ++++ .../v3po/write/InterfaceRoutingCustomizer.java | 61 ++ .../v3po/write/InterfaceRoutingValidator.java | 118 ++++ .../v3po/write/InterfaceUnnumberedCustomizer.java | 56 ++ .../v3po/write/InterfaceUnnumberedValidator.java | 55 ++ .../fd/hc2vpp/v3po/write/InterfaceValidator.java | 74 ++ .../v3po/write/InterfacesStatisticsCustomizer.java | 67 ++ .../v3po/write/InterfacesStatisticsValidator.java | 55 ++ .../java/io/fd/hc2vpp/v3po/write/L2Customizer.java | 89 +++ .../java/io/fd/hc2vpp/v3po/write/L2Validator.java | 58 ++ .../fd/hc2vpp/v3po/write/LoopbackCustomizer.java | 104 +++ .../io/fd/hc2vpp/v3po/write/LoopbackValidator.java | 55 ++ .../io/fd/hc2vpp/v3po/write/RewriteCustomizer.java | 135 ++++ .../io/fd/hc2vpp/v3po/write/RewriteValidator.java | 55 ++ .../io/fd/hc2vpp/v3po/write/RoutingCustomizer.java | 95 +++ .../hc2vpp/v3po/write/SubInterfaceCustomizer.java | 193 ++++++ .../v3po/write/SubInterfaceL2Customizer.java | 100 +++ .../hc2vpp/v3po/write/SubInterfaceL2Validator.java | 58 ++ .../v3po/write/SubInterfaceRoutingCustomizer.java | 57 ++ .../v3po/write/SubInterfaceRoutingValidator.java | 110 +++ .../write/SubInterfaceUnnumberedCustomizer.java | 57 ++ .../write/SubInterfaceUnnumberedValidator.java | 55 ++ .../hc2vpp/v3po/write/SubInterfaceValidator.java | 62 ++ .../io/fd/hc2vpp/v3po/write/TapV2Customizer.java | 227 +++++++ .../io/fd/hc2vpp/v3po/write/TapV2Validator.java | 55 ++ .../fd/hc2vpp/v3po/write/VhostUserCustomizer.java | 169 +++++ .../fd/hc2vpp/v3po/write/VhostUserValidator.java | 55 ++ .../io/fd/hc2vpp/v3po/write/VxlanCustomizer.java | 181 +++++ .../fd/hc2vpp/v3po/write/VxlanGpeCustomizer.java | 164 +++++ .../io/fd/hc2vpp/v3po/write/VxlanGpeValidator.java | 78 +++ .../io/fd/hc2vpp/v3po/write/VxlanValidator.java | 79 +++ .../v3po/write/pbb/PbbRewriteCustomizer.java | 111 +++ .../hc2vpp/v3po/write/pbb/PbbRewriteValidator.java | 82 +++ .../write/span/MirroredInterfaceCustomizer.java | 118 ++++ .../write/span/MirroredInterfaceValidator.java | 79 +++ .../AbstractUnnumberedCustomizerTest.java | 87 --- .../v3po/interfaces/AfPacketCustomizerTest.java | 112 ---- .../v3po/interfaces/AfPacketValidatorTest.java | 88 --- .../v3po/interfaces/EthernetCustomizerTest.java | 82 --- .../v3po/interfaces/EthernetValidatorTest.java | 76 --- .../hc2vpp/v3po/interfaces/GreCustomizerTest.java | 188 ------ .../hc2vpp/v3po/interfaces/GreValidatorTest.java | 111 --- .../v3po/interfaces/InterfaceCustomizerTest.java | 125 ---- .../interfaces/InterfaceRoutingCustomizerTest.java | 115 ---- .../interfaces/InterfaceRoutingValidatorTest.java | 146 ---- .../v3po/interfaces/InterfaceTypeTestUtils.java | 40 -- .../InterfaceUnnumberedCustomizerTest.java | 55 -- .../InterfaceUnnumberedValidatorTest.java | 82 --- .../v3po/interfaces/InterfaceValidatorTest.java | 85 --- .../InterfacesStatisticsCustomizerTest.java | 74 -- .../hc2vpp/v3po/interfaces/L2CustomizerTest.java | 151 ----- .../v3po/interfaces/LoopbackCustomizerTest.java | 105 --- .../v3po/interfaces/RewriteCustomizerTest.java | 197 ------ .../interfaces/SubInterfaceCustomizerTest.java | 256 ------- .../interfaces/SubInterfaceL2CustomizerTest.java | 110 --- .../SubInterfaceRoutingCustomizerTest.java | 148 ---- .../SubInterfaceRoutingValidatorTest.java | 123 ---- .../SubInterfaceUnnumberedCustomizerTest.java | 61 -- .../SubInterfaceUnnumberedValidatorTest.java | 80 --- .../v3po/interfaces/SubInterfaceValidatorTest.java | 85 --- .../v3po/interfaces/TapV2CustomizerTest.java | 162 ----- .../v3po/interfaces/VhostUserCustomizerTest.java | 205 ------ .../v3po/interfaces/VhostUserValidatorTest.java | 79 --- .../v3po/interfaces/VxlanCustomizerTest.java | 223 ------- .../v3po/interfaces/VxlanGpeCustomizerTest.java | 210 ------ .../v3po/interfaces/VxlanGpeValidatorTest.java | 151 ----- .../hc2vpp/v3po/interfaces/VxlanValidatorTest.java | 142 ---- .../interfaces/pbb/PbbRewriteCustomizerTest.java | 193 ------ .../interfaces/pbb/PbbRewriteValidatorTest.java | 189 ------ .../span/MirroredInterfacesCustomizerTest.java | 113 ---- .../span/MirroredInterfacesValidatorTest.java | 115 ---- .../interfacesstate/AfPacketCustomizerTest.java | 127 ---- .../interfacesstate/EthernetCustomizerTest.java | 98 --- .../v3po/interfacesstate/GreCustomizerTest.java | 129 ---- .../interfacesstate/InterfaceCustomizerTest.java | 196 ------ .../InterfaceDataTranslatorTest.java | 104 --- .../InterfaceRoutingCustomizerTest.java | 94 --- .../InterfaceStatisticsCustomizerTest.java | 124 ---- .../v3po/interfacesstate/L2CustomizerTest.java | 160 ----- .../interfacesstate/RewriteCustomizerTest.java | 118 ---- .../SubInterfaceCustomizerTest.java | 138 ---- .../SubInterfaceL2CustomizerTest.java | 73 -- .../SubInterfaceRoutingCustomizerTest.java | 121 ---- .../v3po/interfacesstate/TapV2CustomizerTest.java | 142 ---- .../interfacesstate/VhostUserCustomizerTest.java | 121 ---- .../v3po/interfacesstate/VxlanCustomizerTest.java | 155 ----- .../interfacesstate/VxlanGpeCustomizerTest.java | 141 ---- .../cache/InterfaceCacheDumpManagerImplTest.java | 208 ------ .../pbb/PbbRewriteStateCustomizerTest.java | 35 - .../span/MirroredInterfacesCustomizerTest.java | 128 ---- .../InterfaceChangeNotificationProducerTest.java | 6 +- .../hc2vpp/v3po/read/AfPacketCustomizerTest.java | 127 ++++ .../hc2vpp/v3po/read/EthernetCustomizerTest.java | 98 +++ .../io/fd/hc2vpp/v3po/read/GreCustomizerTest.java | 128 ++++ .../hc2vpp/v3po/read/InterfaceCustomizerTest.java | 196 ++++++ .../v3po/read/InterfaceDataTranslatorTest.java | 104 +++ .../v3po/read/InterfaceRoutingCustomizerTest.java | 94 +++ .../read/InterfaceStatisticsCustomizerTest.java | 124 ++++ .../io/fd/hc2vpp/v3po/read/L2CustomizerTest.java | 159 +++++ .../fd/hc2vpp/v3po/read/RewriteCustomizerTest.java | 118 ++++ .../v3po/read/SubInterfaceCustomizerTest.java | 138 ++++ .../v3po/read/SubInterfaceL2CustomizerTest.java | 73 ++ .../read/SubInterfaceRoutingCustomizerTest.java | 121 ++++ .../fd/hc2vpp/v3po/read/TapV2CustomizerTest.java | 142 ++++ .../hc2vpp/v3po/read/VhostUserCustomizerTest.java | 121 ++++ .../fd/hc2vpp/v3po/read/VxlanCustomizerTest.java | 155 +++++ .../hc2vpp/v3po/read/VxlanGpeCustomizerTest.java | 141 ++++ .../cache/InterfaceCacheDumpManagerImplTest.java | 208 ++++++ .../v3po/read/pbb/PbbRewriteCustomizerTest.java | 35 + .../span/MirroredInterfacesCustomizerTest.java | 128 ++++ .../write/AbstractUnnumberedCustomizerTest.java | 87 +++ .../hc2vpp/v3po/write/AfPacketCustomizerTest.java | 112 ++++ .../hc2vpp/v3po/write/AfPacketValidatorTest.java | 88 +++ .../hc2vpp/v3po/write/EthernetCustomizerTest.java | 82 +++ .../hc2vpp/v3po/write/EthernetValidatorTest.java | 76 +++ .../io/fd/hc2vpp/v3po/write/GreCustomizerTest.java | 188 ++++++ .../io/fd/hc2vpp/v3po/write/GreValidatorTest.java | 111 +++ .../hc2vpp/v3po/write/InterfaceCustomizerTest.java | 125 ++++ .../v3po/write/InterfaceRoutingCustomizerTest.java | 115 ++++ .../v3po/write/InterfaceRoutingValidatorTest.java | 146 ++++ .../hc2vpp/v3po/write/InterfaceTypeTestUtils.java | 40 ++ .../write/InterfaceUnnumberedCustomizerTest.java | 55 ++ .../write/InterfaceUnnumberedValidatorTest.java | 82 +++ .../hc2vpp/v3po/write/InterfaceValidatorTest.java | 85 +++ .../write/InterfacesStatisticsCustomizerTest.java | 74 ++ .../io/fd/hc2vpp/v3po/write/L2CustomizerTest.java | 151 +++++ .../hc2vpp/v3po/write/LoopbackCustomizerTest.java | 105 +++ .../hc2vpp/v3po/write/RewriteCustomizerTest.java | 197 ++++++ .../v3po/write/SubInterfaceCustomizerTest.java | 256 +++++++ .../v3po/write/SubInterfaceL2CustomizerTest.java | 110 +++ .../write/SubInterfaceRoutingCustomizerTest.java | 148 ++++ .../write/SubInterfaceRoutingValidatorTest.java | 123 ++++ .../SubInterfaceUnnumberedCustomizerTest.java | 61 ++ .../write/SubInterfaceUnnumberedValidatorTest.java | 80 +++ .../v3po/write/SubInterfaceValidatorTest.java | 85 +++ .../fd/hc2vpp/v3po/write/TapV2CustomizerTest.java | 162 +++++ .../hc2vpp/v3po/write/VhostUserCustomizerTest.java | 205 ++++++ .../hc2vpp/v3po/write/VhostUserValidatorTest.java | 79 +++ .../fd/hc2vpp/v3po/write/VxlanCustomizerTest.java | 223 +++++++ .../hc2vpp/v3po/write/VxlanGpeCustomizerTest.java | 210 ++++++ .../hc2vpp/v3po/write/VxlanGpeValidatorTest.java | 151 +++++ .../fd/hc2vpp/v3po/write/VxlanValidatorTest.java | 142 ++++ .../v3po/write/pbb/PbbRewriteCustomizerTest.java | 193 ++++++ .../v3po/write/pbb/PbbRewriteValidatorTest.java | 189 ++++++ .../span/MirroredInterfacesCustomizerTest.java | 113 ++++ .../span/MirroredInterfacesValidatorTest.java | 115 ++++ .../main/yang/interface-policer@2017-03-15.yang | 6 - .../main/yang/vpp-interface-acl@2017-03-15.yang | 5 - .../main/yang/vpp-subinterface-acl@2017-03-15.yang | 5 - .../policer/read/InterfacePolicerCustomizer.java | 6 +- .../read/InterfacePolicerReaderFactory.java | 16 +- .../factory/read/InterfaceAclReaderFactory.java | 16 +- .../factory/read/SubInterfaceAclReaderFactory.java | 26 +- .../vpp/classifier/read/ClassifySessionReader.java | 4 +- .../vpp/classifier/read/ClassifyTableReader.java | 4 +- .../vpp/classifier/read/acl/AclCustomizer.java | 6 +- .../read/acl/SubInterfaceAclCustomizer.java | 10 +- .../vpp/classifier/read/acl/AclCustomizerTest.java | 12 +- .../read/acl/SubInterfaceAclCustomizerTest.java | 22 +- vpp-classifier/policer_postman_collection.json | 4 +- 357 files changed, 15188 insertions(+), 16100 deletions(-) delete mode 100644 l3/api/src/main/yang/ietf-ip@2014-06-16.yang create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesReaderFactory.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesStateReaderFactory.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceAugmentationReaderFactory.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceStateAugmentationReaderFactory.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/AbstractUnnumberedCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/AfPacketCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/AfPacketValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/EthernetCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/EthernetValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/GreCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/GreValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterconnectionWriteUtils.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceUnnumberedCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceUnnumberedValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfacesStatisticsCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfacesStatisticsValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/L2Customizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/L2Validator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/LoopbackCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/LoopbackValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RewriteCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RewriteValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RoutingCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceL2Customizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceL2Validator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceUnnumberedCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceUnnumberedValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/TapV2Customizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/TapV2Validator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VhostUserCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VhostUserValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfaceCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfaceValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/AfPacketCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/EthernetCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterconnectionReadUtils.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceRoutingCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceStatisticsCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/L2Customizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/RoutingCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceL2Customizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceRoutingCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/TapV2Customizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VhostUserCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManager.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManagerImpl.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManagerProvider.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceStatisticsManager.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceStatisticsManagerImpl.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceStatisticsManagerProvider.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/pbb/PbbRewriteStateCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/AbstractMirroredInterfacesCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/InterfaceMirroredInterfacesCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/SubInterfaceMirroredInterfacesCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/AfPacketCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/EthernetCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/GreCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterconnectionReadUtils.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterfaceCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterfaceDataTranslator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterfaceRoutingCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterfaceStatisticsCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/L2Customizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/RewriteCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/RoutingCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/SubInterfaceCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/SubInterfaceL2Customizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/SubInterfaceRoutingCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/TapV2Customizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/VhostUserCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/VxlanCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/VxlanGpeCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManager.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerImpl.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerProvider.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceStatisticsManager.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceStatisticsManagerImpl.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceStatisticsManagerProvider.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/pbb/PbbRewriteCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/span/AbstractMirroredInterfacesCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/span/InterfaceMirroredInterfacesCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/span/SubInterfaceMirroredInterfacesCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/AbstractUnnumberedCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/AfPacketCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/AfPacketValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/EthernetCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/EthernetValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/GreCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/GreValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterconnectionWriteUtils.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceRoutingCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceRoutingValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceUnnumberedCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceUnnumberedValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfacesStatisticsCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfacesStatisticsValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/L2Customizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/L2Validator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/LoopbackCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/LoopbackValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/RewriteCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/RewriteValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/RoutingCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceL2Customizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceL2Validator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceRoutingCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceRoutingValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceUnnumberedCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceUnnumberedValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/TapV2Customizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/TapV2Validator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VhostUserCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VhostUserValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VxlanCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VxlanGpeCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VxlanGpeValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VxlanValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/pbb/PbbRewriteCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/pbb/PbbRewriteValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/span/MirroredInterfaceCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/span/MirroredInterfaceValidator.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/AbstractUnnumberedCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/AfPacketCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/AfPacketValidatorTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/EthernetCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/EthernetValidatorTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/GreCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/GreValidatorTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingValidatorTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceTypeTestUtils.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceUnnumberedCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceUnnumberedValidatorTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceValidatorTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfacesStatisticsCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/L2CustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/LoopbackCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/RewriteCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceL2CustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingValidatorTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceUnnumberedCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceUnnumberedValidatorTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceValidatorTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/TapV2CustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VhostUserCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VhostUserValidatorTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VxlanCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeValidatorTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VxlanValidatorTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteValidatorTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfacesCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfacesValidatorTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/AfPacketCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/EthernetCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslatorTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceRoutingCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceStatisticsCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceL2CustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceRoutingCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/TapV2CustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VhostUserCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManagerImplTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/pbb/PbbRewriteStateCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/span/MirroredInterfacesCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/AfPacketCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/EthernetCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/GreCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/InterfaceCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/InterfaceDataTranslatorTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/InterfaceRoutingCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/InterfaceStatisticsCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/L2CustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/RewriteCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/SubInterfaceCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/SubInterfaceL2CustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/SubInterfaceRoutingCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/TapV2CustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/VhostUserCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/VxlanCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/VxlanGpeCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerImplTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/pbb/PbbRewriteCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/span/MirroredInterfacesCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/AbstractUnnumberedCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/AfPacketCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/AfPacketValidatorTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/EthernetCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/EthernetValidatorTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/GreCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/GreValidatorTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceRoutingCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceRoutingValidatorTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceTypeTestUtils.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceUnnumberedCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceUnnumberedValidatorTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceValidatorTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfacesStatisticsCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/L2CustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/LoopbackCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/RewriteCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceL2CustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceRoutingCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceRoutingValidatorTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceUnnumberedCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceUnnumberedValidatorTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceValidatorTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/TapV2CustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VhostUserCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VhostUserValidatorTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VxlanCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VxlanGpeCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VxlanGpeValidatorTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VxlanValidatorTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/pbb/PbbRewriteCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/pbb/PbbRewriteValidatorTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/span/MirroredInterfacesCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/span/MirroredInterfacesValidatorTest.java diff --git a/examples/docker/bgp_demo/postman_collection.json b/examples/docker/bgp_demo/postman_collection.json index 825f41820..7c2dacc0e 100644 --- a/examples/docker/bgp_demo/postman_collection.json +++ b/examples/docker/bgp_demo/postman_collection.json @@ -289,7 +289,7 @@ "raw": "{\n \"interface\": [\n {\n \"name\": \"loop0\",\n \"enabled\": true,\n \"type\": \"v3po:loopback\",\n \"ietf-ip:ipv4\": {\n \"address\": [\n {\n \"ip\": \"10.100.1.1\",\n \"prefix-length\": 24\n }\n ]\n },\n \"v3po:ethernet\": {\n \"mtu\": 9216\n }\n }\n ]\n}" }, "url": { - "raw": "https://172.17.0.3:8445/restconf/operational/ietf-interfaces:interfaces-state/interface/loop0", + "raw": "https://172.17.0.3:8445/restconf/operational/ietf-interfaces:interfaces/interface/loop0", "protocol": "https", "host": [ "172", @@ -301,7 +301,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "loop0" ] diff --git a/examples/docker/mpls_demo/postman_collection.json b/examples/docker/mpls_demo/postman_collection.json index a2ca7fc11..2ebf73bc0 100644 --- a/examples/docker/mpls_demo/postman_collection.json +++ b/examples/docker/mpls_demo/postman_collection.json @@ -354,7 +354,7 @@ "raw": "{\r\n \r\n \"interface\": [\r\n {\r\n \"name\": \"testInterface\",\r\n \"description\": \"for testing purposes\",\r\n \"type\": \"iana-if-type:ethernetCsmacd\",\r\n \"enabled\": \"true\",\r\n \"link-up-down-trap-enable\": \"enabled\",\r\n \"ietf-ip:ipv4\": {\r\n \"enabled\": \"true\",\r\n \"mtu\": \"1500\",\r\n \"address\": [\r\n {\r\n \"ip\": \"1.2.3.0\",\r\n \"netmask\": \"255.255.255.0\"\r\n }\r\n ]\r\n }\r\n }\r\n ]\r\n \r\n}" }, "url": { - "raw": "https://172.17.0.4:8445/restconf/operational/ietf-interfaces:interfaces-state/", + "raw": "https://172.17.0.4:8445/restconf/operational/ietf-interfaces:interfaces/", "protocol": "https", "host": [ "172", @@ -366,7 +366,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "" ] } @@ -652,7 +652,7 @@ "raw": "{\r\n \r\n \"interface\": [\r\n {\r\n \"name\": \"testInterface\",\r\n \"description\": \"for testing purposes\",\r\n \"type\": \"iana-if-type:ethernetCsmacd\",\r\n \"enabled\": \"true\",\r\n \"link-up-down-trap-enable\": \"enabled\",\r\n \"ietf-ip:ipv4\": {\r\n \"enabled\": \"true\",\r\n \"mtu\": \"1500\",\r\n \"address\": [\r\n {\r\n \"ip\": \"1.2.3.0\",\r\n \"netmask\": \"255.255.255.0\"\r\n }\r\n ]\r\n }\r\n }\r\n ]\r\n \r\n}" }, "url": { - "raw": "https://172.17.0.5:8445/restconf/operational/ietf-interfaces:interfaces-state/", + "raw": "https://172.17.0.5:8445/restconf/operational/ietf-interfaces:interfaces/", "protocol": "https", "host": [ "172", @@ -664,7 +664,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "" ] } @@ -1142,7 +1142,7 @@ "raw": "{\r\n \r\n \"interface\": [\r\n {\r\n \"name\": \"testInterface\",\r\n \"description\": \"for testing purposes\",\r\n \"type\": \"iana-if-type:ethernetCsmacd\",\r\n \"enabled\": \"true\",\r\n \"link-up-down-trap-enable\": \"enabled\",\r\n \"ietf-ip:ipv4\": {\r\n \"enabled\": \"true\",\r\n \"mtu\": \"1500\",\r\n \"address\": [\r\n {\r\n \"ip\": \"1.2.3.0\",\r\n \"netmask\": \"255.255.255.0\"\r\n }\r\n ]\r\n }\r\n }\r\n ]\r\n \r\n}" }, "url": { - "raw": "https://172.17.0.2:8445/restconf/operational/ietf-interfaces:interfaces-state/", + "raw": "https://172.17.0.2:8445/restconf/operational/ietf-interfaces:interfaces/", "protocol": "https", "host": [ "172", @@ -1154,7 +1154,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "" ] } @@ -1554,7 +1554,7 @@ "raw": "{\r\n \r\n \"interface\": [\r\n {\r\n \"name\": \"testInterface\",\r\n \"description\": \"for testing purposes\",\r\n \"type\": \"iana-if-type:ethernetCsmacd\",\r\n \"enabled\": \"true\",\r\n \"link-up-down-trap-enable\": \"enabled\",\r\n \"ietf-ip:ipv4\": {\r\n \"enabled\": \"true\",\r\n \"mtu\": \"1500\",\r\n \"address\": [\r\n {\r\n \"ip\": \"1.2.3.0\",\r\n \"netmask\": \"255.255.255.0\"\r\n }\r\n ]\r\n }\r\n }\r\n ]\r\n \r\n}" }, "url": { - "raw": "https://172.17.0.3:8445/restconf/operational/ietf-interfaces:interfaces-state/", + "raw": "https://172.17.0.3:8445/restconf/operational/ietf-interfaces:interfaces/", "protocol": "https", "host": [ "172", @@ -1566,7 +1566,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "" ] } diff --git a/examples/docker/test/show_interfaces_state.sh b/examples/docker/test/show_interfaces_state.sh index 06d972e79..fe154b2e7 100755 --- a/examples/docker/test/show_interfaces_state.sh +++ b/examples/docker/test/show_interfaces_state.sh @@ -3,10 +3,10 @@ # Obtain IP of the container # $1 - container name ip=$(/hc2vpp/test/docker_ip.sh $1) -url="https://$ip:8445/restconf/operational/ietf-interfaces:interfaces-state/" +url="https://$ip:8445/restconf/operational/ietf-interfaces:interfaces/" echo "GET $url" -# Show interfaces-state +# Show interfaces curl --insecure -X GET $url \ -H 'authorization: Basic YWRtaW46YWRtaW4=' \ -H 'cache-control: no-cache' \ diff --git a/l3/api/pom.xml b/l3/api/pom.xml index abcd10b93..59f905e9a 100644 --- a/l3/api/pom.xml +++ b/l3/api/pom.xml @@ -42,6 +42,12 @@ rfc8343 ${odl.binding.model.version} + + + org.opendaylight.mdsal.binding.model.ietf + rfc8344 + ${odl.binding.model.version} + org.opendaylight.mdsal.model ietf-inet-types-2013-07-15 diff --git a/l3/api/src/main/yang/ietf-ip@2014-06-16.yang b/l3/api/src/main/yang/ietf-ip@2014-06-16.yang deleted file mode 100644 index f6c59edea..000000000 --- a/l3/api/src/main/yang/ietf-ip@2014-06-16.yang +++ /dev/null @@ -1,742 +0,0 @@ -module ietf-ip { - - yang-version 1; - - namespace - "urn:ietf:params:xml:ns:yang:ietf-ip"; - - prefix ip; - - import ietf-interfaces { - prefix if; - } - import ietf-inet-types { - prefix inet; - } - import ietf-yang-types { - prefix yang; - } - - organization - "IETF NETMOD (NETCONF Data Modeling Language) Working Group"; - - contact - "WG Web: - WG List: - - WG Chair: Thomas Nadeau - - - WG Chair: Juergen Schoenwaelder - - - Editor: Martin Bjorklund - "; - - description - "This module contains a collection of YANG definitions for - configuring IP implementations. - - Copyright (c) 2014 IETF Trust and the persons identified as - authors of the code. All rights reserved. - - Redistribution and use in source and binary forms, with or - without modification, is permitted pursuant to, and subject - to the license terms contained in, the Simplified BSD License - set forth in Section 4.c of the IETF Trust's Legal Provisions - Relating to IETF Documents - (http://trustee.ietf.org/license-info). - - This version of this YANG module is part of RFC 7277; see - the RFC itself for full legal notices."; - - revision "2014-06-16" { - description "Initial revision."; - reference - "RFC 7277: A YANG Data Model for IP Management"; - - } - - - feature ipv4-non-contiguous-netmasks { - description - "Indicates support for configuring non-contiguous - subnet masks."; - } - - feature ipv6-privacy-autoconf { - description - "Indicates support for Privacy Extensions for Stateless Address - Autoconfiguration in IPv6."; - reference - "RFC 4941: Privacy Extensions for Stateless Address - Autoconfiguration in IPv6"; - - } - - typedef ip-address-origin { - type enumeration { - enum "other" { - value 0; - description - "None of the following."; - } - enum "static" { - value 1; - description - "Indicates that the address has been statically - configured - for example, using NETCONF or a Command Line - Interface."; - } - enum "dhcp" { - value 2; - description - "Indicates an address that has been assigned to this - system by a DHCP server."; - } - enum "link-layer" { - value 3; - description - "Indicates an address created by IPv6 stateless - autoconfiguration that embeds a link-layer address in its - interface identifier."; - } - enum "random" { - value 4; - description - "Indicates an address chosen by the system at - - random, e.g., an IPv4 address within 169.254/16, an - RFC 4941 temporary address, or an RFC 7217 semantically - opaque address."; - reference - "RFC 4941: Privacy Extensions for Stateless Address - Autoconfiguration in IPv6 - RFC 7217: A Method for Generating Semantically Opaque - Interface Identifiers with IPv6 Stateless - Address Autoconfiguration (SLAAC)"; - - } - } - description - "The origin of an address."; - } - - typedef neighbor-origin { - type enumeration { - enum "other" { - value 0; - description - "None of the following."; - } - enum "static" { - value 1; - description - "Indicates that the mapping has been statically - configured - for example, using NETCONF or a Command Line - Interface."; - } - enum "dynamic" { - value 2; - description - "Indicates that the mapping has been dynamically resolved - using, e.g., IPv4 ARP or the IPv6 Neighbor Discovery - protocol."; - } - } - description - "The origin of a neighbor entry."; - } - - augment /if:interfaces/if:interface { - description - "Parameters for configuring IP on interfaces. - - If an interface is not capable of running IP, the server - must not allow the client to configure these parameters."; - container ipv4 { - presence - "Enables IPv4 unless the 'enabled' leaf - (which defaults to 'true') is set to 'false'"; - description - "Parameters for the IPv4 address family."; - leaf enabled { - type boolean; - default 'true'; - description - "Controls whether IPv4 is enabled or disabled on this - interface. When IPv4 is enabled, this interface is - connected to an IPv4 stack, and the interface can send - and receive IPv4 packets."; - } - - leaf forwarding { - type boolean; - default 'false'; - description - "Controls IPv4 packet forwarding of datagrams received by, - but not addressed to, this interface. IPv4 routers - forward datagrams. IPv4 hosts do not (except those - source-routed via the host)."; - } - - leaf mtu { - type uint16 { - range "68..max"; - } - units "octets"; - description - "The size, in octets, of the largest IPv4 packet that the - interface will send and receive. - - The server may restrict the allowed values for this leaf, - depending on the interface's type. - - If this leaf is not configured, the operationally used MTU - depends on the interface's type."; - reference - "RFC 791: Internet Protocol"; - - } - - list address { - key "ip"; - description - "The list of configured IPv4 addresses on the interface."; - leaf ip { - type inet:ipv4-address-no-zone; - description - "The IPv4 address on the interface."; - } - - choice subnet { - mandatory true; - description - "The subnet can be specified as a prefix-length, or, - if the server supports non-contiguous netmasks, as - a netmask."; - leaf prefix-length { - type uint8 { - range "0..32"; - } - description - "The length of the subnet prefix."; - } - leaf netmask { - if-feature ipv4-non-contiguous-netmasks; - type yang:dotted-quad; - description - "The subnet specified as a netmask."; - } - } // choice subnet - } // list address - - list neighbor { - key "ip"; - description - "A list of mappings from IPv4 addresses to - link-layer addresses. - - Entries in this list are used as static entries in the - ARP Cache."; - reference - "RFC 826: An Ethernet Address Resolution Protocol"; - - leaf ip { - type inet:ipv4-address-no-zone; - description - "The IPv4 address of the neighbor node."; - } - - leaf link-layer-address { - type yang:phys-address; - mandatory true; - description - "The link-layer address of the neighbor node."; - } - } // list neighbor - } // container ipv4 - - container ipv6 { - presence - "Enables IPv6 unless the 'enabled' leaf - (which defaults to 'true') is set to 'false'"; - description - "Parameters for the IPv6 address family."; - leaf enabled { - type boolean; - default 'true'; - description - "Controls whether IPv6 is enabled or disabled on this - interface. When IPv6 is enabled, this interface is - connected to an IPv6 stack, and the interface can send - and receive IPv6 packets."; - } - - leaf forwarding { - type boolean; - default 'false'; - description - "Controls IPv6 packet forwarding of datagrams received by, - but not addressed to, this interface. IPv6 routers - forward datagrams. IPv6 hosts do not (except those - source-routed via the host)."; - reference - "RFC 4861: Neighbor Discovery for IP version 6 (IPv6) - Section 6.2.1, IsRouter"; - - } - - leaf mtu { - type uint32 { - range "1280..max"; - } - units "octets"; - description - "The size, in octets, of the largest IPv6 packet that the - interface will send and receive. - - The server may restrict the allowed values for this leaf, - depending on the interface's type. - - If this leaf is not configured, the operationally used MTU - depends on the interface's type."; - reference - "RFC 2460: Internet Protocol, Version 6 (IPv6) Specification - Section 5"; - - } - - list address { - key "ip"; - description - "The list of configured IPv6 addresses on the interface."; - leaf ip { - type inet:ipv6-address-no-zone; - description - "The IPv6 address on the interface."; - } - - leaf prefix-length { - type uint8 { - range "0..128"; - } - mandatory true; - description - "The length of the subnet prefix."; - } - } // list address - - list neighbor { - key "ip"; - description - "A list of mappings from IPv6 addresses to - link-layer addresses. - - Entries in this list are used as static entries in the - Neighbor Cache."; - reference - "RFC 4861: Neighbor Discovery for IP version 6 (IPv6)"; - - leaf ip { - type inet:ipv6-address-no-zone; - description - "The IPv6 address of the neighbor node."; - } - - leaf link-layer-address { - type yang:phys-address; - mandatory true; - description - "The link-layer address of the neighbor node."; - } - } // list neighbor - - leaf dup-addr-detect-transmits { - type uint32; - default '1'; - description - "The number of consecutive Neighbor Solicitation messages - sent while performing Duplicate Address Detection on a - tentative address. A value of zero indicates that - Duplicate Address Detection is not performed on - tentative addresses. A value of one indicates a single - transmission with no follow-up retransmissions."; - reference - "RFC 4862: IPv6 Stateless Address Autoconfiguration"; - - } - - container autoconf { - description - "Parameters to control the autoconfiguration of IPv6 - addresses, as described in RFC 4862."; - reference - "RFC 4862: IPv6 Stateless Address Autoconfiguration"; - - leaf create-global-addresses { - type boolean; - default 'true'; - description - "If enabled, the host creates global addresses as - described in RFC 4862."; - reference - "RFC 4862: IPv6 Stateless Address Autoconfiguration - Section 5.5"; - - } - - leaf create-temporary-addresses { - if-feature ipv6-privacy-autoconf; - type boolean; - default 'false'; - description - "If enabled, the host creates temporary addresses as - described in RFC 4941."; - reference - "RFC 4941: Privacy Extensions for Stateless Address - Autoconfiguration in IPv6"; - - } - - leaf temporary-valid-lifetime { - if-feature ipv6-privacy-autoconf; - type uint32; - units "seconds"; - default '604800'; - description - "The time period during which the temporary address - is valid."; - reference - "RFC 4941: Privacy Extensions for Stateless Address - Autoconfiguration in IPv6 - - TEMP_VALID_LIFETIME"; - - } - - leaf temporary-preferred-lifetime { - if-feature ipv6-privacy-autoconf; - type uint32; - units "seconds"; - default '86400'; - description - "The time period during which the temporary address is - preferred."; - reference - "RFC 4941: Privacy Extensions for Stateless Address - Autoconfiguration in IPv6 - - TEMP_PREFERRED_LIFETIME"; - - } - } // container autoconf - } // container ipv6 - } - - augment /if:interfaces-state/if:interface { - description - "Data nodes for the operational state of IP on interfaces."; - container ipv4 { - presence - "Present if IPv4 is enabled on this interface"; - config false; - description - "Interface-specific parameters for the IPv4 address family."; - leaf forwarding { - type boolean; - description - "Indicates whether IPv4 packet forwarding is enabled or - disabled on this interface."; - } - - leaf mtu { - type uint16 { - range "68..max"; - } - units "octets"; - description - "The size, in octets, of the largest IPv4 packet that the - interface will send and receive."; - reference - "RFC 791: Internet Protocol"; - - } - - list address { - key "ip"; - description - "The list of IPv4 addresses on the interface."; - leaf ip { - type inet:ipv4-address-no-zone; - description - "The IPv4 address on the interface."; - } - - choice subnet { - description - "The subnet can be specified as a prefix-length, or, - if the server supports non-contiguous netmasks, as - a netmask."; - leaf prefix-length { - type uint8 { - range "0..32"; - } - description - "The length of the subnet prefix."; - } - leaf netmask { - if-feature ipv4-non-contiguous-netmasks; - type yang:dotted-quad; - description - "The subnet specified as a netmask."; - } - } // choice subnet - - leaf origin { - type ip-address-origin; - description - "The origin of this address."; - } - } // list address - - list neighbor { - key "ip"; - description - "A list of mappings from IPv4 addresses to - link-layer addresses. - - This list represents the ARP Cache."; - reference - "RFC 826: An Ethernet Address Resolution Protocol"; - - leaf ip { - type inet:ipv4-address-no-zone; - description - "The IPv4 address of the neighbor node."; - } - - leaf link-layer-address { - type yang:phys-address; - description - "The link-layer address of the neighbor node."; - } - - leaf origin { - type neighbor-origin; - description - "The origin of this neighbor entry."; - } - } // list neighbor - } // container ipv4 - - container ipv6 { - presence - "Present if IPv6 is enabled on this interface"; - config false; - description - "Parameters for the IPv6 address family."; - leaf forwarding { - type boolean; - default 'false'; - description - "Indicates whether IPv6 packet forwarding is enabled or - disabled on this interface."; - reference - "RFC 4861: Neighbor Discovery for IP version 6 (IPv6) - Section 6.2.1, IsRouter"; - - } - - leaf mtu { - type uint32 { - range "1280..max"; - } - units "octets"; - description - "The size, in octets, of the largest IPv6 packet that the - interface will send and receive."; - reference - "RFC 2460: Internet Protocol, Version 6 (IPv6) Specification - Section 5"; - - } - - list address { - key "ip"; - description - "The list of IPv6 addresses on the interface."; - leaf ip { - type inet:ipv6-address-no-zone; - description - "The IPv6 address on the interface."; - } - - leaf prefix-length { - type uint8 { - range "0..128"; - } - mandatory true; - description - "The length of the subnet prefix."; - } - - leaf origin { - type ip-address-origin; - description - "The origin of this address."; - } - - leaf status { - type enumeration { - enum "preferred" { - value 0; - description - "This is a valid address that can appear as the - destination or source address of a packet."; - } - enum "deprecated" { - value 1; - description - "This is a valid but deprecated address that should - no longer be used as a source address in new - communications, but packets addressed to such an - address are processed as expected."; - } - enum "invalid" { - value 2; - description - "This isn't a valid address, and it shouldn't appear - as the destination or source address of a packet."; - } - enum "inaccessible" { - value 3; - description - "The address is not accessible because the interface - to which this address is assigned is not - operational."; - } - enum "unknown" { - value 4; - description - "The status cannot be determined for some reason."; - } - enum "tentative" { - value 5; - description - "The uniqueness of the address on the link is being - verified. Addresses in this state should not be - used for general communication and should only be - used to determine the uniqueness of the address."; - } - enum "duplicate" { - value 6; - description - "The address has been determined to be non-unique on - the link and so must not be used."; - } - enum "optimistic" { - value 7; - description - "The address is available for use, subject to - restrictions, while its uniqueness on a link is - being verified."; - } - } - description - "The status of an address. Most of the states correspond - to states from the IPv6 Stateless Address - Autoconfiguration protocol."; - reference - "RFC 4293: Management Information Base for the - Internet Protocol (IP) - - IpAddressStatusTC - RFC 4862: IPv6 Stateless Address Autoconfiguration"; - - } - } // list address - - list neighbor { - key "ip"; - description - "A list of mappings from IPv6 addresses to - link-layer addresses. - - This list represents the Neighbor Cache."; - reference - "RFC 4861: Neighbor Discovery for IP version 6 (IPv6)"; - - leaf ip { - type inet:ipv6-address-no-zone; - description - "The IPv6 address of the neighbor node."; - } - - leaf link-layer-address { - type yang:phys-address; - description - "The link-layer address of the neighbor node."; - } - - leaf origin { - type neighbor-origin; - description - "The origin of this neighbor entry."; - } - - leaf is-router { - type empty; - description - "Indicates that the neighbor node acts as a router."; - } - - leaf state { - type enumeration { - enum "incomplete" { - value 0; - description - "Address resolution is in progress, and the link-layer - address of the neighbor has not yet been - determined."; - } - enum "reachable" { - value 1; - description - "Roughly speaking, the neighbor is known to have been - reachable recently (within tens of seconds ago)."; - } - enum "stale" { - value 2; - description - "The neighbor is no longer known to be reachable, but - until traffic is sent to the neighbor no attempt - should be made to verify its reachability."; - } - enum "delay" { - value 3; - description - "The neighbor is no longer known to be reachable, and - traffic has recently been sent to the neighbor. - Rather than probe the neighbor immediately, however, - delay sending probes for a short while in order to - give upper-layer protocols a chance to provide - reachability confirmation."; - } - enum "probe" { - value 4; - description - "The neighbor is no longer known to be reachable, and - unicast Neighbor Solicitation probes are being sent - to verify reachability."; - } - } - description - "The Neighbor Unreachability Detection state of this - entry."; - reference - "RFC 4861: Neighbor Discovery for IP version 6 (IPv6) - Section 7.3.2"; - - } - } // list neighbor - } // container ipv6 - } -} // module ietf-ip diff --git a/l3/api/src/main/yang/nd-proxy@2017-03-15.yang b/l3/api/src/main/yang/nd-proxy@2017-03-15.yang index 12723baf6..ba4567511 100644 --- a/l3/api/src/main/yang/nd-proxy@2017-03-15.yang +++ b/l3/api/src/main/yang/nd-proxy@2017-03-15.yang @@ -56,16 +56,4 @@ module nd-proxy { } } } - - augment /if:interfaces-state/if:interface/ip:ipv6 { - ext:augment-identifier "nd-proxy-ip6-state-augmentation"; - container nd-proxies { - list nd-proxy { - key "address"; - leaf address { - type inet:ipv6-address-no-zone; - } - } - } - } } diff --git a/l3/api/src/main/yang/proxy-arp@2018-07-03.yang b/l3/api/src/main/yang/proxy-arp@2018-07-03.yang index 479acd44b..d97e8d4f1 100644 --- a/l3/api/src/main/yang/proxy-arp@2018-07-03.yang +++ b/l3/api/src/main/yang/proxy-arp@2018-07-03.yang @@ -78,5 +78,5 @@ module proxy-arp { } } - // TODO(HC2VPP-86): add interfaces-state augmentation once VPP supports ARP proxy read (VPP-225) + // TODO(HC2VPP-86): add interfaces augmentation once VPP supports ARP proxy read (VPP-225) } diff --git a/l3/impl/l3_postman_collection.json b/l3/impl/l3_postman_collection.json index 953a2112e..408d840d8 100644 --- a/l3/impl/l3_postman_collection.json +++ b/l3/impl/l3_postman_collection.json @@ -114,7 +114,7 @@ "raw": "{\r\n \"nd-proxy\":{\r\n \t\"address\":\"2001::1\"\r\n }\r\n}" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/interface/GigabitEthernet0%2F8%2F0/ietf-ip:ipv6/nd-proxy:nd-proxies/", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/interface/GigabitEthernet0%2F8%2F0/ietf-ip:ipv6/nd-proxy:nd-proxies/", "protocol": "http", "host": [ "localhost" @@ -123,7 +123,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "GigabitEthernet0%2F8%2F0", "ietf-ip:ipv6", @@ -595,7 +595,7 @@ "raw": "{\r\n \r\n \"ipv6\":{\r\n \"address\":{\r\n \"ip\":\"2001:0db8:0a0b:12f0:0000:0000:0000:0001\"\r\n },\r\n \"neighbor\":{\r\n \"ip\":\"2001:0db8:0a0b:12f0:0000:0000:0000:0001\",\r\n \"link-layer-address\":\"00:11:22:11:22:00\"\r\n }\r\n }\r\n}" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/interface/GigabitEthernet0%2F8%2F0", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/interface/GigabitEthernet0%2F8%2F0", "protocol": "http", "host": [ "localhost" @@ -604,7 +604,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "GigabitEthernet0%2F8%2F0" ] diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/factory/Ipv4StateReaderFactory.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/factory/Ipv4StateReaderFactory.java index c0b94aede..c752f9801 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/factory/Ipv4StateReaderFactory.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/factory/Ipv4StateReaderFactory.java @@ -30,21 +30,21 @@ import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; import io.fd.jvpp.core.future.FutureJVppCore; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Neighbor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Neighbor; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class Ipv4StateReaderFactory implements ReaderFactory { - private static final InstanceIdentifier IFC_2_ID = - InstanceIdentifier.create(InterfacesState.class) + private static final InstanceIdentifier IFC_1_ID = + InstanceIdentifier.create(Interfaces.class) .child(Interface.class) - .augmentation(Interface2.class); + .augmentation(Interface1.class); @Inject private FutureJVppCore jvpp; @@ -57,10 +57,10 @@ public class Ipv4StateReaderFactory implements ReaderFactory { public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { //add also structural reader - registry.addStructuralReader(IFC_2_ID, Interface2Builder.class); + registry.addStructuralReader(IFC_1_ID, Interface1Builder.class); // Ipv4 - final InstanceIdentifier ipv4Id = IFC_2_ID.child(Ipv4.class); + final InstanceIdentifier ipv4Id = IFC_1_ID.child(Ipv4.class); registry.add(new GenericReader<>(ipv4Id, new Ipv4Customizer(jvpp))); // Ipv4 Address final InstanceIdentifier
ipv4AddrId = ipv4Id.child(Address.class); diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/factory/Ipv6StateReaderFactory.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/factory/Ipv6StateReaderFactory.java index 468dace4f..ffc9bffec 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/factory/Ipv6StateReaderFactory.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/factory/Ipv6StateReaderFactory.java @@ -30,24 +30,24 @@ import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; import io.fd.jvpp.core.future.FutureJVppCore; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.NdProxyIp6StateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.NdProxyIp6StateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces.state._interface.ipv6.NdProxies; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces.state._interface.ipv6.NdProxiesBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxy; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.Neighbor; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.NdProxyIp6Augmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.NdProxyIp6AugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces._interface.ipv6.NdProxies; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces._interface.ipv6.NdProxiesBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxy; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.Neighbor; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class Ipv6StateReaderFactory implements ReaderFactory { - private static final InstanceIdentifier IFC_2_ID = InstanceIdentifier.create(InterfacesState.class) + private static final InstanceIdentifier IFC_1_ID = InstanceIdentifier.create(Interfaces.class) .child(Interface.class) - .augmentation(Interface2.class); + .augmentation(Interface1.class); @Inject private FutureJVppCore jvpp; @@ -59,7 +59,7 @@ public class Ipv6StateReaderFactory implements ReaderFactory { @Override public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { // Ipv6 - final InstanceIdentifier ipv6Id = IFC_2_ID.child(Ipv6.class); + final InstanceIdentifier ipv6Id = IFC_1_ID.child(Ipv6.class); registry.add(new GenericReader<>(ipv6Id, new Ipv6Customizer(jvpp))); // Ipv6 Address final InstanceIdentifier
ipv6AddrId = ipv6Id.child(Address.class); @@ -68,8 +68,8 @@ public class Ipv6StateReaderFactory implements ReaderFactory { final InstanceIdentifier neighborId = ipv6Id.child(Neighbor.class); registry.add(new GenericListReader<>(neighborId, new Ipv6NeighbourCustomizer(jvpp, ifcNamingCtx))); // NdProxyIp6StateAugmentation (Structural) - final InstanceIdentifier ndAugId = ipv6Id.augmentation(NdProxyIp6StateAugmentation.class); - registry.addStructuralReader(ndAugId, NdProxyIp6StateAugmentationBuilder.class); + final InstanceIdentifier ndAugId = ipv6Id.augmentation(NdProxyIp6Augmentation.class); + registry.addStructuralReader(ndAugId, NdProxyIp6AugmentationBuilder.class); // NdProxies (Structural) final InstanceIdentifier ndProxiesId = ndAugId.child(NdProxies.class); registry.addStructuralReader(ndProxiesId, NdProxiesBuilder.class); diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/factory/SubInterfaceStateIpv4ReaderFactory.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/factory/SubInterfaceStateIpv4ReaderFactory.java index 5dbb7bf13..0711b0840 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/factory/SubInterfaceStateIpv4ReaderFactory.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/factory/SubInterfaceStateIpv4ReaderFactory.java @@ -27,22 +27,22 @@ import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; import io.fd.jvpp.core.future.FutureJVppCore; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.Ipv4; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.Ipv4Builder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.ipv4.Address; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.ipv4.Neighbor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class SubInterfaceStateIpv4ReaderFactory implements ReaderFactory { private static final InstanceIdentifier IFC_ID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class); + InstanceIdentifier.create(Interfaces.class).child(Interface.class); @Inject private FutureJVppCore jvpp; @@ -55,7 +55,7 @@ public class SubInterfaceStateIpv4ReaderFactory implements ReaderFactory { public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { final InstanceIdentifier subIfcId = - IFC_ID.augmentation(SubinterfaceStateAugmentation.class) + IFC_ID.augmentation(SubinterfaceAugmentation.class) .child(SubInterfaces.class).child(SubInterface.class); // Ipv4(Structural) diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/factory/SubInterfaceStateIpv6ReaderFactory.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/factory/SubInterfaceStateIpv6ReaderFactory.java index f8cd91383..d2fe688d4 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/factory/SubInterfaceStateIpv6ReaderFactory.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/factory/SubInterfaceStateIpv6ReaderFactory.java @@ -28,21 +28,21 @@ import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; import io.fd.jvpp.core.future.FutureJVppCore; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.Ipv6; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.Ipv6Builder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.ipv6.Address; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.ipv6.Neighbor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class SubInterfaceStateIpv6ReaderFactory implements ReaderFactory { private static final InstanceIdentifier IFC_ID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class); + InstanceIdentifier.create(Interfaces.class).child(Interface.class); @Inject private FutureJVppCore jvpp; @@ -55,7 +55,7 @@ public class SubInterfaceStateIpv6ReaderFactory implements ReaderFactory { public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { final InstanceIdentifier subIfcId = - IFC_ID.augmentation(SubinterfaceStateAugmentation.class) + IFC_ID.augmentation(SubinterfaceAugmentation.class) .child(SubInterfaces.class).child(SubInterface.class); // Ipv6(Structural) diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4AddressCustomizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4AddressCustomizer.java index d30b64103..cbb784756 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4AddressCustomizer.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4AddressCustomizer.java @@ -16,12 +16,11 @@ package io.fd.hc2vpp.l3.read.ipv4; -import java.util.Optional; import com.google.common.base.Preconditions; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.l3.utils.ip.read.IfaceDumpFilter; import io.fd.hc2vpp.l3.utils.ip.read.IpAddressReader; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceCustomizer; +import io.fd.hc2vpp.v3po.read.InterfaceCustomizer; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; @@ -32,16 +31,17 @@ import io.fd.jvpp.core.dto.IpAddressDetails; import io.fd.jvpp.core.dto.IpAddressDetailsReplyDump; import io.fd.jvpp.core.future.FutureJVppCore; import java.util.List; +import java.util.Optional; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.Subnet; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLengthBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.AddressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.AddressKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.Subnet; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -109,36 +109,37 @@ public class Ipv4AddressCustomizer extends IpAddressReader } @Override - public Initialized init( + public Initialized init( @Nonnull final InstanceIdentifier
id, @Nonnull final Address readValue, @Nonnull final ReadContext ctx) { return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder() + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.AddressBuilder() .setIp(readValue.getIp()) .setSubnet(getSubnet(readValue)) .build()); } private static Subnet getSubnet(final Address address) { - final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.Subnet + final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.Subnet subnet = address.getSubnet(); // Only prefix length supported Preconditions.checkArgument( - subnet instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLength); + subnet instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.PrefixLength); - return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder() + return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder() .setPrefixLength( - ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLength) subnet) + ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.PrefixLength) subnet) .getPrefixLength()).build(); } - static InstanceIdentifier getCfgId( + static InstanceIdentifier getCfgId( final InstanceIdentifier
id) { return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) .augmentation(Interface1.class) .child(Ipv4.class) - .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address.class, - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressKey(id.firstKeyOf(Address.class).getIp())); + .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Address.class, + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.AddressKey( + id.firstKeyOf(Address.class).getIp())); } } diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4Customizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4Customizer.java index 99a018054..0bb006856 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4Customizer.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4Customizer.java @@ -22,9 +22,9 @@ import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.jvpp.core.future.FutureJVppCore; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4Builder; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -41,7 +41,7 @@ public class Ipv4Customizer extends FutureJVppCustomizer implements ReaderCustom @Override public void merge(@Nonnull final Builder parentBuilder, @Nonnull final Ipv4 readValue) { - ((Interface2Builder) parentBuilder).setIpv4(readValue); + ((Interface1Builder) parentBuilder).setIpv4(readValue); } @Nonnull diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4NeighbourCustomizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4NeighbourCustomizer.java index 240cfd026..5ec2052e1 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4NeighbourCustomizer.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4NeighbourCustomizer.java @@ -16,10 +16,9 @@ package io.fd.hc2vpp.l3.read.ipv4; -import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.NeighborOrigin.Dynamic; -import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.NeighborOrigin.Static; +import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.NeighborOrigin.Dynamic; +import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.NeighborOrigin.Static; -import java.util.Optional; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.l3.utils.ip.read.IfaceDumpFilter; import io.fd.hc2vpp.l3.utils.ip.read.IpNeighbourReader; @@ -32,13 +31,14 @@ import io.fd.jvpp.core.dto.IpNeighborDetailsReplyDump; import io.fd.jvpp.core.future.FutureJVppCore; import io.fd.jvpp.core.types.IpNeighborFlags; import java.util.List; +import java.util.Optional; import java.util.function.Function; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Neighbor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.NeighborBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.NeighborKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Neighbor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.NeighborBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.NeighborKey; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/subinterface/SubInterfaceIpv4AddressCustomizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/subinterface/SubInterfaceIpv4AddressCustomizer.java index 9b0a99939..33e837f4c 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/subinterface/SubInterfaceIpv4AddressCustomizer.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv4/subinterface/SubInterfaceIpv4AddressCustomizer.java @@ -16,11 +16,10 @@ package io.fd.hc2vpp.l3.read.ipv4.subinterface; -import java.util.Optional; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.l3.utils.ip.read.IfaceDumpFilter; import io.fd.hc2vpp.l3.utils.ip.read.IpAddressReader; -import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceCustomizer; +import io.fd.hc2vpp.v3po.read.SubInterfaceCustomizer; import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; @@ -32,15 +31,16 @@ import io.fd.jvpp.core.dto.IpAddressDetails; import io.fd.jvpp.core.dto.IpAddressDetailsReplyDump; import io.fd.jvpp.core.future.FutureJVppCore; import java.util.List; +import java.util.Optional; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.Ipv4; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.Ipv4Builder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.ipv4.Address; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.ipv4.AddressBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.ipv4.AddressKey; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.ipv4.address.subnet.PrefixLengthBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6AddressCustomizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6AddressCustomizer.java index 86358cb47..88cb0fd27 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6AddressCustomizer.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6AddressCustomizer.java @@ -17,11 +17,10 @@ package io.fd.hc2vpp.l3.read.ipv6; -import java.util.Optional; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.l3.utils.ip.read.IfaceDumpFilter; import io.fd.hc2vpp.l3.utils.ip.read.IpAddressReader; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceCustomizer; +import io.fd.hc2vpp.v3po.read.InterfaceCustomizer; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; @@ -32,14 +31,15 @@ import io.fd.jvpp.core.dto.IpAddressDetails; import io.fd.jvpp.core.dto.IpAddressDetailsReplyDump; import io.fd.jvpp.core.future.FutureJVppCore; import java.util.List; +import java.util.Optional; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.AddressBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.AddressKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.AddressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.AddressKey; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -102,23 +102,23 @@ public class Ipv6AddressCustomizer extends IpAddressReader } @Override - public Initialized init( + public Initialized init( @Nonnull final InstanceIdentifier
id, @Nonnull final Address readValue, @Nonnull final ReadContext ctx) { return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.AddressBuilder() + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.AddressBuilder() .setIp(readValue.getIp()) .setPrefixLength(readValue.getPrefixLength()) .build()); } - static InstanceIdentifier getCfgId( + static InstanceIdentifier getCfgId( final InstanceIdentifier
id) { return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) .augmentation(Interface1.class) .child(Ipv6.class) - .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Address.class, - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.AddressKey( + .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.Address.class, + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.AddressKey( id.firstKeyOf(Address.class).getIp())); } } diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6Customizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6Customizer.java index 95daed566..2b9874922 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6Customizer.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6Customizer.java @@ -22,9 +22,9 @@ import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.jvpp.core.future.FutureJVppCore; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6Builder; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -41,7 +41,7 @@ public class Ipv6Customizer extends FutureJVppCustomizer implements ReaderCustom @Override public void merge(@Nonnull final Builder parentBuilder, @Nonnull final Ipv6 readValue) { - ((Interface2Builder) parentBuilder).setIpv6(readValue); + ((Interface1Builder) parentBuilder).setIpv6(readValue); } @Nonnull diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6NeighbourCustomizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6NeighbourCustomizer.java index 0bccd9cb8..3135ec2fc 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6NeighbourCustomizer.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6NeighbourCustomizer.java @@ -17,10 +17,9 @@ package io.fd.hc2vpp.l3.read.ipv6; -import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.NeighborOrigin.Dynamic; -import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.NeighborOrigin.Static; +import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.NeighborOrigin.Dynamic; +import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.NeighborOrigin.Static; -import java.util.Optional; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.l3.utils.ip.read.IfaceDumpFilter; import io.fd.hc2vpp.l3.utils.ip.read.IpNeighbourReader; @@ -33,13 +32,14 @@ import io.fd.jvpp.core.dto.IpNeighborDetailsReplyDump; import io.fd.jvpp.core.future.FutureJVppCore; import io.fd.jvpp.core.types.IpNeighborFlags; import java.util.List; +import java.util.Optional; import java.util.function.Function; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.Neighbor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.NeighborBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.NeighborKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.Neighbor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.NeighborBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.NeighborKey; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/nd/NdProxyCustomizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/nd/NdProxyCustomizer.java index 55305cd35..ee56346fb 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/nd/NdProxyCustomizer.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/nd/NdProxyCustomizer.java @@ -19,12 +19,11 @@ package io.fd.hc2vpp.l3.read.ipv6.nd; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.VisibleForTesting; -import java.util.Optional; import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.Ipv6Translator; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceCustomizer; +import io.fd.hc2vpp.v3po.read.InterfaceCustomizer; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; @@ -36,17 +35,18 @@ import io.fd.jvpp.core.dto.Ip6NdProxyDump; import io.fd.jvpp.core.future.FutureJVppCore; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.NdProxyIp6Augmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces.state._interface.ipv6.NdProxiesBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxy; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxyBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxyKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces._interface.ipv6.NdProxiesBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxy; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyKey; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/subinterface/SubInterfaceIpv6AddressCustomizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/subinterface/SubInterfaceIpv6AddressCustomizer.java index 72e62cc16..a4731ffbb 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/subinterface/SubInterfaceIpv6AddressCustomizer.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/read/ipv6/subinterface/SubInterfaceIpv6AddressCustomizer.java @@ -17,11 +17,10 @@ package io.fd.hc2vpp.l3.read.ipv6.subinterface; -import java.util.Optional; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.l3.utils.ip.read.IfaceDumpFilter; import io.fd.hc2vpp.l3.utils.ip.read.IpAddressReader; -import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceCustomizer; +import io.fd.hc2vpp.v3po.read.SubInterfaceCustomizer; import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; @@ -33,14 +32,15 @@ import io.fd.jvpp.core.dto.IpAddressDetails; import io.fd.jvpp.core.dto.IpAddressDetailsReplyDump; import io.fd.jvpp.core.future.FutureJVppCore; import java.util.List; +import java.util.Optional; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.Ipv6; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.Ipv6Builder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.ipv6.Address; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.ipv6.AddressBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.ipv6.AddressKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv4WriterFactory.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv4WriterFactory.java index 9268a83bc..747f0c518 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv4WriterFactory.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv4WriterFactory.java @@ -35,10 +35,10 @@ import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder; import io.fd.jvpp.core.future.FutureJVppCore; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Routing; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Neighbor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Neighbor; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class Ipv4WriterFactory implements WriterFactory { diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv6WriterFactory.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv6WriterFactory.java index 1d828005d..63f494135 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv6WriterFactory.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/factory/Ipv6WriterFactory.java @@ -42,10 +42,10 @@ import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.in import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Routing; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Neighbor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.Neighbor; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class Ipv6WriterFactory implements WriterFactory { diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressCustomizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressCustomizer.java index 1459f5cf1..87ab5d00b 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressCustomizer.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressCustomizer.java @@ -25,11 +25,11 @@ import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.jvpp.core.future.FutureJVppCore; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.Subnet; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.Netmask; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLength; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.AddressKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.Subnet; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.Netmask; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.PrefixLength; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressValidator.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressValidator.java index ae7305249..f60b17b1a 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressValidator.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressValidator.java @@ -23,10 +23,10 @@ import io.fd.honeycomb.translate.write.DataValidationFailedException; import io.fd.honeycomb.translate.write.Validator; import io.fd.honeycomb.translate.write.WriteContext; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.Subnet; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.Netmask; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLength; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.Subnet; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.Netmask; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.PrefixLength; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class Ipv4AddressValidator implements Validator
{ diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4Customizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4Customizer.java index f6cdf08dd..228689006 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4Customizer.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4Customizer.java @@ -21,7 +21,7 @@ import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.jvpp.core.future.FutureJVppCore; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourCustomizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourCustomizer.java index e0ac1fac4..5178423ac 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourCustomizer.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourCustomizer.java @@ -29,9 +29,9 @@ import io.fd.jvpp.core.dto.IpNeighborAddDel; import io.fd.jvpp.core.future.FutureJVppCore; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Neighbor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.NeighborKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Neighbor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.NeighborKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourValidator.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourValidator.java index 95fdfbb16..44ffdd884 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourValidator.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourValidator.java @@ -25,7 +25,7 @@ import io.fd.honeycomb.translate.write.Validator; import io.fd.honeycomb.translate.write.WriteContext; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Neighbor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Neighbor; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class Ipv4NeighbourValidator implements Validator { diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6AddressCustomizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6AddressCustomizer.java index f3e1268f2..7cf00811a 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6AddressCustomizer.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6AddressCustomizer.java @@ -25,8 +25,8 @@ import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.jvpp.core.future.FutureJVppCore; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.AddressKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.AddressKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6AddressValidator.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6AddressValidator.java index 28f455045..dd72273fc 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6AddressValidator.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6AddressValidator.java @@ -23,7 +23,7 @@ import io.fd.honeycomb.translate.write.DataValidationFailedException; import io.fd.honeycomb.translate.write.Validator; import io.fd.honeycomb.translate.write.WriteContext; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.Address; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class Ipv6AddressValidator implements Validator
{ diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6Customizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6Customizer.java index 313cbe56f..03b9b0d5c 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6Customizer.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6Customizer.java @@ -21,7 +21,7 @@ import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.jvpp.core.future.FutureJVppCore; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourCustomizer.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourCustomizer.java index b4f647460..389060340 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourCustomizer.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourCustomizer.java @@ -33,8 +33,8 @@ import io.fd.jvpp.core.future.FutureJVppCore; import io.fd.jvpp.core.types.IpNeighborFlags; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Neighbor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.NeighborKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.Neighbor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.NeighborKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourValidator.java b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourValidator.java index 4e0d54ca4..e794d09b3 100644 --- a/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourValidator.java +++ b/l3/impl/src/main/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourValidator.java @@ -25,7 +25,7 @@ import io.fd.honeycomb.translate.write.Validator; import io.fd.honeycomb.translate.write.WriteContext; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Neighbor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.Neighbor; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class Ipv6NeighbourValidator implements Validator { diff --git a/l3/impl/src/test/java/L3ModulesTest.java b/l3/impl/src/test/java/L3ModulesTest.java index bfacbd22d..f1e30f115 100644 --- a/l3/impl/src/test/java/L3ModulesTest.java +++ b/l3/impl/src/test/java/L3ModulesTest.java @@ -45,9 +45,9 @@ import java.util.Set; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesStateBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class L3ModulesTest { @@ -75,9 +75,9 @@ public class L3ModulesTest { // add structural readers here (better than maven dependency). Guice.createInjector(binder -> Multibinder.newSetBinder(binder, ReaderFactory.class) .addBinding().toInstance(registry -> { - registry.addStructuralReader(InstanceIdentifier.create(InterfacesState.class), - InterfacesStateBuilder.class); - registry.add(new GenericListReader<>(InstanceIdentifier.create(InterfacesState.class) + registry.addStructuralReader(InstanceIdentifier.create(Interfaces.class), + InterfacesBuilder.class); + registry.add(new GenericListReader<>(InstanceIdentifier.create(Interfaces.class) .child(Interface.class), mock(ListReaderCustomizer.class))); }), new InterfaceL3Module(), diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4AddressCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4AddressCustomizerTest.java index 64f1509c8..5ef62c866 100644 --- a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4AddressCustomizerTest.java +++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4AddressCustomizerTest.java @@ -48,16 +48,16 @@ import org.junit.Test; import org.mockito.Mockito; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLength; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.AddressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.AddressKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.PrefixLength; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest implements @@ -76,9 +76,9 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest getId(final String address, final String ifaceName) { - return InstanceIdentifier.builder(InterfacesState.class) + return InstanceIdentifier.builder(Interfaces.class) .child(Interface.class, new InterfaceKey(ifaceName)) - .augmentation(Interface2.class) + .augmentation(Interface1.class) .child(Ipv4.class) .child(Address.class, new AddressKey(new Ipv4AddressNoZone(new Ipv4Address(address)))) .build(); @@ -91,15 +91,15 @@ public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest { public Ipv4CustomizerTest() { - super(Ipv4.class, Interface2Builder.class); + super(Ipv4.class, Interface1Builder.class); } @Test diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4NeighbourCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4NeighbourCustomizerTest.java index 4876444eb..5692f3026 100644 --- a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4NeighbourCustomizerTest.java +++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/Ipv4NeighbourCustomizerTest.java @@ -24,15 +24,15 @@ import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import java.util.Arrays; import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Neighbor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.NeighborBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.NeighborKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Neighbor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.NeighborBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.NeighborKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class Ipv4NeighbourCustomizerTest extends ListReaderCustomizerTest @@ -46,9 +46,9 @@ public class Ipv4NeighbourCustomizerTest extends ListReaderCustomizerTest @@ -74,8 +74,8 @@ public class SubInterfaceIpv4AddressCustomizerTest extends ListReaderCustomizerT private static final int SUB_IF_INDEX = 11; private static final int SUB_IF_2_INDEX = 12; private static final InstanceIdentifier IP4_IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(SubinterfaceAugmentation.class) .child(SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)) .child(Ipv4.class); private static final Ipv4AddressNoZone IP1 = new Ipv4AddressNoZone("10.1.1.1"); @@ -102,16 +102,16 @@ public class SubInterfaceIpv4AddressCustomizerTest extends ListReaderCustomizerT protected void setUp() throws Exception { interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - ifaceOneAddressOneIdentifier = InstanceIdentifier.create(InterfacesState.class) + ifaceOneAddressOneIdentifier = InstanceIdentifier.create(Interfaces.class) .child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) + .augmentation(SubinterfaceAugmentation.class) .child(SubInterfaces.class) .child(SubInterface.class, new SubInterfaceKey(1L)) .child(Ipv4.class) .child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1"))); - ifaceTwoAddressOneIdentifier = InstanceIdentifier.create(InterfacesState.class) + ifaceTwoAddressOneIdentifier = InstanceIdentifier.create(Interfaces.class) .child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) + .augmentation(SubinterfaceAugmentation.class) .child(SubInterfaces.class) .child(SubInterface.class, new SubInterfaceKey(2L)) .child(Ipv4.class) diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/SubInterfaceIpv4NeighbourCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/SubInterfaceIpv4NeighbourCustomizerTest.java index 991069f91..b3f5f0585 100644 --- a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/SubInterfaceIpv4NeighbourCustomizerTest.java +++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv4/SubInterfaceIpv4NeighbourCustomizerTest.java @@ -25,18 +25,18 @@ import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import java.util.Arrays; import org.junit.Test; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.Ipv4; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.Ipv4Builder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.ipv4.Neighbor; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.ipv4.NeighborBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.ipv4.NeighborKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class SubInterfaceIpv4NeighbourCustomizerTest extends ListReaderCustomizerTest @@ -50,9 +50,9 @@ public class SubInterfaceIpv4NeighbourCustomizerTest extends ListReaderCustomize @Override protected void setUp() throws Exception { - instanceIdentifier = InstanceIdentifier.create(InterfacesState.class) + instanceIdentifier = InstanceIdentifier.create(Interfaces.class) .child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) + .augmentation(SubinterfaceAugmentation.class) .child(SubInterfaces.class) .child(SubInterface.class, new SubInterfaceKey((long) SUB_IFACE_ID)) .child(Ipv4.class) diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6AddressCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6AddressCustomizerTest.java index 300a52659..28748c22f 100644 --- a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6AddressCustomizerTest.java +++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/Ipv6AddressCustomizerTest.java @@ -24,15 +24,15 @@ import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import java.util.Arrays; import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.AddressBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.AddressKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.AddressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.AddressKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class Ipv6AddressCustomizerTest extends ListReaderCustomizerTest @@ -46,9 +46,9 @@ public class Ipv6AddressCustomizerTest extends ListReaderCustomizerTest @@ -48,9 +48,9 @@ public class SubInterfaceIpv6AddressCustomizerTest extends ListReaderCustomizerT @Override protected void setUp() throws Exception { - instanceIdentifier = InstanceIdentifier.create(InterfacesState.class) + instanceIdentifier = InstanceIdentifier.create(Interfaces.class) .child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) + .augmentation(SubinterfaceAugmentation.class) .child(SubInterfaces.class) .child(SubInterface.class, new SubInterfaceKey((long) SUB_IFACE_ID)) .child(Ipv6.class) diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/SubInterfaceIpv6NeighbourCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/SubInterfaceIpv6NeighbourCustomizerTest.java index 72f56a58f..e548d5898 100644 --- a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/SubInterfaceIpv6NeighbourCustomizerTest.java +++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/SubInterfaceIpv6NeighbourCustomizerTest.java @@ -25,18 +25,18 @@ import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import java.util.Arrays; import org.junit.Test; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.Ipv6; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.Ipv6Builder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.ipv6.Neighbor; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.ipv6.NeighborBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.ipv6.NeighborKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class SubInterfaceIpv6NeighbourCustomizerTest extends ListReaderCustomizerTest @@ -50,9 +50,9 @@ public class SubInterfaceIpv6NeighbourCustomizerTest extends ListReaderCustomize @Override protected void setUp() throws Exception { - instanceIdentifier = InstanceIdentifier.create(InterfacesState.class) + instanceIdentifier = InstanceIdentifier.create(Interfaces.class) .child(Interface.class, new InterfaceKey(IFACE_2_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) + .augmentation(SubinterfaceAugmentation.class) .child(SubInterfaces.class) .child(SubInterface.class, new SubInterfaceKey((long) SUB_IFACE_2_ID)) .child(Ipv6.class) diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/nd/NdProxyCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/nd/NdProxyCustomizerTest.java index 70dd68e43..aa59144de 100644 --- a/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/nd/NdProxyCustomizerTest.java +++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/read/ipv6/nd/NdProxyCustomizerTest.java @@ -32,18 +32,18 @@ import io.fd.jvpp.core.dto.Ip6NdProxyDetailsReplyDump; import io.fd.jvpp.core.types.Ip6Address; import java.util.List; import org.junit.Test; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.NdProxyIp6StateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces.state._interface.ipv6.NdProxies; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces.state._interface.ipv6.NdProxiesBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxy; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxyBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxyKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.NdProxyIp6Augmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces._interface.ipv6.NdProxies; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces._interface.ipv6.NdProxiesBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxy; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyKey; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class NdProxyCustomizerTest extends InitializingListReaderCustomizerTest { @@ -126,8 +126,8 @@ public class NdProxyCustomizerTest extends InitializingListReaderCustomizerTest< } private InstanceIdentifier getProxiesId(final String ifName) { - return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(ifName)) - .augmentation(Interface2.class).child(Ipv6.class).augmentation(NdProxyIp6StateAugmentation.class) + return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(ifName)) + .augmentation(Interface1.class).child(Ipv6.class).augmentation(NdProxyIp6Augmentation.class) .child(NdProxies.class); } } diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressCustomizerTest.java index 52091e5fc..254083bab 100644 --- a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressCustomizerTest.java +++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressCustomizerTest.java @@ -38,14 +38,14 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.Netmask; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.NetmaskBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLength; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.AddressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.Netmask; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.NetmaskBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.PrefixLength; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressValidatorTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressValidatorTest.java index 5b7d56e5e..a968ce9d4 100644 --- a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressValidatorTest.java +++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4AddressValidatorTest.java @@ -26,13 +26,13 @@ import org.junit.Test; import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.Subnet; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.Netmask; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.NetmaskBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLength; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.AddressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.Subnet; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.Netmask; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.NetmaskBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.PrefixLength; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad; public class Ipv4AddressValidatorTest { diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourCustomizerTest.java index b87a714d6..8b2d3451e 100644 --- a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourCustomizerTest.java +++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourCustomizerTest.java @@ -43,10 +43,10 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Neighbor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.NeighborBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Neighbor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.NeighborBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourValidatorTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourValidatorTest.java index 8cf5cd901..7692368eb 100644 --- a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourValidatorTest.java +++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv4/Ipv4NeighbourValidatorTest.java @@ -29,10 +29,10 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Neighbor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.NeighborBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.Neighbor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.NeighborBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourCustomizerTest.java index 68c5f8fc1..0d53d706c 100644 --- a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourCustomizerTest.java +++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourCustomizerTest.java @@ -42,10 +42,10 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Neighbor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.NeighborBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.Neighbor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.NeighborBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourValidatorTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourValidatorTest.java index 6cbe15e5a..820cd7db1 100644 --- a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourValidatorTest.java +++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/Ipv6NeighbourValidatorTest.java @@ -29,10 +29,10 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Neighbor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.NeighborBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.Neighbor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.NeighborBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/nd/NdProxyCustomizerTest.java b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/nd/NdProxyCustomizerTest.java index 73b29360c..44ca196bb 100644 --- a/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/nd/NdProxyCustomizerTest.java +++ b/l3/impl/src/test/java/io/fd/hc2vpp/l3/write/ipv6/nd/NdProxyCustomizerTest.java @@ -37,8 +37,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class NdProxyCustomizerTest extends WriterCustomizerTest { diff --git a/l3/utils/src/main/java/io/fd/hc2vpp/l3/utils/ip/read/IpAddressReader.java b/l3/utils/src/main/java/io/fd/hc2vpp/l3/utils/ip/read/IpAddressReader.java index bcab09ca7..56fba222d 100644 --- a/l3/utils/src/main/java/io/fd/hc2vpp/l3/utils/ip/read/IpAddressReader.java +++ b/l3/utils/src/main/java/io/fd/hc2vpp/l3/utils/ip/read/IpAddressReader.java @@ -18,7 +18,6 @@ package io.fd.hc2vpp.l3.utils.ip.read; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Optional; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.NamingContext; @@ -34,13 +33,14 @@ import io.fd.jvpp.core.dto.IpAddressDump; import io.fd.jvpp.core.future.FutureJVppCore; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yangtools.yang.binding.Identifier; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/l3/utils/src/main/java/io/fd/hc2vpp/l3/utils/ip/read/IpNeighbourReader.java b/l3/utils/src/main/java/io/fd/hc2vpp/l3/utils/ip/read/IpNeighbourReader.java index d75efd394..1c5d8552e 100644 --- a/l3/utils/src/main/java/io/fd/hc2vpp/l3/utils/ip/read/IpNeighbourReader.java +++ b/l3/utils/src/main/java/io/fd/hc2vpp/l3/utils/ip/read/IpNeighbourReader.java @@ -18,7 +18,6 @@ package io.fd.hc2vpp.l3.utils.ip.read; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Optional; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.NamingContext; @@ -33,11 +32,12 @@ import io.fd.jvpp.core.dto.IpNeighborDump; import io.fd.jvpp.core.future.FutureJVppCore; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yangtools.yang.binding.Identifier; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/l3/utils/src/main/java/io/fd/hc2vpp/l3/utils/ip/read/IpReader.java b/l3/utils/src/main/java/io/fd/hc2vpp/l3/utils/ip/read/IpReader.java index 8de12bfc4..036c7a5a3 100644 --- a/l3/utils/src/main/java/io/fd/hc2vpp/l3/utils/ip/read/IpReader.java +++ b/l3/utils/src/main/java/io/fd/hc2vpp/l3/utils/ip/read/IpReader.java @@ -23,8 +23,8 @@ import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.honeycomb.translate.util.read.cache.CacheKeyFactory; import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; /** * Utility class providing Ipv4/6 read support. diff --git a/mpls/mpls_postman_collection.json b/mpls/mpls_postman_collection.json index 42fb2965e..a241a28b7 100644 --- a/mpls/mpls_postman_collection.json +++ b/mpls/mpls_postman_collection.json @@ -96,7 +96,7 @@ "raw": "{\r\n \r\n \"interface\": [\r\n {\r\n \"name\": \"testInterface\",\r\n \"description\": \"for testing purposes\",\r\n \"type\": \"iana-if-type:ethernetCsmacd\",\r\n \"enabled\": \"true\",\r\n \"link-up-down-trap-enable\": \"enabled\",\r\n \"ietf-ip:ipv4\": {\r\n \"enabled\": \"true\",\r\n \"mtu\": \"1500\",\r\n \"address\": [\r\n {\r\n \"ip\": \"1.2.3.0\",\r\n \"netmask\": \"255.255.255.0\"\r\n }\r\n ]\r\n }\r\n }\r\n ]\r\n \r\n}" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/", "protocol": "http", "host": [ "localhost" @@ -105,7 +105,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "" ] } diff --git a/nat/nat-api/src/main/yang/interface-nat@2017-08-16.yang b/nat/nat-api/src/main/yang/interface-nat@2017-08-16.yang index 0382b7352..848b2f6ae 100644 --- a/nat/nat-api/src/main/yang/interface-nat@2017-08-16.yang +++ b/nat/nat-api/src/main/yang/interface-nat@2017-08-16.yang @@ -94,10 +94,4 @@ module interface-nat { uses interface-nat-attributes; } - - augment /if:interfaces-state/if:interface { - ext:augment-identifier "nat-interface-state-augmentation"; - - uses interface-nat-attributes; - } } diff --git a/nat/nat-api/src/main/yang/subinterface-nat@2017-06-15.yang b/nat/nat-api/src/main/yang/subinterface-nat@2017-06-15.yang index b13b8701d..0d910178a 100644 --- a/nat/nat-api/src/main/yang/subinterface-nat@2017-06-15.yang +++ b/nat/nat-api/src/main/yang/subinterface-nat@2017-06-15.yang @@ -50,10 +50,4 @@ module subinterface-nat { uses ifc-nat:interface-nat-attributes; } - - augment /if:interfaces-state/if:interface/vpp-vlan:sub-interfaces/vpp-vlan:sub-interface { - ext:augment-identifier "nat-subinterface-state-augmentation"; - - uses ifc-nat:interface-nat-attributes; - } } diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractInterfaceNatCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractInterfaceNatCustomizer.java index c3bb22d50..30f2a0123 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractInterfaceNatCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractInterfaceNatCustomizer.java @@ -34,7 +34,7 @@ import io.fd.jvpp.nat.future.FutureJVppNatFacade; import io.fd.jvpp.nat.types.NatConfigFlags; import java.util.Optional; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractSubInterfaceNatCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractSubInterfaceNatCustomizer.java index 857e8bc7a..02f95bf7e 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractSubInterfaceNatCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractSubInterfaceNatCustomizer.java @@ -21,8 +21,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.jvpp.nat.future.FutureJVppNatFacade; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/IfcNatReaderFactory.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/IfcNatReaderFactory.java index 24c0f46a7..91920e1c5 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/IfcNatReaderFactory.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/IfcNatReaderFactory.java @@ -24,14 +24,14 @@ import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; import io.fd.jvpp.nat.future.FutureJVppNatFacade; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816.NatInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816.NatInterfaceStateAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816.NatInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816.NatInterfaceAugmentationBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816._interface.nat.attributes.Nat; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816._interface.nat.attributes.NatBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816._interface.nat.attributes.nat.Inbound; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816._interface.nat.attributes.nat.Outbound; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** @@ -40,9 +40,9 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public final class IfcNatReaderFactory implements ReaderFactory { private static final InstanceIdentifier - IFC_ID = InstanceIdentifier.create(InterfacesState.class).child(Interface.class); - private static final InstanceIdentifier NAT_AUG_ID = - IFC_ID.augmentation(NatInterfaceStateAugmentation.class); + IFC_ID = InstanceIdentifier.create(Interfaces.class).child(Interface.class); + private static final InstanceIdentifier NAT_AUG_ID = + IFC_ID.augmentation(NatInterfaceAugmentation.class); private static final InstanceIdentifier NAT_AUG_CONTAINER_ID = NAT_AUG_ID.child(Nat.class); private final NamingContext ifcContext; private final FutureJVppNatFacade jvppNat; @@ -56,7 +56,7 @@ public final class IfcNatReaderFactory implements ReaderFactory { @Override public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { - registry.addStructuralReader(NAT_AUG_ID, NatInterfaceStateAugmentationBuilder.class); + registry.addStructuralReader(NAT_AUG_ID, NatInterfaceAugmentationBuilder.class); registry.addStructuralReader(NAT_AUG_CONTAINER_ID, NatBuilder.class); registry.addAfter(new GenericInitReader<>(NAT_AUG_CONTAINER_ID.child(Inbound.class), diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizer.java index bc1e82a1f..c45049d0f 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizer.java @@ -76,7 +76,7 @@ final class InterfaceInboundNatCustomizer extends AbstractInterfaceNatCustomizer InstanceIdentifier.create(Interfaces.class) .child(Interface.class, new InterfaceKey(id.firstKeyOf( - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface.class) + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface.class) .getName())) .augmentation(NatInterfaceAugmentation.class) .child(Nat.class) diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InterfaceOutboundNatCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InterfaceOutboundNatCustomizer.java index 9cebb2748..2f30b1286 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InterfaceOutboundNatCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InterfaceOutboundNatCustomizer.java @@ -75,7 +75,7 @@ final class InterfaceOutboundNatCustomizer extends AbstractInterfaceNatCustomize InstanceIdentifier.create(Interfaces.class) .child(Interface.class, new InterfaceKey(id.firstKeyOf( - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface.class) + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface.class) .getName())) .augmentation(NatInterfaceAugmentation.class) .child(Nat.class) diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubIfcNatReaderFactory.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubIfcNatReaderFactory.java index 310b7f487..747411fc5 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubIfcNatReaderFactory.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubIfcNatReaderFactory.java @@ -29,13 +29,13 @@ import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816._interface.nat.attributes.NatBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816._interface.nat.attributes.nat.Inbound; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816._interface.nat.attributes.nat.Outbound; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.nat.rev170615.NatSubinterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.nat.rev170615.NatSubinterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.nat.rev170615.NatSubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.nat.rev170615.NatSubinterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** @@ -44,10 +44,10 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public final class SubIfcNatReaderFactory implements ReaderFactory { private static final InstanceIdentifier - SUB_IFC_ID = InstanceIdentifier.create(InterfacesState.class).child(Interface.class).augmentation( - SubinterfaceStateAugmentation.class).child(SubInterfaces.class).child(SubInterface.class); - private static final InstanceIdentifier NAT_SUB_AUG_ID = - SUB_IFC_ID.augmentation(NatSubinterfaceStateAugmentation.class); + SUB_IFC_ID = InstanceIdentifier.create(Interfaces.class).child(Interface.class).augmentation( + SubinterfaceAugmentation.class).child(SubInterfaces.class).child(SubInterface.class); + private static final InstanceIdentifier NAT_SUB_AUG_ID = + SUB_IFC_ID.augmentation(NatSubinterfaceAugmentation.class); private static final InstanceIdentifier NAT_AUG_CONTAINER_ID = NAT_SUB_AUG_ID.child(Nat.class); private final NamingContext ifcContext; @@ -62,7 +62,7 @@ public final class SubIfcNatReaderFactory implements ReaderFactory { @Override public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { - registry.addStructuralReader(NAT_SUB_AUG_ID, NatSubinterfaceStateAugmentationBuilder.class); + registry.addStructuralReader(NAT_SUB_AUG_ID, NatSubinterfaceAugmentationBuilder.class); registry.addStructuralReader(NAT_AUG_CONTAINER_ID, NatBuilder.class); registry.addAfter(new GenericInitReader<>(NAT_AUG_CONTAINER_ID.child(Inbound.class), diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubInterfaceInboundNatCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubInterfaceInboundNatCustomizer.java index f20dad9b6..89ae2b5a1 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubInterfaceInboundNatCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubInterfaceInboundNatCustomizer.java @@ -80,13 +80,13 @@ final class SubInterfaceInboundNatCustomizer extends AbstractSubInterfaceNatCust InstanceIdentifier.create(Interfaces.class) .child(Interface.class, new InterfaceKey(id.firstKeyOf( - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface.class) + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface.class) .getName())) .augmentation(SubinterfaceAugmentation.class) .child(SubInterfaces.class) .child(SubInterface.class, new SubInterfaceKey(id.firstKeyOf( - org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface.class) + org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface.class) .getIdentifier())) .augmentation(NatSubinterfaceAugmentation.class) .child(Nat.class) diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubInterfaceOutboundNatCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubInterfaceOutboundNatCustomizer.java index 5251a793a..c17dd43df 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubInterfaceOutboundNatCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubInterfaceOutboundNatCustomizer.java @@ -79,13 +79,13 @@ final class SubInterfaceOutboundNatCustomizer extends AbstractSubInterfaceNatCus InstanceIdentifier.create(Interfaces.class) .child(Interface.class, new InterfaceKey(id.firstKeyOf( - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface.class) + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface.class) .getName())) .augmentation(SubinterfaceAugmentation.class) .child(SubInterfaces.class) .child(SubInterface.class, new SubInterfaceKey(id.firstKeyOf( - org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface.class) + org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface.class) .getIdentifier())) .augmentation(NatSubinterfaceAugmentation.class) .child(Nat.class) diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/NatModuleTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/NatModuleTest.java index a25ee6316..bd7cc400d 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/NatModuleTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/NatModuleTest.java @@ -46,10 +46,10 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.opendaylight.mdsal.binding.api.DataBroker; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesStateBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class NatModuleTest { @@ -80,8 +80,9 @@ public class NatModuleTest { @Before public void setUp() throws Exception { ietfIfcReaderFactory = registry -> { - registry.addStructuralReader(InstanceIdentifier.create(InterfacesState.class), InterfacesStateBuilder.class); - registry.addStructuralReader(InstanceIdentifier.create(InterfacesState.class).child(Interface.class), InterfaceBuilder.class); + registry.addStructuralReader(InstanceIdentifier.create(Interfaces.class), InterfacesBuilder.class); + registry.addStructuralReader(InstanceIdentifier.create(Interfaces.class).child(Interface.class), + InterfaceBuilder.class); }; initMocks(this); ifcContext = new NamingContext("interface-", "interface-context"); @@ -89,10 +90,10 @@ public class NatModuleTest { // be present, add structural readers (or add V3poModule here, but adding the full Module is not the best solution) Guice.createInjector(binder -> Multibinder.newSetBinder(binder, ReaderFactory.class) .addBinding().toInstance(registry -> { - registry.addStructuralReader(InstanceIdentifier.create(InterfacesState.class), - InterfacesStateBuilder.class); + registry.addStructuralReader(InstanceIdentifier.create(Interfaces.class), + InterfacesBuilder.class); registry.add(new GenericListReader<>( - InstanceIdentifier.create(InterfacesState.class).child(Interface.class), + InstanceIdentifier.create(Interfaces.class).child(Interface.class), mock(ListReaderCustomizer.class))); }), new NatModule(MockJVppNatProvider.class), BoundFieldModule.of(this)).injectMembers(this); } diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizerTest.java index 46a5c8c5e..4e5a6b31f 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizerTest.java @@ -38,14 +38,14 @@ import io.fd.jvpp.nat.types.InterfaceIndex; import io.fd.jvpp.nat.types.NatConfigFlags; import org.junit.Test; import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816.NatInterfaceStateAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816.NatInterfaceAugmentation; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816._interface.nat.attributes.Nat; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816._interface.nat.attributes.NatBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816._interface.nat.attributes.nat.Inbound; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.nat.rev170816._interface.nat.attributes.nat.InboundBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; import org.opendaylight.yangtools.yang.binding.ChildOf; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -67,9 +67,9 @@ public class InterfaceInboundNatCustomizerTest } static > InstanceIdentifier getId(Class boundType) { - return InstanceIdentifier.create(InterfacesState.class) + return InstanceIdentifier.create(Interfaces.class) .child(Interface.class, new InterfaceKey(IFC_NAME)) - .augmentation(NatInterfaceStateAugmentation.class) + .augmentation(NatInterfaceAugmentation.class) .child(Nat.class) .child(boundType); } diff --git a/nat/nat_postman_collection.json b/nat/nat_postman_collection.json index eccdf2bf6..12585224a 100644 --- a/nat/nat_postman_collection.json +++ b/nat/nat_postman_collection.json @@ -1300,7 +1300,7 @@ "raw": "{\r\n \r\n \"interface\": [\r\n {\r\n \"name\": \"testInterface\",\r\n \"description\": \"for testing purposes\",\r\n \"type\": \"iana-if-type:ethernetCsmacd\",\r\n \"enabled\": \"true\",\r\n \"link-up-down-trap-enable\": \"enabled\",\r\n \"ietf-ip:ipv4\": {\r\n \"enabled\": \"true\",\r\n \"mtu\": \"1500\",\r\n \"address\": [\r\n {\r\n \"ip\": \"1.2.3.0\",\r\n \"netmask\": \"255.255.255.0\"\r\n }\r\n ]\r\n }\r\n }\r\n ]\r\n \r\n}" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/", "protocol": "http", "host": [ "localhost" @@ -1309,7 +1309,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "" ] } diff --git a/nsh/nsh_postman_collection.json b/nsh/nsh_postman_collection.json index 421aac6a4..c23905023 100644 --- a/nsh/nsh_postman_collection.json +++ b/nsh/nsh_postman_collection.json @@ -1592,7 +1592,7 @@ "raw": "" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/interface/vxlanGpeTun3", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/interface/vxlanGpeTun3", "protocol": "http", "host": [ "localhost" @@ -1601,7 +1601,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "vxlanGpeTun3" ] @@ -2773,7 +2773,7 @@ "raw": "" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/interface/vxlanGpeTun3", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/interface/vxlanGpeTun3", "protocol": "http", "host": [ "localhost" @@ -2782,7 +2782,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "vxlanGpeTun3" ] @@ -2922,7 +2922,7 @@ "raw": "" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/interface/vxlanTun1", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/interface/vxlanTun1", "protocol": "http", "host": [ "localhost" @@ -2931,7 +2931,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "vxlanTun1" ] diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/RoutingIIds.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/RoutingIIds.java index e52353b05..11df4d18f 100644 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/RoutingIIds.java +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/RoutingIIds.java @@ -18,7 +18,7 @@ package io.fd.hc2vpp.routing; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev180313.StaticRoutes1; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.Ipv4; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv4.Route; @@ -57,7 +57,7 @@ public class RoutingIIds { //Writer IIDs public static final InstanceIdentifier IFCS_IFC_IFC1_IPV6_IPV61_RTADV = InstanceIdentifier.create(Interfaces.class).child(Interface.class).augmentation(Interface1.class) - .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6.class) + .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6.class) .augmentation(Ipv61.class).child(Ipv6RouterAdvertisements.class); public static final InstanceIdentifier IFCS_IFC_IFC1_IPV6_IPV61_RTADV_PRLST_PRFX = IFCS_IFC_IFC1_IPV6_IPV61_RTADV.child(PrefixList.class).child(Prefix.class); diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/helpers/SchemaContextTestHelper.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/helpers/SchemaContextTestHelper.java index f08a52168..1f174826d 100644 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/helpers/SchemaContextTestHelper.java +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/helpers/SchemaContextTestHelper.java @@ -30,7 +30,7 @@ public interface SchemaContextTestHelper extends InjectablesProcessor { org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.$YangModuleInfoImpl .getInstance(), // Default ietf-ip - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.$YangModuleInfoImpl + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.$YangModuleInfoImpl .getInstance(), // Default ietf-routing org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.$YangModuleInfoImpl diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/PrefixCustomizerTest.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/PrefixCustomizerTest.java index 05f36c22b..d69580dc5 100644 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/PrefixCustomizerTest.java +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/PrefixCustomizerTest.java @@ -38,8 +38,8 @@ import org.junit.runner.RunWith; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev180313.Ipv61; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev180313.interfaces._interface.ipv6.Ipv6RouterAdvertisements; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev180313.interfaces._interface.ipv6.ipv6.router.advertisements.PrefixList; @@ -79,7 +79,7 @@ public class PrefixCustomizerTest extends WriterCustomizerTest implements Schema @Test public void testWriteSimple(@InjectTestData(resourcePath = "/ra/simplePrefix.json", id = RA_PATH) PrefixList prefixList) - throws WriteFailedException { + throws WriteFailedException, InterruptedException { final Prefix data = getPrefix(prefixList); customizer.writeCurrentAttributes(IID, data, writeContext); final SwInterfaceIp6NdRaPrefix request = new SwInterfaceIp6NdRaPrefix(); diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/RouterAdvertisementsCustomizerTest.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/RouterAdvertisementsCustomizerTest.java index 18779049f..ee8451c67 100644 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/RouterAdvertisementsCustomizerTest.java +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/RouterAdvertisementsCustomizerTest.java @@ -34,8 +34,8 @@ import org.junit.runner.RunWith; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev180313.Ipv61; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev180313.interfaces._interface.ipv6.Ipv6RouterAdvertisements; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/v3po/api/src/main/yang/subinterface-span@2017-06-07.yang b/v3po/api/src/main/yang/subinterface-span@2017-06-07.yang index e138d0f35..911181eca 100644 --- a/v3po/api/src/main/yang/subinterface-span@2017-06-07.yang +++ b/v3po/api/src/main/yang/subinterface-span@2017-06-07.yang @@ -62,11 +62,4 @@ module subinterface-span { uses v3po:span-attributes; } } - - augment /if:interfaces-state/if:interface/vpp-vlan:sub-interfaces/vpp-vlan:sub-interface { - ext:augment-identifier "vpp-subinterface-span-state-augmentation"; - container span-state { - uses v3po:span-state-attributes; - } - } } diff --git a/v3po/api/src/main/yang/v3po@2019-05-02.yang b/v3po/api/src/main/yang/v3po@2019-05-02.yang index 50112385b..dea978724 100644 --- a/v3po/api/src/main/yang/v3po@2019-05-02.yang +++ b/v3po/api/src/main/yang/v3po@2019-05-02.yang @@ -406,17 +406,15 @@ module v3po { type inet:ipv6-address; description "Host IPv6 gateway address."; } - } - grouping tap-v2-interface-state-attributes { - leaf device-name { - config false; - type string{ - pattern '[a-zA-Z0-9\-;.+@$#^&*!_()=\[\]]*'; - length 1..63; - } - description "Device name of the Tap v2 interface in VPP."; + leaf device-name { + config false; + type string{ + pattern '[a-zA-Z0-9\-;.+@$#^&*!_()=\[\]]*'; + length 1..63; } + description "Device name of the Tap v2 interface in VPP."; + } } grouping loopback-interface-base-attributes { @@ -440,24 +438,12 @@ module v3po { Mapped to hw_interface_set_mtu VPP API message which programs the NIC."; } - } - grouping routing-base-attributes { - leaf ipv4-vrf-id { - type fib-management:fib-table-list-ref; - } - leaf ipv6-vrf-id { - type fib-management:fib-table-list-ref; - } - description - "Defines VRF tables used for ipv4 and ipv6 traffic"; - } - - grouping ethernet-state-attributes { leaf manufacturer-description { type string; config false; } + leaf duplex { type enumeration { enum "half"; @@ -467,6 +453,17 @@ module v3po { } } + grouping routing-base-attributes { + leaf ipv4-vrf-id { + type fib-management:fib-table-list-ref; + } + leaf ipv6-vrf-id { + type fib-management:fib-table-list-ref; + } + description + "Defines VRF tables used for ipv4 and ipv6 traffic"; + } + grouping vhost-user-interface-base-attributes { leaf socket { type string { @@ -488,9 +485,7 @@ module v3po { description "Custom device instance. Autogenerated will be used if not configured"; } description "vhost-user settings"; - } - grouping vhost-user-interface-state-attributes { leaf features { type uint64; config false; @@ -630,26 +625,6 @@ module v3po { } } - grouping l2-state-attributes { - description - "Parameters for configuring Layer2 features on interfaces."; - - choice interconnection { - case xconnect-based { - leaf xconnect-outgoing-interface { - /* Don't allow selection of this interface */ - must "../../if:name != current()"; - type if:interface-state-ref; - description - "L2 xconnect mode"; - } - } - case bridge-based { - uses bridge-based-attributes; - } - } - } - grouping bridge-based-attributes { leaf bridge-domain { type bridge-domain-ref; @@ -698,24 +673,6 @@ module v3po { } } - grouping span-state-attributes { - description "Parameters of the SPAN feature"; - - container mirrored-interfaces { - list mirrored-interface { - key "iface-ref"; - leaf iface-ref { - type if:interface-state-ref; - } - - leaf state { - type span-state; - mandatory true; - } - } - } - } - augment /if:interfaces/if:interface { ext:augment-identifier "vpp-interface-augmentation"; @@ -802,68 +759,6 @@ module v3po { } } - augment /if:interfaces-state/if:interface { - ext:augment-identifier "vpp-interface-state-augmentation"; - - leaf description { - type string; - } - - container tap-v2 { - when "../if:type = 'v3po:tap-v2'"; - uses tap-v2-interface-base-attributes; - uses tap-v2-interface-state-attributes; - } - - container ethernet { - when "../if:type = 'ianaift:ethernetCsmacd'"; - uses ethernet-base-attributes; - uses ethernet-state-attributes; - } - - container routing { - uses routing-base-attributes; - } - - container vhost-user { - when "../if:type = 'v3po:vhost-user'"; - uses vhost-user-interface-base-attributes; - uses vhost-user-interface-state-attributes; - } - - container vxlan { - when "../if:type = 'v3po:vxlan-tunnel'"; - uses vxlan-base-attributes; - } - container vxlan-gpe { - when "../if:type = 'v3po:vxlan-gpe-tunnel'"; - - uses vxlan-gpe-base-attributes; - } - - container gre { - when "../if:type = 'gre-tunnel'"; - uses gre-base-attributes; - } - - container l2 { - must "bridged-virtual-interface = 'true' or " + - "(not (../if:ipv4[if:enabled = 'true']/if:address/if:ip) and " + - "not (../if:ipv6[if:enabled = 'true']/if:address/if:ip))"; - - uses l2-state-attributes; - } - - container af-packet { - when "../if:type = 'v3po:af-packet'"; - uses af-packet-base-attributes; - } - - container span { - uses span-state-attributes; - } - } - augment /if:interfaces { ext:augment-identifier "vpp-interfaces-stats-augmentation"; container statistics{ @@ -874,7 +769,7 @@ module v3po { } } - augment /if:interfaces-state/if:interface/if:statistics { + augment /if:interfaces/if:interface/if:statistics { ext:augment-identifier "vpp-interface-statistics-augmentation"; leaf in-errors-no-buf { type yang:counter64; @@ -925,7 +820,7 @@ module v3po { } } - notification interface-state-change { + notification interface-change { leaf name { type interface-name-or-index; } diff --git a/v3po/api/src/main/yang/vpp-pbb@2016-12-14.yang b/v3po/api/src/main/yang/vpp-pbb@2016-12-14.yang index 3947831f7..159d05de6 100644 --- a/v3po/api/src/main/yang/vpp-pbb@2016-12-14.yang +++ b/v3po/api/src/main/yang/vpp-pbb@2016-12-14.yang @@ -52,7 +52,7 @@ module vpp-pbb { } } - augment /if:interfaces-state/if:interface { + augment /if:interfaces/if:interface { ext:augment-identifier "pbb-rewrite-state-interface-augmentation"; container pbb-rewrite-state { uses pbb-types:pbb-rewrite-attributes; diff --git a/v3po/api/src/main/yang/vpp-vlan@2018-03-19.yang b/v3po/api/src/main/yang/vpp-vlan@2018-03-19.yang index c5f025429..05b088689 100644 --- a/v3po/api/src/main/yang/vpp-vlan@2018-03-19.yang +++ b/v3po/api/src/main/yang/vpp-vlan@2018-03-19.yang @@ -216,13 +216,6 @@ module vpp-vlan { } } - grouping sub-interface-l2-state-attributes { - container l2 { - uses v3po:l2-state-attributes; - uses rewrite-attributes; - } - } - grouping sub-interface-config-attributes { leaf enabled { type boolean; @@ -231,31 +224,38 @@ module vpp-vlan { "Contains the configured, desired state of the sub-interface. To enable sub-interface, the super inerface needs to be enabled"; } - } - grouping sub-interface-operational-attributes { leaf admin-status { type sub-interface-status; mandatory true; + config false; } + leaf oper-status { type sub-interface-status; mandatory true; + config false; } + leaf if-index { type int32 { range "1..2147483647"; } mandatory true; + config false; } + leaf phys-address { type yang:phys-address; description "The sub-interface's Media Access Control (MAC) address."; + config false; } + leaf speed { type yang:gauge64; units "bits/second"; + config false; } } @@ -464,26 +464,4 @@ module vpp-vlan { } } } - - augment /if:interfaces-state/if:interface { - ext:augment-identifier "subinterface-state-augmentation"; - - container sub-interfaces { - description "L2 vlan subinterfaces"; - - list sub-interface { - key "identifier"; - leaf identifier { - type uint32; - } - - uses sub-interface-base-attributes; - uses sub-interface-operational-attributes; - uses sub-interface-ip4-attributes; - uses sub-interface-ip6-attributes; - uses sub-interface-routing-attributes; - uses sub-interface-l2-state-attributes; - } - } - } } diff --git a/v3po/postman_rest_collection.json b/v3po/postman_rest_collection.json index c4eb4f9c9..9659b76ca 100644 --- a/v3po/postman_rest_collection.json +++ b/v3po/postman_rest_collection.json @@ -294,7 +294,7 @@ "raw": "" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/interface/local0/", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/interface/local0/", "protocol": "http", "host": [ "localhost" @@ -303,7 +303,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "local0", "" @@ -800,7 +800,7 @@ "raw": "" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/interface/GigabitEthernet0%2F8%2F0", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/interface/GigabitEthernet0%2F8%2F0", "protocol": "http", "host": [ "localhost" @@ -809,7 +809,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "GigabitEthernet0%2F8%2F0" ] @@ -1190,7 +1190,7 @@ "raw": "" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/interface/local0", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/interface/local0", "protocol": "http", "host": [ "localhost" @@ -1199,7 +1199,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "local0" ] @@ -1343,7 +1343,7 @@ "raw": "" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/interface/local0/ipv4", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/interface/local0/ipv4", "protocol": "http", "host": [ "localhost" @@ -1352,7 +1352,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "local0", "ipv4" @@ -1541,7 +1541,7 @@ "raw": "" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/interface/GigabitEthernet0%2F8%2F0/span", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/interface/GigabitEthernet0%2F8%2F0/span", "protocol": "http", "host": [ "localhost" @@ -1550,7 +1550,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "GigabitEthernet0%2F8%2F0", "span" @@ -1657,7 +1657,7 @@ "raw": "" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/interface/tap-v2/statistics/", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/interface/tap-v2/statistics/", "protocol": "http", "host": [ "localhost" @@ -1666,7 +1666,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "tap-v2", "statistics", @@ -2527,7 +2527,7 @@ "raw": "" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/interface/veth0", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/interface/veth0", "protocol": "http", "host": [ "localhost" @@ -2536,7 +2536,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "veth0" ] @@ -2601,7 +2601,7 @@ "raw": "" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/", "protocol": "http", "host": [ "localhost" @@ -2610,7 +2610,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "" ] } diff --git a/v3po/routing_postman_collection.json b/v3po/routing_postman_collection.json index 42c1020c0..b5edf02f4 100644 --- a/v3po/routing_postman_collection.json +++ b/v3po/routing_postman_collection.json @@ -392,7 +392,7 @@ "raw": "{\n\t\"routing\":{\n\t\t\"ipv4-vrf-id\":4\n\t}\n\t\n}" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/interface/GigabitEthernet0%2F8%2F0/vpp-vlan:sub-interfaces/sub-interface/1/routing", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/interface/GigabitEthernet0%2F8%2F0/vpp-vlan:sub-interfaces/sub-interface/1/routing", "protocol": "http", "host": [ "localhost" @@ -401,7 +401,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "GigabitEthernet0%2F8%2F0", "vpp-vlan:sub-interfaces", diff --git a/v3po/span_postman_collection.json b/v3po/span_postman_collection.json index dbb276f0b..ed80f7cf4 100644 --- a/v3po/span_postman_collection.json +++ b/v3po/span_postman_collection.json @@ -70,7 +70,7 @@ "raw": "" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/interface/GigabitEthernet0%2F8%2F0/span", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/interface/GigabitEthernet0%2F8%2F0/span", "protocol": "http", "host": [ "localhost" @@ -79,7 +79,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "GigabitEthernet0%2F8%2F0", "span" @@ -196,7 +196,7 @@ "raw": "{\r\n \r\n \"span\": {\r\n \t\"mirrored-interfaces\": {\r\n \t\t\"mirrored-interface\": [{\"iface-ref\":\"GigabitEthernet0/8/0\",\"state\":\"receive\"}]\r\n \t}\r\n }\r\n \r\n}" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/interface/GigabitEthernet0%2F8%2F0/vpp-vlan:sub-interfaces/sub-interface/1/span-state", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/interface/GigabitEthernet0%2F8%2F0/vpp-vlan:sub-interfaces/sub-interface/1/span", "protocol": "http", "host": [ "localhost" @@ -205,13 +205,13 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "GigabitEthernet0%2F8%2F0", "vpp-vlan:sub-interfaces", "sub-interface", "1", - "span-state" + "span" ] }, "description": "set span src local0 dst GigabiteEthernet0/8/0" diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/V3poModule.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/V3poModule.java index 1aafca168..28045872c 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/V3poModule.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/V3poModule.java @@ -24,17 +24,17 @@ import com.google.inject.multibindings.Multibinder; import com.google.inject.name.Names; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.stats.jvpp.JVppStatsProvider; -import io.fd.hc2vpp.v3po.factory.InterfacesStateReaderFactory; +import io.fd.hc2vpp.v3po.factory.InterfacesReaderFactory; import io.fd.hc2vpp.v3po.factory.InterfacesWriterFactory; import io.fd.hc2vpp.v3po.factory.L2HoneycombWriterFactory; import io.fd.hc2vpp.v3po.factory.L2StateHoneycombReaderFactory; import io.fd.hc2vpp.v3po.factory.SubinterfaceAugmentationWriterFactory; -import io.fd.hc2vpp.v3po.factory.SubinterfaceStateAugmentationReaderFactory; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManagerProvider; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceStatisticsManager; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceStatisticsManagerProvider; +import io.fd.hc2vpp.v3po.factory.SubinterfaceAugmentationReaderFactory; import io.fd.hc2vpp.v3po.notification.InterfaceChangeNotificationProducerProvider; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManagerProvider; +import io.fd.hc2vpp.v3po.read.cache.InterfaceStatisticsManager; +import io.fd.hc2vpp.v3po.read.cache.InterfaceStatisticsManagerProvider; import io.fd.honeycomb.notification.ManagedNotificationProducer; import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.write.WriterFactory; @@ -81,8 +81,8 @@ public class V3poModule extends AbstractModule { // Readers final Multibinder readerFactoryBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class); - readerFactoryBinder.addBinding().to(InterfacesStateReaderFactory.class); - readerFactoryBinder.addBinding().to(SubinterfaceStateAugmentationReaderFactory.class); + readerFactoryBinder.addBinding().to(InterfacesReaderFactory.class); + readerFactoryBinder.addBinding().to(SubinterfaceAugmentationReaderFactory.class); readerFactoryBinder.addBinding().to(L2StateHoneycombReaderFactory.class); // Expose disabled interfaces in operational data diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesReaderFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesReaderFactory.java new file mode 100644 index 000000000..8b792d5f0 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesReaderFactory.java @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.factory; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.DisabledInterfacesManager; +import io.fd.hc2vpp.v3po.read.AfPacketCustomizer; +import io.fd.hc2vpp.v3po.read.EthernetCustomizer; +import io.fd.hc2vpp.v3po.read.GreCustomizer; +import io.fd.hc2vpp.v3po.read.InterfaceCustomizer; +import io.fd.hc2vpp.v3po.read.InterfaceRoutingCustomizer; +import io.fd.hc2vpp.v3po.read.InterfaceStatisticsCustomizer; +import io.fd.hc2vpp.v3po.read.L2Customizer; +import io.fd.hc2vpp.v3po.read.TapV2Customizer; +import io.fd.hc2vpp.v3po.read.VhostUserCustomizer; +import io.fd.hc2vpp.v3po.read.VxlanCustomizer; +import io.fd.hc2vpp.v3po.read.VxlanGpeCustomizer; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.hc2vpp.v3po.read.cache.InterfaceStatisticsManager; +import io.fd.hc2vpp.v3po.read.pbb.PbbRewriteCustomizer; +import io.fd.hc2vpp.v3po.read.span.InterfaceMirroredInterfacesCustomizer; +import io.fd.honeycomb.translate.impl.read.GenericInitListReader; +import io.fd.honeycomb.translate.impl.read.GenericInitReader; +import io.fd.honeycomb.translate.impl.read.GenericReader; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; +import io.fd.jvpp.core.future.FutureJVppCore; +import io.fd.jvpp.stats.future.FutureJVppStatsFacade; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacket; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Ethernet; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Gre; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Routing; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Span; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.SpanBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUser; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Vxlan; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpe; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.PbbRewriteInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.PbbRewriteInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewrite; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces._interface.Statistics; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public final class InterfacesReaderFactory implements ReaderFactory { + + private final FutureJVppStatsFacade jvppStats; + private final NamingContext ifcNamingCtx; + private final NamingContext bdNamingCtx; + private final DisabledInterfacesManager ifcDisableContext; + private final InterfaceCacheDumpManager ifaceDumpManager; + private final FutureJVppCore jvpp; + private final InterfaceStatisticsManager statisticsManager; + + static final InstanceIdentifier IFC_STATE_ID = + InstanceIdentifier.create(Interfaces.class); + static final InstanceIdentifier IFC_ID = IFC_STATE_ID.child(Interface.class); + + @Inject + public InterfacesReaderFactory(final FutureJVppCore jvpp, + final FutureJVppStatsFacade jvppStats, + @Named("interface-context") final NamingContext ifcNamingCtx, + @Named("bridge-domain-context") final NamingContext bdNamingCtx, + final DisabledInterfacesManager ifcDisableContext, + final InterfaceCacheDumpManager ifaceDumpManager, + final InterfaceStatisticsManager statisticsManager) { + this.jvpp = jvpp; + this.jvppStats = jvppStats; + this.ifcNamingCtx = ifcNamingCtx; + this.bdNamingCtx = bdNamingCtx; + this.ifcDisableContext = ifcDisableContext; + this.ifaceDumpManager = ifaceDumpManager; + this.statisticsManager = statisticsManager; + } + + @Override + public void init(final ModifiableReaderRegistryBuilder registry) { + // Interfaces(Structural) + registry.addStructuralReader(IFC_STATE_ID, InterfacesBuilder.class); + // Interface + registry.add(new GenericInitListReader<>(IFC_ID, + new InterfaceCustomizer(ifcNamingCtx, ifcDisableContext, ifaceDumpManager))); + + // Interface Statistics + registry.add(new GenericReader<>(IFC_ID.child(Statistics.class), + new InterfaceStatisticsCustomizer(ifcNamingCtx, jvppStats, statisticsManager))); + // v3po.yang + initVppIfcAugmentationReaders(registry, IFC_ID); + + //vpp-pbb.yang + initPbbRewriteAugmentation(registry, IFC_ID); + } + + private void initVppIfcAugmentationReaders(final ModifiableReaderRegistryBuilder registry, + final InstanceIdentifier ifcId) { + // VppInterfaceAugmentation + final InstanceIdentifier vppIfcAugId = + ifcId.augmentation(VppInterfaceAugmentation.class); + registry.addStructuralReader(vppIfcAugId, VppInterfaceAugmentationBuilder.class); + // Ethernet + registry.add(new GenericInitReader<>(vppIfcAugId.child(Ethernet.class), + new EthernetCustomizer(ifaceDumpManager))); + // Routing + registry.add(new GenericInitReader<>(vppIfcAugId.child(Routing.class), + new InterfaceRoutingCustomizer(jvpp, ifcNamingCtx))); + // TapV2 + registry.add(new GenericInitReader<>(vppIfcAugId.child(TapV2.class), + new TapV2Customizer(jvpp, ifcNamingCtx, ifaceDumpManager))); + // VhostUser + registry.add(new GenericInitReader<>(vppIfcAugId.child(VhostUser.class), + new VhostUserCustomizer(jvpp, ifcNamingCtx, ifaceDumpManager))); + // AfPacket + registry.add(new GenericInitReader<>(vppIfcAugId.child(AfPacket.class), + new AfPacketCustomizer(jvpp, ifcNamingCtx, ifaceDumpManager))); + // Vxlan + registry.add(new GenericInitReader<>(vppIfcAugId.child(Vxlan.class), + new VxlanCustomizer(jvpp, ifcNamingCtx, ifaceDumpManager))); + // VxlanGpe + registry.add(new GenericInitReader<>(vppIfcAugId.child(VxlanGpe.class), + new VxlanGpeCustomizer(jvpp, ifcNamingCtx, ifaceDumpManager))); + // Gre + registry.add(new GenericInitReader<>(vppIfcAugId.child(Gre.class), + new GreCustomizer(jvpp, ifcNamingCtx, ifaceDumpManager))); + // L2 + registry.add(new GenericInitReader<>(vppIfcAugId.child(L2.class), + new L2Customizer(jvpp, ifcNamingCtx, bdNamingCtx, ifaceDumpManager))); + // Span + final InstanceIdentifier spanId = vppIfcAugId.child(Span.class); + registry.addStructuralReader(spanId, SpanBuilder.class); + // MirroredInterfaces + registry.subtreeAdd( + ImmutableSet.of(InstanceIdentifier.create(MirroredInterfaces.class).child(MirroredInterface.class)), + new GenericInitReader<>(spanId.child(MirroredInterfaces.class), + new InterfaceMirroredInterfacesCustomizer(jvpp, ifcNamingCtx))); + } + + private void initPbbRewriteAugmentation(final ModifiableReaderRegistryBuilder registry, + final InstanceIdentifier ifcId) { + registry.addStructuralReader(ifcId.augmentation(PbbRewriteInterfaceAugmentation.class), + PbbRewriteInterfaceAugmentationBuilder.class); + + registry.add(new GenericReader<>(ifcId.augmentation(PbbRewriteInterfaceAugmentation.class).child( + PbbRewrite.class), new PbbRewriteCustomizer(jvpp))); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesStateReaderFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesStateReaderFactory.java deleted file mode 100644 index 949b98fc2..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesStateReaderFactory.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.factory; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Inject; -import com.google.inject.name.Named; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.DisabledInterfacesManager; -import io.fd.hc2vpp.v3po.interfacesstate.AfPacketCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.EthernetCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.GreCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceRoutingCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceStatisticsCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.L2Customizer; -import io.fd.hc2vpp.v3po.interfacesstate.TapV2Customizer; -import io.fd.hc2vpp.v3po.interfacesstate.VhostUserCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.VxlanCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.VxlanGpeCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceStatisticsManager; -import io.fd.hc2vpp.v3po.interfacesstate.pbb.PbbRewriteStateCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.span.InterfaceMirroredInterfacesCustomizer; -import io.fd.honeycomb.translate.impl.read.GenericInitListReader; -import io.fd.honeycomb.translate.impl.read.GenericInitReader; -import io.fd.honeycomb.translate.impl.read.GenericReader; -import io.fd.honeycomb.translate.read.ReaderFactory; -import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; -import io.fd.jvpp.core.future.FutureJVppCore; -import io.fd.jvpp.stats.future.FutureJVppStatsFacade; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.AfPacket; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.Ethernet; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.Gre; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.L2; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.Routing; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.Span; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.SpanBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.TapV2; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.VhostUser; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.Vxlan; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.VxlanGpe; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.state.attributes.MirroredInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.state.attributes.mirrored.interfaces.MirroredInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.PbbRewriteStateInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.PbbRewriteStateInterfaceAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces.state._interface.PbbRewriteState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesStateBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state._interface.Statistics; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public final class InterfacesStateReaderFactory implements ReaderFactory { - - private final FutureJVppStatsFacade jvppStats; - private final NamingContext ifcNamingCtx; - private final NamingContext bdNamingCtx; - private final DisabledInterfacesManager ifcDisableContext; - private final InterfaceCacheDumpManager ifaceDumpManager; - private final FutureJVppCore jvpp; - private final InterfaceStatisticsManager statisticsManager; - - static final InstanceIdentifier IFC_STATE_ID = - InstanceIdentifier.create(InterfacesState.class); - static final InstanceIdentifier IFC_ID = IFC_STATE_ID.child(Interface.class); - - @Inject - public InterfacesStateReaderFactory(final FutureJVppCore jvpp, - final FutureJVppStatsFacade jvppStats, - @Named("interface-context") final NamingContext ifcNamingCtx, - @Named("bridge-domain-context") final NamingContext bdNamingCtx, - final DisabledInterfacesManager ifcDisableContext, - final InterfaceCacheDumpManager ifaceDumpManager, - final InterfaceStatisticsManager statisticsManager) { - this.jvpp = jvpp; - this.jvppStats = jvppStats; - this.ifcNamingCtx = ifcNamingCtx; - this.bdNamingCtx = bdNamingCtx; - this.ifcDisableContext = ifcDisableContext; - this.ifaceDumpManager = ifaceDumpManager; - this.statisticsManager = statisticsManager; - } - - @Override - public void init(final ModifiableReaderRegistryBuilder registry) { - // InterfacesState(Structural) - registry.addStructuralReader(IFC_STATE_ID, InterfacesStateBuilder.class); - // Interface - registry.add(new GenericInitListReader<>(IFC_ID, - new InterfaceCustomizer(ifcNamingCtx, ifcDisableContext, ifaceDumpManager))); - - // Interface Statistics - registry.add(new GenericReader<>(IFC_ID.child(Statistics.class), - new InterfaceStatisticsCustomizer(ifcNamingCtx, jvppStats, statisticsManager))); - // v3po.yang - initVppIfcAugmentationReaders(registry, IFC_ID); - - //vpp-pbb.yang - initPbbRewriteAugmentation(registry, IFC_ID); - } - - private void initVppIfcAugmentationReaders(final ModifiableReaderRegistryBuilder registry, - final InstanceIdentifier ifcId) { - // VppInterfaceStateAugmentation - final InstanceIdentifier vppIfcAugId = - ifcId.augmentation(VppInterfaceStateAugmentation.class); - registry.addStructuralReader(vppIfcAugId, VppInterfaceStateAugmentationBuilder.class); - // Ethernet - registry.add(new GenericInitReader<>(vppIfcAugId.child(Ethernet.class), - new EthernetCustomizer(ifaceDumpManager))); - // Routing - registry.add(new GenericInitReader<>(vppIfcAugId.child(Routing.class), - new InterfaceRoutingCustomizer(jvpp, ifcNamingCtx))); - // TapV2 - registry.add(new GenericInitReader<>(vppIfcAugId.child(TapV2.class), - new TapV2Customizer(jvpp, ifcNamingCtx, ifaceDumpManager))); - // VhostUser - registry.add(new GenericInitReader<>(vppIfcAugId.child(VhostUser.class), - new VhostUserCustomizer(jvpp, ifcNamingCtx, ifaceDumpManager))); - // AfPacket - registry.add(new GenericInitReader<>(vppIfcAugId.child(AfPacket.class), - new AfPacketCustomizer(jvpp, ifcNamingCtx, ifaceDumpManager))); - // Vxlan - registry.add(new GenericInitReader<>(vppIfcAugId.child(Vxlan.class), - new VxlanCustomizer(jvpp, ifcNamingCtx, ifaceDumpManager))); - // VxlanGpe - registry.add(new GenericInitReader<>(vppIfcAugId.child(VxlanGpe.class), - new VxlanGpeCustomizer(jvpp, ifcNamingCtx, ifaceDumpManager))); - // Gre - registry.add(new GenericInitReader<>(vppIfcAugId.child(Gre.class), - new GreCustomizer(jvpp, ifcNamingCtx, ifaceDumpManager))); - // L2 - registry.add(new GenericInitReader<>(vppIfcAugId.child(L2.class), - new L2Customizer(jvpp, ifcNamingCtx, bdNamingCtx, ifaceDumpManager))); - // Span - final InstanceIdentifier spanId = vppIfcAugId.child(Span.class); - registry.addStructuralReader(spanId, SpanBuilder.class); - // MirroredInterfaces - registry.subtreeAdd( - ImmutableSet.of(InstanceIdentifier.create(MirroredInterfaces.class).child(MirroredInterface.class)), - new GenericInitReader<>(spanId.child(MirroredInterfaces.class), - new InterfaceMirroredInterfacesCustomizer(jvpp, ifcNamingCtx))); - } - - private void initPbbRewriteAugmentation(final ModifiableReaderRegistryBuilder registry, - final InstanceIdentifier ifcId) { - registry.addStructuralReader(ifcId.augmentation(PbbRewriteStateInterfaceAugmentation.class), - PbbRewriteStateInterfaceAugmentationBuilder.class); - - registry.add(new GenericReader<>(ifcId.augmentation(PbbRewriteStateInterfaceAugmentation.class).child( - PbbRewriteState.class), new PbbRewriteStateCustomizer(jvpp))); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java index 4e9f7b9cc..0ba8c351a 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java @@ -21,37 +21,37 @@ import com.google.inject.Inject; import com.google.inject.name.Named; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.v3po.DisabledInterfacesManager; -import io.fd.hc2vpp.v3po.interfaces.AfPacketCustomizer; -import io.fd.hc2vpp.v3po.interfaces.AfPacketValidator; -import io.fd.hc2vpp.v3po.interfaces.EthernetCustomizer; -import io.fd.hc2vpp.v3po.interfaces.EthernetValidator; -import io.fd.hc2vpp.v3po.interfaces.GreCustomizer; -import io.fd.hc2vpp.v3po.interfaces.GreValidator; -import io.fd.hc2vpp.v3po.interfaces.InterfaceCustomizer; -import io.fd.hc2vpp.v3po.interfaces.InterfaceRoutingCustomizer; -import io.fd.hc2vpp.v3po.interfaces.InterfaceRoutingValidator; -import io.fd.hc2vpp.v3po.interfaces.InterfaceUnnumberedCustomizer; -import io.fd.hc2vpp.v3po.interfaces.InterfaceUnnumberedValidator; -import io.fd.hc2vpp.v3po.interfaces.InterfaceValidator; -import io.fd.hc2vpp.v3po.interfaces.InterfacesStatisticsCustomizer; import io.fd.hc2vpp.v3po.interfaces.InterfacesStatisticsValidator; -import io.fd.hc2vpp.v3po.interfaces.L2Customizer; -import io.fd.hc2vpp.v3po.interfaces.L2Validator; -import io.fd.hc2vpp.v3po.interfaces.LoopbackCustomizer; -import io.fd.hc2vpp.v3po.interfaces.LoopbackValidator; -import io.fd.hc2vpp.v3po.interfaces.TapV2Customizer; -import io.fd.hc2vpp.v3po.interfaces.TapV2Validator; -import io.fd.hc2vpp.v3po.interfaces.VhostUserCustomizer; -import io.fd.hc2vpp.v3po.interfaces.VhostUserValidator; -import io.fd.hc2vpp.v3po.interfaces.VxlanCustomizer; -import io.fd.hc2vpp.v3po.interfaces.VxlanGpeCustomizer; -import io.fd.hc2vpp.v3po.interfaces.VxlanGpeValidator; -import io.fd.hc2vpp.v3po.interfaces.VxlanValidator; -import io.fd.hc2vpp.v3po.interfaces.pbb.PbbRewriteCustomizer; -import io.fd.hc2vpp.v3po.interfaces.pbb.PbbRewriteValidator; -import io.fd.hc2vpp.v3po.interfaces.span.MirroredInterfaceCustomizer; -import io.fd.hc2vpp.v3po.interfaces.span.MirroredInterfaceValidator; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceStatisticsManager; +import io.fd.hc2vpp.v3po.write.AfPacketValidator; +import io.fd.hc2vpp.v3po.write.EthernetValidator; +import io.fd.hc2vpp.v3po.write.GreValidator; +import io.fd.hc2vpp.v3po.write.InterfaceRoutingValidator; +import io.fd.hc2vpp.v3po.write.InterfaceUnnumberedValidator; +import io.fd.hc2vpp.v3po.write.InterfaceValidator; +import io.fd.hc2vpp.v3po.write.L2Validator; +import io.fd.hc2vpp.v3po.write.LoopbackValidator; +import io.fd.hc2vpp.v3po.write.TapV2Validator; +import io.fd.hc2vpp.v3po.write.VhostUserValidator; +import io.fd.hc2vpp.v3po.write.VxlanGpeValidator; +import io.fd.hc2vpp.v3po.write.VxlanValidator; +import io.fd.hc2vpp.v3po.write.pbb.PbbRewriteValidator; +import io.fd.hc2vpp.v3po.write.span.MirroredInterfaceValidator; +import io.fd.hc2vpp.v3po.read.cache.InterfaceStatisticsManager; +import io.fd.hc2vpp.v3po.write.AfPacketCustomizer; +import io.fd.hc2vpp.v3po.write.EthernetCustomizer; +import io.fd.hc2vpp.v3po.write.GreCustomizer; +import io.fd.hc2vpp.v3po.write.InterfaceCustomizer; +import io.fd.hc2vpp.v3po.write.InterfaceRoutingCustomizer; +import io.fd.hc2vpp.v3po.write.InterfaceUnnumberedCustomizer; +import io.fd.hc2vpp.v3po.write.InterfacesStatisticsCustomizer; +import io.fd.hc2vpp.v3po.write.L2Customizer; +import io.fd.hc2vpp.v3po.write.LoopbackCustomizer; +import io.fd.hc2vpp.v3po.write.TapV2Customizer; +import io.fd.hc2vpp.v3po.write.VhostUserCustomizer; +import io.fd.hc2vpp.v3po.write.VxlanCustomizer; +import io.fd.hc2vpp.v3po.write.VxlanGpeCustomizer; +import io.fd.hc2vpp.v3po.write.pbb.PbbRewriteCustomizer; +import io.fd.hc2vpp.v3po.write.span.MirroredInterfaceCustomizer; import io.fd.honeycomb.translate.impl.write.GenericListWriter; import io.fd.honeycomb.translate.impl.write.GenericWriter; import io.fd.honeycomb.translate.write.WriterFactory; diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceAugmentationReaderFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceAugmentationReaderFactory.java new file mode 100644 index 000000000..39100b91b --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceAugmentationReaderFactory.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.factory; + +import com.google.common.collect.Sets; +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.RewriteCustomizer; +import io.fd.hc2vpp.v3po.read.SubInterfaceCustomizer; +import io.fd.hc2vpp.v3po.read.SubInterfaceL2Customizer; +import io.fd.hc2vpp.v3po.read.SubInterfaceRoutingCustomizer; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.hc2vpp.v3po.read.span.SubInterfaceMirroredInterfacesCustomizer; +import io.fd.honeycomb.translate.impl.read.GenericInitListReader; +import io.fd.honeycomb.translate.impl.read.GenericInitReader; +import io.fd.honeycomb.translate.impl.read.GenericReader; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; +import io.fd.jvpp.core.future.FutureJVppCore; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev170607.VppSubinterfaceSpanAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev170607.VppSubinterfaceSpanAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev170607.interfaces._interface.sub.interfaces.sub._interface.Span; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev170607.interfaces._interface.sub.interfaces.sub._interface.SpanBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfacesBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.vlan.tagged.VlanTagged; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.Rewrite; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.Match; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.Tags; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.tags.Tag; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.Routing; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.tag.rewrite.PushTags; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public final class SubinterfaceAugmentationReaderFactory implements ReaderFactory { + + private final FutureJVppCore jvpp; + private final NamingContext ifcCtx; + private final NamingContext bdCtx; + private final InterfaceCacheDumpManager ifaceDumpManager; + + @Inject + public SubinterfaceAugmentationReaderFactory(final FutureJVppCore jvpp, + @Named("interface-context") final NamingContext ifcCtx, + @Named("bridge-domain-context") final NamingContext bdCtx, + final InterfaceCacheDumpManager ifaceDumpManager) { + this.jvpp = jvpp; + this.ifcCtx = ifcCtx; + this.bdCtx = bdCtx; + this.ifaceDumpManager = ifaceDumpManager; + } + + @Override + public void init(final ModifiableReaderRegistryBuilder registry) { + // SubinterfaceStateAugmentation(Structural) + final InstanceIdentifier subIfcAugId = + InterfacesReaderFactory.IFC_ID.augmentation(SubinterfaceAugmentation.class); + registry.addStructuralReader(subIfcAugId, SubinterfaceAugmentationBuilder.class); + // SubInterfaces(Structural) + final InstanceIdentifier subIfcsId = subIfcAugId.child(SubInterfaces.class); + registry.addStructuralReader(subIfcsId, SubInterfacesBuilder.class); + // SubInterface(Subtree) + final InstanceIdentifier subIfcId = subIfcsId.child(SubInterface.class); + registry.subtreeAdd(Sets.newHashSet( + InstanceIdentifier.create(SubInterface.class).child(Tags.class), + InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class), + InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class).child(Dot1qTag.class), + InstanceIdentifier.create(SubInterface.class).child(Match.class), + InstanceIdentifier.create(SubInterface.class).child(Match.class).child(VlanTagged.class)), + new GenericInitListReader<>(subIfcId, + new SubInterfaceCustomizer(jvpp, ifcCtx, ifaceDumpManager))); + // L2 + final InstanceIdentifier l2Id = subIfcId.child(L2.class); + registry.add(new GenericInitReader<>(l2Id, + new SubInterfaceL2Customizer(jvpp, ifcCtx, bdCtx, ifaceDumpManager))); + // Rewrite(Subtree) + registry.subtreeAdd(Sets.newHashSet( + InstanceIdentifier.create(Rewrite.class).child(PushTags.class), + InstanceIdentifier.create(Rewrite.class).child(PushTags.class) + .child( + org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.Dot1qTag.class)), + new GenericReader<>(l2Id.child(Rewrite.class), + new RewriteCustomizer(ifaceDumpManager))); + final InstanceIdentifier routingId = subIfcId.child(Routing.class); + registry.add(new GenericReader<>(routingId, new SubInterfaceRoutingCustomizer(jvpp, ifcCtx))); + + final InstanceIdentifier spanAugId = + subIfcId.augmentation(VppSubinterfaceSpanAugmentation.class); + registry.addStructuralReader(spanAugId, VppSubinterfaceSpanAugmentationBuilder.class); + + final InstanceIdentifier spanId = spanAugId.child(Span.class); + registry.addStructuralReader(spanId, SpanBuilder.class); + + final InstanceIdentifier mirroredInterfacesId = spanId.child(MirroredInterfaces.class); + registry.add(new GenericInitReader<>(mirroredInterfacesId, + new SubInterfaceMirroredInterfacesCustomizer(jvpp, ifcCtx))); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceAugmentationWriterFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceAugmentationWriterFactory.java index 237eab57a..877c8d1ab 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceAugmentationWriterFactory.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceAugmentationWriterFactory.java @@ -20,18 +20,18 @@ import com.google.common.collect.Sets; import com.google.inject.Inject; import com.google.inject.name.Named; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfaces.RewriteCustomizer; -import io.fd.hc2vpp.v3po.interfaces.RewriteValidator; -import io.fd.hc2vpp.v3po.interfaces.SubInterfaceCustomizer; -import io.fd.hc2vpp.v3po.interfaces.SubInterfaceL2Customizer; -import io.fd.hc2vpp.v3po.interfaces.SubInterfaceL2Validator; -import io.fd.hc2vpp.v3po.interfaces.SubInterfaceRoutingCustomizer; -import io.fd.hc2vpp.v3po.interfaces.SubInterfaceRoutingValidator; -import io.fd.hc2vpp.v3po.interfaces.SubInterfaceUnnumberedCustomizer; -import io.fd.hc2vpp.v3po.interfaces.SubInterfaceUnnumberedValidator; -import io.fd.hc2vpp.v3po.interfaces.SubInterfaceValidator; -import io.fd.hc2vpp.v3po.interfaces.span.MirroredInterfaceCustomizer; +import io.fd.hc2vpp.v3po.write.RewriteValidator; +import io.fd.hc2vpp.v3po.write.SubInterfaceL2Validator; +import io.fd.hc2vpp.v3po.write.SubInterfaceRoutingValidator; +import io.fd.hc2vpp.v3po.write.SubInterfaceUnnumberedValidator; +import io.fd.hc2vpp.v3po.write.SubInterfaceValidator; import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; +import io.fd.hc2vpp.v3po.write.RewriteCustomizer; +import io.fd.hc2vpp.v3po.write.SubInterfaceCustomizer; +import io.fd.hc2vpp.v3po.write.SubInterfaceL2Customizer; +import io.fd.hc2vpp.v3po.write.SubInterfaceRoutingCustomizer; +import io.fd.hc2vpp.v3po.write.SubInterfaceUnnumberedCustomizer; +import io.fd.hc2vpp.v3po.write.span.MirroredInterfaceCustomizer; import io.fd.honeycomb.translate.impl.write.GenericListWriter; import io.fd.honeycomb.translate.impl.write.GenericWriter; import io.fd.honeycomb.translate.write.WriterFactory; diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceStateAugmentationReaderFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceStateAugmentationReaderFactory.java deleted file mode 100644 index d3fb57da7..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceStateAugmentationReaderFactory.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.factory; - -import com.google.common.collect.Sets; -import com.google.inject.Inject; -import com.google.inject.name.Named; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.RewriteCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceL2Customizer; -import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceRoutingCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.hc2vpp.v3po.interfacesstate.span.SubInterfaceMirroredInterfacesCustomizer; -import io.fd.honeycomb.translate.impl.read.GenericInitListReader; -import io.fd.honeycomb.translate.impl.read.GenericInitReader; -import io.fd.honeycomb.translate.impl.read.GenericReader; -import io.fd.honeycomb.translate.read.ReaderFactory; -import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; -import io.fd.jvpp.core.future.FutureJVppCore; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev170607.VppSubinterfaceSpanStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev170607.VppSubinterfaceSpanStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev170607.interfaces.state._interface.sub.interfaces.sub._interface.SpanState; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev170607.interfaces.state._interface.sub.interfaces.sub._interface.SpanStateBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.state.attributes.MirroredInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.SubInterfacesBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.vlan.tagged.VlanTagged; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.Rewrite; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.Match; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.Tags; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.tags.Tag; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.state.attributes.L2; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.Routing; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.tag.rewrite.PushTags; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public final class SubinterfaceStateAugmentationReaderFactory implements ReaderFactory { - - private final FutureJVppCore jvpp; - private final NamingContext ifcCtx; - private final NamingContext bdCtx; - private final InterfaceCacheDumpManager ifaceDumpManager; - - @Inject - public SubinterfaceStateAugmentationReaderFactory(final FutureJVppCore jvpp, - @Named("interface-context") final NamingContext ifcCtx, - @Named("bridge-domain-context") final NamingContext bdCtx, - final InterfaceCacheDumpManager ifaceDumpManager) { - this.jvpp = jvpp; - this.ifcCtx = ifcCtx; - this.bdCtx = bdCtx; - this.ifaceDumpManager = ifaceDumpManager; - } - - @Override - public void init(final ModifiableReaderRegistryBuilder registry) { - // SubinterfaceStateAugmentation(Structural) - final InstanceIdentifier subIfcAugId = - InterfacesStateReaderFactory.IFC_ID.augmentation(SubinterfaceStateAugmentation.class); - registry.addStructuralReader(subIfcAugId, SubinterfaceStateAugmentationBuilder.class); - // SubInterfaces(Structural) - final InstanceIdentifier subIfcsId = subIfcAugId.child(SubInterfaces.class); - registry.addStructuralReader(subIfcsId, SubInterfacesBuilder.class); - // SubInterface(Subtree) - final InstanceIdentifier subIfcId = subIfcsId.child(SubInterface.class); - registry.subtreeAdd(Sets.newHashSet( - InstanceIdentifier.create(SubInterface.class).child(Tags.class), - InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class), - InstanceIdentifier.create(SubInterface.class).child(Tags.class).child(Tag.class).child(Dot1qTag.class), - InstanceIdentifier.create(SubInterface.class).child(Match.class), - InstanceIdentifier.create(SubInterface.class).child(Match.class).child(VlanTagged.class)), - new GenericInitListReader<>(subIfcId, - new SubInterfaceCustomizer(jvpp, ifcCtx, ifaceDumpManager))); - // L2 - final InstanceIdentifier l2Id = subIfcId.child(L2.class); - registry.add(new GenericInitReader<>(l2Id, - new SubInterfaceL2Customizer(jvpp, ifcCtx, bdCtx, ifaceDumpManager))); - // Rewrite(Subtree) - registry.subtreeAdd(Sets.newHashSet( - InstanceIdentifier.create(Rewrite.class).child(PushTags.class), - InstanceIdentifier.create(Rewrite.class).child(PushTags.class) - .child( - org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.Dot1qTag.class)), - new GenericReader<>(l2Id.child(Rewrite.class), - new RewriteCustomizer(ifaceDumpManager))); - final InstanceIdentifier routingId = subIfcId.child(Routing.class); - registry.add(new GenericReader<>(routingId, new SubInterfaceRoutingCustomizer(jvpp, ifcCtx))); - - final InstanceIdentifier spanStateAugId = - subIfcId.augmentation(VppSubinterfaceSpanStateAugmentation.class); - registry.addStructuralReader(spanStateAugId, VppSubinterfaceSpanStateAugmentationBuilder.class); - - final InstanceIdentifier spanStateId = spanStateAugId - .child(SpanState.class); - registry.addStructuralReader(spanStateId, SpanStateBuilder.class); - - final InstanceIdentifier mirroredInterfacesId = spanStateId.child(MirroredInterfaces.class); - registry.add(new GenericInitReader<>(mirroredInterfacesId, - new SubInterfaceMirroredInterfacesCustomizer(jvpp, ifcCtx))); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/AbstractUnnumberedCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/AbstractUnnumberedCustomizer.java deleted file mode 100644 index 1f71e88f3..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/AbstractUnnumberedCustomizer.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.SwInterfaceSetUnnumbered; -import io.fd.jvpp.core.future.FutureJVppCore; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -abstract class AbstractUnnumberedCustomizer extends FutureJVppCustomizer implements WriterCustomizer, - JvppReplyConsumer, ByteDataTranslator { - private static final Logger LOG = LoggerFactory.getLogger(AbstractUnnumberedCustomizer.class); - - private final NamingContext interfaceContext; - - protected AbstractUnnumberedCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore); - this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null"); - } - - protected void setUnnumbered(@Nonnull final InstanceIdentifier id, - @Nonnull final String unnumberedIfcName, - @Nonnull final Unnumbered data, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final int unnumberedIfcId = interfaceContext.getIndex(unnumberedIfcName, writeContext.getMappingContext()); - final int targetId = interfaceContext.getIndex(data.getUse(), writeContext.getMappingContext()); - final SwInterfaceSetUnnumbered request = getUnnumberedAddDelRequest(targetId, unnumberedIfcId, true); - getReplyForWrite(getFutureJVpp().swInterfaceSetUnnumbered(request).toCompletableFuture(), id); - LOG.debug("The {}(id={}) interface unnumbered flag was set: {}", unnumberedIfcName, unnumberedIfcId, data); - } - - protected void disableUnnumbered(@Nonnull final InstanceIdentifier id, - @Nonnull final String unnumberedIfcName, - @Nonnull final Unnumbered data, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final int unnumberedIfcId = interfaceContext.getIndex(unnumberedIfcName, writeContext.getMappingContext()); - final int targetId = interfaceContext.getIndex(data.getUse(), writeContext.getMappingContext()); - final SwInterfaceSetUnnumbered request = getUnnumberedAddDelRequest(targetId, unnumberedIfcId, false); - getReplyForWrite(getFutureJVpp().swInterfaceSetUnnumbered(request).toCompletableFuture(), id); - LOG.debug("The {}(id={}) interface unnumbered flag was unset: {}", unnumberedIfcName, unnumberedIfcId, data); - } - - private SwInterfaceSetUnnumbered getUnnumberedAddDelRequest(final int targetId, final int unnumberedIfcId, - final Boolean isAdd) { - final SwInterfaceSetUnnumbered request = new SwInterfaceSetUnnumbered(); - request.swIfIndex = targetId; - request.unnumberedSwIfIndex = unnumberedIfcId; - request.isAdd = booleanToByte(isAdd); - return request; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/AfPacketCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/AfPacketCustomizer.java deleted file mode 100644 index ea4220acd..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/AfPacketCustomizer.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2018 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.MacTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.AfPacketCreate; -import io.fd.jvpp.core.dto.AfPacketCreateReply; -import io.fd.jvpp.core.dto.AfPacketDelete; -import io.fd.jvpp.core.dto.AfPacketDeleteReply; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.nio.charset.StandardCharsets; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacket; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class AfPacketCustomizer extends AbstractInterfaceTypeCustomizer - implements MacTranslator, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(AfPacketCustomizer.class); - private final NamingContext interfaceContext; - - public AfPacketCustomizer(@Nonnull final FutureJVppCore vppApi, @Nonnull final NamingContext interfaceContext) { - super(vppApi); - this.interfaceContext = interfaceContext; - } - - @Override - protected Class getExpectedInterfaceType() { - return org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.AfPacket.class; - } - - @Override - protected final void writeInterface(@Nonnull final InstanceIdentifier id, - @Nonnull final AfPacket dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String swIfName = id.firstKeyOf(Interface.class).getName(); - final int swIfIndex = createAfPacketIfc(id, swIfName, dataAfter); - - // Add new interface to our interface context - interfaceContext.addName(swIfIndex, swIfName, writeContext.getMappingContext()); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final AfPacket dataBefore, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String swIfName = id.firstKeyOf(Interface.class).getName(); - deleteAfPacketIfc(id, swIfName, dataBefore); - - // Remove interface from interface context - interfaceContext.removeName(swIfName, writeContext.getMappingContext()); - } - - private int createAfPacketIfc(final InstanceIdentifier id, final String swIfName, final AfPacket afPacket) - throws WriteFailedException { - LOG.debug("Creating af_packet interface {}: {}", swIfName, afPacket); - final CompletionStage createAfPacketIfReplyCompletionStage = - getFutureJVpp().afPacketCreate(getCreateRequest(afPacket)); - final AfPacketCreateReply reply = - getReplyForCreate(createAfPacketIfReplyCompletionStage.toCompletableFuture(), id, afPacket); - LOG.debug("Af_packet interface {} created successfully: {}", swIfName, afPacket); - return reply.swIfIndex; - } - - private AfPacketCreate getCreateRequest(@Nonnull final AfPacket afPacket) { - final AfPacketCreate request = new AfPacketCreate(); - request.hostIfName = afPacket.getHostInterfaceName().getBytes(StandardCharsets.UTF_8); - final PhysAddress mac = afPacket.getMac(); - if (mac == null) { - request.useRandomHwAddr = 1; - request.hwAddr = new byte[6]; - } else { - request.useRandomHwAddr = 0; - request.hwAddr = parseMac(mac.getValue()); - } - return request; - } - - private void deleteAfPacketIfc(final InstanceIdentifier id, final String swIfName, - final AfPacket afPacket) throws WriteFailedException { - LOG.debug("Deleting af_packet interface {}: {}", swIfName, afPacket); - final CompletionStage deleteAfPacketIfReplyCompletionStage = - getFutureJVpp().afPacketDelete(getDeleteRequest(afPacket)); - - getReplyForDelete(deleteAfPacketIfReplyCompletionStage.toCompletableFuture(), id); - LOG.debug("Af_packet interface {} deleted successfully: {}", swIfName, afPacket); - } - - private AfPacketDelete getDeleteRequest(@Nonnull final AfPacket afPacket) { - final AfPacketDelete request = new AfPacketDelete(); - request.hostIfName = afPacket.getHostInterfaceName().getBytes(StandardCharsets.UTF_8); - return request; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/AfPacketValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/AfPacketValidator.java deleted file mode 100644 index f76922cd0..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/AfPacketValidator.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import java.nio.charset.StandardCharsets; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacket; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class AfPacketValidator implements Validator { - - public AfPacketValidator(@Nonnull final NamingContext interfaceContext) { - checkNotNull(interfaceContext, "interfaceContext should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final AfPacket dataAfter, - @Nonnull final WriteContext writeContext) - throws CreateValidationFailedException { - try { - validateAfPacket(dataAfter); - } catch (Exception e) { - throw new CreateValidationFailedException(id, dataAfter, e); - } - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final AfPacket dataBefore, - @Nonnull final AfPacket dataAfter, @Nonnull final WriteContext writeContext) - throws UpdateValidationFailedException { - try { - validateAfPacket(dataAfter); - } catch (Exception e) { - throw new UpdateValidationFailedException(id, dataBefore, dataAfter, e); - } - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final AfPacket dataBefore, - @Nonnull final WriteContext writeContext) - throws DeleteValidationFailedException { - try { - validateAfPacket(dataBefore); - } catch (Exception e) { - throw new DeleteValidationFailedException(id, e); - } - } - - private void validateAfPacket(final AfPacket data) { - checkNotNull(data.getHostInterfaceName(), "host-interface-name is mandatory for af-packet interface"); - byte[] hostIfName = data.getHostInterfaceName().getBytes(StandardCharsets.UTF_8); - checkArgument(hostIfName.length <= 64, - "Interface name for af_packet interface should not be longer than 64 bytes, but was %s", - hostIfName.length); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/EthernetCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/EthernetCustomizer.java deleted file mode 100644 index e5ff62d2b..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/EthernetCustomizer.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.HwInterfaceSetMtu; -import io.fd.jvpp.core.future.FutureJVppCore; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Ethernet; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev180703.EthernetCsmacd; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class EthernetCustomizer extends AbstractInterfaceTypeCustomizer implements JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(EthernetCustomizer.class); - private final NamingContext interfaceContext; - - public EthernetCustomizer(final FutureJVppCore vppApi, final NamingContext interfaceContext) { - super(vppApi); - this.interfaceContext = interfaceContext; - } - - @Override - protected Class getExpectedInterfaceType() { - return EthernetCsmacd.class; - } - - @Override - public void writeInterface(@Nonnull final InstanceIdentifier id, - @Nonnull final Ethernet dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - setEthernetAttributes(id, dataAfter, writeContext); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Ethernet dataBefore, @Nonnull final Ethernet dataAfter, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - setEthernetAttributes(id, dataAfter, writeContext); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Ethernet dataBefore, @Nonnull final WriteContext writeContext) - throws WriteFailedException.DeleteFailedException { - throw new WriteFailedException.DeleteFailedException(id, - new UnsupportedOperationException("Removing ethernet container is not supported")); - } - - private void setEthernetAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Ethernet dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String name = id.firstKeyOf(Interface.class).getName(); - final int index = interfaceContext.getIndex(name, writeContext.getMappingContext()); - LOG.debug("Setting Ethernet attributes for interface: {}, {}. Ethernet: {}", name, index, dataAfter); - - // Set the physical payload MTU. I.e. not including L2 overhead. - // Setting the hardware MTU will program the NIC. - // Setting MTU for software interfaces is currently not supported (TODO: HC2VPP-355). - // More details: - // https://git.fd.io/vpp/tree/src/vnet/MTU.md - final HwInterfaceSetMtu request = new HwInterfaceSetMtu(); - request.swIfIndex = index; - request.mtu = dataAfter.getMtu().shortValue(); - getReplyForWrite(getFutureJVpp().hwInterfaceSetMtu(request).toCompletableFuture(), id); - LOG.debug("Ethernet attributes set successfully for: {}, {}. Ethernet: {}", name, index, dataAfter); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/EthernetValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/EthernetValidator.java deleted file mode 100644 index e8fa32a17..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/EthernetValidator.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Ethernet; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class EthernetValidator implements Validator { - - public EthernetValidator(final NamingContext interfaceContext) { - checkNotNull(interfaceContext, "interfaceContext should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Ethernet dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.CreateValidationFailedException { - checkNotNull(dataAfter.getMtu(), "MTU cannot be null"); - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Ethernet dataBefore, - @Nonnull final Ethernet dataAfter, @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.UpdateValidationFailedException { - checkNotNull(dataAfter.getMtu(), "MTU cannot be null"); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/GreCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/GreCustomizer.java deleted file mode 100644 index b13388102..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/GreCustomizer.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2016 Intel and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; -import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.GreTunnelAddDel; -import io.fd.jvpp.core.dto.GreTunnelAddDelReply; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.GreTunnel; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Gre; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class GreCustomizer extends AbstractInterfaceTypeCustomizer implements JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(GreCustomizer.class); - private final NamingContext interfaceContext; - - public GreCustomizer(final FutureJVppCore vppApi, final NamingContext interfaceContext) { - super(vppApi); - this.interfaceContext = interfaceContext; - } - - private static GreTunnelAddDel getGreTunnelRequest(final byte isAdd, final IpAddressNoZone srcAddr, - final IpAddressNoZone dstAddr, final int outerFibId, - final byte isIpv6) { - final GreTunnelAddDel greTunnelAddDel = new GreTunnelAddDel(); - greTunnelAddDel.isAdd = isAdd; - greTunnelAddDel.tunnel = new io.fd.jvpp.core.types.GreTunnel(); - if (isIpv6==0) { - greTunnelAddDel.tunnel.src = - AddressTranslator.INSTANCE.ipv4AddressNoZoneToAddress(srcAddr.getIpv4AddressNoZone()); - greTunnelAddDel.tunnel.dst = - AddressTranslator.INSTANCE.ipv4AddressNoZoneToAddress(dstAddr.getIpv4AddressNoZone()); - } else { - greTunnelAddDel.tunnel.src = - AddressTranslator.INSTANCE.ipv6AddressToAddress(srcAddr.getIpv6AddressNoZone()); - greTunnelAddDel.tunnel.dst = - AddressTranslator.INSTANCE.ipv6AddressToAddress(dstAddr.getIpv6AddressNoZone()); - } - greTunnelAddDel.tunnel.outerFibId = outerFibId; - greTunnelAddDel.tunnel.isIpv6 = isIpv6; - return greTunnelAddDel; - } - - @Override - protected Class getExpectedInterfaceType() { - return GreTunnel.class; - } - - @Override - protected final void writeInterface(@Nonnull final InstanceIdentifier id, @Nonnull final Gre dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String swIfName = id.firstKeyOf(Interface.class).getName(); - - createGreTunnel(id, swIfName, dataAfter, writeContext); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final Gre dataBefore, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String swIfName = id.firstKeyOf(Interface.class).getName(); - deleteGreTunnel(id, swIfName, dataBefore, writeContext); - } - - private void createGreTunnel(final InstanceIdentifier id, final String swIfName, final Gre gre, - final WriteContext writeContext) throws WriteFailedException { - final byte isIpv6 = (byte) (isIpv6(gre) - ? 1 - : 0); - int outerFibId = gre.getOuterFibId().intValue(); - - LOG.debug("Setting gre tunnel for interface: {}. Gre: {}", swIfName, gre); - final CompletionStage greAddDelTunnelReplyCompletionStage = - getFutureJVpp().greTunnelAddDel(getGreTunnelRequest((byte) 1 /* is add */, gre.getSrc(), - gre.getDst(), outerFibId, isIpv6)); - - final GreTunnelAddDelReply reply = - getReplyForCreate(greAddDelTunnelReplyCompletionStage.toCompletableFuture(), id, gre); - LOG.debug("Gre tunnel set successfully for: {}, gre: {}", swIfName, gre); - if (interfaceContext.containsName(reply.swIfIndex, writeContext.getMappingContext())) { - // VPP keeps gre tunnels present even after they are delete(reserving ID for next tunnel) - // This may cause inconsistencies in mapping context when configuring tunnels like this: - // 1. Add tunnel 2. Delete tunnel 3. Read interfaces (reserved mapping e.g. gre_tunnel0 -> 6 - // will get into mapping context) 4. Add tunnel (this will add another mapping with the same - // reserved ID and context is invalid) - // That's why a check has to be performed here removing mapping gre_tunnel0 -> 6 mapping and storing - // new name for that ID - final String formerName = interfaceContext.getName(reply.swIfIndex, writeContext.getMappingContext()); - LOG.debug("Removing updated mapping of a gre tunnel, id: {}, former name: {}, new name: {}", - reply.swIfIndex, formerName, swIfName); - interfaceContext.removeName(formerName, writeContext.getMappingContext()); - } - // Add new interface to our interface context - interfaceContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); - } - - private boolean isIpv6(final Gre gre) { - return gre.getSrc().getIpv4AddressNoZone() == null; - } - - private void deleteGreTunnel(final InstanceIdentifier id, final String swIfName, final Gre gre, - final WriteContext writeContext) throws WriteFailedException { - final byte isIpv6 = (byte) (isIpv6(gre) - ? 1 - : 0); - - int outerFibId = gre.getOuterFibId().intValue(); - - LOG.debug("Deleting gre tunnel for interface: {}. Gre: {}", swIfName, gre); - final CompletionStage greAddDelTunnelReplyCompletionStage = - getFutureJVpp().greTunnelAddDel(getGreTunnelRequest((byte) 0 /* is add */, gre.getSrc(), - gre.getDst(), outerFibId, isIpv6)); - - getReplyForDelete(greAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); - LOG.debug("Gre tunnel deleted successfully for: {}, gre: {}", swIfName, gre); - // Remove interface from our interface context - interfaceContext.removeName(swIfName, writeContext.getMappingContext()); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/GreValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/GreValidator.java deleted file mode 100644 index 9376ab87d..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/GreValidator.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Gre; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class GreValidator implements Validator { - - public GreValidator(final NamingContext interfaceContext) { - checkNotNull(interfaceContext, "interfaceContext should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Gre dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.CreateValidationFailedException { - try { - validateGre(dataAfter); - } catch (Exception e) { - throw new DataValidationFailedException.CreateValidationFailedException(id, dataAfter, e); - } - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Gre dataBefore, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.DeleteValidationFailedException { - try { - validateGre(dataBefore); - } catch (Exception e) { - throw new DataValidationFailedException.DeleteValidationFailedException(id, e); - } - } - - private void validateGre(final Gre data) { - checkNotNull(data.getOuterFibId(), "Outer Fib ID cannot be null"); - checkNotNull(data.getSrc(), "Source cannot be null"); - checkNotNull(data.getDst(), "Destination cannot be null"); - if (data.getSrc().getIpv4AddressNoZone() == null) { - checkArgument(data.getDst().getIpv4AddressNoZone() == null, "Inconsistent ip addresses: %s, %s", - data.getSrc(), - data.getDst()); - } else { - checkArgument(data.getDst().getIpv6AddressNoZone() == null, "Inconsistent ip addresses: %s, %s", - data.getSrc(), - data.getDst()); - } - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterconnectionWriteUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterconnectionWriteUtils.java deleted file mode 100644 index 37eafc785..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterconnectionWriteUtils.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkArgument; -import static java.util.Objects.requireNonNull; - -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.SwInterfaceSetL2Bridge; -import io.fd.jvpp.core.dto.SwInterfaceSetL2BridgeReply; -import io.fd.jvpp.core.dto.SwInterfaceSetL2Xconnect; -import io.fd.jvpp.core.dto.SwInterfaceSetL2XconnectReply; -import io.fd.jvpp.core.future.FutureJVppCore; -import io.fd.jvpp.core.types.L2PortType; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.Interconnection; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.BridgeBased; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.XconnectBased; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Utility class providing Interconnection CUD support. - */ -final class InterconnectionWriteUtils implements JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(InterconnectionWriteUtils.class); - - private final FutureJVppCore futureJVppCore; - private final NamingContext interfaceContext; - private final NamingContext bridgeDomainContext; - - InterconnectionWriteUtils(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext, - @Nonnull final NamingContext bridgeDomainContext) { - this.futureJVppCore = requireNonNull(futureJVppCore, "futureJVppCore should not be null"); - this.interfaceContext = requireNonNull(interfaceContext, "interfaceContext should not be null"); - this.bridgeDomainContext = requireNonNull(bridgeDomainContext, "bridgeDomainContext should not be null"); - } - - void setInterconnection(final InstanceIdentifier id, final int swIfIndex, - final String ifcName, final Interconnection ic, final WriteContext writeContext) - throws WriteFailedException { - - if (ic == null) { // TODO in case of update we should delete interconnection - LOG.trace("Interconnection is not set. Skipping"); - } else if (ic instanceof XconnectBased) { - setXconnectBasedL2(id, swIfIndex, ifcName, (XconnectBased) ic, writeContext, (byte) 1 /*enable*/); - } else if (ic instanceof BridgeBased) { - setBridgeBasedL2(id, swIfIndex, ifcName, (BridgeBased) ic, writeContext, (byte) 1 /*enable*/); - } else { - // Choices&cases are not data objects, so they cannot have a dedicated Reader/Writer - // This choice is already from augment, so its not possible to augment augmented choice - LOG.error("Unable to handle Interconnection of type {}", ic.getClass()); - throw new WriteFailedException(id, "Unable to handle Interconnection of type " + ic.getClass()); - } - } - - void deleteInterconnection(final InstanceIdentifier id, final int swIfIndex, - final String ifcName, final Interconnection ic, final WriteContext writeContext) - throws WriteFailedException { - - if (ic == null) { // TODO in case of update we should delete interconnection - LOG.trace("Interconnection is not set. Skipping"); - } else if (ic instanceof XconnectBased) { - setXconnectBasedL2(id, swIfIndex, ifcName, (XconnectBased) ic, writeContext, (byte) 0 /*disable*/); - } else if (ic instanceof BridgeBased) { - setBridgeBasedL2(id, swIfIndex, ifcName, (BridgeBased) ic, writeContext, (byte) 0 /*disable*/); - } else { - LOG.error("Unable to delete Interconnection of type {}", ic.getClass()); - throw new WriteFailedException(id, "Unable to delete Interconnection of type " + ic.getClass()); - } - } - - private void setBridgeBasedL2(final InstanceIdentifier id, final int swIfIndex, - final String ifcName, final BridgeBased bb, - final WriteContext writeContext, final byte enabled) throws WriteFailedException { - LOG.debug("Setting bridge based interconnection(bridge-domain={}) for interface: {}", bb.getBridgeDomain(), - ifcName); - - String bdName = bb.getBridgeDomain(); - - int bdId = bridgeDomainContext.getIndex(bdName, writeContext.getMappingContext()); - checkArgument(bdId > 0, "Unable to set Interconnection for Interface: %s, bridge domain: %s does not exist", - ifcName, bdName); - - byte shg = 0; - if (bb.getSplitHorizonGroup() != null) { - shg = bb.getSplitHorizonGroup().byteValue(); - } - - final CompletionStage swInterfaceSetL2BridgeReplyCompletionStage = futureJVppCore - .swInterfaceSetL2Bridge(getL2BridgeRequest(swIfIndex, bdId, shg, bb.isBridgedVirtualInterface(), enabled)); - getReplyForWrite(swInterfaceSetL2BridgeReplyCompletionStage.toCompletableFuture(), id); - - LOG.debug("Bridge based interconnection updated successfully for: {}, interconnection: {}", ifcName, bb); - } - - private SwInterfaceSetL2Bridge getL2BridgeRequest(final int swIfIndex, final int bdId, final byte shg, - final Boolean bvi, final byte enabled) { - final SwInterfaceSetL2Bridge swInterfaceSetL2Bridge = new SwInterfaceSetL2Bridge(); - swInterfaceSetL2Bridge.rxSwIfIndex = swIfIndex; - swInterfaceSetL2Bridge.bdId = bdId; - swInterfaceSetL2Bridge.shg = shg; - - // TODO HC2VPP-389: add support for unknown unicast type - swInterfaceSetL2Bridge.portType = bvi ? L2PortType.L2_API_PORT_TYPE_BVI : L2PortType.L2_API_PORT_TYPE_NORMAL; - swInterfaceSetL2Bridge.enable = enabled; - return swInterfaceSetL2Bridge; - } - - private void setXconnectBasedL2(final InstanceIdentifier id, final int swIfIndex, - final String ifcName, final XconnectBased ic, - final WriteContext writeContext, final byte enabled) throws WriteFailedException { - String outSwIfName = ic.getXconnectOutgoingInterface(); - LOG.debug("Setting xconnect based interconnection(outgoing ifc={}) for interface: {}", outSwIfName, ifcName); - - int outSwIfIndex = interfaceContext.getIndex(outSwIfName, writeContext.getMappingContext()); - checkArgument(outSwIfIndex > 0, - "Unable to set Interconnection for Interface: %s, outgoing interface: %s does not exist", - ifcName, outSwIfIndex); - - final CompletionStage swInterfaceSetL2XconnectReplyCompletionStage = - futureJVppCore - .swInterfaceSetL2Xconnect(getL2XConnectRequest(swIfIndex, outSwIfIndex, enabled)); - getReplyForWrite(swInterfaceSetL2XconnectReplyCompletionStage.toCompletableFuture(), id); - LOG.debug("Xconnect based interconnection updated successfully for: {}, interconnection: {}", ifcName, ic); - } - - private SwInterfaceSetL2Xconnect getL2XConnectRequest(final int rxIfc, final int txIfc, - final byte enabled) { - - final SwInterfaceSetL2Xconnect swInterfaceSetL2Xconnect = new SwInterfaceSetL2Xconnect(); - swInterfaceSetL2Xconnect.enable = enabled; - swInterfaceSetL2Xconnect.rxSwIfIndex = rxIfc; - swInterfaceSetL2Xconnect.txSwIfIndex = txIfc; - return swInterfaceSetL2Xconnect; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizer.java deleted file mode 100644 index d6a5abd49..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizer.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.SwInterfaceSetFlags; -import io.fd.jvpp.core.dto.SwInterfaceSetFlagsReply; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Ietf interface write customizer that only caches interface objects for child writers - */ -public class InterfaceCustomizer extends FutureJVppCustomizer - implements ListWriterCustomizer, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(InterfaceCustomizer.class); - private static final String LOCAL0_NAME = "local0"; - - private final NamingContext interfaceContext; - - public InterfaceCustomizer(final FutureJVppCore vppApi, final NamingContext interfaceContext) { - super(vppApi); - this.interfaceContext = interfaceContext; - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Interface dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - - setInterface(id, dataAfter, writeContext); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Interface dataBefore, - @Nonnull final Interface dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - updateInterface(id, dataAfter, writeContext); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Interface dataBefore, - @Nonnull final WriteContext writeContext) - throws WriteFailedException.DeleteFailedException { - // Special handling for local0 interface (HC2VPP-308): - if (LOCAL0_NAME.equals(dataBefore.getName())) { - throw new WriteFailedException.DeleteFailedException(id, - new UnsupportedOperationException("Removing " + LOCAL0_NAME + " interface is not supported")); - } - // For other interfaces, delegate delete to customizers for specific interface types (e.g. VXLan, Tap). - } - - private void setInterface(final InstanceIdentifier id, final Interface swIf, - final WriteContext writeContext) throws WriteFailedException { - LOG.debug("Setting interface: {} to: {}", id, swIf); - setInterfaceAttributes(id, swIf, swIf.getName(), writeContext); - } - - private void setInterfaceAttributes(final InstanceIdentifier id, final Interface swIf, - final String swIfName, final WriteContext writeContext) - throws WriteFailedException { - - setInterfaceFlags(id, swIfName, interfaceContext.getIndex(swIfName, writeContext.getMappingContext()), - swIf.isEnabled() - ? (byte) 1 - : (byte) 0); - } - - private void updateInterface(final InstanceIdentifier id, - final Interface dataAfter, final WriteContext writeContext) - throws WriteFailedException { - LOG.debug("Updating interface:{} to: {}", id, dataAfter); - setInterfaceAttributes(id, dataAfter, dataAfter.getName(), writeContext); - } - - private void setInterfaceFlags(final InstanceIdentifier id, final String swIfName, final int swIfIndex, - final byte enabled) throws WriteFailedException { - final CompletionStage swInterfaceSetFlagsReplyFuture = - getFutureJVpp().swInterfaceSetFlags(getSwInterfaceSetFlagsInput(swIfIndex, enabled)); - - LOG.debug("Updating interface flags for: {}, index: {}, enabled: {}", swIfName, swIfIndex, enabled); - - getReplyForWrite(swInterfaceSetFlagsReplyFuture.toCompletableFuture(), id); - LOG.debug("Interface flags updated successfully for: {}, index: {}, enabled: {}", - swIfName, swIfIndex, enabled); - } - - private SwInterfaceSetFlags getSwInterfaceSetFlagsInput(final int swIfIndex, final byte enabled) { - final SwInterfaceSetFlags swInterfaceSetFlags = new SwInterfaceSetFlags(); - swInterfaceSetFlags.swIfIndex = swIfIndex; - swInterfaceSetFlags.adminUpDown = enabled; - return swInterfaceSetFlags; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizer.java deleted file mode 100644 index e498e0cae..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizer.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.future.FutureJVppCore; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Routing; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceRoutingCustomizer extends RoutingCustomizer - implements WriterCustomizer { - - public InterfaceRoutingCustomizer(@Nonnull final FutureJVppCore vppApi, - @Nonnull final NamingContext interfaceContext) { - super(vppApi, interfaceContext); - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Routing dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String ifName = id.firstKeyOf(Interface.class).getName(); - setRouting(id, ifName, dataAfter, writeContext); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Routing dataBefore, @Nonnull final Routing dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String ifName = id.firstKeyOf(Interface.class).getName(); - setRouting(id, ifName, dataAfter, writeContext); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Routing dataBefore, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String ifName = id.firstKeyOf(Interface.class).getName(); - disableRouting(id, ifName, writeContext); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingValidator.java deleted file mode 100644 index 011772600..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingValidator.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import java.util.List; -import java.util.Optional; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.RoutingBaseAttributes; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Routing; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceRoutingValidator implements Validator { - - public InterfaceRoutingValidator(@Nonnull final NamingContext interfaceContext) { - checkNotNull(interfaceContext, "interfaceContext should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Routing dataAfter, - @Nonnull final WriteContext writeContext) - throws CreateValidationFailedException { - try { - checkVrfIds(dataAfter); - checkInterfaceAddressConf(id, writeContext, true); - } catch (Exception e) { - throw new CreateValidationFailedException(id, dataAfter, e); - } - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Routing dataBefore, - @Nonnull final Routing dataAfter, @Nonnull final WriteContext writeContext) - throws UpdateValidationFailedException { - try { - checkVrfIds(dataAfter); - checkInterfaceAddressConf(id, writeContext, true); - } catch (Exception e) { - throw new UpdateValidationFailedException(id, dataBefore, dataAfter, e); - } - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Routing dataBefore, - @Nonnull final WriteContext writeContext) - throws DeleteValidationFailedException { - try { - checkVrfIds(dataBefore); - checkInterfaceAddressConf(id, writeContext, false); - } catch (Exception e) { - throw new DeleteValidationFailedException(id, e); - } - } - - private void checkVrfIds(final RoutingBaseAttributes data) { - checkArgument(data.getIpv4VrfId() != null || data.getIpv6VrfId() != null, "No vrf-id given"); - } - - private void checkInterfaceAddressConf(@Nonnull final InstanceIdentifier id, - @Nonnull final WriteContext ctx, - boolean checkBefore) { - checkState(isAddressNotPresentForInterface(id, ctx, checkBefore), - "Cannot change routing configuration, if address is present for interface"); - } - - /** - * Returns true if interface does not have v4/v6 addresses configured - */ - private boolean isAddressNotPresentForInterface(@Nonnull final InstanceIdentifier id, - @Nonnull final WriteContext ctx, - boolean checkBefore) { - final Optional interfaceData = checkBefore - ? ctx.readBefore(RWUtils.cutId(id, Interface.class)) - : ctx.readAfter(RWUtils.cutId(id, Interface.class)); - - if (interfaceData.isPresent()) { - final java.util.Optional augData = java.util.Optional.of(interfaceData.get()) - .map(iface -> iface.augmentation(Interface1.class)); - - final boolean v4NotPresent = - augData.map(Interface1::getIpv4).map(Ipv4::getAddress).map(List::isEmpty).orElse(true); - - final boolean v6NotPresent = - augData.map(Interface1::getIpv6).map(Ipv6::getAddress).map(List::isEmpty).orElse(true); - - return v4NotPresent && v6NotPresent; - } - return true; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceUnnumberedCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceUnnumberedCustomizer.java deleted file mode 100644 index 36b32317b..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceUnnumberedCustomizer.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.future.FutureJVppCore; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public final class InterfaceUnnumberedCustomizer extends AbstractUnnumberedCustomizer { - - public InterfaceUnnumberedCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore, interfaceContext); - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Unnumbered dataAfter, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - setUnnumbered(id, id.firstKeyOf(Interface.class).getName(), dataAfter, writeContext); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Unnumbered dataBefore, @Nonnull final Unnumbered dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - setUnnumbered(id, id.firstKeyOf(Interface.class).getName(), dataAfter, writeContext); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Unnumbered dataBefore, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - disableUnnumbered(id, id.firstKeyOf(Interface.class).getName(), dataBefore, writeContext); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceUnnumberedValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceUnnumberedValidator.java deleted file mode 100644 index 0120582d1..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceUnnumberedValidator.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceUnnumberedValidator implements Validator { - - public InterfaceUnnumberedValidator(final NamingContext interfaceContext) { - checkNotNull(interfaceContext, "interfaceContext should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Unnumbered dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.CreateValidationFailedException { - checkNotNull(dataAfter.getUse(), "Use cannot be null"); - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Unnumbered dataBefore, - @Nonnull final Unnumbered dataAfter, @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.UpdateValidationFailedException { - checkNotNull(dataAfter.getUse(), "Use cannot be null"); - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Unnumbered dataBefore, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.DeleteValidationFailedException { - checkNotNull(dataBefore.getUse(), "Use cannot be null"); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceValidator.java deleted file mode 100644 index 3e6ed638e..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceValidator.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceValidator implements Validator { - - public InterfaceValidator(final NamingContext interfaceContext) { - checkNotNull(interfaceContext, "interfaceContext should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Interface dataAfter, - @Nonnull final WriteContext writeContext) - throws CreateValidationFailedException { - try { - checkInterface(dataAfter); - } catch (Exception e) { - throw new CreateValidationFailedException(id, dataAfter, e); - } - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Interface dataBefore, - @Nonnull final Interface dataAfter, @Nonnull final WriteContext writeContext) - throws UpdateValidationFailedException { - try { - checkInterface(dataAfter); - } catch (Exception e) { - throw new UpdateValidationFailedException(id, dataBefore, dataAfter, e); - } - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Interface dataBefore, - @Nonnull final WriteContext writeContext) - throws DeleteValidationFailedException { - try { - checkInterface(dataBefore); - } catch (Exception e) { - throw new DeleteValidationFailedException(id, e); - } - } - - private void checkInterface(final Interface data) { - checkNotNull(data.isEnabled(), "Enabled tag cannot be null"); - checkNotNull(data.getName(), "Name cannot be null"); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfacesStatisticsCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfacesStatisticsCustomizer.java deleted file mode 100644 index e7ef14dc4..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfacesStatisticsCustomizer.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceStatisticsManager; -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.Statistics; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfacesStatisticsCustomizer implements WriterCustomizer { - - private final InterfaceStatisticsManager statisticsManager; - - public InterfacesStatisticsCustomizer(final InterfaceStatisticsManager statisticsManager) { - this.statisticsManager = statisticsManager; - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier instanceIdentifier, - @Nonnull final Statistics statisticsCollection, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - enableDisableStatistics(statisticsCollection); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Statistics dataBefore, - @Nonnull final Statistics dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - enableDisableStatistics(dataAfter); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier instanceIdentifier, - @Nonnull final Statistics statisticsCollection, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - statisticsManager.disableStatistics(); - } - - private void enableDisableStatistics(final Statistics statsCollect) { - if (statsCollect != null) { - if (statsCollect.isEnabled()) { - statisticsManager.enableStatistics(); - return; - } - } - statisticsManager.disableStatistics(); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfacesStatisticsValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfacesStatisticsValidator.java deleted file mode 100644 index 00c58b5fc..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfacesStatisticsValidator.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceStatisticsManager; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.Statistics; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfacesStatisticsValidator implements Validator { - - public InterfacesStatisticsValidator(final InterfaceStatisticsManager statisticsManager) { - checkNotNull(statisticsManager, "Statistics Collection Manager should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Statistics dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.CreateValidationFailedException { - // there is nothing to validate yet - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Statistics dataBefore, - @Nonnull final Statistics dataAfter, @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.UpdateValidationFailedException { - // there is nothing to validate yet - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Statistics dataBefore, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.DeleteValidationFailedException { - // there is nothing to validate yet - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/L2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/L2Customizer.java deleted file mode 100644 index 7f91f8183..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/L2Customizer.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.future.FutureJVppCore; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class L2Customizer extends FutureJVppCustomizer implements WriterCustomizer { - - private static final Logger LOG = LoggerFactory.getLogger(L2Customizer.class); - private final NamingContext interfaceContext; - private final InterconnectionWriteUtils icWriteUtils; - - public L2Customizer(final FutureJVppCore vppApi, final NamingContext interfaceContext, - final NamingContext bridgeDomainContext) { - super(vppApi); - this.interfaceContext = interfaceContext; - this.icWriteUtils = new InterconnectionWriteUtils(vppApi, interfaceContext, bridgeDomainContext); - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - - final String ifcName = id.firstKeyOf(Interface.class).getName(); - final int swIfc = interfaceContext.getIndex(ifcName, writeContext.getMappingContext()); - setL2(id, swIfc, ifcName, dataAfter, writeContext); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataBefore, - @Nonnull final L2 dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - - final String ifcName = id.firstKeyOf(Interface.class).getName(); - final int swIfc = interfaceContext.getIndex(ifcName, writeContext.getMappingContext()); - // No update, again calling set - setL2(id, swIfc, ifcName, dataAfter, writeContext); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataBefore, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - final String ifcName = id.firstKeyOf(Interface.class).getName(); - final int swIfc = interfaceContext.getIndex(ifcName, writeContext.getMappingContext()); - deleteL2(id, swIfc, ifcName, dataBefore, writeContext); - } - - private void setL2(final InstanceIdentifier id, final int swIfIndex, final String ifcName, final L2 l2, - final WriteContext writeContext) - throws WriteFailedException { - LOG.debug("Setting L2 for interface: {}", ifcName); - // Nothing besides interconnection here - icWriteUtils.setInterconnection(id, swIfIndex, ifcName, l2.getInterconnection(), writeContext); - } - - private void deleteL2(final InstanceIdentifier id, final int swIfIndex, final String ifcName, final L2 l2Before, - final WriteContext writeContext) - throws WriteFailedException { - LOG.debug("Deleting L2 for interface: {}", ifcName); - // Nothing besides interconnection here - icWriteUtils.deleteInterconnection(id, swIfIndex, ifcName, l2Before.getInterconnection(), writeContext); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/L2Validator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/L2Validator.java deleted file mode 100644 index 3c59bd98d..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/L2Validator.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class L2Validator implements Validator { - - public L2Validator(final NamingContext interfaceContext, - final NamingContext bridgeDomainContext) { - checkNotNull(interfaceContext, "interfaceContext should not be null"); - checkNotNull(bridgeDomainContext, "bridgeDomainContext should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.CreateValidationFailedException { - // there is nothing to validate yet - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataBefore, - @Nonnull final L2 dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.UpdateValidationFailedException { - // there is nothing to validate yet - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataBefore, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.DeleteValidationFailedException { - // there is nothing to validate yet - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/LoopbackCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/LoopbackCustomizer.java deleted file mode 100644 index a4cd4b0d4..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/LoopbackCustomizer.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.MacTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.CreateLoopback; -import io.fd.jvpp.core.dto.CreateLoopbackReply; -import io.fd.jvpp.core.dto.DeleteLoopback; -import io.fd.jvpp.core.future.FutureJVppCore; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Loopback; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class LoopbackCustomizer extends AbstractInterfaceTypeCustomizer - implements MacTranslator, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(LoopbackCustomizer.class); - private final NamingContext interfaceContext; - - public LoopbackCustomizer(final FutureJVppCore vppApi, final NamingContext interfaceContext) { - super(vppApi); - this.interfaceContext = interfaceContext; - } - - @Override - protected Class getExpectedInterfaceType() { - return org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.Loopback.class; - } - - @Override - protected final void writeInterface(@Nonnull final InstanceIdentifier id, @Nonnull final Loopback dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String ifcName = id.firstKeyOf(Interface.class).getName(); - createLoopback(id, ifcName, dataAfter, writeContext); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final Loopback dataBefore, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String ifcName = id.firstKeyOf(Interface.class).getName(); - - final int index; - try { - index = interfaceContext.getIndex(ifcName, writeContext.getMappingContext()); - } catch (IllegalArgumentException e) { - throw new WriteFailedException.DeleteFailedException(id, e); - } - - deleteLoopback(id, ifcName, index, dataBefore, writeContext); - } - - private void createLoopback(final InstanceIdentifier id, final String swIfName, final Loopback loopback, - final WriteContext writeContext) throws WriteFailedException { - LOG.debug("Setting loopback interface: {}. Loopback: {}", swIfName, loopback); - - final CreateLoopback createLoopback = new CreateLoopback(); - if (loopback.getMac() != null) { - createLoopback.macAddress = parseMac(loopback.getMac().getValue()); - } - final CreateLoopbackReply reply = - getReplyForCreate(getFutureJVpp().createLoopback(createLoopback).toCompletableFuture(), id, loopback); - - LOG.debug("Loopback set successfully for: {}, loopback: {}", swIfName, loopback); - // Add new interface to our interface context - interfaceContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); - } - - private void deleteLoopback(final InstanceIdentifier id, final String swIfName, final int index, - final Loopback dataBefore, final WriteContext writeContext) - throws WriteFailedException { - LOG.debug("Deleting loopback interface: {}. Loopback: {}", swIfName, dataBefore); - final DeleteLoopback deleteLoopback = new DeleteLoopback(); - deleteLoopback.swIfIndex = index; - getReplyForDelete(getFutureJVpp().deleteLoopback(deleteLoopback).toCompletableFuture(), id); - LOG.debug("Loopback deleted successfully for: {}, loopback: {}", swIfName, dataBefore); - // Remove deleted interface from interface context - interfaceContext.removeName(swIfName, writeContext.getMappingContext()); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/LoopbackValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/LoopbackValidator.java deleted file mode 100644 index 57f1eb108..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/LoopbackValidator.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Loopback; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class LoopbackValidator implements Validator { - - public LoopbackValidator(final NamingContext interfaceContext) { - checkNotNull(interfaceContext, "interfaceContext should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Loopback dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.CreateValidationFailedException { - // there is nothing to validate yet - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Loopback dataBefore, - @Nonnull final Loopback dataAfter, @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.UpdateValidationFailedException { - // there is nothing to validate yet - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Loopback dataBefore, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.DeleteValidationFailedException { - // there is nothing to validate yet - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RewriteCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RewriteCustomizer.java deleted file mode 100644 index 169dd9958..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RewriteCustomizer.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.common.translate.util.TagRewriteOperation; -import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.L2InterfaceVlanTagRewrite; -import io.fd.jvpp.core.dto.L2InterfaceVlanTagRewriteReply; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.List; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319._802dot1q; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.Rewrite; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.RewriteBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.tag.rewrite.PushTags; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Writer Customizer responsible for vlan tag rewrite.
Sends {@code l2_interface_vlan_tag_rewrite} message to - * VPP.
Equivalent of invoking {@code vppctl set interface l2 tag-rewrite} command. - */ -public class RewriteCustomizer extends FutureJVppCustomizer - implements WriterCustomizer, ByteDataTranslator, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(RewriteCustomizer.class); - private final NamingContext interfaceContext; - - public RewriteCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore); - this.interfaceContext = interfaceContext; - } - - @Override - public void writeCurrentAttributes(final InstanceIdentifier id, final Rewrite dataAfter, - final WriteContext writeContext) - throws WriteFailedException { - final String subifName = getSubInterfaceName(id); - setTagRewrite(id, subifName, dataAfter, writeContext); - } - - private static String getSubInterfaceName(final InstanceIdentifier id) { - return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), - Math.toIntExact(id.firstKeyOf(SubInterface.class).getIdentifier())); - } - - private void setTagRewrite(final InstanceIdentifier id, final String ifname, final Rewrite rewrite, - final WriteContext writeContext) throws WriteFailedException { - final int swIfIndex = interfaceContext.getIndex(ifname, writeContext.getMappingContext()); - LOG.debug("Setting tag rewrite for interface {}(id=): {}", ifname, swIfIndex, rewrite); - - final CompletionStage replyCompletionStage = - getFutureJVpp().l2InterfaceVlanTagRewrite(getTagRewriteRequest(swIfIndex, rewrite)); - - getReplyForWrite(replyCompletionStage.toCompletableFuture(), id); - LOG.debug("Tag rewrite for interface {}(id=) set successfully: {}", ifname, swIfIndex, rewrite); - } - - private L2InterfaceVlanTagRewrite getTagRewriteRequest(final int swIfIndex, final Rewrite rewrite) { - final L2InterfaceVlanTagRewrite request = new L2InterfaceVlanTagRewrite(); - request.swIfIndex = swIfIndex; - request.pushDot1Q = booleanToByte(_802dot1q.class == rewrite.getVlanType()); - - final List pushTags = rewrite.getPushTags(); - final Short popTags = rewrite.getPopTags(); - - final int numberOfTagsToPop = popTags == null - ? 0 - : popTags.intValue(); - final int numberOfTagsToPush = pushTags == null - ? 0 - : pushTags.size(); - - request.vtrOp = TagRewriteOperation.get(numberOfTagsToPop, numberOfTagsToPush).ordinal(); - - if (numberOfTagsToPush > 0) { - for (final PushTags tag : pushTags) { - if (tag.getIndex() == 0) { - request.tag1 = tag.getDot1qTag().getVlanId().getValue(); - } else { - request.tag2 = tag.getDot1qTag().getVlanId().getValue(); - } - } - } - - LOG.debug("Generated tag rewrite request: {}", request); - return request; - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Rewrite dataBefore, - @Nonnull final Rewrite dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String subifName = getSubInterfaceName(id); - setTagRewrite(id, subifName, dataAfter, writeContext); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Rewrite dataBefore, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String subifName = getSubInterfaceName(id); - - LOG.debug("Disabling tag rewrite for interface {}", subifName); - final Rewrite rewrite = new RewriteBuilder().build(); // rewrite without push and pops will cause delete - setTagRewrite(id, subifName, rewrite, writeContext); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RewriteValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RewriteValidator.java deleted file mode 100644 index e867a10f4..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RewriteValidator.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.Rewrite; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class RewriteValidator implements Validator { - - public RewriteValidator(@Nonnull final NamingContext interfaceContext) { - checkNotNull(interfaceContext, "interfaceContext should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Rewrite dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.CreateValidationFailedException { - // there is nothing to validate yet - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Rewrite dataBefore, - @Nonnull final Rewrite dataAfter, @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.UpdateValidationFailedException { - // there is nothing to validate yet - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Rewrite dataBefore, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.DeleteValidationFailedException { - // there is nothing to validate yet - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RoutingCustomizer.java deleted file mode 100644 index 4566e4925..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RoutingCustomizer.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkArgument; - -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.SwInterfaceSetTable; -import io.fd.jvpp.core.dto.SwInterfaceSetTableReply; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.RoutingBaseAttributes; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -abstract class RoutingCustomizer extends FutureJVppCustomizer implements JvppReplyConsumer, ByteDataTranslator { - private static final Logger LOG = LoggerFactory.getLogger(RoutingCustomizer.class); - protected final NamingContext interfaceContext; - - protected RoutingCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore); - this.interfaceContext = interfaceContext; - } - - protected void setRouting(@Nonnull final InstanceIdentifier id, - @Nonnull final String name, - @Nonnull final RoutingBaseAttributes rt, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - final int swIfc = interfaceContext.getIndex(name, writeContext.getMappingContext()); - LOG.debug("Setting routing for interface: {}, {}. Routing: {}", name, swIfc, rt); - checkArgument(rt.getIpv4VrfId() != null || rt.getIpv6VrfId() != null, "No vrf-id given"); - - setVrfId(id, swIfc, rt.getIpv4VrfId(), false); - setVrfId(id, swIfc, rt.getIpv6VrfId(), true); - - LOG.debug("Routing set successfully for interface: {}, {}, routing: {}", name, swIfc, rt); - } - - private void setVrfId(final InstanceIdentifier id, final int swIfc, - final VniReference vniRef, boolean isIp6) - throws WriteFailedException { - if (vniRef == null || vniRef.getValue() == null) { - return; - } - final CompletionStage cs = getFutureJVpp().swInterfaceSetTable( - getInterfaceSetTableRequest(swIfc, booleanToByte(isIp6), vniRef.getValue().intValue())); - getReplyForWrite(cs.toCompletableFuture(), id); - } - - /** - * In this case, there is no such thing as delete routing,only thing that can be done is to disable it by setting - * default value 0 - */ - void disableRouting(final InstanceIdentifier id, final String name, - final WriteContext writeContext) throws WriteFailedException { - final int swIfc = interfaceContext.getIndex(name, writeContext.getMappingContext()); - LOG.debug("Disabling routing for interface: {}, {}.", name, swIfc); - - getReplyForDelete(getFutureJVpp() - .swInterfaceSetTable(getInterfaceSetTableRequest(swIfc, (byte) 0, 0)).toCompletableFuture(), id); - LOG.debug("Routing for interface: {}, {} successfully disabled", name, swIfc); - - } - - private SwInterfaceSetTable getInterfaceSetTableRequest(final int swIfc, final byte isIpv6, final int vrfId) { - final SwInterfaceSetTable swInterfaceSetTable = new SwInterfaceSetTable(); - swInterfaceSetTable.isIpv6 = isIpv6; - swInterfaceSetTable.swIfIndex = swIfc; - swInterfaceSetTable.vrfId = vrfId; - return swInterfaceSetTable; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceCustomizer.java deleted file mode 100644 index 881447543..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceCustomizer.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkState; -import static io.fd.hc2vpp.v3po.util.SubInterfaceUtils.getNumberOfTags; -import static io.fd.hc2vpp.v3po.util.SubInterfaceUtils.getSubInterfaceName; - -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.CreateSubif; -import io.fd.jvpp.core.dto.CreateSubifReply; -import io.fd.jvpp.core.dto.SwInterfaceSetFlags; -import io.fd.jvpp.core.dto.SwInterfaceSetFlagsReply; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319._802dot1ad; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.MatchType; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.Default; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.VlanTagged; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.tags.Tag; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.CVlan; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qVlanId; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.SVlan; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Writer Customizer responsible for sub interface creation.
Sends {@code create_subif} message to VPP.
- * Equivalent of invoking {@code vppclt create subif} command. - */ -public class SubInterfaceCustomizer extends FutureJVppCustomizer - implements ListWriterCustomizer, ByteDataTranslator, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceCustomizer.class); - private final NamingContext interfaceContext; - - public SubInterfaceCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore); - this.interfaceContext = interfaceContext; - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final SubInterface dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String superIfName = id.firstKeyOf(Interface.class).getName(); - createSubInterface(id, superIfName, dataAfter, writeContext); - } - - private void createSubInterface(final InstanceIdentifier id, @Nonnull final String superIfName, - @Nonnull final SubInterface subInterface, final WriteContext writeContext) - throws WriteFailedException { - final int superIfIndex = interfaceContext.getIndex(superIfName, writeContext.getMappingContext()); - final CompletionStage createSubifReplyCompletionStage = - getFutureJVpp().createSubif(getCreateSubifRequest(subInterface, superIfIndex)); - - final CreateSubifReply reply = - getReplyForCreate(createSubifReplyCompletionStage.toCompletableFuture(), id, subInterface); - - setInterfaceState(id, reply.swIfIndex, booleanToByte(subInterface.isEnabled())); - interfaceContext.addName(reply.swIfIndex, - getSubInterfaceName(superIfName, Math.toIntExact(subInterface.getIdentifier())), - writeContext.getMappingContext()); - LOG.debug("Sub interface created successfully for: {}, subInterface: {}", superIfName, subInterface); - } - - private CreateSubif getCreateSubifRequest(@Nonnull final SubInterface subInterface, final int swIfIndex) { - // TODO HONEYCOMB-183 add validation - CreateSubif request = new CreateSubif(); - request.subId = Math.toIntExact(subInterface.getIdentifier().intValue()); - request.swIfIndex = swIfIndex; - - final int numberOfTags = getNumberOfTags(subInterface.getTags()); - switch (numberOfTags) { - case 0: - request.noTags = 1; - break; - case 1: - request.oneTag = 1; - break; - case 2: - request.twoTags = 1; - break; - } - request.dot1Ad = booleanToByte(_802dot1ad.class == subInterface.getVlanType()); - - // TODO HONEYCOMB-183 match should be mandatory - final MatchType matchType = subInterface.getMatch().getMatchType(); - request.exactMatch = booleanToByte( - matchType instanceof VlanTagged - && ((VlanTagged) matchType).getVlanTagged().isMatchExactTags() - ); - request.defaultSub = booleanToByte(matchType instanceof Default); - if (numberOfTags > 0) { - for (final Tag tag : subInterface.getTags().getTag()) { - if (tag.getIndex() == 0) { - setOuterTag(request, tag); - } else if (tag.getIndex() == 1) { - setInnerTag(request, tag); - } - } - } - return request; - } - - private void setOuterTag(final CreateSubif request, final Tag outerTag) { - checkState(SVlan.class == outerTag.getDot1qTag().getTagType(), "Service Tag expected at index 0"); - final Dot1qTag.VlanId vlanId = outerTag.getDot1qTag().getVlanId(); - - request.outerVlanId = dot1qVlanIdToShort(vlanId.getDot1qVlanId()); - request.outerVlanIdAny = booleanToByte(Dot1qTag.VlanId.Enumeration.Any.equals(vlanId.getEnumeration())); - } - - private void setInnerTag(final CreateSubif request, final Tag innerTag) { - checkState(CVlan.class == innerTag.getDot1qTag().getTagType(), "Customer Tag expected at index 1"); - final Dot1qTag.VlanId vlanId = innerTag.getDot1qTag().getVlanId(); - - request.innerVlanId = dot1qVlanIdToShort(vlanId.getDot1qVlanId()); - request.innerVlanIdAny = booleanToByte(Dot1qTag.VlanId.Enumeration.Any.equals(vlanId.getEnumeration())); - } - - private static short dot1qVlanIdToShort(@Nullable Dot1qVlanId dot1qVlanId) { - if (dot1qVlanId == null) { - return 0; // tell VPP that optional argument is missing - } else { - return dot1qVlanId.getValue().shortValue(); - } - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final SubInterface dataBefore, @Nonnull final SubInterface dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String subIfaceName = getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), - Math.toIntExact(dataAfter.getIdentifier())); - setInterfaceState(id, interfaceContext.getIndex(subIfaceName, writeContext.getMappingContext()), - booleanToByte(dataAfter.isEnabled())); - } - - private void setInterfaceState(final InstanceIdentifier id, final int swIfIndex, final byte enabled) - throws WriteFailedException { - final SwInterfaceSetFlags swInterfaceSetFlags = new SwInterfaceSetFlags(); - swInterfaceSetFlags.swIfIndex = swIfIndex; - swInterfaceSetFlags.adminUpDown = enabled; - - final CompletionStage swInterfaceSetFlagsReplyFuture = - getFutureJVpp().swInterfaceSetFlags(swInterfaceSetFlags); - - LOG.debug("Updating interface state for interface if={}, enabled: {}", swIfIndex, enabled); - - SwInterfaceSetFlagsReply reply = - getReplyForWrite(swInterfaceSetFlagsReplyFuture.toCompletableFuture(), id); - LOG.debug("Interface state updated successfully for interface index: {}, enabled: {}, ctxId: {}", - swIfIndex, enabled, reply.context); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final SubInterface dataBefore, - @Nonnull final WriteContext writeContext) - throws WriteFailedException.DeleteFailedException { - throw new UnsupportedOperationException("Sub interface delete is not supported"); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceL2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceL2Customizer.java deleted file mode 100644 index 7e3eab98c..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceL2Customizer.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.future.FutureJVppCore; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Customizer for writing vlan sub interface l2 configuration - */ -public class SubInterfaceL2Customizer extends FutureJVppCustomizer implements WriterCustomizer { - - private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceL2Customizer.class); - private final NamingContext interfaceContext; - private final InterconnectionWriteUtils icWriterUtils; - - public SubInterfaceL2Customizer(final FutureJVppCore vppApi, final NamingContext interfaceContext, - final NamingContext bridgeDomainContext) { - super(vppApi); - this.interfaceContext = interfaceContext; - this.icWriterUtils = new InterconnectionWriteUtils(vppApi, interfaceContext, bridgeDomainContext); - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String subInterfaceName = getSubInterfaceName(id); - final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, writeContext.getMappingContext()); - setL2(id, subInterfaceIndex, subInterfaceName, dataAfter, writeContext); - } - - private String getSubInterfaceName(@Nonnull final InstanceIdentifier id) { - final InterfaceKey parentInterfacekey = id.firstKeyOf(Interface.class); - final SubInterfaceKey subInterfacekey = id.firstKeyOf(SubInterface.class); - return SubInterfaceUtils - .getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue()); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataBefore, - @Nonnull final L2 dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - - final String subInterfaceName = getSubInterfaceName(id); - final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, writeContext.getMappingContext()); - // Setting L2 to new values - setL2(id, subInterfaceIndex, subInterfaceName, dataAfter, writeContext); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataBefore, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - final String subInterfaceName = getSubInterfaceName(id); - final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, writeContext.getMappingContext()); - deleteL2(id, subInterfaceIndex, subInterfaceName, dataBefore, writeContext); - } - - private void setL2(final InstanceIdentifier id, final int swIfIndex, final String ifcName, final L2 l2, - final WriteContext writeContext) - throws WriteFailedException { - LOG.debug("Setting L2 for sub-interface: {}", ifcName); - icWriterUtils.setInterconnection(id, swIfIndex, ifcName, l2.getInterconnection(), writeContext); - } - - private void deleteL2(final InstanceIdentifier id, final int swIfIndex, final String ifcName, final L2 l2Before, - final WriteContext writeContext) - throws WriteFailedException { - LOG.debug("Deleting L2 for sub-interface: {}", ifcName); - icWriterUtils.deleteInterconnection(id, swIfIndex, ifcName, l2Before.getInterconnection(), writeContext); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceL2Validator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceL2Validator.java deleted file mode 100644 index 3a2ed5d0c..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceL2Validator.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceL2Validator implements Validator { - - public SubInterfaceL2Validator(final NamingContext interfaceContext, - final NamingContext bridgeDomainContext) { - checkNotNull(interfaceContext, "interfaceContext should not be null"); - checkNotNull(bridgeDomainContext, "bridgeDomainContext should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.CreateValidationFailedException { - // there is nothing to validate yet - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataBefore, - @Nonnull final L2 dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.UpdateValidationFailedException { - // there is nothing to validate yet - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataBefore, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.DeleteValidationFailedException { - // there is nothing to validate yet - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizer.java deleted file mode 100644 index 951944a57..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizer.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static io.fd.hc2vpp.v3po.util.SubInterfaceUtils.subInterfaceFullNameConfig; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.future.FutureJVppCore; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.Routing; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceRoutingCustomizer extends RoutingCustomizer implements WriterCustomizer { - - public SubInterfaceRoutingCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore, interfaceContext); - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier instanceIdentifier, - @Nonnull final Routing routing, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - setRouting(instanceIdentifier, subInterfaceFullNameConfig(instanceIdentifier), routing, writeContext); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier instanceIdentifier, - @Nonnull final Routing routing, @Nonnull final Routing d1, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - setRouting(instanceIdentifier, subInterfaceFullNameConfig(instanceIdentifier), routing, writeContext); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier instanceIdentifier, - @Nonnull final Routing routing, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - disableRouting(instanceIdentifier, subInterfaceFullNameConfig(instanceIdentifier), writeContext); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingValidator.java deleted file mode 100644 index 85b864d14..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingValidator.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import java.util.List; -import java.util.Optional; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.Ipv4; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.Ipv6; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.Routing; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceRoutingValidator implements Validator { - - public SubInterfaceRoutingValidator(@Nonnull final NamingContext interfaceContext) { - checkNotNull(interfaceContext, "interfaceContext should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Routing dataAfter, - @Nonnull final WriteContext writeContext) - throws CreateValidationFailedException { - try { - checkInterfaceAddressConf(id, writeContext, true); - } catch (Exception e) { - throw new CreateValidationFailedException(id, dataAfter, e); - } - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Routing dataBefore, - @Nonnull final Routing dataAfter, @Nonnull final WriteContext writeContext) - throws UpdateValidationFailedException { - try { - checkInterfaceAddressConf(id, writeContext, true); - } catch (Exception e) { - throw new UpdateValidationFailedException(id, dataBefore, dataAfter, e); - } - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Routing dataBefore, - @Nonnull final WriteContext writeContext) - throws DeleteValidationFailedException { - try { - checkInterfaceAddressConf(id, writeContext, false); - } catch (Exception e) { - throw new DeleteValidationFailedException(id, e); - } - } - - private void checkInterfaceAddressConf(@Nonnull final InstanceIdentifier id, - @Nonnull final WriteContext ctx, - boolean checkBefore) { - checkState(isAddressNotPresentForSubInterface(id, ctx, checkBefore), - "Cannot change routing configuration, if address is present for sub-interface"); - } - - /** - * Returns true if interface does not have v4/v6 addresses configured - */ - private boolean isAddressNotPresentForSubInterface(@Nonnull final InstanceIdentifier id, - @Nonnull final WriteContext ctx, - boolean checkBefore) { - final Optional subInterfaceData = checkBefore - ? - ctx.readBefore(RWUtils.cutId(id, SubInterface.class)) - : - ctx.readAfter(RWUtils.cutId(id, SubInterface.class)); - - if (subInterfaceData.isPresent()) { - final SubInterface subInterface = subInterfaceData.get(); - - final boolean v4NotPresent = - java.util.Optional.ofNullable(subInterface.getIpv4()).map(Ipv4::getAddress).map(List::isEmpty) - .orElse(true); - - final boolean v6NotPresent = - java.util.Optional.ofNullable(subInterface.getIpv6()).map(Ipv6::getAddress).map(List::isEmpty) - .orElse(true); - return v4NotPresent && v6NotPresent; - } - return true; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceUnnumberedCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceUnnumberedCustomizer.java deleted file mode 100644 index 58614060f..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceUnnumberedCustomizer.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static io.fd.hc2vpp.v3po.util.SubInterfaceUtils.subInterfaceFullNameConfig; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.future.FutureJVppCore; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public final class SubInterfaceUnnumberedCustomizer extends AbstractUnnumberedCustomizer { - - public SubInterfaceUnnumberedCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore, interfaceContext); - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Unnumbered dataAfter, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - setUnnumbered(id, subInterfaceFullNameConfig(id), dataAfter, writeContext); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Unnumbered dataBefore, @Nonnull final Unnumbered dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - setUnnumbered(id, subInterfaceFullNameConfig(id), dataAfter, writeContext); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Unnumbered dataBefore, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - disableUnnumbered(id, subInterfaceFullNameConfig(id), dataBefore, writeContext); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceUnnumberedValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceUnnumberedValidator.java deleted file mode 100644 index 8cc565c5a..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceUnnumberedValidator.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceUnnumberedValidator implements Validator { - - public SubInterfaceUnnumberedValidator(final NamingContext interfaceContext) { - checkNotNull(interfaceContext, "interfaceContext should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Unnumbered dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.CreateValidationFailedException { - checkNotNull(dataAfter.getUse()); - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Unnumbered dataBefore, - @Nonnull final Unnumbered dataAfter, @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.UpdateValidationFailedException { - checkNotNull(dataAfter.getUse()); - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Unnumbered dataBefore, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.DeleteValidationFailedException { - checkNotNull(dataBefore.getUse()); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceValidator.java deleted file mode 100644 index 0f8a86232..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceValidator.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceValidator implements Validator { - - public SubInterfaceValidator(@Nonnull final NamingContext interfaceContext) { - checkNotNull(interfaceContext, "interfaceContext should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final SubInterface dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.CreateValidationFailedException { - try { - checkSubInterface(dataAfter); - } catch (Exception e) { - throw new DataValidationFailedException.CreateValidationFailedException(id, dataAfter, e); - } - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, - @Nonnull final SubInterface dataBefore, - @Nonnull final SubInterface dataAfter, @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.UpdateValidationFailedException { - try { - checkSubInterface(dataAfter); - } catch (Exception e) { - throw new DataValidationFailedException.UpdateValidationFailedException(id, dataBefore, dataAfter, e); - } - } - - private void checkSubInterface(final SubInterface data) { - checkNotNull(data.getIdentifier(), "Identifier cannot be null"); - checkNotNull(data.getMatch(), "Match cannot be null"); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/TapV2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/TapV2Customizer.java deleted file mode 100644 index ef2902a8c..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/TapV2Customizer.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (c) 2018 Pantheon Technologies and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static java.nio.charset.StandardCharsets.UTF_8; - -import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; -import io.fd.hc2vpp.common.translate.util.Ipv4Translator; -import io.fd.hc2vpp.common.translate.util.Ipv6Translator; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.MacTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.TapCreateV2; -import io.fd.jvpp.core.dto.TapCreateV2Reply; -import io.fd.jvpp.core.dto.TapDeleteV2; -import io.fd.jvpp.core.dto.TapDeleteV2Reply; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.nio.charset.StandardCharsets; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class TapV2Customizer extends AbstractInterfaceTypeCustomizer - implements MacTranslator, Ipv4Translator, Ipv6Translator, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(TapV2Customizer.class); - private final NamingContext interfaceContext; - - public TapV2Customizer(final FutureJVppCore vppApi, final NamingContext interfaceContext) { - super(vppApi); - this.interfaceContext = interfaceContext; - } - - @Override - protected Class getExpectedInterfaceType() { - return org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.TapV2.class; - } - - @Override - protected final void writeInterface(@Nonnull final InstanceIdentifier id, @Nonnull final TapV2 dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String ifcName = id.firstKeyOf(Interface.class).getName(); - createTapV2(id, ifcName, dataAfter, writeContext); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final TapV2 dataBefore, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String ifcName = id.firstKeyOf(Interface.class).getName(); - - final int index; - try { - index = interfaceContext.getIndex(ifcName, writeContext.getMappingContext()); - } catch (IllegalArgumentException e) { - throw new WriteFailedException.DeleteFailedException(id, e); - } - - deleteTapV2(id, ifcName, index, dataBefore, writeContext); - } - - private void createTapV2(final InstanceIdentifier id, final String swIfName, final TapV2 tapv2, - final WriteContext writeContext) throws WriteFailedException { - LOG.debug("Setting TapV2 interface: {}. TapV2: {}", swIfName, tapv2); - final CompletionStage tapV2CreateFuture = getFutureJVpp() - .tapCreateV2(getTapV2CreateRequest(tapv2)); - final TapCreateV2Reply reply = getReplyForCreate(tapV2CreateFuture.toCompletableFuture(), id, tapv2); - LOG.debug("TapV2 set successfully for: {}, TapV2: {}", swIfName, tapv2); - // Add new interface to our interface context - interfaceContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); - } - - private void deleteTapV2(final InstanceIdentifier id, final String swIfName, final int index, - final TapV2 dataBefore, final WriteContext writeContext) - throws WriteFailedException { - LOG.debug("Deleting TapV2 interface: {}. TapV2: {}", swIfName, dataBefore); - final CompletionStage vxlanAddDelTunnelReplyCompletionStage = - getFutureJVpp().tapDeleteV2(getTapV2DeleteRequest(index)); - getReplyForDelete(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); - LOG.debug("TapV2 deleted successfully for: {}, TapV2: {}", swIfName, dataBefore); - // Remove deleted interface from interface context - interfaceContext.removeName(swIfName, writeContext.getMappingContext()); - } - - private TapCreateV2 getTapV2CreateRequest(final TapV2 tapv2) { - final TapCreateV2 tapConnect = new TapCreateV2(); - final PhysAddress mac = tapv2.getMac(); - if (mac == null) { - tapConnect.useRandomMac = 1; - tapConnect.macAddress = new byte[6]; - } else { - tapConnect.useRandomMac = 0; - tapConnect.macAddress = parseMac(mac.getValue()); - } - - final Integer rxRingSz = tapv2.getRxRingSize(); - if (rxRingSz != null) { - tapConnect.rxRingSz = rxRingSz.shortValue(); - } - - final Integer txRingSz = tapv2.getTxRingSize(); - if (txRingSz != null) { - tapConnect.txRingSz = txRingSz.shortValue(); - } - - final String tag = tapv2.getTag(); - if (tag != null) { - tapConnect.tag = tag.getBytes(StandardCharsets.US_ASCII); - } - - setHostProperties(tapConnect, tapv2); - return tapConnect; - } - - private TapDeleteV2 getTapV2DeleteRequest(final int swIndex) { - final TapDeleteV2 tapDeleteV2 = new TapDeleteV2(); - tapDeleteV2.swIfIndex = swIndex; - return tapDeleteV2; - } - - private void setHostProperties(TapCreateV2 tapConnect, TapV2 tapv2) { - - final PhysAddress hostMacAddress = tapv2.getHostMac(); - if (hostMacAddress != null) { - tapConnect.hostMacAddr = parseMac(hostMacAddress.getValue()); - tapConnect.hostMacAddrSet = 1; - } else { - tapConnect.hostMacAddr = new byte[6]; - tapConnect.hostMacAddrSet = 0; - } - - final String hostIfName = tapv2.getHostInterfaceName(); - if (hostIfName != null) { - tapConnect.hostIfName = hostIfName.getBytes(UTF_8); - tapConnect.hostIfNameSet = 1; - } else { - tapConnect.hostIfNameSet = 0; - tapConnect.hostIfName = new byte[64]; - } - - final String hostBridge = tapv2.getHostBridge(); - if (hostBridge != null) { - tapConnect.hostBridgeSet = 1; - tapConnect.hostBridge = hostBridge.getBytes(UTF_8); - } else { - tapConnect.hostBridgeSet = 0; - tapConnect.hostBridge = new byte[64]; - } - - final String hostNamespace = tapv2.getHostNamespace(); - if (hostNamespace != null) { - tapConnect.hostNamespaceSet = 1; - tapConnect.hostNamespace = hostNamespace.getBytes(UTF_8); - } else { - tapConnect.hostNamespaceSet = 0; - tapConnect.hostNamespace = new byte[64]; - } - - final Ipv4Prefix hostIpv4address = tapv2.getHostIpv4Address(); - if (hostIpv4address != null) { - tapConnect.hostIp4Addr = ipv4AddressPrefixToArray(hostIpv4address); - tapConnect.hostIp4AddrSet = 1; - tapConnect.hostIp4PrefixLen = extractPrefix(hostIpv4address); - } else { - tapConnect.hostIp4Addr = new byte[4]; - tapConnect.hostIp4AddrSet = 0; - tapConnect.hostIp4PrefixLen = 0; - } - - final Ipv4Address hostIpv4GW = tapv2.getHostIpv4Gateway(); - if (hostIpv4GW != null) { - tapConnect.hostIp4Gw = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(hostIpv4GW)); - tapConnect.hostIp4GwSet = 1; - } else { - tapConnect.hostIp4Gw = new byte[4]; - tapConnect.hostIp4GwSet = 0; - } - - final Ipv6Prefix hostIpv6address = tapv2.getHostIpv6Address(); - if (hostIpv6address != null) { - tapConnect.hostIp6Addr = ipv6AddressPrefixToArray(hostIpv6address); - tapConnect.hostIp6AddrSet = 1; - tapConnect.hostIp6PrefixLen = extractPrefix(hostIpv6address); - } else { - tapConnect.hostIp6Addr = new byte[16]; - tapConnect.hostIp6AddrSet = 0; - tapConnect.hostIp6PrefixLen = 0; - } - - final Ipv6Address hostIpv6GW = tapv2.getHostIpv6Gateway(); - if (hostIpv6GW != null) { - tapConnect.hostIp6Gw = ipv6AddressNoZoneToArray(hostIpv6GW); - tapConnect.hostIp6GwSet = 1; - } else { - tapConnect.hostIp6Gw = new byte[16]; - tapConnect.hostIp6GwSet = 0; - } - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/TapV2Validator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/TapV2Validator.java deleted file mode 100644 index 0d3c3efa6..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/TapV2Validator.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class TapV2Validator implements Validator { - - public TapV2Validator(final NamingContext interfaceContext) { - checkNotNull(interfaceContext, "interfaceContext should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final TapV2 dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.CreateValidationFailedException { - // there is nothing to validate yet - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final TapV2 dataBefore, - @Nonnull final TapV2 dataAfter, @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.UpdateValidationFailedException { - // there is nothing to validate yet - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final TapV2 dataBefore, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.DeleteValidationFailedException { - // there is nothing to validate yet - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VhostUserCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VhostUserCustomizer.java deleted file mode 100644 index 61ce5468c..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VhostUserCustomizer.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.CreateVhostUserIf; -import io.fd.jvpp.core.dto.CreateVhostUserIfReply; -import io.fd.jvpp.core.dto.DeleteVhostUserIf; -import io.fd.jvpp.core.dto.DeleteVhostUserIfReply; -import io.fd.jvpp.core.dto.ModifyVhostUserIf; -import io.fd.jvpp.core.dto.ModifyVhostUserIfReply; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.nio.charset.StandardCharsets; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUserRole; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUser; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Writer Customizer responsible for passing vhost user interface CRD operations to VPP - */ -public class VhostUserCustomizer extends AbstractInterfaceTypeCustomizer - implements ByteDataTranslator, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(VhostUserCustomizer.class); - private final NamingContext interfaceContext; - - public VhostUserCustomizer(@Nonnull final FutureJVppCore vppApi, @Nonnull final NamingContext interfaceContext) { - super(vppApi); - this.interfaceContext = interfaceContext; - } - - @Override - protected Class getExpectedInterfaceType() { - return org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUser.class; - } - - @Override - protected final void writeInterface(@Nonnull final InstanceIdentifier id, - @Nonnull final VhostUser dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String swIfName = id.firstKeyOf(Interface.class).getName(); - createVhostUserIf(id, swIfName, dataAfter, writeContext); - } - - private void createVhostUserIf(final InstanceIdentifier id, final String swIfName, - final VhostUser vhostUser, final WriteContext writeContext) - throws WriteFailedException { - LOG.debug("Creating vhost user interface: name={}, vhostUser={}", swIfName, vhostUser); - - final CompletionStage createVhostUserIfReplyCompletionStage = - getFutureJVpp().createVhostUserIf(getCreateVhostUserIfRequest(vhostUser)); - final CreateVhostUserIfReply reply = - getReplyForCreate(createVhostUserIfReplyCompletionStage.toCompletableFuture(), id, vhostUser); - LOG.debug("Vhost user interface created successfully for: {}, vhostUser: {}", swIfName, vhostUser); - // Add new interface to our interface context - interfaceContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); - } - - private CreateVhostUserIf getCreateVhostUserIfRequest(final VhostUser vhostUser) { - CreateVhostUserIf request = new CreateVhostUserIf(); - request.isServer = booleanToByte(VhostUserRole.Server.equals(vhostUser.getRole())); - request.sockFilename = vhostUser.getSocket().getBytes(); - final Long deviceInstance = vhostUser.getDeviceInstance(); - if (deviceInstance == null) { - request.renumber = 0; - } else { - request.renumber = 1; - request.customDevInstance = Math.toIntExact(deviceInstance); - } - final String tag = vhostUser.getTag(); - if (tag != null) { - request.tag = tag.getBytes(StandardCharsets.US_ASCII); - } - request.useCustomMac = 0; - request.macAddress = new byte[]{}; - return request; - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final VhostUser dataBefore, @Nonnull final VhostUser dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String swIfName = id.firstKeyOf(Interface.class).getName(); - modifyVhostUserIf(id, swIfName, dataBefore, dataAfter, writeContext); - } - - private void modifyVhostUserIf(final InstanceIdentifier id, final String swIfName, - final VhostUser vhostUserBefore, final VhostUser vhostUserAfter, - final WriteContext writeContext) throws WriteFailedException { - LOG.debug("Updating vhost user interface: name={}, vhostUser={}", swIfName, vhostUserAfter); - final CompletionStage modifyVhostUserIfReplyCompletionStage = - getFutureJVpp() - .modifyVhostUserIf(getModifyVhostUserIfRequest(vhostUserAfter, - interfaceContext.getIndex(swIfName, writeContext.getMappingContext()))); - - getReplyForUpdate(modifyVhostUserIfReplyCompletionStage.toCompletableFuture(), id, vhostUserBefore, - vhostUserAfter); - LOG.debug("Vhost user interface updated successfully for: {}, vhostUser: {}", swIfName, vhostUserAfter); - } - - private ModifyVhostUserIf getModifyVhostUserIfRequest(final VhostUser vhostUser, final int swIfIndex) { - ModifyVhostUserIf request = new ModifyVhostUserIf(); - request.isServer = booleanToByte(VhostUserRole.Server.equals(vhostUser.getRole())); - request.sockFilename = vhostUser.getSocket().getBytes(); - final Long deviceInstance = vhostUser.getDeviceInstance(); - if (deviceInstance == null) { - request.renumber = 0; - } else { - request.renumber = 1; - request.customDevInstance = Math.toIntExact(deviceInstance); - } - request.swIfIndex = swIfIndex; - return request; - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final VhostUser dataBefore, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String swIfName = id.firstKeyOf(Interface.class).getName(); - deleteVhostUserIf(id, swIfName, dataBefore, writeContext); - } - - private void deleteVhostUserIf(final InstanceIdentifier id, final String swIfName, - final VhostUser vhostUser, final WriteContext writeContext) - throws WriteFailedException { - LOG.debug("Deleting vhost user interface: name={}, vhostUser={}", swIfName, vhostUser); - final CompletionStage deleteVhostUserIfReplyCompletionStage = - getFutureJVpp().deleteVhostUserIf(getDeleteVhostUserIfRequest( - interfaceContext.getIndex(swIfName, writeContext.getMappingContext()))); - - getReplyForDelete(deleteVhostUserIfReplyCompletionStage.toCompletableFuture(), id); - LOG.debug("Vhost user interface deleted successfully for: {}, vhostUser: {}", swIfName, vhostUser); - // Remove interface from our interface context - interfaceContext.removeName(swIfName, writeContext.getMappingContext()); - } - - private DeleteVhostUserIf getDeleteVhostUserIfRequest(final int swIfIndex) { - DeleteVhostUserIf request = new DeleteVhostUserIf(); - request.swIfIndex = swIfIndex; - return request; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VhostUserValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VhostUserValidator.java deleted file mode 100644 index 5526bbb22..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VhostUserValidator.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUser; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class VhostUserValidator implements Validator { - - public VhostUserValidator(@Nonnull final NamingContext interfaceContext) { - checkNotNull(interfaceContext, "interfaceContext should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final VhostUser dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.CreateValidationFailedException { - checkNotNull(dataAfter.getSocket(), "Socket cannot be null"); - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final VhostUser dataBefore, - @Nonnull final VhostUser dataAfter, @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.UpdateValidationFailedException { - checkNotNull(dataAfter.getSocket(), "Socket cannot be null"); - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final VhostUser dataBefore, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.DeleteValidationFailedException { - // there is nothing to validate yet - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanCustomizer.java deleted file mode 100644 index 638d7ec62..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanCustomizer.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; -import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.DisabledInterfacesManager; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.VxlanAddDelTunnel; -import io.fd.jvpp.core.dto.VxlanAddDelTunnelReply; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.L2Input; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.NshProxy; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanTunnel; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Vxlan; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer implements JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(VxlanCustomizer.class); - - private final NamingContext interfaceNamingContext; - private final DisabledInterfacesManager interfaceDisableContext; - - public VxlanCustomizer(@Nonnull final FutureJVppCore vppApi, - @Nonnull final NamingContext interfaceNamingContext, - @Nonnull final DisabledInterfacesManager interfaceDisableContext) { - super(vppApi); - this.interfaceNamingContext = interfaceNamingContext; - this.interfaceDisableContext = interfaceDisableContext; - } - - @Override - protected Class getExpectedInterfaceType() { - return VxlanTunnel.class; - } - - @Override - protected final void writeInterface(@Nonnull final InstanceIdentifier id, @Nonnull final Vxlan dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String swIfName = id.firstKeyOf(Interface.class).getName(); - createVxlanTunnel(id, swIfName, dataAfter, writeContext); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final Vxlan dataBefore, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String swIfName = id.firstKeyOf(Interface.class).getName(); - deleteVxlanTunnel(id, swIfName, dataBefore, writeContext); - } - - private void createVxlanTunnel(final InstanceIdentifier id, final String swIfName, final Vxlan vxlan, - final WriteContext writeContext) - throws WriteFailedException { - final byte isIpv6 = (byte) (isIpv6(vxlan) - ? 1 - : 0); - - int encapVrfId = vxlan.getEncapVrfId().getValue().intValue(); - int vni = vxlan.getVni().getValue().intValue(); - - int decapNext = -1; - if (vxlan.getDecapNext() == L2Input.class) { - decapNext = 1; - } else if (vxlan.getDecapNext() == NshProxy.class) { - decapNext = 2; - } - - LOG.debug("Setting vxlan tunnel for interface: {}. Vxlan: {}", swIfName, vxlan); - final CompletionStage vxlanAddDelTunnelReplyCompletionStage = - getFutureJVpp().vxlanAddDelTunnel(getVxlanTunnelRequest((byte) 1 /* is add */, vxlan.getSrc(), - vxlan.getDst(), encapVrfId, decapNext, vni, isIpv6)); - - final VxlanAddDelTunnelReply reply = - getReplyForCreate(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id, vxlan); - LOG.debug("Vxlan tunnel set successfully for: {}, vxlan: {}", swIfName, vxlan); - if (interfaceNamingContext.containsName(reply.swIfIndex, writeContext.getMappingContext())) { - // VPP keeps vxlan tunnels present even after they are delete(reserving ID for next tunnel) - // This may cause inconsistencies in mapping context when configuring tunnels like this: - // 1. Add tunnel 2. Delete tunnel 3. Read interfaces (reserved mapping e.g. vxlan_tunnel0 -> 6 - // will get into mapping context) 4. Add tunnel (this will add another mapping with the same - // reserved ID and context is invalid) - // That's why a check has to be performed here removing mapping vxlan_tunnel0 -> 6 mapping and storing - // new name for that ID - final String formerName = interfaceNamingContext.getName(reply.swIfIndex, writeContext.getMappingContext()); - LOG.debug("Removing updated mapping of a vxlan tunnel, id: {}, former name: {}, new name: {}", - reply.swIfIndex, formerName, swIfName); - interfaceNamingContext.removeName(formerName, writeContext.getMappingContext()); - - } - - // Removing disability of an interface in case a vxlan tunnel formerly deleted is being reused in VPP - // further details in above comment - if (interfaceDisableContext.isInterfaceDisabled(reply.swIfIndex, writeContext.getMappingContext())) { - LOG.debug("Removing disability of vxlan tunnel, id: {}, name: {}", reply.swIfIndex, swIfName); - interfaceDisableContext.removeDisabledInterface(reply.swIfIndex, writeContext.getMappingContext()); - } - - // Add new interface to our interface context - interfaceNamingContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); - } - - private boolean isIpv6(final Vxlan vxlan) { - return vxlan.getSrc().getIpv4AddressNoZone() == null; - - } - - private void deleteVxlanTunnel(final InstanceIdentifier id, final String swIfName, final Vxlan vxlan, - final WriteContext writeContext) throws WriteFailedException { - final byte isIpv6 = (byte) (isIpv6(vxlan) - ? 1 - : 0); - - int encapVrfId = vxlan.getEncapVrfId().getValue().intValue(); - int vni = vxlan.getVni().getValue().intValue(); - - int decapNext = -1; - if (vxlan.getDecapNext() == L2Input.class) { - decapNext = 1; - } else if (vxlan.getDecapNext() == NshProxy.class) { - decapNext = 2; - } - - LOG.debug("Deleting vxlan tunnel for interface: {}. Vxlan: {}", swIfName, vxlan); - final CompletionStage vxlanAddDelTunnelReplyCompletionStage = - getFutureJVpp().vxlanAddDelTunnel(getVxlanTunnelRequest((byte) 0 /* is add */, vxlan.getSrc(), - vxlan.getDst(), encapVrfId, decapNext, vni, isIpv6)); - - getReplyForDelete(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); - LOG.debug("Vxlan tunnel deleted successfully for: {}, vxlan: {}", swIfName, vxlan); - - final int index = interfaceNamingContext.getIndex(swIfName, writeContext.getMappingContext()); - // Mark this interface as disabled to not include it in operational reads - // because VPP will keep the interface there - LOG.debug("Marking vxlan tunnel as disabled, id: {}, name: {}", index, swIfName); - interfaceDisableContext.disableInterface(index, writeContext.getMappingContext()); - // Remove interface from our interface naming context - interfaceNamingContext.removeName(swIfName, writeContext.getMappingContext()); - } - - private static VxlanAddDelTunnel getVxlanTunnelRequest(final byte isAdd, final IpAddressNoZone srcAddr, - final IpAddressNoZone dstAddr, - final int encapVrfId, - final int decapNextIndex, final int vni, final byte isIpv6) { - final VxlanAddDelTunnel vxlanAddDelTunnel = new VxlanAddDelTunnel(); - vxlanAddDelTunnel.isAdd = isAdd; - vxlanAddDelTunnel.srcAddress = AddressTranslator.INSTANCE.ipAddressToArray(srcAddr); - vxlanAddDelTunnel.dstAddress = AddressTranslator.INSTANCE.ipAddressToArray(dstAddr); - vxlanAddDelTunnel.encapVrfId = encapVrfId; - vxlanAddDelTunnel.vni = vni; - vxlanAddDelTunnel.decapNextIndex = decapNextIndex; - vxlanAddDelTunnel.isIpv6 = isIpv6; - return vxlanAddDelTunnel; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeCustomizer.java deleted file mode 100644 index b3629415b..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeCustomizer.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; -import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.DisabledInterfacesManager; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.VxlanGpeAddDelTunnel; -import io.fd.jvpp.core.dto.VxlanGpeAddDelTunnelReply; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeTunnel; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpe; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class VxlanGpeCustomizer extends AbstractInterfaceTypeCustomizer implements JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(VxlanGpeCustomizer.class); - private final NamingContext interfaceNamingContext; - private final DisabledInterfacesManager interfaceDisableContext; - - public VxlanGpeCustomizer(@Nonnull final FutureJVppCore vppApi, - @Nonnull final NamingContext interfaceNamingContext, - @Nonnull final DisabledInterfacesManager interfaceDisableContext) { - super(vppApi); - this.interfaceNamingContext = interfaceNamingContext; - this.interfaceDisableContext = interfaceDisableContext; - } - - @Override - protected Class getExpectedInterfaceType() { - return VxlanGpeTunnel.class; - } - - @Override - protected final void writeInterface(@Nonnull final InstanceIdentifier id, - @Nonnull final VxlanGpe dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String swIfName = id.firstKeyOf(Interface.class).getName(); - createVxlanGpeTunnel(id, swIfName, dataAfter, writeContext); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final VxlanGpe dataBefore, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String swIfName = id.firstKeyOf(Interface.class).getName(); - deleteVxlanGpeTunnel(id, swIfName, dataBefore, writeContext); - } - - private void createVxlanGpeTunnel(final InstanceIdentifier id, final String swIfName, - final VxlanGpe vxlanGpe, final WriteContext writeContext) - throws WriteFailedException { - final byte isIpv6 = (byte) (isIpv6(vxlanGpe) - ? 1 - : 0); - - int vni = vxlanGpe.getVni().getValue().intValue(); - byte protocol = (byte) vxlanGpe.getNextProtocol().getIntValue(); - int encapVrfId = vxlanGpe.getEncapVrfId().intValue(); - int decapVrfId = vxlanGpe.getDecapVrfId().intValue(); - - LOG.debug("Setting VxlanGpe tunnel for interface: {}. VxlanGpe: {}", swIfName, vxlanGpe); - final CompletionStage VxlanGpeAddDelTunnelReplyCompletionStage = - getFutureJVpp() - .vxlanGpeAddDelTunnel(getVxlanGpeTunnelRequest((byte) 1 /* is add */, vxlanGpe.getLocal(), - vxlanGpe.getRemote(), vni, protocol, encapVrfId, decapVrfId, isIpv6)); - - final VxlanGpeAddDelTunnelReply reply = - getReplyForCreate(VxlanGpeAddDelTunnelReplyCompletionStage.toCompletableFuture(), id, vxlanGpe); - LOG.debug("VxlanGpe tunnel set successfully for: {}, VxlanGpe: {}", swIfName, vxlanGpe); - if (interfaceNamingContext.containsName(reply.swIfIndex, writeContext.getMappingContext())) { - final String formerName = interfaceNamingContext.getName(reply.swIfIndex, writeContext.getMappingContext()); - LOG.debug("Removing updated mapping of a vxlan-gpe tunnel, id: {}, former name: {}, new name: {}", - reply.swIfIndex, formerName, swIfName); - interfaceNamingContext.removeName(formerName, writeContext.getMappingContext()); - } - - // Removing disability of an interface in case a vxlan-gpe tunnel formerly deleted is being reused in VPP - // further details in above comment - if (interfaceDisableContext.isInterfaceDisabled(reply.swIfIndex, writeContext.getMappingContext())) { - LOG.debug("Removing disability of vxlan tunnel, id: {}, name: {}", reply.swIfIndex, swIfName); - interfaceDisableContext.removeDisabledInterface(reply.swIfIndex, writeContext.getMappingContext()); - } - - // Add new interface to our interface context - interfaceNamingContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); - } - - private boolean isIpv6(final VxlanGpe vxlanGpe) { - return vxlanGpe.getLocal().getIpv4AddressNoZone() == null; - - } - - private void deleteVxlanGpeTunnel(final InstanceIdentifier id, final String swIfName, - final VxlanGpe vxlanGpe, final WriteContext writeContext) - throws WriteFailedException { - final byte isIpv6 = (byte) (isIpv6(vxlanGpe) - ? 1 - : 0); - - int vni = vxlanGpe.getVni().getValue().intValue(); - byte protocol = (byte) vxlanGpe.getNextProtocol().getIntValue(); - int encapVrfId = vxlanGpe.getEncapVrfId().intValue(); - int decapVrfId = vxlanGpe.getDecapVrfId().intValue(); - - LOG.debug("Deleting VxlanGpe tunnel for interface: {}. VxlanGpe: {}", swIfName, vxlanGpe); - final CompletionStage VxlanGpeAddDelTunnelReplyCompletionStage = - getFutureJVpp() - .vxlanGpeAddDelTunnel(getVxlanGpeTunnelRequest((byte) 0 /* is delete */, vxlanGpe.getLocal(), - vxlanGpe.getRemote(), vni, protocol, encapVrfId, decapVrfId, isIpv6)); - getReplyForDelete(VxlanGpeAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); - final int index = interfaceNamingContext.getIndex(swIfName, writeContext.getMappingContext()); - // Mark this interface as disabled to not include it in operational reads - // because VPP will keep the interface there - LOG.debug("Marking vxlan tunnel as disabled, id: {}, name: {}", index, swIfName); - interfaceDisableContext.disableInterface(index, writeContext.getMappingContext()); - // Remove interface from our interface naming context - interfaceNamingContext.removeName(swIfName, writeContext.getMappingContext()); - } - - private static VxlanGpeAddDelTunnel getVxlanGpeTunnelRequest(final byte isAdd, final IpAddressNoZone local, - final IpAddressNoZone remote, - final int vni, final byte protocol, - final int encapVrfId, final int decapVrfId, - final byte isIpv6) { - final VxlanGpeAddDelTunnel VxlanGpeAddDelTunnel = new VxlanGpeAddDelTunnel(); - VxlanGpeAddDelTunnel.isAdd = isAdd; - VxlanGpeAddDelTunnel.local = AddressTranslator.INSTANCE.ipAddressToArray(local); - VxlanGpeAddDelTunnel.remote = AddressTranslator.INSTANCE.ipAddressToArray(remote); - VxlanGpeAddDelTunnel.vni = vni; - VxlanGpeAddDelTunnel.protocol = protocol; - VxlanGpeAddDelTunnel.encapVrfId = encapVrfId; - VxlanGpeAddDelTunnel.decapVrfId = decapVrfId; - VxlanGpeAddDelTunnel.isIpv6 = isIpv6; - return VxlanGpeAddDelTunnel; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeValidator.java deleted file mode 100644 index 22b5365f5..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeValidator.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.DisabledInterfacesManager; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpe; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class VxlanGpeValidator implements Validator { - - public VxlanGpeValidator(@Nonnull final NamingContext interfaceNamingContext, - @Nonnull final DisabledInterfacesManager interfaceDisableContext) { - checkNotNull(interfaceNamingContext, "interfaceContext should not be null"); - checkNotNull(interfaceDisableContext, "DisabledInterfacesManager should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final VxlanGpe dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.CreateValidationFailedException { - try { - validateVxlanGpe(dataAfter); - } catch (Exception e) { - throw new DataValidationFailedException.CreateValidationFailedException(id, dataAfter, e); - } - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final VxlanGpe dataBefore, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.DeleteValidationFailedException { - try { - validateVxlanGpe(dataBefore); - } catch (Exception e) { - throw new DataValidationFailedException.DeleteValidationFailedException(id, e); - } - } - - private void validateVxlanGpe(final VxlanGpe data) { - checkNotNull(data.getLocal(), "Local address cannot be null"); - checkNotNull(data.getRemote(), "Remote address cannot be null"); - if (data.getLocal().getIpv4AddressNoZone() == null) { - checkArgument(data.getRemote().getIpv4AddressNoZone() == null, "Inconsistent ip addresses: %s, %s", - data.getLocal(), - data.getRemote()); - } else { - checkArgument(data.getRemote().getIpv6AddressNoZone() == null, "Inconsistent ip addresses: %s, %s", - data.getLocal(), - data.getRemote()); - } - checkNotNull(data.getEncapVrfId(), "encap-vrf-id is mandatory but was not given"); - checkNotNull(data.getDecapVrfId(), "decap-vrf-id is mandatory but was not given"); - checkNotNull(data.getVni(), "VNI cannot be null"); - checkNotNull(data.getNextProtocol(), "Next protocol cannot be null"); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanValidator.java deleted file mode 100644 index 1496a884a..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/VxlanValidator.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.DisabledInterfacesManager; -import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Vxlan; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class VxlanValidator implements Validator { - - public VxlanValidator(@Nonnull final NamingContext interfaceNamingContext, - @Nonnull final DisabledInterfacesManager disabledInterfacesManager) { - checkNotNull(interfaceNamingContext, "interfaceContext should not be null"); - checkNotNull(disabledInterfacesManager, "disabledInterfacesManager should not be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Vxlan dataAfter, - @Nonnull final WriteContext writeContext) - throws CreateValidationFailedException { - try { - validateVxlan(dataAfter); - } catch (Exception e) { - throw new CreateValidationFailedException(id, dataAfter, e); - } - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Vxlan dataBefore, - @Nonnull final WriteContext writeContext) - throws DeleteValidationFailedException { - try { - validateVxlan(dataBefore); - } catch (Exception e) { - throw new DeleteValidationFailedException(id, e); - } - } - - private void validateVxlan(final Vxlan data) { - - checkNotNull(data.getSrc(), "Source cannot be null"); - checkNotNull(data.getDst(), "Destination cannot be null"); - if (data.getSrc().getIpv4AddressNoZone() == null) { - checkArgument(data.getDst().getIpv4AddressNoZone() == null, "Inconsistent ip addresses: %s, %s", - data.getSrc(), - data.getDst()); - } else { - checkArgument(data.getDst().getIpv6AddressNoZone() == null, "Inconsistent ip addresses: %s, %s", - data.getSrc(), - data.getDst()); - } - checkArgument(data.getEncapVrfId() != null && data.getEncapVrfId().getValue() != null, - "encap-vrf-id is mandatory but was not given"); - checkNotNull(data.getVni(), "VNI cannot be null"); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteCustomizer.java deleted file mode 100644 index 86622663d..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteCustomizer.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces.pbb; - -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.MacTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.VppBaseCallException; -import io.fd.jvpp.core.dto.L2InterfacePbbTagRewrite; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.concurrent.TimeoutException; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewrite; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class PbbRewriteCustomizer extends FutureJVppCustomizer - implements WriterCustomizer, MacTranslator, JvppReplyConsumer { - - private static final int OPERATION_DISABLE = 0; - - private final NamingContext interfaceNamingContext; - - public PbbRewriteCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceNamingContext) { - super(futureJVppCore); - this.interfaceNamingContext = interfaceNamingContext; - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final PbbRewrite dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - try { - setPbbRewrite(id, dataAfter, writeContext, false); - } catch (TimeoutException | VppBaseCallException e) { - throw new WriteFailedException.CreateFailedException(id, dataAfter, e); - } - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final PbbRewrite dataBefore, @Nonnull final PbbRewrite dataAfter, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - try { - setPbbRewrite(id, dataAfter, writeContext, false); - } catch (TimeoutException | VppBaseCallException e) { - throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, e); - } - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final PbbRewrite dataBefore, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - - try { - setPbbRewrite(id, dataBefore, writeContext, true); - } catch (TimeoutException | VppBaseCallException e) { - throw new WriteFailedException.DeleteFailedException(id, e); - } - } - - private void setPbbRewrite(final InstanceIdentifier id, final PbbRewrite data, - final WriteContext writeContext, final boolean disable) - throws TimeoutException, VppBaseCallException { - final String interfaceName = id.firstKeyOf(Interface.class).getName(); - - final L2InterfacePbbTagRewrite request = new L2InterfacePbbTagRewrite(); - - //checking all attributes in preconditions(pbb-rewrite is subcontainer, so there can't be mandatory statements) - request.swIfIndex = interfaceNamingContext.getIndex(interfaceName, writeContext.getMappingContext()); - request.bDmac = parseMac(data.getDestinationAddress().getValue()); - request.bSmac = parseMac(data.getSourceAddress().getValue()); - request.bVlanid = data.getBVlanTagVlanId().shortValue(); - request.iSid = data.getITagIsid().intValue(); - request.vtrOp = verifiedOperation(data, disable); - - //not sure whats gonna happen to this attribute, so its left optional for now - if (data.getOuterTag() != null) { - request.outerTag = data.getOuterTag().shortValue(); - } - - getReply(getFutureJVpp().l2InterfacePbbTagRewrite(request).toCompletableFuture()); - } - - // if disabled ,then uses non-public allowed value 0, which is equal to operation disable - private int verifiedOperation(final PbbRewrite data, final boolean disable) { - return disable - ? OPERATION_DISABLE - : data.getInterfaceOperation().getIntValue(); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteValidator.java deleted file mode 100644 index e5ec7fc69..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteValidator.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces.pbb; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewrite; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class PbbRewriteValidator implements Validator { - - - public PbbRewriteValidator(@Nonnull final NamingContext interfaceNamingContext) { - checkNotNull(interfaceNamingContext, "Interface naming context cannot be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final PbbRewrite dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.CreateValidationFailedException { - try { - validatePbbRewrite(id, dataAfter, false); - } catch(Exception e) { - throw new DataValidationFailedException.CreateValidationFailedException(id, dataAfter, e); - } - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final PbbRewrite dataBefore, - @Nonnull final PbbRewrite dataAfter, @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.UpdateValidationFailedException { - - try { - validatePbbRewrite(id, dataAfter, false); - } catch(Exception e) { - throw new DataValidationFailedException.UpdateValidationFailedException(id, dataBefore, dataAfter, e); - } - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final PbbRewrite dataBefore, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.DeleteValidationFailedException { - try { - validatePbbRewrite(id, dataBefore, true); - } catch(Exception e) { - throw new DataValidationFailedException.DeleteValidationFailedException(id, e); - } - } - - private void validatePbbRewrite(final InstanceIdentifier id, @Nonnull final PbbRewrite data, - final boolean disable) { - checkNotNull(id.firstKeyOf(Interface.class), "Interface key not found"); - checkNotNull(data.getDestinationAddress(), "Destination address cannot be null"); - checkNotNull(data.getSourceAddress(), "Source address cannot be null"); - checkNotNull(data.getBVlanTagVlanId(), "BVlan id cannot be null"); - checkNotNull(data.getITagIsid(), "ISid cannot be null"); - if (disable) { - checkNotNull(data.getInterfaceOperation(), "Operation cannot be null"); - } - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfaceCustomizer.java deleted file mode 100644 index 635afd38a..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfaceCustomizer.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces.span; - -import static io.fd.honeycomb.translate.util.RWUtils.cutId; - -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.SwInterfaceSpanEnableDisable; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.function.Function; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.SpanState; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class MirroredInterfaceCustomizer extends FutureJVppCustomizer - implements ListWriterCustomizer, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(MirroredInterfaceCustomizer.class); - - private final NamingContext ifcContext; - private final Function, String> destinationInterfaceNameExtractor; - - public MirroredInterfaceCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext ifcContext, - @Nonnull final Function, String> destinationInterfaceNameExtractor) { - super(futureJVppCore); - this.ifcContext = ifcContext; - this.destinationInterfaceNameExtractor = destinationInterfaceNameExtractor; - } - - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final MirroredInterface mirroredInterface, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String destinationInterfaceName = - destinationInterfaceNameExtractor.apply(cutId(id, MirroredInterfaces.class)); - final String sourceInterfaceName = mirroredInterface.getIfaceRef(); - final SpanState spanState = mirroredInterface.getState(); - - LOG.debug("Enabling span for source interface {} | destination interface {} | state {}", sourceInterfaceName, - destinationInterfaceName, spanState); - - getReplyForWrite(getFutureJVpp().swInterfaceSpanEnableDisable( - getSpanAddDelRequest( - interfaceId(writeContext, ifcContext, destinationInterfaceName), - interfaceId(writeContext, ifcContext, sourceInterfaceName), - true, - spanState)) - .toCompletableFuture(), id); - LOG.debug("Span for source interface {} | destination interface {} | state {} successfully enabled", - sourceInterfaceName, destinationInterfaceName, spanState); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final MirroredInterface mirroredInterface, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - final String destinationInterfaceName = - destinationInterfaceNameExtractor.apply(cutId(id, MirroredInterfaces.class)); - final String sourceInterfaceName = mirroredInterface.getIfaceRef(); - LOG.debug("Disabling span for source interface {} | destination interface {} ", sourceInterfaceName, - destinationInterfaceName); - - getReplyForWrite(getFutureJVpp().swInterfaceSpanEnableDisable( - getSpanAddDelRequest( - interfaceId(writeContext, ifcContext, destinationInterfaceName), - interfaceId(writeContext, ifcContext, sourceInterfaceName), - false, - null)) - .toCompletableFuture(), id); - LOG.debug("Span for source interface {} | destination interface {} successfully disabled", - sourceInterfaceName, destinationInterfaceName); - } - - private SwInterfaceSpanEnableDisable getSpanAddDelRequest(final int dstId, final Integer srcId, final boolean isAdd, - @Nullable final SpanState state) { - final SwInterfaceSpanEnableDisable spanAddDel = new SwInterfaceSpanEnableDisable(); - spanAddDel.state = (byte) (isAdd - ? state != null - ? state.getIntValue() - : 0 - : 0);// either one of 1(rx),2(tx),3(both) or 0 for disable/delete - spanAddDel.swIfIndexFrom = srcId; - spanAddDel.swIfIndexTo = dstId; - return spanAddDel; - } - - private static int interfaceId(final WriteContext writeContext, final NamingContext ifcContext, final String name) { - return ifcContext.getIndex(name, writeContext.getMappingContext()); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfaceValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfaceValidator.java deleted file mode 100644 index f51ad6f0c..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfaceValidator.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces.span; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.Validator; -import io.fd.honeycomb.translate.write.WriteContext; -import java.util.function.Function; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterface; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class MirroredInterfaceValidator implements Validator { - - public MirroredInterfaceValidator(@Nonnull final NamingContext ifcContext, - @Nonnull final Function, String> destinationInterfaceNameExtractor) { - checkNotNull(ifcContext, "Interface naming context cannot be null"); - checkNotNull(destinationInterfaceNameExtractor, "Destination Interface Name extractor cannot be null"); - } - - @Override - public void validateWrite(@Nonnull final InstanceIdentifier id, - @Nonnull final MirroredInterface dataAfter, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.CreateValidationFailedException { - try { - checkMirroredInterfaceData(dataAfter); - } catch (Exception e) { - throw new DataValidationFailedException.CreateValidationFailedException(id, dataAfter, e); - } - } - - @Override - public void validateUpdate(@Nonnull final InstanceIdentifier id, - @Nonnull final MirroredInterface dataBefore, - @Nonnull final MirroredInterface dataAfter, @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.UpdateValidationFailedException { - try { - checkMirroredInterfaceData(dataAfter); - } catch (Exception e) { - throw new DataValidationFailedException.UpdateValidationFailedException(id, dataBefore, dataAfter, e); - } - } - - @Override - public void validateDelete(@Nonnull final InstanceIdentifier id, - @Nonnull final MirroredInterface dataBefore, - @Nonnull final WriteContext writeContext) - throws DataValidationFailedException.DeleteValidationFailedException { - try { - checkMirroredInterfaceData(dataBefore); - } catch (Exception e) { - throw new DataValidationFailedException.DeleteValidationFailedException(id, e); - } - } - - private void checkMirroredInterfaceData(final MirroredInterface data) { - checkNotNull(data.getIfaceRef(), "IfaceRef cannot be null"); - checkNotNull(data.getState(), "State cannot be null"); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/AfPacketCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/AfPacketCustomizer.java deleted file mode 100644 index 4bd6fccf0..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/AfPacketCustomizer.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2018 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static java.lang.String.format; - -import com.google.common.annotations.VisibleForTesting; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; -import io.fd.honeycomb.translate.util.read.cache.StaticCacheKeyFactory; -import io.fd.jvpp.core.dto.AfPacketDetails; -import io.fd.jvpp.core.dto.AfPacketDetailsReplyDump; -import io.fd.jvpp.core.dto.AfPacketDump; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.AfPacket; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.AfPacketBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class AfPacketCustomizer implements InitializingReaderCustomizer, - InterfaceDataTranslator, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(AfPacketCustomizer.class); - private NamingContext interfaceContext; - private final InterfaceCacheDumpManager dumpManager; - private final DumpCacheManager afPacketDumpManager; - - public AfPacketCustomizer(@Nonnull final FutureJVppCore jvpp, - @Nonnull final NamingContext interfaceContext, - @Nonnull final InterfaceCacheDumpManager dumpManager) { - this.interfaceContext = interfaceContext; - this.dumpManager = dumpManager; - this.afPacketDumpManager = - new DumpCacheManager.DumpCacheManagerBuilder() - .withCacheKeyFactory(new StaticCacheKeyFactory(AfPacketCustomizer.class.getName() + "_dump", - AfPacketDetailsReplyDump.class)) - .withExecutor((identifier, params) -> { - final CompletionStage cs = jvpp.afPacketDump(new AfPacketDump()); - return getReplyForRead(cs.toCompletableFuture(), identifier); - }).build(); - } - - @Override - public void merge(@Nonnull Builder parentBuilder, @Nonnull AfPacket readValue) { - ((VppInterfaceStateAugmentationBuilder) parentBuilder).setAfPacket(readValue); - } - - @Nonnull - @Override - public AfPacketBuilder getBuilder(@Nonnull InstanceIdentifier id) { - return new AfPacketBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final AfPacketBuilder builder, - @Nonnull final ReadContext ctx) throws ReadFailedException { - final InterfaceKey key = id.firstKeyOf(Interface.class); - final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext()); - final SwInterfaceDetails ifcDetails = dumpManager.getInterfaceDetail(id, ctx, key.getName()); - - if (!isInterfaceOfType( - org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.AfPacket.class, - ifcDetails)) { - return; - } - - final AfPacketDetailsReplyDump dump = afPacketDumpManager.getDump(id, ctx.getModificationCache()) - .orElse(new AfPacketDetailsReplyDump()); - // Relying here that parent InterfaceCustomizer was invoked first to fill in the context with initial ifc mapping - final AfPacketDetails afPacketDetails = dump.afPacketDetails.stream() - .filter(detail -> detail.swIfIndex == index) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException(format("AfPacket interface %s not found", key.getName()))); - LOG.trace("AfPacket interface: {} attributes returned from VPP: {}", key.getName(), afPacketDetails); - - builder.setMac(new PhysAddress(vppPhysAddrToYang(ifcDetails.l2Address))); - builder.setHostInterfaceName(toString(afPacketDetails.hostIfName)); - - LOG.debug("AfPacket interface: {}, id: {} attributes read as: {}", key.getName(), index, builder); - } - - @Nonnull - @Override - public Initialized init( - @Nonnull final InstanceIdentifier id, - @Nonnull final AfPacket readValue, - @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacketBuilder() - .setHostInterfaceName(readValue.getHostInterfaceName()) - .setMac(readValue.getMac()) - .build()); - } - - @VisibleForTesting - static InstanceIdentifier getCfgId( - final InstanceIdentifier id) { - return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) - .augmentation(VppInterfaceAugmentation.class) - .child( - org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacket.class); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/EthernetCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/EthernetCustomizer.java deleted file mode 100644 index 745acfb5a..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/EthernetCustomizer.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.Ethernet; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.EthernetBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - - -public class EthernetCustomizer - implements InitializingReaderCustomizer, InterfaceDataTranslator { - - private final InterfaceCacheDumpManager dumpManager; - - public EthernetCustomizer(@Nonnull final InterfaceCacheDumpManager dumpManager) { - this.dumpManager = dumpManager; - } - - @Override - public void merge(@Nonnull final Builder parentBuilder, - @Nonnull final Ethernet readValue) { - ((VppInterfaceStateAugmentationBuilder) parentBuilder).setEthernet(readValue); - } - - @Nonnull - @Override - public EthernetBuilder getBuilder(@Nonnull InstanceIdentifier id) { - return new EthernetBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final EthernetBuilder builder, - @Nonnull final ReadContext ctx) throws ReadFailedException { - - final InterfaceKey key = id.firstKeyOf(Interface.class); - final SwInterfaceDetails iface = dumpManager.getInterfaceDetail(id, ctx, key.getName()); - - if (iface.linkMtu != 0) { - // Read physical payload MTU (link_mtu) if given. - // VPP since 18.07 supports also setting MTUs for software interfaces, - // but these are not supported by HC (TODO: HC2VPP-355). - // More details: - // https://git.fd.io/vpp/tree/src/vnet/MTU.md - builder.setMtu((int) iface.linkMtu); - } - - switch (iface.linkDuplex) { - case 1: - builder.setDuplex(Ethernet.Duplex.Half); - break; - case 2: - builder.setDuplex(Ethernet.Duplex.Full); - break; - default: - break; - } - } - - @Override - public Initialized init( - @Nonnull final InstanceIdentifier id, - @Nonnull final Ethernet readValue, - @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.EthernetBuilder() - .setMtu(readValue.getMtu()) - .build()); - } - - private InstanceIdentifier getCfgId( - final InstanceIdentifier id) { - return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) - .augmentation(VppInterfaceAugmentation.class) - .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Ethernet.class); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizer.java deleted file mode 100644 index b3a98b10e..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizer.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2016 Intel and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static com.google.common.base.Preconditions.checkState; - -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.Ipv4Translator; -import io.fd.hc2vpp.common.translate.util.Ipv6Translator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.jvpp.core.dto.GreTunnelDetails; -import io.fd.jvpp.core.dto.GreTunnelDetailsReplyDump; -import io.fd.jvpp.core.dto.GreTunnelDump; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.GreTunnel; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.Gre; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.GreBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class GreCustomizer extends FutureJVppCustomizer - implements InitializingReaderCustomizer, InterfaceDataTranslator, Ipv4Translator, - Ipv6Translator { - - private static final Logger LOG = LoggerFactory.getLogger(GreCustomizer.class); - private final NamingContext interfaceContext; - private final InterfaceCacheDumpManager dumpManager; - - public GreCustomizer(@Nonnull final FutureJVppCore jvpp, - @Nonnull final NamingContext interfaceContext, - @Nonnull final InterfaceCacheDumpManager dumpManager) { - super(jvpp); - this.interfaceContext = interfaceContext; - this.dumpManager = dumpManager; - } - - @Override - public void merge(@Nonnull Builder parentBuilder, - @Nonnull Gre readValue) { - ((VppInterfaceStateAugmentationBuilder) parentBuilder).setGre(readValue); - } - - @Nonnull - @Override - public GreBuilder getBuilder(@Nonnull InstanceIdentifier id) { - return new GreBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final GreBuilder builder, - @Nonnull final ReadContext ctx) throws ReadFailedException { - final InterfaceKey key = id.firstKeyOf(Interface.class); - final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext()); - if (!isInterfaceOfType(dumpManager, id, ctx, GreTunnel.class)) { - return; - } - - LOG.debug("Reading attributes for gre tunnel: {}", key.getName()); - // Dump just a single - final GreTunnelDump request = new GreTunnelDump(); - request.swIfIndex = index; - - final CompletionStage swInterfaceGreDetailsReplyDumpCompletionStage = - getFutureJVpp().greTunnelDump(request); - final GreTunnelDetailsReplyDump reply = - getReplyForRead(swInterfaceGreDetailsReplyDumpCompletionStage.toCompletableFuture(), id); - - // VPP keeps gre tunnel interfaces even after they were deleted (optimization) - // However there ar no longer any gre tunnel specific fields assigned to it and this call - // returns nothing - if (reply == null || reply.greTunnelDetails == null || reply.greTunnelDetails.isEmpty()) { - LOG.debug( - "Gre tunnel {}, id {} has no attributes assigned in VPP. Probably is a leftover interface placeholder" + - "after delete", key.getName(), index); - return; - } - - checkState(reply.greTunnelDetails.size() == 1, - "Unexpected number of returned gre tunnels: {} for tunnel: {}", reply.greTunnelDetails, - key.getName()); - LOG.trace("Gre tunnel: {} attributes returned from VPP: {}", key.getName(), reply); - - final GreTunnelDetails swInterfaceGreDetails = reply.greTunnelDetails.get(0); - if (swInterfaceGreDetails.tunnel.isIpv6 == 1) { - builder.setDst(new IpAddressNoZone( - arrayToIpv4AddressNoZone(swInterfaceGreDetails.tunnel.dst.un.getIp6().ip6Address))); - builder.setSrc(new IpAddressNoZone( - arrayToIpv6AddressNoZone(swInterfaceGreDetails.tunnel.src.un.getIp6().ip6Address))); - } else { - builder.setDst(new IpAddressNoZone( - arrayToIpv4AddressNoZone(swInterfaceGreDetails.tunnel.dst.un.getIp4().ip4Address))); - builder.setSrc(new IpAddressNoZone( - arrayToIpv4AddressNoZone(swInterfaceGreDetails.tunnel.src.un.getIp4().ip4Address))); - } - builder.setOuterFibId((long) swInterfaceGreDetails.tunnel.outerFibId); - LOG.debug("Gre tunnel: {}, id: {} attributes read as: {}", key.getName(), index, builder); - } - - @Override - public Initialized init( - @Nonnull final InstanceIdentifier id, @Nonnull final Gre readValue, @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.GreBuilder() - .setDst(readValue.getDst()) - .setSrc(readValue.getSrc()) - .setOuterFibId(readValue.getOuterFibId()) - .build()); - } - - private InstanceIdentifier getCfgId( - final InstanceIdentifier id) { - return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) - .augmentation(VppInterfaceAugmentation.class) - .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Gre.class); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterconnectionReadUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterconnectionReadUtils.java deleted file mode 100644 index d4541b914..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterconnectionReadUtils.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static com.google.common.base.Preconditions.checkState; -import static java.util.Objects.requireNonNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; -import io.fd.jvpp.core.dto.BridgeDomainDetails; -import io.fd.jvpp.core.dto.BridgeDomainDetailsReplyDump; -import io.fd.jvpp.core.dto.BridgeDomainDump; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import io.fd.jvpp.core.future.FutureJVppCore; -import io.fd.jvpp.core.types.BridgeDomainSwIf; -import java.util.Arrays; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.state.attributes.Interconnection; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.state.attributes.interconnection.BridgeBasedBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Utility class providing Interconnection read support. - */ -final class InterconnectionReadUtils implements InterfaceDataTranslator { - - private static final Logger LOG = LoggerFactory.getLogger(InterconnectionReadUtils.class); - - private final NamingContext interfaceContext; - private final NamingContext bridgeDomainContext; - private final InterfaceCacheDumpManager dumpManager; - private final DumpCacheManager bdDumpManager; - - InterconnectionReadUtils(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext, - @Nonnull final NamingContext bridgeDomainContext, - @Nonnull final InterfaceCacheDumpManager dumpManager) { - requireNonNull(futureJVppCore, "futureJVppCore should not be null"); - this.interfaceContext = requireNonNull(interfaceContext, "interfaceContext should not be null"); - this.bridgeDomainContext = requireNonNull(bridgeDomainContext, "bridgeDomainContext should not be null"); - this.dumpManager = requireNonNull(dumpManager, "dumpManager should not be null"); - this.bdDumpManager = new DumpCacheManager.DumpCacheManagerBuilder() - .acceptOnly(BridgeDomainDetailsReplyDump.class) - .withExecutor((id, params) -> { - final BridgeDomainDump request = new BridgeDomainDump(); - request.bdId = -1; - - final CompletableFuture bdCompletableFuture = - futureJVppCore.bridgeDomainDump(request).toCompletableFuture(); - return getReplyForRead(bdCompletableFuture, id); - }) - .build(); - } - - @Nullable - Interconnection readInterconnection(@Nonnull final InstanceIdentifier id, @Nonnull final String ifaceName, - @Nonnull final ReadContext ctx) - throws ReadFailedException { - final int ifaceId = interfaceContext.getIndex(ifaceName, ctx.getMappingContext()); - - final SwInterfaceDetails iface = dumpManager.getInterfaceDetail(id, ctx, ifaceName); - LOG.debug("Interface details for interface: {}, details: {}", ifaceName, iface); - - final BridgeDomainDetailsReplyDump dumpReply = bdDumpManager.getDump(id, ctx.getModificationCache()) - .orElse(new BridgeDomainDetailsReplyDump()); - for (final BridgeDomainDetails bd : dumpReply.bridgeDomainDetails) { - final Optional bdIfAssignment = getBridgeDomainSwIf(ifaceId, bd); - if (bdIfAssignment.isPresent()) { - final BridgeDomainSwIf bridgeDomainSwIf = bdIfAssignment.get(); - final BridgeBasedBuilder bbBuilder = new BridgeBasedBuilder(); - bbBuilder.setBridgeDomain(bridgeDomainContext.getName(bd.bdId, ctx.getMappingContext())); - - // Set BVI if the bridgeDomainDetails.bviSwIfIndex == current sw if index - final Optional bridgeDomainForInterface = - getBridgeDomainForInterface(dumpReply, bd.bdId); - // Since we already found an interface assigned to a bridge domain, the details for BD must be present - checkState(bridgeDomainForInterface.isPresent()); - if (bridgeDomainForInterface.get().bviSwIfIndex == ifaceId) { - bbBuilder.setBridgedVirtualInterface(true); - } else { - bbBuilder.setBridgedVirtualInterface(false); - } - - if (bridgeDomainSwIf.shg != 0) { - bbBuilder.setSplitHorizonGroup((short) bridgeDomainSwIf.shg); - } - return bbBuilder.build(); - } - } - // TODO HONEYCOMB-190 is there a way to check if interconnection is XconnectBased? - - return null; - } - - private Optional getBridgeDomainSwIf(final int ifaceId, @Nonnull final BridgeDomainDetails bd) { - if (null == bd.swIfDetails) { - return Optional.empty(); - } - // interface can be added to only one BD only - return Arrays.stream(bd.swIfDetails).filter(el -> el.swIfIndex == ifaceId).findFirst(); - } - - private Optional getBridgeDomainForInterface(final BridgeDomainDetailsReplyDump reply, - int bdId) { - return reply.bridgeDomainDetails.stream().filter(a -> a.bdId == bdId).findFirst(); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizer.java deleted file mode 100644 index e59e93084..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizer.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.DisabledInterfacesManager; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.MappingContext; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesStateBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface.AdminStatus; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface.OperStatus; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Customizer for reading ietf-interfaces:interfaces-state/interface. - */ -public class InterfaceCustomizer - implements InitializingListReaderCustomizer, ByteDataTranslator, - InterfaceDataTranslator { - - private static final Logger LOG = LoggerFactory.getLogger(InterfaceCustomizer.class); - private final NamingContext interfaceNamingContext; - private final DisabledInterfacesManager interfaceDisableContext; - private final InterfaceCacheDumpManager dumpManager; - - public InterfaceCustomizer(@Nonnull final NamingContext interfaceNamingContext, - @Nonnull final DisabledInterfacesManager interfaceDisableContext, - @Nonnull final InterfaceCacheDumpManager dumpManager) { - this.interfaceNamingContext = interfaceNamingContext; - this.interfaceDisableContext = interfaceDisableContext; - this.dumpManager = dumpManager; - } - - @Nonnull - @Override - public InterfaceBuilder getBuilder(@Nonnull InstanceIdentifier id) { - return new InterfaceBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull InterfaceBuilder builder, - @Nonnull ReadContext ctx) throws ReadFailedException { - LOG.debug("Reading attributes for interface: {}", id); - final String ifaceName = id.firstKeyOf(id.getTargetType()).getName(); - - final int index = interfaceNamingContext.getIndex(ifaceName, ctx.getMappingContext()); - - // Ignore disabled interface (such as deleted VXLAN tunnels) - if (interfaceDisableContext.isInterfaceDisabled(index, ctx.getMappingContext())) { - LOG.debug("Skipping disabled interface: {}", id); - return; - } - - final SwInterfaceDetails iface = dumpManager.getInterfaceDetail(id, ctx, ifaceName); - LOG.debug("Interface details for interface: {}, details: {}", ifaceName, iface); - - if (!isRegularInterface(iface)) { - LOG.debug("Interface: {} is a sub-interface. Ignoring read request.", ifaceName); - return; - } - - builder.setName(ifaceName); - builder.setType(getInterfaceType(new String(iface.interfaceName).intern())); - builder.setIfIndex(vppIfIndexToYang(iface.swIfIndex)); - builder.setAdminStatus(1 == iface.adminUpDown - ? AdminStatus.Up - : AdminStatus.Down); - builder.setOperStatus(1 == iface.linkUpDown - ? OperStatus.Up - : OperStatus.Down); - if (0 != iface.linkSpeed) { - builder.setSpeed(vppInterfaceSpeedToYang(iface.linkSpeed)); - } - if (iface.l2AddressLength == 6) { - builder.setPhysAddress(new PhysAddress(vppPhysAddrToYang(iface.l2Address))); - } - LOG.trace("Base attributes read for interface: {} as: {}", ifaceName, builder); - } - - @Nonnull - @Override - public List getAllIds(@Nonnull final InstanceIdentifier id, - @Nonnull final ReadContext context) throws ReadFailedException { - final List interfacesKeys; - LOG.trace("Dumping all interfaces to get all IDs"); - final MappingContext mappingCtx = context.getMappingContext(); - final Set interfacesIdxs = dumpManager.getInterfaces(id, context) - .filter(elt -> elt != null) - // Filter out disabled interfaces, dont read them - // This also prevents child readers in being invoked such as vxlan (which relies on disabling interfaces) - .filter(elt -> !interfaceDisableContext - .isInterfaceDisabled(elt.swIfIndex, mappingCtx)) - // filter out sub-interfaces - .filter(InterfaceDataTranslator.INSTANCE::isRegularInterface) - .map(elt -> elt.swIfIndex) - .collect(Collectors.toSet()); - - // Clean disabled interfaces list - interfaceDisableContext.getDisabledInterfaces(mappingCtx).stream() - // Find indices not currently in VPP - .filter(interfacesIdxs::contains) - // Remove from disabled list ... not disabled if not existing - .forEach(idx -> interfaceDisableContext.removeDisabledInterface(idx, mappingCtx)); - - // Transform indices to keys - interfacesKeys = interfacesIdxs.stream() - .map(index -> new InterfaceKey(interfaceNamingContext.getName(index, context.getMappingContext()))) - .collect(Collectors.toList()); - - LOG.debug("Interfaces found in VPP: {}", interfacesKeys); - return interfacesKeys; - } - - @Override - public void merge(@Nonnull final org.opendaylight.yangtools.concepts.Builder builder, - @Nonnull final List readData) { - ((InterfacesStateBuilder) builder).setInterface(readData); - } - - @Override - public Initialized init( - @Nonnull final InstanceIdentifier id, @Nonnull final Interface readValue, - @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder() - .setName(readValue.getName()) - .setType(readValue.getType()) - .setEnabled(AdminStatus.Up.equals(readValue.getAdminStatus())) - // Not present in interfaces-state - // .setLinkUpDownTrapEnable() - .build()); - } - - public static InstanceIdentifier getCfgId( - final InstanceIdentifier id) { - return InstanceIdentifier.create(Interfaces.class).child( - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface.class, - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey( - id.firstKeyOf(Interface.class).getName())); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslator.java deleted file mode 100644 index c77db2959..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslator.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static com.google.common.base.Preconditions.checkArgument; - -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import java.math.BigInteger; -import java.util.Objects; -import java.util.stream.Collector; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.AfPacket; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.GreTunnel; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.Loopback; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.TapV2; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUser; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeTunnel; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanTunnel; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev180703.EthernetCsmacd; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Gauge64; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public interface InterfaceDataTranslator extends ByteDataTranslator, JvppReplyConsumer { - - InterfaceDataTranslator INSTANCE = new InterfaceDataTranslator() { - }; - - int PHYSICAL_ADDRESS_LENGTH = 6; - - Collector SINGLE_ITEM_COLLECTOR = - RWUtils.singleItemCollector(); - - /** - * Convert VPP's link speed in kbits per second to Yang type. - * - * @param vppLinkSpeed Link speed in kbits per second from VPP. - * @return Converted value from VPP link speed - */ - default Gauge64 vppInterfaceSpeedToYang(int vppLinkSpeed) { - return new Gauge64(BigInteger.valueOf(Integer.toUnsignedLong(vppLinkSpeed) * 1000)); - } - - /** - * Reads first 6 bytes of supplied byte array and converts to string as Yang dictates

Replace later with - * https://git.opendaylight.org/gerrit/#/c/34869/10/model/ietf/ietf-type- util/src/main/ - * java/org/opendaylight/mdsal/model/ietf/util/AbstractIetfYangUtil.java - * - * @param vppPhysAddress byte array of bytes in big endian order, constructing the network IF physical address. - * @return String like "aa:bb:cc:dd:ee:ff" - * @throws NullPointerException if vppPhysAddress is null - * @throws IllegalArgumentException if vppPhysAddress.length < 6 - */ - default String vppPhysAddrToYang(@Nonnull final byte[] vppPhysAddress) { - Objects.requireNonNull(vppPhysAddress, "Empty physical address bytes"); - final int endIndex = PHYSICAL_ADDRESS_LENGTH; - checkArgument(endIndex <= vppPhysAddress.length, - "Invalid physical address size (%s), expected >= %s", vppPhysAddress.length, endIndex); - // Extended (64-bit) MAC addresses are currently not supported , so use first 48-bits. - // Adding support for extended MAC addresses might require yang model change. - // Also VPP is not consistent (e.g. for TAP it allows to configure MAC of 6 bytes, but sw_interface_details - // contains 8 bytes. - return printHexBinary(vppPhysAddress, 0, PHYSICAL_ADDRESS_LENGTH); - } - - /** - * VPP's interface index is counted from 0, whereas ietf-interface's if-index is from 1. This function converts from - * VPP's interface index to YANG's interface index. - * - * @param vppIfIndex the sw interface index VPP reported. - * @return VPP's interface index incremented by one - */ - default int vppIfIndexToYang(int vppIfIndex) { - return vppIfIndex + 1; - } - - /** - * This function does the opposite of what {@link #vppIfIndexToYang(int)} does. - * - * @param yangIfIndex if-index from ietf-interfaces. - * @return VPP's representation of the if-index - */ - default int yangIfIndexToVpp(int yangIfIndex) { - checkArgument(yangIfIndex >= 1, "YANG if-index has invalid value %s", yangIfIndex); - return yangIfIndex - 1; - } - - /** - * Determine interface type based on its VPP name (relying on VPP's interface naming conventions) - * - * @param interfaceName VPP generated interface name - * @return Interface type - */ - @Nonnull - default Class getInterfaceType(@Nonnull final String interfaceName) { - - if (interfaceName.startsWith("tap")) { - return TapV2.class; - } - - if (interfaceName.startsWith("vxlan_gpe")) { - return VxlanGpeTunnel.class; - } - - if (interfaceName.startsWith("vxlan")) { - return VxlanTunnel.class; - } - - if (interfaceName.startsWith("gre")) { - return GreTunnel.class; - } - - if (interfaceName.startsWith("VirtualEthernet")) { - return VhostUser.class; - } - - if (interfaceName.startsWith("host-")) { - return AfPacket.class; - } - - if (interfaceName.startsWith("loop")) { - return Loopback.class; - } - - return EthernetCsmacd.class; - } - - /** - * Check interface type. Uses interface details from VPP to determine. - */ - default boolean isInterfaceOfType(@Nonnull final InterfaceCacheDumpManager dumpManager, - @Nonnull final InstanceIdentifier id, - @Nonnull final ReadContext ctx, - @Nonnull final Class ifcType) - throws ReadFailedException { - final String name = id.firstKeyOf(Interface.class).getName(); - final SwInterfaceDetails vppInterfaceDetails = dumpManager.getInterfaceDetail(id, ctx, name); - - return isInterfaceOfType(ifcType, vppInterfaceDetails); - } - - default boolean isInterfaceOfType(@Nonnull final Class ifcType, - @Nullable final SwInterfaceDetails cachedDetails) { - if (cachedDetails == null) { - return false; - } else { - return ifcType.equals(getInterfaceType(toString(cachedDetails.interfaceName))); - } - } - - /** - * Checks whether provided {@link SwInterfaceDetails} is detail of sub-interface
- *

    - *
  • subId == unique number of sub-interface within set of sub-interfaces of single interface
  • - *
  • swIfIndex == unique index of interface/sub-interface within all interfaces
  • - *
  • supSwIfIndex == unique index of parent interface
  • - *
  • in case of interface , swIfIndex value equals supSwIfIndex
  • - *
  • in case of subinterface, supSwIfIndex equals index of parent interface, swIfIndex is index of - * subinterface itselt
  • - *
- */ - default boolean isSubInterface(@Nonnull final SwInterfaceDetails elt) { - //cant check by subId != 0, because you can pick 0 as value - return elt.supSwIfIndex != elt.swIfIndex; - } - - /** - * Checks whether provided {@link SwInterfaceDetails} is detail of interface
- *
    - *
  • subId == unique number of subinterface within set of subinterfaces of single interface
  • - *
  • swIfIndex == unique index of interface/subinterface within all interfaces
  • - *
  • supSwIfIndex == unique index of parent interface
  • - *
  • in case of interface , swIfIndex value equals supSwIfIndex
  • - *
  • in case of subinterface, supSwIfIndex equals index of parent interface, swIfIndex is index - * of subinterface itselt
  • - *
- */ - default boolean isRegularInterface(@Nonnull final SwInterfaceDetails elt) { - return !isSubInterface(elt); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceRoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceRoutingCustomizer.java deleted file mode 100644 index 86fc52109..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceRoutingCustomizer.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.jvpp.core.future.FutureJVppCore; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.Routing; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.RoutingBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class InterfaceRoutingCustomizer extends RoutingCustomizer implements - InitializingReaderCustomizer { - - private static final Logger LOG = LoggerFactory.getLogger(InterfaceRoutingCustomizer.class); - - public InterfaceRoutingCustomizer(@Nonnull final FutureJVppCore vppApi, - @Nonnull final NamingContext interfaceContext) { - super(vppApi, interfaceContext); - } - - @Nonnull - @Override - public RoutingBuilder getBuilder(@Nonnull final InstanceIdentifier id) { - return new RoutingBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final RoutingBuilder builder, - @Nonnull final ReadContext ctx) throws ReadFailedException { - LOG.debug("Reading attributes for Routing: {}", id); - final String ifName = id.firstKeyOf(Interface.class).getName(); - readInterfaceRouting(id, builder::setIpv4VrfId, builder::setIpv6VrfId, ctx, ifName); - } - - @Override - public void merge(@Nonnull final Builder parentBuilder, @Nonnull final Routing readValue) { - ((VppInterfaceStateAugmentationBuilder) parentBuilder).setRouting(readValue); - } - - @Nonnull - @Override - public Initialized init( - @Nonnull final InstanceIdentifier id, - @Nonnull final Routing readValue, - @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.RoutingBuilder() - .setIpv4VrfId(readValue.getIpv4VrfId()) - .setIpv6VrfId(readValue.getIpv6VrfId()) - .build()); - } - - private InstanceIdentifier getCfgId( - final InstanceIdentifier id) { - return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) - .augmentation(VppInterfaceAugmentation.class) - .child( - org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Routing.class); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceStatisticsCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceStatisticsCustomizer.java deleted file mode 100644 index dee0f4cbc..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceStatisticsCustomizer.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceStatisticsManager; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.stats.dto.InterfaceStatistics; -import io.fd.jvpp.stats.dto.InterfaceStatisticsDetails; -import io.fd.jvpp.stats.dto.InterfaceStatisticsDetailsReplyDump; -import io.fd.jvpp.stats.dto.InterfaceStatisticsDump; -import io.fd.jvpp.stats.future.FutureJVppStatsFacade; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.Optional; -import java.util.concurrent.Future; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state._interface.Statistics; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state._interface.StatisticsBuilder; -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.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class InterfaceStatisticsCustomizer implements ReaderCustomizer { - - private static final Logger LOG = LoggerFactory.getLogger(InterfaceStatisticsCustomizer.class); - - private final NamingContext ifcNamingCtx; - private final FutureJVppStatsFacade jvppStats; - private final InterfaceStatisticsManager statisticsManager; - - public InterfaceStatisticsCustomizer(final NamingContext ifcNamingCtx, - final FutureJVppStatsFacade jvppStats, - final InterfaceStatisticsManager statisticsManager) { - this.ifcNamingCtx = checkNotNull(ifcNamingCtx, "Naming context should not be null"); - this.jvppStats = checkNotNull(jvppStats, "JVpp Stats facade should not be null"); - this.statisticsManager = checkNotNull(statisticsManager, "Statistics Manager should not be null"); - } - - @Nonnull - @Override - public StatisticsBuilder getBuilder(@Nonnull final InstanceIdentifier instanceIdentifier) { - return new StatisticsBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier instanceIdentifier, - @Nonnull final StatisticsBuilder statisticsBuilder, - @Nonnull final ReadContext readContext) - throws ReadFailedException { - if (!statisticsManager.isStatisticsEnabled()) return; - - final InterfaceKey key = instanceIdentifier.firstKeyOf(Interface.class); - final int index = ifcNamingCtx.getIndex(key.getName(), readContext.getMappingContext()); - InterfaceStatisticsDetails stats = getStatisticsDump(instanceIdentifier); - if (stats != null) { - Optional statsDetail = - Arrays.asList(stats.interfaceStatistics).stream().filter(elt -> elt.swIfIndex == index).findFirst(); - if (statsDetail.isPresent()) { - InterfaceStatistics detail = statsDetail.get(); - statisticsBuilder.setOutOctets(new Counter64(BigInteger.valueOf(detail.outBytes))) - .setOutUnicastPkts(new Counter64(BigInteger.valueOf(detail.outUnicastPkts))) - .setOutMulticastPkts(new Counter64(BigInteger.valueOf(detail.outMulticastPkts))) - .setOutBroadcastPkts(new Counter64(BigInteger.valueOf(detail.outBroadcastPkts))) - .setOutErrors(new Counter32(new Long(detail.outErrors))) - .setInOctets(new Counter64(BigInteger.valueOf(detail.inBytes))) - .setInUnicastPkts(new Counter64(BigInteger.valueOf(detail.inUnicastPkts))) - .setInMulticastPkts(new Counter64(BigInteger.valueOf(detail.inMulticastPkts))) - .setInBroadcastPkts(new Counter64(BigInteger.valueOf(detail.inBroadcastPkts))) - .setInErrors(new Counter32(new Long(detail.inErrors))); - } - } - } - - @Override - public void merge(@Nonnull final Builder builder, @Nonnull final Statistics statistics) { - ((InterfaceBuilder) builder).setStatistics(statistics); - } - - private InterfaceStatisticsDetails getStatisticsDump(InstanceIdentifier id) throws ReadFailedException { - LOG.debug("Sending InterfaceStatisticsDump request..."); - final InterfaceStatisticsDump request = new InterfaceStatisticsDump(); - - final Future replyFuture = - jvppStats.interfaceStatisticsDump(request).toCompletableFuture(); - final InterfaceStatisticsDetailsReplyDump reply; - try { - reply = replyFuture.get(); - } catch (Exception e) { - throw new ReadFailedException(id, e); - } - - if (reply == null || reply.interfaceStatisticsDetails == null) { - throw new ReadFailedException(id, - new IllegalStateException("Received null response for empty dump: " + reply)); - } - return reply.interfaceStatisticsDetails; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/L2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/L2Customizer.java deleted file mode 100644 index a339f9f80..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/L2Customizer.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.jvpp.core.future.FutureJVppCore; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.L2; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.L2Builder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.BridgeBasedBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.XconnectBasedBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.state.attributes.Interconnection; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.state.attributes.interconnection.BridgeBased; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.state.attributes.interconnection.XconnectBased; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Customizer for reading ietf-interfaces:interfaces-state/interface/iface_name/v3po:l2 - */ -public class L2Customizer extends FutureJVppCustomizer implements InitializingReaderCustomizer { - - private static final Logger LOG = LoggerFactory.getLogger(L2Customizer.class); - private final InterconnectionReadUtils icReadUtils; - - public L2Customizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext, - @Nonnull final NamingContext bridgeDomainContext, - @Nonnull final InterfaceCacheDumpManager dumpManager) { - super(futureJVppCore); - this.icReadUtils = - new InterconnectionReadUtils(futureJVppCore, interfaceContext, bridgeDomainContext, dumpManager); - } - - @Override - public void merge(@Nonnull final Builder parentBuilder, @Nonnull final L2 readValue) { - ((VppInterfaceStateAugmentationBuilder) parentBuilder).setL2(readValue); - } - - @Nonnull - @Override - public L2Builder getBuilder(@Nonnull final InstanceIdentifier id) { - return new L2Builder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final L2Builder builder, - @Nonnull final ReadContext ctx) throws ReadFailedException { - - LOG.debug("Reading attributes for L2: {}", id); - final InterfaceKey key = id.firstKeyOf(Interface.class); - final String ifaceName = key.getName(); - builder.setInterconnection(icReadUtils.readInterconnection(id, ifaceName, ctx)); - } - - @Override - public Initialized init( - @Nonnull final InstanceIdentifier id, - @Nonnull final L2 readValue, - @Nonnull final ReadContext ctx) { - final org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2Builder - l2Builder = - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2Builder(); - - final Interconnection interconnection = readValue.getInterconnection(); - if (interconnection != null) { - if (interconnection instanceof XconnectBased) { - final XconnectBasedBuilder xconnectBasedBuilder = new XconnectBasedBuilder(); - xconnectBasedBuilder.setXconnectOutgoingInterface( - ((XconnectBased) interconnection).getXconnectOutgoingInterface()); - l2Builder.setInterconnection(xconnectBasedBuilder.build()); - } else if (interconnection instanceof BridgeBased) { - final BridgeBasedBuilder bridgeBasedBuilder = new BridgeBasedBuilder(); - bridgeBasedBuilder.setBridgeDomain(((BridgeBased) interconnection).getBridgeDomain()); - bridgeBasedBuilder - .setBridgedVirtualInterface(((BridgeBased) interconnection).isBridgedVirtualInterface()); - bridgeBasedBuilder.setSplitHorizonGroup(((BridgeBased) interconnection).getSplitHorizonGroup()); - l2Builder.setInterconnection(bridgeBasedBuilder.build()); - } - } - - return Initialized.create(getCfgId(id), l2Builder.build()); - } - - private InstanceIdentifier getCfgId( - final InstanceIdentifier id) { - return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) - .augmentation(VppInterfaceAugmentation.class) - .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2.class); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizer.java deleted file mode 100644 index c7abe379f..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizer.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - -import io.fd.hc2vpp.common.translate.util.TagRewriteOperation; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import java.util.ArrayList; -import java.util.List; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319._802dot1ad; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319._802dot1q; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.Rewrite; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.RewriteBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.state.attributes.L2Builder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.tag.rewrite.PushTags; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.tag.rewrite.PushTagsBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.tag.rewrite.PushTagsKey; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.CVlan; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qTagVlanType; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qVlanId; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.SVlan; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.Dot1qTagBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Customizer for reading vlan tag-rewrite configuration state form the VPP. - */ -public class RewriteCustomizer - implements ReaderCustomizer, InterfaceDataTranslator { - - // No initialization necessary since its parent Subinterface L2 customzier sets the entire subtree during - // initialization - - private static final Logger LOG = LoggerFactory.getLogger(RewriteCustomizer.class); - private final InterfaceCacheDumpManager dumpManager; - - public RewriteCustomizer(@Nonnull final InterfaceCacheDumpManager dumpManager) { - this.dumpManager = checkNotNull(dumpManager, "dumpManager should not be null"); - } - - @Override - public void merge(@Nonnull final Builder parentBuilder, - @Nonnull final Rewrite readValue) { - ((L2Builder) parentBuilder).setRewrite(readValue); - } - - @Nonnull - @Override - public RewriteBuilder getBuilder(@Nonnull final InstanceIdentifier id) { - return new RewriteBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final RewriteBuilder builder, @Nonnull final ReadContext ctx) - throws ReadFailedException { - final String subInterfaceName = getSubInterfaceName(id); - LOG.debug("Reading attributes for sub interface: {}", subInterfaceName); - - final SwInterfaceDetails iface = dumpManager.getInterfaceDetail(id, ctx, subInterfaceName); - LOG.debug("VPP sub-interface details: {}", iface); - - checkState(isSubInterface(iface), "Interface returned by the VPP is not a sub-interface"); - - final TagRewriteOperation operation = TagRewriteOperation.get(iface.vtrOp); - if (TagRewriteOperation.disabled == operation) { - LOG.debug("Tag rewrite operation is disabled for "); - return; - } - - builder.setVlanType(iface.vtrPushDot1Q == 1 - ? _802dot1q.class - : _802dot1ad.class); - - setPushTags(builder, iface); - setPopTags(builder, operation); - } - - private static String getSubInterfaceName(final InstanceIdentifier id) { - return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), - Math.toIntExact(id.firstKeyOf(SubInterface.class).getIdentifier())); - } - - private void setPopTags(final RewriteBuilder builder, final TagRewriteOperation operation) { - final byte numberOfTagsToPop = operation.getPopTags(); - if (numberOfTagsToPop != 0) { - builder.setPopTags(Short.valueOf(numberOfTagsToPop)); - } - } - - private void setPushTags(final RewriteBuilder builder, final SwInterfaceDetails iface) { - final List tags = new ArrayList<>(); - if (iface.vtrTag1 != 0) { - tags.add(buildTag((short) 0, SVlan.class, iface.vtrTag1)); - } - if (iface.vtrTag2 != 0) { - tags.add(buildTag((short) 1, CVlan.class, iface.vtrTag2)); - } - if (tags.size() > 0) { - builder.setPushTags(tags); - } - } - - private PushTags buildTag(final short index, final Class tagType, final int vlanId) { - final PushTagsBuilder tag = new PushTagsBuilder(); - tag.setIndex(index); - tag.withKey(new PushTagsKey(index)); - final Dot1qTagBuilder dtag = new Dot1qTagBuilder(); - dtag.setTagType(tagType); - dtag.setVlanId(new Dot1qVlanId(vlanId)); - tag.setDot1qTag(dtag.build()); - return tag.build(); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/RoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/RoutingCustomizer.java deleted file mode 100644 index f44680260..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/RoutingCustomizer.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import com.google.common.primitives.UnsignedInts; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.jvpp.core.dto.SwInterfaceGetTable; -import io.fd.jvpp.core.dto.SwInterfaceGetTableReply; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.function.Consumer; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.RoutingBaseAttributes; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -abstract class RoutingCustomizer extends FutureJVppCustomizer implements JvppReplyConsumer { - private final NamingContext interfaceContext; - - protected RoutingCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore); - this.interfaceContext = interfaceContext; - } - - protected void readInterfaceRouting(@Nonnull final InstanceIdentifier id, - @Nonnull final Consumer v4VrfConsumer, - @Nonnull final Consumer v6VrfConsumer, - @Nonnull final ReadContext ctx, final String interfaceName) - throws ReadFailedException { - final SwInterfaceGetTable request = new SwInterfaceGetTable(); - request.swIfIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext()); - request.isIpv6 = 0; - final SwInterfaceGetTableReply - ip4Reply = getReplyForRead(getFutureJVpp().swInterfaceGetTable(request).toCompletableFuture(), id); - - request.isIpv6 = 1; - final SwInterfaceGetTableReply ip6Reply = - getReplyForRead(getFutureJVpp().swInterfaceGetTable(request).toCompletableFuture(), id); - - if (ip4Reply.vrfId != 0) { - v4VrfConsumer.accept(new VniReference(UnsignedInts.toLong(ip4Reply.vrfId))); - } - if (ip6Reply.vrfId != 0) { - v6VrfConsumer.accept(new VniReference(UnsignedInts.toLong(ip6Reply.vrfId))); - } - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizer.java deleted file mode 100644 index a97edb564..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizer.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubInterfaceStatus; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.SubInterfacesBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.DefaultBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.UntaggedBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.vlan.tagged.VlanTaggedBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.Match; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.MatchBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.Tags; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.TagsBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.tags.Tag; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.tags.TagBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.tags.TagKey; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.CVlan; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qTagVlanType; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qVlanId; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.SVlan; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTagBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Customizer for reading sub interfaces form the VPP. - */ -public class SubInterfaceCustomizer extends FutureJVppCustomizer - implements InitializingListReaderCustomizer, - ByteDataTranslator, - InterfaceDataTranslator { - - private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceCustomizer.class); - private static final Dot1qTag.VlanId ANY_VLAN_ID = new Dot1qTag.VlanId(Dot1qTag.VlanId.Enumeration.Any); - private final NamingContext interfaceContext; - private final InterfaceCacheDumpManager dumpManager; - - public SubInterfaceCustomizer(@Nonnull final FutureJVppCore jvpp, - @Nonnull final NamingContext interfaceContext, - @Nonnull final InterfaceCacheDumpManager dumpManager) { - super(jvpp); - this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null"); - this.dumpManager = checkNotNull(dumpManager, "dumpManager should not be null"); - } - - private static String getSubInterfaceName(final InstanceIdentifier id) { - return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), - Math.toIntExact(id.firstKeyOf(id.getTargetType()).getIdentifier())); - } - - private static Tag buildTag(final short index, final Class tagType, - final Dot1qTag.VlanId vlanId) { - TagBuilder tag = new TagBuilder(); - tag.setIndex(index); - tag.withKey(new TagKey(index)); - final Dot1qTagBuilder dtag = new Dot1qTagBuilder(); - dtag.setTagType(tagType); - dtag.setVlanId(vlanId); - tag.setDot1qTag(dtag.build()); - return tag.build(); - } - - private static Dot1qTag.VlanId buildVlanId(final short vlanId) { - // treat vlanId as unsigned value: - return new Dot1qTag.VlanId(new Dot1qVlanId(0xffff & vlanId)); - } - - @Nonnull - @Override - public List getAllIds(@Nonnull final InstanceIdentifier id, - @Nonnull final ReadContext context) throws ReadFailedException { - // Relying here that parent InterfaceCustomizer was invoked first (PREORDER) - // to fill in the context with initial ifc mapping - final InterfaceKey key = id.firstKeyOf(Interface.class); - final String ifaceName = key.getName(); - final int ifaceId = interfaceContext.getIndex(ifaceName, context.getMappingContext()); - - final List interfacesKeys = dumpManager.getInterfaces(id,context) - .filter(Objects::nonNull) - // accept only sub-interfaces for current iface: - .filter(elt -> isSubInterface(elt) && elt.supSwIfIndex == ifaceId) - .map(details -> new SubInterfaceKey(new Long(details.subId))) - .collect(Collectors.toList()); - - LOG.debug("Sub-interfaces of {} found in VPP: {}", ifaceName, interfacesKeys); - return interfacesKeys; - } - - @Override - public void merge(@Nonnull final Builder builder, - @Nonnull final List readData) { - ((SubInterfacesBuilder) builder).setSubInterface(readData); - } - - @Nonnull - @Override - public SubInterfaceBuilder getBuilder(@Nonnull final InstanceIdentifier id) { - return new SubInterfaceBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final SubInterfaceBuilder builder, @Nonnull final ReadContext ctx) - throws ReadFailedException { - final String subInterfaceName = getSubInterfaceName(id); - LOG.debug("Reading attributes for sub interface: {}", subInterfaceName); - - final SwInterfaceDetails iface = dumpManager.getInterfaceDetail(id, ctx, subInterfaceName); - LOG.debug("VPP sub-interface details: {}", iface); - - checkState(isSubInterface(iface), "Interface returned by the VPP is not a sub-interface"); - - builder.setIdentifier((long) iface.subId); - builder.withKey(new SubInterfaceKey(builder.getIdentifier())); - - // sub-interface-base-attributes: - builder.setTags(readTags(iface)); - builder.setMatch(readMatch(iface)); - - // sub-interface-operational-attributes: - builder.setAdminStatus(1 == iface.adminUpDown - ? SubInterfaceStatus.Up - : SubInterfaceStatus.Down); - builder.setOperStatus(1 == iface.linkUpDown - ? SubInterfaceStatus.Up - : SubInterfaceStatus.Down); - builder.setIfIndex(vppIfIndexToYang(iface.swIfIndex)); - if (iface.l2AddressLength == 6) { - builder.setPhysAddress(new PhysAddress(vppPhysAddrToYang(iface.l2Address))); - } - if (0 != iface.linkSpeed) { - builder.setSpeed(vppInterfaceSpeedToYang(iface.linkSpeed)); - } - } - - private Tags readTags(final SwInterfaceDetails iface) { - final TagsBuilder tags = new TagsBuilder(); - final List list = new ArrayList<>(); - if (iface.subNumberOfTags > 0) { - if (iface.subOuterVlanIdAny == 1) { - list.add(buildTag((short) 0, SVlan.class, ANY_VLAN_ID)); - } else { - list.add(buildTag((short) 0, SVlan.class, buildVlanId(iface.subOuterVlanId))); - } - // inner tag (customer tag): - if (iface.subNumberOfTags == 2) { - if (iface.subInnerVlanIdAny == 1) { - list.add(buildTag((short) 1, CVlan.class, ANY_VLAN_ID)); - } else { - list.add(buildTag((short) 1, CVlan.class, buildVlanId(iface.subInnerVlanId))); - } - } - } - tags.setTag(list); - return tags.build(); - } - - private Match readMatch(final SwInterfaceDetails iface) { - final MatchBuilder match = new MatchBuilder(); - if (iface.subDefault == 1) { - match.setMatchType(new DefaultBuilder().build()); - } else if (iface.subNumberOfTags == 0) { - match.setMatchType(new UntaggedBuilder().build()); - } else { - final VlanTaggedBuilder tagged = new VlanTaggedBuilder(); - tagged.setMatchExactTags(byteToBoolean(iface.subExactMatch)); - match.setMatchType( - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.VlanTaggedBuilder() - .setVlanTagged(tagged.build()).build()); - } - return match.build(); - } - - @Override - public Initialized init( - @Nonnull final InstanceIdentifier id, @Nonnull final SubInterface readValue, - @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceBuilder() - .setEnabled(SubInterfaceStatus.Up.equals(readValue.getAdminStatus())) - .setIdentifier(readValue.getIdentifier()) - .setMatch(readValue.getMatch()) - .setTags(readValue.getTags()) - .setVlanType(readValue.getVlanType()) - .build()); - } - - public static InstanceIdentifier getCfgId( - final InstanceIdentifier id) { - return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) - .augmentation(SubinterfaceAugmentation.class) - .child(SubInterfaces.class) - .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface.class, - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey( - id.firstKeyOf(SubInterface.class).getIdentifier())); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceL2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceL2Customizer.java deleted file mode 100644 index 71fdabb1a..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceL2Customizer.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static io.fd.hc2vpp.v3po.util.SubInterfaceUtils.getSubInterfaceName; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.jvpp.core.future.FutureJVppCore; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.state.attributes.interconnection.BridgeBased; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.state.attributes.interconnection.XconnectBased; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.state.attributes.L2; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.state.attributes.L2Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Customizer for reading vlan sub interface L2 operational state - */ -public class SubInterfaceL2Customizer - implements InitializingReaderCustomizer { - - private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceL2Customizer.class); - private final InterconnectionReadUtils icReadUtils; - - public SubInterfaceL2Customizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext, - @Nonnull final NamingContext bridgeDomainContext, - @Nonnull final InterfaceCacheDumpManager dumpManager) { - this.icReadUtils = - new InterconnectionReadUtils(futureJVppCore, interfaceContext, bridgeDomainContext, dumpManager); - } - - @Override - public void merge(@Nonnull final Builder parentBuilder, @Nonnull final L2 readValue) { - ((SubInterfaceBuilder) parentBuilder).setL2(readValue); - } - - @Nonnull - @Override - public L2Builder getBuilder(@Nonnull final InstanceIdentifier id) { - return new L2Builder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final L2Builder builder, - @Nonnull final ReadContext ctx) throws ReadFailedException { - LOG.debug("Reading attributes for sub-interface L2: {}", id); - final InterfaceKey parentInterfacekey = id.firstKeyOf(Interface.class); - final SubInterfaceKey subInterfacekey = id.firstKeyOf(SubInterface.class); - final String subInterfaceName = - getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue()); - - builder.setInterconnection(icReadUtils.readInterconnection(id, subInterfaceName, ctx)); - } - - @Override - public Initialized init( - @Nonnull final InstanceIdentifier id, - @Nonnull final L2 readValue, - @Nonnull final ReadContext ctx) { - - org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2Builder - builder = - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2Builder(); - - if (readValue.getInterconnection() instanceof XconnectBased) { - XconnectBased state = (XconnectBased) readValue.getInterconnection(); - builder.setInterconnection( - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.XconnectBasedBuilder() - .setXconnectOutgoingInterface(state.getXconnectOutgoingInterface()) - .build()); - } else { - BridgeBased state = (BridgeBased) readValue.getInterconnection(); - builder.setInterconnection( - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.BridgeBasedBuilder() - .setBridgeDomain(state.getBridgeDomain()) - .setBridgedVirtualInterface(state.isBridgedVirtualInterface()) - .setSplitHorizonGroup(state.getSplitHorizonGroup()) - .build()); - } - - return Initialized.create(getCfgId(id), builder.setRewrite(readValue.getRewrite()).build()); - } - - static InstanceIdentifier getCfgId( - final InstanceIdentifier id) { - return SubInterfaceCustomizer.getCfgId(RWUtils.cutId(id, SubInterface.class)) - .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2.class); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceRoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceRoutingCustomizer.java deleted file mode 100644 index 2a6c7406e..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceRoutingCustomizer.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static io.fd.hc2vpp.v3po.util.SubInterfaceUtils.subInterfaceFullNameOperational; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; -import io.fd.jvpp.core.future.FutureJVppCore; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.Routing; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.RoutingBuilder; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - - -public class SubInterfaceRoutingCustomizer extends RoutingCustomizer implements - InitializingReaderCustomizer { - public SubInterfaceRoutingCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore, interfaceContext); - } - - @Nonnull - @Override - public Initialized init(@Nonnull final InstanceIdentifier instanceIdentifier, - @Nonnull final Routing routing, - @Nonnull final ReadContext readContext) { - return Initialized.create(instanceIdentifier, routing); - } - - @Nonnull - @Override - public RoutingBuilder getBuilder(@Nonnull final InstanceIdentifier instanceIdentifier) { - return new RoutingBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier instanceIdentifier, - @Nonnull final RoutingBuilder routingBuilder, - @Nonnull final ReadContext readContext) - throws ReadFailedException { - readInterfaceRouting(instanceIdentifier, routingBuilder::setIpv4VrfId, routingBuilder::setIpv6VrfId, - readContext, subInterfaceFullNameOperational(instanceIdentifier)); - } - - @Override - public void merge(@Nonnull final Builder builder, @Nonnull final Routing routing) { - ((SubInterfaceBuilder)builder).setRouting(routing); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/TapV2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/TapV2Customizer.java deleted file mode 100644 index dab689416..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/TapV2Customizer.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright (c) 2018 Pantheon Technologies and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static com.google.common.base.Preconditions.checkState; -import static java.lang.String.format; - -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.Ipv4Translator; -import io.fd.hc2vpp.common.translate.util.Ipv6Translator; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.MacTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; -import io.fd.honeycomb.translate.util.read.cache.StaticCacheKeyFactory; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import io.fd.jvpp.core.dto.SwInterfaceTapV2Details; -import io.fd.jvpp.core.dto.SwInterfaceTapV2DetailsReplyDump; -import io.fd.jvpp.core.dto.SwInterfaceTapV2Dump; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.Optional; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.TapV2; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.TapV2Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public class TapV2Customizer extends FutureJVppCustomizer - implements InitializingReaderCustomizer, InterfaceDataTranslator, JvppReplyConsumer, - MacTranslator, Ipv4Translator, Ipv6Translator{ - - private static final Logger LOG = LoggerFactory.getLogger(TapV2Customizer.class); - private NamingContext interfaceContext; - private final InterfaceCacheDumpManager dumpManager; - private final DumpCacheManager tapV2DumpManager; - - public TapV2Customizer(@Nonnull final FutureJVppCore jvpp, - @Nonnull final NamingContext interfaceContext, - @Nonnull final InterfaceCacheDumpManager dumpManager) { - super(jvpp); - this.interfaceContext = interfaceContext; - this.dumpManager = dumpManager; - this.tapV2DumpManager = new DumpCacheManager.DumpCacheManagerBuilder() - .withCacheKeyFactory(new StaticCacheKeyFactory(TapV2Customizer.class.getName() + "_dump", - SwInterfaceTapV2DetailsReplyDump.class)) - .withExecutor((identifier, params) -> { - // Full TapV2 dump has to be performed here, no filter or anything is here to help so at least we cache it - return getReplyForRead(getFutureJVpp() - .swInterfaceTapV2Dump(new SwInterfaceTapV2Dump()).toCompletableFuture(), identifier); - }).build(); - } - - @Override - public void merge(@Nonnull Builder parentBuilder, @Nonnull TapV2 readValue) { - ((VppInterfaceStateAugmentationBuilder) parentBuilder).setTapV2(readValue); - } - - @Nonnull - @Override - public TapV2Builder getBuilder(@Nonnull InstanceIdentifier id) { - return new TapV2Builder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final TapV2Builder builder, - @Nonnull final ReadContext ctx) throws ReadFailedException { - - final InterfaceKey key = id.firstKeyOf(Interface.class); - final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext()); - if (!isInterfaceOfType(dumpManager, id, ctx, - org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.TapV2.class)) { - return; - } - - LOG.debug("Reading attributes for tapV2 interface: {}", key.getName()); - final SwInterfaceTapV2DetailsReplyDump reply = tapV2DumpManager.getDump(id, ctx.getModificationCache()) - .orElse(new SwInterfaceTapV2DetailsReplyDump()); - - final Optional detail = reply.swInterfaceTapV2Details.stream() - .filter(d -> d.swIfIndex == index) - .findAny(); - - checkState(detail.isPresent(), "TapV2 interface for index %s not found", index); - final SwInterfaceTapV2Details swInterfaceTapV2Details = detail.get(); - - LOG.trace("TapV2 interface: {} attributes returned from VPP: {}", key.getName(), swInterfaceTapV2Details); - if (swInterfaceTapV2Details.devName != null && swInterfaceTapV2Details.devName[0] != 0) { - builder.setDeviceName(toString(swInterfaceTapV2Details.devName)); - } else { - builder.setDeviceName(null); - } - - if (swInterfaceTapV2Details.hostBridge != null && swInterfaceTapV2Details.hostBridge[0] != 0) { - builder.setHostBridge(toString(swInterfaceTapV2Details.hostBridge)); - } else { - builder.setHostBridge(null); - } - - if (swInterfaceTapV2Details.hostMacAddr != null && - !ByteDataTranslator.INSTANCE.isArrayZeroed(swInterfaceTapV2Details.hostMacAddr)) { - builder.setHostMac(toPhysAddress(swInterfaceTapV2Details.hostMacAddr)); - } else { - builder.setHostMac(null); - } - - if (swInterfaceTapV2Details.hostIfName != null && swInterfaceTapV2Details.hostIfName[0] != 0) { - builder.setHostInterfaceName(toString(swInterfaceTapV2Details.hostIfName)); - } else { - builder.setHostInterfaceName(null); - } - - if (swInterfaceTapV2Details.hostIp4Addr != null && swInterfaceTapV2Details.hostIp4PrefixLen != 0) { - builder.setHostIpv4Address( - toIpv4Prefix(swInterfaceTapV2Details.hostIp4Addr, swInterfaceTapV2Details.hostIp4PrefixLen)); - } else { - builder.setHostIpv4Address(null); - } - - if (swInterfaceTapV2Details.hostIp6Addr != null && swInterfaceTapV2Details.hostIp6PrefixLen != 0) { - builder.setHostIpv6Address( - toIpv6Prefix(swInterfaceTapV2Details.hostIp6Addr, - Byte.toUnsignedInt(swInterfaceTapV2Details.hostIp6PrefixLen))); - } else { - builder.setHostIpv6Address(null); - } - - if (swInterfaceTapV2Details.hostNamespace != null && swInterfaceTapV2Details.hostNamespace[0] != 0) { - builder.setHostNamespace(toString(swInterfaceTapV2Details.hostNamespace)); - } else { - builder.setHostNamespace(null); - } - - - builder.setRxRingSize(Short.toUnsignedInt(swInterfaceTapV2Details.rxRingSz)); - builder.setTxRingSize(Short.toUnsignedInt(swInterfaceTapV2Details.txRingSz)); - final SwInterfaceDetails ifcDetails = dumpManager.getInterfaceDetail(id, ctx, key.getName()); - - if (ifcDetails.tag[0] != 0) { // tag supplied - builder.setTag(toString(ifcDetails.tag)); - } - LOG.debug("TapV2 interface: {}, id: {} attributes read as: {}", key.getName(), index, builder); - } - - @Override - public Initialized init( - @Nonnull final InstanceIdentifier id, @Nonnull final TapV2 readValue, - @Nonnull final ReadContext ctx) { - // The MAC address & tag is set from interface details, those details are retrieved from cache - final InterfaceKey key = id.firstKeyOf(Interface.class); - - final SwInterfaceDetails ifcDetails; - try { - ifcDetails = dumpManager.getInterfaceDetail(id, ctx, key.getName()); - } catch (ReadFailedException e) { - throw new IllegalStateException(format("Unable to read interface %s", key.getName()), e); - } - - return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2Builder() - .setMac(new PhysAddress(vppPhysAddrToYang(ifcDetails.l2Address))) - .setHostInterfaceName(readValue.getHostInterfaceName()) - .setTag(ifcDetails.tag[0] == 0 - ? null - : toString(ifcDetails.tag)) - .setHostBridge(readValue.getHostBridge()) - .setHostIpv4Address(readValue.getHostIpv4Address()) - .setHostIpv6Address(readValue.getHostIpv6Address()) - .setRxRingSize(readValue.getRxRingSize()) - .setTxRingSize(readValue.getTxRingSize()) - .setHostMac(readValue.getHostMac()) - .setHostNamespace(readValue.getHostNamespace()) - .build()); - } - - private InstanceIdentifier getCfgId( - final InstanceIdentifier id) { - return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) - .augmentation(VppInterfaceAugmentation.class) - .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2.class); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VhostUserCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VhostUserCustomizer.java deleted file mode 100644 index a93577c44..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VhostUserCustomizer.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static java.lang.String.format; - -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; -import io.fd.honeycomb.translate.util.read.cache.StaticCacheKeyFactory; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import io.fd.jvpp.core.dto.SwInterfaceVhostUserDetails; -import io.fd.jvpp.core.dto.SwInterfaceVhostUserDetailsReplyDump; -import io.fd.jvpp.core.dto.SwInterfaceVhostUserDump; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.math.BigInteger; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUserRole; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.VhostUser; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.VhostUserBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class VhostUserCustomizer implements InitializingReaderCustomizer, - InterfaceDataTranslator, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(VhostUserCustomizer.class); - private NamingContext interfaceContext; - private final InterfaceCacheDumpManager dumpManager; - private final DumpCacheManager vhostDumpManager; - - public VhostUserCustomizer(@Nonnull final FutureJVppCore jvpp, - @Nonnull final NamingContext interfaceContext, - @Nonnull final InterfaceCacheDumpManager dumpManager) { - this.interfaceContext = interfaceContext; - this.dumpManager = dumpManager; - this.vhostDumpManager = - new DumpCacheManager.DumpCacheManagerBuilder() - .withCacheKeyFactory(new StaticCacheKeyFactory(VhostUserCustomizer.class.getName() + "_dump", - SwInterfaceVhostUserDetailsReplyDump.class)) - .withExecutor((identifier, params) -> { - final CompletionStage - swInterfaceVhostUserDetailsReplyDumpCompletionStage = - jvpp.swInterfaceVhostUserDump(new SwInterfaceVhostUserDump()); - return getReplyForRead( - swInterfaceVhostUserDetailsReplyDumpCompletionStage.toCompletableFuture(), - identifier); - }).build(); - } - - @Override - public void merge(@Nonnull Builder parentBuilder, @Nonnull VhostUser readValue) { - ((VppInterfaceStateAugmentationBuilder) parentBuilder).setVhostUser(readValue); - } - - @Nonnull - @Override - public VhostUserBuilder getBuilder(@Nonnull InstanceIdentifier id) { - return new VhostUserBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final VhostUserBuilder builder, - @Nonnull final ReadContext ctx) throws ReadFailedException { - - final InterfaceKey key = id.firstKeyOf(Interface.class); - final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext()); - final SwInterfaceDetails ifcDetails = dumpManager.getInterfaceDetail(id, ctx, key.getName()); - - - if (!isInterfaceOfType( - org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUser.class, - ifcDetails)) { - return; - } - - LOG.debug("Reading attributes for vhpost user interface: {}", key.getName()); - - - final SwInterfaceVhostUserDetailsReplyDump dump = - vhostDumpManager.getDump(id, ctx.getModificationCache()) - .orElse(new SwInterfaceVhostUserDetailsReplyDump()); - - // Relying here that parent InterfaceCustomizer was invoked first to fill in the context with initial ifc mapping - final SwInterfaceVhostUserDetails swInterfaceVhostUserDetails = dump.swInterfaceVhostUserDetails.stream() - .filter(detail -> detail.swIfIndex == index) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException( - format("Vhost user for interface %s not found", key.getName()))); - LOG.trace("Vhost user interface: {} attributes returned from VPP: {}", key.getName(), - swInterfaceVhostUserDetails); - - builder.setRole(swInterfaceVhostUserDetails.isServer == 1 - ? VhostUserRole.Server - : VhostUserRole.Client); - builder.setFeatures(BigInteger.valueOf(swInterfaceVhostUserDetails.features)); - builder.setNumMemoryRegions((long) swInterfaceVhostUserDetails.numRegions); - builder.setSocket(toString(swInterfaceVhostUserDetails.sockFilename)); - builder.setVirtioNetHdrSize((long) swInterfaceVhostUserDetails.virtioNetHdrSz); - // TODO: map error code to meaningful message after VPP-436 is done - builder.setConnectError(Integer.toString(swInterfaceVhostUserDetails.sockErrno)); - if (ifcDetails.tag[0] != 0) { // tag supplied - builder.setTag(toString(ifcDetails.tag)); - } - - LOG.debug("Vhost user interface: {}, id: {} attributes read as: {}", key.getName(), index, builder); - } - - @Override - public Initialized init( - @Nonnull final InstanceIdentifier id, - @Nonnull final VhostUser readValue, - @Nonnull final ReadContext ctx) { - // The tag is set from interface details, those details are retrieved from cache - final InterfaceKey key = id.firstKeyOf(Interface.class); - final SwInterfaceDetails ifcDetails; - try { - ifcDetails = dumpManager.getInterfaceDetail(id, ctx, key.getName()); - } catch (ReadFailedException e) { - throw new IllegalStateException(format("Unable to find VHost interface %s", key.getName()), e); - } - return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUserBuilder() - .setRole(readValue.getRole()) - .setSocket(readValue.getSocket()) - .setTag(ifcDetails.tag[0] == 0 - ? null - : toString(ifcDetails.tag)) - .build()); - } - - private InstanceIdentifier getCfgId( - final InstanceIdentifier id) { - return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) - .augmentation(VppInterfaceAugmentation.class) - .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUser.class); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizer.java deleted file mode 100644 index f4d6aed58..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizer.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static com.google.common.base.Preconditions.checkState; - -import com.google.common.primitives.UnsignedInts; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.Ipv4Translator; -import io.fd.hc2vpp.common.translate.util.Ipv6Translator; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.jvpp.core.dto.VxlanTunnelDetails; -import io.fd.jvpp.core.dto.VxlanTunnelDetailsReplyDump; -import io.fd.jvpp.core.dto.VxlanTunnelDump; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.L2Input; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.NshProxy; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanTunnel; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanVni; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.Vxlan; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.VxlanBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class VxlanCustomizer extends FutureJVppCustomizer - implements InitializingReaderCustomizer, InterfaceDataTranslator, JvppReplyConsumer, - Ipv4Translator, Ipv6Translator { - - private static final Logger LOG = LoggerFactory.getLogger(VxlanCustomizer.class); - private final NamingContext interfaceContext; - private final InterfaceCacheDumpManager dumpManager; - - public VxlanCustomizer(@Nonnull final FutureJVppCore jvpp, @Nonnull final NamingContext interfaceContext, - @Nonnull final InterfaceCacheDumpManager dumpManager) { - super(jvpp); - this.interfaceContext = interfaceContext; - this.dumpManager = dumpManager; - } - - @Override - public void merge(@Nonnull Builder parentBuilder, - @Nonnull Vxlan readValue) { - ((VppInterfaceStateAugmentationBuilder) parentBuilder).setVxlan(readValue); - } - - @Nonnull - @Override - public VxlanBuilder getBuilder(@Nonnull InstanceIdentifier id) { - return new VxlanBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final VxlanBuilder builder, - @Nonnull final ReadContext ctx) throws ReadFailedException { - - final InterfaceKey key = id.firstKeyOf(Interface.class); - final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext()); - if (!isInterfaceOfType(dumpManager, id, ctx, VxlanTunnel.class)) { - return; - } - - LOG.debug("Reading attributes for vxlan tunnel: {}", key.getName()); - // Dump just a single - final VxlanTunnelDump request = new VxlanTunnelDump(); - request.swIfIndex = index; - - final CompletionStage swInterfaceVxlanDetailsReplyDumpCompletionStage = - getFutureJVpp().vxlanTunnelDump(request); - final VxlanTunnelDetailsReplyDump reply = - getReplyForRead(swInterfaceVxlanDetailsReplyDumpCompletionStage.toCompletableFuture(), id); - - // VPP keeps vxlan tunnel interfaces even after they were deleted (optimization) - // However there ar no longer any vxlan tunnel specific fields assigned to it and this call - // returns nothing - if (reply == null || reply.vxlanTunnelDetails == null || reply.vxlanTunnelDetails.isEmpty()) { - LOG.debug( - "Vxlan tunnel {}, id {} has no attributes assigned in VPP. Probably is a leftover interface placeholder" + - "after delete", key.getName(), index); - return; - } - - checkState(reply.vxlanTunnelDetails.size() == 1, - "Unexpected number of returned vxlan tunnels: {} for tunnel: {}", reply.vxlanTunnelDetails, - key.getName()); - LOG.trace("Vxlan tunnel: {} attributes returned from VPP: {}", key.getName(), reply); - - final VxlanTunnelDetails swInterfaceVxlanDetails = reply.vxlanTunnelDetails.get(0); - if (swInterfaceVxlanDetails.isIpv6 == 1) { - builder.setDst(new IpAddressNoZone(arrayToIpv6AddressNoZone(swInterfaceVxlanDetails.dstAddress))); - builder.setSrc(new IpAddressNoZone(arrayToIpv6AddressNoZone(swInterfaceVxlanDetails.srcAddress))); - } else { - builder.setDst(new IpAddressNoZone(arrayToIpv4AddressNoZone(swInterfaceVxlanDetails.dstAddress))); - builder.setSrc(new IpAddressNoZone(arrayToIpv4AddressNoZone(swInterfaceVxlanDetails.srcAddress))); - } - builder.setEncapVrfId(new VniReference(UnsignedInts.toLong(swInterfaceVxlanDetails.encapVrfId))); - builder.setVni(new VxlanVni(UnsignedInts.toLong(swInterfaceVxlanDetails.vni))); - switch (swInterfaceVxlanDetails.decapNextIndex) { - case 1: - builder.setDecapNext(L2Input.class); - break; - case 2: - builder.setDecapNext(NshProxy.class); - break; - default: - LOG.trace("Unsupported decap next index for vxlan: {}", swInterfaceVxlanDetails.decapNextIndex); - return; - } - LOG.debug("Vxlan tunnel: {}, id: {} attributes read as: {}", key.getName(), index, builder); - } - - @Override - public Initialized init( - @Nonnull final InstanceIdentifier id, @Nonnull final Vxlan readValue, - @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanBuilder() - .setDst(readValue.getDst()) - .setSrc(readValue.getSrc()) - .setEncapVrfId(readValue.getEncapVrfId()) - .setVni(new VxlanVni(readValue.getVni())) - .setDecapNext(readValue.getDecapNext()) - .build()); - } - - private InstanceIdentifier getCfgId( - final InstanceIdentifier id) { - return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) - .augmentation(VppInterfaceAugmentation.class) - .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Vxlan.class); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizer.java deleted file mode 100644 index 4e275b01b..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizer.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static com.google.common.base.Preconditions.checkState; - -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.Ipv4Translator; -import io.fd.hc2vpp.common.translate.util.Ipv6Translator; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.jvpp.core.dto.VxlanGpeTunnelDetails; -import io.fd.jvpp.core.dto.VxlanGpeTunnelDetailsReplyDump; -import io.fd.jvpp.core.dto.VxlanGpeTunnelDump; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeNextProtocol; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeTunnel; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeVni; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.VxlanGpe; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.VxlanGpeBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class VxlanGpeCustomizer extends FutureJVppCustomizer - implements InitializingReaderCustomizer, InterfaceDataTranslator, JvppReplyConsumer, - Ipv4Translator, Ipv6Translator { - - private static final Logger LOG = LoggerFactory.getLogger(VxlanGpeCustomizer.class); - private final NamingContext interfaceContext; - private final InterfaceCacheDumpManager dumpManager; - - public VxlanGpeCustomizer(@Nonnull final FutureJVppCore jvpp, - @Nonnull final NamingContext interfaceContext, - @Nonnull final InterfaceCacheDumpManager dumpManager) { - super(jvpp); - this.interfaceContext = interfaceContext; - this.dumpManager = dumpManager; - } - - @Override - public void merge(@Nonnull Builder parentBuilder, - @Nonnull VxlanGpe readValue) { - ((VppInterfaceStateAugmentationBuilder) parentBuilder).setVxlanGpe(readValue); - } - - @Nonnull - @Override - public VxlanGpeBuilder getBuilder(@Nonnull InstanceIdentifier id) { - return new VxlanGpeBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final VxlanGpeBuilder builder, - @Nonnull final ReadContext ctx) throws ReadFailedException { - - final InterfaceKey key = id.firstKeyOf(Interface.class); - final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext()); - if (!isInterfaceOfType(dumpManager, id, ctx, VxlanGpeTunnel.class)) { - return; - } - - LOG.debug("Reading attributes for VxlanGpe tunnel: {}", key.getName()); - // Dump just a single - final VxlanGpeTunnelDump request = new VxlanGpeTunnelDump(); - request.swIfIndex = index; - - final CompletionStage swInterfaceVxlanGpeDetailsReplyDumpCompletionStage = - getFutureJVpp().vxlanGpeTunnelDump(request); - final VxlanGpeTunnelDetailsReplyDump reply = - getReplyForRead(swInterfaceVxlanGpeDetailsReplyDumpCompletionStage.toCompletableFuture(), - id); - - // VPP keeps VxlanGpe tunnel interfaces even after they were deleted (optimization) - // However there are no longer any VxlanGpe tunnel specific fields assigned to it and this call - // returns nothing - if (reply == null || reply.vxlanGpeTunnelDetails == null || reply.vxlanGpeTunnelDetails.isEmpty()) { - LOG.debug( - "VxlanGpe tunnel {}, id {} has no attributes assigned in VPP. Probably is a leftover interface placeholder" + - "after delete", key.getName(), index); - return; - } - - checkState(reply.vxlanGpeTunnelDetails.size() == 1, - "Unexpected number of returned VxlanGpe tunnels: {} for tunnel: {}", reply.vxlanGpeTunnelDetails, - key.getName()); - LOG.trace("VxlanGpe tunnel: {} attributes returned from VPP: {}", key.getName(), reply); - - final VxlanGpeTunnelDetails swInterfaceVxlanGpeDetails = reply.vxlanGpeTunnelDetails.get(0); - if (swInterfaceVxlanGpeDetails.isIpv6 == 1) { - builder.setRemote(new IpAddressNoZone(arrayToIpv6AddressNoZone(swInterfaceVxlanGpeDetails.remote))); - builder.setLocal(new IpAddressNoZone(arrayToIpv6AddressNoZone(swInterfaceVxlanGpeDetails.local))); - } else { - builder.setRemote(new IpAddressNoZone(arrayToIpv4AddressNoZone(swInterfaceVxlanGpeDetails.remote))); - builder.setLocal(new IpAddressNoZone(arrayToIpv4AddressNoZone(swInterfaceVxlanGpeDetails.local))); - } - builder.setVni(new VxlanGpeVni((long) swInterfaceVxlanGpeDetails.vni)); - builder.setNextProtocol(VxlanGpeNextProtocol.forValue(swInterfaceVxlanGpeDetails.protocol)); - builder.setEncapVrfId((long) swInterfaceVxlanGpeDetails.encapVrfId); - builder.setDecapVrfId((long) swInterfaceVxlanGpeDetails.decapVrfId); - LOG.debug("VxlanGpe tunnel: {}, id: {} attributes read as: {}", key.getName(), index, builder); - } - - @Override - public Initialized init( - @Nonnull final InstanceIdentifier id, @Nonnull final VxlanGpe readValue, - @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpeBuilder() - .setLocal(readValue.getLocal()) - .setRemote(readValue.getRemote()) - .setVni(new VxlanGpeVni(readValue.getVni())) - .setNextProtocol(readValue.getNextProtocol()) - .setEncapVrfId(readValue.getEncapVrfId()) - .setDecapVrfId(readValue.getDecapVrfId()) - .build()); - } - - private InstanceIdentifier getCfgId( - final InstanceIdentifier id) { - return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) - .augmentation(VppInterfaceAugmentation.class) - .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpe.class); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManager.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManager.java deleted file mode 100644 index c570e0d80..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManager.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate.cache; - -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import java.util.stream.Stream; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -/** - * Manager for dump data of interfaces. The main purpose of this manager is to cache common interface data between - * various classes that process this kind of data. If reader does not use this utility, it introduces a big overhead - * because of size/complexity of interfaces dump - */ -public interface InterfaceCacheDumpManager { - - /** - * Provides stream of all currently configured vpp interfaces - * - * @param identifier id of currently processed data - * @param ctx context of current transaction - * @return {@link Stream} of currently configured interfaces - * @throws ReadFailedException if dumping of data was unsuccessful - */ - @Nonnull - Stream getInterfaces(@Nonnull final InstanceIdentifier identifier, - @Nonnull final ReadContext ctx) throws ReadFailedException; - - /** - * Provides details of interface - * - * @param identifier id of currently processed data - * @param ctx context of current transaction - * @param interfaceName name of requested interface - * @return {@link SwInterfaceDetails} of requested interface - * @throws ReadFailedException if dumping of data was unsuccessful - */ - @Nullable - SwInterfaceDetails getInterfaceDetail(@Nonnull final InstanceIdentifier identifier, - @Nonnull final ReadContext ctx, - @Nonnull final String interfaceName) throws ReadFailedException; -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManagerImpl.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManagerImpl.java deleted file mode 100644 index f0f08d9d7..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManagerImpl.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate.cache; - -import static io.fd.hc2vpp.common.translate.util.JvppReplyConsumer.INSTANCE; -import static java.util.stream.Collectors.toMap; - -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.ModificationCache; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; -import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; -import io.fd.honeycomb.translate.util.read.cache.StaticCacheKeyFactory; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import io.fd.jvpp.core.dto.SwInterfaceDetailsReplyDump; -import io.fd.jvpp.core.dto.SwInterfaceDump; -import io.fd.jvpp.core.future.FutureJVppCore; -import io.fd.jvpp.core.types.InterfaceIndex; -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.stream.Stream; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Manager for dump data of interfaces/sub-interfaces - */ -final class InterfaceCacheDumpManagerImpl implements InterfaceCacheDumpManager { - - private static final Logger LOG = LoggerFactory.getLogger(InterfaceCacheDumpManagerImpl.class); - - // byNameIndex must be cached, not held as reference here, to have it destroyed with cache after transaction - static final String BY_NAME_INDEX_KEY = InterfaceCacheDumpManagerImpl.class.getName() + "_byNameIndex"; - private NamingContext namingContext; - private final DumpCacheManager specificDumpManager; - private final DumpCacheManager fullDumpManager; - - InterfaceCacheDumpManagerImpl(@Nonnull final FutureJVppCore jvpp, - @Nonnull final NamingContext namingContext) { - this.namingContext = namingContext; - specificDumpManager = specificInterfaceDumpManager(jvpp); - fullDumpManager = fullInterfaceDumpManager(jvpp, - new StaticCacheKeyFactory(InterfaceCacheDumpManagerImpl.class.getName() + "_dump", SwInterfaceDetailsReplyDump.class)); - } - - @Override - @Nonnull - public synchronized Stream getInterfaces(@Nonnull final InstanceIdentifier identifier, - @Nonnull final ReadContext ctx) - throws ReadFailedException { - LOG.debug("Reading all interfaces[{}]", identifier); - return initMapAndGet(identifier, ctx).entrySet().stream().map(Map.Entry::getValue); - } - - @Override - @Nullable - public synchronized SwInterfaceDetails getInterfaceDetail(@Nonnull final InstanceIdentifier identifier, - @Nonnull final ReadContext ctx, - @Nonnull final String interfaceName) - throws ReadFailedException { - final Map interfaceIndex = getMap(ctx); - - // does not attempt to cover cases with concurrent updates, as tx should be atomic - if (interfaceIndex != null) { - // tries to find interface in map - return interfaceIndex.get(interfaceName); - } else { - // if map is not present, use specific dump(it will be cached standard way, under key constructed from IID) - return dumpSpecificDetail(identifier, ctx, interfaceName); - } - } - - private SwInterfaceDetails dumpSpecificDetail(@Nonnull final InstanceIdentifier identifier, - @Nonnull final ReadContext ctx, - @Nonnull final String interfaceName) - throws ReadFailedException { - LOG.debug("Interface {} not present in cached data, performing specific dump[{}]", interfaceName, - identifier); - final SwInterfaceDetailsReplyDump reply = - specificDumpManager.getDump(identifier, ctx.getModificationCache(), interfaceName) - .orElse(new SwInterfaceDetailsReplyDump()); - - if (reply.swInterfaceDetails.isEmpty()) { - return null; - } - - return reply.swInterfaceDetails.get(0); - } - - private Map initMapAndGet(final InstanceIdentifier identifier, final ReadContext ctx) - throws ReadFailedException { - - final ModificationCache cache = ctx.getModificationCache(); - if (!cache.containsKey(BY_NAME_INDEX_KEY)) { - LOG.debug("Performing dump[{}]", identifier); - final SwInterfaceDetailsReplyDump dump = - fullDumpManager.getDump(identifier, cache) - .orElse(new SwInterfaceDetailsReplyDump()); - - // naming context initialization must be done here, as it is uses getName in next step, therefore it would - // create artificial mapping for every interface, because this happens before interface dump is processed - dump.swInterfaceDetails.forEach((elt) -> { - // Store interface name from VPP in context if not yet present - if (!namingContext.containsName(elt.swIfIndex, ctx.getMappingContext())) { - namingContext.addName(elt.swIfIndex, ByteDataTranslator.INSTANCE.toString(elt.interfaceName), - ctx.getMappingContext()); - } - LOG.trace("Interface with name: {}, VPP name: {} and index: {} found in VPP", - getInterfaceName(ctx, elt), - elt.interfaceName, - elt.swIfIndex); - }); - - final Map freshIndex = dump.swInterfaceDetails.stream() - .collect(toMap(detail -> getInterfaceName(ctx, detail), - detail -> detail)); - putMap(freshIndex, ctx); - } - - return getMap(ctx); - } - - private String getInterfaceName(final ReadContext ctx, final SwInterfaceDetails elt) { - return namingContext.getName(elt.swIfIndex, ctx.getMappingContext()); - } - - private static Map getMap(final ReadContext ctx) { - return (Map) ctx.getModificationCache().get(BY_NAME_INDEX_KEY); - } - - private static void putMap(final Map map, final ReadContext ctx) { - ctx.getModificationCache().put(BY_NAME_INDEX_KEY, map); - } - - - private static DumpCacheManager fullInterfaceDumpManager( - final FutureJVppCore jvpp, - final StaticCacheKeyFactory cacheKeyFactory) { - return new DumpCacheManager.DumpCacheManagerBuilder() - .withExecutor(fullInterfaceDumpExecutor(jvpp)) - .withCacheKeyFactory(cacheKeyFactory) - .acceptOnly(SwInterfaceDetailsReplyDump.class) - .build(); - } - - private static DumpCacheManager specificInterfaceDumpManager( - final FutureJVppCore jvpp) { - return new DumpCacheManager.DumpCacheManagerBuilder() - .withExecutor(specificInterfaceDumpExecutor(jvpp)) - .acceptOnly(SwInterfaceDetailsReplyDump.class) - .build(); - } - - private static EntityDumpExecutor fullInterfaceDumpExecutor( - final FutureJVppCore api) { - return (identifier, params) -> { - final SwInterfaceDump request = new SwInterfaceDump(); - request.swIfIndex = new InterfaceIndex(); - request.swIfIndex.interfaceindex = ~0; - request.nameFilter = "".getBytes(); - request.nameFilterValid = 0; - - final CompletableFuture - swInterfaceDetailsReplyDumpCompletableFuture = api.swInterfaceDump(request).toCompletableFuture(); - return INSTANCE.getReplyForRead(swInterfaceDetailsReplyDumpCompletableFuture, identifier); - }; - } - - private static EntityDumpExecutor specificInterfaceDumpExecutor( - final FutureJVppCore api) { - return (identifier, ifaceName) -> { - final SwInterfaceDump request = new SwInterfaceDump(); - request.swIfIndex = new InterfaceIndex(); - request.swIfIndex.interfaceindex =~0; - request.nameFilter = ifaceName.getBytes(); - request.nameFilterValid = 1; - - final CompletableFuture - swInterfaceDetailsReplyDumpCompletableFuture = api.swInterfaceDump(request).toCompletableFuture(); - return INSTANCE.getReplyForRead(swInterfaceDetailsReplyDumpCompletableFuture, identifier); - }; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManagerProvider.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManagerProvider.java deleted file mode 100644 index b5a010670..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManagerProvider.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate.cache; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.jvpp.core.future.FutureJVppCore; -import javax.inject.Named; - -public class InterfaceCacheDumpManagerProvider implements Provider { - - @Inject - private FutureJVppCore jvpp; - - @Inject - @Named("interface-context") - private NamingContext namingContext; - - @Override - public InterfaceCacheDumpManager get() { - return new InterfaceCacheDumpManagerImpl(jvpp, namingContext); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceStatisticsManager.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceStatisticsManager.java deleted file mode 100644 index 0c5e36248..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceStatisticsManager.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate.cache; - -public interface InterfaceStatisticsManager { - - boolean isStatisticsEnabled(); - - void enableStatistics(); - - void disableStatistics(); -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceStatisticsManagerImpl.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceStatisticsManagerImpl.java deleted file mode 100644 index 0543fe745..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceStatisticsManagerImpl.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate.cache; - -public class InterfaceStatisticsManagerImpl implements InterfaceStatisticsManager { - - private boolean isEnabled; - - @Override - public boolean isStatisticsEnabled() { - return isEnabled; - } - - @Override - public void enableStatistics() { - isEnabled = true; - } - - @Override - public void disableStatistics() { - isEnabled = false; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceStatisticsManagerProvider.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceStatisticsManagerProvider.java deleted file mode 100644 index 7306efcfd..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceStatisticsManagerProvider.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate.cache; - -import com.google.inject.Provider; - -public class InterfaceStatisticsManagerProvider implements Provider { - - @Override - public InterfaceStatisticsManager get() { - return new InterfaceStatisticsManagerImpl(); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/pbb/PbbRewriteStateCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/pbb/PbbRewriteStateCustomizer.java deleted file mode 100644 index cd1c9d571..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/pbb/PbbRewriteStateCustomizer.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate.pbb; - -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.core.future.FutureJVppCore; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.PbbRewriteStateInterfaceAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces.state._interface.PbbRewriteState; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces.state._interface.PbbRewriteStateBuilder; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class PbbRewriteStateCustomizer extends FutureJVppCustomizer - implements ReaderCustomizer { - - public PbbRewriteStateCustomizer(@Nonnull final FutureJVppCore futureJVppCore) { - super(futureJVppCore); - } - - @Nonnull - @Override - public PbbRewriteStateBuilder getBuilder(@Nonnull final InstanceIdentifier id) { - return new PbbRewriteStateBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final PbbRewriteStateBuilder builder, @Nonnull final ReadContext ctx) - throws ReadFailedException { - //TODO implement read after https://jira.fd.io/browse/VPP-468 + init - } - - @Override - public void merge(@Nonnull final Builder parentBuilder, - @Nonnull final PbbRewriteState readValue) { - ((PbbRewriteStateInterfaceAugmentationBuilder) parentBuilder).setPbbRewriteState(readValue); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/AbstractMirroredInterfacesCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/AbstractMirroredInterfacesCustomizer.java deleted file mode 100644 index 1c063bad2..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/AbstractMirroredInterfacesCustomizer.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate.span; - -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.MappingContext; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; -import io.fd.jvpp.core.dto.SwInterfaceSpanDetailsReplyDump; -import io.fd.jvpp.core.dto.SwInterfaceSpanDump; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.SpanState; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.state.attributes.MirroredInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.state.attributes.MirroredInterfacesBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.state.attributes.mirrored.interfaces.MirroredInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.state.attributes.mirrored.interfaces.MirroredInterfaceBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.state.attributes.mirrored.interfaces.MirroredInterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -abstract class AbstractMirroredInterfacesCustomizer - extends FutureJVppCustomizer - implements InitializingReaderCustomizer, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(AbstractMirroredInterfacesCustomizer.class); - - private final NamingContext ifcContext; - private final Function, String> destinationInterfaceNameExtractor; - - protected AbstractMirroredInterfacesCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext ifcContext, - @Nonnull final Function, String> destinationInterfaceNameExtractor) { - super(futureJVppCore); - this.ifcContext = ifcContext; - this.destinationInterfaceNameExtractor = destinationInterfaceNameExtractor; - } - - @Nonnull - @Override - public MirroredInterfacesBuilder getBuilder(@Nonnull final InstanceIdentifier id) { - return new MirroredInterfacesBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final MirroredInterfacesBuilder builder, @Nonnull final ReadContext ctx) - throws ReadFailedException { - LOG.trace("Reading mirrored interfaces under: {}", id); - final int dstId = destinationInterfaceIndex(id, ctx.getMappingContext()); - - final SwInterfaceSpanDetailsReplyDump replyForRead; - if (ctx.getModificationCache().containsKey(getCacheKey())) { - replyForRead = (SwInterfaceSpanDetailsReplyDump) ctx.getModificationCache().get(getCacheKey()); - } else { - replyForRead = getReplyForRead(getFutureJVpp().swInterfaceSpanDump( - new SwInterfaceSpanDump()).toCompletableFuture(), id); - ctx.getModificationCache().put(getCacheKey(), replyForRead); - } - - final List mirroredInterfaces = - replyForRead.swInterfaceSpanDetails.stream() - .filter(detail -> detail.swIfIndexTo == dstId) - .filter(detail -> detail.state != 0) // filters disabled(we use disabled as delete) - .map(detail -> { - final String interfaceName = - ifcContext.getName(detail.swIfIndexFrom, ctx.getMappingContext()); - return new MirroredInterfaceBuilder() - .setIfaceRef(interfaceName) - .withKey(new MirroredInterfaceKey(interfaceName)) - .setState(SpanState.forValue(detail.state)) - .build(); - } - ) - .collect(Collectors.toList()); - - LOG.debug("Mirrored interfaces for: {} read as: {}", id, mirroredInterfaces); - - if (!mirroredInterfaces.isEmpty()) { - builder.setMirroredInterface(mirroredInterfaces); - } - } - - private String getCacheKey() { - return getClass().getName(); - } - - private int destinationInterfaceIndex(@Nonnull final InstanceIdentifier id, - @Nonnull final MappingContext mappingContext) { - final String destinationInterfaceName = destinationInterfaceNameExtractor.apply(id); - return ifcContext.getIndex(destinationInterfaceName, mappingContext); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/InterfaceMirroredInterfacesCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/InterfaceMirroredInterfacesCustomizer.java deleted file mode 100644 index 4236285c8..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/InterfaceMirroredInterfacesCustomizer.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate.span; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceCustomizer; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.Collections; -import java.util.Optional; -import java.util.stream.Collectors; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.SpanBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfacesBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceKey; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.state.attributes.MirroredInterfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -/** - * Provides interface-specific logic to read/init port mirroring configuration - */ -public class InterfaceMirroredInterfacesCustomizer extends AbstractMirroredInterfacesCustomizer { - - public InterfaceMirroredInterfacesCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext ifcContext) { - super(futureJVppCore, ifcContext, id -> id.firstKeyOf(Interface.class).getName()); - } - - @Nonnull - @Override - public Initialized init(@Nonnull final InstanceIdentifier id, - @Nonnull final MirroredInterfaces readValue, - @Nonnull final ReadContext ctx) { - final InstanceIdentifier cfgId = - InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) - .augmentation(VppInterfaceAugmentation.class) - .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Span.class) - .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces.class); - final org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces - cfgValue = new MirroredInterfacesBuilder() - .setMirroredInterface(Optional.ofNullable(readValue.getMirroredInterface()).orElse(Collections.emptyList()) - .stream() - .map(mirroredInterface -> new MirroredInterfaceBuilder() - .setState(mirroredInterface.getState()) - .withKey(new MirroredInterfaceKey(mirroredInterface.key().getIfaceRef())) - .setIfaceRef(mirroredInterface.getIfaceRef()) - .build()) - .collect(Collectors.toList())) - .build(); - return Initialized.create(cfgId, cfgValue); - } - - @Override - public void merge(@Nonnull Builder builder, @Nonnull MirroredInterfaces mirroredInterfaces) { - ((SpanBuilder) builder).setMirroredInterfaces(mirroredInterfaces); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/SubInterfaceMirroredInterfacesCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/SubInterfaceMirroredInterfacesCustomizer.java deleted file mode 100644 index 33dec5bed..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/SubInterfaceMirroredInterfacesCustomizer.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate.span; - - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceCustomizer; -import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.jvpp.core.future.FutureJVppCore; -import java.util.Collections; -import java.util.Optional; -import java.util.stream.Collectors; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev170607.VppSubinterfaceSpanAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev170607.interfaces._interface.sub.interfaces.sub._interface.Span; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev170607.interfaces.state._interface.sub.interfaces.sub._interface.SpanStateBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.state.attributes.MirroredInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -/** - * Provides sub-interface-specific logic to read/init port mirroring configuration - */ -public class SubInterfaceMirroredInterfacesCustomizer extends AbstractMirroredInterfacesCustomizer { - - public SubInterfaceMirroredInterfacesCustomizer(@Nonnull FutureJVppCore futureJVppCore, NamingContext ifcContext) { - super(futureJVppCore, ifcContext, SubInterfaceUtils::subInterfaceFullNameOperational); - } - - @Nonnull - @Override - public Initialized init(@Nonnull InstanceIdentifier id, - @Nonnull MirroredInterfaces readValue, - @Nonnull ReadContext readContext) { - final InstanceIdentifier cfgId = - SubInterfaceCustomizer.getCfgId(RWUtils.cutId(id, SubInterface.class)) - .augmentation(VppSubinterfaceSpanAugmentation.class) - .child(Span.class) - .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces.class); - - final org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces - cfgValue = new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfacesBuilder() - .setMirroredInterface( - Optional.ofNullable(readValue.getMirroredInterface()).orElse(Collections.emptyList()) - .stream() - .map(mirroredInterface -> new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceBuilder() - .withKey(new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceKey(mirroredInterface.key().getIfaceRef())) - .setIfaceRef(mirroredInterface.getIfaceRef()) - .setState(mirroredInterface.getState()) - .build()) - .collect(Collectors.toList())) - .build(); - - return Initialized.create(cfgId, cfgValue); - } - - @Override - public void merge(@Nonnull Builder builder, @Nonnull MirroredInterfaces mirroredInterfaces) { - ((SpanStateBuilder) builder).setMirroredInterfaces(mirroredInterfaces); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizer.java index 9e4bda429..182cdc546 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizer.java @@ -20,7 +20,7 @@ import com.google.common.base.Preconditions; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceDataTranslator; +import io.fd.hc2vpp.v3po.read.InterfaceDataTranslator; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/notification/InterfaceChangeNotificationProducer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/notification/InterfaceChangeNotificationProducer.java index b6dab53dc..84e8dd2b1 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/notification/InterfaceChangeNotificationProducer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/notification/InterfaceChangeNotificationProducer.java @@ -16,7 +16,6 @@ package io.fd.hc2vpp.v3po.notification; -import java.util.Optional; import com.google.common.collect.Lists; import com.google.inject.Inject; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; @@ -33,16 +32,17 @@ import io.fd.jvpp.core.dto.WantInterfaceEventsReply; import io.fd.jvpp.core.future.FutureJVppCore; import java.util.ArrayList; import java.util.Collection; +import java.util.Optional; import java.util.concurrent.CompletionStage; import java.util.concurrent.TimeoutException; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.concurrent.NotThreadSafe; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.InterfaceChange; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.InterfaceChangeBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.InterfaceDeleted; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.InterfaceDeletedBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.InterfaceNameOrIndex; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.InterfaceStateChange; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.InterfaceStateChangeBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.InterfaceStatus; import org.opendaylight.yangtools.yang.binding.Notification; import org.slf4j.Logger; @@ -105,7 +105,7 @@ final class InterfaceChangeNotificationProducer implements ManagedNotificationPr if (swInterfaceEvent.deleted == 1) { return new InterfaceDeletedBuilder().setName(getIfcName(swInterfaceEvent)).build(); } else { - return new InterfaceStateChangeBuilder() + return new InterfaceChangeBuilder() .setName(getIfcName(swInterfaceEvent)) .setAdminStatus(swInterfaceEvent.adminUpDown == 1 ? InterfaceStatus.Up @@ -166,7 +166,7 @@ final class InterfaceChangeNotificationProducer implements ManagedNotificationPr @Override public Collection> getNotificationTypes() { final ArrayList> classes = Lists.newArrayList(); - classes.add(InterfaceStateChange.class); + classes.add(InterfaceChange.class); classes.add(InterfaceDeleted.class); return classes; } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/AfPacketCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/AfPacketCustomizer.java new file mode 100644 index 000000000..0022015ec --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/AfPacketCustomizer.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2018 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static java.lang.String.format; + +import com.google.common.annotations.VisibleForTesting; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.StaticCacheKeyFactory; +import io.fd.jvpp.core.dto.AfPacketDetails; +import io.fd.jvpp.core.dto.AfPacketDetailsReplyDump; +import io.fd.jvpp.core.dto.AfPacketDump; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacket; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacketBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AfPacketCustomizer implements InitializingReaderCustomizer, + InterfaceDataTranslator, JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(AfPacketCustomizer.class); + private NamingContext interfaceContext; + private final InterfaceCacheDumpManager dumpManager; + private final DumpCacheManager afPacketDumpManager; + + public AfPacketCustomizer(@Nonnull final FutureJVppCore jvpp, + @Nonnull final NamingContext interfaceContext, + @Nonnull final InterfaceCacheDumpManager dumpManager) { + this.interfaceContext = interfaceContext; + this.dumpManager = dumpManager; + this.afPacketDumpManager = + new DumpCacheManager.DumpCacheManagerBuilder() + .withCacheKeyFactory(new StaticCacheKeyFactory(AfPacketCustomizer.class.getName() + "_dump", + AfPacketDetailsReplyDump.class)) + .withExecutor((identifier, params) -> { + final CompletionStage cs = jvpp.afPacketDump(new AfPacketDump()); + return getReplyForRead(cs.toCompletableFuture(), identifier); + }).build(); + } + + @Override + public void merge(@Nonnull Builder parentBuilder, @Nonnull AfPacket readValue) { + ((VppInterfaceAugmentationBuilder) parentBuilder).setAfPacket(readValue); + } + + @Nonnull + @Override + public AfPacketBuilder getBuilder(@Nonnull InstanceIdentifier id) { + return new AfPacketBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final AfPacketBuilder builder, + @Nonnull final ReadContext ctx) throws ReadFailedException { + final InterfaceKey key = id.firstKeyOf(Interface.class); + final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext()); + final SwInterfaceDetails ifcDetails = dumpManager.getInterfaceDetail(id, ctx, key.getName()); + + if (!isInterfaceOfType( + org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.AfPacket.class, + ifcDetails)) { + return; + } + + final AfPacketDetailsReplyDump dump = afPacketDumpManager.getDump(id, ctx.getModificationCache()) + .orElse(new AfPacketDetailsReplyDump()); + // Relying here that parent InterfaceCustomizer was invoked first to fill in the context with initial ifc mapping + final AfPacketDetails afPacketDetails = dump.afPacketDetails.stream() + .filter(detail -> detail.swIfIndex == index) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException(format("AfPacket interface %s not found", key.getName()))); + LOG.trace("AfPacket interface: {} attributes returned from VPP: {}", key.getName(), afPacketDetails); + + builder.setMac(new PhysAddress(vppPhysAddrToYang(ifcDetails.l2Address))); + builder.setHostInterfaceName(toString(afPacketDetails.hostIfName)); + + LOG.debug("AfPacket interface: {}, id: {} attributes read as: {}", key.getName(), index, builder); + } + + @Nonnull + @Override + public Initialized init( + @Nonnull final InstanceIdentifier id, + @Nonnull final AfPacket readValue, + @Nonnull final ReadContext ctx) { + return Initialized.create(getCfgId(id), + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacketBuilder() + .setHostInterfaceName(readValue.getHostInterfaceName()) + .setMac(readValue.getMac()) + .build()); + } + + @VisibleForTesting + static InstanceIdentifier getCfgId( + final InstanceIdentifier id) { + return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) + .augmentation(VppInterfaceAugmentation.class) + .child( + org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacket.class); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/EthernetCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/EthernetCustomizer.java new file mode 100644 index 000000000..bdad55b21 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/EthernetCustomizer.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Ethernet; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.EthernetBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + + +public class EthernetCustomizer + implements InitializingReaderCustomizer, InterfaceDataTranslator { + + private final InterfaceCacheDumpManager dumpManager; + + public EthernetCustomizer(@Nonnull final InterfaceCacheDumpManager dumpManager) { + this.dumpManager = dumpManager; + } + + @Override + public void merge(@Nonnull final Builder parentBuilder, + @Nonnull final Ethernet readValue) { + ((VppInterfaceAugmentationBuilder) parentBuilder).setEthernet(readValue); + } + + @Nonnull + @Override + public EthernetBuilder getBuilder(@Nonnull InstanceIdentifier id) { + return new EthernetBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final EthernetBuilder builder, + @Nonnull final ReadContext ctx) throws ReadFailedException { + + final InterfaceKey key = id.firstKeyOf(Interface.class); + final SwInterfaceDetails iface = dumpManager.getInterfaceDetail(id, ctx, key.getName()); + + if (iface.linkMtu != 0) { + // Read physical payload MTU (link_mtu) if given. + // VPP since 18.07 supports also setting MTUs for software interfaces, + // but these are not supported by HC (TODO: HC2VPP-355). + // More details: + // https://git.fd.io/vpp/tree/src/vnet/MTU.md + builder.setMtu((int) iface.linkMtu); + } + + switch (iface.linkDuplex) { + case 1: + builder.setDuplex(Ethernet.Duplex.Half); + break; + case 2: + builder.setDuplex(Ethernet.Duplex.Full); + break; + default: + break; + } + } + + @Override + public Initialized init( + @Nonnull final InstanceIdentifier id, + @Nonnull final Ethernet readValue, + @Nonnull final ReadContext ctx) { + return Initialized.create(getCfgId(id), + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.EthernetBuilder() + .setMtu(readValue.getMtu()) + .build()); + } + + private InstanceIdentifier getCfgId( + final InstanceIdentifier id) { + return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) + .augmentation(VppInterfaceAugmentation.class) + .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Ethernet.class); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/GreCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/GreCustomizer.java new file mode 100644 index 000000000..3bb0cbdf8 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/GreCustomizer.java @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2016 Intel and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static com.google.common.base.Preconditions.checkState; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.Ipv4Translator; +import io.fd.hc2vpp.common.translate.util.Ipv6Translator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.jvpp.core.dto.GreTunnelDetails; +import io.fd.jvpp.core.dto.GreTunnelDetailsReplyDump; +import io.fd.jvpp.core.dto.GreTunnelDump; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.GreTunnel; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Gre; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.GreBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class GreCustomizer extends FutureJVppCustomizer + implements InitializingReaderCustomizer, InterfaceDataTranslator, Ipv4Translator, + Ipv6Translator { + + private static final Logger LOG = LoggerFactory.getLogger(GreCustomizer.class); + private final NamingContext interfaceContext; + private final InterfaceCacheDumpManager dumpManager; + + public GreCustomizer(@Nonnull final FutureJVppCore jvpp, + @Nonnull final NamingContext interfaceContext, + @Nonnull final InterfaceCacheDumpManager dumpManager) { + super(jvpp); + this.interfaceContext = interfaceContext; + this.dumpManager = dumpManager; + } + + @Override + public void merge(@Nonnull Builder parentBuilder, + @Nonnull Gre readValue) { + ((VppInterfaceAugmentationBuilder) parentBuilder).setGre(readValue); + } + + @Nonnull + @Override + public GreBuilder getBuilder(@Nonnull InstanceIdentifier id) { + return new GreBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final GreBuilder builder, + @Nonnull final ReadContext ctx) throws ReadFailedException { + final InterfaceKey key = id.firstKeyOf(Interface.class); + final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext()); + if (!isInterfaceOfType(dumpManager, id, ctx, GreTunnel.class)) { + return; + } + + LOG.debug("Reading attributes for gre tunnel: {}", key.getName()); + // Dump just a single + final GreTunnelDump request = new GreTunnelDump(); + request.swIfIndex = index; + + final CompletionStage swInterfaceGreDetailsReplyDumpCompletionStage = + getFutureJVpp().greTunnelDump(request); + final GreTunnelDetailsReplyDump reply = + getReplyForRead(swInterfaceGreDetailsReplyDumpCompletionStage.toCompletableFuture(), id); + + // VPP keeps gre tunnel interfaces even after they were deleted (optimization) + // However there ar no longer any gre tunnel specific fields assigned to it and this call + // returns nothing + if (reply == null || reply.greTunnelDetails == null || reply.greTunnelDetails.isEmpty()) { + LOG.debug( + "Gre tunnel {}, id {} has no attributes assigned in VPP. Probably is a leftover interface placeholder" + + "after delete", key.getName(), index); + return; + } + + checkState(reply.greTunnelDetails.size() == 1, + "Unexpected number of returned gre tunnels: {} for tunnel: {}", reply.greTunnelDetails, + key.getName()); + LOG.trace("Gre tunnel: {} attributes returned from VPP: {}", key.getName(), reply); + + final GreTunnelDetails swInterfaceGreDetails = reply.greTunnelDetails.get(0); + if (swInterfaceGreDetails.tunnel.isIpv6 == 1) { + builder.setDst(new IpAddressNoZone( + arrayToIpv4AddressNoZone(swInterfaceGreDetails.tunnel.dst.un.getIp6().ip6Address))); + builder.setSrc(new IpAddressNoZone( + arrayToIpv6AddressNoZone(swInterfaceGreDetails.tunnel.src.un.getIp6().ip6Address))); + } else { + builder.setDst(new IpAddressNoZone( + arrayToIpv4AddressNoZone(swInterfaceGreDetails.tunnel.dst.un.getIp4().ip4Address))); + builder.setSrc(new IpAddressNoZone( + arrayToIpv4AddressNoZone(swInterfaceGreDetails.tunnel.src.un.getIp4().ip4Address))); + } + builder.setOuterFibId((long) swInterfaceGreDetails.tunnel.outerFibId); + LOG.debug("Gre tunnel: {}, id: {} attributes read as: {}", key.getName(), index, builder); + } + + @Override + public Initialized init( + @Nonnull final InstanceIdentifier id, @Nonnull final Gre readValue, @Nonnull final ReadContext ctx) { + return Initialized.create(getCfgId(id), + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.GreBuilder() + .setDst(readValue.getDst()) + .setSrc(readValue.getSrc()) + .setOuterFibId(readValue.getOuterFibId()) + .build()); + } + + private InstanceIdentifier getCfgId( + final InstanceIdentifier id) { + return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) + .augmentation(VppInterfaceAugmentation.class) + .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Gre.class); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterconnectionReadUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterconnectionReadUtils.java new file mode 100644 index 000000000..ab6072615 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterconnectionReadUtils.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static com.google.common.base.Preconditions.checkState; +import static java.util.Objects.requireNonNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.jvpp.core.dto.BridgeDomainDetails; +import io.fd.jvpp.core.dto.BridgeDomainDetailsReplyDump; +import io.fd.jvpp.core.dto.BridgeDomainDump; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import io.fd.jvpp.core.future.FutureJVppCore; +import io.fd.jvpp.core.types.BridgeDomainSwIf; +import java.util.Arrays; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.Interconnection; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.BridgeBasedBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Utility class providing Interconnection read support. + */ +final class InterconnectionReadUtils implements InterfaceDataTranslator { + + private static final Logger LOG = LoggerFactory.getLogger(InterconnectionReadUtils.class); + + private final NamingContext interfaceContext; + private final NamingContext bridgeDomainContext; + private final InterfaceCacheDumpManager dumpManager; + private final DumpCacheManager bdDumpManager; + + InterconnectionReadUtils(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext, + @Nonnull final NamingContext bridgeDomainContext, + @Nonnull final InterfaceCacheDumpManager dumpManager) { + requireNonNull(futureJVppCore, "futureJVppCore should not be null"); + this.interfaceContext = requireNonNull(interfaceContext, "interfaceContext should not be null"); + this.bridgeDomainContext = requireNonNull(bridgeDomainContext, "bridgeDomainContext should not be null"); + this.dumpManager = requireNonNull(dumpManager, "dumpManager should not be null"); + this.bdDumpManager = new DumpCacheManager.DumpCacheManagerBuilder() + .acceptOnly(BridgeDomainDetailsReplyDump.class) + .withExecutor((id, params) -> { + final BridgeDomainDump request = new BridgeDomainDump(); + request.bdId = -1; + + final CompletableFuture bdCompletableFuture = + futureJVppCore.bridgeDomainDump(request).toCompletableFuture(); + return getReplyForRead(bdCompletableFuture, id); + }) + .build(); + } + + @Nullable + Interconnection readInterconnection(@Nonnull final InstanceIdentifier id, @Nonnull final String ifaceName, + @Nonnull final ReadContext ctx) + throws ReadFailedException { + final int ifaceId = interfaceContext.getIndex(ifaceName, ctx.getMappingContext()); + + final SwInterfaceDetails iface = dumpManager.getInterfaceDetail(id, ctx, ifaceName); + LOG.debug("Interface details for interface: {}, details: {}", ifaceName, iface); + + final BridgeDomainDetailsReplyDump dumpReply = bdDumpManager.getDump(id, ctx.getModificationCache()) + .orElse(new BridgeDomainDetailsReplyDump()); + for (final BridgeDomainDetails bd : dumpReply.bridgeDomainDetails) { + final Optional bdIfAssignment = getBridgeDomainSwIf(ifaceId, bd); + if (bdIfAssignment.isPresent()) { + final BridgeDomainSwIf bridgeDomainSwIf = bdIfAssignment.get(); + final BridgeBasedBuilder bbBuilder = new BridgeBasedBuilder(); + bbBuilder.setBridgeDomain(bridgeDomainContext.getName(bd.bdId, ctx.getMappingContext())); + + // Set BVI if the bridgeDomainDetails.bviSwIfIndex == current sw if index + final Optional bridgeDomainForInterface = + getBridgeDomainForInterface(dumpReply, bd.bdId); + // Since we already found an interface assigned to a bridge domain, the details for BD must be present + checkState(bridgeDomainForInterface.isPresent()); + if (bridgeDomainForInterface.get().bviSwIfIndex == ifaceId) { + bbBuilder.setBridgedVirtualInterface(true); + } else { + bbBuilder.setBridgedVirtualInterface(false); + } + + if (bridgeDomainSwIf.shg != 0) { + bbBuilder.setSplitHorizonGroup((short) bridgeDomainSwIf.shg); + } + return bbBuilder.build(); + } + } + // TODO HONEYCOMB-190 is there a way to check if interconnection is XconnectBased? + + return null; + } + + private Optional getBridgeDomainSwIf(final int ifaceId, @Nonnull final BridgeDomainDetails bd) { + if (null == bd.swIfDetails) { + return Optional.empty(); + } + // interface can be added to only one BD only + return Arrays.stream(bd.swIfDetails).filter(el -> el.swIfIndex == ifaceId).findFirst(); + } + + private Optional getBridgeDomainForInterface(final BridgeDomainDetailsReplyDump reply, + int bdId) { + return reply.bridgeDomainDetails.stream().filter(a -> a.bdId == bdId).findFirst(); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterfaceCustomizer.java new file mode 100644 index 000000000..3e0a1dc41 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterfaceCustomizer.java @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.DisabledInterfacesManager; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface.AdminStatus; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface.OperStatus; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Customizer for reading ietf-interfaces:interfaces/interface. + */ +public class InterfaceCustomizer + implements InitializingListReaderCustomizer, ByteDataTranslator, + InterfaceDataTranslator { + + private static final Logger LOG = LoggerFactory.getLogger(InterfaceCustomizer.class); + private final NamingContext interfaceNamingContext; + private final DisabledInterfacesManager interfaceDisableContext; + private final InterfaceCacheDumpManager dumpManager; + + public InterfaceCustomizer(@Nonnull final NamingContext interfaceNamingContext, + @Nonnull final DisabledInterfacesManager interfaceDisableContext, + @Nonnull final InterfaceCacheDumpManager dumpManager) { + this.interfaceNamingContext = interfaceNamingContext; + this.interfaceDisableContext = interfaceDisableContext; + this.dumpManager = dumpManager; + } + + @Nonnull + @Override + public InterfaceBuilder getBuilder(@Nonnull InstanceIdentifier id) { + return new InterfaceBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull InterfaceBuilder builder, + @Nonnull ReadContext ctx) throws ReadFailedException { + LOG.debug("Reading attributes for interface: {}", id); + final String ifaceName = id.firstKeyOf(id.getTargetType()).getName(); + + final int index = interfaceNamingContext.getIndex(ifaceName, ctx.getMappingContext()); + + // Ignore disabled interface (such as deleted VXLAN tunnels) + if (interfaceDisableContext.isInterfaceDisabled(index, ctx.getMappingContext())) { + LOG.debug("Skipping disabled interface: {}", id); + return; + } + + final SwInterfaceDetails iface = dumpManager.getInterfaceDetail(id, ctx, ifaceName); + LOG.debug("Interface details for interface: {}, details: {}", ifaceName, iface); + + if (!isRegularInterface(iface)) { + LOG.debug("Interface: {} is a sub-interface. Ignoring read request.", ifaceName); + return; + } + + builder.setName(ifaceName); + builder.setType(getInterfaceType(new String(iface.interfaceName).intern())); + builder.setIfIndex(vppIfIndexToYang(iface.swIfIndex)); + builder.setAdminStatus(1 == iface.adminUpDown + ? AdminStatus.Up + : AdminStatus.Down); + builder.setOperStatus(1 == iface.linkUpDown + ? OperStatus.Up + : OperStatus.Down); + if (0 != iface.linkSpeed) { + builder.setSpeed(vppInterfaceSpeedToYang(iface.linkSpeed)); + } + if (iface.l2AddressLength == 6) { + builder.setPhysAddress(new PhysAddress(vppPhysAddrToYang(iface.l2Address))); + } + LOG.trace("Base attributes read for interface: {} as: {}", ifaceName, builder); + } + + @Nonnull + @Override + public List getAllIds(@Nonnull final InstanceIdentifier id, + @Nonnull final ReadContext context) throws ReadFailedException { + final List interfacesKeys; + LOG.trace("Dumping all interfaces to get all IDs"); + final MappingContext mappingCtx = context.getMappingContext(); + final Set interfacesIdxs = dumpManager.getInterfaces(id, context) + .filter(elt -> elt != null) + // Filter out disabled interfaces, dont read them + // This also prevents child readers in being invoked such as vxlan (which relies on disabling interfaces) + .filter(elt -> !interfaceDisableContext + .isInterfaceDisabled(elt.swIfIndex, mappingCtx)) + // filter out sub-interfaces + .filter(InterfaceDataTranslator.INSTANCE::isRegularInterface) + .map(elt -> elt.swIfIndex) + .collect(Collectors.toSet()); + + // Clean disabled interfaces list + interfaceDisableContext.getDisabledInterfaces(mappingCtx).stream() + // Find indices not currently in VPP + .filter(interfacesIdxs::contains) + // Remove from disabled list ... not disabled if not existing + .forEach(idx -> interfaceDisableContext.removeDisabledInterface(idx, mappingCtx)); + + // Transform indices to keys + interfacesKeys = interfacesIdxs.stream() + .map(index -> new InterfaceKey(interfaceNamingContext.getName(index, context.getMappingContext()))) + .collect(Collectors.toList()); + + LOG.debug("Interfaces found in VPP: {}", interfacesKeys); + return interfacesKeys; + } + + @Override + public void merge(@Nonnull final org.opendaylight.yangtools.concepts.Builder builder, + @Nonnull final List readData) { + ((InterfacesBuilder) builder).setInterface(readData); + } + + @Override + public Initialized init( + @Nonnull final InstanceIdentifier id, @Nonnull final Interface readValue, + @Nonnull final ReadContext ctx) { + return Initialized.create(getCfgId(id), + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder() + .setName(readValue.getName()) + .setType(readValue.getType()) + .setEnabled(AdminStatus.Up.equals(readValue.getAdminStatus())) + // Not present in interfaces + // .setLinkUpDownTrapEnable() + .build()); + } + + public static InstanceIdentifier getCfgId( + final InstanceIdentifier id) { + return InstanceIdentifier.create(Interfaces.class).child( + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface.class, + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey( + id.firstKeyOf(Interface.class).getName())); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterfaceDataTranslator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterfaceDataTranslator.java new file mode 100644 index 000000000..b916431f3 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterfaceDataTranslator.java @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static com.google.common.base.Preconditions.checkArgument; + +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import java.math.BigInteger; +import java.util.Objects; +import java.util.stream.Collector; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.AfPacket; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.GreTunnel; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.Loopback; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.TapV2; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUser; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeTunnel; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanTunnel; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev180703.EthernetCsmacd; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Gauge64; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public interface InterfaceDataTranslator extends ByteDataTranslator, JvppReplyConsumer { + + InterfaceDataTranslator INSTANCE = new InterfaceDataTranslator() { + }; + + int PHYSICAL_ADDRESS_LENGTH = 6; + + Collector SINGLE_ITEM_COLLECTOR = + RWUtils.singleItemCollector(); + + /** + * Convert VPP's link speed in kbits per second to Yang type. + * + * @param vppLinkSpeed Link speed in kbits per second from VPP. + * @return Converted value from VPP link speed + */ + default Gauge64 vppInterfaceSpeedToYang(int vppLinkSpeed) { + return new Gauge64(BigInteger.valueOf(Integer.toUnsignedLong(vppLinkSpeed) * 1000)); + } + + /** + * Reads first 6 bytes of supplied byte array and converts to string as Yang dictates

Replace later with + * https://git.opendaylight.org/gerrit/#/c/34869/10/model/ietf/ietf-type- util/src/main/ + * java/org/opendaylight/mdsal/model/ietf/util/AbstractIetfYangUtil.java + * + * @param vppPhysAddress byte array of bytes in big endian order, constructing the network IF physical address. + * @return String like "aa:bb:cc:dd:ee:ff" + * @throws NullPointerException if vppPhysAddress is null + * @throws IllegalArgumentException if vppPhysAddress.length < 6 + */ + default String vppPhysAddrToYang(@Nonnull final byte[] vppPhysAddress) { + Objects.requireNonNull(vppPhysAddress, "Empty physical address bytes"); + final int endIndex = PHYSICAL_ADDRESS_LENGTH; + checkArgument(endIndex <= vppPhysAddress.length, + "Invalid physical address size (%s), expected >= %s", vppPhysAddress.length, endIndex); + // Extended (64-bit) MAC addresses are currently not supported , so use first 48-bits. + // Adding support for extended MAC addresses might require yang model change. + // Also VPP is not consistent (e.g. for TAP it allows to configure MAC of 6 bytes, but sw_interface_details + // contains 8 bytes. + return printHexBinary(vppPhysAddress, 0, PHYSICAL_ADDRESS_LENGTH); + } + + /** + * VPP's interface index is counted from 0, whereas ietf-interface's if-index is from 1. This function converts from + * VPP's interface index to YANG's interface index. + * + * @param vppIfIndex the sw interface index VPP reported. + * @return VPP's interface index incremented by one + */ + default int vppIfIndexToYang(int vppIfIndex) { + return vppIfIndex + 1; + } + + /** + * This function does the opposite of what {@link #vppIfIndexToYang(int)} does. + * + * @param yangIfIndex if-index from ietf-interfaces. + * @return VPP's representation of the if-index + */ + default int yangIfIndexToVpp(int yangIfIndex) { + checkArgument(yangIfIndex >= 1, "YANG if-index has invalid value %s", yangIfIndex); + return yangIfIndex - 1; + } + + /** + * Determine interface type based on its VPP name (relying on VPP's interface naming conventions) + * + * @param interfaceName VPP generated interface name + * @return Interface type + */ + @Nonnull + default Class getInterfaceType(@Nonnull final String interfaceName) { + + if (interfaceName.startsWith("tap")) { + return TapV2.class; + } + + if (interfaceName.startsWith("vxlan_gpe")) { + return VxlanGpeTunnel.class; + } + + if (interfaceName.startsWith("vxlan")) { + return VxlanTunnel.class; + } + + if (interfaceName.startsWith("gre")) { + return GreTunnel.class; + } + + if (interfaceName.startsWith("VirtualEthernet")) { + return VhostUser.class; + } + + if (interfaceName.startsWith("host-")) { + return AfPacket.class; + } + + if (interfaceName.startsWith("loop")) { + return Loopback.class; + } + + return EthernetCsmacd.class; + } + + /** + * Check interface type. Uses interface details from VPP to determine. + */ + default boolean isInterfaceOfType(@Nonnull final InterfaceCacheDumpManager dumpManager, + @Nonnull final InstanceIdentifier id, + @Nonnull final ReadContext ctx, + @Nonnull final Class ifcType) + throws ReadFailedException { + final String name = id.firstKeyOf(Interface.class).getName(); + final SwInterfaceDetails vppInterfaceDetails = dumpManager.getInterfaceDetail(id, ctx, name); + + return isInterfaceOfType(ifcType, vppInterfaceDetails); + } + + default boolean isInterfaceOfType(@Nonnull final Class ifcType, + @Nullable final SwInterfaceDetails cachedDetails) { + if (cachedDetails == null) { + return false; + } else { + return ifcType.equals(getInterfaceType(toString(cachedDetails.interfaceName))); + } + } + + /** + * Checks whether provided {@link SwInterfaceDetails} is detail of sub-interface
+ *

    + *
  • subId == unique number of sub-interface within set of sub-interfaces of single interface
  • + *
  • swIfIndex == unique index of interface/sub-interface within all interfaces
  • + *
  • supSwIfIndex == unique index of parent interface
  • + *
  • in case of interface , swIfIndex value equals supSwIfIndex
  • + *
  • in case of subinterface, supSwIfIndex equals index of parent interface, swIfIndex is index of + * subinterface itselt
  • + *
+ */ + default boolean isSubInterface(@Nonnull final SwInterfaceDetails elt) { + //cant check by subId != 0, because you can pick 0 as value + return elt.supSwIfIndex != elt.swIfIndex; + } + + /** + * Checks whether provided {@link SwInterfaceDetails} is detail of interface
+ *
    + *
  • subId == unique number of subinterface within set of subinterfaces of single interface
  • + *
  • swIfIndex == unique index of interface/subinterface within all interfaces
  • + *
  • supSwIfIndex == unique index of parent interface
  • + *
  • in case of interface , swIfIndex value equals supSwIfIndex
  • + *
  • in case of subinterface, supSwIfIndex equals index of parent interface, swIfIndex is index + * of subinterface itselt
  • + *
+ */ + default boolean isRegularInterface(@Nonnull final SwInterfaceDetails elt) { + return !isSubInterface(elt); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterfaceRoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterfaceRoutingCustomizer.java new file mode 100644 index 000000000..b87228edf --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterfaceRoutingCustomizer.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Routing; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.RoutingBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class InterfaceRoutingCustomizer extends RoutingCustomizer implements + InitializingReaderCustomizer { + + private static final Logger LOG = LoggerFactory.getLogger(InterfaceRoutingCustomizer.class); + + public InterfaceRoutingCustomizer(@Nonnull final FutureJVppCore vppApi, + @Nonnull final NamingContext interfaceContext) { + super(vppApi, interfaceContext); + } + + @Nonnull + @Override + public RoutingBuilder getBuilder(@Nonnull final InstanceIdentifier id) { + return new RoutingBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final RoutingBuilder builder, + @Nonnull final ReadContext ctx) throws ReadFailedException { + LOG.debug("Reading attributes for Routing: {}", id); + final String ifName = id.firstKeyOf(Interface.class).getName(); + readInterfaceRouting(id, builder::setIpv4VrfId, builder::setIpv6VrfId, ctx, ifName); + } + + @Override + public void merge(@Nonnull final Builder parentBuilder, @Nonnull final Routing readValue) { + ((VppInterfaceAugmentationBuilder) parentBuilder).setRouting(readValue); + } + + @Nonnull + @Override + public Initialized init( + @Nonnull final InstanceIdentifier id, + @Nonnull final Routing readValue, + @Nonnull final ReadContext ctx) { + return Initialized.create(getCfgId(id), + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.RoutingBuilder() + .setIpv4VrfId(readValue.getIpv4VrfId()) + .setIpv6VrfId(readValue.getIpv6VrfId()) + .build()); + } + + private InstanceIdentifier getCfgId( + final InstanceIdentifier id) { + return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) + .augmentation(VppInterfaceAugmentation.class) + .child( + org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Routing.class); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterfaceStatisticsCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterfaceStatisticsCustomizer.java new file mode 100644 index 000000000..bfcb3ee52 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/InterfaceStatisticsCustomizer.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2019 PANTHEON.tech. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceStatisticsManager; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.stats.dto.InterfaceStatistics; +import io.fd.jvpp.stats.dto.InterfaceStatisticsDetails; +import io.fd.jvpp.stats.dto.InterfaceStatisticsDetailsReplyDump; +import io.fd.jvpp.stats.dto.InterfaceStatisticsDump; +import io.fd.jvpp.stats.future.FutureJVppStatsFacade; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Optional; +import java.util.concurrent.Future; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces._interface.Statistics; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces._interface.StatisticsBuilder; +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.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class InterfaceStatisticsCustomizer implements ReaderCustomizer { + + private static final Logger LOG = LoggerFactory.getLogger(InterfaceStatisticsCustomizer.class); + + private final NamingContext ifcNamingCtx; + private final FutureJVppStatsFacade jvppStats; + private final InterfaceStatisticsManager statisticsManager; + + public InterfaceStatisticsCustomizer(final NamingContext ifcNamingCtx, + final FutureJVppStatsFacade jvppStats, + final InterfaceStatisticsManager statisticsManager) { + this.ifcNamingCtx = checkNotNull(ifcNamingCtx, "Naming context should not be null"); + this.jvppStats = checkNotNull(jvppStats, "JVpp Stats facade should not be null"); + this.statisticsManager = checkNotNull(statisticsManager, "Statistics Manager should not be null"); + } + + @Nonnull + @Override + public StatisticsBuilder getBuilder(@Nonnull final InstanceIdentifier instanceIdentifier) { + return new StatisticsBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier instanceIdentifier, + @Nonnull final StatisticsBuilder statisticsBuilder, + @Nonnull final ReadContext readContext) + throws ReadFailedException { + if (!statisticsManager.isStatisticsEnabled()) return; + + final InterfaceKey key = instanceIdentifier.firstKeyOf(Interface.class); + final int index = ifcNamingCtx.getIndex(key.getName(), readContext.getMappingContext()); + InterfaceStatisticsDetails stats = getStatisticsDump(instanceIdentifier); + if (stats != null) { + Optional statsDetail = + Arrays.asList(stats.interfaceStatistics).stream().filter(elt -> elt.swIfIndex == index).findFirst(); + if (statsDetail.isPresent()) { + InterfaceStatistics detail = statsDetail.get(); + statisticsBuilder.setOutOctets(new Counter64(BigInteger.valueOf(detail.outBytes))) + .setOutUnicastPkts(new Counter64(BigInteger.valueOf(detail.outUnicastPkts))) + .setOutMulticastPkts(new Counter64(BigInteger.valueOf(detail.outMulticastPkts))) + .setOutBroadcastPkts(new Counter64(BigInteger.valueOf(detail.outBroadcastPkts))) + .setOutErrors(new Counter32(new Long(detail.outErrors))) + .setInOctets(new Counter64(BigInteger.valueOf(detail.inBytes))) + .setInUnicastPkts(new Counter64(BigInteger.valueOf(detail.inUnicastPkts))) + .setInMulticastPkts(new Counter64(BigInteger.valueOf(detail.inMulticastPkts))) + .setInBroadcastPkts(new Counter64(BigInteger.valueOf(detail.inBroadcastPkts))) + .setInErrors(new Counter32(new Long(detail.inErrors))); + } + } + } + + @Override + public void merge(@Nonnull final Builder builder, @Nonnull final Statistics statistics) { + ((InterfaceBuilder) builder).setStatistics(statistics); + } + + private InterfaceStatisticsDetails getStatisticsDump(InstanceIdentifier id) throws ReadFailedException { + LOG.debug("Sending InterfaceStatisticsDump request..."); + final InterfaceStatisticsDump request = new InterfaceStatisticsDump(); + + final Future replyFuture = + jvppStats.interfaceStatisticsDump(request).toCompletableFuture(); + final InterfaceStatisticsDetailsReplyDump reply; + try { + reply = replyFuture.get(); + } catch (Exception e) { + throw new ReadFailedException(id, e); + } + + if (reply == null || reply.interfaceStatisticsDetails == null) { + throw new ReadFailedException(id, + new IllegalStateException("Received null response for empty dump: " + reply)); + } + return reply.interfaceStatisticsDetails; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/L2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/L2Customizer.java new file mode 100644 index 000000000..13440ef63 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/L2Customizer.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2Builder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.Interconnection; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.BridgeBased; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.BridgeBasedBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.XconnectBased; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.XconnectBasedBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Customizer for reading ietf-interfaces:interfaces/interface/iface_name/v3po:l2 + */ +public class L2Customizer extends FutureJVppCustomizer implements InitializingReaderCustomizer { + + private static final Logger LOG = LoggerFactory.getLogger(L2Customizer.class); + private final InterconnectionReadUtils icReadUtils; + + public L2Customizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext, + @Nonnull final NamingContext bridgeDomainContext, + @Nonnull final InterfaceCacheDumpManager dumpManager) { + super(futureJVppCore); + this.icReadUtils = + new InterconnectionReadUtils(futureJVppCore, interfaceContext, bridgeDomainContext, dumpManager); + } + + @Override + public void merge(@Nonnull final Builder parentBuilder, @Nonnull final L2 readValue) { + ((VppInterfaceAugmentationBuilder) parentBuilder).setL2(readValue); + } + + @Nonnull + @Override + public L2Builder getBuilder(@Nonnull final InstanceIdentifier id) { + return new L2Builder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final L2Builder builder, + @Nonnull final ReadContext ctx) throws ReadFailedException { + + LOG.debug("Reading attributes for L2: {}", id); + final InterfaceKey key = id.firstKeyOf(Interface.class); + final String ifaceName = key.getName(); + builder.setInterconnection(icReadUtils.readInterconnection(id, ifaceName, ctx)); + } + + @Override + public Initialized init( + @Nonnull final InstanceIdentifier id, + @Nonnull final L2 readValue, + @Nonnull final ReadContext ctx) { + final org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2Builder + l2Builder = + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2Builder(); + + final Interconnection interconnection = readValue.getInterconnection(); + if (interconnection != null) { + if (interconnection instanceof XconnectBased) { + final XconnectBasedBuilder xconnectBasedBuilder = new XconnectBasedBuilder(); + xconnectBasedBuilder.setXconnectOutgoingInterface( + ((XconnectBased) interconnection).getXconnectOutgoingInterface()); + l2Builder.setInterconnection(xconnectBasedBuilder.build()); + } else if (interconnection instanceof BridgeBased) { + final BridgeBasedBuilder bridgeBasedBuilder = new BridgeBasedBuilder(); + bridgeBasedBuilder.setBridgeDomain(((BridgeBased) interconnection).getBridgeDomain()); + bridgeBasedBuilder + .setBridgedVirtualInterface(((BridgeBased) interconnection).isBridgedVirtualInterface()); + bridgeBasedBuilder.setSplitHorizonGroup(((BridgeBased) interconnection).getSplitHorizonGroup()); + l2Builder.setInterconnection(bridgeBasedBuilder.build()); + } + } + + return Initialized.create(getCfgId(id), l2Builder.build()); + } + + private InstanceIdentifier getCfgId( + final InstanceIdentifier id) { + return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) + .augmentation(VppInterfaceAugmentation.class) + .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2.class); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/RewriteCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/RewriteCustomizer.java new file mode 100644 index 000000000..54164cc10 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/RewriteCustomizer.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import io.fd.hc2vpp.common.translate.util.TagRewriteOperation; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319._802dot1ad; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319._802dot1q; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.Rewrite; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.RewriteBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2Builder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.tag.rewrite.PushTags; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.tag.rewrite.PushTagsBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.tag.rewrite.PushTagsKey; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.CVlan; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qTagVlanType; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qVlanId; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.SVlan; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.Dot1qTagBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Customizer for reading vlan tag-rewrite configuration state form the VPP. + */ +public class RewriteCustomizer + implements ReaderCustomizer, InterfaceDataTranslator { + + // No initialization necessary since its parent Subinterface L2 customzier sets the entire subtree during + // initialization + + private static final Logger LOG = LoggerFactory.getLogger(RewriteCustomizer.class); + private final InterfaceCacheDumpManager dumpManager; + + public RewriteCustomizer(@Nonnull final InterfaceCacheDumpManager dumpManager) { + this.dumpManager = checkNotNull(dumpManager, "dumpManager should not be null"); + } + + @Override + public void merge(@Nonnull final Builder parentBuilder, + @Nonnull final Rewrite readValue) { + ((L2Builder) parentBuilder).setRewrite(readValue); + } + + @Nonnull + @Override + public RewriteBuilder getBuilder(@Nonnull final InstanceIdentifier id) { + return new RewriteBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final RewriteBuilder builder, @Nonnull final ReadContext ctx) + throws ReadFailedException { + final String subInterfaceName = getSubInterfaceName(id); + LOG.debug("Reading attributes for sub interface: {}", subInterfaceName); + + final SwInterfaceDetails iface = dumpManager.getInterfaceDetail(id, ctx, subInterfaceName); + LOG.debug("VPP sub-interface details: {}", iface); + + checkState(isSubInterface(iface), "Interface returned by the VPP is not a sub-interface"); + + final TagRewriteOperation operation = TagRewriteOperation.get(iface.vtrOp); + if (TagRewriteOperation.disabled == operation) { + LOG.debug("Tag rewrite operation is disabled for "); + return; + } + + builder.setVlanType(iface.vtrPushDot1Q == 1 + ? _802dot1q.class + : _802dot1ad.class); + + setPushTags(builder, iface); + setPopTags(builder, operation); + } + + private static String getSubInterfaceName(final InstanceIdentifier id) { + return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), + Math.toIntExact(id.firstKeyOf(SubInterface.class).getIdentifier())); + } + + private void setPopTags(final RewriteBuilder builder, final TagRewriteOperation operation) { + final byte numberOfTagsToPop = operation.getPopTags(); + if (numberOfTagsToPop != 0) { + builder.setPopTags(Short.valueOf(numberOfTagsToPop)); + } + } + + private void setPushTags(final RewriteBuilder builder, final SwInterfaceDetails iface) { + final List tags = new ArrayList<>(); + if (iface.vtrTag1 != 0) { + tags.add(buildTag((short) 0, SVlan.class, iface.vtrTag1)); + } + if (iface.vtrTag2 != 0) { + tags.add(buildTag((short) 1, CVlan.class, iface.vtrTag2)); + } + if (tags.size() > 0) { + builder.setPushTags(tags); + } + } + + private PushTags buildTag(final short index, final Class tagType, final int vlanId) { + final PushTagsBuilder tag = new PushTagsBuilder(); + tag.setIndex(index); + tag.withKey(new PushTagsKey(index)); + final Dot1qTagBuilder dtag = new Dot1qTagBuilder(); + dtag.setTagType(tagType); + dtag.setVlanId(new Dot1qVlanId(vlanId)); + tag.setDot1qTag(dtag.build()); + return tag.build(); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/RoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/RoutingCustomizer.java new file mode 100644 index 000000000..2ac172af6 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/RoutingCustomizer.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import com.google.common.primitives.UnsignedInts; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.jvpp.core.dto.SwInterfaceGetTable; +import io.fd.jvpp.core.dto.SwInterfaceGetTableReply; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.function.Consumer; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.RoutingBaseAttributes; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +abstract class RoutingCustomizer extends FutureJVppCustomizer implements JvppReplyConsumer { + private final NamingContext interfaceContext; + + protected RoutingCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + this.interfaceContext = interfaceContext; + } + + protected void readInterfaceRouting(@Nonnull final InstanceIdentifier id, + @Nonnull final Consumer v4VrfConsumer, + @Nonnull final Consumer v6VrfConsumer, + @Nonnull final ReadContext ctx, final String interfaceName) + throws ReadFailedException { + final SwInterfaceGetTable request = new SwInterfaceGetTable(); + request.swIfIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext()); + request.isIpv6 = 0; + final SwInterfaceGetTableReply + ip4Reply = getReplyForRead(getFutureJVpp().swInterfaceGetTable(request).toCompletableFuture(), id); + + request.isIpv6 = 1; + final SwInterfaceGetTableReply ip6Reply = + getReplyForRead(getFutureJVpp().swInterfaceGetTable(request).toCompletableFuture(), id); + + if (ip4Reply.vrfId != 0) { + v4VrfConsumer.accept(new VniReference(UnsignedInts.toLong(ip4Reply.vrfId))); + } + if (ip6Reply.vrfId != 0) { + v6VrfConsumer.accept(new VniReference(UnsignedInts.toLong(ip6Reply.vrfId))); + } + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/SubInterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/SubInterfaceCustomizer.java new file mode 100644 index 000000000..f4bba6d2c --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/SubInterfaceCustomizer.java @@ -0,0 +1,243 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubInterfaceStatus; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfacesBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.DefaultBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.UntaggedBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.vlan.tagged.VlanTaggedBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.Match; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.MatchBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.Tags; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.TagsBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.tags.Tag; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.tags.TagBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.tags.TagKey; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.CVlan; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qTagVlanType; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qVlanId; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.SVlan; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTagBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Customizer for reading sub interfaces form the VPP. + */ +public class SubInterfaceCustomizer extends FutureJVppCustomizer + implements InitializingListReaderCustomizer, + ByteDataTranslator, + InterfaceDataTranslator { + + private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceCustomizer.class); + private static final Dot1qTag.VlanId ANY_VLAN_ID = new Dot1qTag.VlanId(Dot1qTag.VlanId.Enumeration.Any); + private final NamingContext interfaceContext; + private final InterfaceCacheDumpManager dumpManager; + + public SubInterfaceCustomizer(@Nonnull final FutureJVppCore jvpp, + @Nonnull final NamingContext interfaceContext, + @Nonnull final InterfaceCacheDumpManager dumpManager) { + super(jvpp); + this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null"); + this.dumpManager = checkNotNull(dumpManager, "dumpManager should not be null"); + } + + private static String getSubInterfaceName(final InstanceIdentifier id) { + return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), + Math.toIntExact(id.firstKeyOf(id.getTargetType()).getIdentifier())); + } + + private static Tag buildTag(final short index, final Class tagType, + final Dot1qTag.VlanId vlanId) { + TagBuilder tag = new TagBuilder(); + tag.setIndex(index); + tag.withKey(new TagKey(index)); + final Dot1qTagBuilder dtag = new Dot1qTagBuilder(); + dtag.setTagType(tagType); + dtag.setVlanId(vlanId); + tag.setDot1qTag(dtag.build()); + return tag.build(); + } + + private static Dot1qTag.VlanId buildVlanId(final short vlanId) { + // treat vlanId as unsigned value: + return new Dot1qTag.VlanId(new Dot1qVlanId(0xffff & vlanId)); + } + + @Nonnull + @Override + public List getAllIds(@Nonnull final InstanceIdentifier id, + @Nonnull final ReadContext context) throws ReadFailedException { + // Relying here that parent InterfaceCustomizer was invoked first (PREORDER) + // to fill in the context with initial ifc mapping + final InterfaceKey key = id.firstKeyOf(Interface.class); + final String ifaceName = key.getName(); + final int ifaceId = interfaceContext.getIndex(ifaceName, context.getMappingContext()); + + final List interfacesKeys = dumpManager.getInterfaces(id,context) + .filter(Objects::nonNull) + // accept only sub-interfaces for current iface: + .filter(elt -> isSubInterface(elt) && elt.supSwIfIndex == ifaceId) + .map(details -> new SubInterfaceKey(new Long(details.subId))) + .collect(Collectors.toList()); + + LOG.debug("Sub-interfaces of {} found in VPP: {}", ifaceName, interfacesKeys); + return interfacesKeys; + } + + @Override + public void merge(@Nonnull final Builder builder, + @Nonnull final List readData) { + ((SubInterfacesBuilder) builder).setSubInterface(readData); + } + + @Nonnull + @Override + public SubInterfaceBuilder getBuilder(@Nonnull final InstanceIdentifier id) { + return new SubInterfaceBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final SubInterfaceBuilder builder, @Nonnull final ReadContext ctx) + throws ReadFailedException { + final String subInterfaceName = getSubInterfaceName(id); + LOG.debug("Reading attributes for sub interface: {}", subInterfaceName); + + final SwInterfaceDetails iface = dumpManager.getInterfaceDetail(id, ctx, subInterfaceName); + LOG.debug("VPP sub-interface details: {}", iface); + + checkState(isSubInterface(iface), "Interface returned by the VPP is not a sub-interface"); + + builder.setIdentifier((long) iface.subId); + builder.withKey(new SubInterfaceKey(builder.getIdentifier())); + + // sub-interface-base-attributes: + builder.setTags(readTags(iface)); + builder.setMatch(readMatch(iface)); + + // sub-interface-operational-attributes: + builder.setAdminStatus(1 == iface.adminUpDown + ? SubInterfaceStatus.Up + : SubInterfaceStatus.Down); + builder.setOperStatus(1 == iface.linkUpDown + ? SubInterfaceStatus.Up + : SubInterfaceStatus.Down); + builder.setIfIndex(vppIfIndexToYang(iface.swIfIndex)); + if (iface.l2AddressLength == 6) { + builder.setPhysAddress(new PhysAddress(vppPhysAddrToYang(iface.l2Address))); + } + if (0 != iface.linkSpeed) { + builder.setSpeed(vppInterfaceSpeedToYang(iface.linkSpeed)); + } + } + + private Tags readTags(final SwInterfaceDetails iface) { + final TagsBuilder tags = new TagsBuilder(); + final List list = new ArrayList<>(); + if (iface.subNumberOfTags > 0) { + if (iface.subOuterVlanIdAny == 1) { + list.add(buildTag((short) 0, SVlan.class, ANY_VLAN_ID)); + } else { + list.add(buildTag((short) 0, SVlan.class, buildVlanId(iface.subOuterVlanId))); + } + // inner tag (customer tag): + if (iface.subNumberOfTags == 2) { + if (iface.subInnerVlanIdAny == 1) { + list.add(buildTag((short) 1, CVlan.class, ANY_VLAN_ID)); + } else { + list.add(buildTag((short) 1, CVlan.class, buildVlanId(iface.subInnerVlanId))); + } + } + } + tags.setTag(list); + return tags.build(); + } + + private Match readMatch(final SwInterfaceDetails iface) { + final MatchBuilder match = new MatchBuilder(); + if (iface.subDefault == 1) { + match.setMatchType(new DefaultBuilder().build()); + } else if (iface.subNumberOfTags == 0) { + match.setMatchType(new UntaggedBuilder().build()); + } else { + final VlanTaggedBuilder tagged = new VlanTaggedBuilder(); + tagged.setMatchExactTags(byteToBoolean(iface.subExactMatch)); + match.setMatchType( + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.VlanTaggedBuilder() + .setVlanTagged(tagged.build()).build()); + } + return match.build(); + } + + @Override + public Initialized init( + @Nonnull final InstanceIdentifier id, @Nonnull final SubInterface readValue, + @Nonnull final ReadContext ctx) { + return Initialized.create(getCfgId(id), + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceBuilder() + .setEnabled(SubInterfaceStatus.Up.equals(readValue.getAdminStatus())) + .setIdentifier(readValue.getIdentifier()) + .setMatch(readValue.getMatch()) + .setTags(readValue.getTags()) + .setVlanType(readValue.getVlanType()) + .build()); + } + + public static InstanceIdentifier getCfgId( + final InstanceIdentifier id) { + return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) + .augmentation(SubinterfaceAugmentation.class) + .child(SubInterfaces.class) + .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface.class, + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey( + id.firstKeyOf(SubInterface.class).getIdentifier())); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/SubInterfaceL2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/SubInterfaceL2Customizer.java new file mode 100644 index 000000000..598f3d5ac --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/SubInterfaceL2Customizer.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static io.fd.hc2vpp.v3po.util.SubInterfaceUtils.getSubInterfaceName; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.BridgeBased; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.XconnectBased; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Customizer for reading vlan sub interface L2 operational state + */ +public class SubInterfaceL2Customizer + implements InitializingReaderCustomizer { + + private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceL2Customizer.class); + private final InterconnectionReadUtils icReadUtils; + + public SubInterfaceL2Customizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext, + @Nonnull final NamingContext bridgeDomainContext, + @Nonnull final InterfaceCacheDumpManager dumpManager) { + this.icReadUtils = + new InterconnectionReadUtils(futureJVppCore, interfaceContext, bridgeDomainContext, dumpManager); + } + + @Override + public void merge(@Nonnull final Builder parentBuilder, @Nonnull final L2 readValue) { + ((SubInterfaceBuilder) parentBuilder).setL2(readValue); + } + + @Nonnull + @Override + public L2Builder getBuilder(@Nonnull final InstanceIdentifier id) { + return new L2Builder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final L2Builder builder, + @Nonnull final ReadContext ctx) throws ReadFailedException { + LOG.debug("Reading attributes for sub-interface L2: {}", id); + final InterfaceKey parentInterfacekey = id.firstKeyOf(Interface.class); + final SubInterfaceKey subInterfacekey = id.firstKeyOf(SubInterface.class); + final String subInterfaceName = + getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue()); + + builder.setInterconnection(icReadUtils.readInterconnection(id, subInterfaceName, ctx)); + } + + @Override + public Initialized init( + @Nonnull final InstanceIdentifier id, + @Nonnull final L2 readValue, + @Nonnull final ReadContext ctx) { + + org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2Builder + builder = + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2Builder(); + + if (readValue.getInterconnection() instanceof XconnectBased) { + XconnectBased state = (XconnectBased) readValue.getInterconnection(); + builder.setInterconnection( + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.XconnectBasedBuilder() + .setXconnectOutgoingInterface(state.getXconnectOutgoingInterface()) + .build()); + } else { + BridgeBased state = (BridgeBased) readValue.getInterconnection(); + builder.setInterconnection( + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.BridgeBasedBuilder() + .setBridgeDomain(state.getBridgeDomain()) + .setBridgedVirtualInterface(state.isBridgedVirtualInterface()) + .setSplitHorizonGroup(state.getSplitHorizonGroup()) + .build()); + } + + return Initialized.create(getCfgId(id), builder.setRewrite(readValue.getRewrite()).build()); + } + + static InstanceIdentifier getCfgId( + final InstanceIdentifier id) { + return SubInterfaceCustomizer.getCfgId(RWUtils.cutId(id, SubInterface.class)) + .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2.class); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/SubInterfaceRoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/SubInterfaceRoutingCustomizer.java new file mode 100644 index 000000000..831da821c --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/SubInterfaceRoutingCustomizer.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static io.fd.hc2vpp.v3po.util.SubInterfaceUtils.subInterfaceFullNameOperational; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; +import io.fd.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.Routing; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.RoutingBuilder; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + + +public class SubInterfaceRoutingCustomizer extends RoutingCustomizer implements + InitializingReaderCustomizer { + public SubInterfaceRoutingCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore, interfaceContext); + } + + @Nonnull + @Override + public Initialized init(@Nonnull final InstanceIdentifier instanceIdentifier, + @Nonnull final Routing routing, + @Nonnull final ReadContext readContext) { + return Initialized.create(instanceIdentifier, routing); + } + + @Nonnull + @Override + public RoutingBuilder getBuilder(@Nonnull final InstanceIdentifier instanceIdentifier) { + return new RoutingBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier instanceIdentifier, + @Nonnull final RoutingBuilder routingBuilder, + @Nonnull final ReadContext readContext) + throws ReadFailedException { + readInterfaceRouting(instanceIdentifier, routingBuilder::setIpv4VrfId, routingBuilder::setIpv6VrfId, + readContext, subInterfaceFullNameOperational(instanceIdentifier)); + } + + @Override + public void merge(@Nonnull final Builder builder, @Nonnull final Routing routing) { + ((SubInterfaceBuilder)builder).setRouting(routing); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/TapV2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/TapV2Customizer.java new file mode 100644 index 000000000..902440a34 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/TapV2Customizer.java @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2018 Pantheon Technologies and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static com.google.common.base.Preconditions.checkState; +import static java.lang.String.format; + +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.Ipv4Translator; +import io.fd.hc2vpp.common.translate.util.Ipv6Translator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.MacTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.StaticCacheKeyFactory; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import io.fd.jvpp.core.dto.SwInterfaceTapV2Details; +import io.fd.jvpp.core.dto.SwInterfaceTapV2DetailsReplyDump; +import io.fd.jvpp.core.dto.SwInterfaceTapV2Dump; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class TapV2Customizer extends FutureJVppCustomizer + implements InitializingReaderCustomizer, InterfaceDataTranslator, JvppReplyConsumer, + MacTranslator, Ipv4Translator, Ipv6Translator{ + + private static final Logger LOG = LoggerFactory.getLogger(TapV2Customizer.class); + private NamingContext interfaceContext; + private final InterfaceCacheDumpManager dumpManager; + private final DumpCacheManager tapV2DumpManager; + + public TapV2Customizer(@Nonnull final FutureJVppCore jvpp, + @Nonnull final NamingContext interfaceContext, + @Nonnull final InterfaceCacheDumpManager dumpManager) { + super(jvpp); + this.interfaceContext = interfaceContext; + this.dumpManager = dumpManager; + this.tapV2DumpManager = new DumpCacheManager.DumpCacheManagerBuilder() + .withCacheKeyFactory(new StaticCacheKeyFactory(TapV2Customizer.class.getName() + "_dump", + SwInterfaceTapV2DetailsReplyDump.class)) + .withExecutor((identifier, params) -> { + // Full TapV2 dump has to be performed here, no filter or anything is here to help so at least we cache it + return getReplyForRead(getFutureJVpp() + .swInterfaceTapV2Dump(new SwInterfaceTapV2Dump()).toCompletableFuture(), identifier); + }).build(); + } + + @Override + public void merge(@Nonnull Builder parentBuilder, @Nonnull TapV2 readValue) { + ((VppInterfaceAugmentationBuilder) parentBuilder).setTapV2(readValue); + } + + @Nonnull + @Override + public TapV2Builder getBuilder(@Nonnull InstanceIdentifier id) { + return new TapV2Builder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final TapV2Builder builder, + @Nonnull final ReadContext ctx) throws ReadFailedException { + + final InterfaceKey key = id.firstKeyOf(Interface.class); + final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext()); + if (!isInterfaceOfType(dumpManager, id, ctx, + org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.TapV2.class)) { + return; + } + + LOG.debug("Reading attributes for tapV2 interface: {}", key.getName()); + final SwInterfaceTapV2DetailsReplyDump reply = tapV2DumpManager.getDump(id, ctx.getModificationCache()) + .orElse(new SwInterfaceTapV2DetailsReplyDump()); + + final Optional detail = reply.swInterfaceTapV2Details.stream() + .filter(d -> d.swIfIndex == index) + .findAny(); + + checkState(detail.isPresent(), "TapV2 interface for index %s not found", index); + final SwInterfaceTapV2Details swInterfaceTapV2Details = detail.get(); + + LOG.trace("TapV2 interface: {} attributes returned from VPP: {}", key.getName(), swInterfaceTapV2Details); + if (swInterfaceTapV2Details.devName != null && swInterfaceTapV2Details.devName[0] != 0) { + builder.setDeviceName(toString(swInterfaceTapV2Details.devName)); + } else { + builder.setDeviceName(null); + } + + if (swInterfaceTapV2Details.hostBridge != null && swInterfaceTapV2Details.hostBridge[0] != 0) { + builder.setHostBridge(toString(swInterfaceTapV2Details.hostBridge)); + } else { + builder.setHostBridge(null); + } + + if (swInterfaceTapV2Details.hostMacAddr != null && + !ByteDataTranslator.INSTANCE.isArrayZeroed(swInterfaceTapV2Details.hostMacAddr)) { + builder.setHostMac(toPhysAddress(swInterfaceTapV2Details.hostMacAddr)); + } else { + builder.setHostMac(null); + } + + if (swInterfaceTapV2Details.hostIfName != null && swInterfaceTapV2Details.hostIfName[0] != 0) { + builder.setHostInterfaceName(toString(swInterfaceTapV2Details.hostIfName)); + } else { + builder.setHostInterfaceName(null); + } + + if (swInterfaceTapV2Details.hostIp4Addr != null && swInterfaceTapV2Details.hostIp4PrefixLen != 0) { + builder.setHostIpv4Address( + toIpv4Prefix(swInterfaceTapV2Details.hostIp4Addr, swInterfaceTapV2Details.hostIp4PrefixLen)); + } else { + builder.setHostIpv4Address(null); + } + + if (swInterfaceTapV2Details.hostIp6Addr != null && swInterfaceTapV2Details.hostIp6PrefixLen != 0) { + builder.setHostIpv6Address( + toIpv6Prefix(swInterfaceTapV2Details.hostIp6Addr, + Byte.toUnsignedInt(swInterfaceTapV2Details.hostIp6PrefixLen))); + } else { + builder.setHostIpv6Address(null); + } + + if (swInterfaceTapV2Details.hostNamespace != null && swInterfaceTapV2Details.hostNamespace[0] != 0) { + builder.setHostNamespace(toString(swInterfaceTapV2Details.hostNamespace)); + } else { + builder.setHostNamespace(null); + } + + + builder.setRxRingSize(Short.toUnsignedInt(swInterfaceTapV2Details.rxRingSz)); + builder.setTxRingSize(Short.toUnsignedInt(swInterfaceTapV2Details.txRingSz)); + final SwInterfaceDetails ifcDetails = dumpManager.getInterfaceDetail(id, ctx, key.getName()); + + if (ifcDetails.tag[0] != 0) { // tag supplied + builder.setTag(toString(ifcDetails.tag)); + } + LOG.debug("TapV2 interface: {}, id: {} attributes read as: {}", key.getName(), index, builder); + } + + @Override + public Initialized init( + @Nonnull final InstanceIdentifier id, @Nonnull final TapV2 readValue, + @Nonnull final ReadContext ctx) { + // The MAC address & tag is set from interface details, those details are retrieved from cache + final InterfaceKey key = id.firstKeyOf(Interface.class); + + final SwInterfaceDetails ifcDetails; + try { + ifcDetails = dumpManager.getInterfaceDetail(id, ctx, key.getName()); + } catch (ReadFailedException e) { + throw new IllegalStateException(format("Unable to read interface %s", key.getName()), e); + } + + return Initialized.create(getCfgId(id), + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2Builder() + .setMac(new PhysAddress(vppPhysAddrToYang(ifcDetails.l2Address))) + .setHostInterfaceName(readValue.getHostInterfaceName()) + .setTag(ifcDetails.tag[0] == 0 + ? null + : toString(ifcDetails.tag)) + .setHostBridge(readValue.getHostBridge()) + .setHostIpv4Address(readValue.getHostIpv4Address()) + .setHostIpv6Address(readValue.getHostIpv6Address()) + .setRxRingSize(readValue.getRxRingSize()) + .setTxRingSize(readValue.getTxRingSize()) + .setHostMac(readValue.getHostMac()) + .setHostNamespace(readValue.getHostNamespace()) + .build()); + } + + private InstanceIdentifier getCfgId( + final InstanceIdentifier id) { + return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) + .augmentation(VppInterfaceAugmentation.class) + .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2.class); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/VhostUserCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/VhostUserCustomizer.java new file mode 100644 index 000000000..58f395511 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/VhostUserCustomizer.java @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static java.lang.String.format; + +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.StaticCacheKeyFactory; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import io.fd.jvpp.core.dto.SwInterfaceVhostUserDetails; +import io.fd.jvpp.core.dto.SwInterfaceVhostUserDetailsReplyDump; +import io.fd.jvpp.core.dto.SwInterfaceVhostUserDump; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.math.BigInteger; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUserRole; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUser; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUserBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class VhostUserCustomizer implements InitializingReaderCustomizer, + InterfaceDataTranslator, JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(VhostUserCustomizer.class); + private NamingContext interfaceContext; + private final InterfaceCacheDumpManager dumpManager; + private final DumpCacheManager vhostDumpManager; + + public VhostUserCustomizer(@Nonnull final FutureJVppCore jvpp, + @Nonnull final NamingContext interfaceContext, + @Nonnull final InterfaceCacheDumpManager dumpManager) { + this.interfaceContext = interfaceContext; + this.dumpManager = dumpManager; + this.vhostDumpManager = + new DumpCacheManager.DumpCacheManagerBuilder() + .withCacheKeyFactory(new StaticCacheKeyFactory(VhostUserCustomizer.class.getName() + "_dump", + SwInterfaceVhostUserDetailsReplyDump.class)) + .withExecutor((identifier, params) -> { + final CompletionStage + swInterfaceVhostUserDetailsReplyDumpCompletionStage = + jvpp.swInterfaceVhostUserDump(new SwInterfaceVhostUserDump()); + return getReplyForRead( + swInterfaceVhostUserDetailsReplyDumpCompletionStage.toCompletableFuture(), + identifier); + }).build(); + } + + @Override + public void merge(@Nonnull Builder parentBuilder, @Nonnull VhostUser readValue) { + ((VppInterfaceAugmentationBuilder) parentBuilder).setVhostUser(readValue); + } + + @Nonnull + @Override + public VhostUserBuilder getBuilder(@Nonnull InstanceIdentifier id) { + return new VhostUserBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final VhostUserBuilder builder, + @Nonnull final ReadContext ctx) throws ReadFailedException { + + final InterfaceKey key = id.firstKeyOf(Interface.class); + final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext()); + final SwInterfaceDetails ifcDetails = dumpManager.getInterfaceDetail(id, ctx, key.getName()); + + + if (!isInterfaceOfType( + org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUser.class, + ifcDetails)) { + return; + } + + LOG.debug("Reading attributes for vhpost user interface: {}", key.getName()); + + + final SwInterfaceVhostUserDetailsReplyDump dump = + vhostDumpManager.getDump(id, ctx.getModificationCache()) + .orElse(new SwInterfaceVhostUserDetailsReplyDump()); + + // Relying here that parent InterfaceCustomizer was invoked first to fill in the context with initial ifc mapping + final SwInterfaceVhostUserDetails swInterfaceVhostUserDetails = dump.swInterfaceVhostUserDetails.stream() + .filter(detail -> detail.swIfIndex == index) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException( + format("Vhost user for interface %s not found", key.getName()))); + LOG.trace("Vhost user interface: {} attributes returned from VPP: {}", key.getName(), + swInterfaceVhostUserDetails); + + builder.setRole(swInterfaceVhostUserDetails.isServer == 1 + ? VhostUserRole.Server + : VhostUserRole.Client); + builder.setFeatures(BigInteger.valueOf(swInterfaceVhostUserDetails.features)); + builder.setNumMemoryRegions((long) swInterfaceVhostUserDetails.numRegions); + builder.setSocket(toString(swInterfaceVhostUserDetails.sockFilename)); + builder.setVirtioNetHdrSize((long) swInterfaceVhostUserDetails.virtioNetHdrSz); + // TODO: map error code to meaningful message after VPP-436 is done + builder.setConnectError(Integer.toString(swInterfaceVhostUserDetails.sockErrno)); + if (ifcDetails.tag[0] != 0) { // tag supplied + builder.setTag(toString(ifcDetails.tag)); + } + + LOG.debug("Vhost user interface: {}, id: {} attributes read as: {}", key.getName(), index, builder); + } + + @Override + public Initialized init( + @Nonnull final InstanceIdentifier id, + @Nonnull final VhostUser readValue, + @Nonnull final ReadContext ctx) { + // The tag is set from interface details, those details are retrieved from cache + final InterfaceKey key = id.firstKeyOf(Interface.class); + final SwInterfaceDetails ifcDetails; + try { + ifcDetails = dumpManager.getInterfaceDetail(id, ctx, key.getName()); + } catch (ReadFailedException e) { + throw new IllegalStateException(format("Unable to find VHost interface %s", key.getName()), e); + } + return Initialized.create(getCfgId(id), + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUserBuilder() + .setRole(readValue.getRole()) + .setSocket(readValue.getSocket()) + .setTag(ifcDetails.tag[0] == 0 + ? null + : toString(ifcDetails.tag)) + .build()); + } + + private InstanceIdentifier getCfgId( + final InstanceIdentifier id) { + return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) + .augmentation(VppInterfaceAugmentation.class) + .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUser.class); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/VxlanCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/VxlanCustomizer.java new file mode 100644 index 000000000..f2376bb45 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/VxlanCustomizer.java @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static com.google.common.base.Preconditions.checkState; + +import com.google.common.primitives.UnsignedInts; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.Ipv4Translator; +import io.fd.hc2vpp.common.translate.util.Ipv6Translator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.jvpp.core.dto.VxlanTunnelDetails; +import io.fd.jvpp.core.dto.VxlanTunnelDetailsReplyDump; +import io.fd.jvpp.core.dto.VxlanTunnelDump; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.L2Input; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.NshProxy; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanTunnel; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanVni; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Vxlan; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class VxlanCustomizer extends FutureJVppCustomizer + implements InitializingReaderCustomizer, InterfaceDataTranslator, JvppReplyConsumer, + Ipv4Translator, Ipv6Translator { + + private static final Logger LOG = LoggerFactory.getLogger(VxlanCustomizer.class); + private final NamingContext interfaceContext; + private final InterfaceCacheDumpManager dumpManager; + + public VxlanCustomizer(@Nonnull final FutureJVppCore jvpp, @Nonnull final NamingContext interfaceContext, + @Nonnull final InterfaceCacheDumpManager dumpManager) { + super(jvpp); + this.interfaceContext = interfaceContext; + this.dumpManager = dumpManager; + } + + @Override + public void merge(@Nonnull Builder parentBuilder, + @Nonnull Vxlan readValue) { + ((VppInterfaceAugmentationBuilder) parentBuilder).setVxlan(readValue); + } + + @Nonnull + @Override + public VxlanBuilder getBuilder(@Nonnull InstanceIdentifier id) { + return new VxlanBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final VxlanBuilder builder, + @Nonnull final ReadContext ctx) throws ReadFailedException { + + final InterfaceKey key = id.firstKeyOf(Interface.class); + final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext()); + if (!isInterfaceOfType(dumpManager, id, ctx, VxlanTunnel.class)) { + return; + } + + LOG.debug("Reading attributes for vxlan tunnel: {}", key.getName()); + // Dump just a single + final VxlanTunnelDump request = new VxlanTunnelDump(); + request.swIfIndex = index; + + final CompletionStage swInterfaceVxlanDetailsReplyDumpCompletionStage = + getFutureJVpp().vxlanTunnelDump(request); + final VxlanTunnelDetailsReplyDump reply = + getReplyForRead(swInterfaceVxlanDetailsReplyDumpCompletionStage.toCompletableFuture(), id); + + // VPP keeps vxlan tunnel interfaces even after they were deleted (optimization) + // However there ar no longer any vxlan tunnel specific fields assigned to it and this call + // returns nothing + if (reply == null || reply.vxlanTunnelDetails == null || reply.vxlanTunnelDetails.isEmpty()) { + LOG.debug( + "Vxlan tunnel {}, id {} has no attributes assigned in VPP. Probably is a leftover interface placeholder" + + "after delete", key.getName(), index); + return; + } + + checkState(reply.vxlanTunnelDetails.size() == 1, + "Unexpected number of returned vxlan tunnels: {} for tunnel: {}", reply.vxlanTunnelDetails, + key.getName()); + LOG.trace("Vxlan tunnel: {} attributes returned from VPP: {}", key.getName(), reply); + + final VxlanTunnelDetails swInterfaceVxlanDetails = reply.vxlanTunnelDetails.get(0); + if (swInterfaceVxlanDetails.isIpv6 == 1) { + builder.setDst(new IpAddressNoZone(arrayToIpv6AddressNoZone(swInterfaceVxlanDetails.dstAddress))); + builder.setSrc(new IpAddressNoZone(arrayToIpv6AddressNoZone(swInterfaceVxlanDetails.srcAddress))); + } else { + builder.setDst(new IpAddressNoZone(arrayToIpv4AddressNoZone(swInterfaceVxlanDetails.dstAddress))); + builder.setSrc(new IpAddressNoZone(arrayToIpv4AddressNoZone(swInterfaceVxlanDetails.srcAddress))); + } + builder.setEncapVrfId(new VniReference(UnsignedInts.toLong(swInterfaceVxlanDetails.encapVrfId))); + builder.setVni(new VxlanVni(UnsignedInts.toLong(swInterfaceVxlanDetails.vni))); + switch (swInterfaceVxlanDetails.decapNextIndex) { + case 1: + builder.setDecapNext(L2Input.class); + break; + case 2: + builder.setDecapNext(NshProxy.class); + break; + default: + LOG.trace("Unsupported decap next index for vxlan: {}", swInterfaceVxlanDetails.decapNextIndex); + return; + } + LOG.debug("Vxlan tunnel: {}, id: {} attributes read as: {}", key.getName(), index, builder); + } + + @Override + public Initialized init( + @Nonnull final InstanceIdentifier id, @Nonnull final Vxlan readValue, + @Nonnull final ReadContext ctx) { + return Initialized.create(getCfgId(id), + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanBuilder() + .setDst(readValue.getDst()) + .setSrc(readValue.getSrc()) + .setEncapVrfId(readValue.getEncapVrfId()) + .setVni(new VxlanVni(readValue.getVni())) + .setDecapNext(readValue.getDecapNext()) + .build()); + } + + private InstanceIdentifier getCfgId( + final InstanceIdentifier id) { + return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) + .augmentation(VppInterfaceAugmentation.class) + .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Vxlan.class); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/VxlanGpeCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/VxlanGpeCustomizer.java new file mode 100644 index 000000000..eb7269c4b --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/VxlanGpeCustomizer.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static com.google.common.base.Preconditions.checkState; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.Ipv4Translator; +import io.fd.hc2vpp.common.translate.util.Ipv6Translator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.jvpp.core.dto.VxlanGpeTunnelDetails; +import io.fd.jvpp.core.dto.VxlanGpeTunnelDetailsReplyDump; +import io.fd.jvpp.core.dto.VxlanGpeTunnelDump; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeNextProtocol; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeTunnel; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeVni; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpe; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpeBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class VxlanGpeCustomizer extends FutureJVppCustomizer + implements InitializingReaderCustomizer, InterfaceDataTranslator, JvppReplyConsumer, + Ipv4Translator, Ipv6Translator { + + private static final Logger LOG = LoggerFactory.getLogger(VxlanGpeCustomizer.class); + private final NamingContext interfaceContext; + private final InterfaceCacheDumpManager dumpManager; + + public VxlanGpeCustomizer(@Nonnull final FutureJVppCore jvpp, + @Nonnull final NamingContext interfaceContext, + @Nonnull final InterfaceCacheDumpManager dumpManager) { + super(jvpp); + this.interfaceContext = interfaceContext; + this.dumpManager = dumpManager; + } + + @Override + public void merge(@Nonnull Builder parentBuilder, + @Nonnull VxlanGpe readValue) { + ((VppInterfaceAugmentationBuilder) parentBuilder).setVxlanGpe(readValue); + } + + @Nonnull + @Override + public VxlanGpeBuilder getBuilder(@Nonnull InstanceIdentifier id) { + return new VxlanGpeBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final VxlanGpeBuilder builder, + @Nonnull final ReadContext ctx) throws ReadFailedException { + + final InterfaceKey key = id.firstKeyOf(Interface.class); + final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext()); + if (!isInterfaceOfType(dumpManager, id, ctx, VxlanGpeTunnel.class)) { + return; + } + + LOG.debug("Reading attributes for VxlanGpe tunnel: {}", key.getName()); + // Dump just a single + final VxlanGpeTunnelDump request = new VxlanGpeTunnelDump(); + request.swIfIndex = index; + + final CompletionStage swInterfaceVxlanGpeDetailsReplyDumpCompletionStage = + getFutureJVpp().vxlanGpeTunnelDump(request); + final VxlanGpeTunnelDetailsReplyDump reply = + getReplyForRead(swInterfaceVxlanGpeDetailsReplyDumpCompletionStage.toCompletableFuture(), + id); + + // VPP keeps VxlanGpe tunnel interfaces even after they were deleted (optimization) + // However there are no longer any VxlanGpe tunnel specific fields assigned to it and this call + // returns nothing + if (reply == null || reply.vxlanGpeTunnelDetails == null || reply.vxlanGpeTunnelDetails.isEmpty()) { + LOG.debug( + "VxlanGpe tunnel {}, id {} has no attributes assigned in VPP. Probably is a leftover interface placeholder" + + "after delete", key.getName(), index); + return; + } + + checkState(reply.vxlanGpeTunnelDetails.size() == 1, + "Unexpected number of returned VxlanGpe tunnels: {} for tunnel: {}", reply.vxlanGpeTunnelDetails, + key.getName()); + LOG.trace("VxlanGpe tunnel: {} attributes returned from VPP: {}", key.getName(), reply); + + final VxlanGpeTunnelDetails swInterfaceVxlanGpeDetails = reply.vxlanGpeTunnelDetails.get(0); + if (swInterfaceVxlanGpeDetails.isIpv6 == 1) { + builder.setRemote(new IpAddressNoZone(arrayToIpv6AddressNoZone(swInterfaceVxlanGpeDetails.remote))); + builder.setLocal(new IpAddressNoZone(arrayToIpv6AddressNoZone(swInterfaceVxlanGpeDetails.local))); + } else { + builder.setRemote(new IpAddressNoZone(arrayToIpv4AddressNoZone(swInterfaceVxlanGpeDetails.remote))); + builder.setLocal(new IpAddressNoZone(arrayToIpv4AddressNoZone(swInterfaceVxlanGpeDetails.local))); + } + builder.setVni(new VxlanGpeVni((long) swInterfaceVxlanGpeDetails.vni)); + builder.setNextProtocol(VxlanGpeNextProtocol.forValue(swInterfaceVxlanGpeDetails.protocol)); + builder.setEncapVrfId((long) swInterfaceVxlanGpeDetails.encapVrfId); + builder.setDecapVrfId((long) swInterfaceVxlanGpeDetails.decapVrfId); + LOG.debug("VxlanGpe tunnel: {}, id: {} attributes read as: {}", key.getName(), index, builder); + } + + @Override + public Initialized init( + @Nonnull final InstanceIdentifier id, @Nonnull final VxlanGpe readValue, + @Nonnull final ReadContext ctx) { + return Initialized.create(getCfgId(id), + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpeBuilder() + .setLocal(readValue.getLocal()) + .setRemote(readValue.getRemote()) + .setVni(new VxlanGpeVni(readValue.getVni())) + .setNextProtocol(readValue.getNextProtocol()) + .setEncapVrfId(readValue.getEncapVrfId()) + .setDecapVrfId(readValue.getDecapVrfId()) + .build()); + } + + private InstanceIdentifier getCfgId( + final InstanceIdentifier id) { + return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) + .augmentation(VppInterfaceAugmentation.class) + .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpe.class); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManager.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManager.java new file mode 100644 index 000000000..3d8df7e6c --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManager.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read.cache; + +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import java.util.stream.Stream; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * Manager for dump data of interfaces. The main purpose of this manager is to cache common interface data between + * various classes that process this kind of data. If reader does not use this utility, it introduces a big overhead + * because of size/complexity of interfaces dump + */ +public interface InterfaceCacheDumpManager { + + /** + * Provides stream of all currently configured vpp interfaces + * + * @param identifier id of currently processed data + * @param ctx context of current transaction + * @return {@link Stream} of currently configured interfaces + * @throws ReadFailedException if dumping of data was unsuccessful + */ + @Nonnull + Stream getInterfaces(@Nonnull final InstanceIdentifier identifier, + @Nonnull final ReadContext ctx) throws ReadFailedException; + + /** + * Provides details of interface + * + * @param identifier id of currently processed data + * @param ctx context of current transaction + * @param interfaceName name of requested interface + * @return {@link SwInterfaceDetails} of requested interface + * @throws ReadFailedException if dumping of data was unsuccessful + */ + @Nullable + SwInterfaceDetails getInterfaceDetail(@Nonnull final InstanceIdentifier identifier, + @Nonnull final ReadContext ctx, + @Nonnull final String interfaceName) throws ReadFailedException; +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerImpl.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerImpl.java new file mode 100644 index 000000000..0aee8e459 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerImpl.java @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read.cache; + +import static io.fd.hc2vpp.common.translate.util.JvppReplyConsumer.INSTANCE; +import static java.util.stream.Collectors.toMap; + +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; +import io.fd.honeycomb.translate.util.read.cache.StaticCacheKeyFactory; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import io.fd.jvpp.core.dto.SwInterfaceDetailsReplyDump; +import io.fd.jvpp.core.dto.SwInterfaceDump; +import io.fd.jvpp.core.future.FutureJVppCore; +import io.fd.jvpp.core.types.InterfaceIndex; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Stream; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Manager for dump data of interfaces/sub-interfaces + */ +final class InterfaceCacheDumpManagerImpl implements InterfaceCacheDumpManager { + + private static final Logger LOG = LoggerFactory.getLogger(InterfaceCacheDumpManagerImpl.class); + + // byNameIndex must be cached, not held as reference here, to have it destroyed with cache after transaction + static final String BY_NAME_INDEX_KEY = InterfaceCacheDumpManagerImpl.class.getName() + "_byNameIndex"; + private NamingContext namingContext; + private final DumpCacheManager specificDumpManager; + private final DumpCacheManager fullDumpManager; + + InterfaceCacheDumpManagerImpl(@Nonnull final FutureJVppCore jvpp, + @Nonnull final NamingContext namingContext) { + this.namingContext = namingContext; + specificDumpManager = specificInterfaceDumpManager(jvpp); + fullDumpManager = fullInterfaceDumpManager(jvpp, + new StaticCacheKeyFactory(InterfaceCacheDumpManagerImpl.class.getName() + "_dump", SwInterfaceDetailsReplyDump.class)); + } + + @Override + @Nonnull + public synchronized Stream getInterfaces(@Nonnull final InstanceIdentifier identifier, + @Nonnull final ReadContext ctx) + throws ReadFailedException { + LOG.debug("Reading all interfaces[{}]", identifier); + return initMapAndGet(identifier, ctx).entrySet().stream().map(Map.Entry::getValue); + } + + @Override + @Nullable + public synchronized SwInterfaceDetails getInterfaceDetail(@Nonnull final InstanceIdentifier identifier, + @Nonnull final ReadContext ctx, + @Nonnull final String interfaceName) + throws ReadFailedException { + final Map interfaceIndex = getMap(ctx); + + // does not attempt to cover cases with concurrent updates, as tx should be atomic + if (interfaceIndex != null) { + // tries to find interface in map + return interfaceIndex.get(interfaceName); + } else { + // if map is not present, use specific dump(it will be cached standard way, under key constructed from IID) + return dumpSpecificDetail(identifier, ctx, interfaceName); + } + } + + private SwInterfaceDetails dumpSpecificDetail(@Nonnull final InstanceIdentifier identifier, + @Nonnull final ReadContext ctx, + @Nonnull final String interfaceName) + throws ReadFailedException { + LOG.debug("Interface {} not present in cached data, performing specific dump[{}]", interfaceName, + identifier); + final SwInterfaceDetailsReplyDump reply = + specificDumpManager.getDump(identifier, ctx.getModificationCache(), interfaceName) + .orElse(new SwInterfaceDetailsReplyDump()); + + if (reply.swInterfaceDetails.isEmpty()) { + return null; + } + + return reply.swInterfaceDetails.get(0); + } + + private Map initMapAndGet(final InstanceIdentifier identifier, final ReadContext ctx) + throws ReadFailedException { + + final ModificationCache cache = ctx.getModificationCache(); + if (!cache.containsKey(BY_NAME_INDEX_KEY)) { + LOG.debug("Performing dump[{}]", identifier); + final SwInterfaceDetailsReplyDump dump = + fullDumpManager.getDump(identifier, cache) + .orElse(new SwInterfaceDetailsReplyDump()); + + // naming context initialization must be done here, as it is uses getName in next step, therefore it would + // create artificial mapping for every interface, because this happens before interface dump is processed + dump.swInterfaceDetails.forEach((elt) -> { + // Store interface name from VPP in context if not yet present + if (!namingContext.containsName(elt.swIfIndex, ctx.getMappingContext())) { + namingContext.addName(elt.swIfIndex, ByteDataTranslator.INSTANCE.toString(elt.interfaceName), + ctx.getMappingContext()); + } + LOG.trace("Interface with name: {}, VPP name: {} and index: {} found in VPP", + getInterfaceName(ctx, elt), + elt.interfaceName, + elt.swIfIndex); + }); + + final Map freshIndex = dump.swInterfaceDetails.stream() + .collect(toMap(detail -> getInterfaceName(ctx, detail), + detail -> detail)); + putMap(freshIndex, ctx); + } + + return getMap(ctx); + } + + private String getInterfaceName(final ReadContext ctx, final SwInterfaceDetails elt) { + return namingContext.getName(elt.swIfIndex, ctx.getMappingContext()); + } + + private static Map getMap(final ReadContext ctx) { + return (Map) ctx.getModificationCache().get(BY_NAME_INDEX_KEY); + } + + private static void putMap(final Map map, final ReadContext ctx) { + ctx.getModificationCache().put(BY_NAME_INDEX_KEY, map); + } + + + private static DumpCacheManager fullInterfaceDumpManager( + final FutureJVppCore jvpp, + final StaticCacheKeyFactory cacheKeyFactory) { + return new DumpCacheManager.DumpCacheManagerBuilder() + .withExecutor(fullInterfaceDumpExecutor(jvpp)) + .withCacheKeyFactory(cacheKeyFactory) + .acceptOnly(SwInterfaceDetailsReplyDump.class) + .build(); + } + + private static DumpCacheManager specificInterfaceDumpManager( + final FutureJVppCore jvpp) { + return new DumpCacheManager.DumpCacheManagerBuilder() + .withExecutor(specificInterfaceDumpExecutor(jvpp)) + .acceptOnly(SwInterfaceDetailsReplyDump.class) + .build(); + } + + private static EntityDumpExecutor fullInterfaceDumpExecutor( + final FutureJVppCore api) { + return (identifier, params) -> { + final SwInterfaceDump request = new SwInterfaceDump(); + request.swIfIndex = new InterfaceIndex(); + request.swIfIndex.interfaceindex = ~0; + request.nameFilter = "".getBytes(); + request.nameFilterValid = 0; + + final CompletableFuture + swInterfaceDetailsReplyDumpCompletableFuture = api.swInterfaceDump(request).toCompletableFuture(); + return INSTANCE.getReplyForRead(swInterfaceDetailsReplyDumpCompletableFuture, identifier); + }; + } + + private static EntityDumpExecutor specificInterfaceDumpExecutor( + final FutureJVppCore api) { + return (identifier, ifaceName) -> { + final SwInterfaceDump request = new SwInterfaceDump(); + request.swIfIndex = new InterfaceIndex(); + request.swIfIndex.interfaceindex =~0; + request.nameFilter = ifaceName.getBytes(); + request.nameFilterValid = 1; + + final CompletableFuture + swInterfaceDetailsReplyDumpCompletableFuture = api.swInterfaceDump(request).toCompletableFuture(); + return INSTANCE.getReplyForRead(swInterfaceDetailsReplyDumpCompletableFuture, identifier); + }; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerProvider.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerProvider.java new file mode 100644 index 000000000..6fb4f730f --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerProvider.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read.cache; + +import com.google.inject.Inject; +import com.google.inject.Provider; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.jvpp.core.future.FutureJVppCore; +import javax.inject.Named; + +public class InterfaceCacheDumpManagerProvider implements Provider { + + @Inject + private FutureJVppCore jvpp; + + @Inject + @Named("interface-context") + private NamingContext namingContext; + + @Override + public InterfaceCacheDumpManager get() { + return new InterfaceCacheDumpManagerImpl(jvpp, namingContext); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceStatisticsManager.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceStatisticsManager.java new file mode 100644 index 000000000..d23f06eac --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceStatisticsManager.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2019 PANTHEON.tech. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read.cache; + +public interface InterfaceStatisticsManager { + + boolean isStatisticsEnabled(); + + void enableStatistics(); + + void disableStatistics(); +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceStatisticsManagerImpl.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceStatisticsManagerImpl.java new file mode 100644 index 000000000..8450d3484 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceStatisticsManagerImpl.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019 PANTHEON.tech. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read.cache; + +public class InterfaceStatisticsManagerImpl implements InterfaceStatisticsManager { + + private boolean isEnabled; + + @Override + public boolean isStatisticsEnabled() { + return isEnabled; + } + + @Override + public void enableStatistics() { + isEnabled = true; + } + + @Override + public void disableStatistics() { + isEnabled = false; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceStatisticsManagerProvider.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceStatisticsManagerProvider.java new file mode 100644 index 000000000..b62487b56 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/cache/InterfaceStatisticsManagerProvider.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2019 PANTHEON.tech. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read.cache; + +import com.google.inject.Provider; + +public class InterfaceStatisticsManagerProvider implements Provider { + + @Override + public InterfaceStatisticsManager get() { + return new InterfaceStatisticsManagerImpl(); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/pbb/PbbRewriteCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/pbb/PbbRewriteCustomizer.java new file mode 100644 index 000000000..a77a7db7d --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/pbb/PbbRewriteCustomizer.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read.pbb; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.PbbRewriteInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewrite; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewriteBuilder; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class PbbRewriteCustomizer extends FutureJVppCustomizer + implements ReaderCustomizer { + + public PbbRewriteCustomizer(@Nonnull final FutureJVppCore futureJVppCore) { + super(futureJVppCore); + } + + @Nonnull + @Override + public PbbRewriteBuilder getBuilder(@Nonnull final InstanceIdentifier id) { + return new PbbRewriteBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final PbbRewriteBuilder builder, @Nonnull final ReadContext ctx) + throws ReadFailedException { + //TODO implement read after https://jira.fd.io/browse/VPP-468 + init + } + + @Override + public void merge(@Nonnull final Builder parentBuilder, + @Nonnull final PbbRewrite readValue) { + ((PbbRewriteInterfaceAugmentationBuilder) parentBuilder).setPbbRewrite(readValue); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/span/AbstractMirroredInterfacesCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/span/AbstractMirroredInterfacesCustomizer.java new file mode 100644 index 000000000..12dcbe3cc --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/span/AbstractMirroredInterfacesCustomizer.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read.span; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; +import io.fd.jvpp.core.dto.SwInterfaceSpanDetailsReplyDump; +import io.fd.jvpp.core.dto.SwInterfaceSpanDump; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.SpanState; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfacesBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +abstract class AbstractMirroredInterfacesCustomizer + extends FutureJVppCustomizer + implements InitializingReaderCustomizer, JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(AbstractMirroredInterfacesCustomizer.class); + + private final NamingContext ifcContext; + private final Function, String> destinationInterfaceNameExtractor; + + protected AbstractMirroredInterfacesCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext ifcContext, + @Nonnull final Function, String> destinationInterfaceNameExtractor) { + super(futureJVppCore); + this.ifcContext = ifcContext; + this.destinationInterfaceNameExtractor = destinationInterfaceNameExtractor; + } + + @Nonnull + @Override + public MirroredInterfacesBuilder getBuilder(@Nonnull final InstanceIdentifier id) { + return new MirroredInterfacesBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final MirroredInterfacesBuilder builder, @Nonnull final ReadContext ctx) + throws ReadFailedException { + LOG.trace("Reading mirrored interfaces under: {}", id); + final int dstId = destinationInterfaceIndex(id, ctx.getMappingContext()); + + final SwInterfaceSpanDetailsReplyDump replyForRead; + if (ctx.getModificationCache().containsKey(getCacheKey())) { + replyForRead = (SwInterfaceSpanDetailsReplyDump) ctx.getModificationCache().get(getCacheKey()); + } else { + replyForRead = getReplyForRead(getFutureJVpp().swInterfaceSpanDump( + new SwInterfaceSpanDump()).toCompletableFuture(), id); + ctx.getModificationCache().put(getCacheKey(), replyForRead); + } + + final List mirroredInterfaces = + replyForRead.swInterfaceSpanDetails.stream() + .filter(detail -> detail.swIfIndexTo == dstId) + .filter(detail -> detail.state != 0) // filters disabled(we use disabled as delete) + .map(detail -> { + final String interfaceName = + ifcContext.getName(detail.swIfIndexFrom, ctx.getMappingContext()); + return new MirroredInterfaceBuilder() + .setIfaceRef(interfaceName) + .withKey(new MirroredInterfaceKey(interfaceName)) + .setState(SpanState.forValue(detail.state)) + .build(); + } + ) + .collect(Collectors.toList()); + + LOG.debug("Mirrored interfaces for: {} read as: {}", id, mirroredInterfaces); + + if (!mirroredInterfaces.isEmpty()) { + builder.setMirroredInterface(mirroredInterfaces); + } + } + + private String getCacheKey() { + return getClass().getName(); + } + + private int destinationInterfaceIndex(@Nonnull final InstanceIdentifier id, + @Nonnull final MappingContext mappingContext) { + final String destinationInterfaceName = destinationInterfaceNameExtractor.apply(id); + return ifcContext.getIndex(destinationInterfaceName, mappingContext); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/span/InterfaceMirroredInterfacesCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/span/InterfaceMirroredInterfacesCustomizer.java new file mode 100644 index 000000000..841ee85da --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/span/InterfaceMirroredInterfacesCustomizer.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read.span; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.InterfaceCustomizer; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.Collections; +import java.util.Optional; +import java.util.stream.Collectors; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.SpanBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfacesBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * Provides interface-specific logic to read/init port mirroring configuration + */ +public class InterfaceMirroredInterfacesCustomizer extends AbstractMirroredInterfacesCustomizer { + + public InterfaceMirroredInterfacesCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext ifcContext) { + super(futureJVppCore, ifcContext, id -> id.firstKeyOf(Interface.class).getName()); + } + + @Nonnull + @Override + public Initialized init(@Nonnull final InstanceIdentifier id, + @Nonnull final MirroredInterfaces readValue, + @Nonnull final ReadContext ctx) { + final InstanceIdentifier cfgId = + InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) + .augmentation(VppInterfaceAugmentation.class) + .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Span.class) + .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces.class); + final org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces + cfgValue = new MirroredInterfacesBuilder() + .setMirroredInterface(Optional.ofNullable(readValue.getMirroredInterface()).orElse(Collections.emptyList()) + .stream() + .map(mirroredInterface -> new MirroredInterfaceBuilder() + .setState(mirroredInterface.getState()) + .withKey(new MirroredInterfaceKey(mirroredInterface.key().getIfaceRef())) + .setIfaceRef(mirroredInterface.getIfaceRef()) + .build()) + .collect(Collectors.toList())) + .build(); + return Initialized.create(cfgId, cfgValue); + } + + @Override + public void merge(@Nonnull Builder builder, @Nonnull MirroredInterfaces mirroredInterfaces) { + ((SpanBuilder) builder).setMirroredInterfaces(mirroredInterfaces); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/span/SubInterfaceMirroredInterfacesCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/span/SubInterfaceMirroredInterfacesCustomizer.java new file mode 100644 index 000000000..308edee8e --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/read/span/SubInterfaceMirroredInterfacesCustomizer.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read.span; + + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.SubInterfaceCustomizer; +import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.Collections; +import java.util.Optional; +import java.util.stream.Collectors; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev170607.VppSubinterfaceSpanAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev170607.interfaces._interface.sub.interfaces.sub._interface.Span; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.subinterface.span.rev170607.interfaces._interface.sub.interfaces.sub._interface.SpanBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * Provides sub-interface-specific logic to read/init port mirroring configuration + */ +public class SubInterfaceMirroredInterfacesCustomizer extends AbstractMirroredInterfacesCustomizer { + + public SubInterfaceMirroredInterfacesCustomizer(@Nonnull FutureJVppCore futureJVppCore, NamingContext ifcContext) { + super(futureJVppCore, ifcContext, SubInterfaceUtils::subInterfaceFullNameOperational); + } + + @Nonnull + @Override + public Initialized init(@Nonnull InstanceIdentifier id, + @Nonnull MirroredInterfaces readValue, + @Nonnull ReadContext readContext) { + final InstanceIdentifier cfgId = + SubInterfaceCustomizer.getCfgId(RWUtils.cutId(id, SubInterface.class)) + .augmentation(VppSubinterfaceSpanAugmentation.class) + .child(Span.class) + .child(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces.class); + + final org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces + cfgValue = new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfacesBuilder() + .setMirroredInterface( + Optional.ofNullable(readValue.getMirroredInterface()).orElse(Collections.emptyList()) + .stream() + .map(mirroredInterface -> new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceBuilder() + .withKey(new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceKey(mirroredInterface.key().getIfaceRef())) + .setIfaceRef(mirroredInterface.getIfaceRef()) + .setState(mirroredInterface.getState()) + .build()) + .collect(Collectors.toList())) + .build(); + + return Initialized.create(cfgId, cfgValue); + } + + @Override + public void merge(@Nonnull Builder builder, @Nonnull MirroredInterfaces mirroredInterfaces) { + ((SpanBuilder) builder).setMirroredInterfaces(mirroredInterfaces); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/util/SubInterfaceUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/util/SubInterfaceUtils.java index dc3073fef..3b21af392 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/util/SubInterfaceUtils.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/util/SubInterfaceUtils.java @@ -47,10 +47,9 @@ public final class SubInterfaceUtils { } public static String subInterfaceFullNameOperational(final @Nonnull InstanceIdentifier instanceIdentifier) { - final String parentInterfaceName = checkNotNull(instanceIdentifier.firstKeyOf( - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface.class), + final String parentInterfaceName = checkNotNull(instanceIdentifier.firstKeyOf(Interface.class), "Operational identifier expected").getName(); - final Long subIfId = instanceIdentifier.firstKeyOf(org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface.class).getIdentifier(); + final Long subIfId = instanceIdentifier.firstKeyOf(SubInterface.class).getIdentifier(); return SubInterfaceUtils.getSubInterfaceName(parentInterfaceName, subIfId.intValue()); } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/AbstractUnnumberedCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/AbstractUnnumberedCustomizer.java new file mode 100644 index 000000000..15b4be75b --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/AbstractUnnumberedCustomizer.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.SwInterfaceSetUnnumbered; +import io.fd.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +abstract class AbstractUnnumberedCustomizer extends FutureJVppCustomizer implements WriterCustomizer, + JvppReplyConsumer, ByteDataTranslator { + private static final Logger LOG = LoggerFactory.getLogger(AbstractUnnumberedCustomizer.class); + + private final NamingContext interfaceContext; + + protected AbstractUnnumberedCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + protected void setUnnumbered(@Nonnull final InstanceIdentifier id, + @Nonnull final String unnumberedIfcName, + @Nonnull final Unnumbered data, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final int unnumberedIfcId = interfaceContext.getIndex(unnumberedIfcName, writeContext.getMappingContext()); + final int targetId = interfaceContext.getIndex(data.getUse(), writeContext.getMappingContext()); + final SwInterfaceSetUnnumbered request = getUnnumberedAddDelRequest(targetId, unnumberedIfcId, true); + getReplyForWrite(getFutureJVpp().swInterfaceSetUnnumbered(request).toCompletableFuture(), id); + LOG.debug("The {}(id={}) interface unnumbered flag was set: {}", unnumberedIfcName, unnumberedIfcId, data); + } + + protected void disableUnnumbered(@Nonnull final InstanceIdentifier id, + @Nonnull final String unnumberedIfcName, + @Nonnull final Unnumbered data, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final int unnumberedIfcId = interfaceContext.getIndex(unnumberedIfcName, writeContext.getMappingContext()); + final int targetId = interfaceContext.getIndex(data.getUse(), writeContext.getMappingContext()); + final SwInterfaceSetUnnumbered request = getUnnumberedAddDelRequest(targetId, unnumberedIfcId, false); + getReplyForWrite(getFutureJVpp().swInterfaceSetUnnumbered(request).toCompletableFuture(), id); + LOG.debug("The {}(id={}) interface unnumbered flag was unset: {}", unnumberedIfcName, unnumberedIfcId, data); + } + + private SwInterfaceSetUnnumbered getUnnumberedAddDelRequest(final int targetId, final int unnumberedIfcId, + final Boolean isAdd) { + final SwInterfaceSetUnnumbered request = new SwInterfaceSetUnnumbered(); + request.swIfIndex = targetId; + request.unnumberedSwIfIndex = unnumberedIfcId; + request.isAdd = booleanToByte(isAdd); + return request; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/AfPacketCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/AfPacketCustomizer.java new file mode 100644 index 000000000..f8e658216 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/AfPacketCustomizer.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2018 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.MacTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.AfPacketCreate; +import io.fd.jvpp.core.dto.AfPacketCreateReply; +import io.fd.jvpp.core.dto.AfPacketDelete; +import io.fd.jvpp.core.dto.AfPacketDeleteReply; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacket; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AfPacketCustomizer extends AbstractInterfaceTypeCustomizer + implements MacTranslator, JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(AfPacketCustomizer.class); + private final NamingContext interfaceContext; + + public AfPacketCustomizer(@Nonnull final FutureJVppCore vppApi, @Nonnull final NamingContext interfaceContext) { + super(vppApi); + this.interfaceContext = interfaceContext; + } + + @Override + protected Class getExpectedInterfaceType() { + return org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.AfPacket.class; + } + + @Override + protected final void writeInterface(@Nonnull final InstanceIdentifier id, + @Nonnull final AfPacket dataAfter, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String swIfName = id.firstKeyOf(Interface.class).getName(); + final int swIfIndex = createAfPacketIfc(id, swIfName, dataAfter); + + // Add new interface to our interface context + interfaceContext.addName(swIfIndex, swIfName, writeContext.getMappingContext()); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final AfPacket dataBefore, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String swIfName = id.firstKeyOf(Interface.class).getName(); + deleteAfPacketIfc(id, swIfName, dataBefore); + + // Remove interface from interface context + interfaceContext.removeName(swIfName, writeContext.getMappingContext()); + } + + private int createAfPacketIfc(final InstanceIdentifier id, final String swIfName, final AfPacket afPacket) + throws WriteFailedException { + LOG.debug("Creating af_packet interface {}: {}", swIfName, afPacket); + final CompletionStage createAfPacketIfReplyCompletionStage = + getFutureJVpp().afPacketCreate(getCreateRequest(afPacket)); + final AfPacketCreateReply reply = + getReplyForCreate(createAfPacketIfReplyCompletionStage.toCompletableFuture(), id, afPacket); + LOG.debug("Af_packet interface {} created successfully: {}", swIfName, afPacket); + return reply.swIfIndex; + } + + private AfPacketCreate getCreateRequest(@Nonnull final AfPacket afPacket) { + final AfPacketCreate request = new AfPacketCreate(); + request.hostIfName = afPacket.getHostInterfaceName().getBytes(StandardCharsets.UTF_8); + final PhysAddress mac = afPacket.getMac(); + if (mac == null) { + request.useRandomHwAddr = 1; + request.hwAddr = new byte[6]; + } else { + request.useRandomHwAddr = 0; + request.hwAddr = parseMac(mac.getValue()); + } + return request; + } + + private void deleteAfPacketIfc(final InstanceIdentifier id, final String swIfName, + final AfPacket afPacket) throws WriteFailedException { + LOG.debug("Deleting af_packet interface {}: {}", swIfName, afPacket); + final CompletionStage deleteAfPacketIfReplyCompletionStage = + getFutureJVpp().afPacketDelete(getDeleteRequest(afPacket)); + + getReplyForDelete(deleteAfPacketIfReplyCompletionStage.toCompletableFuture(), id); + LOG.debug("Af_packet interface {} deleted successfully: {}", swIfName, afPacket); + } + + private AfPacketDelete getDeleteRequest(@Nonnull final AfPacket afPacket) { + final AfPacketDelete request = new AfPacketDelete(); + request.hostIfName = afPacket.getHostInterfaceName().getBytes(StandardCharsets.UTF_8); + return request; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/AfPacketValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/AfPacketValidator.java new file mode 100644 index 000000000..392875190 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/AfPacketValidator.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import java.nio.charset.StandardCharsets; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacket; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class AfPacketValidator implements Validator { + + public AfPacketValidator(@Nonnull final NamingContext interfaceContext) { + checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final AfPacket dataAfter, + @Nonnull final WriteContext writeContext) + throws CreateValidationFailedException { + try { + validateAfPacket(dataAfter); + } catch (Exception e) { + throw new CreateValidationFailedException(id, dataAfter, e); + } + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final AfPacket dataBefore, + @Nonnull final AfPacket dataAfter, @Nonnull final WriteContext writeContext) + throws UpdateValidationFailedException { + try { + validateAfPacket(dataAfter); + } catch (Exception e) { + throw new UpdateValidationFailedException(id, dataBefore, dataAfter, e); + } + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final AfPacket dataBefore, + @Nonnull final WriteContext writeContext) + throws DeleteValidationFailedException { + try { + validateAfPacket(dataBefore); + } catch (Exception e) { + throw new DeleteValidationFailedException(id, e); + } + } + + private void validateAfPacket(final AfPacket data) { + checkNotNull(data.getHostInterfaceName(), "host-interface-name is mandatory for af-packet interface"); + byte[] hostIfName = data.getHostInterfaceName().getBytes(StandardCharsets.UTF_8); + checkArgument(hostIfName.length <= 64, + "Interface name for af_packet interface should not be longer than 64 bytes, but was %s", + hostIfName.length); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/EthernetCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/EthernetCustomizer.java new file mode 100644 index 000000000..029f6f308 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/EthernetCustomizer.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.HwInterfaceSetMtu; +import io.fd.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Ethernet; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev180703.EthernetCsmacd; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class EthernetCustomizer extends AbstractInterfaceTypeCustomizer implements JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(EthernetCustomizer.class); + private final NamingContext interfaceContext; + + public EthernetCustomizer(final FutureJVppCore vppApi, final NamingContext interfaceContext) { + super(vppApi); + this.interfaceContext = interfaceContext; + } + + @Override + protected Class getExpectedInterfaceType() { + return EthernetCsmacd.class; + } + + @Override + public void writeInterface(@Nonnull final InstanceIdentifier id, + @Nonnull final Ethernet dataAfter, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + setEthernetAttributes(id, dataAfter, writeContext); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Ethernet dataBefore, @Nonnull final Ethernet dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + setEthernetAttributes(id, dataAfter, writeContext); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Ethernet dataBefore, @Nonnull final WriteContext writeContext) + throws WriteFailedException.DeleteFailedException { + throw new WriteFailedException.DeleteFailedException(id, + new UnsupportedOperationException("Removing ethernet container is not supported")); + } + + private void setEthernetAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Ethernet dataAfter, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String name = id.firstKeyOf(Interface.class).getName(); + final int index = interfaceContext.getIndex(name, writeContext.getMappingContext()); + LOG.debug("Setting Ethernet attributes for interface: {}, {}. Ethernet: {}", name, index, dataAfter); + + // Set the physical payload MTU. I.e. not including L2 overhead. + // Setting the hardware MTU will program the NIC. + // Setting MTU for software interfaces is currently not supported (TODO: HC2VPP-355). + // More details: + // https://git.fd.io/vpp/tree/src/vnet/MTU.md + final HwInterfaceSetMtu request = new HwInterfaceSetMtu(); + request.swIfIndex = index; + request.mtu = dataAfter.getMtu().shortValue(); + getReplyForWrite(getFutureJVpp().hwInterfaceSetMtu(request).toCompletableFuture(), id); + LOG.debug("Ethernet attributes set successfully for: {}, {}. Ethernet: {}", name, index, dataAfter); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/EthernetValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/EthernetValidator.java new file mode 100644 index 000000000..ebdd17346 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/EthernetValidator.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Ethernet; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class EthernetValidator implements Validator { + + public EthernetValidator(final NamingContext interfaceContext) { + checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Ethernet dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.CreateValidationFailedException { + checkNotNull(dataAfter.getMtu(), "MTU cannot be null"); + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Ethernet dataBefore, + @Nonnull final Ethernet dataAfter, @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.UpdateValidationFailedException { + checkNotNull(dataAfter.getMtu(), "MTU cannot be null"); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/GreCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/GreCustomizer.java new file mode 100644 index 000000000..adb7e2401 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/GreCustomizer.java @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2016 Intel and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.GreTunnelAddDel; +import io.fd.jvpp.core.dto.GreTunnelAddDelReply; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.GreTunnel; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Gre; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class GreCustomizer extends AbstractInterfaceTypeCustomizer implements JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(GreCustomizer.class); + private final NamingContext interfaceContext; + + public GreCustomizer(final FutureJVppCore vppApi, final NamingContext interfaceContext) { + super(vppApi); + this.interfaceContext = interfaceContext; + } + + private static GreTunnelAddDel getGreTunnelRequest(final byte isAdd, final IpAddressNoZone srcAddr, + final IpAddressNoZone dstAddr, final int outerFibId, + final byte isIpv6) { + final GreTunnelAddDel greTunnelAddDel = new GreTunnelAddDel(); + greTunnelAddDel.isAdd = isAdd; + greTunnelAddDel.tunnel = new io.fd.jvpp.core.types.GreTunnel(); + if (isIpv6==0) { + greTunnelAddDel.tunnel.src = + AddressTranslator.INSTANCE.ipv4AddressNoZoneToAddress(srcAddr.getIpv4AddressNoZone()); + greTunnelAddDel.tunnel.dst = + AddressTranslator.INSTANCE.ipv4AddressNoZoneToAddress(dstAddr.getIpv4AddressNoZone()); + } else { + greTunnelAddDel.tunnel.src = + AddressTranslator.INSTANCE.ipv6AddressToAddress(srcAddr.getIpv6AddressNoZone()); + greTunnelAddDel.tunnel.dst = + AddressTranslator.INSTANCE.ipv6AddressToAddress(dstAddr.getIpv6AddressNoZone()); + } + greTunnelAddDel.tunnel.outerFibId = outerFibId; + greTunnelAddDel.tunnel.isIpv6 = isIpv6; + return greTunnelAddDel; + } + + @Override + protected Class getExpectedInterfaceType() { + return GreTunnel.class; + } + + @Override + protected final void writeInterface(@Nonnull final InstanceIdentifier id, @Nonnull final Gre dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String swIfName = id.firstKeyOf(Interface.class).getName(); + + createGreTunnel(id, swIfName, dataAfter, writeContext); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final Gre dataBefore, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String swIfName = id.firstKeyOf(Interface.class).getName(); + deleteGreTunnel(id, swIfName, dataBefore, writeContext); + } + + private void createGreTunnel(final InstanceIdentifier id, final String swIfName, final Gre gre, + final WriteContext writeContext) throws WriteFailedException { + final byte isIpv6 = (byte) (isIpv6(gre) + ? 1 + : 0); + int outerFibId = gre.getOuterFibId().intValue(); + + LOG.debug("Setting gre tunnel for interface: {}. Gre: {}", swIfName, gre); + final CompletionStage greAddDelTunnelReplyCompletionStage = + getFutureJVpp().greTunnelAddDel(getGreTunnelRequest((byte) 1 /* is add */, gre.getSrc(), + gre.getDst(), outerFibId, isIpv6)); + + final GreTunnelAddDelReply reply = + getReplyForCreate(greAddDelTunnelReplyCompletionStage.toCompletableFuture(), id, gre); + LOG.debug("Gre tunnel set successfully for: {}, gre: {}", swIfName, gre); + if (interfaceContext.containsName(reply.swIfIndex, writeContext.getMappingContext())) { + // VPP keeps gre tunnels present even after they are delete(reserving ID for next tunnel) + // This may cause inconsistencies in mapping context when configuring tunnels like this: + // 1. Add tunnel 2. Delete tunnel 3. Read interfaces (reserved mapping e.g. gre_tunnel0 -> 6 + // will get into mapping context) 4. Add tunnel (this will add another mapping with the same + // reserved ID and context is invalid) + // That's why a check has to be performed here removing mapping gre_tunnel0 -> 6 mapping and storing + // new name for that ID + final String formerName = interfaceContext.getName(reply.swIfIndex, writeContext.getMappingContext()); + LOG.debug("Removing updated mapping of a gre tunnel, id: {}, former name: {}, new name: {}", + reply.swIfIndex, formerName, swIfName); + interfaceContext.removeName(formerName, writeContext.getMappingContext()); + } + // Add new interface to our interface context + interfaceContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); + } + + private boolean isIpv6(final Gre gre) { + return gre.getSrc().getIpv4AddressNoZone() == null; + } + + private void deleteGreTunnel(final InstanceIdentifier id, final String swIfName, final Gre gre, + final WriteContext writeContext) throws WriteFailedException { + final byte isIpv6 = (byte) (isIpv6(gre) + ? 1 + : 0); + + int outerFibId = gre.getOuterFibId().intValue(); + + LOG.debug("Deleting gre tunnel for interface: {}. Gre: {}", swIfName, gre); + final CompletionStage greAddDelTunnelReplyCompletionStage = + getFutureJVpp().greTunnelAddDel(getGreTunnelRequest((byte) 0 /* is add */, gre.getSrc(), + gre.getDst(), outerFibId, isIpv6)); + + getReplyForDelete(greAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); + LOG.debug("Gre tunnel deleted successfully for: {}, gre: {}", swIfName, gre); + // Remove interface from our interface context + interfaceContext.removeName(swIfName, writeContext.getMappingContext()); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/GreValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/GreValidator.java new file mode 100644 index 000000000..df487fde8 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/GreValidator.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Gre; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class GreValidator implements Validator { + + public GreValidator(final NamingContext interfaceContext) { + checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Gre dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.CreateValidationFailedException { + try { + validateGre(dataAfter); + } catch (Exception e) { + throw new DataValidationFailedException.CreateValidationFailedException(id, dataAfter, e); + } + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Gre dataBefore, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.DeleteValidationFailedException { + try { + validateGre(dataBefore); + } catch (Exception e) { + throw new DataValidationFailedException.DeleteValidationFailedException(id, e); + } + } + + private void validateGre(final Gre data) { + checkNotNull(data.getOuterFibId(), "Outer Fib ID cannot be null"); + checkNotNull(data.getSrc(), "Source cannot be null"); + checkNotNull(data.getDst(), "Destination cannot be null"); + if (data.getSrc().getIpv4AddressNoZone() == null) { + checkArgument(data.getDst().getIpv4AddressNoZone() == null, "Inconsistent ip addresses: %s, %s", + data.getSrc(), + data.getDst()); + } else { + checkArgument(data.getDst().getIpv6AddressNoZone() == null, "Inconsistent ip addresses: %s, %s", + data.getSrc(), + data.getDst()); + } + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterconnectionWriteUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterconnectionWriteUtils.java new file mode 100644 index 000000000..b93168496 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterconnectionWriteUtils.java @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Objects.requireNonNull; + +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.SwInterfaceSetL2Bridge; +import io.fd.jvpp.core.dto.SwInterfaceSetL2BridgeReply; +import io.fd.jvpp.core.dto.SwInterfaceSetL2Xconnect; +import io.fd.jvpp.core.dto.SwInterfaceSetL2XconnectReply; +import io.fd.jvpp.core.future.FutureJVppCore; +import io.fd.jvpp.core.types.L2PortType; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.Interconnection; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.BridgeBased; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.XconnectBased; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Utility class providing Interconnection CUD support. + */ +final class InterconnectionWriteUtils implements JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(InterconnectionWriteUtils.class); + + private final FutureJVppCore futureJVppCore; + private final NamingContext interfaceContext; + private final NamingContext bridgeDomainContext; + + InterconnectionWriteUtils(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext, + @Nonnull final NamingContext bridgeDomainContext) { + this.futureJVppCore = requireNonNull(futureJVppCore, "futureJVppCore should not be null"); + this.interfaceContext = requireNonNull(interfaceContext, "interfaceContext should not be null"); + this.bridgeDomainContext = requireNonNull(bridgeDomainContext, "bridgeDomainContext should not be null"); + } + + void setInterconnection(final InstanceIdentifier id, final int swIfIndex, + final String ifcName, final Interconnection ic, final WriteContext writeContext) + throws WriteFailedException { + + if (ic == null) { // TODO in case of update we should delete interconnection + LOG.trace("Interconnection is not set. Skipping"); + } else if (ic instanceof XconnectBased) { + setXconnectBasedL2(id, swIfIndex, ifcName, (XconnectBased) ic, writeContext, (byte) 1 /*enable*/); + } else if (ic instanceof BridgeBased) { + setBridgeBasedL2(id, swIfIndex, ifcName, (BridgeBased) ic, writeContext, (byte) 1 /*enable*/); + } else { + // Choices&cases are not data objects, so they cannot have a dedicated Reader/Writer + // This choice is already from augment, so its not possible to augment augmented choice + LOG.error("Unable to handle Interconnection of type {}", ic.getClass()); + throw new WriteFailedException(id, "Unable to handle Interconnection of type " + ic.getClass()); + } + } + + void deleteInterconnection(final InstanceIdentifier id, final int swIfIndex, + final String ifcName, final Interconnection ic, final WriteContext writeContext) + throws WriteFailedException { + + if (ic == null) { // TODO in case of update we should delete interconnection + LOG.trace("Interconnection is not set. Skipping"); + } else if (ic instanceof XconnectBased) { + setXconnectBasedL2(id, swIfIndex, ifcName, (XconnectBased) ic, writeContext, (byte) 0 /*disable*/); + } else if (ic instanceof BridgeBased) { + setBridgeBasedL2(id, swIfIndex, ifcName, (BridgeBased) ic, writeContext, (byte) 0 /*disable*/); + } else { + LOG.error("Unable to delete Interconnection of type {}", ic.getClass()); + throw new WriteFailedException(id, "Unable to delete Interconnection of type " + ic.getClass()); + } + } + + private void setBridgeBasedL2(final InstanceIdentifier id, final int swIfIndex, + final String ifcName, final BridgeBased bb, + final WriteContext writeContext, final byte enabled) throws WriteFailedException { + LOG.debug("Setting bridge based interconnection(bridge-domain={}) for interface: {}", bb.getBridgeDomain(), + ifcName); + + String bdName = bb.getBridgeDomain(); + + int bdId = bridgeDomainContext.getIndex(bdName, writeContext.getMappingContext()); + checkArgument(bdId > 0, "Unable to set Interconnection for Interface: %s, bridge domain: %s does not exist", + ifcName, bdName); + + byte shg = 0; + if (bb.getSplitHorizonGroup() != null) { + shg = bb.getSplitHorizonGroup().byteValue(); + } + + final CompletionStage swInterfaceSetL2BridgeReplyCompletionStage = futureJVppCore + .swInterfaceSetL2Bridge(getL2BridgeRequest(swIfIndex, bdId, shg, bb.isBridgedVirtualInterface(), enabled)); + getReplyForWrite(swInterfaceSetL2BridgeReplyCompletionStage.toCompletableFuture(), id); + + LOG.debug("Bridge based interconnection updated successfully for: {}, interconnection: {}", ifcName, bb); + } + + private SwInterfaceSetL2Bridge getL2BridgeRequest(final int swIfIndex, final int bdId, final byte shg, + final Boolean bvi, final byte enabled) { + final SwInterfaceSetL2Bridge swInterfaceSetL2Bridge = new SwInterfaceSetL2Bridge(); + swInterfaceSetL2Bridge.rxSwIfIndex = swIfIndex; + swInterfaceSetL2Bridge.bdId = bdId; + swInterfaceSetL2Bridge.shg = shg; + + // TODO HC2VPP-389: add support for unknown unicast type + swInterfaceSetL2Bridge.portType = bvi ? L2PortType.L2_API_PORT_TYPE_BVI : L2PortType.L2_API_PORT_TYPE_NORMAL; + swInterfaceSetL2Bridge.enable = enabled; + return swInterfaceSetL2Bridge; + } + + private void setXconnectBasedL2(final InstanceIdentifier id, final int swIfIndex, + final String ifcName, final XconnectBased ic, + final WriteContext writeContext, final byte enabled) throws WriteFailedException { + String outSwIfName = ic.getXconnectOutgoingInterface(); + LOG.debug("Setting xconnect based interconnection(outgoing ifc={}) for interface: {}", outSwIfName, ifcName); + + int outSwIfIndex = interfaceContext.getIndex(outSwIfName, writeContext.getMappingContext()); + checkArgument(outSwIfIndex > 0, + "Unable to set Interconnection for Interface: %s, outgoing interface: %s does not exist", + ifcName, outSwIfIndex); + + final CompletionStage swInterfaceSetL2XconnectReplyCompletionStage = + futureJVppCore + .swInterfaceSetL2Xconnect(getL2XConnectRequest(swIfIndex, outSwIfIndex, enabled)); + getReplyForWrite(swInterfaceSetL2XconnectReplyCompletionStage.toCompletableFuture(), id); + LOG.debug("Xconnect based interconnection updated successfully for: {}, interconnection: {}", ifcName, ic); + } + + private SwInterfaceSetL2Xconnect getL2XConnectRequest(final int rxIfc, final int txIfc, + final byte enabled) { + + final SwInterfaceSetL2Xconnect swInterfaceSetL2Xconnect = new SwInterfaceSetL2Xconnect(); + swInterfaceSetL2Xconnect.enable = enabled; + swInterfaceSetL2Xconnect.rxSwIfIndex = rxIfc; + swInterfaceSetL2Xconnect.txSwIfIndex = txIfc; + return swInterfaceSetL2Xconnect; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceCustomizer.java new file mode 100644 index 000000000..147575bb1 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceCustomizer.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.SwInterfaceSetFlags; +import io.fd.jvpp.core.dto.SwInterfaceSetFlagsReply; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Ietf interface write customizer that only caches interface objects for child writers + */ +public class InterfaceCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer, JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(InterfaceCustomizer.class); + private static final String LOCAL0_NAME = "local0"; + + private final NamingContext interfaceContext; + + public InterfaceCustomizer(final FutureJVppCore vppApi, final NamingContext interfaceContext) { + super(vppApi); + this.interfaceContext = interfaceContext; + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Interface dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + + setInterface(id, dataAfter, writeContext); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Interface dataBefore, + @Nonnull final Interface dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + updateInterface(id, dataAfter, writeContext); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Interface dataBefore, + @Nonnull final WriteContext writeContext) + throws WriteFailedException.DeleteFailedException { + // Special handling for local0 interface (HC2VPP-308): + if (LOCAL0_NAME.equals(dataBefore.getName())) { + throw new WriteFailedException.DeleteFailedException(id, + new UnsupportedOperationException("Removing " + LOCAL0_NAME + " interface is not supported")); + } + // For other interfaces, delegate delete to customizers for specific interface types (e.g. VXLan, Tap). + } + + private void setInterface(final InstanceIdentifier id, final Interface swIf, + final WriteContext writeContext) throws WriteFailedException { + LOG.debug("Setting interface: {} to: {}", id, swIf); + setInterfaceAttributes(id, swIf, swIf.getName(), writeContext); + } + + private void setInterfaceAttributes(final InstanceIdentifier id, final Interface swIf, + final String swIfName, final WriteContext writeContext) + throws WriteFailedException { + + setInterfaceFlags(id, swIfName, interfaceContext.getIndex(swIfName, writeContext.getMappingContext()), + swIf.isEnabled() + ? (byte) 1 + : (byte) 0); + } + + private void updateInterface(final InstanceIdentifier id, + final Interface dataAfter, final WriteContext writeContext) + throws WriteFailedException { + LOG.debug("Updating interface:{} to: {}", id, dataAfter); + setInterfaceAttributes(id, dataAfter, dataAfter.getName(), writeContext); + } + + private void setInterfaceFlags(final InstanceIdentifier id, final String swIfName, final int swIfIndex, + final byte enabled) throws WriteFailedException { + final CompletionStage swInterfaceSetFlagsReplyFuture = + getFutureJVpp().swInterfaceSetFlags(getSwInterfaceSetFlagsInput(swIfIndex, enabled)); + + LOG.debug("Updating interface flags for: {}, index: {}, enabled: {}", swIfName, swIfIndex, enabled); + + getReplyForWrite(swInterfaceSetFlagsReplyFuture.toCompletableFuture(), id); + LOG.debug("Interface flags updated successfully for: {}, index: {}, enabled: {}", + swIfName, swIfIndex, enabled); + } + + private SwInterfaceSetFlags getSwInterfaceSetFlagsInput(final int swIfIndex, final byte enabled) { + final SwInterfaceSetFlags swInterfaceSetFlags = new SwInterfaceSetFlags(); + swInterfaceSetFlags.swIfIndex = swIfIndex; + swInterfaceSetFlags.adminUpDown = enabled; + return swInterfaceSetFlags; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceRoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceRoutingCustomizer.java new file mode 100644 index 000000000..51d15e348 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceRoutingCustomizer.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Routing; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceRoutingCustomizer extends RoutingCustomizer + implements WriterCustomizer { + + public InterfaceRoutingCustomizer(@Nonnull final FutureJVppCore vppApi, + @Nonnull final NamingContext interfaceContext) { + super(vppApi, interfaceContext); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Routing dataAfter, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String ifName = id.firstKeyOf(Interface.class).getName(); + setRouting(id, ifName, dataAfter, writeContext); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Routing dataBefore, @Nonnull final Routing dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String ifName = id.firstKeyOf(Interface.class).getName(); + setRouting(id, ifName, dataAfter, writeContext); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Routing dataBefore, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String ifName = id.firstKeyOf(Interface.class).getName(); + disableRouting(id, ifName, writeContext); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceRoutingValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceRoutingValidator.java new file mode 100644 index 000000000..608bda3fa --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceRoutingValidator.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2019 PANTHEON.tech. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import java.util.List; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.RoutingBaseAttributes; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Routing; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceRoutingValidator implements Validator { + + public InterfaceRoutingValidator(@Nonnull final NamingContext interfaceContext) { + checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Routing dataAfter, + @Nonnull final WriteContext writeContext) + throws CreateValidationFailedException { + try { + checkVrfIds(dataAfter); + checkInterfaceAddressConf(id, writeContext, true); + } catch (Exception e) { + throw new CreateValidationFailedException(id, dataAfter, e); + } + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Routing dataBefore, + @Nonnull final Routing dataAfter, @Nonnull final WriteContext writeContext) + throws UpdateValidationFailedException { + try { + checkVrfIds(dataAfter); + checkInterfaceAddressConf(id, writeContext, true); + } catch (Exception e) { + throw new UpdateValidationFailedException(id, dataBefore, dataAfter, e); + } + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Routing dataBefore, + @Nonnull final WriteContext writeContext) + throws DeleteValidationFailedException { + try { + checkVrfIds(dataBefore); + checkInterfaceAddressConf(id, writeContext, false); + } catch (Exception e) { + throw new DeleteValidationFailedException(id, e); + } + } + + private void checkVrfIds(final RoutingBaseAttributes data) { + checkArgument(data.getIpv4VrfId() != null || data.getIpv6VrfId() != null, "No vrf-id given"); + } + + private void checkInterfaceAddressConf(@Nonnull final InstanceIdentifier id, + @Nonnull final WriteContext ctx, + boolean checkBefore) { + checkState(isAddressNotPresentForInterface(id, ctx, checkBefore), + "Cannot change routing configuration, if address is present for interface"); + } + + /** + * Returns true if interface does not have v4/v6 addresses configured + */ + private boolean isAddressNotPresentForInterface(@Nonnull final InstanceIdentifier id, + @Nonnull final WriteContext ctx, + boolean checkBefore) { + final Optional interfaceData = checkBefore + ? ctx.readBefore(RWUtils.cutId(id, Interface.class)) + : ctx.readAfter(RWUtils.cutId(id, Interface.class)); + + if (interfaceData.isPresent()) { + final java.util.Optional augData = java.util.Optional.of(interfaceData.get()) + .map(iface -> iface.augmentation(Interface1.class)); + + final boolean v4NotPresent = + augData.map(Interface1::getIpv4).map(Ipv4::getAddress).map(List::isEmpty).orElse(true); + + final boolean v6NotPresent = + augData.map(Interface1::getIpv6).map(Ipv6::getAddress).map(List::isEmpty).orElse(true); + + return v4NotPresent && v6NotPresent; + } + return true; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceUnnumberedCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceUnnumberedCustomizer.java new file mode 100644 index 000000000..a6eada50a --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceUnnumberedCustomizer.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public final class InterfaceUnnumberedCustomizer extends AbstractUnnumberedCustomizer { + + public InterfaceUnnumberedCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore, interfaceContext); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Unnumbered dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + setUnnumbered(id, id.firstKeyOf(Interface.class).getName(), dataAfter, writeContext); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Unnumbered dataBefore, @Nonnull final Unnumbered dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + setUnnumbered(id, id.firstKeyOf(Interface.class).getName(), dataAfter, writeContext); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Unnumbered dataBefore, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + disableUnnumbered(id, id.firstKeyOf(Interface.class).getName(), dataBefore, writeContext); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceUnnumberedValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceUnnumberedValidator.java new file mode 100644 index 000000000..19f115119 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceUnnumberedValidator.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceUnnumberedValidator implements Validator { + + public InterfaceUnnumberedValidator(final NamingContext interfaceContext) { + checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Unnumbered dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.CreateValidationFailedException { + checkNotNull(dataAfter.getUse(), "Use cannot be null"); + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Unnumbered dataBefore, + @Nonnull final Unnumbered dataAfter, @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.UpdateValidationFailedException { + checkNotNull(dataAfter.getUse(), "Use cannot be null"); + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Unnumbered dataBefore, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.DeleteValidationFailedException { + checkNotNull(dataBefore.getUse(), "Use cannot be null"); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceValidator.java new file mode 100644 index 000000000..59acbd7af --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfaceValidator.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceValidator implements Validator { + + public InterfaceValidator(final NamingContext interfaceContext) { + checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Interface dataAfter, + @Nonnull final WriteContext writeContext) + throws CreateValidationFailedException { + try { + checkInterface(dataAfter); + } catch (Exception e) { + throw new CreateValidationFailedException(id, dataAfter, e); + } + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Interface dataBefore, + @Nonnull final Interface dataAfter, @Nonnull final WriteContext writeContext) + throws UpdateValidationFailedException { + try { + checkInterface(dataAfter); + } catch (Exception e) { + throw new UpdateValidationFailedException(id, dataBefore, dataAfter, e); + } + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Interface dataBefore, + @Nonnull final WriteContext writeContext) + throws DeleteValidationFailedException { + try { + checkInterface(dataBefore); + } catch (Exception e) { + throw new DeleteValidationFailedException(id, e); + } + } + + private void checkInterface(final Interface data) { + checkNotNull(data.isEnabled(), "Enabled tag cannot be null"); + checkNotNull(data.getName(), "Name cannot be null"); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfacesStatisticsCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfacesStatisticsCustomizer.java new file mode 100644 index 000000000..ca22aa5ea --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfacesStatisticsCustomizer.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2019 PANTHEON.tech. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.v3po.read.cache.InterfaceStatisticsManager; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.Statistics; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfacesStatisticsCustomizer implements WriterCustomizer { + + private final InterfaceStatisticsManager statisticsManager; + + public InterfacesStatisticsCustomizer(final InterfaceStatisticsManager statisticsManager) { + this.statisticsManager = statisticsManager; + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier instanceIdentifier, + @Nonnull final Statistics statisticsCollection, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + enableDisableStatistics(statisticsCollection); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Statistics dataBefore, + @Nonnull final Statistics dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + enableDisableStatistics(dataAfter); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier instanceIdentifier, + @Nonnull final Statistics statisticsCollection, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + statisticsManager.disableStatistics(); + } + + private void enableDisableStatistics(final Statistics statsCollect) { + if (statsCollect != null) { + if (statsCollect.isEnabled()) { + statisticsManager.enableStatistics(); + return; + } + } + statisticsManager.disableStatistics(); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfacesStatisticsValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfacesStatisticsValidator.java new file mode 100644 index 000000000..06c532842 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/InterfacesStatisticsValidator.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019 PANTHEON.tech. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.interfaces; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.v3po.read.cache.InterfaceStatisticsManager; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.Statistics; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfacesStatisticsValidator implements Validator { + + public InterfacesStatisticsValidator(final InterfaceStatisticsManager statisticsManager) { + checkNotNull(statisticsManager, "Statistics Collection Manager should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Statistics dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.CreateValidationFailedException { + // there is nothing to validate yet + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Statistics dataBefore, + @Nonnull final Statistics dataAfter, @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.UpdateValidationFailedException { + // there is nothing to validate yet + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Statistics dataBefore, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.DeleteValidationFailedException { + // there is nothing to validate yet + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/L2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/L2Customizer.java new file mode 100644 index 000000000..cbceea36f --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/L2Customizer.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class L2Customizer extends FutureJVppCustomizer implements WriterCustomizer { + + private static final Logger LOG = LoggerFactory.getLogger(L2Customizer.class); + private final NamingContext interfaceContext; + private final InterconnectionWriteUtils icWriteUtils; + + public L2Customizer(final FutureJVppCore vppApi, final NamingContext interfaceContext, + final NamingContext bridgeDomainContext) { + super(vppApi); + this.interfaceContext = interfaceContext; + this.icWriteUtils = new InterconnectionWriteUtils(vppApi, interfaceContext, bridgeDomainContext); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + + final String ifcName = id.firstKeyOf(Interface.class).getName(); + final int swIfc = interfaceContext.getIndex(ifcName, writeContext.getMappingContext()); + setL2(id, swIfc, ifcName, dataAfter, writeContext); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataBefore, + @Nonnull final L2 dataAfter, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + + final String ifcName = id.firstKeyOf(Interface.class).getName(); + final int swIfc = interfaceContext.getIndex(ifcName, writeContext.getMappingContext()); + // No update, again calling set + setL2(id, swIfc, ifcName, dataAfter, writeContext); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataBefore, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + final String ifcName = id.firstKeyOf(Interface.class).getName(); + final int swIfc = interfaceContext.getIndex(ifcName, writeContext.getMappingContext()); + deleteL2(id, swIfc, ifcName, dataBefore, writeContext); + } + + private void setL2(final InstanceIdentifier id, final int swIfIndex, final String ifcName, final L2 l2, + final WriteContext writeContext) + throws WriteFailedException { + LOG.debug("Setting L2 for interface: {}", ifcName); + // Nothing besides interconnection here + icWriteUtils.setInterconnection(id, swIfIndex, ifcName, l2.getInterconnection(), writeContext); + } + + private void deleteL2(final InstanceIdentifier id, final int swIfIndex, final String ifcName, final L2 l2Before, + final WriteContext writeContext) + throws WriteFailedException { + LOG.debug("Deleting L2 for interface: {}", ifcName); + // Nothing besides interconnection here + icWriteUtils.deleteInterconnection(id, swIfIndex, ifcName, l2Before.getInterconnection(), writeContext); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/L2Validator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/L2Validator.java new file mode 100644 index 000000000..1dedf3817 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/L2Validator.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class L2Validator implements Validator { + + public L2Validator(final NamingContext interfaceContext, + final NamingContext bridgeDomainContext) { + checkNotNull(interfaceContext, "interfaceContext should not be null"); + checkNotNull(bridgeDomainContext, "bridgeDomainContext should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.CreateValidationFailedException { + // there is nothing to validate yet + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataBefore, + @Nonnull final L2 dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.UpdateValidationFailedException { + // there is nothing to validate yet + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataBefore, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.DeleteValidationFailedException { + // there is nothing to validate yet + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/LoopbackCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/LoopbackCustomizer.java new file mode 100644 index 000000000..0be934598 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/LoopbackCustomizer.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.MacTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.CreateLoopback; +import io.fd.jvpp.core.dto.CreateLoopbackReply; +import io.fd.jvpp.core.dto.DeleteLoopback; +import io.fd.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Loopback; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class LoopbackCustomizer extends AbstractInterfaceTypeCustomizer + implements MacTranslator, JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(LoopbackCustomizer.class); + private final NamingContext interfaceContext; + + public LoopbackCustomizer(final FutureJVppCore vppApi, final NamingContext interfaceContext) { + super(vppApi); + this.interfaceContext = interfaceContext; + } + + @Override + protected Class getExpectedInterfaceType() { + return org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.Loopback.class; + } + + @Override + protected final void writeInterface(@Nonnull final InstanceIdentifier id, @Nonnull final Loopback dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String ifcName = id.firstKeyOf(Interface.class).getName(); + createLoopback(id, ifcName, dataAfter, writeContext); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final Loopback dataBefore, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String ifcName = id.firstKeyOf(Interface.class).getName(); + + final int index; + try { + index = interfaceContext.getIndex(ifcName, writeContext.getMappingContext()); + } catch (IllegalArgumentException e) { + throw new WriteFailedException.DeleteFailedException(id, e); + } + + deleteLoopback(id, ifcName, index, dataBefore, writeContext); + } + + private void createLoopback(final InstanceIdentifier id, final String swIfName, final Loopback loopback, + final WriteContext writeContext) throws WriteFailedException { + LOG.debug("Setting loopback interface: {}. Loopback: {}", swIfName, loopback); + + final CreateLoopback createLoopback = new CreateLoopback(); + if (loopback.getMac() != null) { + createLoopback.macAddress = parseMac(loopback.getMac().getValue()); + } + final CreateLoopbackReply reply = + getReplyForCreate(getFutureJVpp().createLoopback(createLoopback).toCompletableFuture(), id, loopback); + + LOG.debug("Loopback set successfully for: {}, loopback: {}", swIfName, loopback); + // Add new interface to our interface context + interfaceContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); + } + + private void deleteLoopback(final InstanceIdentifier id, final String swIfName, final int index, + final Loopback dataBefore, final WriteContext writeContext) + throws WriteFailedException { + LOG.debug("Deleting loopback interface: {}. Loopback: {}", swIfName, dataBefore); + final DeleteLoopback deleteLoopback = new DeleteLoopback(); + deleteLoopback.swIfIndex = index; + getReplyForDelete(getFutureJVpp().deleteLoopback(deleteLoopback).toCompletableFuture(), id); + LOG.debug("Loopback deleted successfully for: {}, loopback: {}", swIfName, dataBefore); + // Remove deleted interface from interface context + interfaceContext.removeName(swIfName, writeContext.getMappingContext()); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/LoopbackValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/LoopbackValidator.java new file mode 100644 index 000000000..af6126bfb --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/LoopbackValidator.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Loopback; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class LoopbackValidator implements Validator { + + public LoopbackValidator(final NamingContext interfaceContext) { + checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Loopback dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.CreateValidationFailedException { + // there is nothing to validate yet + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Loopback dataBefore, + @Nonnull final Loopback dataAfter, @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.UpdateValidationFailedException { + // there is nothing to validate yet + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Loopback dataBefore, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.DeleteValidationFailedException { + // there is nothing to validate yet + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/RewriteCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/RewriteCustomizer.java new file mode 100644 index 000000000..15eb7b0b4 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/RewriteCustomizer.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.common.translate.util.TagRewriteOperation; +import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.L2InterfaceVlanTagRewrite; +import io.fd.jvpp.core.dto.L2InterfaceVlanTagRewriteReply; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.List; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319._802dot1q; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.Rewrite; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.RewriteBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.tag.rewrite.PushTags; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Writer Customizer responsible for vlan tag rewrite.
Sends {@code l2_interface_vlan_tag_rewrite} message to + * VPP.
Equivalent of invoking {@code vppctl set interface l2 tag-rewrite} command. + */ +public class RewriteCustomizer extends FutureJVppCustomizer + implements WriterCustomizer, ByteDataTranslator, JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(RewriteCustomizer.class); + private final NamingContext interfaceContext; + + public RewriteCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + this.interfaceContext = interfaceContext; + } + + @Override + public void writeCurrentAttributes(final InstanceIdentifier id, final Rewrite dataAfter, + final WriteContext writeContext) + throws WriteFailedException { + final String subifName = getSubInterfaceName(id); + setTagRewrite(id, subifName, dataAfter, writeContext); + } + + private static String getSubInterfaceName(final InstanceIdentifier id) { + return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), + Math.toIntExact(id.firstKeyOf(SubInterface.class).getIdentifier())); + } + + private void setTagRewrite(final InstanceIdentifier id, final String ifname, final Rewrite rewrite, + final WriteContext writeContext) throws WriteFailedException { + final int swIfIndex = interfaceContext.getIndex(ifname, writeContext.getMappingContext()); + LOG.debug("Setting tag rewrite for interface {}(id=): {}", ifname, swIfIndex, rewrite); + + final CompletionStage replyCompletionStage = + getFutureJVpp().l2InterfaceVlanTagRewrite(getTagRewriteRequest(swIfIndex, rewrite)); + + getReplyForWrite(replyCompletionStage.toCompletableFuture(), id); + LOG.debug("Tag rewrite for interface {}(id=) set successfully: {}", ifname, swIfIndex, rewrite); + } + + private L2InterfaceVlanTagRewrite getTagRewriteRequest(final int swIfIndex, final Rewrite rewrite) { + final L2InterfaceVlanTagRewrite request = new L2InterfaceVlanTagRewrite(); + request.swIfIndex = swIfIndex; + request.pushDot1Q = booleanToByte(_802dot1q.class == rewrite.getVlanType()); + + final List pushTags = rewrite.getPushTags(); + final Short popTags = rewrite.getPopTags(); + + final int numberOfTagsToPop = popTags == null + ? 0 + : popTags.intValue(); + final int numberOfTagsToPush = pushTags == null + ? 0 + : pushTags.size(); + + request.vtrOp = TagRewriteOperation.get(numberOfTagsToPop, numberOfTagsToPush).ordinal(); + + if (numberOfTagsToPush > 0) { + for (final PushTags tag : pushTags) { + if (tag.getIndex() == 0) { + request.tag1 = tag.getDot1qTag().getVlanId().getValue(); + } else { + request.tag2 = tag.getDot1qTag().getVlanId().getValue(); + } + } + } + + LOG.debug("Generated tag rewrite request: {}", request); + return request; + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Rewrite dataBefore, + @Nonnull final Rewrite dataAfter, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String subifName = getSubInterfaceName(id); + setTagRewrite(id, subifName, dataAfter, writeContext); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Rewrite dataBefore, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String subifName = getSubInterfaceName(id); + + LOG.debug("Disabling tag rewrite for interface {}", subifName); + final Rewrite rewrite = new RewriteBuilder().build(); // rewrite without push and pops will cause delete + setTagRewrite(id, subifName, rewrite, writeContext); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/RewriteValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/RewriteValidator.java new file mode 100644 index 000000000..a16bbafc4 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/RewriteValidator.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.Rewrite; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class RewriteValidator implements Validator { + + public RewriteValidator(@Nonnull final NamingContext interfaceContext) { + checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Rewrite dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.CreateValidationFailedException { + // there is nothing to validate yet + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Rewrite dataBefore, + @Nonnull final Rewrite dataAfter, @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.UpdateValidationFailedException { + // there is nothing to validate yet + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Rewrite dataBefore, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.DeleteValidationFailedException { + // there is nothing to validate yet + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/RoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/RoutingCustomizer.java new file mode 100644 index 000000000..b28b6e3c9 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/RoutingCustomizer.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkArgument; + +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.SwInterfaceSetTable; +import io.fd.jvpp.core.dto.SwInterfaceSetTableReply; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.RoutingBaseAttributes; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +abstract class RoutingCustomizer extends FutureJVppCustomizer implements JvppReplyConsumer, ByteDataTranslator { + private static final Logger LOG = LoggerFactory.getLogger(RoutingCustomizer.class); + protected final NamingContext interfaceContext; + + protected RoutingCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + this.interfaceContext = interfaceContext; + } + + protected void setRouting(@Nonnull final InstanceIdentifier id, + @Nonnull final String name, + @Nonnull final RoutingBaseAttributes rt, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + final int swIfc = interfaceContext.getIndex(name, writeContext.getMappingContext()); + LOG.debug("Setting routing for interface: {}, {}. Routing: {}", name, swIfc, rt); + checkArgument(rt.getIpv4VrfId() != null || rt.getIpv6VrfId() != null, "No vrf-id given"); + + setVrfId(id, swIfc, rt.getIpv4VrfId(), false); + setVrfId(id, swIfc, rt.getIpv6VrfId(), true); + + LOG.debug("Routing set successfully for interface: {}, {}, routing: {}", name, swIfc, rt); + } + + private void setVrfId(final InstanceIdentifier id, final int swIfc, + final VniReference vniRef, boolean isIp6) + throws WriteFailedException { + if (vniRef == null || vniRef.getValue() == null) { + return; + } + final CompletionStage cs = getFutureJVpp().swInterfaceSetTable( + getInterfaceSetTableRequest(swIfc, booleanToByte(isIp6), vniRef.getValue().intValue())); + getReplyForWrite(cs.toCompletableFuture(), id); + } + + /** + * In this case, there is no such thing as delete routing,only thing that can be done is to disable it by setting + * default value 0 + */ + void disableRouting(final InstanceIdentifier id, final String name, + final WriteContext writeContext) throws WriteFailedException { + final int swIfc = interfaceContext.getIndex(name, writeContext.getMappingContext()); + LOG.debug("Disabling routing for interface: {}, {}.", name, swIfc); + + getReplyForDelete(getFutureJVpp() + .swInterfaceSetTable(getInterfaceSetTableRequest(swIfc, (byte) 0, 0)).toCompletableFuture(), id); + LOG.debug("Routing for interface: {}, {} successfully disabled", name, swIfc); + + } + + private SwInterfaceSetTable getInterfaceSetTableRequest(final int swIfc, final byte isIpv6, final int vrfId) { + final SwInterfaceSetTable swInterfaceSetTable = new SwInterfaceSetTable(); + swInterfaceSetTable.isIpv6 = isIpv6; + swInterfaceSetTable.swIfIndex = swIfc; + swInterfaceSetTable.vrfId = vrfId; + return swInterfaceSetTable; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceCustomizer.java new file mode 100644 index 000000000..65d7de55e --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceCustomizer.java @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkState; +import static io.fd.hc2vpp.v3po.util.SubInterfaceUtils.getNumberOfTags; +import static io.fd.hc2vpp.v3po.util.SubInterfaceUtils.getSubInterfaceName; + +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.CreateSubif; +import io.fd.jvpp.core.dto.CreateSubifReply; +import io.fd.jvpp.core.dto.SwInterfaceSetFlags; +import io.fd.jvpp.core.dto.SwInterfaceSetFlagsReply; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319._802dot1ad; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.MatchType; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.Default; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.VlanTagged; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.tags.Tag; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.CVlan; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qVlanId; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.SVlan; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Writer Customizer responsible for sub interface creation.
Sends {@code create_subif} message to VPP.
+ * Equivalent of invoking {@code vppclt create subif} command. + */ +public class SubInterfaceCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer, ByteDataTranslator, JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceCustomizer.class); + private final NamingContext interfaceContext; + + public SubInterfaceCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + this.interfaceContext = interfaceContext; + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final SubInterface dataAfter, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String superIfName = id.firstKeyOf(Interface.class).getName(); + createSubInterface(id, superIfName, dataAfter, writeContext); + } + + private void createSubInterface(final InstanceIdentifier id, @Nonnull final String superIfName, + @Nonnull final SubInterface subInterface, final WriteContext writeContext) + throws WriteFailedException { + final int superIfIndex = interfaceContext.getIndex(superIfName, writeContext.getMappingContext()); + final CompletionStage createSubifReplyCompletionStage = + getFutureJVpp().createSubif(getCreateSubifRequest(subInterface, superIfIndex)); + + final CreateSubifReply reply = + getReplyForCreate(createSubifReplyCompletionStage.toCompletableFuture(), id, subInterface); + + setInterfaceState(id, reply.swIfIndex, booleanToByte(subInterface.isEnabled())); + interfaceContext.addName(reply.swIfIndex, + getSubInterfaceName(superIfName, Math.toIntExact(subInterface.getIdentifier())), + writeContext.getMappingContext()); + LOG.debug("Sub interface created successfully for: {}, subInterface: {}", superIfName, subInterface); + } + + private CreateSubif getCreateSubifRequest(@Nonnull final SubInterface subInterface, final int swIfIndex) { + // TODO HONEYCOMB-183 add validation + CreateSubif request = new CreateSubif(); + request.subId = Math.toIntExact(subInterface.getIdentifier().intValue()); + request.swIfIndex = swIfIndex; + + final int numberOfTags = getNumberOfTags(subInterface.getTags()); + switch (numberOfTags) { + case 0: + request.noTags = 1; + break; + case 1: + request.oneTag = 1; + break; + case 2: + request.twoTags = 1; + break; + } + request.dot1Ad = booleanToByte(_802dot1ad.class == subInterface.getVlanType()); + + // TODO HONEYCOMB-183 match should be mandatory + final MatchType matchType = subInterface.getMatch().getMatchType(); + request.exactMatch = booleanToByte( + matchType instanceof VlanTagged + && ((VlanTagged) matchType).getVlanTagged().isMatchExactTags() + ); + request.defaultSub = booleanToByte(matchType instanceof Default); + if (numberOfTags > 0) { + for (final Tag tag : subInterface.getTags().getTag()) { + if (tag.getIndex() == 0) { + setOuterTag(request, tag); + } else if (tag.getIndex() == 1) { + setInnerTag(request, tag); + } + } + } + return request; + } + + private void setOuterTag(final CreateSubif request, final Tag outerTag) { + checkState(SVlan.class == outerTag.getDot1qTag().getTagType(), "Service Tag expected at index 0"); + final Dot1qTag.VlanId vlanId = outerTag.getDot1qTag().getVlanId(); + + request.outerVlanId = dot1qVlanIdToShort(vlanId.getDot1qVlanId()); + request.outerVlanIdAny = booleanToByte(Dot1qTag.VlanId.Enumeration.Any.equals(vlanId.getEnumeration())); + } + + private void setInnerTag(final CreateSubif request, final Tag innerTag) { + checkState(CVlan.class == innerTag.getDot1qTag().getTagType(), "Customer Tag expected at index 1"); + final Dot1qTag.VlanId vlanId = innerTag.getDot1qTag().getVlanId(); + + request.innerVlanId = dot1qVlanIdToShort(vlanId.getDot1qVlanId()); + request.innerVlanIdAny = booleanToByte(Dot1qTag.VlanId.Enumeration.Any.equals(vlanId.getEnumeration())); + } + + private static short dot1qVlanIdToShort(@Nullable Dot1qVlanId dot1qVlanId) { + if (dot1qVlanId == null) { + return 0; // tell VPP that optional argument is missing + } else { + return dot1qVlanId.getValue().shortValue(); + } + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final SubInterface dataBefore, @Nonnull final SubInterface dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String subIfaceName = getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), + Math.toIntExact(dataAfter.getIdentifier())); + setInterfaceState(id, interfaceContext.getIndex(subIfaceName, writeContext.getMappingContext()), + booleanToByte(dataAfter.isEnabled())); + } + + private void setInterfaceState(final InstanceIdentifier id, final int swIfIndex, final byte enabled) + throws WriteFailedException { + final SwInterfaceSetFlags swInterfaceSetFlags = new SwInterfaceSetFlags(); + swInterfaceSetFlags.swIfIndex = swIfIndex; + swInterfaceSetFlags.adminUpDown = enabled; + + final CompletionStage swInterfaceSetFlagsReplyFuture = + getFutureJVpp().swInterfaceSetFlags(swInterfaceSetFlags); + + LOG.debug("Updating interface state for interface if={}, enabled: {}", swIfIndex, enabled); + + SwInterfaceSetFlagsReply reply = + getReplyForWrite(swInterfaceSetFlagsReplyFuture.toCompletableFuture(), id); + LOG.debug("Interface state updated successfully for interface index: {}, enabled: {}, ctxId: {}", + swIfIndex, enabled, reply.context); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final SubInterface dataBefore, + @Nonnull final WriteContext writeContext) + throws WriteFailedException.DeleteFailedException { + throw new UnsupportedOperationException("Sub interface delete is not supported"); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceL2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceL2Customizer.java new file mode 100644 index 000000000..091713c26 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceL2Customizer.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Customizer for writing vlan sub interface l2 configuration + */ +public class SubInterfaceL2Customizer extends FutureJVppCustomizer implements WriterCustomizer { + + private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceL2Customizer.class); + private final NamingContext interfaceContext; + private final InterconnectionWriteUtils icWriterUtils; + + public SubInterfaceL2Customizer(final FutureJVppCore vppApi, final NamingContext interfaceContext, + final NamingContext bridgeDomainContext) { + super(vppApi); + this.interfaceContext = interfaceContext; + this.icWriterUtils = new InterconnectionWriteUtils(vppApi, interfaceContext, bridgeDomainContext); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String subInterfaceName = getSubInterfaceName(id); + final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, writeContext.getMappingContext()); + setL2(id, subInterfaceIndex, subInterfaceName, dataAfter, writeContext); + } + + private String getSubInterfaceName(@Nonnull final InstanceIdentifier id) { + final InterfaceKey parentInterfacekey = id.firstKeyOf(Interface.class); + final SubInterfaceKey subInterfacekey = id.firstKeyOf(SubInterface.class); + return SubInterfaceUtils + .getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue()); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataBefore, + @Nonnull final L2 dataAfter, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + + final String subInterfaceName = getSubInterfaceName(id); + final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, writeContext.getMappingContext()); + // Setting L2 to new values + setL2(id, subInterfaceIndex, subInterfaceName, dataAfter, writeContext); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataBefore, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + final String subInterfaceName = getSubInterfaceName(id); + final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, writeContext.getMappingContext()); + deleteL2(id, subInterfaceIndex, subInterfaceName, dataBefore, writeContext); + } + + private void setL2(final InstanceIdentifier id, final int swIfIndex, final String ifcName, final L2 l2, + final WriteContext writeContext) + throws WriteFailedException { + LOG.debug("Setting L2 for sub-interface: {}", ifcName); + icWriterUtils.setInterconnection(id, swIfIndex, ifcName, l2.getInterconnection(), writeContext); + } + + private void deleteL2(final InstanceIdentifier id, final int swIfIndex, final String ifcName, final L2 l2Before, + final WriteContext writeContext) + throws WriteFailedException { + LOG.debug("Deleting L2 for sub-interface: {}", ifcName); + icWriterUtils.deleteInterconnection(id, swIfIndex, ifcName, l2Before.getInterconnection(), writeContext); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceL2Validator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceL2Validator.java new file mode 100644 index 000000000..713a80d30 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceL2Validator.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceL2Validator implements Validator { + + public SubInterfaceL2Validator(final NamingContext interfaceContext, + final NamingContext bridgeDomainContext) { + checkNotNull(interfaceContext, "interfaceContext should not be null"); + checkNotNull(bridgeDomainContext, "bridgeDomainContext should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.CreateValidationFailedException { + // there is nothing to validate yet + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataBefore, + @Nonnull final L2 dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.UpdateValidationFailedException { + // there is nothing to validate yet + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final L2 dataBefore, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.DeleteValidationFailedException { + // there is nothing to validate yet + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceRoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceRoutingCustomizer.java new file mode 100644 index 000000000..6fe3c3c01 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceRoutingCustomizer.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static io.fd.hc2vpp.v3po.util.SubInterfaceUtils.subInterfaceFullNameConfig; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.Routing; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceRoutingCustomizer extends RoutingCustomizer implements WriterCustomizer { + + public SubInterfaceRoutingCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore, interfaceContext); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier instanceIdentifier, + @Nonnull final Routing routing, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + setRouting(instanceIdentifier, subInterfaceFullNameConfig(instanceIdentifier), routing, writeContext); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier instanceIdentifier, + @Nonnull final Routing routing, @Nonnull final Routing d1, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + setRouting(instanceIdentifier, subInterfaceFullNameConfig(instanceIdentifier), routing, writeContext); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier instanceIdentifier, + @Nonnull final Routing routing, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + disableRouting(instanceIdentifier, subInterfaceFullNameConfig(instanceIdentifier), writeContext); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceRoutingValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceRoutingValidator.java new file mode 100644 index 000000000..e769409bd --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceRoutingValidator.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import java.util.List; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.Ipv4; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.Ipv6; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.Routing; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceRoutingValidator implements Validator { + + public SubInterfaceRoutingValidator(@Nonnull final NamingContext interfaceContext) { + checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Routing dataAfter, + @Nonnull final WriteContext writeContext) + throws CreateValidationFailedException { + try { + checkInterfaceAddressConf(id, writeContext, true); + } catch (Exception e) { + throw new CreateValidationFailedException(id, dataAfter, e); + } + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Routing dataBefore, + @Nonnull final Routing dataAfter, @Nonnull final WriteContext writeContext) + throws UpdateValidationFailedException { + try { + checkInterfaceAddressConf(id, writeContext, true); + } catch (Exception e) { + throw new UpdateValidationFailedException(id, dataBefore, dataAfter, e); + } + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Routing dataBefore, + @Nonnull final WriteContext writeContext) + throws DeleteValidationFailedException { + try { + checkInterfaceAddressConf(id, writeContext, false); + } catch (Exception e) { + throw new DeleteValidationFailedException(id, e); + } + } + + private void checkInterfaceAddressConf(@Nonnull final InstanceIdentifier id, + @Nonnull final WriteContext ctx, + boolean checkBefore) { + checkState(isAddressNotPresentForSubInterface(id, ctx, checkBefore), + "Cannot change routing configuration, if address is present for sub-interface"); + } + + /** + * Returns true if interface does not have v4/v6 addresses configured + */ + private boolean isAddressNotPresentForSubInterface(@Nonnull final InstanceIdentifier id, + @Nonnull final WriteContext ctx, + boolean checkBefore) { + final Optional subInterfaceData = checkBefore + ? + ctx.readBefore(RWUtils.cutId(id, SubInterface.class)) + : + ctx.readAfter(RWUtils.cutId(id, SubInterface.class)); + + if (subInterfaceData.isPresent()) { + final SubInterface subInterface = subInterfaceData.get(); + + final boolean v4NotPresent = + java.util.Optional.ofNullable(subInterface.getIpv4()).map(Ipv4::getAddress).map(List::isEmpty) + .orElse(true); + + final boolean v6NotPresent = + java.util.Optional.ofNullable(subInterface.getIpv6()).map(Ipv6::getAddress).map(List::isEmpty) + .orElse(true); + return v4NotPresent && v6NotPresent; + } + return true; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceUnnumberedCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceUnnumberedCustomizer.java new file mode 100644 index 000000000..314e9a4fe --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceUnnumberedCustomizer.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static io.fd.hc2vpp.v3po.util.SubInterfaceUtils.subInterfaceFullNameConfig; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public final class SubInterfaceUnnumberedCustomizer extends AbstractUnnumberedCustomizer { + + public SubInterfaceUnnumberedCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore, interfaceContext); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Unnumbered dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + setUnnumbered(id, subInterfaceFullNameConfig(id), dataAfter, writeContext); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Unnumbered dataBefore, @Nonnull final Unnumbered dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + setUnnumbered(id, subInterfaceFullNameConfig(id), dataAfter, writeContext); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Unnumbered dataBefore, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + disableUnnumbered(id, subInterfaceFullNameConfig(id), dataBefore, writeContext); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceUnnumberedValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceUnnumberedValidator.java new file mode 100644 index 000000000..d4224534a --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceUnnumberedValidator.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceUnnumberedValidator implements Validator { + + public SubInterfaceUnnumberedValidator(final NamingContext interfaceContext) { + checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Unnumbered dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.CreateValidationFailedException { + checkNotNull(dataAfter.getUse()); + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final Unnumbered dataBefore, + @Nonnull final Unnumbered dataAfter, @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.UpdateValidationFailedException { + checkNotNull(dataAfter.getUse()); + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Unnumbered dataBefore, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.DeleteValidationFailedException { + checkNotNull(dataBefore.getUse()); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceValidator.java new file mode 100644 index 000000000..92b64bcaa --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/SubInterfaceValidator.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceValidator implements Validator { + + public SubInterfaceValidator(@Nonnull final NamingContext interfaceContext) { + checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final SubInterface dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.CreateValidationFailedException { + try { + checkSubInterface(dataAfter); + } catch (Exception e) { + throw new DataValidationFailedException.CreateValidationFailedException(id, dataAfter, e); + } + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, + @Nonnull final SubInterface dataBefore, + @Nonnull final SubInterface dataAfter, @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.UpdateValidationFailedException { + try { + checkSubInterface(dataAfter); + } catch (Exception e) { + throw new DataValidationFailedException.UpdateValidationFailedException(id, dataBefore, dataAfter, e); + } + } + + private void checkSubInterface(final SubInterface data) { + checkNotNull(data.getIdentifier(), "Identifier cannot be null"); + checkNotNull(data.getMatch(), "Match cannot be null"); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/TapV2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/TapV2Customizer.java new file mode 100644 index 000000000..773a48fa0 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/TapV2Customizer.java @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2018 Pantheon Technologies and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; +import io.fd.hc2vpp.common.translate.util.Ipv4Translator; +import io.fd.hc2vpp.common.translate.util.Ipv6Translator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.MacTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.TapCreateV2; +import io.fd.jvpp.core.dto.TapCreateV2Reply; +import io.fd.jvpp.core.dto.TapDeleteV2; +import io.fd.jvpp.core.dto.TapDeleteV2Reply; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TapV2Customizer extends AbstractInterfaceTypeCustomizer + implements MacTranslator, Ipv4Translator, Ipv6Translator, JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(TapV2Customizer.class); + private final NamingContext interfaceContext; + + public TapV2Customizer(final FutureJVppCore vppApi, final NamingContext interfaceContext) { + super(vppApi); + this.interfaceContext = interfaceContext; + } + + @Override + protected Class getExpectedInterfaceType() { + return org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.TapV2.class; + } + + @Override + protected final void writeInterface(@Nonnull final InstanceIdentifier id, @Nonnull final TapV2 dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String ifcName = id.firstKeyOf(Interface.class).getName(); + createTapV2(id, ifcName, dataAfter, writeContext); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final TapV2 dataBefore, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String ifcName = id.firstKeyOf(Interface.class).getName(); + + final int index; + try { + index = interfaceContext.getIndex(ifcName, writeContext.getMappingContext()); + } catch (IllegalArgumentException e) { + throw new WriteFailedException.DeleteFailedException(id, e); + } + + deleteTapV2(id, ifcName, index, dataBefore, writeContext); + } + + private void createTapV2(final InstanceIdentifier id, final String swIfName, final TapV2 tapv2, + final WriteContext writeContext) throws WriteFailedException { + LOG.debug("Setting TapV2 interface: {}. TapV2: {}", swIfName, tapv2); + final CompletionStage tapV2CreateFuture = getFutureJVpp() + .tapCreateV2(getTapV2CreateRequest(tapv2)); + final TapCreateV2Reply reply = getReplyForCreate(tapV2CreateFuture.toCompletableFuture(), id, tapv2); + LOG.debug("TapV2 set successfully for: {}, TapV2: {}", swIfName, tapv2); + // Add new interface to our interface context + interfaceContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); + } + + private void deleteTapV2(final InstanceIdentifier id, final String swIfName, final int index, + final TapV2 dataBefore, final WriteContext writeContext) + throws WriteFailedException { + LOG.debug("Deleting TapV2 interface: {}. TapV2: {}", swIfName, dataBefore); + final CompletionStage vxlanAddDelTunnelReplyCompletionStage = + getFutureJVpp().tapDeleteV2(getTapV2DeleteRequest(index)); + getReplyForDelete(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); + LOG.debug("TapV2 deleted successfully for: {}, TapV2: {}", swIfName, dataBefore); + // Remove deleted interface from interface context + interfaceContext.removeName(swIfName, writeContext.getMappingContext()); + } + + private TapCreateV2 getTapV2CreateRequest(final TapV2 tapv2) { + final TapCreateV2 tapConnect = new TapCreateV2(); + final PhysAddress mac = tapv2.getMac(); + if (mac == null) { + tapConnect.useRandomMac = 1; + tapConnect.macAddress = new byte[6]; + } else { + tapConnect.useRandomMac = 0; + tapConnect.macAddress = parseMac(mac.getValue()); + } + + final Integer rxRingSz = tapv2.getRxRingSize(); + if (rxRingSz != null) { + tapConnect.rxRingSz = rxRingSz.shortValue(); + } + + final Integer txRingSz = tapv2.getTxRingSize(); + if (txRingSz != null) { + tapConnect.txRingSz = txRingSz.shortValue(); + } + + final String tag = tapv2.getTag(); + if (tag != null) { + tapConnect.tag = tag.getBytes(StandardCharsets.US_ASCII); + } + + setHostProperties(tapConnect, tapv2); + return tapConnect; + } + + private TapDeleteV2 getTapV2DeleteRequest(final int swIndex) { + final TapDeleteV2 tapDeleteV2 = new TapDeleteV2(); + tapDeleteV2.swIfIndex = swIndex; + return tapDeleteV2; + } + + private void setHostProperties(TapCreateV2 tapConnect, TapV2 tapv2) { + + final PhysAddress hostMacAddress = tapv2.getHostMac(); + if (hostMacAddress != null) { + tapConnect.hostMacAddr = parseMac(hostMacAddress.getValue()); + tapConnect.hostMacAddrSet = 1; + } else { + tapConnect.hostMacAddr = new byte[6]; + tapConnect.hostMacAddrSet = 0; + } + + final String hostIfName = tapv2.getHostInterfaceName(); + if (hostIfName != null) { + tapConnect.hostIfName = hostIfName.getBytes(UTF_8); + tapConnect.hostIfNameSet = 1; + } else { + tapConnect.hostIfNameSet = 0; + tapConnect.hostIfName = new byte[64]; + } + + final String hostBridge = tapv2.getHostBridge(); + if (hostBridge != null) { + tapConnect.hostBridgeSet = 1; + tapConnect.hostBridge = hostBridge.getBytes(UTF_8); + } else { + tapConnect.hostBridgeSet = 0; + tapConnect.hostBridge = new byte[64]; + } + + final String hostNamespace = tapv2.getHostNamespace(); + if (hostNamespace != null) { + tapConnect.hostNamespaceSet = 1; + tapConnect.hostNamespace = hostNamespace.getBytes(UTF_8); + } else { + tapConnect.hostNamespaceSet = 0; + tapConnect.hostNamespace = new byte[64]; + } + + final Ipv4Prefix hostIpv4address = tapv2.getHostIpv4Address(); + if (hostIpv4address != null) { + tapConnect.hostIp4Addr = ipv4AddressPrefixToArray(hostIpv4address); + tapConnect.hostIp4AddrSet = 1; + tapConnect.hostIp4PrefixLen = extractPrefix(hostIpv4address); + } else { + tapConnect.hostIp4Addr = new byte[4]; + tapConnect.hostIp4AddrSet = 0; + tapConnect.hostIp4PrefixLen = 0; + } + + final Ipv4Address hostIpv4GW = tapv2.getHostIpv4Gateway(); + if (hostIpv4GW != null) { + tapConnect.hostIp4Gw = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(hostIpv4GW)); + tapConnect.hostIp4GwSet = 1; + } else { + tapConnect.hostIp4Gw = new byte[4]; + tapConnect.hostIp4GwSet = 0; + } + + final Ipv6Prefix hostIpv6address = tapv2.getHostIpv6Address(); + if (hostIpv6address != null) { + tapConnect.hostIp6Addr = ipv6AddressPrefixToArray(hostIpv6address); + tapConnect.hostIp6AddrSet = 1; + tapConnect.hostIp6PrefixLen = extractPrefix(hostIpv6address); + } else { + tapConnect.hostIp6Addr = new byte[16]; + tapConnect.hostIp6AddrSet = 0; + tapConnect.hostIp6PrefixLen = 0; + } + + final Ipv6Address hostIpv6GW = tapv2.getHostIpv6Gateway(); + if (hostIpv6GW != null) { + tapConnect.hostIp6Gw = ipv6AddressNoZoneToArray(hostIpv6GW); + tapConnect.hostIp6GwSet = 1; + } else { + tapConnect.hostIp6Gw = new byte[16]; + tapConnect.hostIp6GwSet = 0; + } + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/TapV2Validator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/TapV2Validator.java new file mode 100644 index 000000000..83ca218da --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/TapV2Validator.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class TapV2Validator implements Validator { + + public TapV2Validator(final NamingContext interfaceContext) { + checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final TapV2 dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.CreateValidationFailedException { + // there is nothing to validate yet + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final TapV2 dataBefore, + @Nonnull final TapV2 dataAfter, @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.UpdateValidationFailedException { + // there is nothing to validate yet + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final TapV2 dataBefore, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.DeleteValidationFailedException { + // there is nothing to validate yet + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VhostUserCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VhostUserCustomizer.java new file mode 100644 index 000000000..69ade6a75 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VhostUserCustomizer.java @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.CreateVhostUserIf; +import io.fd.jvpp.core.dto.CreateVhostUserIfReply; +import io.fd.jvpp.core.dto.DeleteVhostUserIf; +import io.fd.jvpp.core.dto.DeleteVhostUserIfReply; +import io.fd.jvpp.core.dto.ModifyVhostUserIf; +import io.fd.jvpp.core.dto.ModifyVhostUserIfReply; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUserRole; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUser; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Writer Customizer responsible for passing vhost user interface CRD operations to VPP + */ +public class VhostUserCustomizer extends AbstractInterfaceTypeCustomizer + implements ByteDataTranslator, JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(VhostUserCustomizer.class); + private final NamingContext interfaceContext; + + public VhostUserCustomizer(@Nonnull final FutureJVppCore vppApi, @Nonnull final NamingContext interfaceContext) { + super(vppApi); + this.interfaceContext = interfaceContext; + } + + @Override + protected Class getExpectedInterfaceType() { + return org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUser.class; + } + + @Override + protected final void writeInterface(@Nonnull final InstanceIdentifier id, + @Nonnull final VhostUser dataAfter, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String swIfName = id.firstKeyOf(Interface.class).getName(); + createVhostUserIf(id, swIfName, dataAfter, writeContext); + } + + private void createVhostUserIf(final InstanceIdentifier id, final String swIfName, + final VhostUser vhostUser, final WriteContext writeContext) + throws WriteFailedException { + LOG.debug("Creating vhost user interface: name={}, vhostUser={}", swIfName, vhostUser); + + final CompletionStage createVhostUserIfReplyCompletionStage = + getFutureJVpp().createVhostUserIf(getCreateVhostUserIfRequest(vhostUser)); + final CreateVhostUserIfReply reply = + getReplyForCreate(createVhostUserIfReplyCompletionStage.toCompletableFuture(), id, vhostUser); + LOG.debug("Vhost user interface created successfully for: {}, vhostUser: {}", swIfName, vhostUser); + // Add new interface to our interface context + interfaceContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); + } + + private CreateVhostUserIf getCreateVhostUserIfRequest(final VhostUser vhostUser) { + CreateVhostUserIf request = new CreateVhostUserIf(); + request.isServer = booleanToByte(VhostUserRole.Server.equals(vhostUser.getRole())); + request.sockFilename = vhostUser.getSocket().getBytes(); + final Long deviceInstance = vhostUser.getDeviceInstance(); + if (deviceInstance == null) { + request.renumber = 0; + } else { + request.renumber = 1; + request.customDevInstance = Math.toIntExact(deviceInstance); + } + final String tag = vhostUser.getTag(); + if (tag != null) { + request.tag = tag.getBytes(StandardCharsets.US_ASCII); + } + request.useCustomMac = 0; + request.macAddress = new byte[]{}; + return request; + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final VhostUser dataBefore, @Nonnull final VhostUser dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String swIfName = id.firstKeyOf(Interface.class).getName(); + modifyVhostUserIf(id, swIfName, dataBefore, dataAfter, writeContext); + } + + private void modifyVhostUserIf(final InstanceIdentifier id, final String swIfName, + final VhostUser vhostUserBefore, final VhostUser vhostUserAfter, + final WriteContext writeContext) throws WriteFailedException { + LOG.debug("Updating vhost user interface: name={}, vhostUser={}", swIfName, vhostUserAfter); + final CompletionStage modifyVhostUserIfReplyCompletionStage = + getFutureJVpp() + .modifyVhostUserIf(getModifyVhostUserIfRequest(vhostUserAfter, + interfaceContext.getIndex(swIfName, writeContext.getMappingContext()))); + + getReplyForUpdate(modifyVhostUserIfReplyCompletionStage.toCompletableFuture(), id, vhostUserBefore, + vhostUserAfter); + LOG.debug("Vhost user interface updated successfully for: {}, vhostUser: {}", swIfName, vhostUserAfter); + } + + private ModifyVhostUserIf getModifyVhostUserIfRequest(final VhostUser vhostUser, final int swIfIndex) { + ModifyVhostUserIf request = new ModifyVhostUserIf(); + request.isServer = booleanToByte(VhostUserRole.Server.equals(vhostUser.getRole())); + request.sockFilename = vhostUser.getSocket().getBytes(); + final Long deviceInstance = vhostUser.getDeviceInstance(); + if (deviceInstance == null) { + request.renumber = 0; + } else { + request.renumber = 1; + request.customDevInstance = Math.toIntExact(deviceInstance); + } + request.swIfIndex = swIfIndex; + return request; + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final VhostUser dataBefore, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String swIfName = id.firstKeyOf(Interface.class).getName(); + deleteVhostUserIf(id, swIfName, dataBefore, writeContext); + } + + private void deleteVhostUserIf(final InstanceIdentifier id, final String swIfName, + final VhostUser vhostUser, final WriteContext writeContext) + throws WriteFailedException { + LOG.debug("Deleting vhost user interface: name={}, vhostUser={}", swIfName, vhostUser); + final CompletionStage deleteVhostUserIfReplyCompletionStage = + getFutureJVpp().deleteVhostUserIf(getDeleteVhostUserIfRequest( + interfaceContext.getIndex(swIfName, writeContext.getMappingContext()))); + + getReplyForDelete(deleteVhostUserIfReplyCompletionStage.toCompletableFuture(), id); + LOG.debug("Vhost user interface deleted successfully for: {}, vhostUser: {}", swIfName, vhostUser); + // Remove interface from our interface context + interfaceContext.removeName(swIfName, writeContext.getMappingContext()); + } + + private DeleteVhostUserIf getDeleteVhostUserIfRequest(final int swIfIndex) { + DeleteVhostUserIf request = new DeleteVhostUserIf(); + request.swIfIndex = swIfIndex; + return request; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VhostUserValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VhostUserValidator.java new file mode 100644 index 000000000..c6b84b2b4 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VhostUserValidator.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUser; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VhostUserValidator implements Validator { + + public VhostUserValidator(@Nonnull final NamingContext interfaceContext) { + checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final VhostUser dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.CreateValidationFailedException { + checkNotNull(dataAfter.getSocket(), "Socket cannot be null"); + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final VhostUser dataBefore, + @Nonnull final VhostUser dataAfter, @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.UpdateValidationFailedException { + checkNotNull(dataAfter.getSocket(), "Socket cannot be null"); + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final VhostUser dataBefore, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.DeleteValidationFailedException { + // there is nothing to validate yet + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VxlanCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VxlanCustomizer.java new file mode 100644 index 000000000..6cac99c38 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VxlanCustomizer.java @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.DisabledInterfacesManager; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.VxlanAddDelTunnel; +import io.fd.jvpp.core.dto.VxlanAddDelTunnelReply; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.L2Input; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.NshProxy; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanTunnel; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Vxlan; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer implements JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(VxlanCustomizer.class); + + private final NamingContext interfaceNamingContext; + private final DisabledInterfacesManager interfaceDisableContext; + + public VxlanCustomizer(@Nonnull final FutureJVppCore vppApi, + @Nonnull final NamingContext interfaceNamingContext, + @Nonnull final DisabledInterfacesManager interfaceDisableContext) { + super(vppApi); + this.interfaceNamingContext = interfaceNamingContext; + this.interfaceDisableContext = interfaceDisableContext; + } + + @Override + protected Class getExpectedInterfaceType() { + return VxlanTunnel.class; + } + + @Override + protected final void writeInterface(@Nonnull final InstanceIdentifier id, @Nonnull final Vxlan dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String swIfName = id.firstKeyOf(Interface.class).getName(); + createVxlanTunnel(id, swIfName, dataAfter, writeContext); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final Vxlan dataBefore, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String swIfName = id.firstKeyOf(Interface.class).getName(); + deleteVxlanTunnel(id, swIfName, dataBefore, writeContext); + } + + private void createVxlanTunnel(final InstanceIdentifier id, final String swIfName, final Vxlan vxlan, + final WriteContext writeContext) + throws WriteFailedException { + final byte isIpv6 = (byte) (isIpv6(vxlan) + ? 1 + : 0); + + int encapVrfId = vxlan.getEncapVrfId().getValue().intValue(); + int vni = vxlan.getVni().getValue().intValue(); + + int decapNext = -1; + if (vxlan.getDecapNext() == L2Input.class) { + decapNext = 1; + } else if (vxlan.getDecapNext() == NshProxy.class) { + decapNext = 2; + } + + LOG.debug("Setting vxlan tunnel for interface: {}. Vxlan: {}", swIfName, vxlan); + final CompletionStage vxlanAddDelTunnelReplyCompletionStage = + getFutureJVpp().vxlanAddDelTunnel(getVxlanTunnelRequest((byte) 1 /* is add */, vxlan.getSrc(), + vxlan.getDst(), encapVrfId, decapNext, vni, isIpv6)); + + final VxlanAddDelTunnelReply reply = + getReplyForCreate(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id, vxlan); + LOG.debug("Vxlan tunnel set successfully for: {}, vxlan: {}", swIfName, vxlan); + if (interfaceNamingContext.containsName(reply.swIfIndex, writeContext.getMappingContext())) { + // VPP keeps vxlan tunnels present even after they are delete(reserving ID for next tunnel) + // This may cause inconsistencies in mapping context when configuring tunnels like this: + // 1. Add tunnel 2. Delete tunnel 3. Read interfaces (reserved mapping e.g. vxlan_tunnel0 -> 6 + // will get into mapping context) 4. Add tunnel (this will add another mapping with the same + // reserved ID and context is invalid) + // That's why a check has to be performed here removing mapping vxlan_tunnel0 -> 6 mapping and storing + // new name for that ID + final String formerName = interfaceNamingContext.getName(reply.swIfIndex, writeContext.getMappingContext()); + LOG.debug("Removing updated mapping of a vxlan tunnel, id: {}, former name: {}, new name: {}", + reply.swIfIndex, formerName, swIfName); + interfaceNamingContext.removeName(formerName, writeContext.getMappingContext()); + + } + + // Removing disability of an interface in case a vxlan tunnel formerly deleted is being reused in VPP + // further details in above comment + if (interfaceDisableContext.isInterfaceDisabled(reply.swIfIndex, writeContext.getMappingContext())) { + LOG.debug("Removing disability of vxlan tunnel, id: {}, name: {}", reply.swIfIndex, swIfName); + interfaceDisableContext.removeDisabledInterface(reply.swIfIndex, writeContext.getMappingContext()); + } + + // Add new interface to our interface context + interfaceNamingContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); + } + + private boolean isIpv6(final Vxlan vxlan) { + return vxlan.getSrc().getIpv4AddressNoZone() == null; + + } + + private void deleteVxlanTunnel(final InstanceIdentifier id, final String swIfName, final Vxlan vxlan, + final WriteContext writeContext) throws WriteFailedException { + final byte isIpv6 = (byte) (isIpv6(vxlan) + ? 1 + : 0); + + int encapVrfId = vxlan.getEncapVrfId().getValue().intValue(); + int vni = vxlan.getVni().getValue().intValue(); + + int decapNext = -1; + if (vxlan.getDecapNext() == L2Input.class) { + decapNext = 1; + } else if (vxlan.getDecapNext() == NshProxy.class) { + decapNext = 2; + } + + LOG.debug("Deleting vxlan tunnel for interface: {}. Vxlan: {}", swIfName, vxlan); + final CompletionStage vxlanAddDelTunnelReplyCompletionStage = + getFutureJVpp().vxlanAddDelTunnel(getVxlanTunnelRequest((byte) 0 /* is add */, vxlan.getSrc(), + vxlan.getDst(), encapVrfId, decapNext, vni, isIpv6)); + + getReplyForDelete(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); + LOG.debug("Vxlan tunnel deleted successfully for: {}, vxlan: {}", swIfName, vxlan); + + final int index = interfaceNamingContext.getIndex(swIfName, writeContext.getMappingContext()); + // Mark this interface as disabled to not include it in operational reads + // because VPP will keep the interface there + LOG.debug("Marking vxlan tunnel as disabled, id: {}, name: {}", index, swIfName); + interfaceDisableContext.disableInterface(index, writeContext.getMappingContext()); + // Remove interface from our interface naming context + interfaceNamingContext.removeName(swIfName, writeContext.getMappingContext()); + } + + private static VxlanAddDelTunnel getVxlanTunnelRequest(final byte isAdd, final IpAddressNoZone srcAddr, + final IpAddressNoZone dstAddr, + final int encapVrfId, + final int decapNextIndex, final int vni, final byte isIpv6) { + final VxlanAddDelTunnel vxlanAddDelTunnel = new VxlanAddDelTunnel(); + vxlanAddDelTunnel.isAdd = isAdd; + vxlanAddDelTunnel.srcAddress = AddressTranslator.INSTANCE.ipAddressToArray(srcAddr); + vxlanAddDelTunnel.dstAddress = AddressTranslator.INSTANCE.ipAddressToArray(dstAddr); + vxlanAddDelTunnel.encapVrfId = encapVrfId; + vxlanAddDelTunnel.vni = vni; + vxlanAddDelTunnel.decapNextIndex = decapNextIndex; + vxlanAddDelTunnel.isIpv6 = isIpv6; + return vxlanAddDelTunnel; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VxlanGpeCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VxlanGpeCustomizer.java new file mode 100644 index 000000000..b435fa169 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VxlanGpeCustomizer.java @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.common.translate.util.AbstractInterfaceTypeCustomizer; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.DisabledInterfacesManager; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.VxlanGpeAddDelTunnel; +import io.fd.jvpp.core.dto.VxlanGpeAddDelTunnelReply; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeTunnel; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpe; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class VxlanGpeCustomizer extends AbstractInterfaceTypeCustomizer implements JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(VxlanGpeCustomizer.class); + private final NamingContext interfaceNamingContext; + private final DisabledInterfacesManager interfaceDisableContext; + + public VxlanGpeCustomizer(@Nonnull final FutureJVppCore vppApi, + @Nonnull final NamingContext interfaceNamingContext, + @Nonnull final DisabledInterfacesManager interfaceDisableContext) { + super(vppApi); + this.interfaceNamingContext = interfaceNamingContext; + this.interfaceDisableContext = interfaceDisableContext; + } + + @Override + protected Class getExpectedInterfaceType() { + return VxlanGpeTunnel.class; + } + + @Override + protected final void writeInterface(@Nonnull final InstanceIdentifier id, + @Nonnull final VxlanGpe dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String swIfName = id.firstKeyOf(Interface.class).getName(); + createVxlanGpeTunnel(id, swIfName, dataAfter, writeContext); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final VxlanGpe dataBefore, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String swIfName = id.firstKeyOf(Interface.class).getName(); + deleteVxlanGpeTunnel(id, swIfName, dataBefore, writeContext); + } + + private void createVxlanGpeTunnel(final InstanceIdentifier id, final String swIfName, + final VxlanGpe vxlanGpe, final WriteContext writeContext) + throws WriteFailedException { + final byte isIpv6 = (byte) (isIpv6(vxlanGpe) + ? 1 + : 0); + + int vni = vxlanGpe.getVni().getValue().intValue(); + byte protocol = (byte) vxlanGpe.getNextProtocol().getIntValue(); + int encapVrfId = vxlanGpe.getEncapVrfId().intValue(); + int decapVrfId = vxlanGpe.getDecapVrfId().intValue(); + + LOG.debug("Setting VxlanGpe tunnel for interface: {}. VxlanGpe: {}", swIfName, vxlanGpe); + final CompletionStage VxlanGpeAddDelTunnelReplyCompletionStage = + getFutureJVpp() + .vxlanGpeAddDelTunnel(getVxlanGpeTunnelRequest((byte) 1 /* is add */, vxlanGpe.getLocal(), + vxlanGpe.getRemote(), vni, protocol, encapVrfId, decapVrfId, isIpv6)); + + final VxlanGpeAddDelTunnelReply reply = + getReplyForCreate(VxlanGpeAddDelTunnelReplyCompletionStage.toCompletableFuture(), id, vxlanGpe); + LOG.debug("VxlanGpe tunnel set successfully for: {}, VxlanGpe: {}", swIfName, vxlanGpe); + if (interfaceNamingContext.containsName(reply.swIfIndex, writeContext.getMappingContext())) { + final String formerName = interfaceNamingContext.getName(reply.swIfIndex, writeContext.getMappingContext()); + LOG.debug("Removing updated mapping of a vxlan-gpe tunnel, id: {}, former name: {}, new name: {}", + reply.swIfIndex, formerName, swIfName); + interfaceNamingContext.removeName(formerName, writeContext.getMappingContext()); + } + + // Removing disability of an interface in case a vxlan-gpe tunnel formerly deleted is being reused in VPP + // further details in above comment + if (interfaceDisableContext.isInterfaceDisabled(reply.swIfIndex, writeContext.getMappingContext())) { + LOG.debug("Removing disability of vxlan tunnel, id: {}, name: {}", reply.swIfIndex, swIfName); + interfaceDisableContext.removeDisabledInterface(reply.swIfIndex, writeContext.getMappingContext()); + } + + // Add new interface to our interface context + interfaceNamingContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); + } + + private boolean isIpv6(final VxlanGpe vxlanGpe) { + return vxlanGpe.getLocal().getIpv4AddressNoZone() == null; + + } + + private void deleteVxlanGpeTunnel(final InstanceIdentifier id, final String swIfName, + final VxlanGpe vxlanGpe, final WriteContext writeContext) + throws WriteFailedException { + final byte isIpv6 = (byte) (isIpv6(vxlanGpe) + ? 1 + : 0); + + int vni = vxlanGpe.getVni().getValue().intValue(); + byte protocol = (byte) vxlanGpe.getNextProtocol().getIntValue(); + int encapVrfId = vxlanGpe.getEncapVrfId().intValue(); + int decapVrfId = vxlanGpe.getDecapVrfId().intValue(); + + LOG.debug("Deleting VxlanGpe tunnel for interface: {}. VxlanGpe: {}", swIfName, vxlanGpe); + final CompletionStage VxlanGpeAddDelTunnelReplyCompletionStage = + getFutureJVpp() + .vxlanGpeAddDelTunnel(getVxlanGpeTunnelRequest((byte) 0 /* is delete */, vxlanGpe.getLocal(), + vxlanGpe.getRemote(), vni, protocol, encapVrfId, decapVrfId, isIpv6)); + getReplyForDelete(VxlanGpeAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); + final int index = interfaceNamingContext.getIndex(swIfName, writeContext.getMappingContext()); + // Mark this interface as disabled to not include it in operational reads + // because VPP will keep the interface there + LOG.debug("Marking vxlan tunnel as disabled, id: {}, name: {}", index, swIfName); + interfaceDisableContext.disableInterface(index, writeContext.getMappingContext()); + // Remove interface from our interface naming context + interfaceNamingContext.removeName(swIfName, writeContext.getMappingContext()); + } + + private static VxlanGpeAddDelTunnel getVxlanGpeTunnelRequest(final byte isAdd, final IpAddressNoZone local, + final IpAddressNoZone remote, + final int vni, final byte protocol, + final int encapVrfId, final int decapVrfId, + final byte isIpv6) { + final VxlanGpeAddDelTunnel VxlanGpeAddDelTunnel = new VxlanGpeAddDelTunnel(); + VxlanGpeAddDelTunnel.isAdd = isAdd; + VxlanGpeAddDelTunnel.local = AddressTranslator.INSTANCE.ipAddressToArray(local); + VxlanGpeAddDelTunnel.remote = AddressTranslator.INSTANCE.ipAddressToArray(remote); + VxlanGpeAddDelTunnel.vni = vni; + VxlanGpeAddDelTunnel.protocol = protocol; + VxlanGpeAddDelTunnel.encapVrfId = encapVrfId; + VxlanGpeAddDelTunnel.decapVrfId = decapVrfId; + VxlanGpeAddDelTunnel.isIpv6 = isIpv6; + return VxlanGpeAddDelTunnel; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VxlanGpeValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VxlanGpeValidator.java new file mode 100644 index 000000000..3be51b8df --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VxlanGpeValidator.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.DisabledInterfacesManager; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpe; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VxlanGpeValidator implements Validator { + + public VxlanGpeValidator(@Nonnull final NamingContext interfaceNamingContext, + @Nonnull final DisabledInterfacesManager interfaceDisableContext) { + checkNotNull(interfaceNamingContext, "interfaceContext should not be null"); + checkNotNull(interfaceDisableContext, "DisabledInterfacesManager should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final VxlanGpe dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.CreateValidationFailedException { + try { + validateVxlanGpe(dataAfter); + } catch (Exception e) { + throw new DataValidationFailedException.CreateValidationFailedException(id, dataAfter, e); + } + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final VxlanGpe dataBefore, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.DeleteValidationFailedException { + try { + validateVxlanGpe(dataBefore); + } catch (Exception e) { + throw new DataValidationFailedException.DeleteValidationFailedException(id, e); + } + } + + private void validateVxlanGpe(final VxlanGpe data) { + checkNotNull(data.getLocal(), "Local address cannot be null"); + checkNotNull(data.getRemote(), "Remote address cannot be null"); + if (data.getLocal().getIpv4AddressNoZone() == null) { + checkArgument(data.getRemote().getIpv4AddressNoZone() == null, "Inconsistent ip addresses: %s, %s", + data.getLocal(), + data.getRemote()); + } else { + checkArgument(data.getRemote().getIpv6AddressNoZone() == null, "Inconsistent ip addresses: %s, %s", + data.getLocal(), + data.getRemote()); + } + checkNotNull(data.getEncapVrfId(), "encap-vrf-id is mandatory but was not given"); + checkNotNull(data.getDecapVrfId(), "decap-vrf-id is mandatory but was not given"); + checkNotNull(data.getVni(), "VNI cannot be null"); + checkNotNull(data.getNextProtocol(), "Next protocol cannot be null"); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VxlanValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VxlanValidator.java new file mode 100644 index 000000000..5ca34fdd4 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/VxlanValidator.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.DisabledInterfacesManager; +import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Vxlan; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VxlanValidator implements Validator { + + public VxlanValidator(@Nonnull final NamingContext interfaceNamingContext, + @Nonnull final DisabledInterfacesManager disabledInterfacesManager) { + checkNotNull(interfaceNamingContext, "interfaceContext should not be null"); + checkNotNull(disabledInterfacesManager, "disabledInterfacesManager should not be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final Vxlan dataAfter, + @Nonnull final WriteContext writeContext) + throws CreateValidationFailedException { + try { + validateVxlan(dataAfter); + } catch (Exception e) { + throw new CreateValidationFailedException(id, dataAfter, e); + } + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final Vxlan dataBefore, + @Nonnull final WriteContext writeContext) + throws DeleteValidationFailedException { + try { + validateVxlan(dataBefore); + } catch (Exception e) { + throw new DeleteValidationFailedException(id, e); + } + } + + private void validateVxlan(final Vxlan data) { + + checkNotNull(data.getSrc(), "Source cannot be null"); + checkNotNull(data.getDst(), "Destination cannot be null"); + if (data.getSrc().getIpv4AddressNoZone() == null) { + checkArgument(data.getDst().getIpv4AddressNoZone() == null, "Inconsistent ip addresses: %s, %s", + data.getSrc(), + data.getDst()); + } else { + checkArgument(data.getDst().getIpv6AddressNoZone() == null, "Inconsistent ip addresses: %s, %s", + data.getSrc(), + data.getDst()); + } + checkArgument(data.getEncapVrfId() != null && data.getEncapVrfId().getValue() != null, + "encap-vrf-id is mandatory but was not given"); + checkNotNull(data.getVni(), "VNI cannot be null"); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/pbb/PbbRewriteCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/pbb/PbbRewriteCustomizer.java new file mode 100644 index 000000000..42d6b1969 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/pbb/PbbRewriteCustomizer.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write.pbb; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.MacTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.VppBaseCallException; +import io.fd.jvpp.core.dto.L2InterfacePbbTagRewrite; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.TimeoutException; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewrite; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class PbbRewriteCustomizer extends FutureJVppCustomizer + implements WriterCustomizer, MacTranslator, JvppReplyConsumer { + + private static final int OPERATION_DISABLE = 0; + + private final NamingContext interfaceNamingContext; + + public PbbRewriteCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceNamingContext) { + super(futureJVppCore); + this.interfaceNamingContext = interfaceNamingContext; + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final PbbRewrite dataAfter, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + try { + setPbbRewrite(id, dataAfter, writeContext, false); + } catch (TimeoutException | VppBaseCallException e) { + throw new WriteFailedException.CreateFailedException(id, dataAfter, e); + } + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final PbbRewrite dataBefore, @Nonnull final PbbRewrite dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + try { + setPbbRewrite(id, dataAfter, writeContext, false); + } catch (TimeoutException | VppBaseCallException e) { + throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, e); + } + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final PbbRewrite dataBefore, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + + try { + setPbbRewrite(id, dataBefore, writeContext, true); + } catch (TimeoutException | VppBaseCallException e) { + throw new WriteFailedException.DeleteFailedException(id, e); + } + } + + private void setPbbRewrite(final InstanceIdentifier id, final PbbRewrite data, + final WriteContext writeContext, final boolean disable) + throws TimeoutException, VppBaseCallException { + final String interfaceName = id.firstKeyOf(Interface.class).getName(); + + final L2InterfacePbbTagRewrite request = new L2InterfacePbbTagRewrite(); + + //checking all attributes in preconditions(pbb-rewrite is subcontainer, so there can't be mandatory statements) + request.swIfIndex = interfaceNamingContext.getIndex(interfaceName, writeContext.getMappingContext()); + request.bDmac = parseMac(data.getDestinationAddress().getValue()); + request.bSmac = parseMac(data.getSourceAddress().getValue()); + request.bVlanid = data.getBVlanTagVlanId().shortValue(); + request.iSid = data.getITagIsid().intValue(); + request.vtrOp = verifiedOperation(data, disable); + + //not sure whats gonna happen to this attribute, so its left optional for now + if (data.getOuterTag() != null) { + request.outerTag = data.getOuterTag().shortValue(); + } + + getReply(getFutureJVpp().l2InterfacePbbTagRewrite(request).toCompletableFuture()); + } + + // if disabled ,then uses non-public allowed value 0, which is equal to operation disable + private int verifiedOperation(final PbbRewrite data, final boolean disable) { + return disable + ? OPERATION_DISABLE + : data.getInterfaceOperation().getIntValue(); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/pbb/PbbRewriteValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/pbb/PbbRewriteValidator.java new file mode 100644 index 000000000..90ea236a0 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/pbb/PbbRewriteValidator.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write.pbb; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewrite; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class PbbRewriteValidator implements Validator { + + + public PbbRewriteValidator(@Nonnull final NamingContext interfaceNamingContext) { + checkNotNull(interfaceNamingContext, "Interface naming context cannot be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, @Nonnull final PbbRewrite dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.CreateValidationFailedException { + try { + validatePbbRewrite(id, dataAfter, false); + } catch(Exception e) { + throw new DataValidationFailedException.CreateValidationFailedException(id, dataAfter, e); + } + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, @Nonnull final PbbRewrite dataBefore, + @Nonnull final PbbRewrite dataAfter, @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.UpdateValidationFailedException { + + try { + validatePbbRewrite(id, dataAfter, false); + } catch(Exception e) { + throw new DataValidationFailedException.UpdateValidationFailedException(id, dataBefore, dataAfter, e); + } + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, @Nonnull final PbbRewrite dataBefore, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.DeleteValidationFailedException { + try { + validatePbbRewrite(id, dataBefore, true); + } catch(Exception e) { + throw new DataValidationFailedException.DeleteValidationFailedException(id, e); + } + } + + private void validatePbbRewrite(final InstanceIdentifier id, @Nonnull final PbbRewrite data, + final boolean disable) { + checkNotNull(id.firstKeyOf(Interface.class), "Interface key not found"); + checkNotNull(data.getDestinationAddress(), "Destination address cannot be null"); + checkNotNull(data.getSourceAddress(), "Source address cannot be null"); + checkNotNull(data.getBVlanTagVlanId(), "BVlan id cannot be null"); + checkNotNull(data.getITagIsid(), "ISid cannot be null"); + if (disable) { + checkNotNull(data.getInterfaceOperation(), "Operation cannot be null"); + } + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/span/MirroredInterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/span/MirroredInterfaceCustomizer.java new file mode 100644 index 000000000..31b129537 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/span/MirroredInterfaceCustomizer.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write.span; + +import static io.fd.honeycomb.translate.util.RWUtils.cutId; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.SwInterfaceSpanEnableDisable; +import io.fd.jvpp.core.future.FutureJVppCore; +import java.util.function.Function; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.SpanState; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class MirroredInterfaceCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer, JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(MirroredInterfaceCustomizer.class); + + private final NamingContext ifcContext; + private final Function, String> destinationInterfaceNameExtractor; + + public MirroredInterfaceCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext ifcContext, + @Nonnull final Function, String> destinationInterfaceNameExtractor) { + super(futureJVppCore); + this.ifcContext = ifcContext; + this.destinationInterfaceNameExtractor = destinationInterfaceNameExtractor; + } + + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final MirroredInterface mirroredInterface, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String destinationInterfaceName = + destinationInterfaceNameExtractor.apply(cutId(id, MirroredInterfaces.class)); + final String sourceInterfaceName = mirroredInterface.getIfaceRef(); + final SpanState spanState = mirroredInterface.getState(); + + LOG.debug("Enabling span for source interface {} | destination interface {} | state {}", sourceInterfaceName, + destinationInterfaceName, spanState); + + getReplyForWrite(getFutureJVpp().swInterfaceSpanEnableDisable( + getSpanAddDelRequest( + interfaceId(writeContext, ifcContext, destinationInterfaceName), + interfaceId(writeContext, ifcContext, sourceInterfaceName), + true, + spanState)) + .toCompletableFuture(), id); + LOG.debug("Span for source interface {} | destination interface {} | state {} successfully enabled", + sourceInterfaceName, destinationInterfaceName, spanState); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final MirroredInterface mirroredInterface, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + final String destinationInterfaceName = + destinationInterfaceNameExtractor.apply(cutId(id, MirroredInterfaces.class)); + final String sourceInterfaceName = mirroredInterface.getIfaceRef(); + LOG.debug("Disabling span for source interface {} | destination interface {} ", sourceInterfaceName, + destinationInterfaceName); + + getReplyForWrite(getFutureJVpp().swInterfaceSpanEnableDisable( + getSpanAddDelRequest( + interfaceId(writeContext, ifcContext, destinationInterfaceName), + interfaceId(writeContext, ifcContext, sourceInterfaceName), + false, + null)) + .toCompletableFuture(), id); + LOG.debug("Span for source interface {} | destination interface {} successfully disabled", + sourceInterfaceName, destinationInterfaceName); + } + + private SwInterfaceSpanEnableDisable getSpanAddDelRequest(final int dstId, final Integer srcId, final boolean isAdd, + @Nullable final SpanState state) { + final SwInterfaceSpanEnableDisable spanAddDel = new SwInterfaceSpanEnableDisable(); + spanAddDel.state = (byte) (isAdd + ? state != null + ? state.getIntValue() + : 0 + : 0);// either one of 1(rx),2(tx),3(both) or 0 for disable/delete + spanAddDel.swIfIndexFrom = srcId; + spanAddDel.swIfIndexTo = dstId; + return spanAddDel; + } + + private static int interfaceId(final WriteContext writeContext, final NamingContext ifcContext, final String name) { + return ifcContext.getIndex(name, writeContext.getMappingContext()); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/span/MirroredInterfaceValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/span/MirroredInterfaceValidator.java new file mode 100644 index 000000000..90c740be8 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/write/span/MirroredInterfaceValidator.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write.span; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import java.util.function.Function; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class MirroredInterfaceValidator implements Validator { + + public MirroredInterfaceValidator(@Nonnull final NamingContext ifcContext, + @Nonnull final Function, String> destinationInterfaceNameExtractor) { + checkNotNull(ifcContext, "Interface naming context cannot be null"); + checkNotNull(destinationInterfaceNameExtractor, "Destination Interface Name extractor cannot be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier id, + @Nonnull final MirroredInterface dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.CreateValidationFailedException { + try { + checkMirroredInterfaceData(dataAfter); + } catch (Exception e) { + throw new DataValidationFailedException.CreateValidationFailedException(id, dataAfter, e); + } + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier id, + @Nonnull final MirroredInterface dataBefore, + @Nonnull final MirroredInterface dataAfter, @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.UpdateValidationFailedException { + try { + checkMirroredInterfaceData(dataAfter); + } catch (Exception e) { + throw new DataValidationFailedException.UpdateValidationFailedException(id, dataBefore, dataAfter, e); + } + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier id, + @Nonnull final MirroredInterface dataBefore, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.DeleteValidationFailedException { + try { + checkMirroredInterfaceData(dataBefore); + } catch (Exception e) { + throw new DataValidationFailedException.DeleteValidationFailedException(id, e); + } + } + + private void checkMirroredInterfaceData(final MirroredInterface data) { + checkNotNull(data.getIfaceRef(), "IfaceRef cannot be null"); + checkNotNull(data.getState(), "State cannot be null"); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/AbstractUnnumberedCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/AbstractUnnumberedCustomizerTest.java deleted file mode 100644 index 112ae8bd3..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/AbstractUnnumberedCustomizerTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.jvpp.core.dto.SwInterfaceSetUnnumbered; -import io.fd.jvpp.core.dto.SwInterfaceSetUnnumberedReply; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.UnnumberedBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -abstract class AbstractUnnumberedCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { - - protected static final String IFC_CTX_NAME = "ifc-ctx"; - private AbstractUnnumberedCustomizer customizer; - private static final String TARGET_IFC0_NAME = "eth0"; - private static final int TARGET_IFC0_ID = 0; - private static final String TARGET_IFC1_NAME = "eth1"; - private static final int TARGET_IFC1_ID = 1; - - - @Override - public void setUpTest() { - customizer = getCustomizer(); - defineMapping(mappingContext, TARGET_IFC0_NAME, TARGET_IFC0_ID, IFC_CTX_NAME); - defineMapping(mappingContext, TARGET_IFC1_NAME, TARGET_IFC1_ID, IFC_CTX_NAME); - defineMapping(mappingContext, getUnnumberedIfcName(), getUnnumberedIfcId(), IFC_CTX_NAME); - when(api.swInterfaceSetUnnumbered(any())).thenReturn(future(new SwInterfaceSetUnnumberedReply())); - } - - protected abstract int getUnnumberedIfcId(); - - protected abstract String getUnnumberedIfcName(); - - protected abstract InstanceIdentifier getUnnumberedIfcIId(); - - protected abstract AbstractUnnumberedCustomizer getCustomizer(); - - @Test - public void testWrite() throws Exception { - final Unnumbered data = new UnnumberedBuilder().setUse(TARGET_IFC0_NAME).build(); - customizer.writeCurrentAttributes(getUnnumberedIfcIId(), data, writeContext); - verify(api).swInterfaceSetUnnumbered(expectedRequest(true, TARGET_IFC0_ID)); - } - @Test - public void testUpdate() throws Exception { - final Unnumbered before = new UnnumberedBuilder().setUse(TARGET_IFC0_NAME).build(); - final Unnumbered after = new UnnumberedBuilder().setUse(TARGET_IFC1_NAME).build(); - customizer.updateCurrentAttributes(getUnnumberedIfcIId(), before, after, writeContext); - verify(api).swInterfaceSetUnnumbered(expectedRequest(true, TARGET_IFC1_ID)); - } - - @Test - public void testDelete() throws Exception { - final Unnumbered data = new UnnumberedBuilder().setUse(TARGET_IFC0_NAME).build(); - customizer.deleteCurrentAttributes(getUnnumberedIfcIId(), data, writeContext); - verify(api).swInterfaceSetUnnumbered(expectedRequest(false, TARGET_IFC0_ID)); - } - - private SwInterfaceSetUnnumbered expectedRequest(final boolean isAdd, int swIfIntex) { - final SwInterfaceSetUnnumbered request = new SwInterfaceSetUnnumbered(); - request.swIfIndex = swIfIntex; - request.unnumberedSwIfIndex = getUnnumberedIfcId(); - request.isAdd = booleanToByte(isAdd); - return request; - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/AfPacketCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/AfPacketCustomizerTest.java deleted file mode 100644 index 3b7929ce7..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/AfPacketCustomizerTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2018 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -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 io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.Ipv4Translator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.AfPacketCreate; -import io.fd.jvpp.core.dto.AfPacketCreateReply; -import io.fd.jvpp.core.dto.AfPacketDelete; -import io.fd.jvpp.core.dto.AfPacketDeleteReply; -import java.nio.charset.StandardCharsets; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacket; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacketBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class AfPacketCustomizerTest extends WriterCustomizerTest implements Ipv4Translator { - - private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; - private static final int IFACE_ID = 1; - private static final String IFACE_NAME = "veth1"; - private static final InstanceIdentifier ID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(VppInterfaceAugmentation.class).child(AfPacket.class); - private AfPacketCustomizer customizer; - - @Override - public void setUpTest() throws Exception { - InterfaceTypeTestUtils.setupWriteContext(writeContext, - org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.AfPacket.class); - customizer = new AfPacketCustomizer(api, new NamingContext("generatedInterfaceName", IFC_TEST_INSTANCE)); - - final AfPacketCreateReply createReply = new AfPacketCreateReply(); - createReply.swIfIndex = IFACE_ID; - when(api.afPacketCreate(any())).thenReturn(future(createReply)); - when(api.afPacketDelete(any())).thenReturn(future(new AfPacketDeleteReply())); - } - - @Test - public void testWriteRandomMac() throws WriteFailedException { - final AfPacketCreate expectedCreateRequest = new AfPacketCreate(); - expectedCreateRequest.hostIfName = IFACE_NAME.getBytes(StandardCharsets.UTF_8); - expectedCreateRequest.useRandomHwAddr = 1; - expectedCreateRequest.hwAddr = new byte[6]; - - customizer.writeCurrentAttributes(ID, afPacket(), writeContext); - - verify(api).afPacketCreate(expectedCreateRequest); - verify(mappingContext).put(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE), mapping(IFACE_NAME, IFACE_ID).get()); - } - - @Test - public void testWriteExplicitMac() throws WriteFailedException { - final AfPacket afPacket = afPacket("01:02:03:04:05:06"); - - final AfPacketCreate expectedCreateRequest = new AfPacketCreate(); - expectedCreateRequest.hostIfName = IFACE_NAME.getBytes(StandardCharsets.UTF_8); - expectedCreateRequest.useRandomHwAddr = 0; - expectedCreateRequest.hwAddr = new byte[] {1, 2, 3, 4, 5, 6}; - - customizer.writeCurrentAttributes(ID, afPacket, writeContext); - - verify(api).afPacketCreate(expectedCreateRequest); - verify(mappingContext).put(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE), mapping(IFACE_NAME, IFACE_ID).get()); - } - - @Test - public void testDelete() throws WriteFailedException { - final AfPacket afPacket = afPacket("02:03:04:05:06:07"); - final AfPacketDelete expectedDeleteRequest = new AfPacketDelete(); - expectedDeleteRequest.hostIfName = IFACE_NAME.getBytes(StandardCharsets.UTF_8); - - customizer.deleteCurrentAttributes(ID, afPacket, writeContext); - - verify(api).afPacketDelete(expectedDeleteRequest); - verify(mappingContext).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE))); - } - - private static AfPacket afPacket() { - return new AfPacketBuilder().setHostInterfaceName(IFACE_NAME).build(); - } - - private static AfPacket afPacket(String mac) { - return new AfPacketBuilder().setHostInterfaceName(IFACE_NAME).setMac(new PhysAddress(mac)).build(); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/AfPacketValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/AfPacketValidatorTest.java deleted file mode 100644 index ebdc770fe..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/AfPacketValidatorTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; -import io.fd.honeycomb.translate.write.WriteContext; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacket; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacketBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class AfPacketValidatorTest { - - private AfPacketValidator validator; - - @Mock - private WriteContext writeContext; - - private final String IFACE_NAME = "veth1"; - private final InstanceIdentifier ID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(VppInterfaceAugmentation.class).child(AfPacket.class); - - @Before - public void setUp() { - initMocks(this); - NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); - validator = new AfPacketValidator(ifcContext); - } - - @Test - public void testWriteSuccessful() throws CreateValidationFailedException { - validator.validateWrite(ID, afPacket(IFACE_NAME), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoHostName() throws CreateValidationFailedException { - validator.validateWrite(ID, afPacket(null), writeContext); - } - - @Test(expected = IllegalArgumentException.class) - public void testWriteFailedLongHostName() throws CreateValidationFailedException { - validator.validateWrite(ID, - afPacket(IntStream.range(1, 64).boxed().map(i -> i.toString()).collect(Collectors.joining(","))), - writeContext); - } - - @Test - public void testUpdateSuccessful() throws UpdateValidationFailedException { - validator.validateUpdate(ID, afPacket(IFACE_NAME), afPacket(IFACE_NAME), writeContext); - } - - @Test - public void testDeleteSuccessful() throws DeleteValidationFailedException { - validator.validateDelete(ID, afPacket(IFACE_NAME), writeContext); - } - - private AfPacket afPacket(String name) { - return new AfPacketBuilder().setHostInterfaceName(name).build(); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/EthernetCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/EthernetCustomizerTest.java deleted file mode 100644 index f7befc4e9..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/EthernetCustomizerTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.HwInterfaceSetMtu; -import io.fd.jvpp.core.dto.HwInterfaceSetMtuReply; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Ethernet; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev180703.EthernetCsmacd; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class EthernetCustomizerTest extends WriterCustomizerTest { - - private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; - private static final String IF_NAME = "eth0"; - private static final int IF_INDEX = 1; - private static final InstanceIdentifier IF_IID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation( - VppInterfaceAugmentation.class).child(Ethernet.class); - private EthernetCustomizer customizer; - - @Override - public void setUpTest() throws Exception { - InterfaceTypeTestUtils.setupWriteContext(writeContext, EthernetCsmacd.class); - customizer = new EthernetCustomizer(api, new NamingContext("ifcintest", IFC_TEST_INSTANCE)); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE); - } - - @Test - public void testWrite() throws WriteFailedException { - when(api.hwInterfaceSetMtu(any())).thenReturn(future(new HwInterfaceSetMtuReply())); - final int mtu = 1234; - customizer.writeCurrentAttributes(IF_IID, EthernetValidatorTest.ethernet(mtu), writeContext); - verify(api).hwInterfaceSetMtu(mtuSetRequest(mtu)); - } - - @Test - public void testUpdate() throws WriteFailedException { - when(api.hwInterfaceSetMtu(any())).thenReturn(future(new HwInterfaceSetMtuReply())); - final int mtu = 5678; - customizer.updateCurrentAttributes(IF_IID, mock(Ethernet.class), EthernetValidatorTest.ethernet(mtu), writeContext); - verify(api).hwInterfaceSetMtu(mtuSetRequest(mtu)); - } - - private HwInterfaceSetMtu mtuSetRequest(final int mtu) { - final HwInterfaceSetMtu request = new HwInterfaceSetMtu(); - request.swIfIndex = IF_INDEX; - request.mtu = (short)mtu; - return request; - } - - @Test(expected = WriteFailedException.class) - public void testDelete() throws WriteFailedException { - customizer.deleteCurrentAttributes(IF_IID, mock(Ethernet.class), writeContext); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/EthernetValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/EthernetValidatorTest.java deleted file mode 100644 index ce639d22f..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/EthernetValidatorTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; -import io.fd.honeycomb.translate.write.WriteContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Ethernet; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.EthernetBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class EthernetValidatorTest { - - private EthernetValidator validator; - - @Mock - private WriteContext writeContext; - - private static final String IF_NAME = "eth0"; - private static final int IF_MTU = 1234; - private static final InstanceIdentifier ID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation( - VppInterfaceAugmentation.class).child(Ethernet.class); - - @Before - public void setUp() { - initMocks(this); - NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); - validator = new EthernetValidator(ifcContext); - } - - @Test - public void testWriteSuccessful() throws CreateValidationFailedException { - validator.validateWrite(ID, ethernet(IF_MTU), writeContext); - } - - @Test(expected = NullPointerException.class) - public void testWriteFailedNoMTU() throws CreateValidationFailedException { - validator.validateWrite(ID, ethernet(null), writeContext); - } - - @Test - public void testUpdateSuccessful() throws UpdateValidationFailedException { - validator.validateUpdate(ID, ethernet(IF_MTU), ethernet(IF_MTU + 1), writeContext); - } - - static Ethernet ethernet(final Integer mtu) { - final EthernetBuilder ethernet = new EthernetBuilder(); - ethernet.setMtu(mtu); - return ethernet.build(); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/GreCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/GreCustomizerTest.java deleted file mode 100644 index d8f6f5682..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/GreCustomizerTest.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.VppBaseCallException; -import io.fd.jvpp.VppInvocationException; -import io.fd.jvpp.core.dto.GreTunnelAddDel; -import io.fd.jvpp.core.dto.GreTunnelAddDelReply; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Gre; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.GreBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class GreCustomizerTest extends WriterCustomizerTest implements AddressTranslator { - - private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; - private static final byte ADD_GRE = 1; - private static final byte DEL_GRE = 0; - private final String IFACE_NAME = "eth0"; - private final int IFACE_ID = 1; - private InstanceIdentifier id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(VppInterfaceAugmentation.class).child(Gre.class); - private GreCustomizer customizer; - - private static Gre generateGre() { - final GreBuilder builder = new GreBuilder(); - builder.setSrc(new IpAddressNoZone(new Ipv4AddressNoZone("192.168.20.10"))); - builder.setDst(new IpAddressNoZone(new Ipv4AddressNoZone("192.168.20.11"))); - builder.setOuterFibId(Long.valueOf(123)); - return builder.build(); - } - - @Override - public void setUpTest() throws Exception { - InterfaceTypeTestUtils.setupWriteContext(writeContext, - org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.GreTunnel.class); - customizer = new GreCustomizer(api, new NamingContext("generateInterfaceNAme", IFC_TEST_INSTANCE)); - } - - private void whenGreAddDelTunnelThenSuccess() { - final GreTunnelAddDelReply reply = new GreTunnelAddDelReply(); - reply.swIfIndex = IFACE_ID; - doReturn(future(reply)).when(api).greTunnelAddDel(any(GreTunnelAddDel.class)); - } - - private void whenGreAddDelTunnelThenFailure() { - doReturn(failedFuture()).when(api).greTunnelAddDel(any(GreTunnelAddDel.class)); - } - - private GreTunnelAddDel verifyGreAddDelTunnelWasInvoked(final Gre gre) throws VppInvocationException { - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(GreTunnelAddDel.class); - verify(api).greTunnelAddDel(argumentCaptor.capture()); - final GreTunnelAddDel actual = argumentCaptor.getValue(); - assertEquals(0, actual.tunnel.isIpv6); - assertArrayEquals(ipAddressToArray(gre.getSrc()), actual.tunnel.src.un.getIp4().ip4Address); - assertArrayEquals(ipAddressToArray(gre.getDst()), actual.tunnel.dst.un.getIp4().ip4Address); - assertEquals(gre.getOuterFibId().intValue(), actual.tunnel.outerFibId); - return actual; - } - - private void verifyGreAddWasInvoked(final Gre gre) throws VppInvocationException { - final GreTunnelAddDel actual = verifyGreAddDelTunnelWasInvoked(gre); - assertEquals(ADD_GRE, actual.isAdd); - } - - private void verifyGreDeleteWasInvoked(final Gre gre) throws VppInvocationException { - final GreTunnelAddDel actual = verifyGreAddDelTunnelWasInvoked(gre); - assertEquals(DEL_GRE, actual.isAdd); - } - - @Test - public void testWriteCurrentAttributes() throws Exception { - final Gre gre = generateGre(); - - whenGreAddDelTunnelThenSuccess(); - - noMappingDefined(mappingContext, IFACE_NAME, IFC_TEST_INSTANCE); - - customizer.writeCurrentAttributes(id, gre, writeContext); - verifyGreAddWasInvoked(gre); - verify(mappingContext).put(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), - eq(mapping(IFACE_NAME, IFACE_ID).get())); - } - - @Test - public void testWriteCurrentAttributesMappingAlreadyPresent() throws Exception { - final Gre gre = generateGre(); - - whenGreAddDelTunnelThenSuccess(); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE); - - customizer.writeCurrentAttributes(id, gre, writeContext); - verifyGreAddWasInvoked(gre); - - // Remove the first mapping before putting in the new one - verify(mappingContext).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE))); - verify(mappingContext).put(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(mapping(IFACE_NAME, IFACE_ID).get())); - } - - @Test - public void testWriteCurrentAttributesFailed() throws Exception { - final Gre gre = generateGre(); - - whenGreAddDelTunnelThenFailure(); - - try { - customizer.writeCurrentAttributes(id, gre, writeContext); - } catch (WriteFailedException.CreateFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyGreAddWasInvoked(gre); - // Mapping not stored due to failure - verify(mappingContext, times(0)).put(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(mapping( - IFACE_NAME, 0).get())); - return; - } - fail("WriteFailedException.CreateFailedException was expected"); - } - - @Test(expected = UnsupportedOperationException.class) - public void testUpdateCurrentAttributes() throws Exception { - customizer.updateCurrentAttributes(id, generateGre(), generateGre(), writeContext); - } - - @Test - public void testDeleteCurrentAttributes() throws Exception { - final Gre gre = generateGre(); - - whenGreAddDelTunnelThenSuccess(); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE); - - customizer.deleteCurrentAttributes(id, gre, writeContext); - verifyGreDeleteWasInvoked(gre); - verify(mappingContext).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE))); - } - - @Test - public void testDeleteCurrentAttributesaFailed() throws Exception { - final Gre gre = generateGre(); - - whenGreAddDelTunnelThenFailure(); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE); - - try { - customizer.deleteCurrentAttributes(id, gre, writeContext); - } catch (WriteFailedException.DeleteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyGreDeleteWasInvoked(gre); - verify(mappingContext, times(0)).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE))); - return; - } - fail("WriteFailedException.DeleteFailedException was expected"); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/GreValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/GreValidatorTest.java deleted file mode 100644 index e7f786bde..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/GreValidatorTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; -import io.fd.honeycomb.translate.write.WriteContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Gre; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.GreBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class GreValidatorTest { - - private GreValidator validator; - - @Mock - private WriteContext writeContext; - - private static final String IPV6 = "a::100"; - private static final String IPV4_1 = "192.168.20.10"; - private static final String IPV4_2 = "192.168.20.11"; - private static final Long OUT_FIB_ID = Long.valueOf(123); - private static final String IFACE_NAME = "eth0"; - private static final InstanceIdentifier ID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(VppInterfaceAugmentation.class).child(Gre.class); - - @Before - public void setUp() { - initMocks(this); - NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); - validator = new GreValidator(ifcContext); - } - - @Test - public void testWriteSuccessful() throws CreateValidationFailedException { - validator.validateWrite(ID, generateCorrectGre(), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedMixedIpv4Ipv6() throws CreateValidationFailedException { - validator.validateWrite(ID, generateGre(ip4(IPV4_1), ip6(IPV6), OUT_FIB_ID), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoSrcAddr() throws CreateValidationFailedException { - validator.validateWrite(ID, generateGre(null, ip6(IPV6), OUT_FIB_ID), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoDstAddr() throws CreateValidationFailedException { - validator.validateWrite(ID, generateGre(ip4(IPV4_1), null, OUT_FIB_ID), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoOutFibId() throws CreateValidationFailedException { - validator.validateWrite(ID, generateGre(ip4(IPV4_1), ip4(IPV4_2), null), writeContext); - } - - @Test - public void testDeleteSuccessful() throws DeleteValidationFailedException { - validator.validateDelete(ID, generateCorrectGre(), writeContext); - } - - private Gre generateCorrectGre() { - return generateGre(ip4(IPV4_1), ip4(IPV4_2), OUT_FIB_ID); - } - - private Gre generateGre(final IpAddressNoZone srcAddr, final IpAddressNoZone dstAddr, final Long outerFibId) { - final GreBuilder builder = new GreBuilder(); - builder.setSrc(srcAddr); - builder.setDst(dstAddr); - builder.setOuterFibId(outerFibId); - return builder.build(); - } - - private IpAddressNoZone ip4(String addr) { - return new IpAddressNoZone(new Ipv4AddressNoZone(addr)); - } - - private IpAddressNoZone ip6(String addr) { - return new IpAddressNoZone(new Ipv6AddressNoZone(addr)); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizerTest.java deleted file mode 100644 index 8d2afcc97..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizerTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.VppBaseCallException; -import io.fd.jvpp.core.dto.SwInterfaceSetFlags; -import io.fd.jvpp.core.dto.SwInterfaceSetFlagsReply; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { - private static final String IFACE_CTX_NAME = "interface-ctx"; - private static final String IF_NAME = "eth1"; - private static final int IF_INDEX = 1; - - private static final InstanceIdentifier IID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)); - - private static final String LOCAL0_IFC_NAME = "local0"; - private static final InstanceIdentifier LOCAL0_IID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(LOCAL0_IFC_NAME)); - private InterfaceCustomizer customizer; - - @Override - protected void setUpTest() throws Exception { - customizer = new InterfaceCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME)); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME); - } - - @Test - public void testWrite() throws WriteFailedException { - final boolean enabled = true; - when(api.swInterfaceSetFlags(any())).thenReturn(future(new SwInterfaceSetFlagsReply())); - customizer.writeCurrentAttributes(IID, iface(enabled), writeContext); - verify(api).swInterfaceSetFlags(expectedRequest(enabled)); - } - - @Test - public void testWriteFailed() { - final boolean enabled = false; - when(api.swInterfaceSetFlags(any())).thenReturn(failedFuture()); - try { - customizer.writeCurrentAttributes(IID, iface(enabled), writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verify(api).swInterfaceSetFlags(expectedRequest(enabled)); - return; - } - fail("WriteFailedException expected"); - } - - @Test - public void testUpdate() throws WriteFailedException { - when(api.swInterfaceSetFlags(any())).thenReturn(future(new SwInterfaceSetFlagsReply())); - customizer.updateCurrentAttributes(IID, iface(false), iface(true), writeContext); - verify(api).swInterfaceSetFlags(expectedRequest(true)); - } - - @Test - public void testUpdateFailed() { - when(api.swInterfaceSetFlags(any())).thenReturn(failedFuture()); - try { - customizer.updateCurrentAttributes(IID, iface(false), iface(true), writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verify(api).swInterfaceSetFlags(expectedRequest(true)); - return; - } - fail("WriteFailedException expected"); - } - - @Test - public void testDelete() throws WriteFailedException { - customizer.deleteCurrentAttributes(IID, mock(Interface.class), writeContext); - verifyZeroInteractions(api); - } - - @Test(expected = WriteFailedException.DeleteFailedException.class) - public void testDeleteLocal0() throws WriteFailedException { - final Interface ifc = mock(Interface.class); - when(ifc.getName()).thenReturn(LOCAL0_IFC_NAME); - customizer.deleteCurrentAttributes(LOCAL0_IID, ifc, writeContext); - } - - private Interface iface(final boolean enabled) { - return new InterfaceBuilder().setName(IF_NAME).setEnabled(enabled).build(); - } - - private SwInterfaceSetFlags expectedRequest(final boolean enabled) { - final SwInterfaceSetFlags request = new SwInterfaceSetFlags(); - request.adminUpDown = booleanToByte(enabled); - request.swIfIndex = IF_INDEX; - return request; - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java deleted file mode 100644 index 533c627f6..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizerTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.SwInterfaceSetTable; -import io.fd.jvpp.core.dto.SwInterfaceSetTableReply; -import java.util.Optional; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Routing; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.RoutingBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceRoutingCustomizerTest extends WriterCustomizerTest { - private static final String IFACE_CTX_NAME = "interface-ctx"; - private static final String IF_NAME = "eth1"; - private static final int IF_INDEX = 1; - private static final InstanceIdentifier IID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(VppInterfaceAugmentation.class).child(Routing.class); - - private InterfaceRoutingCustomizer customizer; - - @Override - protected void setUpTest() throws Exception { - customizer = new InterfaceRoutingCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME)); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME); - } - - @Test - public void testWrite() throws WriteFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - final int vrfId = 123; - when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply())); - customizer.writeCurrentAttributes(IID, routing(vrfId), writeContext); - verify(api).swInterfaceSetTable(expectedRequest(vrfId)); - } - - @Test(expected = WriteFailedException.class) - public void testWriteFailed() throws WriteFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - when(api.swInterfaceSetTable(any())).thenReturn(failedFuture()); - customizer.writeCurrentAttributes(IID, routing(213), writeContext); - } - - @Test - public void testWriteEmptyIfaceData() throws WriteFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))) - .thenReturn(Optional.of(new InterfaceBuilder().build())); - final int vrfId = 123; - when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply())); - customizer.writeCurrentAttributes(IID, routing(vrfId), writeContext); - verify(api).swInterfaceSetTable(expectedRequest(vrfId)); - } - - @Test(expected = WriteFailedException.class) - public void testUpdateFailed() throws WriteFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - when(api.swInterfaceSetTable(any())).thenReturn(failedFuture()); - customizer.updateCurrentAttributes(IID, routing(123L), routing(321L), writeContext); - } - - @Test - public void testDelete() throws WriteFailedException { - when(writeContext.readAfter(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply())); - customizer.deleteCurrentAttributes(IID, routing(123), writeContext); - verify(api).swInterfaceSetTable(expectedRequest(0)); - } - - @Test(expected = WriteFailedException.DeleteFailedException.class) - public void testDeleteFailed() throws WriteFailedException { - when(writeContext.readAfter(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - when(api.swInterfaceSetTable(any())).thenReturn(failedFuture()); - customizer.deleteCurrentAttributes(IID, routing(123), writeContext); - } - - private Routing routing(final long vrfId) { - return new RoutingBuilder().setIpv4VrfId(new VniReference(vrfId)).build(); - } - - private SwInterfaceSetTable expectedRequest(final int vrfId) { - final SwInterfaceSetTable request = new SwInterfaceSetTable(); - request.isIpv6 = 0; - request.swIfIndex = IF_INDEX; - request.vrfId = vrfId; - return request; - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingValidatorTest.java deleted file mode 100644 index e10aba4a2..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingValidatorTest.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; -import io.fd.honeycomb.translate.write.WriteContext; -import java.util.Collections; -import java.util.Optional; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Routing; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.RoutingBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceRoutingValidatorTest { - - private InterfaceRoutingValidator validator; - - @Mock - private WriteContext writeContext; - - private static final String IF_NAME = "eth1"; - private static final Long VRF_ID = Long.valueOf(123); - - private static final InstanceIdentifier ID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(VppInterfaceAugmentation.class).child(Routing.class); - - @Before - public void setUp() { - initMocks(this); - NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); - validator = new InterfaceRoutingValidator(ifcContext); - } - - @Test - public void testWriteSuccessful() throws CreateValidationFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - validator.validateWrite(ID, routing(VRF_ID, true, false), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoFrfIds() throws CreateValidationFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - validator.validateWrite(ID, routing(null, true, true), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedWithV4Address() throws CreateValidationFailedException { - when(writeContext.readBefore(RWUtils.cutId(ID, Interface.class))) - .thenReturn(Optional.of(ifaceWithV4Address())); - validator.validateWrite(ID, routing(VRF_ID, true, false), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedWithV6Address() throws CreateValidationFailedException { - when(writeContext.readBefore(RWUtils.cutId(ID, Interface.class))) - .thenReturn(Optional.of(ifaceWithV6Address())); - validator.validateWrite(ID, routing(VRF_ID, true, false), writeContext); - } - - @Test - public void testUpdateSuccessful() throws UpdateValidationFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - validator.validateUpdate(ID, routing(VRF_ID, true, false), - routing(VRF_ID, true, true), writeContext); - } - - @Test - public void testDeleteSuccessful() throws DeleteValidationFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - validator.validateDelete(ID, routing(VRF_ID, true, false), writeContext); - } - - private Routing routing(final Long vrfId, final boolean hasIpv4, final boolean hasIpv6) { - VniReference vni = null; - if (vrfId != null) { - vni = new VniReference(vrfId); - } - - RoutingBuilder builder = new RoutingBuilder(); - if (hasIpv4) { - builder.setIpv4VrfId(vni); - } - if (hasIpv6) { - builder.setIpv6VrfId(vni); - } - return builder.build(); - } - - private Interface ifaceWithV4Address() { - return new InterfaceBuilder() - .addAugmentation(Interface1.class, new Interface1Builder() - .setIpv4(new Ipv4Builder() - .setAddress(Collections.singletonList(new AddressBuilder().build())) - .build()) - .build()) - .build(); - } - - private Interface ifaceWithV6Address() { - return new InterfaceBuilder() - .addAugmentation(Interface1.class, new Interface1Builder() - .setIpv6(new Ipv6Builder() - .setAddress(Collections.singletonList( - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.AddressBuilder() - .build())) - .build()) - .build()) - .build(); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceTypeTestUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceTypeTestUtils.java deleted file mode 100644 index 23ad531a7..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceTypeTestUtils.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.Mockito.doReturn; - -import java.util.Optional; -import io.fd.honeycomb.translate.ModificationCache; -import io.fd.honeycomb.translate.write.WriteContext; -import org.mockito.Matchers; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -final class InterfaceTypeTestUtils { - - private InterfaceTypeTestUtils() {} - - static void setupWriteContext(final WriteContext writeContext, final Class ifcType) { - doReturn(new ModificationCache()).when(writeContext).getModificationCache(); - doReturn(Optional.of(new InterfaceBuilder() - .setType(ifcType) - .build())).when(writeContext).readAfter(Matchers.any(InstanceIdentifier.class)); - } - -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceUnnumberedCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceUnnumberedCustomizerTest.java deleted file mode 100644 index 5c49663a3..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceUnnumberedCustomizerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.InterfaceUnnumberedAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceUnnumberedCustomizerTest extends AbstractUnnumberedCustomizerTest { - private static final String UNNUMBERED_IFC_NAME = "eth2"; - private static final int UNNUMBERED_IFC_ID = 2; - private static final InstanceIdentifier UNNUMBERED_IFC_IID = InstanceIdentifier.create(Interfaces.class) - .child(Interface.class, new InterfaceKey(UNNUMBERED_IFC_NAME)) - .augmentation(InterfaceUnnumberedAugmentation.class) - .child(Unnumbered.class); - - @Override - protected int getUnnumberedIfcId() { - return UNNUMBERED_IFC_ID; - } - - @Override - protected String getUnnumberedIfcName() { - return UNNUMBERED_IFC_NAME; - } - - @Override - protected InstanceIdentifier getUnnumberedIfcIId() { - return UNNUMBERED_IFC_IID; - } - - @Override - protected AbstractUnnumberedCustomizer getCustomizer() { - return new InterfaceUnnumberedCustomizer(api, new NamingContext("ifc-prefix", IFC_CTX_NAME)); - } - -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceUnnumberedValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceUnnumberedValidatorTest.java deleted file mode 100644 index 79b3f9185..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceUnnumberedValidatorTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; -import io.fd.honeycomb.translate.write.WriteContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.InterfaceUnnumberedAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.UnnumberedBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceUnnumberedValidatorTest { - - private InterfaceUnnumberedValidator validator; - - @Mock - private WriteContext writeContext; - - private static final String IF_NAME = "eth2"; - private static final String TARGET_IFC0_NAME = "eth0"; - private static final InstanceIdentifier ID = InstanceIdentifier.create(Interfaces.class) - .child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(InterfaceUnnumberedAugmentation.class) - .child(Unnumbered.class); - - @Before - public void setUp() { - initMocks(this); - NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); - validator = new InterfaceUnnumberedValidator(ifcContext); - } - - @Test - public void testWriteSuccessful() throws CreateValidationFailedException { - validator.validateWrite(ID, getUnnumberedIfc(TARGET_IFC0_NAME), writeContext); - } - - @Test(expected = NullPointerException.class) - public void testWriteFailedNoUse() throws CreateValidationFailedException { - validator.validateWrite(ID, getUnnumberedIfc(null), writeContext); - } - - @Test - public void testUpdateSuccessful() throws UpdateValidationFailedException { - validator.validateUpdate(ID, getUnnumberedIfc(TARGET_IFC0_NAME), getUnnumberedIfc(TARGET_IFC0_NAME), - writeContext); - } - - @Test - public void testDeleteeSuccessful() throws DeleteValidationFailedException { - validator.validateDelete(ID, getUnnumberedIfc(TARGET_IFC0_NAME), writeContext); - } - - private Unnumbered getUnnumberedIfc(String use) { - return new UnnumberedBuilder().setUse(use).build(); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceValidatorTest.java deleted file mode 100644 index 21de26fed..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceValidatorTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; -import io.fd.honeycomb.translate.write.WriteContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceValidatorTest { - - private InterfaceValidator validator; - - @Mock - private WriteContext writeContext; - - private static final String IF_NAME = "eth0"; - private static final InstanceIdentifier ID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)); - - @Before - public void setUp() { - initMocks(this); - NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); - validator = new InterfaceValidator(ifcContext); - } - - @Test - public void testWriteSuccessful() throws CreateValidationFailedException { - validator.validateWrite(ID, getInterface(true), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoName() throws CreateValidationFailedException { - validator.validateWrite(ID, getInterface(null, true), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoEnableFlag() throws CreateValidationFailedException { - validator.validateWrite(ID, getInterface(null), writeContext); - } - - @Test - public void testUpdateSuccessful() throws UpdateValidationFailedException { - validator.validateUpdate(ID, getInterface(true), getInterface(true), writeContext); - } - - @Test - public void testDeleteSuccessful() throws DeleteValidationFailedException { - validator.validateDelete(ID, getInterface(true), writeContext); - } - - private Interface getInterface(final String name, final Boolean enabled) { - return new InterfaceBuilder().setName(name).setEnabled(enabled).build(); - } - - private Interface getInterface(final Boolean enabled) { - return new InterfaceBuilder().setName(IF_NAME).setEnabled(enabled).build(); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfacesStatisticsCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfacesStatisticsCustomizerTest.java deleted file mode 100644 index cd0da31a8..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfacesStatisticsCustomizerTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceStatisticsManager; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceStatisticsManagerImpl; -import io.fd.honeycomb.translate.write.WriteFailedException; -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfacesStatsAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.Statistics; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.StatisticsBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfacesStatisticsCustomizerTest extends WriterCustomizerTest { - - public static final InstanceIdentifier IID = - InstanceIdentifier.create(Interfaces.class).augmentation(VppInterfacesStatsAugmentation.class) - .child(Statistics.class); - - private InterfacesStatisticsCustomizer customizer; - private InterfaceStatisticsManager statsManager; - - @Override - protected void setUpTest() throws Exception { - statsManager = new InterfaceStatisticsManagerImpl(); - customizer = new InterfacesStatisticsCustomizer(statsManager); - } - - @Test - public void testWrite() throws WriteFailedException { - customizer.writeCurrentAttributes(IID, enableStats(true), writeContext); - Assert.assertTrue(statsManager.isStatisticsEnabled()); - } - - @Test - public void testUpdatetoEnabled() throws WriteFailedException { - customizer.updateCurrentAttributes(IID, enableStats(true), enableStats(false), writeContext); - Assert.assertFalse(statsManager.isStatisticsEnabled()); - } - - @Test - public void testUpdateToDisabled() throws WriteFailedException { - customizer.updateCurrentAttributes(IID, enableStats(false), enableStats(true), writeContext); - Assert.assertTrue(statsManager.isStatisticsEnabled()); - } - - @Test - public void testDelete() throws WriteFailedException { - customizer.deleteCurrentAttributes(IID, enableStats(true), writeContext); - Assert.assertFalse(statsManager.isStatisticsEnabled()); - } - - private Statistics enableStats(final boolean enabled) { - StatisticsBuilder builder = new StatisticsBuilder(); - return builder.setEnabled(enabled).build(); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/L2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/L2CustomizerTest.java deleted file mode 100644 index ac75d60fd..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/L2CustomizerTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.VppBaseCallException; -import io.fd.jvpp.core.dto.SwInterfaceSetL2Bridge; -import io.fd.jvpp.core.dto.SwInterfaceSetL2BridgeReply; -import io.fd.jvpp.core.dto.SwInterfaceSetL2Xconnect; -import io.fd.jvpp.core.dto.SwInterfaceSetL2XconnectReply; -import io.fd.jvpp.core.types.L2PortType; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2Builder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.Interconnection; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.BridgeBased; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.BridgeBasedBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.XconnectBased; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.XconnectBasedBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class L2CustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { - private static final String IFACE_CTX_NAME = "interface-ctx"; - private static final String BD_CTX_NAME = "bd-ctx"; - private static final String IF1_NAME = "eth1"; - private static final int IF1_INDEX = 1; - private static final String IF2_NAME = "eth2"; - private static final int IF2_INDEX = 2; - private static final InstanceIdentifier IID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF1_NAME)) - .augmentation(VppInterfaceAugmentation.class).child(L2.class); - private static final String BD_NAME = "test_bd"; - private static final int BD_INDEX = 13; - - private L2Customizer customizer; - - @Override - protected void setUpTest() throws Exception { - customizer = new L2Customizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME), - new NamingContext("bdPrefix", BD_CTX_NAME)); - defineMapping(mappingContext, IF1_NAME, IF1_INDEX, IFACE_CTX_NAME); - defineMapping(mappingContext, IF2_NAME, IF2_INDEX, IFACE_CTX_NAME); - defineMapping(mappingContext, BD_NAME, BD_INDEX, BD_CTX_NAME); - } - - @Test - public void testWrite() throws WriteFailedException { - when(api.swInterfaceSetL2Xconnect(any())).thenReturn(future(new SwInterfaceSetL2XconnectReply())); - customizer.writeCurrentAttributes(IID, l2(xconnectBased()), writeContext); - verify(api).swInterfaceSetL2Xconnect(xconnectRequest(true)); - } - - @Test - public void testWriteFailed() { - when(api.swInterfaceSetL2Bridge(any())).thenReturn(failedFuture()); - try { - customizer.writeCurrentAttributes(IID, l2(bridgeBased(false)), writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verify(api).swInterfaceSetL2Bridge(bridgeRequest(false, true)); - return; - } - fail("WriteFailedException expected"); - } - - @Test - public void testUpdate() throws WriteFailedException { - when(api.swInterfaceSetL2Bridge(any())).thenReturn(future(new SwInterfaceSetL2BridgeReply())); - customizer.updateCurrentAttributes(IID, l2(bridgeBased(false)), l2(bridgeBased(true)), writeContext); - verify(api).swInterfaceSetL2Bridge(bridgeRequest(true, true)); - } - - @Test - public void testDelete() throws WriteFailedException { - when(api.swInterfaceSetL2Xconnect(any())).thenReturn(future(new SwInterfaceSetL2XconnectReply())); - customizer.deleteCurrentAttributes(IID, l2(xconnectBased()), writeContext); - verify(api).swInterfaceSetL2Xconnect(xconnectRequest(false)); - } - - @Test - public void testDeleteFailed() { - when(api.swInterfaceSetL2Bridge(any())).thenReturn(failedFuture()); - try { - customizer.deleteCurrentAttributes(IID, l2(bridgeBased(true)), writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verify(api).swInterfaceSetL2Bridge(bridgeRequest(true, false)); - return; - } - fail("WriteFailedException expected"); - } - - private XconnectBased xconnectBased() { - return new XconnectBasedBuilder().setXconnectOutgoingInterface(IF2_NAME).build(); - } - - private SwInterfaceSetL2Xconnect xconnectRequest(final boolean enable) { - final SwInterfaceSetL2Xconnect request = new SwInterfaceSetL2Xconnect(); - request.rxSwIfIndex = IF1_INDEX; - request.txSwIfIndex = IF2_INDEX; - request.enable = booleanToByte(enable); - return request; - } - - private BridgeBased bridgeBased(final boolean bvi) { - return new BridgeBasedBuilder().setBridgedVirtualInterface(bvi) - .setBridgeDomain(BD_NAME).setSplitHorizonGroup((short) 123).build(); - } - - private SwInterfaceSetL2Bridge bridgeRequest(final boolean bvi, final boolean enable) { - final SwInterfaceSetL2Bridge request = new SwInterfaceSetL2Bridge(); - request.bdId = BD_INDEX; - request.rxSwIfIndex = IF1_INDEX; - request.portType = bvi ? L2PortType.L2_API_PORT_TYPE_BVI : L2PortType.L2_API_PORT_TYPE_NORMAL; - request.enable = booleanToByte(enable); - request.shg = 123; - return request; - } - - - private L2 l2(final Interconnection interconnection) { - return new L2Builder().setInterconnection(interconnection).build(); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/LoopbackCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/LoopbackCustomizerTest.java deleted file mode 100644 index ca86df563..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/LoopbackCustomizerTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.jvpp.core.dto.CreateLoopback; -import io.fd.jvpp.core.dto.CreateLoopbackReply; -import io.fd.jvpp.core.dto.DeleteLoopback; -import io.fd.jvpp.core.dto.DeleteLoopbackReply; -import org.junit.Test; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Loopback; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.LoopbackBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class LoopbackCustomizerTest extends WriterCustomizerTest { - - private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; - private LoopbackCustomizer loopCustomizer; - - @Override - public void setUpTest() throws Exception { - InterfaceTypeTestUtils.setupWriteContext(writeContext, - org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.Loopback.class); - loopCustomizer = new LoopbackCustomizer(api, new NamingContext("ifcintest", IFC_TEST_INSTANCE)); - } - - @Test - public void testCreate() throws Exception { - doAnswer(new Answer() { - - int idx = 0; - - @Override - public Object answer(final InvocationOnMock invocation) throws Throwable { - final CreateLoopbackReply t = new CreateLoopbackReply(); - t.swIfIndex = idx++; - return future(t); - } - }).when(api).createLoopback(any(CreateLoopback.class)); - - loopCustomizer.writeCurrentAttributes(getLoopbackId("loop"), getLoopbackData("ff:ff:ff:ff:ff:ff"), writeContext); - loopCustomizer.writeCurrentAttributes(getLoopbackId("loop2"), getLoopbackData("ff:ff:ff:ff:ff:ff"), writeContext); - - verify(api, times(2)).createLoopback(any(CreateLoopback.class)); - verify(mappingContext).put(eq(mappingIid("loop", IFC_TEST_INSTANCE)), eq( - mapping("loop", 0).get())); - verify(mappingContext).put(eq(mappingIid("loop2", IFC_TEST_INSTANCE)), eq( - mapping("loop2", 1).get())); - } - - @Test - public void testDelete() throws Exception { - final CreateLoopbackReply t = new CreateLoopbackReply(); - t.swIfIndex = 0; - doReturn(future(t)).when(api).createLoopback(any(CreateLoopback.class)); - - doReturn(future(new DeleteLoopbackReply())).when(api).deleteLoopback(any(DeleteLoopback.class)); - - loopCustomizer.writeCurrentAttributes(getLoopbackId("loop"), getLoopbackData("ff:ff:ff:ff:ff:ff"), writeContext); - defineMapping(mappingContext, "loop", 1, IFC_TEST_INSTANCE); - loopCustomizer.deleteCurrentAttributes(getLoopbackId("loop"), getLoopbackData("ff:ff:ff:ff:ff:ff"), writeContext); - - verify(api).createLoopback(any(CreateLoopback.class)); - verify(api).deleteLoopback(any(DeleteLoopback.class)); - verify(mappingContext).delete(eq(mappingIid("loop", IFC_TEST_INSTANCE))); - } - - private InstanceIdentifier getLoopbackId(final String loop) { - return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(loop)).augmentation( - VppInterfaceAugmentation.class).child(Loopback.class); - } - - private Loopback getLoopbackData(final String mac) { - return new LoopbackBuilder().setMac(new PhysAddress(mac)).build(); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/RewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/RewriteCustomizerTest.java deleted file mode 100644 index a51741f32..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/RewriteCustomizerTest.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.common.translate.util.TagRewriteOperation; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.VppBaseCallException; -import io.fd.jvpp.VppInvocationException; -import io.fd.jvpp.core.dto.L2InterfaceVlanTagRewrite; -import io.fd.jvpp.core.dto.L2InterfaceVlanTagRewriteReply; -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319._802dot1q; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.Rewrite; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.RewriteBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.ChildOf; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class RewriteCustomizerTest extends WriterCustomizerTest { - - private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; - private static final String IF_NAME = "local0"; - private static final String VLAN_IF_NAME = "local0.1"; - private static final int VLAN_IF_ID = 1; - private static final int VLAN_IF_INDEX = 11; - private NamingContext namingContext; - private RewriteCustomizer customizer; - private InstanceIdentifier VLAN_IID; - - private static InstanceIdentifier getVlanTagRewriteId(final String name, final long index) { - final Class> child = (Class) Rewrite.class; - final InstanceIdentifier id = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)).augmentation( - SubinterfaceAugmentation.class).child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey(index)) - .child(child); - return id; - } - - @Override - public void setUpTest() throws Exception { - namingContext = new NamingContext("generatedSubInterfaceName", IFC_TEST_INSTANCE); - customizer = new RewriteCustomizer(api, namingContext); - VLAN_IID = getVlanTagRewriteId(IF_NAME, VLAN_IF_ID); - defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_TEST_INSTANCE); - } - - private Rewrite generateRewrite(final TagRewriteOperation op) { - final RewriteBuilder builder = new RewriteBuilder(); - builder.setPopTags((short) op.getPopTags()); - builder.setVlanType(_802dot1q.class); - return builder.build(); - } - - private L2InterfaceVlanTagRewrite generateL2InterfaceVlanTagRewrite(final int swIfIndex, - final TagRewriteOperation op) { - final L2InterfaceVlanTagRewrite request = new L2InterfaceVlanTagRewrite(); - request.swIfIndex = swIfIndex; - request.vtrOp = op.ordinal(); - request.pushDot1Q = 1; - return request; - } - - /** - * Positive response - */ - private void whenL2InterfaceVlanTagRewriteThenSuccess() { - doReturn(future(new L2InterfaceVlanTagRewriteReply())).when(api) - .l2InterfaceVlanTagRewrite(any(L2InterfaceVlanTagRewrite.class)); - } - - /** - * Failure response send - */ - private void whenL2InterfaceVlanTagRewriteThenFailure() { - doReturn(failedFuture()).when(api).l2InterfaceVlanTagRewrite(any(L2InterfaceVlanTagRewrite.class)); - } - - private void verifyL2InterfaceVlanTagRewriteDeleteWasInvoked() throws VppInvocationException { - final L2InterfaceVlanTagRewrite request = new L2InterfaceVlanTagRewrite(); - request.swIfIndex = VLAN_IF_INDEX; - verify(api).l2InterfaceVlanTagRewrite(request); - } - - @Test - public void testCreate() throws Exception { - final TagRewriteOperation op = TagRewriteOperation.pop_2; - final Rewrite vlanTagRewrite = generateRewrite(op); - - whenL2InterfaceVlanTagRewriteThenSuccess(); - - customizer.writeCurrentAttributes(VLAN_IID, vlanTagRewrite, writeContext); - - verify(api).l2InterfaceVlanTagRewrite(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, op)); - } - - @Test - public void testCreateFailed() throws Exception { - final TagRewriteOperation op = TagRewriteOperation.pop_2; - final Rewrite vlanTagRewrite = generateRewrite(op); - - whenL2InterfaceVlanTagRewriteThenFailure(); - - try { - customizer.writeCurrentAttributes(VLAN_IID, vlanTagRewrite, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verify(api).l2InterfaceVlanTagRewrite(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, op)); - return; - } - fail("WriteFailedException.CreateFailedException was expected"); - } - - @Test - public void testUpdate() throws Exception { - final Rewrite before = generateRewrite(TagRewriteOperation.pop_2); - final Rewrite after = generateRewrite(TagRewriteOperation.pop_1); - - whenL2InterfaceVlanTagRewriteThenSuccess(); - - customizer.updateCurrentAttributes(VLAN_IID, before, after, writeContext); - - verify(api) - .l2InterfaceVlanTagRewrite(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1)); - } - - @Test - public void testUpdateFailed() throws Exception { - final Rewrite before = generateRewrite(TagRewriteOperation.pop_2); - final Rewrite after = generateRewrite(TagRewriteOperation.pop_1); - - whenL2InterfaceVlanTagRewriteThenFailure(); - - try { - customizer.updateCurrentAttributes(VLAN_IID, before, after, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verify(api) - .l2InterfaceVlanTagRewrite( - generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1)); - return; - } - fail("WriteFailedException.UpdateFailedException was expected"); - } - - @Test - public void testDelete() throws Exception { - whenL2InterfaceVlanTagRewriteThenSuccess(); - - customizer.deleteCurrentAttributes(VLAN_IID, null, writeContext); - - verifyL2InterfaceVlanTagRewriteDeleteWasInvoked(); - } - - @Test - public void testDeleteFailed() throws Exception { - whenL2InterfaceVlanTagRewriteThenFailure(); - - try { - customizer.deleteCurrentAttributes(VLAN_IID, null, writeContext); - } catch (WriteFailedException e) { - Assert.assertTrue(e.getCause() instanceof VppBaseCallException); - verifyL2InterfaceVlanTagRewriteDeleteWasInvoked(); - return; - } - fail("WriteFailedException.DeleteFailedException was expected"); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceCustomizerTest.java deleted file mode 100644 index 37a185d6a..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceCustomizerTest.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.VppBaseCallException; -import io.fd.jvpp.core.dto.CreateSubif; -import io.fd.jvpp.core.dto.CreateSubifReply; -import io.fd.jvpp.core.dto.SwInterfaceSetFlags; -import io.fd.jvpp.core.dto.SwInterfaceSetFlagsReply; -import java.util.Arrays; -import java.util.List; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319._802dot1ad; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.vlan.tagged.VlanTaggedBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.Match; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.MatchBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.TagsBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.tags.Tag; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.tags.TagBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.tags.TagKey; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.CVlan; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qTagVlanType; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qVlanId; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.SVlan; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag; -import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTagBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceCustomizerTest extends WriterCustomizerTest { - - private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; - private static final String SUPER_IF_NAME = "local0"; - private static final int SUPER_IF_ID = 1; - private static final String SUB_IFACE_NAME = "local0.11"; - private static final int SUBIF_INDEX = 11; - private static final short STAG_ID = 100; - private static final short CTAG_ID = 200; - private static final short CTAG_ANY_ID = 0; // only the *IdAny flag is set - private final Tag STAG_100; - private final Tag CTAG_200; - private final Tag CTAG_ANY; - private NamingContext namingContext; - private SubInterfaceCustomizer customizer; - - public SubInterfaceCustomizerTest() { - STAG_100 = generateTag((short) 0, SVlan.class, new Dot1qTag.VlanId(new Dot1qVlanId((int) STAG_ID))); - CTAG_200 = generateTag((short) 1, CVlan.class, new Dot1qTag.VlanId(new Dot1qVlanId(200))); - CTAG_ANY = generateTag((short) 1, CVlan.class, new Dot1qTag.VlanId(Dot1qTag.VlanId.Enumeration.Any)); - } - - private static Tag generateTag(final short index, final Class tagType, - final Dot1qTag.VlanId vlanId) { - TagBuilder tag = new TagBuilder(); - tag.setIndex(index); - tag.withKey(new TagKey(index)); - final Dot1qTagBuilder dtag = new Dot1qTagBuilder(); - dtag.setTagType(tagType); - dtag.setVlanId(vlanId); - tag.setDot1qTag(dtag.build()); - return tag.build(); - } - - static Match generateMatch() { - final MatchBuilder match = new MatchBuilder(); - final VlanTaggedBuilder tagged = new VlanTaggedBuilder(); - tagged.setMatchExactTags(true); - match.setMatchType( - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.VlanTaggedBuilder() - .setVlanTagged(tagged.build()).build()); - return match.build(); - } - - @Override - public void setUpTest() throws Exception { - namingContext = new NamingContext("generatedSubInterfaceName", IFC_TEST_INSTANCE); - customizer = new SubInterfaceCustomizer(api, namingContext); - defineMapping(mappingContext, SUB_IFACE_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE); - defineMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_ID, IFC_TEST_INSTANCE); - } - - private SubInterface generateSubInterface(final boolean enabled, final List tagList) { - SubInterfaceBuilder builder = new SubInterfaceBuilder(); - builder.setVlanType(_802dot1ad.class); - builder.setIdentifier(11L); - final TagsBuilder tags = new TagsBuilder(); - - tags.setTag(tagList); - - builder.setTags(tags.build()); - - builder.setMatch(generateMatch()); - builder.setEnabled(enabled); - return builder.build(); - } - - private CreateSubif generateSubInterfaceRequest(final int superIfId, final short innerVlanId, - final boolean isInnerAny) { - CreateSubif request = new CreateSubif(); - request.subId = 11; - request.swIfIndex = superIfId; - request.twoTags = 1; - request.innerVlanId = innerVlanId; - request.innerVlanIdAny = (byte) (isInnerAny - ? 1 - : 0); - request.dot1Ad = 1; - request.outerVlanId = STAG_ID; - request.exactMatch = 1; - return request; - } - - private SwInterfaceSetFlags generateSwInterfaceEnableRequest(final int swIfIndex) { - SwInterfaceSetFlags request = new SwInterfaceSetFlags(); - request.swIfIndex = swIfIndex; - request.adminUpDown = 1; - return request; - } - - private InstanceIdentifier getSubInterfaceId(final String name, final long index) { - return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)).augmentation( - SubinterfaceAugmentation.class).child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey(index)); - } - - private void whenCreateSubifThenSuccess() { - doReturn(future(new CreateSubifReply())).when(api).createSubif(any(CreateSubif.class)); - } - - /** - * Failure response send - */ - private void whenCreateSubifThenFailure() { - doReturn(failedFuture()).when(api).createSubif(any(CreateSubif.class)); - } - - private void whenSwInterfaceSetFlagsThenSuccess() { - doReturn(future(new SwInterfaceSetFlagsReply())).when(api).swInterfaceSetFlags(any(SwInterfaceSetFlags.class)); - } - - private SwInterfaceSetFlags verifySwInterfaceSetFlagsWasInvoked(final SwInterfaceSetFlags expected) - throws VppBaseCallException { - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(SwInterfaceSetFlags.class); - verify(api).swInterfaceSetFlags(argumentCaptor.capture()); - final SwInterfaceSetFlags actual = argumentCaptor.getValue(); - - assertEquals(expected.swIfIndex, actual.swIfIndex); - assertEquals(expected.adminUpDown, actual.adminUpDown); - return actual; - } - - @Test - public void testCreateTwoTags() throws Exception { - final SubInterface subInterface = generateSubInterface(false, Arrays.asList(STAG_100, CTAG_200)); - final InstanceIdentifier id = getSubInterfaceId(SUPER_IF_NAME, SUBIF_INDEX); - - whenCreateSubifThenSuccess(); - whenSwInterfaceSetFlagsThenSuccess(); - - customizer.writeCurrentAttributes(id, subInterface, writeContext); - - verify(api).createSubif(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ID, false)); - verify(mappingContext) - .put(eq(mappingIid(SUB_IFACE_NAME, IFC_TEST_INSTANCE)), eq( - mapping(SUB_IFACE_NAME, 0).get())); - } - - @Test - public void testCreateDot1qAnyTag() throws Exception { - final SubInterface subInterface = generateSubInterface(false, Arrays.asList(STAG_100, CTAG_ANY)); - final InstanceIdentifier id = getSubInterfaceId(SUPER_IF_NAME, SUBIF_INDEX); - - whenCreateSubifThenSuccess(); - whenSwInterfaceSetFlagsThenSuccess(); - - customizer.writeCurrentAttributes(id, subInterface, writeContext); - - verify(api).createSubif(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ANY_ID, true)); - verify(mappingContext) - .put(eq(mappingIid(SUB_IFACE_NAME, IFC_TEST_INSTANCE)), eq( - mapping(SUB_IFACE_NAME, 0).get())); - } - - @Test - public void testCreateFailed() throws Exception { - final SubInterface subInterface = generateSubInterface(false, Arrays.asList(STAG_100, CTAG_200)); - final InstanceIdentifier id = getSubInterfaceId(SUPER_IF_NAME, SUBIF_INDEX); - - whenCreateSubifThenFailure(); - - try { - customizer.writeCurrentAttributes(id, subInterface, writeContext); - } catch (WriteFailedException.CreateFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verify(api).createSubif(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ID, false)); - verify(mappingContext, times(0)).put( - eq(mappingIid(SUPER_IF_NAME, IFC_TEST_INSTANCE)), - eq(mapping(SUPER_IF_NAME, 0).get())); - return; - } - fail("WriteFailedException.CreateFailedException was expected"); - } - - @Test - public void testUpdate() throws Exception { - final List tags = Arrays.asList(STAG_100, CTAG_200); - final SubInterface before = generateSubInterface(false, tags); - final SubInterface after = generateSubInterface(true, tags); - final InstanceIdentifier id = getSubInterfaceId(SUPER_IF_NAME, SUBIF_INDEX); - - whenSwInterfaceSetFlagsThenSuccess(); - customizer.updateCurrentAttributes(id, before, after, writeContext); - - verifySwInterfaceSetFlagsWasInvoked(generateSwInterfaceEnableRequest(SUBIF_INDEX)); - } - - @Test(expected = UnsupportedOperationException.class) - public void testDelete() throws Exception { - final SubInterface subInterface = generateSubInterface(false, Arrays.asList(STAG_100, CTAG_200)); - customizer.deleteCurrentAttributes(null, subInterface, writeContext); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceL2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceL2CustomizerTest.java deleted file mode 100644 index 58d1803d3..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceL2CustomizerTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.SwInterfaceSetL2Bridge; -import io.fd.jvpp.core.dto.SwInterfaceSetL2BridgeReply; -import io.fd.jvpp.core.types.L2PortType; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.BridgeBasedBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceL2CustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { - private static final String IFACE_CTX_NAME = "interface-ctx"; - private static final String IF_NAME = "local0"; - private static final int IF_INDEX = 1; - private static final String SUBIF_NAME = "local0.0"; - private static final int SUBIF_INDEX = 11; - private static final long SUBIF_ID = 0; - - private static final InstanceIdentifier IID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation( - SubinterfaceAugmentation.class).child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey(SUBIF_ID)).child(L2.class); - - - private static final String BD_CTX_NAME = "bd-ctx"; - private static final String BD_NAME = "test_bd"; - private static final int BD_INDEX = 13; - - private SubInterfaceL2Customizer customizer; - - @Override - protected void setUpTest() throws Exception { - customizer = new SubInterfaceL2Customizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME), - new NamingContext("bdPrefix", BD_CTX_NAME)); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME); - defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFACE_CTX_NAME); - defineMapping(mappingContext, BD_NAME, BD_INDEX, BD_CTX_NAME); - } - - @Test - public void testWrite() throws WriteFailedException { - final boolean bvi = true; - when(api.swInterfaceSetL2Bridge(any())).thenReturn(future(new SwInterfaceSetL2BridgeReply())); - customizer.writeCurrentAttributes(IID, l2(bvi), writeContext); - verify(api).swInterfaceSetL2Bridge(bridgeRequest(bvi, true)); - } - - @Test - public void testUpdate() throws WriteFailedException { - final boolean bvi = false; - when(api.swInterfaceSetL2Bridge(any())).thenReturn(future(new SwInterfaceSetL2BridgeReply())); - customizer.updateCurrentAttributes(IID, l2(true), l2(bvi), writeContext); - verify(api).swInterfaceSetL2Bridge(bridgeRequest(bvi, true)); - } - - @Test - public void testDelete() throws WriteFailedException { - final boolean bvi = true; - when(api.swInterfaceSetL2Bridge(any())).thenReturn(future(new SwInterfaceSetL2BridgeReply())); - customizer.deleteCurrentAttributes(IID, l2(bvi), writeContext); - verify(api).swInterfaceSetL2Bridge(bridgeRequest(bvi, false)); - } - - private L2 l2(final boolean bvi) { - return new L2Builder().setInterconnection(new BridgeBasedBuilder().setBridgedVirtualInterface(bvi) - .setBridgeDomain(BD_NAME).setSplitHorizonGroup((short) 123).build()).build(); - } - - private SwInterfaceSetL2Bridge bridgeRequest(final boolean bvi, final boolean enable) { - final SwInterfaceSetL2Bridge request = new SwInterfaceSetL2Bridge(); - request.bdId = BD_INDEX; - request.rxSwIfIndex = SUBIF_INDEX; - request.portType = bvi ? L2PortType.L2_API_PORT_TYPE_BVI : L2PortType.L2_API_PORT_TYPE_NORMAL; - request.enable = booleanToByte(enable); - request.shg = 123; - return request; - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizerTest.java deleted file mode 100644 index 90c9d66c8..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizerTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.google.common.collect.ImmutableSet; -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.core.dto.SwInterfaceSetTable; -import io.fd.jvpp.core.dto.SwInterfaceSetTableReply; -import java.util.Collections; -import java.util.Optional; -import java.util.Set; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.Routing; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.RoutingBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceRoutingCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { - - private static final String IFACE_CTX_NAME = "interface-ctx"; - private static final String IF_NAME = "eth1"; - private static final String SUBIF_NAME = "eth1.0"; - private static final int IF_INDEX = 1; - private static final int SUBIF_INDEX = 0; - private static final InstanceIdentifier VALID_ID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(SubinterfaceAugmentation.class) - .child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey((long) SUBIF_INDEX)) - .child(Routing.class); - private static final int DISABLE_VRF = 0; - - @Captor - private ArgumentCaptor requestCaptor; - - - private SubInterfaceRoutingCustomizer customizer; - - @Override - protected void setUpTest() throws Exception { - customizer = new SubInterfaceRoutingCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME)); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME); - defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFACE_CTX_NAME); - when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply())); - when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply())); - } - - @Test - public void testWriteIpv4Vrf() throws WriteFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - final Routing v4Routing = new RoutingBuilder().setIpv4VrfId(new VniReference(4L)).build(); - customizer.writeCurrentAttributes(VALID_ID, v4Routing, writeContext); - verifySetTableRequest(1, Collections.singleton(request(false, SUBIF_INDEX, 4))); - } - - @Test - public void testWriteIpv6Vrf() throws WriteFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - final Routing v6Routing = new RoutingBuilder().setIpv6VrfId(new VniReference(3L)).build(); - customizer.writeCurrentAttributes(VALID_ID, v6Routing, writeContext); - verifySetTableRequest(1, Collections.singleton(request(true, SUBIF_INDEX, 3))); - } - - @Test - public void testUpdateIpv4Vrf() throws WriteFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - final Routing routingBefore = new RoutingBuilder().setIpv6VrfId(new VniReference(3L)) - .setIpv4VrfId(new VniReference(4L)).build(); - final Routing routingAfter = new RoutingBuilder().setIpv6VrfId(new VniReference(3L)) - .setIpv4VrfId(new VniReference(5L)).build(); - customizer.updateCurrentAttributes(VALID_ID, routingBefore, routingAfter, writeContext); - verifySetTableRequest(2, ImmutableSet.of(request(false, SUBIF_INDEX, 5), - request(true, SUBIF_INDEX, 3))); - } - - @Test - public void testUpdateIpv6Vrf() throws WriteFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - final Routing routingBefore = new RoutingBuilder().setIpv6VrfId(new VniReference(3L)) - .setIpv4VrfId(new VniReference(4L)).build(); - final Routing routingAfter = new RoutingBuilder().setIpv6VrfId(new VniReference(8L)) - .setIpv4VrfId(new VniReference(4L)).build(); - customizer.updateCurrentAttributes(VALID_ID, routingBefore, routingAfter, writeContext); - verifySetTableRequest(2, ImmutableSet.of(request(false, SUBIF_INDEX, 4), - request(true, SUBIF_INDEX, 8))); - } - - @Test - public void testDeleteIpv4Vrf() throws WriteFailedException { - when(writeContext.readAfter(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - final Routing v4Routing = new RoutingBuilder().setIpv4VrfId(new VniReference(4L)).build(); - customizer.deleteCurrentAttributes(VALID_ID, v4Routing, writeContext); - verifySetTableRequest(1, Collections.singleton(request(false, SUBIF_INDEX, DISABLE_VRF))); - } - - - @Test - public void testDeleteIpv6Vrf() throws WriteFailedException { - when(writeContext.readAfter(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - final Routing v6Routing = new RoutingBuilder().setIpv6VrfId(new VniReference(3L)).build(); - customizer.deleteCurrentAttributes(VALID_ID, v6Routing, writeContext); - verifySetTableRequest(1, Collections.singleton(request(true, SUBIF_INDEX, DISABLE_VRF))); - } - - private SwInterfaceSetTable request(final boolean ipv6, final int index, final int vrf) { - final SwInterfaceSetTable request = new SwInterfaceSetTable(); - request.vrfId = vrf; - request.swIfIndex = index; - request.isIpv6 = booleanToByte(ipv6); - return request; - } - - private void verifySetTableRequest(final int times, final Set requests) { - verify(api, times(times)).swInterfaceSetTable(requestCaptor.capture()); - requestCaptor.getAllValues().containsAll(requests); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingValidatorTest.java deleted file mode 100644 index 510887e70..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingValidatorTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; -import io.fd.honeycomb.translate.write.WriteContext; -import java.util.Collections; -import java.util.Optional; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.Ipv4Builder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.ipv4.AddressBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.Ipv6Builder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.Routing; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.RoutingBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceRoutingValidatorTest { - - private SubInterfaceRoutingValidator validator; - - @Mock - private WriteContext writeContext; - - private static final String IF_NAME = "eth1"; - private static final int SUBIF_INDEX = 0; - private static final InstanceIdentifier ID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(SubinterfaceAugmentation.class) - .child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey((long) SUBIF_INDEX)) - .child(Routing.class); - - @Before - public void setUp() { - initMocks(this); - NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); - validator = new SubInterfaceRoutingValidator(ifcContext); - } - - @Test - public void testWriteSuccessful() throws CreateValidationFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - validator.validateWrite(ID, getRouting(), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedV4AddressPresent() throws CreateValidationFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.of(v4AddressPresent())); - validator.validateWrite(ID, getRouting(), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedV6AddressPresent() throws CreateValidationFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.of(v6AddressPresent())); - validator.validateWrite(ID, getRouting(), writeContext); - } - - @Test - public void testUpdateSuccessful() throws UpdateValidationFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - validator.validateUpdate(ID, getRouting(), getRouting(), writeContext); - } - - @Test - public void testDeleteSuccessful() throws DeleteValidationFailedException { - when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); - validator.validateDelete(ID, getRouting(), writeContext); - } - - private Routing getRouting() { - return new RoutingBuilder().setIpv4VrfId(new VniReference(4L)).build(); - } - - private SubInterface v4AddressPresent() { - return new SubInterfaceBuilder() - .setIpv4(new Ipv4Builder() - .setAddress(Collections.singletonList(new AddressBuilder().build())) - .build()) - .build(); - } - - private SubInterface v6AddressPresent() { - return new SubInterfaceBuilder() - .setIpv6(new Ipv6Builder() - .setAddress(Collections.singletonList( - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.ipv6.AddressBuilder() - .build())) - .build()) - .build(); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceUnnumberedCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceUnnumberedCustomizerTest.java deleted file mode 100644 index fdaf6f925..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceUnnumberedCustomizerTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.SubinterfaceUnnumberedAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceUnnumberedCustomizerTest extends AbstractUnnumberedCustomizerTest { - private static final String PARENT_IFC_NAME = "eth2"; - private static final String UNNUMBERED_IFC_NAME = "eth2.123"; - private static final int UNNUMBERED_IFC_ID = 2; - private static final long UNNUMBERED_IFC_NUMBER = 123; - private static final InstanceIdentifier UNNUMBERED_IFC_IID = InstanceIdentifier.create(Interfaces.class) - .child(Interface.class, new InterfaceKey(PARENT_IFC_NAME)) - .augmentation(SubinterfaceAugmentation.class).child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey(UNNUMBERED_IFC_NUMBER)) - .augmentation(SubinterfaceUnnumberedAugmentation.class).child(Unnumbered.class); - - @Override - protected int getUnnumberedIfcId() { - return UNNUMBERED_IFC_ID; - } - - @Override - protected String getUnnumberedIfcName() { - return UNNUMBERED_IFC_NAME; - } - - @Override - protected InstanceIdentifier getUnnumberedIfcIId() { - return UNNUMBERED_IFC_IID; - } - - @Override - protected AbstractUnnumberedCustomizer getCustomizer() { - return new SubInterfaceUnnumberedCustomizer(api, new NamingContext("ifc-prefix", IFC_CTX_NAME)); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceUnnumberedValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceUnnumberedValidatorTest.java deleted file mode 100644 index 73043be8b..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceUnnumberedValidatorTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.WriteContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.InterfaceUnnumberedAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.UnnumberedBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceUnnumberedValidatorTest { - - private SubInterfaceUnnumberedValidator validator; - - @Mock - private WriteContext writeContext; - - private static final String IF_NAME = "eth2"; - private static final String TARGET_IFC0_NAME = "eth0"; - private static final InstanceIdentifier ID = InstanceIdentifier.create(Interfaces.class) - .child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(InterfaceUnnumberedAugmentation.class) - .child(Unnumbered.class); - - @Before - public void setUp() { - initMocks(this); - NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); - validator = new SubInterfaceUnnumberedValidator(ifcContext); - } - - @Test - public void testWriteSuccessful() throws DataValidationFailedException.CreateValidationFailedException { - validator.validateWrite(ID, getUnnumberedIfc(TARGET_IFC0_NAME), writeContext); - } - - @Test(expected = NullPointerException.class) - public void testWriteFailedNoUse() throws DataValidationFailedException.CreateValidationFailedException { - validator.validateWrite(ID, getUnnumberedIfc(null), writeContext); - } - - @Test - public void testUpdateSuccessful() throws DataValidationFailedException.UpdateValidationFailedException { - validator.validateUpdate(ID, getUnnumberedIfc(TARGET_IFC0_NAME), getUnnumberedIfc(TARGET_IFC0_NAME), - writeContext); - } - - @Test - public void testDeleteeSuccessful() throws DataValidationFailedException.DeleteValidationFailedException { - validator.validateDelete(ID, getUnnumberedIfc(TARGET_IFC0_NAME), writeContext); - } - - private Unnumbered getUnnumberedIfc(String use) { - return new UnnumberedBuilder().setUse(use).build(); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceValidatorTest.java deleted file mode 100644 index e7b9e668b..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceValidatorTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; -import io.fd.honeycomb.translate.write.WriteContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.Match; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceValidatorTest { - - private SubInterfaceValidator validator; - - @Mock - private WriteContext writeContext; - - private static final String SUPER_IF_NAME = "local0"; - private static final String SUB_IFACE_NAME = "local0.11"; - private static final long SUBIF_INDEX = 11; - private static final InstanceIdentifier ID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(SUPER_IF_NAME)) - .augmentation( - SubinterfaceAugmentation.class).child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey(SUBIF_INDEX)); - - @Before - public void setUp() { - initMocks(this); - NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); - validator = new SubInterfaceValidator(ifcContext); - } - - @Test - public void testWriteSuccessful() throws CreateValidationFailedException { - validator - .validateWrite(ID, generateSubInterface(11L, SubInterfaceCustomizerTest.generateMatch()), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoIdentifier() throws CreateValidationFailedException { - validator.validateWrite(ID, generateSubInterface(null, SubInterfaceCustomizerTest.generateMatch()), - writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoMatch() throws CreateValidationFailedException { - validator.validateWrite(ID, generateSubInterface(11L, null), writeContext); - } - - private SubInterface generateSubInterface(final Long identifier, final Match match) { - return new SubInterfaceBuilder() - .setIdentifier(identifier) - .setMatch(match) - .setEnabled(true) - .build(); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/TapV2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/TapV2CustomizerTest.java deleted file mode 100644 index a0f138219..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/TapV2CustomizerTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2018 Pantheon Technologies and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.Ipv4Translator; -import io.fd.hc2vpp.common.translate.util.Ipv6Translator; -import io.fd.hc2vpp.common.translate.util.MacTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.jvpp.core.dto.TapCreateV2; -import io.fd.jvpp.core.dto.TapCreateV2Reply; -import io.fd.jvpp.core.dto.TapDeleteV2; -import io.fd.jvpp.core.dto.TapDeleteV2Reply; -import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class TapV2CustomizerTest extends WriterCustomizerTest - implements Ipv4Translator, Ipv6Translator, MacTranslator { - - private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; - private TapV2Customizer tapCustomizer; - private static final String HOST_IF_NAME = "tapV21"; - private static final String HOST_BRIDGE = "TestBridge"; - private static final String HOST_IPV4_PREFIX = "192.168.255.100"; - private static final byte HOST_IPV4_PREFIX_LEN = 24; - private static final String HOST_IPV4_GW = "192.168.255.1"; - private static final String HOST_IPV6_PREFIX = "a::100"; - private static final String HOST_IPV6_GW = "a::1"; - private static final byte HOST_IPV6_PREFIX_LEN = -128; - private static final int HOST_IPV6_PREFIX_LEN_EXP = 128; - private static final int RX_TX_RING_SIZE = 512; - private static final String HOST_MAC = "00:ee:ee:ee:ee:ee"; - private static final String HOST_NAMESPACE = "testHostNS"; - - @Override - public void setUpTest() throws Exception { - InterfaceTypeTestUtils.setupWriteContext(writeContext, - org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.TapV2.class); - tapCustomizer = new TapV2Customizer(api, new NamingContext("ifcintest", IFC_TEST_INSTANCE)); - } - - @Test - public void testCreate() throws Exception { - final AtomicInteger idx = new AtomicInteger(0); - doAnswer((i) -> { - final TapCreateV2 tapData = i.getArgument(0); - if (tapData == null) { - return failedFuture(); - } - - Assert.assertArrayEquals(tapData.hostBridge, HOST_BRIDGE.getBytes()); - Assert.assertEquals(tapData.hostBridgeSet, 1); - Assert.assertArrayEquals(tapData.hostIfName, HOST_IF_NAME.getBytes()); - Assert.assertEquals(tapData.hostIfNameSet, 1); - Assert.assertArrayEquals(tapData.hostNamespace, HOST_NAMESPACE.getBytes()); - Assert.assertEquals(tapData.hostNamespaceSet, 1); - Assert.assertArrayEquals(tapData.hostIp4Addr, ipv4AddressPrefixToArray( - new Ipv4Prefix(String.format("%s/%d", HOST_IPV4_PREFIX, HOST_IPV4_PREFIX_LEN)))); - Assert.assertEquals(tapData.hostIp4AddrSet, 1); - Assert.assertEquals(tapData.hostIp4PrefixLen, HOST_IPV4_PREFIX_LEN); - Assert.assertArrayEquals(tapData.hostIp6Addr, ipv6AddressPrefixToArray( - new Ipv6Prefix(String.format("%s/%d", HOST_IPV6_PREFIX, HOST_IPV6_PREFIX_LEN_EXP)))); - Assert.assertEquals(tapData.hostIp6AddrSet, 1); - Assert.assertEquals(tapData.hostIp6PrefixLen, HOST_IPV6_PREFIX_LEN); - Assert.assertArrayEquals(tapData.hostIp4Gw, ipv4AddressPrefixToArray( - new Ipv4Prefix(String.format("%s/%d", HOST_IPV4_GW, 24)))); - Assert.assertEquals(tapData.hostIp4GwSet, 1); - Assert.assertArrayEquals(tapData.hostIp6Gw, ipv6AddressPrefixToArray( - new Ipv6Prefix(String.format("%s/%d", HOST_IPV6_GW, 96)))); - Assert.assertEquals(tapData.hostIp6GwSet, 1); - Assert.assertArrayEquals(tapData.hostMacAddr, parseMac(HOST_MAC)); - Assert.assertEquals(tapData.hostMacAddrSet, 1); - Assert.assertEquals(tapData.rxRingSz, RX_TX_RING_SIZE); - Assert.assertEquals(tapData.txRingSz, RX_TX_RING_SIZE); - final TapCreateV2Reply t = new TapCreateV2Reply(); - t.swIfIndex = idx.getAndIncrement(); - return future(t); - - }).when(api).tapCreateV2(any(TapCreateV2.class)); - - tapCustomizer.writeCurrentAttributes(getTapId("tap"), getTapData("tap"), writeContext); - tapCustomizer.writeCurrentAttributes(getTapId("tap2"), getTapData("tap2"), writeContext); - - verify(api, times(2)).tapCreateV2(any(TapCreateV2.class)); - verify(mappingContext).put(eq(mappingIid("tap", IFC_TEST_INSTANCE)), eq( - mapping("tap", 0).get())); - verify(mappingContext).put(eq(mappingIid("tap2", IFC_TEST_INSTANCE)), eq( - mapping("tap2", 1).get())); - } - - @Test - public void testDelete() throws Exception { - final TapCreateV2Reply t = new TapCreateV2Reply(); - t.swIfIndex = 0; - doReturn(future(t)).when(api).tapCreateV2(any(TapCreateV2.class)); - - doReturn(future(new TapDeleteV2Reply())).when(api).tapDeleteV2(any(TapDeleteV2.class)); - tapCustomizer.writeCurrentAttributes(getTapId("tap-v2"), getTapData("tap-v2"), writeContext); - defineMapping(mappingContext, "tap-v2", 1, IFC_TEST_INSTANCE); - tapCustomizer.deleteCurrentAttributes(getTapId("tap-v2"), getTapData("tap-v2"), writeContext); - - verify(api).tapCreateV2(any(TapCreateV2.class)); - verify(api).tapDeleteV2(any(TapDeleteV2.class)); - verify(mappingContext).delete(eq(mappingIid("tap-v2", IFC_TEST_INSTANCE))); - } - - private InstanceIdentifier getTapId(final String tap) { - return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(tap)).augmentation( - VppInterfaceAugmentation.class).child(TapV2.class); - } - - private TapV2 getTapData(final String tap) { - return new TapV2Builder() - .setHostInterfaceName(HOST_IF_NAME) - .setMac(new PhysAddress(HOST_MAC)) - .setTag(tap + "_tag") - .setHostBridge(HOST_BRIDGE) - .setHostIpv4Address(new Ipv4Prefix(String.format("%s/%s", HOST_IPV4_PREFIX, HOST_IPV4_PREFIX_LEN))) - .setHostIpv4Gateway(new Ipv4Address(HOST_IPV4_GW)) - .setHostIpv6Address(new Ipv6Prefix(String.format("%s/%s", HOST_IPV6_PREFIX, HOST_IPV6_PREFIX_LEN_EXP))) - .setHostIpv6Gateway(new Ipv6Address(HOST_IPV6_GW)) - .setRxRingSize(RX_TX_RING_SIZE) - .setTxRingSize(RX_TX_RING_SIZE) - .setHostMac(new PhysAddress(HOST_MAC)) - .setHostNamespace(HOST_NAMESPACE) - .build(); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VhostUserCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VhostUserCustomizerTest.java deleted file mode 100644 index db190ee06..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VhostUserCustomizerTest.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.Ipv4Translator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.VppBaseCallException; -import io.fd.jvpp.VppInvocationException; -import io.fd.jvpp.core.dto.CreateVhostUserIf; -import io.fd.jvpp.core.dto.CreateVhostUserIfReply; -import io.fd.jvpp.core.dto.DeleteVhostUserIf; -import io.fd.jvpp.core.dto.DeleteVhostUserIfReply; -import io.fd.jvpp.core.dto.ModifyVhostUserIf; -import io.fd.jvpp.core.dto.ModifyVhostUserIfReply; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUserRole; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUser; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUserBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class VhostUserCustomizerTest extends WriterCustomizerTest implements Ipv4Translator { - - private static final int IFACE_ID = 1; - private static final String IFACE_NAME = "eth0"; - private static final InstanceIdentifier ID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(VppInterfaceAugmentation.class).child(VhostUser.class); - private VhostUserCustomizer customizer; - - static VhostUser generateVhostUser(final VhostUserRole role, final String socketName) { - VhostUserBuilder builder = new VhostUserBuilder(); - builder.setRole(role); - builder.setSocket(socketName); - return builder.build(); - } - - @Override - public void setUpTest() throws Exception { - InterfaceTypeTestUtils.setupWriteContext(writeContext, - org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUser.class); - customizer = new VhostUserCustomizer(api, new NamingContext("generatedInterfaceName", "test-instance")); - } - - private CreateVhostUserIf verifyCreateVhostUserIfWasInvoked(final VhostUser vhostUser) - throws VppInvocationException { - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(CreateVhostUserIf.class); - verify(api).createVhostUserIf(argumentCaptor.capture()); - final CreateVhostUserIf actual = argumentCaptor.getValue(); - assertEquals(0, actual.customDevInstance); - - assertEquals(booleanToByte(VhostUserRole.Server.equals(vhostUser.getRole())), actual.isServer); - assertEquals(0, actual.renumber); - assertEquals(0, actual.useCustomMac); - assertArrayEquals(vhostUser.getSocket().getBytes(), actual.sockFilename); - assertNotNull(actual.macAddress); - return actual; - } - - private ModifyVhostUserIf verifyModifyVhostUserIfWasInvoked(final VhostUser vhostUser, final int swIfIndex) - throws VppInvocationException { - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(ModifyVhostUserIf.class); - verify(api).modifyVhostUserIf(argumentCaptor.capture()); - final ModifyVhostUserIf actual = argumentCaptor.getValue(); - assertEquals(0, actual.customDevInstance); - - assertEquals(booleanToByte(VhostUserRole.Server.equals(vhostUser.getRole())), actual.isServer); - assertEquals(0, actual.renumber); - assertEquals(swIfIndex, actual.swIfIndex); - assertArrayEquals(vhostUser.getSocket().getBytes(), actual.sockFilename); - return actual; - } - - private DeleteVhostUserIf verifyDeleteVhostUserIfWasInvoked(final int swIfIndex) throws VppInvocationException { - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(DeleteVhostUserIf.class); - verify(api).deleteVhostUserIf(argumentCaptor.capture()); - final DeleteVhostUserIf actual = argumentCaptor.getValue(); - assertEquals(swIfIndex, actual.swIfIndex); - return actual; - } - - @Test - public void testWriteCurrentAttributes() throws Exception { - final VhostUser vhostUser = generateVhostUser(VhostUserRole.Server, "socketName"); - - when(api.createVhostUserIf(any(CreateVhostUserIf.class))).thenReturn(future(new CreateVhostUserIfReply())); - - customizer.writeCurrentAttributes(ID, vhostUser, writeContext); - verifyCreateVhostUserIfWasInvoked(vhostUser); - verify(mappingContext).put(eq(mappingIid(IFACE_NAME, "test-instance")), eq( - mapping(IFACE_NAME, 0).get())); - } - - @Test - public void testWriteCurrentAttributesFailed() throws Exception { - final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName"); - - doReturn(failedFuture()).when(api).createVhostUserIf(any(CreateVhostUserIf.class)); - - try { - customizer.writeCurrentAttributes(ID, vhostUser, writeContext); - } catch (WriteFailedException.CreateFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyCreateVhostUserIfWasInvoked(vhostUser); - verifyZeroInteractions(mappingContext); - return; - } - fail("WriteFailedException.CreateFailedException was expected"); - } - - @Test - public void testUpdateCurrentAttributes() throws Exception { - final VhostUser vhostUserBefore = generateVhostUser(VhostUserRole.Client, "socketName0"); - final VhostUser vhostUserAfter = generateVhostUser(VhostUserRole.Server, "socketName1"); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); - - when(api.modifyVhostUserIf(any(ModifyVhostUserIf.class))).thenReturn(future(new ModifyVhostUserIfReply())); - - customizer.updateCurrentAttributes(ID, vhostUserBefore, vhostUserAfter, writeContext); - verifyModifyVhostUserIfWasInvoked(vhostUserAfter, IFACE_ID); - } - - @Test - public void testUpdateCurrentAttributesFailed() throws Exception { - final VhostUser vhostUserBefore = generateVhostUser(VhostUserRole.Client, "socketName0"); - final VhostUser vhostUserAfter = generateVhostUser(VhostUserRole.Server, "socketName1"); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); - - doReturn(failedFuture()).when(api).modifyVhostUserIf(any(ModifyVhostUserIf.class)); - - try { - customizer.updateCurrentAttributes(ID, vhostUserBefore, vhostUserAfter, writeContext); - } catch (WriteFailedException.UpdateFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyModifyVhostUserIfWasInvoked(vhostUserAfter, IFACE_ID); - return; - } - fail("WriteFailedException.UpdateFailedException was expected"); - } - - @Test - public void testDeleteCurrentAttributes() throws Exception { - final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName"); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); - - when(api.deleteVhostUserIf(any(DeleteVhostUserIf.class))).thenReturn(future(new DeleteVhostUserIfReply())); - - customizer.deleteCurrentAttributes(ID, vhostUser, writeContext); - verifyDeleteVhostUserIfWasInvoked(IFACE_ID); - verify(mappingContext).delete(eq(mappingIid(IFACE_NAME, "test-instance"))); - } - - @Test - public void testDeleteCurrentAttributesFailed() throws Exception { - final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName"); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); - - doReturn(failedFuture()).when(api).deleteVhostUserIf(any(DeleteVhostUserIf.class)); - - try { - customizer.deleteCurrentAttributes(ID, vhostUser, writeContext); - } catch (WriteFailedException.DeleteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyDeleteVhostUserIfWasInvoked(IFACE_ID); - // Delete from context not invoked if delete from VPP failed - verify(mappingContext, times(0)).delete(eq(mappingIid(IFACE_NAME, "test-instance"))); - verify(mappingContext).read(eq(mappingIid(IFACE_NAME, "test-instance"))); - return; - } - fail("WriteFailedException.DeleteFailedException was expected"); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VhostUserValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VhostUserValidatorTest.java deleted file mode 100644 index eb8541270..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VhostUserValidatorTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.WriteContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUserRole; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUser; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class VhostUserValidatorTest { - - private VhostUserValidator validator; - - @Mock - private WriteContext writeContext; - - private static final String SOCKET = "testSocket"; - private static final String IFACE_NAME = "eth0"; - private static final InstanceIdentifier ID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(VppInterfaceAugmentation.class).child(VhostUser.class); - - @Before - public void setUp() { - initMocks(this); - NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); - validator = new VhostUserValidator(ifcContext); - } - - @Test - public void testWriteSuccessful() throws DataValidationFailedException.CreateValidationFailedException { - validator.validateWrite(ID, getVhostUser(SOCKET), writeContext); - } - - @Test(expected = NullPointerException.class) - public void testWriteFailedNoSocket() throws DataValidationFailedException.CreateValidationFailedException { - validator.validateWrite(ID, getVhostUser(null), writeContext); - } - - @Test - public void testUpdateSuccessful() throws DataValidationFailedException.UpdateValidationFailedException { - validator.validateUpdate(ID, getVhostUser(SOCKET), - getVhostUser(SOCKET), writeContext); - } - - @Test - public void testDeleteeSuccessful() throws DataValidationFailedException.DeleteValidationFailedException { - validator.validateDelete(ID, getVhostUser(SOCKET), writeContext); - } - - private VhostUser getVhostUser(final String socketName) { - return VhostUserCustomizerTest.generateVhostUser(VhostUserRole.Client, socketName); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VxlanCustomizerTest.java deleted file mode 100644 index f04fd1422..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VxlanCustomizerTest.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.DisabledInterfacesManager; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.VppBaseCallException; -import io.fd.jvpp.VppInvocationException; -import io.fd.jvpp.core.dto.VxlanAddDelTunnel; -import io.fd.jvpp.core.dto.VxlanAddDelTunnelReply; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.L2Input; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanVni; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Vxlan; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class VxlanCustomizerTest extends WriterCustomizerTest implements AddressTranslator { - - private static final byte ADD_VXLAN = 1; - private static final byte DEL_VXLAN = 0; - - @Mock - private DisabledInterfacesManager disableContext; - - private VxlanCustomizer customizer; - private String ifaceName; - private InstanceIdentifier id; - - private static Vxlan generateVxlan(long vni) { - final VxlanBuilder builder = new VxlanBuilder(); - builder.setSrc(new IpAddressNoZone(new Ipv4AddressNoZone("192.168.20.10"))); - builder.setDst(new IpAddressNoZone(new Ipv4AddressNoZone("192.168.20.11"))); - builder.setEncapVrfId(new VniReference(123L)); - builder.setVni(new VxlanVni(Long.valueOf(vni))); - builder.setDecapNext(L2Input.class); - return builder.build(); - } - - private static Vxlan generateVxlan() { - return generateVxlan(Long.valueOf(11)); - } - - @Override - public void setUpTest() throws Exception { - InterfaceTypeTestUtils.setupWriteContext(writeContext, - org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanTunnel.class); - - customizer = - new VxlanCustomizer(api, new NamingContext("generateInterfaceNAme", "test-instance"), disableContext); - - ifaceName = "eth0"; - id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(ifaceName)) - .augmentation(VppInterfaceAugmentation.class).child(Vxlan.class); - } - - private void whenVxlanAddDelTunnelThenSuccess() { - when(api.vxlanAddDelTunnel(any(VxlanAddDelTunnel.class))).thenReturn(future(new VxlanAddDelTunnelReply())); - } - - private void whenVxlanAddDelTunnelThenFailure() { - doReturn(failedFuture()).when(api).vxlanAddDelTunnel(any(VxlanAddDelTunnel.class)); - } - - private VxlanAddDelTunnel verifyVxlanAddDelTunnelWasInvoked(final Vxlan vxlan) throws VppInvocationException { - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(VxlanAddDelTunnel.class); - verify(api).vxlanAddDelTunnel(argumentCaptor.capture()); - final VxlanAddDelTunnel actual = argumentCaptor.getValue(); - assertEquals(0, actual.isIpv6); - assertEquals(1, actual.decapNextIndex); - - assertArrayEquals(ipAddressToArray(vxlan.getSrc()), actual.srcAddress); - assertArrayEquals(ipAddressToArray(vxlan.getDst()), actual.dstAddress); - assertEquals(vxlan.getEncapVrfId().getValue().intValue(), actual.encapVrfId); - assertEquals(vxlan.getVni().getValue().intValue(), actual.vni); - return actual; - } - - private void verifyVxlanAddWasInvoked(final Vxlan vxlan) throws VppInvocationException { - final VxlanAddDelTunnel actual = verifyVxlanAddDelTunnelWasInvoked(vxlan); - assertEquals(ADD_VXLAN, actual.isAdd); - } - - private void verifyVxlanDeleteWasInvoked(final Vxlan vxlan) throws VppInvocationException { - final VxlanAddDelTunnel actual = verifyVxlanAddDelTunnelWasInvoked(vxlan); - assertEquals(DEL_VXLAN, actual.isAdd); - } - - @Test - public void testWriteCurrentAttributes() throws Exception { - final Vxlan vxlan = generateVxlan(); - - whenVxlanAddDelTunnelThenSuccess(); - noMappingDefined(mappingContext, ifaceName, "test-instance"); - - customizer.writeCurrentAttributes(id, vxlan, writeContext); - verifyVxlanAddWasInvoked(vxlan); - verify(mappingContext).put(eq(mappingIid(ifaceName, "test-instance")), eq(mapping(ifaceName, 0).get())); - } - - @Test - public void testWriteCurrentAttributesWithExistingVxlanPlaceholder() throws Exception { - final Vxlan vxlan = generateVxlan(); - - whenVxlanAddDelTunnelThenSuccess(); - noMappingDefined(mappingContext, ifaceName, "test-instance"); - doReturn(true).when(disableContext).isInterfaceDisabled(0, mappingContext); - - customizer.writeCurrentAttributes(id, vxlan, writeContext); - verifyVxlanAddWasInvoked(vxlan); - verify(mappingContext).put(eq(mappingIid(ifaceName, "test-instance")), eq(mapping(ifaceName, 0).get())); - verify(disableContext).removeDisabledInterface(0, mappingContext); - } - - @Test - public void testWriteCurrentAttributesMappingAlreadyPresent() throws Exception { - final Vxlan vxlan = generateVxlan(); - final int ifaceId = 0; - - whenVxlanAddDelTunnelThenSuccess(); - defineMapping(mappingContext, ifaceName, ifaceId, "test-instance"); - - customizer.writeCurrentAttributes(id, vxlan, writeContext); - verifyVxlanAddWasInvoked(vxlan); - - // Remove the first mapping before putting in the new one - verify(mappingContext).delete(eq(mappingIid(ifaceName, "test-instance"))); - verify(mappingContext) - .put(eq(mappingIid(ifaceName, "test-instance")), eq(mapping(ifaceName, ifaceId).get())); - } - - @Test - public void testWriteCurrentAttributesFailed() throws Exception { - final Vxlan vxlan = generateVxlan(); - - whenVxlanAddDelTunnelThenFailure(); - - try { - customizer.writeCurrentAttributes(id, vxlan, writeContext); - } catch (WriteFailedException.CreateFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyVxlanAddWasInvoked(vxlan); - // Mapping not stored due to failure - verify(mappingContext, times(0)) - .put(eq(mappingIid(ifaceName, "test-instance")), eq(mapping(ifaceName, 0).get())); - return; - } - fail("WriteFailedException.CreateFailedException was expected"); - } - - @Test(expected = UnsupportedOperationException.class) - public void testUpdateCurrentAttributes() throws Exception { - customizer.updateCurrentAttributes(id, generateVxlan(10), generateVxlan(11), writeContext); - } - - @Test - public void testDeleteCurrentAttributes() throws Exception { - final Vxlan vxlan = generateVxlan(); - - whenVxlanAddDelTunnelThenSuccess(); - defineMapping(mappingContext, ifaceName, 1, "test-instance"); - - customizer.deleteCurrentAttributes(id, vxlan, writeContext); - verifyVxlanDeleteWasInvoked(vxlan); - verify(mappingContext).delete(eq(mappingIid(ifaceName, "test-instance"))); - verify(disableContext).disableInterface(1, mappingContext); - } - - @Test - public void testDeleteCurrentAttributesaFailed() throws Exception { - final Vxlan vxlan = generateVxlan(); - - whenVxlanAddDelTunnelThenFailure(); - defineMapping(mappingContext, ifaceName, 1, "test-instance"); - - try { - customizer.deleteCurrentAttributes(id, vxlan, writeContext); - } catch (WriteFailedException.DeleteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyVxlanDeleteWasInvoked(vxlan); - verify(mappingContext, times(0)).delete(eq(mappingIid(ifaceName, "test-instance"))); - return; - } - fail("WriteFailedException.DeleteFailedException was expected"); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeCustomizerTest.java deleted file mode 100644 index 39a3d22b4..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeCustomizerTest.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.DisabledInterfacesManager; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.VppBaseCallException; -import io.fd.jvpp.core.dto.VxlanGpeAddDelTunnel; -import io.fd.jvpp.core.dto.VxlanGpeAddDelTunnelReply; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeNextProtocol; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeVni; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpe; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpeBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class VxlanGpeCustomizerTest extends WriterCustomizerTest implements AddressTranslator { - - private static final byte ADD_VXLAN_GPE = 1; - private static final byte DEL_VXLAN_GPE = 0; - - @Mock - private DisabledInterfacesManager interfaceDisableContext; - - private VxlanGpeCustomizer customizer; - private String ifaceName; - private InstanceIdentifier id; - - private static VxlanGpe generateVxlanGpe(long vni) { - final VxlanGpeBuilder builder = new VxlanGpeBuilder(); - builder.setLocal(new IpAddressNoZone(new Ipv4AddressNoZone("192.168.20.10"))); - builder.setRemote(new IpAddressNoZone(new Ipv4AddressNoZone("192.168.20.11"))); - builder.setVni(new VxlanGpeVni(Long.valueOf(vni))); - builder.setNextProtocol(VxlanGpeNextProtocol.forValue(1)); - builder.setEncapVrfId(Long.valueOf(123)); - builder.setDecapVrfId(Long.valueOf(456)); - return builder.build(); - } - - private static VxlanGpe generateVxlanGpe() { - return generateVxlanGpe(Long.valueOf(11)); - } - - @Override - public void setUpTest() throws Exception { - InterfaceTypeTestUtils.setupWriteContext(writeContext, - org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeTunnel.class); - NamingContext namingContext = new NamingContext("generateInterfaceName", "test-instance"); - customizer = new VxlanGpeCustomizer(api, namingContext, interfaceDisableContext); - - ifaceName = "elth0"; - id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(ifaceName)) - .augmentation(VppInterfaceAugmentation.class).child(VxlanGpe.class); - } - - private void whenVxlanGpeAddDelTunnelThenSuccess() { - when(api.vxlanGpeAddDelTunnel(any(VxlanGpeAddDelTunnel.class))) - .thenReturn(future(new VxlanGpeAddDelTunnelReply())); - } - - private void whenVxlanGpeAddDelTunnelThenFailure() { - doReturn(failedFuture()).when(api).vxlanGpeAddDelTunnel(any(VxlanGpeAddDelTunnel.class)); - } - - private VxlanGpeAddDelTunnel verifyVxlanGpeAddDelTunnelWasInvoked(final VxlanGpe vxlanGpe) - throws VppBaseCallException { - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(VxlanGpeAddDelTunnel.class); - verify(api).vxlanGpeAddDelTunnel(argumentCaptor.capture()); - final VxlanGpeAddDelTunnel actual = argumentCaptor.getValue(); - assertEquals(0, actual.isIpv6); - assertArrayEquals(ipAddressToArray(vxlanGpe.getLocal()), actual.local); - assertArrayEquals(ipAddressToArray(vxlanGpe.getRemote()), actual.remote); - assertEquals(vxlanGpe.getVni().getValue().intValue(), actual.vni); - assertEquals(vxlanGpe.getNextProtocol().getIntValue(), actual.protocol); - assertEquals(vxlanGpe.getEncapVrfId().intValue(), actual.encapVrfId); - assertEquals(vxlanGpe.getDecapVrfId().intValue(), actual.decapVrfId); - return actual; - } - - private void verifyVxlanGpeAddWasInvoked(final VxlanGpe vxlanGpe) throws VppBaseCallException { - final VxlanGpeAddDelTunnel actual = verifyVxlanGpeAddDelTunnelWasInvoked(vxlanGpe); - assertEquals(ADD_VXLAN_GPE, actual.isAdd); - } - - private void verifyVxlanGpeDeleteWasInvoked(final VxlanGpe vxlanGpe) throws VppBaseCallException { - final VxlanGpeAddDelTunnel actual = verifyVxlanGpeAddDelTunnelWasInvoked(vxlanGpe); - assertEquals(DEL_VXLAN_GPE, actual.isAdd); - } - - @Test - public void testWriteCurrentAttributes() throws Exception { - final VxlanGpe vxlanGpe = generateVxlanGpe(); - - whenVxlanGpeAddDelTunnelThenSuccess(); - noMappingDefined(mappingContext, ifaceName, "test-instance"); - - customizer.writeCurrentAttributes(id, vxlanGpe, writeContext); - verifyVxlanGpeAddWasInvoked(vxlanGpe); - verify(mappingContext).put(eq(mappingIid(ifaceName, "test-instance")), eq( - mapping(ifaceName, 0).get())); - } - - @Test - public void testWriteCurrentAttributesMappingAlreadyPresent() throws Exception { - final VxlanGpe vxlanGpe = generateVxlanGpe(); - final int ifaceId = 0; - - whenVxlanGpeAddDelTunnelThenSuccess(); - defineMapping(mappingContext, ifaceName, ifaceId, "test-instance"); - - customizer.writeCurrentAttributes(id, vxlanGpe, writeContext); - verifyVxlanGpeAddWasInvoked(vxlanGpe); - - // Remove the first mapping before putting in the new one - verify(mappingContext).delete(eq(mappingIid(ifaceName, "test-instance"))); - verify(mappingContext).put(eq(mappingIid(ifaceName, "test-instance")), - eq(mapping(ifaceName, ifaceId).get())); - } - - @Test - public void testWriteCurrentAttributesFailed() throws Exception { - final VxlanGpe vxlanGpe = generateVxlanGpe(); - - whenVxlanGpeAddDelTunnelThenFailure(); - - try { - customizer.writeCurrentAttributes(id, vxlanGpe, writeContext); - } catch (WriteFailedException.CreateFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyVxlanGpeAddWasInvoked(vxlanGpe); - // Mapping not stored due to failure - verify(mappingContext, times(0)) - .put(eq(mappingIid(ifaceName, "test-instance")), eq( - mapping(ifaceName, 0).get())); - return; - } - fail("WriteFailedException.CreateFailedException was expected"); - } - - @Test(expected = UnsupportedOperationException.class) - public void testUpdateCurrentAttributes() throws Exception { - customizer.updateCurrentAttributes(id, generateVxlanGpe(10), generateVxlanGpe(11), writeContext); - } - - @Test - public void testDeleteCurrentAttributes() throws Exception { - final VxlanGpe vxlanGpe = generateVxlanGpe(); - - whenVxlanGpeAddDelTunnelThenSuccess(); - defineMapping(mappingContext, ifaceName, 1, "test-instance"); - - customizer.deleteCurrentAttributes(id, vxlanGpe, writeContext); - verifyVxlanGpeDeleteWasInvoked(vxlanGpe); - verify(mappingContext).delete(eq(mappingIid(ifaceName, "test-instance"))); - } - - @Test - public void testDeleteCurrentAttributesaFailed() throws Exception { - final VxlanGpe vxlanGpe = generateVxlanGpe(); - - whenVxlanGpeAddDelTunnelThenFailure(); - defineMapping(mappingContext, ifaceName, 1, "test-instance"); - - try { - customizer.deleteCurrentAttributes(id, vxlanGpe, writeContext); - } catch (WriteFailedException.DeleteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyVxlanGpeDeleteWasInvoked(vxlanGpe); - verify(mappingContext, times(0)).delete(eq(mappingIid(ifaceName, "test-instance"))); - return; - } - fail("WriteFailedException.DeleteFailedException was expected"); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeValidatorTest.java deleted file mode 100644 index c4955d881..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VxlanGpeValidatorTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.DisabledInterfacesManager; -import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; -import io.fd.honeycomb.translate.write.WriteContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeNextProtocol; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeVni; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpe; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpeBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class VxlanGpeValidatorTest { - - private VxlanGpeValidator validator; - - @Mock - private WriteContext writeContext; - @Mock - private DisabledInterfacesManager interfaceDisableContext; - - private static final String IPV6 = "a::100"; - private static final String IPV4_1 = "192.168.20.10"; - private static final String IPV4_2 = "192.168.20.11"; - private static final Long VNI = Long.valueOf(11); - private static final Long ENCAP = Long.valueOf(123); - private static final Long DECAP = Long.valueOf(321); - private static final String IFACE_NAME = "eth0"; - private static final InstanceIdentifier ID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(VppInterfaceAugmentation.class).child(VxlanGpe.class); - - @Before - public void setUp() { - initMocks(this); - NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); - validator = new VxlanGpeValidator(ifcContext, interfaceDisableContext); - } - - @Test - public void testWriteSuccessful() throws CreateValidationFailedException { - validator.validateWrite(ID, generateVxlanCorrect(), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedMixedIpFamilies() throws CreateValidationFailedException { - validator.validateWrite(ID, generateVxlanMixedIpFamilies(), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoLocal() throws CreateValidationFailedException { - validator.validateWrite(ID, generateVxlanSetFields(false, true, true, true, true, true), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoRemote() throws CreateValidationFailedException { - validator.validateWrite(ID, generateVxlanSetFields(true, false, true, true, true, true), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoEncapVrfId() throws CreateValidationFailedException { - validator.validateWrite(ID, generateVxlanSetFields(true, true, false, true, true, true), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoDecapVrfId() throws CreateValidationFailedException { - validator.validateWrite(ID, generateVxlanSetFields(true, true, true, false, true, true), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoVNI() throws CreateValidationFailedException { - validator.validateWrite(ID, generateVxlanSetFields(true, true, true, true, false, true), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoNextProtocol() throws CreateValidationFailedException { - validator.validateWrite(ID, generateVxlanSetFields(true, true, true, true, true, false), writeContext); - } - - @Test - public void testDeleteSuccessful() throws DeleteValidationFailedException { - validator.validateDelete(ID, generateVxlanCorrect(), writeContext); - } - - private VxlanGpe generateVxlanSetFields(final boolean src, final boolean dst, final boolean encapVrfId, - final boolean decapVrfId, final boolean vni, final boolean protocol) { - final VxlanGpeBuilder builder = new VxlanGpeBuilder(); - builder.setLocal(src - ? new IpAddressNoZone(new Ipv4AddressNoZone(IPV4_1)) - : null); - builder.setRemote(dst - ? new IpAddressNoZone(new Ipv4AddressNoZone(IPV4_2)) - : null); - builder.setEncapVrfId(encapVrfId - ? ENCAP - : null); - builder.setDecapVrfId(decapVrfId - ? DECAP - : null); - builder.setVni(vni - ? new VxlanGpeVni(VNI) - : null); - builder.setNextProtocol(protocol - ? VxlanGpeNextProtocol.forValue(1) - : null); - return builder.build(); - } - - private VxlanGpe generateVxlanCorrect() { - return generateVxlanSetFields(true, true, true, true, true, true); - } - - private VxlanGpe generateVxlanMixedIpFamilies() { - return new VxlanGpeBuilder() - .setLocal(new IpAddressNoZone(new Ipv6AddressNoZone(IPV6))) - .setRemote(new IpAddressNoZone(new Ipv4AddressNoZone(IPV4_1))) - .setEncapVrfId(ENCAP).setDecapVrfId(DECAP) - .setVni(new VxlanGpeVni(VNI)) - .setNextProtocol(VxlanGpeNextProtocol.forValue(1)) - .build(); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VxlanValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VxlanValidatorTest.java deleted file mode 100644 index 587b9f313..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/VxlanValidatorTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.DisabledInterfacesManager; -import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; -import io.fd.honeycomb.translate.write.WriteContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.L2Input; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanVni; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Vxlan; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class VxlanValidatorTest { - - private VxlanValidator validator; - - @Mock - private WriteContext writeContext; - @Mock - private DisabledInterfacesManager interfaceDisableContext; - - private static final String IPV6 = "a::100"; - private static final String IPV4_1 = "192.168.20.10"; - private static final String IPV4_2 = "192.168.20.11"; - private static final Long VNI = Long.valueOf(11); - private static final Long ENCAP = Long.valueOf(123); - private static final String IFACE_NAME = "eth0"; - private static final InstanceIdentifier ID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(VppInterfaceAugmentation.class).child(Vxlan.class); - - @Before - public void setUp() { - initMocks(this); - NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); - validator = new VxlanValidator(ifcContext, interfaceDisableContext); - } - - @Test - public void testWriteSuccessful() throws CreateValidationFailedException { - validator.validateWrite(ID, generateVxlanCorrect(), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedMixedIpFamilies() throws CreateValidationFailedException { - validator.validateWrite(ID, generateVxlanMixedIpFamilies(), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoSrc() throws CreateValidationFailedException { - validator.validateWrite(ID, generateVxlanSetFields(false, true, true, true), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoDst() throws CreateValidationFailedException { - validator.validateWrite(ID, generateVxlanSetFields(true, false, true, true), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoEncap() throws CreateValidationFailedException { - validator.validateWrite(ID, generateVxlanSetFields(true, true, false, true), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedNoVNI() throws CreateValidationFailedException { - validator.validateWrite(ID, generateVxlanSetFields(true, true, true, false), writeContext); - } - - @Test - public void testDeleteSuccessful() throws DeleteValidationFailedException { - validator.validateDelete(ID, generateVxlanCorrect(), writeContext); - } - - private Vxlan generateVxlan(final IpAddressNoZone src, final IpAddressNoZone dst, final VniReference encapVrfId, - final long vni) { - final VxlanBuilder builder = new VxlanBuilder(); - builder.setSrc(src); - builder.setDst(dst); - builder.setEncapVrfId(encapVrfId); - builder.setVni(new VxlanVni(vni)); - builder.setDecapNext(L2Input.class); - return builder.build(); - } - - private Vxlan generateVxlanSetFields(final boolean src, final boolean dst, final boolean encapVrfId, - final boolean vni) { - final VxlanBuilder builder = new VxlanBuilder(); - builder.setSrc(src - ? new IpAddressNoZone(new Ipv4AddressNoZone(IPV4_1)) - : null); - builder.setDst(dst - ? new IpAddressNoZone(new Ipv4AddressNoZone(IPV4_2)) - : null); - builder.setEncapVrfId(encapVrfId - ? new VniReference(ENCAP) - : null); - builder.setVni(vni - ? new VxlanVni(VNI) - : null); - builder.setDecapNext(L2Input.class); - return builder.build(); - } - - private Vxlan generateVxlanCorrect() { - return generateVxlanSetFields(true, true, true, true); - } - - private Vxlan generateVxlanMixedIpFamilies() { - return generateVxlan(new IpAddressNoZone(new Ipv6AddressNoZone(IPV6)), - new IpAddressNoZone(new Ipv4AddressNoZone(IPV4_2)), new VniReference(ENCAP), VNI); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteCustomizerTest.java deleted file mode 100644 index 206a5a086..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteCustomizerTest.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces.pbb; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.jvpp.VppCallbackException; -import io.fd.jvpp.core.dto.L2InterfacePbbTagRewrite; -import io.fd.jvpp.core.dto.L2InterfacePbbTagRewriteReply; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.pbb.types.rev161214.Operation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.PbbRewriteInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewrite; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class PbbRewriteCustomizerTest extends WriterCustomizerTest { - - @Captor - private ArgumentCaptor rewriteArgumentCaptor; - - private NamingContext interfaceContext; - private PbbRewriteCustomizer customizer; - private InstanceIdentifier validId; - private InstanceIdentifier invalidId; - - @Override - protected void setUpTest() throws Exception { - interfaceContext = new NamingContext("interface", "interface-context"); - customizer = new PbbRewriteCustomizer(api, interfaceContext); - - defineMapping(mappingContext, "pbb-interface", 1, "interface-context"); - validId = InstanceIdentifier.create(Interfaces.class) - .child(Interface.class, new InterfaceKey("pbb-interface")) - .augmentation(PbbRewriteInterfaceAugmentation.class) - .child(PbbRewrite.class); - - invalidId = InstanceIdentifier.create(PbbRewrite.class); - } - - @Test - public void testWrite() throws WriteFailedException { - whenRewriteThenSuccess(); - customizer.writeCurrentAttributes(validId, PbbRewriteValidatorTest.validData(), writeContext); - verifyRewriteRequest(desiredSetResult()); - } - - @Test - public void testWriteFailedCallFailed() { - whenRewriteThenFail(); - final PbbRewrite validData = PbbRewriteValidatorTest.validData(); - try { - customizer.writeCurrentAttributes(validId, validData, writeContext); - } catch (Exception e) { - assertTrue(e instanceof WriteFailedException.CreateFailedException); - assertTrue(e.getCause() instanceof VppCallbackException); - - final WriteFailedException.CreateFailedException ex = ((WriteFailedException.CreateFailedException) e); - assertEquals(validId, ex.getFailedId()); - assertEquals(validData, ex.getData()); - return; - } - - fail("Test should have failed"); - } - - @Test - public void testUpdate() throws WriteFailedException { - whenRewriteThenSuccess(); - final PbbRewrite rewrite = PbbRewriteValidatorTest.validData(); - customizer.updateCurrentAttributes(validId, rewrite, rewrite, writeContext); - verifyRewriteRequest(desiredSetResult()); - } - - @Test - public void testUpdateFailedCallFailed() { - whenRewriteThenFail(); - final PbbRewrite invalidData = PbbRewriteValidatorTest.invalidDataNoVlan(); - final PbbRewrite validData = PbbRewriteValidatorTest.validData(); - try { - customizer.updateCurrentAttributes(validId, invalidData, validData, writeContext); - } catch (Exception e) { - assertTrue(e instanceof WriteFailedException.UpdateFailedException); - assertTrue(e.getCause() instanceof VppCallbackException); - - final WriteFailedException.UpdateFailedException ex = ((WriteFailedException.UpdateFailedException) e); - assertEquals(validId, ex.getFailedId()); - assertEquals(invalidData, ex.getDataBefore()); - assertEquals(validData, ex.getDataAfter()); - return; - } - - fail("Test should have failed"); - } - - @Test - public void testDelete() throws WriteFailedException { - whenRewriteThenSuccess(); - customizer.deleteCurrentAttributes(validId, PbbRewriteValidatorTest.validData(), writeContext); - verifyRewriteRequest(desiredDisableResult()); - } - - @Test - public void testDeleteFailedCallFailed() { - whenRewriteThenFail(); - final PbbRewrite validData = PbbRewriteValidatorTest.validData(); - try { - customizer.deleteCurrentAttributes(validId, validData, writeContext); - } catch (Exception e) { - assertTrue(e instanceof WriteFailedException.DeleteFailedException); - assertTrue(e.getCause() instanceof VppCallbackException); - assertEquals(validId, ((WriteFailedException.DeleteFailedException) e).getFailedId()); - return; - } - - fail("Test should have failed"); - } - - private void whenRewriteThenSuccess() { - when(api.l2InterfacePbbTagRewrite(any())).thenReturn(future(new L2InterfacePbbTagRewriteReply())); - } - - private void whenRewriteThenFail() { - when(api.l2InterfacePbbTagRewrite(any())).thenReturn(failedFuture()); - } - - private L2InterfacePbbTagRewrite desiredSetResult() { - final L2InterfacePbbTagRewrite desiredResult = new L2InterfacePbbTagRewrite(); - desiredResult.swIfIndex = 1; - desiredResult.vtrOp = Operation.Pop2.getIntValue(); - desiredResult.bDmac = new byte[]{-69, -69, -69, -69, -69, -69}; - desiredResult.bSmac = new byte[]{-86, -86, -86, -86, -86, -86}; - desiredResult.bVlanid = 1234; - desiredResult.iSid = 2; - - return desiredResult; - } - - private L2InterfacePbbTagRewrite desiredDisableResult() { - final L2InterfacePbbTagRewrite desiredResult = new L2InterfacePbbTagRewrite(); - desiredResult.swIfIndex = 1; - desiredResult.vtrOp = 0; - desiredResult.bDmac = new byte[]{-69, -69, -69, -69, -69, -69}; - desiredResult.bSmac = new byte[]{-86, -86, -86, -86, -86, -86}; - desiredResult.bVlanid = 1234; - desiredResult.iSid = 2; - - return desiredResult; - } - - private void verifyRewriteRequest(final L2InterfacePbbTagRewrite desiredResult) { - verify(api, times(1)).l2InterfacePbbTagRewrite(rewriteArgumentCaptor.capture()); - - final L2InterfacePbbTagRewrite actualRequest = rewriteArgumentCaptor.getValue(); - - assertNotNull(actualRequest); - assertEquals(actualRequest.bVlanid, desiredResult.bVlanid); - assertEquals(actualRequest.iSid, desiredResult.iSid); - assertEquals(actualRequest.vtrOp, desiredResult.vtrOp); - assertEquals(actualRequest.outerTag, desiredResult.outerTag); - assertArrayEquals(actualRequest.bDmac, desiredResult.bDmac); - assertArrayEquals(actualRequest.bSmac, desiredResult.bSmac); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteValidatorTest.java deleted file mode 100644 index 114a1bc19..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteValidatorTest.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces.pbb; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; -import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; -import io.fd.honeycomb.translate.write.WriteContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.pbb.types.rev161214.Operation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.PbbRewriteInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewrite; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewriteBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class PbbRewriteValidatorTest { - - private PbbRewriteValidator validator; - private InstanceIdentifier validId; - private InstanceIdentifier invalidId; - - @Mock - private WriteContext writeContext; - - @Before - public void setUp() { - initMocks(this); - NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); - validator = new PbbRewriteValidator(ifcContext); - validId = InstanceIdentifier.create(Interfaces.class) - .child(Interface.class, new InterfaceKey("pbb-interface")) - .augmentation(PbbRewriteInterfaceAugmentation.class) - .child(PbbRewrite.class); - - invalidId = InstanceIdentifier.create(PbbRewrite.class); - } - - @Test - public void testWriteSuccessful() - throws CreateValidationFailedException { - validator.validateWrite(validId, validData(), writeContext); - } - - @Test(expected = CreateValidationFailedException.class) - public void testWriteFailedInvalidIID() - throws CreateValidationFailedException { - validator.validateWrite(invalidId, validData(), writeContext); - } - - @Test - public void testWriteFailedInvalidData() { - verifyInvalidWriteDataCombination(invalidDataNoDestination()); - verifyInvalidWriteDataCombination(invalidDataNoSource()); - verifyInvalidWriteDataCombination(invalidDataNoItag()); - verifyInvalidWriteDataCombination(invalidDataNoOperation()); - verifyInvalidWriteDataCombination(invalidDataNoVlan()); - } - - @Test - public void testUpdateFailedInvalidData() { - verifyInvalidUpdateDataCombination(invalidDataNoDestination()); - verifyInvalidUpdateDataCombination(invalidDataNoSource()); - verifyInvalidUpdateDataCombination(invalidDataNoItag()); - verifyInvalidUpdateDataCombination(invalidDataNoOperation()); - verifyInvalidUpdateDataCombination(invalidDataNoVlan()); - } - - @Test - public void testDeleteFailedInvalidData() { - verifyInvalidDeleteDataCombination(invalidDataNoDestination()); - verifyInvalidDeleteDataCombination(invalidDataNoSource()); - verifyInvalidDeleteDataCombination(invalidDataNoItag()); - verifyInvalidDeleteDataCombination(invalidDataNoOperation()); - verifyInvalidDeleteDataCombination(invalidDataNoVlan()); - } - - private void verifyInvalidWriteDataCombination(final PbbRewrite invalidData) { - try { - validator.validateWrite(validId, invalidData, writeContext); - } catch (Exception e) { - assertTrue(e instanceof CreateValidationFailedException); - return; - } - - fail("Verifying of invalid combination failed"); - } - - private void verifyInvalidUpdateDataCombination(final PbbRewrite invalidData) { - try { - validator.validateUpdate(validId, validData(), invalidData, writeContext); - } catch (Exception e) { - assertTrue(e instanceof UpdateValidationFailedException); - return; - } - - fail("Verifying of invalid combination failed"); - } - - private void verifyInvalidDeleteDataCombination(final PbbRewrite invalidData) { - try { - validator.validateDelete(validId, invalidData, writeContext); - } catch (Exception e) { - assertTrue(e instanceof DeleteValidationFailedException); - return; - } - - fail("Verifying of invalid combination failed"); - } - - static PbbRewrite invalidDataNoDestination() { - return new PbbRewriteBuilder() - .setBVlanTagVlanId(1234) - .setITagIsid(2L) - .setSourceAddress(new MacAddress("aa:aa:aa:aa:aa:aa")) - .setInterfaceOperation(Operation.Pop2) - .build(); - } - - static PbbRewrite invalidDataNoSource() { - return new PbbRewriteBuilder() - .setBVlanTagVlanId(1234) - .setITagIsid(2L) - .setDestinationAddress(new MacAddress("bb:bb:bb:bb:bb:bb")) - .setInterfaceOperation(Operation.Pop2) - .build(); - } - - static PbbRewrite invalidDataNoItag() { - return new PbbRewriteBuilder() - .setBVlanTagVlanId(1234) - .setSourceAddress(new MacAddress("aa:aa:aa:aa:aa:aa")) - .setDestinationAddress(new MacAddress("bb:bb:bb:bb:bb:bb")) - .setInterfaceOperation(Operation.Pop2) - .build(); - } - - static PbbRewrite invalidDataNoVlan() { - return new PbbRewriteBuilder() - .setITagIsid(2L) - .setSourceAddress(new MacAddress("aa:aa:aa:aa:aa:aa")) - .setDestinationAddress(new MacAddress("bb:bb:bb:bb:bb:bb")) - .setInterfaceOperation(Operation.Pop2) - .build(); - } - - static PbbRewrite invalidDataNoOperation() { - return new PbbRewriteBuilder() - .setITagIsid(2L) - .setSourceAddress(new MacAddress("aa:aa:aa:aa:aa:aa")) - .setDestinationAddress(new MacAddress("bb:bb:bb:bb:bb:bb")) - .setInterfaceOperation(Operation.Pop2) - .build(); - } - - static PbbRewrite validData() { - return new PbbRewriteBuilder() - .setBVlanTagVlanId(1234) - .setITagIsid(2L) - .setSourceAddress(new MacAddress("aa:aa:aa:aa:aa:aa")) - .setDestinationAddress(new MacAddress("bb:bb:bb:bb:bb:bb")) - .setInterfaceOperation(Operation.Pop2) - .build(); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfacesCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfacesCustomizerTest.java deleted file mode 100644 index e73106a57..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfacesCustomizerTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces.span; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.jvpp.core.dto.SwInterfaceSpanEnableDisable; -import io.fd.jvpp.core.dto.SwInterfaceSpanEnableDisableReply; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.SpanState; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Span; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class MirroredInterfacesCustomizerTest extends WriterCustomizerTest { - - private static final String IFACE_NAME = "iface"; - private static final int IFACE_INDEX = 3; - private static final String SRC_IFACE_NAME = "src-iface"; - private static final int SRC_IFACE_INDEX = 5; - - private NamingContext interfaceContext; - private MirroredInterfaceCustomizer customizer; - - private InstanceIdentifier validId; - private MirroredInterface validData; - - @Captor - private ArgumentCaptor requestCaptor; - - @Override - public void setUpTest() { - interfaceContext = new NamingContext("iface", "iface-context"); - customizer = - new MirroredInterfaceCustomizer(api, interfaceContext, id -> id.firstKeyOf(Interface.class).getName()); - defineMapping(mappingContext, IFACE_NAME, IFACE_INDEX, "iface-context"); - defineMapping(mappingContext, SRC_IFACE_NAME, SRC_IFACE_INDEX, "iface-context"); - - validId = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(VppInterfaceAugmentation.class).child(Span.class) - .child(MirroredInterfaces.class) - .child(MirroredInterface.class); - - validData = new MirroredInterfaceBuilder() - .setIfaceRef(SRC_IFACE_NAME) - .setState(SpanState.Receive) - .build(); - - when(api.swInterfaceSpanEnableDisable(any())).thenReturn(future(new SwInterfaceSpanEnableDisableReply())); - } - - @Test - public void writeCurrentAttributes() throws Exception { - customizer.writeCurrentAttributes(validId, validData, writeContext); - verify(api, times(1)).swInterfaceSpanEnableDisable(requestCaptor.capture()); - assertCreateRequest(requestCaptor.getValue()); - } - - @Test(expected = UnsupportedOperationException.class) - public void updateCurrentAttributes() throws Exception { - customizer.updateCurrentAttributes(validId, validData, validData, writeContext); - } - - @Test - public void deleteCurrentAttributes() throws Exception { - customizer.deleteCurrentAttributes(validId, validData, writeContext); - verify(api, times(1)).swInterfaceSpanEnableDisable(requestCaptor.capture()); - assertDeleteRequest(requestCaptor.getValue()); - } - - private static void assertCreateRequest(final SwInterfaceSpanEnableDisable createRequest) { - assertNotNull(createRequest); - assertEquals(1, createRequest.state); - assertEquals(IFACE_INDEX, createRequest.swIfIndexTo); - assertEquals(SRC_IFACE_INDEX, createRequest.swIfIndexFrom); - } - - private static void assertDeleteRequest(final SwInterfaceSpanEnableDisable deleteRequest) { - assertNotNull(deleteRequest); - assertEquals(0, deleteRequest.state); - assertEquals(IFACE_INDEX, deleteRequest.swIfIndexTo); - assertEquals(SRC_IFACE_INDEX, deleteRequest.swIfIndexFrom); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfacesValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfacesValidatorTest.java deleted file mode 100644 index e596c130f..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfacesValidatorTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces.span; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.DataValidationFailedException; -import io.fd.honeycomb.translate.write.WriteContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.SpanState; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Span; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class MirroredInterfacesValidatorTest { - - private InstanceIdentifier validId; - private MirroredInterfaceValidator validator; - private static final String IFACE_NAME = "iface"; - private static final String SRC_IFACE_NAME = "src-iface"; - - @Mock - private WriteContext writeContext; - - @Before - public void setUp() { - initMocks(this); - NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); - validator = new MirroredInterfaceValidator(ifcContext, id -> id.firstKeyOf(Interface.class).getName()); - validId = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(VppInterfaceAugmentation.class).child(Span.class) - .child(MirroredInterfaces.class) - .child(MirroredInterface.class); - } - - @Test - public void testWriteSuccessful() - throws DataValidationFailedException.CreateValidationFailedException { - validator.validateWrite(validId, validData(), writeContext); - } - - @Test - public void testWriteFailed() { - validateWritingIncorrectData(incorrectDataNoIfaceRef()); - validateWritingIncorrectData(incorrectDataNoSpanState()); - } - - @Test - public void testUpdateSuccessful() - throws DataValidationFailedException.UpdateValidationFailedException { - validator.validateUpdate(validId, validData(), validData(), writeContext); - } - - @Test - public void testDeleteSuccessful() - throws DataValidationFailedException.DeleteValidationFailedException { - validator.validateDelete(validId, validData(), writeContext); - } - - private void validateWritingIncorrectData(final MirroredInterface data) { - try { - validator.validateWrite(validId, data, writeContext); - } catch (DataValidationFailedException.CreateValidationFailedException e) { - assertTrue(e instanceof DataValidationFailedException.CreateValidationFailedException); - return; - } - fail("Verifying of invalid combination failed"); - } - - private MirroredInterface incorrectDataNoIfaceRef() { - return new MirroredInterfaceBuilder() - .setIfaceRef(null) - .setState(SpanState.Receive) - .build(); - } - - private MirroredInterface incorrectDataNoSpanState() { - return new MirroredInterfaceBuilder() - .setIfaceRef(SRC_IFACE_NAME) - .setState(null) - .build(); - } - - private MirroredInterface validData() { - return new MirroredInterfaceBuilder() - .setIfaceRef(SRC_IFACE_NAME) - .setState(SpanState.Receive) - .build(); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/AfPacketCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/AfPacketCustomizerTest.java deleted file mode 100644 index 66b1f6c75..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/AfPacketCustomizerTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2018 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static io.fd.hc2vpp.v3po.interfacesstate.AfPacketCustomizer.getCfgId; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.read.InitializingReaderCustomizerTest; -import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.core.dto.AfPacketDetails; -import io.fd.jvpp.core.dto.AfPacketDetailsReplyDump; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import java.util.Collections; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.AfPacket; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.AfPacketBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class AfPacketCustomizerTest extends InitializingReaderCustomizerTest - implements InterfaceDumpHelper { - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IF_NAME = "host-veth1"; - private static final int IF_INDEX = 1; - private static final InstanceIdentifier IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(VppInterfaceStateAugmentation.class).child(AfPacket.class); - - private NamingContext interfaceContext; - - @Mock - private InterfaceCacheDumpManager dumpCacheManager; - - public AfPacketCustomizerTest() { - super(AfPacket.class, VppInterfaceStateAugmentationBuilder.class); - } - - @Override - protected void setUp() throws Exception { - interfaceContext = new NamingContext("generatedInterfaceName", IFC_CTX_NAME); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new AfPacketCustomizer(api, interfaceContext, dumpCacheManager); - } - - @Test - public void testRead() throws ReadFailedException { - final AfPacketBuilder builder = mock(AfPacketBuilder.class); - when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)).thenReturn(ifaceDetails()); - when(api.afPacketDump(any())).thenReturn(future(afPacketReplyDump())); - - getCustomizer().readCurrentAttributes(IID, builder, ctx); - - verify(builder).setMac(new PhysAddress("01:02:03:04:05:06")); - } - - @Test - public void testReadFailed() throws ReadFailedException { - final AfPacketBuilder builder = mock(AfPacketBuilder.class); - when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)).thenReturn(null); - - getCustomizer().readCurrentAttributes(IID, builder, ctx); - - verifyZeroInteractions(builder); - } - - @Test - public void testInit() { - final AfPacket operData = new AfPacketBuilder() - .setHostInterfaceName(IF_NAME) - .setMac(new PhysAddress("11:22:33:44:55:66")).build(); - final org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacket - cfgData = - new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacketBuilder() - .setHostInterfaceName(IF_NAME) - .setMac(new PhysAddress("11:22:33:44:55:66")).build(); - invokeInitTest(IID, operData, getCfgId(IID), cfgData); - } - - private SwInterfaceDetails ifaceDetails() { - final SwInterfaceDetails details = new SwInterfaceDetails(); - details.swIfIndex = IF_INDEX; - details.interfaceName = IF_NAME.getBytes(); - details.l2Address = new byte[] {1, 2, 3, 4, 5, 6}; - return details; - } - - private AfPacketDetailsReplyDump afPacketReplyDump() { - final AfPacketDetailsReplyDump reply = new AfPacketDetailsReplyDump(); - final AfPacketDetails details0 = new AfPacketDetails(); - details0.swIfIndex = IF_INDEX; - details0.hostIfName = IF_NAME.getBytes(); - reply.afPacketDetails = Collections.singletonList(details0); - return reply; - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/EthernetCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/EthernetCustomizerTest.java deleted file mode 100644 index cb8ce5413..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/EthernetCustomizerTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.EthernetStateAttributes; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.Ethernet; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.EthernetBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class EthernetCustomizerTest extends ReaderCustomizerTest implements - InterfaceDumpHelper { - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IF_NAME = "local0"; - private static final int IF_INDEX = 1; - private static final InstanceIdentifier IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(VppInterfaceStateAugmentation.class).child(Ethernet.class); - private NamingContext interfaceContext; - - @Mock - private InterfaceCacheDumpManager dumpCacheManager; - - public EthernetCustomizerTest() { - super(Ethernet.class, VppInterfaceStateAugmentationBuilder.class); - } - - @Override - protected void setUp() throws Exception { - interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new EthernetCustomizer(dumpCacheManager); - } - - private void testRead(final int linkDuplex, final EthernetStateAttributes.Duplex duplex) - throws ReadFailedException { - final EthernetBuilder builder = mock(EthernetBuilder.class); - final short mtu = 123; - when(dumpCacheManager.getInterfaceDetail(any(), any(), any())).thenReturn(ifaceDetails(mtu, linkDuplex)); - getCustomizer().readCurrentAttributes(IID, builder, ctx); - verify(builder).setMtu((int) mtu); - verify(builder).setDuplex(duplex); - } - - private SwInterfaceDetails ifaceDetails(final short mtu, final int duplex) { - final SwInterfaceDetails details = new SwInterfaceDetails(); - details.swIfIndex = IF_INDEX; - details.linkMtu = mtu; - details.linkDuplex = (byte) duplex; - return details; - } - - @Test - public void testReadHalfDuplex() throws ReadFailedException { - testRead(1, EthernetStateAttributes.Duplex.Half); - } - - @Test - public void testReadFullDuplex() throws ReadFailedException { - testRead(2, EthernetStateAttributes.Duplex.Full); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizerTest.java deleted file mode 100644 index 969a98c3b..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/GreCustomizerTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -import com.google.common.collect.Lists; -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.VppInvocationException; -import io.fd.jvpp.core.dto.GreTunnelDetails; -import io.fd.jvpp.core.dto.GreTunnelDetailsReplyDump; -import io.fd.jvpp.core.dto.GreTunnelDump; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import io.fd.jvpp.core.types.Address; -import io.fd.jvpp.core.types.GreTunnel; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.Gre; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.GreBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class GreCustomizerTest extends ReaderCustomizerTest implements AddressTranslator { - - private static final String IFACE_NAME = "ifc1"; - private static final int IFACE_ID = 0; - private static final String IFC_CTX_NAME = "ifc-test-instance"; - - private NamingContext interfacesContext; - static final InstanceIdentifier IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(VppInterfaceStateAugmentation.class).child(Gre.class); - - @Mock - private InterfaceCacheDumpManager dumpCacheManager; - - public GreCustomizerTest() { - super(Gre.class, VppInterfaceStateAugmentationBuilder.class); - } - - @Override - public void setUp() throws VppInvocationException, ReadFailedException { - interfacesContext = new NamingContext("gre-tunnel", IFC_CTX_NAME); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - - final SwInterfaceDetails v = new SwInterfaceDetails(); - v.interfaceName = "gre-tunnel4".getBytes(); - - when(dumpCacheManager.getInterfaceDetail(IID, ctx, IFACE_NAME)).thenReturn(v); - - final GreTunnelDetailsReplyDump value = new GreTunnelDetailsReplyDump(); - final GreTunnelDetails greTunnelDetails = new GreTunnelDetails(); - greTunnelDetails.tunnel = new GreTunnel(); - greTunnelDetails.tunnel.isIpv6 = 0; - greTunnelDetails.tunnel.dst = ipv4AddressToAddress(new Ipv4Address("1.2.3.4")); - greTunnelDetails.tunnel.src = ipv4AddressToAddress(new Ipv4Address("1.2.3.5")); - greTunnelDetails.tunnel.outerFibId = 55; - greTunnelDetails.tunnel.swIfIndex = 0; - value.greTunnelDetails = Lists.newArrayList(greTunnelDetails); - - doReturn(future(value)).when(api).greTunnelDump(any(GreTunnelDump.class)); - } - - @Test - public void testReadCurrentAttributes() throws Exception { - final GreBuilder builder = getCustomizer().getBuilder(IID); - getCustomizer().readCurrentAttributes(IID, builder, ctx); - - assertEquals(55, builder.getOuterFibId().intValue()); - - assertNull(builder.getSrc().getIpv6AddressNoZone()); - assertNotNull(builder.getSrc().getIpv4AddressNoZone()); - assertEquals("1.2.3.5", builder.getSrc().getIpv4AddressNoZone().getValue()); - - assertNull(builder.getDst().getIpv6AddressNoZone()); - assertNotNull(builder.getDst().getIpv4AddressNoZone()); - assertEquals("1.2.3.4", builder.getDst().getIpv4AddressNoZone().getValue()); - - verify(api).greTunnelDump(any(GreTunnelDump.class)); - } - - @Test - public void testReadCurrentAttributesWrongType() throws Exception { - final SwInterfaceDetails v = new SwInterfaceDetails(); - v.interfaceName = "tap-2".getBytes(); - - when(dumpCacheManager.getInterfaceDetail(IID, ctx, IFACE_NAME)).thenReturn(v); - - final GreBuilder builder = getCustomizer().getBuilder(IID); - getCustomizer().readCurrentAttributes(IID, builder, ctx); - verifyZeroInteractions(api); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new GreCustomizer(api, interfacesContext, dumpCacheManager); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java deleted file mode 100644 index a3188b426..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceCustomizerTest.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; -import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.DisabledInterfacesManager; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import io.fd.jvpp.core.dto.SwInterfaceDump; -import io.fd.jvpp.core.types.InterfaceIndex; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Stream; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesStateBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceCustomizerTest extends ListReaderCustomizerTest - implements InterfaceDataTranslator, InterfaceDumpHelper { - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IFACE0_NAME = "eth0"; - private static final String IFACE1_NAME = "eth1"; - private static final String SUB_IFACE_NAME = "eth1.1"; - private static final int IFACE0_ID = 0; - private static final int IFACE1_ID = 1; - private static final int SUB_IFACE_ID = 2; - - private NamingContext interfacesContext; - @Mock - private DisabledInterfacesManager interfaceDisableContext; - @Mock - private InterfaceCacheDumpManager dumpCacheManager; - - public InterfaceCustomizerTest() { - super(Interface.class, InterfacesStateBuilder.class); - } - - @Override - public void setUp() { - interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - defineMapping(mappingContext, IFACE0_NAME, IFACE0_ID, IFC_CTX_NAME); - defineMapping(mappingContext, IFACE1_NAME, IFACE1_ID, IFC_CTX_NAME); - defineMapping(mappingContext, SUB_IFACE_NAME, SUB_IFACE_ID, IFC_CTX_NAME); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new InterfaceCustomizer(interfacesContext, interfaceDisableContext, dumpCacheManager); - } - - private void assertIfacesAreEqual(final Interface iface, final SwInterfaceDetails details) { - assertEquals(iface.getName(), new String(details.interfaceName)); - assertEquals(yangIfIndexToVpp(iface.getIfIndex().intValue()), details.swIfIndex); - assertEquals(iface.getPhysAddress().getValue(), vppPhysAddrToYang(details.l2Address)); - } - - @Test - public void testReadCurrentAttributes() throws Exception { - final InstanceIdentifier id = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IFACE0_NAME)); - final InterfaceBuilder builder = getCustomizer().getBuilder(id); - - final SwInterfaceDetails iface = new SwInterfaceDetails(); - iface.interfaceName = IFACE0_NAME.getBytes(); - iface.swIfIndex = 0; - iface.linkSpeed = 1; - iface.l2AddressLength = 6; - iface.l2Address = new byte[iface.l2AddressLength]; - when(dumpCacheManager.getInterfaceDetail(id, ctx, IFACE0_NAME)).thenReturn(iface); - - getCustomizer().readCurrentAttributes(id, builder, ctx); - - final SwInterfaceDump request = new SwInterfaceDump(); - request.swIfIndex = new InterfaceIndex(); - request.swIfIndex.interfaceindex =~0; - request.nameFilter = IFACE0_NAME.getBytes(); - request.nameFilterValid = 1; - - assertIfacesAreEqual(builder.build(), iface); - verify(dumpCacheManager, times(1)).getInterfaceDetail(id, ctx, IFACE0_NAME); - } - - @Test - public void testReadSubInterface() throws Exception { - final InstanceIdentifier id = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(SUB_IFACE_NAME)); - final InterfaceBuilder builder = mock(InterfaceBuilder.class); - - final SwInterfaceDetails iface = new SwInterfaceDetails(); - iface.interfaceName = SUB_IFACE_NAME.getBytes(); - iface.swIfIndex = 2; - iface.supSwIfIndex = 1; - iface.subId = 1; - when(dumpCacheManager.getInterfaceDetail(id, ctx, SUB_IFACE_NAME)).thenReturn(iface); - - getCustomizer().readCurrentAttributes(id, builder, ctx); - - final SwInterfaceDump request = new SwInterfaceDump(); - request.swIfIndex = new InterfaceIndex(); - request.swIfIndex.interfaceindex =~0; - request.nameFilter = SUB_IFACE_NAME.getBytes(); - request.nameFilterValid = 1; - - verifyZeroInteractions(builder); - verify(dumpCacheManager, times(1)).getInterfaceDetail(id, ctx, SUB_IFACE_NAME); - } - - @Test - public void testGetAllIds() throws Exception { - final InstanceIdentifier id = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class); - - final SwInterfaceDetails swIf0 = new SwInterfaceDetails(); - swIf0.swIfIndex = 0; - swIf0.supSwIfIndex = 0; - swIf0.interfaceName = IFACE0_NAME.getBytes(); - final SwInterfaceDetails swIf1 = new SwInterfaceDetails(); - swIf1.swIfIndex = 1; - swIf1.supSwIfIndex = 1; - swIf1.interfaceName = IFACE1_NAME.getBytes(); - final SwInterfaceDetails swSubIf1 = new SwInterfaceDetails(); - swSubIf1.swIfIndex = 2; - swSubIf1.subId = 1; - swSubIf1.supSwIfIndex = 1; - swSubIf1.interfaceName = SUB_IFACE_NAME.getBytes(); - when(dumpCacheManager.getInterfaces(id, ctx)).thenReturn(Stream.of(swIf0, swIf1, swSubIf1)); - - final List expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME), new InterfaceKey( - IFACE1_NAME)); - final List actualIds = getCustomizer().getAllIds(id, ctx); - - final SwInterfaceDump request = new SwInterfaceDump(); - request.swIfIndex = new InterfaceIndex(); - request.swIfIndex.interfaceindex = ~0; - request.nameFilter = "".getBytes(); - request.nameFilterValid = 0; - - // sub-interface should not be on the list - assertEquals(expectedIds, actualIds); - verify(dumpCacheManager, times(1)).getInterfaces(id, ctx); - } - - @Test - public void testGetAllIdsWithDisabled() throws Exception { - final InstanceIdentifier id = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class); - - doReturn(true).when(interfaceDisableContext).isInterfaceDisabled(1, mappingContext); - - final SwInterfaceDetails swIf0 = new SwInterfaceDetails(); - swIf0.swIfIndex = 0; - swIf0.interfaceName = IFACE0_NAME.getBytes(); - final SwInterfaceDetails swIf1 = new SwInterfaceDetails(); - swIf1.swIfIndex = 1; - swIf1.interfaceName = IFACE1_NAME.getBytes(); - when(dumpCacheManager.getInterfaces(id, ctx)).thenReturn(Stream.of(swIf0, swIf1)); - - final List expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME)); - final List actualIds = getCustomizer().getAllIds(id, ctx); - - // disabled interface should not be on the list - assertEquals(expectedIds, actualIds); - verify(dumpCacheManager, times(1)).getInterfaces(id, ctx); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslatorTest.java deleted file mode 100644 index 7ea94a921..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslatorTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import java.nio.charset.StandardCharsets; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.AfPacket; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.TapV2; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUser; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeTunnel; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanTunnel; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev180703.EthernetCsmacd; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceDataTranslatorTest implements InterfaceDataTranslator { - - @Test - public void testVppPhysAddrToYang() throws Exception { - assertEquals("01:02:03:04:05:06", vppPhysAddrToYang(new byte[] {1, 2, 3, 4, 5, 6})); - // Extended (64-bit) MAC addresses are currently not supported (it might require yang model update), - // so test if extended part is ignored - assertEquals("0a:0b:0c:0d:0e:0f", vppPhysAddrToYang(new byte[] {0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 0})); - } - - @Test(expected = NullPointerException.class) - public void testVppPhysAddrToYangFailNullArgument() throws Exception { - vppPhysAddrToYang(null); - } - - @Test(expected = IllegalArgumentException.class) - public void testVppPhysAddrToYangInvalidByteArrayLength() throws Exception { - vppPhysAddrToYang(new byte[] {1, 2, 3, 4, 5}); - } - - @Test - public void testGetInterfaceType() { - assertEquals(TapV2.class, getInterfaceType("tap0")); - assertEquals(VxlanTunnel.class, getInterfaceType("vxlan0")); - assertEquals(VxlanGpeTunnel.class, getInterfaceType("vxlan_gpe0")); - assertEquals(VhostUser.class, getInterfaceType("VirtualEthernet0/0/0")); - assertEquals(AfPacket.class, getInterfaceType("host-veth0")); - assertEquals(EthernetCsmacd.class, getInterfaceType("eth0.0")); - assertEquals(EthernetCsmacd.class, getInterfaceType("local0")); - } - - @Test - public void testIsInterfaceOfType() { - assertTrue(isInterfaceOfType(TapV2.class, interfaceDetails("tap0"))); - assertTrue(isInterfaceOfType(VxlanTunnel.class, interfaceDetails("vxlan0"))); - assertTrue(isInterfaceOfType(VxlanGpeTunnel.class, interfaceDetails("vxlan_gpe0"))); - assertTrue(isInterfaceOfType(VhostUser.class, interfaceDetails("VirtualEthernet0/0/0"))); - assertTrue(isInterfaceOfType(AfPacket.class, interfaceDetails("host-veth0"))); - assertTrue(isInterfaceOfType(EthernetCsmacd.class, interfaceDetails("eth0.0"))); - assertTrue(isInterfaceOfType(EthernetCsmacd.class, interfaceDetails("local0"))); - } - - @Test - public void testIsInterfaceOfTypeMissingIfc() throws ReadFailedException { - final InterfaceCacheDumpManager dumpManager = mock(InterfaceCacheDumpManager.class); - final ReadContext ctx = mock(ReadContext.class); - final String ifcName = "tapThatDoesNotExists"; - final InstanceIdentifier id = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(ifcName)); - - when(dumpManager.getInterfaceDetail(id, ctx, ifcName)).thenReturn(null); - - assertFalse(isInterfaceOfType(dumpManager, id, ctx, TapV2.class)); - } - - private SwInterfaceDetails interfaceDetails(final String interfaceName) { - final SwInterfaceDetails details = new SwInterfaceDetails(); - details.interfaceName = interfaceName.getBytes(StandardCharsets.UTF_8); - return details; - } - - -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceRoutingCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceRoutingCustomizerTest.java deleted file mode 100644 index b72130939..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceRoutingCustomizerTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.core.dto.SwInterfaceGetTableReply; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.Routing; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.RoutingBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceRoutingCustomizerTest extends ReaderCustomizerTest { - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IF_NAME = "local0"; - private static final int IF_ID = 1; - private static final Long IP4_VRF_ID = 1L; - private static final Long IP6_VRF_ID = 2L; - - private NamingContext interfacesContext; - - public InterfaceRoutingCustomizerTest() { - super(Routing.class, VppInterfaceStateAugmentationBuilder.class); - } - - @Override - public void setUp() { - interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - defineMapping(mappingContext, IF_NAME, IF_ID, IFC_CTX_NAME); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new InterfaceRoutingCustomizer(api, interfacesContext); - } - - private InstanceIdentifier getRoutingId(final String name) { - return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)) - .augmentation(VppInterfaceStateAugmentation.class).child(Routing.class); - } - - @Test - public void testRead() throws Exception { - final RoutingBuilder builder = mock(RoutingBuilder.class); - when(api.swInterfaceGetTable(any())).thenReturn(future(tableReply(IP4_VRF_ID))).thenReturn(future(tableReply(IP6_VRF_ID))); - getCustomizer().readCurrentAttributes(getRoutingId(IF_NAME), builder, ctx); - - verify(builder).setIpv4VrfId(new VniReference(IP4_VRF_ID)); - verify(builder).setIpv6VrfId(new VniReference(IP6_VRF_ID)); - } - - @Test - public void testReadRoutingNotDefined() throws Exception { - final RoutingBuilder builder = mock(RoutingBuilder.class); - final Long vrfId = 0L; - when(api.swInterfaceGetTable(any())).thenReturn(future(tableReply(vrfId))); - getCustomizer().readCurrentAttributes(getRoutingId(IF_NAME), builder, ctx); - verifyZeroInteractions(builder); - } - - private SwInterfaceGetTableReply tableReply(final Long vrfId) { - final SwInterfaceGetTableReply reply = new SwInterfaceGetTableReply(); - reply.vrfId = vrfId.intValue(); - return reply; - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceStatisticsCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceStatisticsCustomizerTest.java deleted file mode 100644 index ae280cd8f..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceStatisticsCustomizerTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceStatisticsManager; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceStatisticsManagerImpl; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.stats.dto.InterfaceStatistics; -import io.fd.jvpp.stats.dto.InterfaceStatisticsDetails; -import io.fd.jvpp.stats.dto.InterfaceStatisticsDetailsReplyDump; -import io.fd.jvpp.stats.future.FutureJVppStatsFacade; -import java.util.Optional; -import org.junit.Assert; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state._interface.Statistics; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state._interface.StatisticsBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceStatisticsCustomizerTest extends ReaderCustomizerTest { - - private static final String IFC_CTX_NAME = "ifc-test-stats-instance"; - private static final String IF_NAME = "testIfc"; - private static final int SW_IF_INDEX = 1; - private static final int OUT_ERRORS = 2; - private static final int OUT_MULTI = 3; - private static final int OUT_UNI = 4; - private static final int OUT_BROAD = 5; - private static final int OUT_BYTES = 6; - private static final int IN_ERRORS = 22; - private static final int IN_MULTI = 33; - private static final int IN_UNI = 44; - private static final int IN_BROAD = 55; - private static final int IN_BYTES = 66; - private NamingContext interfaceContext; - private static final InstanceIdentifier IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .child(Statistics.class); - @Mock - private FutureJVppStatsFacade jvppStats; - - private InterfaceStatisticsManager statisticsManager; - - public InterfaceStatisticsCustomizerTest() { - super(Statistics.class, InterfaceBuilder.class); - } - - @Override - public void setUp() { - interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - interfaceContext.addName(1, IF_NAME, ctx.getMappingContext()); - } - - @Override - protected ReaderCustomizer initCustomizer() { - statisticsManager = new InterfaceStatisticsManagerImpl(); - return new InterfaceStatisticsCustomizer(interfaceContext, jvppStats, statisticsManager); - } - - @Test - public void testReadStatistics() throws Exception { - statisticsManager.enableStatistics(); - when(ctx.getMappingContext().read(any())) - .thenReturn(Optional.of(new MappingBuilder().setName(IF_NAME).setIndex(SW_IF_INDEX).build())); - when(jvppStats.interfaceStatisticsDump(any())).thenReturn(future(getStatistics())); - StatisticsBuilder statBuilder = new StatisticsBuilder(); - getCustomizer().readCurrentAttributes(IID, statBuilder, ctx); - Statistics stat = statBuilder.build(); - int[] expected = new int[]{SW_IF_INDEX, OUT_ERRORS, OUT_MULTI, OUT_UNI, OUT_BROAD, - OUT_BYTES, IN_ERRORS, IN_MULTI, IN_UNI, IN_BROAD, IN_BYTES}; - int[] actual = new int[]{interfaceContext.getIndex(IF_NAME, ctx.getMappingContext()), - stat.getOutErrors().getValue().intValue(), stat.getOutMulticastPkts().getValue().intValue(), - stat.getOutUnicastPkts().getValue().intValue(), stat.getOutBroadcastPkts().getValue().intValue(), - stat.getOutOctets().getValue().intValue(), stat.getInErrors().getValue().intValue(), - stat.getInMulticastPkts().getValue().intValue(), stat.getInUnicastPkts().getValue().intValue(), - stat.getInBroadcastPkts().getValue().intValue(), stat.getInOctets().getValue().intValue()}; - - Assert.assertArrayEquals(expected, actual); - } - - @Test(expected = ReadFailedException.class) - public void testReadStatisticsFailed() throws Exception { - statisticsManager.enableStatistics(); - when(ctx.getMappingContext().read(any())) - .thenReturn(Optional.of(new MappingBuilder().setName(IF_NAME).setIndex(SW_IF_INDEX).build())); - when(jvppStats.interfaceStatisticsDump(any())).thenReturn(future(null)); - StatisticsBuilder statBuilder = new StatisticsBuilder(); - getCustomizer().readCurrentAttributes(IID, statBuilder, ctx); - } - - private InterfaceStatisticsDetailsReplyDump getStatistics() { - InterfaceStatisticsDetailsReplyDump dumpReply = new InterfaceStatisticsDetailsReplyDump(); - dumpReply.interfaceStatisticsDetails = new InterfaceStatisticsDetails(1, 1); - dumpReply.interfaceStatisticsDetails.interfaceStatistics[0] = - new InterfaceStatistics(SW_IF_INDEX, OUT_ERRORS, OUT_MULTI, OUT_UNI, OUT_BROAD, - OUT_BYTES, IN_ERRORS, IN_MULTI, IN_UNI, IN_BROAD, IN_BYTES); - return dumpReply; - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java deleted file mode 100644 index 3a074c664..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/L2CustomizerTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.core.dto.BridgeDomainDetails; -import io.fd.jvpp.core.dto.BridgeDomainDetailsReplyDump; -import io.fd.jvpp.core.dto.BridgeDomainDump; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import io.fd.jvpp.core.types.BridgeDomainSwIf; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.L2; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.L2Builder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.state.attributes.Interconnection; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.state.attributes.interconnection.BridgeBasedBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class L2CustomizerTest extends ReaderCustomizerTest { - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String BD_CTX_NAME = "bd-test-instance"; - private NamingContext interfaceContext; - private NamingContext bridgeDomainContext; - - @Mock - private InterfaceCacheDumpManager dumpCacheManager; - - public L2CustomizerTest() { - super(L2.class, VppInterfaceStateAugmentationBuilder.class); - } - - @Override - public void setUp() { - interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - bridgeDomainContext = new NamingContext("generatedBDName", BD_CTX_NAME); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new L2Customizer(api, interfaceContext, bridgeDomainContext, dumpCacheManager); - } - - private InstanceIdentifier getL2Id(final String name) { - return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)) - .augmentation( - VppInterfaceStateAugmentation.class).child(L2.class); - } - - private void whenBridgeDomainDumpThenReturn(final List bridgeDomainDetails) { - final BridgeDomainDetailsReplyDump reply = new BridgeDomainDetailsReplyDump(); - reply.bridgeDomainDetails = bridgeDomainDetails; - when(api.bridgeDomainDump(any(BridgeDomainDump.class))).thenReturn(future(reply)); - } - - - private BridgeDomainSwIf generateBdSwIfDetails(final int ifId) { - final BridgeDomainSwIf bdSwIfDetails = new BridgeDomainSwIf(); - bdSwIfDetails.swIfIndex = ifId; - bdSwIfDetails.shg = 1; - return bdSwIfDetails; - } - - private Interconnection generateInterconnection(final String bdName, final Boolean bvi) { - final BridgeBasedBuilder bbBuilder = new BridgeBasedBuilder(); - bbBuilder.setBridgeDomain(bdName); - bbBuilder.setSplitHorizonGroup((short) 1); - if (bvi != null) { - bbBuilder.setBridgedVirtualInterface(bvi); - } else { - bbBuilder.setBridgedVirtualInterface(false); // false is default - } - return bbBuilder.build(); - } - - @Test - public void testReadBvi() throws Exception { - final int ifId = 1; - final int bdId = 1; - final String bdName = "bd001"; - final String ifName = "eth0.sub0"; - defineMapping(mappingContext, ifName, ifId, IFC_CTX_NAME); - defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); - - final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); - ifaceDetails.subId = ifId; - - // BVIinterfaceContext - whenBridgeDomainDumpThenReturn(Collections.singletonList(generateBdDetails(ifId, ifId, bdId))); - - L2Builder builder = mock(L2Builder.class); - getCustomizer().readCurrentAttributes(getL2Id(ifName), builder, ctx); - - verify(builder).setInterconnection(generateInterconnection(bdName, true)); - } - - // split to separate test to avoid using cached value from previous run(cannot mock cache) - @Test - public void testReadNoBvi() throws Exception { - final Map cachedInterfaceDump = new HashMap<>(); - final int ifId = 1; - final int bdId = 1; - final String bdName = "bd001"; - final String ifName = "eth0.sub0"; - defineMapping(mappingContext, ifName, ifId, IFC_CTX_NAME); - defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); - - final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); - ifaceDetails.subId = ifId; - cachedInterfaceDump.put(ifId, ifaceDetails); - - // Not BVI - whenBridgeDomainDumpThenReturn(Collections - .singletonList(generateBdDetails(ifId, 99 /* Different ifc is marked as BVI in bd details */, bdId))); - - L2Builder builder = mock(L2Builder.class); - getCustomizer().readCurrentAttributes(getL2Id(ifName), builder, ctx); - - verify(builder).setInterconnection(generateInterconnection(bdName, null)); - } - - private BridgeDomainDetails generateBdDetails(final int ifId, final int bviSwIfIndex, int bdId) { - final BridgeDomainDetails bridgeDomainDetails = new BridgeDomainDetails(); - bridgeDomainDetails.bviSwIfIndex = bviSwIfIndex; - bridgeDomainDetails.bdId = bdId; - bridgeDomainDetails.swIfDetails = new BridgeDomainSwIf[]{generateBdSwIfDetails(ifId)}; - return bridgeDomainDetails; - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizerTest.java deleted file mode 100644 index a64064f84..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/RewriteCustomizerTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.common.translate.util.TagRewriteOperation; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import java.util.List; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319._802dot1q; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.Rewrite; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.RewriteBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.state.attributes.L2Builder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.tag.rewrite.PushTags; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.ChildOf; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class RewriteCustomizerTest extends ReaderCustomizerTest { - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IF_NAME = "local0"; - private static final String VLAN_IF_NAME = "local0.1"; - private static final int VLAN_IF_INDEX = 11; - private static final int VLAN_ID = 1; - - private NamingContext interfacesContext; - - @Captor - private ArgumentCaptor> captor; - - @Mock - private InterfaceCacheDumpManager dumpCacheManager; - - public RewriteCustomizerTest() { - super(Rewrite.class, L2Builder.class); - } - - @Override - public void setUp() { - interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new RewriteCustomizer(dumpCacheManager); - } - - private InstanceIdentifier getVlanTagRewriteId(final String name, final long index) { - final Class> child = (Class) Rewrite.class; - final InstanceIdentifier id = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)) - .augmentation( - SubinterfaceStateAugmentation.class).child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey(index)) - .child(child); - return id; - } - - @Test - public void testRead() throws ReadFailedException { - final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); - ifaceDetails.subId = VLAN_ID; - ifaceDetails.interfaceName = VLAN_IF_NAME.getBytes(); - ifaceDetails.vtrOp = TagRewriteOperation.translate_2_to_2.ordinal(); - ifaceDetails.subNumberOfTags = 2; - ifaceDetails.vtrTag1 = 123; - ifaceDetails.vtrTag2 = 321; - ifaceDetails.vtrPushDot1Q = 1; - ifaceDetails.swIfIndex = VLAN_IF_INDEX; - ifaceDetails.supSwIfIndex = 2; - - final RewriteBuilder builder = mock(RewriteBuilder.class); - final InstanceIdentifier vlanTagRewriteId = getVlanTagRewriteId(IF_NAME, VLAN_ID); - when(dumpCacheManager.getInterfaceDetail(vlanTagRewriteId, ctx, VLAN_IF_NAME)).thenReturn(ifaceDetails); - getCustomizer().readCurrentAttributes(vlanTagRewriteId, builder, ctx); - - verify(builder).setVlanType(_802dot1q.class); - verify(builder).setPopTags((short) 2); - - verify(builder).setPushTags(captor.capture()); - final List tags = captor.getValue(); - assertEquals(ifaceDetails.subNumberOfTags, tags.size()); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizerTest.java deleted file mode 100644 index e1afd9c99..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceCustomizerTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; -import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import java.util.List; -import java.util.stream.Stream; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.SubInterfacesBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.VlanTagged; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.Match; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.Tags; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceCustomizerTest - extends ListReaderCustomizerTest implements - InterfaceDumpHelper { - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String SUPER_IF_NAME = "local0"; - private static final int SUPER_IF_INDEX = 1; - private static final String VLAN_IF_NAME = "local0.1"; - private static final int VLAN_IF_ID = 1; - private static final int VLAN_IF_INDEX = 11; - - private NamingContext interfacesContext; - - @Mock - private InterfaceCacheDumpManager dumpCacheManager; - - public SubInterfaceCustomizerTest() { - super(SubInterface.class, SubInterfacesBuilder.class); - } - - @Override - public void setUp() { - interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - defineMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_INDEX, IFC_CTX_NAME); - defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new SubInterfaceCustomizer(api, interfacesContext, dumpCacheManager); - } - - private InstanceIdentifier getSubInterfaceId(final String name, final long id) { - return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(name)) - .augmentation( - SubinterfaceStateAugmentation.class).child( - SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(id)); - } - - @Test - public void testRead() throws ReadFailedException { - - final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); - ifaceDetails.subId = VLAN_IF_ID; - ifaceDetails.interfaceName = VLAN_IF_NAME.getBytes(); - ifaceDetails.swIfIndex = 2; - ifaceDetails.supSwIfIndex = SUPER_IF_INDEX; - defineMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_INDEX, IFC_CTX_NAME); - defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME); - ifaceDetails.subNumberOfTags = 2; - ifaceDetails.subOuterVlanIdAny = 1; - ifaceDetails.subInnerVlanIdAny = 1; - ifaceDetails.subExactMatch = 1; - - final SubInterfaceBuilder builder = mock(SubInterfaceBuilder.class); - final InstanceIdentifier subInterfaceId = getSubInterfaceId(SUPER_IF_NAME, VLAN_IF_ID); - - when(dumpCacheManager.getInterfaceDetail(subInterfaceId, ctx, VLAN_IF_NAME)).thenReturn(ifaceDetails); - getCustomizer().readCurrentAttributes(subInterfaceId, builder, ctx); - - verify(builder).setIdentifier((long) VLAN_IF_ID); - - ArgumentCaptor tagCaptor = ArgumentCaptor.forClass(Tags.class); - verify(builder).setTags(tagCaptor.capture()); - assertEquals(ifaceDetails.subNumberOfTags, tagCaptor.getValue().getTag().size()); - - ArgumentCaptor matchCaptor = ArgumentCaptor.forClass(Match.class); - verify(builder).setMatch(matchCaptor.capture()); - final VlanTagged matchType = (VlanTagged) matchCaptor.getValue().getMatchType(); - assertTrue(matchType.getVlanTagged().isMatchExactTags()); - } - - @Test - public void testGetAllIds() throws Exception { - final SwInterfaceDetails iface = new SwInterfaceDetails(); - iface.interfaceName = VLAN_IF_NAME.getBytes(); - iface.swIfIndex = VLAN_IF_INDEX; - iface.subId = VLAN_IF_ID; - iface.supSwIfIndex = SUPER_IF_INDEX; - - final InstanceIdentifier subInterfaceId = getSubInterfaceId(SUPER_IF_NAME, VLAN_IF_ID); - when(dumpCacheManager.getInterfaces(subInterfaceId, ctx)).thenReturn(Stream.of(iface)); - final List allIds = - getCustomizer().getAllIds(subInterfaceId, ctx); - - assertEquals(1, allIds.size()); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceL2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceL2CustomizerTest.java deleted file mode 100644 index 59ff8f497..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceL2CustomizerTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.state.attributes.L2; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.state.attributes.L2Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceL2CustomizerTest extends ReaderCustomizerTest { - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String BD_CTX_NAME = "bd-test-instance"; - private NamingContext interfaceContext; - private NamingContext bridgeDomainContext; - - private static final String IF_NAME = "local0"; - private static final int IF_INDEX = 1; - private static final String SUB_IF_NAME = "local0.1"; - private static final long SUB_IF_ID = 1; - private static final int SUB_IF_INDEX = 11; - private InstanceIdentifier IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) - .child(SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)) - .child(L2.class); - - @Mock - private InterfaceCacheDumpManager dumpCacheManager; - - public SubInterfaceL2CustomizerTest() { - super(L2.class, SubInterfaceBuilder.class); - } - - @Override - protected void setUp() { - interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - bridgeDomainContext = new NamingContext("generatedBDName", BD_CTX_NAME); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); - defineMapping(mappingContext, SUB_IF_NAME, SUB_IF_INDEX, IFC_CTX_NAME); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new SubInterfaceL2Customizer(api, interfaceContext, bridgeDomainContext, dumpCacheManager); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceRoutingCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceRoutingCustomizerTest.java deleted file mode 100644 index 33d118a26..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/SubInterfaceRoutingCustomizerTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.core.dto.SwInterfaceGetTable; -import io.fd.jvpp.core.dto.SwInterfaceGetTableReply; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.Routing; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.RoutingBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceRoutingCustomizerTest extends ReaderCustomizerTest implements - ByteDataTranslator { - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IF_NAME = "local0"; - private static final int IF_ID = 1; - private static final String SUBIF_NAME = "local0.4"; - private static final int SUBIF_ID = 4; - private static final InstanceIdentifier VALID_ID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) - .child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey((long) SUBIF_ID)) - .child(Routing.class); - private static final int IPV4_VRF = 4; - private static final int IPV6_VRF = 6; - private static final int NO_VRF = 0; - - private NamingContext interfacesContext; - - public SubInterfaceRoutingCustomizerTest() { - super(Routing.class, SubInterfaceBuilder.class); - } - - @Override - protected void setUp() throws Exception { - interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - defineMapping(mappingContext, IF_NAME, IF_ID, IFC_CTX_NAME); - defineMapping(mappingContext, SUBIF_NAME, SUBIF_ID, IFC_CTX_NAME); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new SubInterfaceRoutingCustomizer(api, interfacesContext); - } - - @Test - public void testReadAttributesAllDefined() throws ReadFailedException { - when(api.swInterfaceGetTable(request(false, SUBIF_ID))).thenReturn(future(reply(IPV4_VRF))); - when(api.swInterfaceGetTable(request(true, SUBIF_ID))).thenReturn(future(reply(IPV6_VRF))); - final RoutingBuilder routingBuilder = new RoutingBuilder(); - getCustomizer().readCurrentAttributes(VALID_ID, routingBuilder, ctx); - assertEquals(IPV4_VRF, routingBuilder.getIpv4VrfId().getValue().intValue()); - assertEquals(IPV6_VRF, routingBuilder.getIpv6VrfId().getValue().intValue()); - } - - @Test - public void testReadAttributesOneDefined() throws ReadFailedException { - when(api.swInterfaceGetTable(request(false, SUBIF_ID))).thenReturn(future(reply(IPV4_VRF))); - when(api.swInterfaceGetTable(request(true, SUBIF_ID))).thenReturn(future(reply(NO_VRF))); - final RoutingBuilder routingBuilder = new RoutingBuilder(); - getCustomizer().readCurrentAttributes(VALID_ID, routingBuilder, ctx); - assertEquals(IPV4_VRF, routingBuilder.getIpv4VrfId().getValue().intValue()); - assertNull(routingBuilder.getIpv6VrfId()); - } - - @Test - public void testReadAttributesNoDefined() throws ReadFailedException { - when(api.swInterfaceGetTable(any())).thenReturn(future(reply(NO_VRF))); - final RoutingBuilder routingBuilder = new RoutingBuilder(); - getCustomizer().readCurrentAttributes(VALID_ID, routingBuilder, ctx); - assertNull(routingBuilder.getIpv4VrfId()); - assertNull(routingBuilder.getIpv6VrfId()); - } - - private SwInterfaceGetTable request(final boolean ipv6, final int index) { - SwInterfaceGetTable request = new SwInterfaceGetTable(); - request.isIpv6 = booleanToByte(ipv6); - request.swIfIndex = index; - return request; - } - - private SwInterfaceGetTableReply reply(final int vrf) { - SwInterfaceGetTableReply reply = new SwInterfaceGetTableReply(); - reply.vrfId = vrf; - return reply; - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/TapV2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/TapV2CustomizerTest.java deleted file mode 100644 index ce5f491d4..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/TapV2CustomizerTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2018 Pantheon Technologies and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; -import io.fd.hc2vpp.common.translate.util.Ipv4Translator; -import io.fd.hc2vpp.common.translate.util.Ipv6Translator; -import io.fd.hc2vpp.common.translate.util.MacTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import io.fd.jvpp.core.dto.SwInterfaceTapV2Details; -import io.fd.jvpp.core.dto.SwInterfaceTapV2DetailsReplyDump; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.TapV2; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.TapV2Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class TapV2CustomizerTest extends ReaderCustomizerTest implements InterfaceDumpHelper, - Ipv4Translator, Ipv6Translator, MacTranslator { - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IF_NAME = "tapV21"; - private static final String DEVICE_NAME = "testTapV2Device"; - private static final int IF_INDEX = 1; - private static final String HOST_BRIDGE = "TestBridge"; - private static final String HOST_IPV4_PREFIX = "192.168.255.100"; - private static final byte HOST_IPV4_PREFIX_LEN = 24; - private static final String HOST_IPV6_PREFIX = "a::100"; - private static final byte HOST_IPV6_PREFIX_LEN = -128; - private static final int HOST_IPV6_PREFIX_LEN_EXP = 128; - private static final int RX_TX_RING_SIZE = 512; - private static final String HOST_MAC = "00:ee:ee:ee:ee:ee"; - private static final String HOST_NAMESPACE = "testHostNS"; - - private static final InstanceIdentifier IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(VppInterfaceStateAugmentation.class).child(TapV2.class); - private NamingContext interfaceContext; - - @Mock - private InterfaceCacheDumpManager dumpCacheManager; - - public TapV2CustomizerTest() { - super(TapV2.class, VppInterfaceStateAugmentationBuilder.class); - } - - @Override - protected void setUp() throws Exception { - interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); - when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)).thenReturn(ifaceDetails()); - } - - private SwInterfaceDetails ifaceDetails() { - final SwInterfaceDetails details = new SwInterfaceDetails(); - details.swIfIndex = IF_INDEX; - details.interfaceName = IF_NAME.getBytes(); - details.tag = new byte[64]; - return details; - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new TapV2Customizer(api, interfaceContext, dumpCacheManager); - } - - @Test - public void testRead() throws ReadFailedException { - final TapV2Builder builder = mock(TapV2Builder.class); - when(api.swInterfaceTapV2Dump(any())).thenReturn(future(tapDump())); - getCustomizer().readCurrentAttributes(IID, builder, ctx); - verify(builder).setHostInterfaceName(IF_NAME); - verify(builder).setDeviceName(DEVICE_NAME); - verify(builder).setHostBridge(HOST_BRIDGE); - verify(builder) - .setHostIpv4Address(new Ipv4Prefix(String.format("%s/%d", HOST_IPV4_PREFIX, HOST_IPV4_PREFIX_LEN))); - verify(builder) - .setHostIpv6Address(new Ipv6Prefix(String.format("%s/%d", HOST_IPV6_PREFIX, HOST_IPV6_PREFIX_LEN_EXP))); - verify(builder).setTxRingSize(RX_TX_RING_SIZE); - verify(builder).setRxRingSize(RX_TX_RING_SIZE); - verify(builder).setHostNamespace(HOST_NAMESPACE); - verify(builder).setHostMac(new PhysAddress(HOST_MAC)); - } - - @Test(expected = ReadFailedException.class) - public void testReadFailed() throws ReadFailedException { - when(api.swInterfaceTapV2Dump(any())).thenReturn(failedFuture()); - getCustomizer().readCurrentAttributes(IID, mock(TapV2Builder.class), ctx); - } - - private SwInterfaceTapV2DetailsReplyDump tapDump() { - final SwInterfaceTapV2DetailsReplyDump reply = new SwInterfaceTapV2DetailsReplyDump(); - final SwInterfaceTapV2Details details = new SwInterfaceTapV2Details(); - details.devName = DEVICE_NAME.getBytes(UTF_8); - details.swIfIndex = IF_INDEX; - details.hostBridge = HOST_BRIDGE.getBytes(UTF_8); - details.hostNamespace = HOST_NAMESPACE.getBytes(UTF_8); - details.hostIfName = IF_NAME.getBytes(UTF_8); - details.hostIp4PrefixLen = HOST_IPV4_PREFIX_LEN; - details.hostIp4Addr = ipv4AddressNoZoneToArray(HOST_IPV4_PREFIX); - details.hostIp6Addr = ipv6AddressNoZoneToArray(new Ipv6AddressNoZone(HOST_IPV6_PREFIX)); - details.hostIp6PrefixLen = HOST_IPV6_PREFIX_LEN; - details.hostMacAddr = parseMac(HOST_MAC); - details.txRingSz = details.rxRingSz = RX_TX_RING_SIZE; - reply.swInterfaceTapV2Details.add(details); - return reply; - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VhostUserCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VhostUserCustomizerTest.java deleted file mode 100644 index 0f849ed42..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VhostUserCustomizerTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import io.fd.jvpp.core.dto.SwInterfaceVhostUserDetails; -import io.fd.jvpp.core.dto.SwInterfaceVhostUserDetailsReplyDump; -import java.math.BigInteger; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUserRole; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.VhostUser; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.VhostUserBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class VhostUserCustomizerTest extends ReaderCustomizerTest implements - InterfaceDumpHelper { - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IF_NAME = "VirtualEthernet1"; - private static final int IF_INDEX = 1; - private static final InstanceIdentifier IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(VppInterfaceStateAugmentation.class).child(VhostUser.class); - - private NamingContext interfaceContext; - - @Mock - private InterfaceCacheDumpManager dumpCacheManager; - - public VhostUserCustomizerTest() { - super(VhostUser.class, VppInterfaceStateAugmentationBuilder.class); - } - - @Override - protected void setUp() throws Exception { - interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); - when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)).thenReturn(ifaceDetails()); - } - - private SwInterfaceDetails ifaceDetails() { - final SwInterfaceDetails details = new SwInterfaceDetails(); - details.swIfIndex = IF_INDEX; - details.interfaceName = IF_NAME.getBytes(); - details.tag = new byte[64]; - return details; - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new VhostUserCustomizer(api, interfaceContext, dumpCacheManager); - } - - @Test - public void testRead() throws ReadFailedException { - final VhostUserBuilder builder = mock(VhostUserBuilder.class); - when(api.swInterfaceVhostUserDump(any())).thenReturn(future(vhostDump())); - getCustomizer().readCurrentAttributes(IID, builder, ctx); - verifyVhostBuilder(builder); - } - - @Test(expected = ReadFailedException.class) - public void testReadFailed() throws ReadFailedException { - when(api.swInterfaceVhostUserDump(any())).thenReturn(failedFuture()); - getCustomizer().readCurrentAttributes(IID, mock(VhostUserBuilder.class), ctx); - } - - private SwInterfaceVhostUserDetailsReplyDump vhostDump() { - final SwInterfaceVhostUserDetailsReplyDump reply = new SwInterfaceVhostUserDetailsReplyDump(); - final SwInterfaceVhostUserDetails details = new SwInterfaceVhostUserDetails(); - details.swIfIndex = IF_INDEX; - details.interfaceName = IF_NAME.getBytes(); - details.isServer = 1; - details.features = 2; - details.numRegions = 3; - details.sockFilename = "socketName".getBytes(); - details.virtioNetHdrSz = 4; - details.sockErrno = 5; - reply.swInterfaceVhostUserDetails.add(details); - return reply; - } - - private void verifyVhostBuilder(final VhostUserBuilder builder) { - verify(builder).setRole(VhostUserRole.Server); - verify(builder).setFeatures(BigInteger.valueOf(2)); - verify(builder).setNumMemoryRegions(3L); - verify(builder).setSocket("socketName"); - verify(builder).setVirtioNetHdrSize(4L); - verify(builder).setConnectError("5"); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizerTest.java deleted file mode 100644 index 80a8975d1..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanCustomizerTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -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.Mockito.doReturn; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -import com.google.common.collect.Lists; -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.VppInvocationException; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import io.fd.jvpp.core.dto.VxlanTunnelDetails; -import io.fd.jvpp.core.dto.VxlanTunnelDetailsReplyDump; -import io.fd.jvpp.core.dto.VxlanTunnelDump; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.L2Input; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.Vxlan; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.VxlanBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class VxlanCustomizerTest extends ReaderCustomizerTest { - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IF_NAME = "ifc1"; - private static final int IF_INDEX = 0; - - private NamingContext interfacesContext; - static final InstanceIdentifier IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(VppInterfaceStateAugmentation.class).child(Vxlan.class); - - @Mock - private InterfaceCacheDumpManager dumpCacheManager; - - public VxlanCustomizerTest() { - super(Vxlan.class, VppInterfaceStateAugmentationBuilder.class); - } - - @Override - public void setUp() throws VppInvocationException, ReadFailedException { - interfacesContext = new NamingContext("vxlan-tunnel", IFC_CTX_NAME); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); - - final SwInterfaceDetails v = new SwInterfaceDetails(); - v.interfaceName = "vxlan-tunnel4".getBytes(); - - when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)).thenReturn(v); - doReturn(future(getVxlanTunnelDetailsReplyDump(55))).when(api).vxlanTunnelDump(any(VxlanTunnelDump.class)); - } - - @Test - public void testRead() throws Exception { - final VxlanBuilder builder = getCustomizer().getBuilder(IID); - getCustomizer().readCurrentAttributes(IID, builder, ctx); - - assertEquals(9, builder.getVni().getValue().intValue()); - assertEquals(55, builder.getEncapVrfId().getValue().intValue()); - assertEquals(L2Input.class, builder.getDecapNext()); - - assertNull(builder.getSrc().getIpv6AddressNoZone()); - assertNotNull(builder.getSrc().getIpv4AddressNoZone()); - assertEquals("1.2.3.5", builder.getSrc().getIpv4AddressNoZone().getValue()); - - assertNull(builder.getDst().getIpv6AddressNoZone()); - assertNotNull(builder.getDst().getIpv4AddressNoZone()); - assertEquals("1.2.3.4", builder.getDst().getIpv4AddressNoZone().getValue()); - - verify(api).vxlanTunnelDump(any(VxlanTunnelDump.class)); - } - - @Test - public void testReadVniOverflow() throws Exception { - final long encapVrfId = 4294967295L; - doReturn(future(getVxlanTunnelDetailsReplyDump((int) encapVrfId))).when(api) - .vxlanTunnelDump(any(VxlanTunnelDump.class)); - final VxlanBuilder builder = getCustomizer().getBuilder(IID); - getCustomizer().readCurrentAttributes(IID, builder, ctx); - - assertEquals(encapVrfId, builder.getEncapVrfId().getValue().longValue()); - verify(api).vxlanTunnelDump(any(VxlanTunnelDump.class)); - } - - @Test(expected = IllegalArgumentException.class) - public void testReadVppNameNotCached() throws Exception { - when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)) - .thenThrow(new IllegalArgumentException("Detail for interface not found")); - - final VxlanBuilder builder = getCustomizer().getBuilder(IID); - getCustomizer().readCurrentAttributes(IID, builder, ctx); - } - - @Test - public void testReadWrongType() throws Exception { - final SwInterfaceDetails v = new SwInterfaceDetails(); - v.interfaceName = "tap-2".getBytes(); - - when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)).thenReturn(v); - - final VxlanBuilder builder = getCustomizer().getBuilder(IID); - getCustomizer().readCurrentAttributes(IID, builder, ctx); - - // Should be ignored - verifyZeroInteractions(api); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new VxlanCustomizer(api, interfacesContext, dumpCacheManager); - } - - private static VxlanTunnelDetailsReplyDump getVxlanTunnelDetailsReplyDump(final int encapVrfId) { - final VxlanTunnelDetailsReplyDump replyDump = new VxlanTunnelDetailsReplyDump(); - final VxlanTunnelDetails vxlanTunnelDetails = new VxlanTunnelDetails(); - vxlanTunnelDetails.isIpv6 = 0; - vxlanTunnelDetails.dstAddress = AddressTranslator.INSTANCE.ipv4AddressNoZoneToArray("1.2.3.4"); - vxlanTunnelDetails.srcAddress = AddressTranslator.INSTANCE.ipv4AddressNoZoneToArray("1.2.3.5"); - vxlanTunnelDetails.encapVrfId = encapVrfId; - vxlanTunnelDetails.swIfIndex = 0; - vxlanTunnelDetails.vni = 9; - vxlanTunnelDetails.decapNextIndex = 1; - replyDump.vxlanTunnelDetails = Lists.newArrayList(vxlanTunnelDetails); - return replyDump; - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizerTest.java deleted file mode 100644 index e5bd6dc34..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/VxlanGpeCustomizerTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.mockito.ArgumentMatchers.matches; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -import com.google.common.collect.Lists; -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManager; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.VppBaseCallException; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import io.fd.jvpp.core.dto.VxlanGpeTunnelDetails; -import io.fd.jvpp.core.dto.VxlanGpeTunnelDetailsReplyDump; -import io.fd.jvpp.core.dto.VxlanGpeTunnelDump; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.VxlanGpe; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.VxlanGpeBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class VxlanGpeCustomizerTest extends ReaderCustomizerTest - implements AddressTranslator { - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IF_NAME = "ifc2"; - private static final int IF_INDEX = 0; - - private NamingContext interfacesContext; - private static final InstanceIdentifier VXLAN_GPE_ID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(VppInterfaceStateAugmentation.class).child(VxlanGpe.class); - - @Mock - private InterfaceCacheDumpManager dumpCacheManager; - - public VxlanGpeCustomizerTest() { - super(VxlanGpe.class, VppInterfaceStateAugmentationBuilder.class); - } - - @Override - public void setUp() throws VppBaseCallException, ReadFailedException { - interfacesContext = new NamingContext("vxlan_gpe_inf", IFC_CTX_NAME); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); - - final SwInterfaceDetails v = new SwInterfaceDetails(); - v.interfaceName = "vxlan_gpe_inf2".getBytes(); - - when(dumpCacheManager.getInterfaceDetail(any(), any(), matches(IF_NAME))).thenReturn(v); - - final VxlanGpeTunnelDetailsReplyDump value = new VxlanGpeTunnelDetailsReplyDump(); - final VxlanGpeTunnelDetails vxlanGpeTunnelDetails = new VxlanGpeTunnelDetails(); - vxlanGpeTunnelDetails.isIpv6 = 0; - vxlanGpeTunnelDetails.local = ipv4AddressNoZoneToArray("1.2.3.4"); - vxlanGpeTunnelDetails.remote = ipv4AddressNoZoneToArray("1.2.3.5"); - vxlanGpeTunnelDetails.vni = 9; - vxlanGpeTunnelDetails.protocol = 1; - vxlanGpeTunnelDetails.encapVrfId = 55; - vxlanGpeTunnelDetails.decapVrfId = 66; - vxlanGpeTunnelDetails.swIfIndex = 0; - value.vxlanGpeTunnelDetails = Lists.newArrayList(vxlanGpeTunnelDetails); - doReturn(future(value)).when(api).vxlanGpeTunnelDump(any(VxlanGpeTunnelDump.class)); - } - - @Test - public void testReadCurrentAttributes() throws Exception { - final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID); - getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx); - - assertNull(builder.getLocal().getIpv6AddressNoZone()); - assertNotNull(builder.getLocal().getIpv4AddressNoZone()); - assertEquals("1.2.3.4", builder.getLocal().getIpv4AddressNoZone().getValue()); - - assertNull(builder.getRemote().getIpv6AddressNoZone()); - assertNotNull(builder.getRemote().getIpv4AddressNoZone()); - assertEquals("1.2.3.5", builder.getRemote().getIpv4AddressNoZone().getValue()); - - assertEquals(9, builder.getVni().getValue().intValue()); - assertEquals(1, builder.getNextProtocol().getIntValue()); - assertEquals(55, builder.getEncapVrfId().intValue()); - assertEquals(66, builder.getDecapVrfId().intValue()); - - verify(api).vxlanGpeTunnelDump(any(VxlanGpeTunnelDump.class)); - } - - @Test(expected = IllegalArgumentException.class) - public void testReadCurrentAttributesVppNameNotCached() throws Exception { - when(dumpCacheManager.getInterfaceDetail(VXLAN_GPE_ID, ctx, IF_NAME)) - .thenThrow(new IllegalArgumentException("Detail for interface not found")); - - final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID); - getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx); - } - - @Test - public void testReadCurrentAttributesWrongType() throws Exception { - final SwInterfaceDetails v = new SwInterfaceDetails(); - v.interfaceName = "tap-3".getBytes(); - - when(dumpCacheManager.getInterfaceDetail(VXLAN_GPE_ID, ctx, IF_NAME)).thenReturn(v); - - final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID); - getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx); - verifyZeroInteractions(api); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new VxlanGpeCustomizer(api, interfacesContext, dumpCacheManager); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManagerImplTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManagerImplTest.java deleted file mode 100644 index e8d265aa7..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/cache/InterfaceCacheDumpManagerImplTest.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate.cache; - -import static io.fd.hc2vpp.v3po.interfacesstate.cache.InterfaceCacheDumpManagerImpl.BY_NAME_INDEX_KEY; -import static org.junit.Assert.assertEquals; -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 static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.test.util.FutureProducer; -import io.fd.hc2vpp.common.test.util.NamingContextHelper; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.MappingContext; -import io.fd.honeycomb.translate.ModificationCache; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.jvpp.core.dto.SwInterfaceDetails; -import io.fd.jvpp.core.dto.SwInterfaceDetailsReplyDump; -import io.fd.jvpp.core.dto.SwInterfaceDump; -import io.fd.jvpp.core.future.FutureJVppCore; -import io.fd.jvpp.core.types.InterfaceIndex; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.stream.Collectors; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class InterfaceCacheDumpManagerImplTest implements NamingContextHelper, FutureProducer { - - private static final String IFACE_0 = "iface-0"; - private static final String IFACE_1 = "iface-1"; - private static final String IFACE_2 = "iface-2"; - private static final String IFACE_3 = "iface-3"; - - @Mock - private FutureJVppCore jvpp; - @Mock - private ReadContext ctx; - @Mock - private MappingContext mappingContext; - - private InstanceIdentifier identifier; - private InstanceIdentifier identifierThree; - private NamingContext namingContext; - private ModificationCache cache; - private InterfaceCacheDumpManagerImpl manager; - - @Before - public void setUp() throws Exception { - initMocks(this); - namingContext = new NamingContext("interface-", "interface-context"); - cache = new ModificationCache(); - manager = new InterfaceCacheDumpManagerImpl(jvpp, namingContext); - when(ctx.getModificationCache()).thenReturn(cache); - when(ctx.getMappingContext()).thenReturn(mappingContext); - identifier = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IFACE_0)); - - identifierThree = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IFACE_3)); - - when(jvpp.swInterfaceDump(fullRequest())).thenReturn(future(fullReply())); - - // this one is not in full dump - when(jvpp.swInterfaceDump(specificRequest(IFACE_3))).thenReturn(future(specificReplyThree())); - defineMapping(mappingContext, IFACE_0, 0, "interface-context"); - defineMapping(mappingContext, IFACE_1, 1, "interface-context"); - defineMapping(mappingContext, IFACE_2, 2, "interface-context"); - defineMapping(mappingContext, IFACE_3, 3, "interface-context"); - } - - @Test - public void getInterfaces() throws Exception { - assertFalse(cache.containsKey(BY_NAME_INDEX_KEY)); - final List interfaces = manager.getInterfaces(identifier, ctx).collect(Collectors.toList()); - assertEquals(3, interfaces.size()); - assertTrue(interfaces.contains(detailZero())); - assertTrue(interfaces.contains(detailOne())); - assertTrue(interfaces.contains(detailTwo())); - - // first request must call jvpp - verify(jvpp, times(1)).swInterfaceDump(fullRequest()); - assertTrue(cache.containsKey(BY_NAME_INDEX_KEY)); - - // then cached value should be returned - final List cachedInterfaces = - manager.getInterfaces(identifier, ctx).collect(Collectors.toList()); - assertEquals(3, cachedInterfaces.size()); - assertTrue(cachedInterfaces.contains(detailZero())); - assertTrue(cachedInterfaces.contains(detailOne())); - assertTrue(cachedInterfaces.contains(detailTwo())); - - //verify that dump wasn't invoked again - verifyNoMoreInteractions(jvpp); - } - - @Test - public void getInterfaceDetailFromCache() throws Exception { - final HashMap cachedMap = new HashMap<>(); - final SwInterfaceDetails detailZero = detailZero(); - cachedMap.put(IFACE_0, detailZero); - cache.put(BY_NAME_INDEX_KEY, cachedMap); - when(jvpp.swInterfaceDump(specificRequest(IFACE_0))).thenReturn(future(specificReplyZero())); - final SwInterfaceDetails interfaceDetail = manager.getInterfaceDetail(identifier, ctx, IFACE_0); - assertEquals(detailZero, interfaceDetail); - - // must not call jvpp, just get it from cache - verifyZeroInteractions(jvpp); - } - - @Test - public void getInterfaceDetailNotInFullDump() throws Exception { - assertFalse(cache.containsKey(BY_NAME_INDEX_KEY)); - final SwInterfaceDetails specificDetail = manager.getInterfaceDetail(identifierThree, ctx, IFACE_3); - assertEquals(detailThree(), specificDetail); - - verify(jvpp, times(1)).swInterfaceDump(specificRequest(IFACE_3)); - } - - private SwInterfaceDetailsReplyDump fullReply() { - final SwInterfaceDetailsReplyDump reply = new SwInterfaceDetailsReplyDump(); - reply.swInterfaceDetails = Arrays.asList(detailZero(), detailOne(), detailTwo()); - return reply; - } - - private static SwInterfaceDetails detailTwo() { - SwInterfaceDetails detail3 = new SwInterfaceDetails(); - detail3.swIfIndex = 2; - detail3.interfaceName = IFACE_2.getBytes(); - return detail3; - } - - private static SwInterfaceDetails detailOne() { - SwInterfaceDetails detail2 = new SwInterfaceDetails(); - detail2.swIfIndex = 1; - detail2.interfaceName = IFACE_1.getBytes(); - return detail2; - } - - private static SwInterfaceDetails detailThree() { - SwInterfaceDetails detail2 = new SwInterfaceDetails(); - detail2.swIfIndex = 3; - detail2.interfaceName = IFACE_3.getBytes(); - return detail2; - } - - private static SwInterfaceDetails detailZero() { - SwInterfaceDetails detail1 = new SwInterfaceDetails(); - detail1.swIfIndex = 0; - detail1.interfaceName = IFACE_0.getBytes(); - return detail1; - } - - private SwInterfaceDetailsReplyDump specificReplyThree() { - final SwInterfaceDetailsReplyDump reply = new SwInterfaceDetailsReplyDump(); - reply.swInterfaceDetails = Arrays.asList(detailThree()); - return reply; - } - - private SwInterfaceDetailsReplyDump specificReplyZero() { - final SwInterfaceDetailsReplyDump reply = new SwInterfaceDetailsReplyDump(); - reply.swInterfaceDetails = Arrays.asList(detailZero()); - return reply; - } - - private static SwInterfaceDump specificRequest(final String ifaceName) { - final SwInterfaceDump specificRequest = new SwInterfaceDump(); - specificRequest.swIfIndex = new InterfaceIndex(); - specificRequest.swIfIndex.interfaceindex =~0; - specificRequest.nameFilterValid = 1; - specificRequest.nameFilter = ifaceName.getBytes(); - return specificRequest; - } - - private static SwInterfaceDump fullRequest() { - final SwInterfaceDump fullRequest = new SwInterfaceDump(); - fullRequest.swIfIndex = new InterfaceIndex(); - fullRequest.swIfIndex.interfaceindex = ~0; - fullRequest.nameFilterValid = 0; - fullRequest.nameFilter = "".getBytes(); - return fullRequest; - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/pbb/PbbRewriteStateCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/pbb/PbbRewriteStateCustomizerTest.java deleted file mode 100644 index 07ace6b6a..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/pbb/PbbRewriteStateCustomizerTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate.pbb; - -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.PbbRewriteStateInterfaceAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces.state._interface.PbbRewriteState; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces.state._interface.PbbRewriteStateBuilder; - -public class PbbRewriteStateCustomizerTest extends ReaderCustomizerTest { - - public PbbRewriteStateCustomizerTest() { - super(PbbRewriteState.class, PbbRewriteStateInterfaceAugmentationBuilder.class); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new PbbRewriteStateCustomizer(api); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/span/MirroredInterfacesCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/span/MirroredInterfacesCustomizerTest.java deleted file mode 100644 index c13775c75..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/span/MirroredInterfacesCustomizerTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfacesstate.span; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.hasSize; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.jvpp.core.dto.SwInterfaceSpanDetails; -import io.fd.jvpp.core.dto.SwInterfaceSpanDetailsReplyDump; -import java.util.Arrays; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.SpanState; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.Span; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.state._interface.SpanBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.state.attributes.MirroredInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.state.attributes.MirroredInterfacesBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.state.attributes.mirrored.interfaces.MirroredInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.state.attributes.mirrored.interfaces.MirroredInterfaceBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.state.attributes.mirrored.interfaces.MirroredInterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - - -public class MirroredInterfacesCustomizerTest - extends ReaderCustomizerTest { - - private static final String IFACE_NAME = "iface"; - - private static final String SRC_IFACE_NAME_1 = "src-one"; - private static final String SRC_IFACE_NAME_2 = "src-two"; - private static final String SRC_IFACE_NAME_3 = "src-three"; - - private static final int IFACE_INDEX = 3; - - private NamingContext interfaceContext; - private InstanceIdentifier validId; - private MirroredInterface validData; - - public MirroredInterfacesCustomizerTest() { - super(MirroredInterfaces.class, SpanBuilder.class); - } - - @Override - protected void setUp() throws Exception { - interfaceContext = new NamingContext("iface", "iface-context"); - defineMapping(mappingContext, IFACE_NAME, IFACE_INDEX, "iface-context"); - defineMapping(mappingContext, SRC_IFACE_NAME_1, 1, "iface-context"); - defineMapping(mappingContext, SRC_IFACE_NAME_2, 2, "iface-context"); - defineMapping(mappingContext, SRC_IFACE_NAME_3, 3, "iface-context"); - - validId = InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(VppInterfaceStateAugmentation.class).child(Span.class) - .child(MirroredInterfaces.class); - - SwInterfaceSpanDetailsReplyDump dump = new SwInterfaceSpanDetailsReplyDump(); - SwInterfaceSpanDetails detail1 = new SwInterfaceSpanDetails(); - - detail1.swIfIndexTo = IFACE_INDEX; - detail1.swIfIndexFrom = 1; - detail1.state = 1; - - SwInterfaceSpanDetails detail2 = new SwInterfaceSpanDetails(); - - detail2.swIfIndexTo = IFACE_INDEX; - detail2.swIfIndexFrom = 2; - detail2.state = 3; - - SwInterfaceSpanDetails detail3 = new SwInterfaceSpanDetails(); - - detail3.swIfIndexTo = IFACE_INDEX; - detail3.swIfIndexFrom = 3; - detail3.state = 0; - - dump.swInterfaceSpanDetails = Arrays.asList(detail1, detail2, detail3); - - when(api.swInterfaceSpanDump(any())).thenReturn(future(dump)); - } - - @Test - public void readCurrentAttributes() throws Exception { - MirroredInterfacesBuilder builder = new MirroredInterfacesBuilder(); - getCustomizer().readCurrentAttributes(validId, builder, ctx); - - final MirroredInterfaces data = builder.build(); - // 1,2 should be returned,0 should be filtered out because of disabled state - - assertThat(data.getMirroredInterface(), hasSize(2)); - assertThat(data.getMirroredInterface(), containsInAnyOrder( - mirroredInterface(SRC_IFACE_NAME_1, SpanState.Receive), - mirroredInterface(SRC_IFACE_NAME_2, SpanState.Both))); - } - - private MirroredInterface mirroredInterface(final String ifaceName, final SpanState state) { - return new MirroredInterfaceBuilder() - .setIfaceRef(ifaceName) - .withKey(new MirroredInterfaceKey(ifaceName)) - .setState(state) - .build(); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new InterfaceMirroredInterfacesCustomizer(api, interfaceContext); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/notification/InterfaceChangeNotificationProducerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/notification/InterfaceChangeNotificationProducerTest.java index f52bc45fe..e6007e7de 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/notification/InterfaceChangeNotificationProducerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/notification/InterfaceChangeNotificationProducerTest.java @@ -38,7 +38,7 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.InterfaceStateChange; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.InterfaceChange; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.InterfaceStatus; public class InterfaceChangeNotificationProducerTest implements FutureProducer, NamingContextHelper { @@ -101,8 +101,8 @@ public class InterfaceChangeNotificationProducerTest implements FutureProducer, swInterfaceSetFlagsNotification.adminUpDown = 1; swInterfaceSetFlagsNotification.linkUpDown = 1; callbackArgumentCaptor.getValue().onSwInterfaceEvent(swInterfaceSetFlagsNotification); - final ArgumentCaptor notificationCaptor = - ArgumentCaptor.forClass(InterfaceStateChange.class); + final ArgumentCaptor notificationCaptor = + ArgumentCaptor.forClass(InterfaceChange.class); verify(collector).onNotification(notificationCaptor.capture()); assertEquals(IFACE_NAME, notificationCaptor.getValue().getName().getString()); diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/AfPacketCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/AfPacketCustomizerTest.java new file mode 100644 index 000000000..1719f1c20 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/AfPacketCustomizerTest.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2018 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static io.fd.hc2vpp.v3po.read.AfPacketCustomizer.getCfgId; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.read.InitializingReaderCustomizerTest; +import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.core.dto.AfPacketDetails; +import io.fd.jvpp.core.dto.AfPacketDetailsReplyDump; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import java.util.Collections; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacket; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacketBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class AfPacketCustomizerTest extends InitializingReaderCustomizerTest + implements InterfaceDumpHelper { + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IF_NAME = "host-veth1"; + private static final int IF_INDEX = 1; + private static final InstanceIdentifier IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(AfPacket.class); + + private NamingContext interfaceContext; + + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + + public AfPacketCustomizerTest() { + super(AfPacket.class, VppInterfaceAugmentationBuilder.class); + } + + @Override + protected void setUp() throws Exception { + interfaceContext = new NamingContext("generatedInterfaceName", IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new AfPacketCustomizer(api, interfaceContext, dumpCacheManager); + } + + @Test + public void testRead() throws ReadFailedException { + final AfPacketBuilder builder = mock(AfPacketBuilder.class); + when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)).thenReturn(ifaceDetails()); + when(api.afPacketDump(any())).thenReturn(future(afPacketReplyDump())); + + getCustomizer().readCurrentAttributes(IID, builder, ctx); + + verify(builder).setMac(new PhysAddress("01:02:03:04:05:06")); + } + + @Test + public void testReadFailed() throws ReadFailedException { + final AfPacketBuilder builder = mock(AfPacketBuilder.class); + when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)).thenReturn(null); + + getCustomizer().readCurrentAttributes(IID, builder, ctx); + + verifyZeroInteractions(builder); + } + + @Test + public void testInit() { + final AfPacket operData = new AfPacketBuilder() + .setHostInterfaceName(IF_NAME) + .setMac(new PhysAddress("11:22:33:44:55:66")).build(); + final org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacket + cfgData = + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacketBuilder() + .setHostInterfaceName(IF_NAME) + .setMac(new PhysAddress("11:22:33:44:55:66")).build(); + invokeInitTest(IID, operData, getCfgId(IID), cfgData); + } + + private SwInterfaceDetails ifaceDetails() { + final SwInterfaceDetails details = new SwInterfaceDetails(); + details.swIfIndex = IF_INDEX; + details.interfaceName = IF_NAME.getBytes(); + details.l2Address = new byte[] {1, 2, 3, 4, 5, 6}; + return details; + } + + private AfPacketDetailsReplyDump afPacketReplyDump() { + final AfPacketDetailsReplyDump reply = new AfPacketDetailsReplyDump(); + final AfPacketDetails details0 = new AfPacketDetails(); + details0.swIfIndex = IF_INDEX; + details0.hostIfName = IF_NAME.getBytes(); + reply.afPacketDetails = Collections.singletonList(details0); + return reply; + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/EthernetCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/EthernetCustomizerTest.java new file mode 100644 index 000000000..33246b63f --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/EthernetCustomizerTest.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.EthernetBaseAttributes; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Ethernet; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.EthernetBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class EthernetCustomizerTest extends ReaderCustomizerTest implements + InterfaceDumpHelper { + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IF_NAME = "local0"; + private static final int IF_INDEX = 1; + private static final InstanceIdentifier IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(Ethernet.class); + private NamingContext interfaceContext; + + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + + public EthernetCustomizerTest() { + super(Ethernet.class, VppInterfaceAugmentationBuilder.class); + } + + @Override + protected void setUp() throws Exception { + interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new EthernetCustomizer(dumpCacheManager); + } + + private void testRead(final int linkDuplex, final EthernetBaseAttributes.Duplex duplex) + throws ReadFailedException { + final EthernetBuilder builder = mock(EthernetBuilder.class); + final short mtu = 123; + when(dumpCacheManager.getInterfaceDetail(any(), any(), any())).thenReturn(ifaceDetails(mtu, linkDuplex)); + getCustomizer().readCurrentAttributes(IID, builder, ctx); + verify(builder).setMtu((int) mtu); + verify(builder).setDuplex(duplex); + } + + private SwInterfaceDetails ifaceDetails(final short mtu, final int duplex) { + final SwInterfaceDetails details = new SwInterfaceDetails(); + details.swIfIndex = IF_INDEX; + details.linkMtu = mtu; + details.linkDuplex = (byte) duplex; + return details; + } + + @Test + public void testReadHalfDuplex() throws ReadFailedException { + testRead(1, EthernetBaseAttributes.Duplex.Half); + } + + @Test + public void testReadFullDuplex() throws ReadFailedException { + testRead(2, EthernetBaseAttributes.Duplex.Full); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/GreCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/GreCustomizerTest.java new file mode 100644 index 000000000..48decf256 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/GreCustomizerTest.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; + +import com.google.common.collect.Lists; +import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.VppInvocationException; +import io.fd.jvpp.core.dto.GreTunnelDetails; +import io.fd.jvpp.core.dto.GreTunnelDetailsReplyDump; +import io.fd.jvpp.core.dto.GreTunnelDump; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import io.fd.jvpp.core.types.GreTunnel; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Gre; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.GreBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class GreCustomizerTest extends ReaderCustomizerTest implements AddressTranslator { + + private static final String IFACE_NAME = "ifc1"; + private static final int IFACE_ID = 0; + private static final String IFC_CTX_NAME = "ifc-test-instance"; + + private NamingContext interfacesContext; + static final InstanceIdentifier IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(Gre.class); + + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + + public GreCustomizerTest() { + super(Gre.class, VppInterfaceAugmentationBuilder.class); + } + + @Override + public void setUp() throws VppInvocationException, ReadFailedException { + interfacesContext = new NamingContext("gre-tunnel", IFC_CTX_NAME); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + + final SwInterfaceDetails v = new SwInterfaceDetails(); + v.interfaceName = "gre-tunnel4".getBytes(); + + when(dumpCacheManager.getInterfaceDetail(IID, ctx, IFACE_NAME)).thenReturn(v); + + final GreTunnelDetailsReplyDump value = new GreTunnelDetailsReplyDump(); + final GreTunnelDetails greTunnelDetails = new GreTunnelDetails(); + greTunnelDetails.tunnel = new GreTunnel(); + greTunnelDetails.tunnel.isIpv6 = 0; + greTunnelDetails.tunnel.dst = ipv4AddressToAddress(new Ipv4Address("1.2.3.4")); + greTunnelDetails.tunnel.src = ipv4AddressToAddress(new Ipv4Address("1.2.3.5")); + greTunnelDetails.tunnel.outerFibId = 55; + greTunnelDetails.tunnel.swIfIndex = 0; + value.greTunnelDetails = Lists.newArrayList(greTunnelDetails); + + doReturn(future(value)).when(api).greTunnelDump(any(GreTunnelDump.class)); + } + + @Test + public void testReadCurrentAttributes() throws Exception { + final GreBuilder builder = getCustomizer().getBuilder(IID); + getCustomizer().readCurrentAttributes(IID, builder, ctx); + + assertEquals(55, builder.getOuterFibId().intValue()); + + assertNull(builder.getSrc().getIpv6AddressNoZone()); + assertNotNull(builder.getSrc().getIpv4AddressNoZone()); + assertEquals("1.2.3.5", builder.getSrc().getIpv4AddressNoZone().getValue()); + + assertNull(builder.getDst().getIpv6AddressNoZone()); + assertNotNull(builder.getDst().getIpv4AddressNoZone()); + assertEquals("1.2.3.4", builder.getDst().getIpv4AddressNoZone().getValue()); + + verify(api).greTunnelDump(any(GreTunnelDump.class)); + } + + @Test + public void testReadCurrentAttributesWrongType() throws Exception { + final SwInterfaceDetails v = new SwInterfaceDetails(); + v.interfaceName = "tap-2".getBytes(); + + when(dumpCacheManager.getInterfaceDetail(IID, ctx, IFACE_NAME)).thenReturn(v); + + final GreBuilder builder = getCustomizer().getBuilder(IID); + getCustomizer().readCurrentAttributes(IID, builder, ctx); + verifyZeroInteractions(api); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new GreCustomizer(api, interfacesContext, dumpCacheManager); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/InterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/InterfaceCustomizerTest.java new file mode 100644 index 000000000..05d4bc2f9 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/InterfaceCustomizerTest.java @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; +import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.DisabledInterfacesManager; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import io.fd.jvpp.core.dto.SwInterfaceDump; +import io.fd.jvpp.core.types.InterfaceIndex; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceCustomizerTest extends ListReaderCustomizerTest + implements InterfaceDataTranslator, InterfaceDumpHelper { + + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IFACE0_NAME = "eth0"; + private static final String IFACE1_NAME = "eth1"; + private static final String SUB_IFACE_NAME = "eth1.1"; + private static final int IFACE0_ID = 0; + private static final int IFACE1_ID = 1; + private static final int SUB_IFACE_ID = 2; + + private NamingContext interfacesContext; + @Mock + private DisabledInterfacesManager interfaceDisableContext; + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + + public InterfaceCustomizerTest() { + super(Interface.class, InterfacesBuilder.class); + } + + @Override + public void setUp() { + interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + defineMapping(mappingContext, IFACE0_NAME, IFACE0_ID, IFC_CTX_NAME); + defineMapping(mappingContext, IFACE1_NAME, IFACE1_ID, IFC_CTX_NAME); + defineMapping(mappingContext, SUB_IFACE_NAME, SUB_IFACE_ID, IFC_CTX_NAME); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new InterfaceCustomizer(interfacesContext, interfaceDisableContext, dumpCacheManager); + } + + private void assertIfacesAreEqual(final Interface iface, final SwInterfaceDetails details) { + assertEquals(iface.getName(), new String(details.interfaceName)); + assertEquals(yangIfIndexToVpp(iface.getIfIndex().intValue()), details.swIfIndex); + assertEquals(iface.getPhysAddress().getValue(), vppPhysAddrToYang(details.l2Address)); + } + + @Test + public void testReadCurrentAttributes() throws Exception { + final InstanceIdentifier id = InstanceIdentifier.create(Interfaces.class) + .child(Interface.class, new InterfaceKey(IFACE0_NAME)); + final InterfaceBuilder builder = getCustomizer().getBuilder(id); + + final SwInterfaceDetails iface = new SwInterfaceDetails(); + iface.interfaceName = IFACE0_NAME.getBytes(); + iface.swIfIndex = 0; + iface.linkSpeed = 1; + iface.l2AddressLength = 6; + iface.l2Address = new byte[iface.l2AddressLength]; + when(dumpCacheManager.getInterfaceDetail(id, ctx, IFACE0_NAME)).thenReturn(iface); + + getCustomizer().readCurrentAttributes(id, builder, ctx); + + final SwInterfaceDump request = new SwInterfaceDump(); + request.swIfIndex = new InterfaceIndex(); + request.swIfIndex.interfaceindex =~0; + request.nameFilter = IFACE0_NAME.getBytes(); + request.nameFilterValid = 1; + + assertIfacesAreEqual(builder.build(), iface); + verify(dumpCacheManager, times(1)).getInterfaceDetail(id, ctx, IFACE0_NAME); + } + + @Test + public void testReadSubInterface() throws Exception { + final InstanceIdentifier id = InstanceIdentifier.create(Interfaces.class) + .child(Interface.class, new InterfaceKey(SUB_IFACE_NAME)); + final InterfaceBuilder builder = mock(InterfaceBuilder.class); + + final SwInterfaceDetails iface = new SwInterfaceDetails(); + iface.interfaceName = SUB_IFACE_NAME.getBytes(); + iface.swIfIndex = 2; + iface.supSwIfIndex = 1; + iface.subId = 1; + when(dumpCacheManager.getInterfaceDetail(id, ctx, SUB_IFACE_NAME)).thenReturn(iface); + + getCustomizer().readCurrentAttributes(id, builder, ctx); + + final SwInterfaceDump request = new SwInterfaceDump(); + request.swIfIndex = new InterfaceIndex(); + request.swIfIndex.interfaceindex =~0; + request.nameFilter = SUB_IFACE_NAME.getBytes(); + request.nameFilterValid = 1; + + verifyZeroInteractions(builder); + verify(dumpCacheManager, times(1)).getInterfaceDetail(id, ctx, SUB_IFACE_NAME); + } + + @Test + public void testGetAllIds() throws Exception { + final InstanceIdentifier id = InstanceIdentifier.create(Interfaces.class) + .child(Interface.class); + + final SwInterfaceDetails swIf0 = new SwInterfaceDetails(); + swIf0.swIfIndex = 0; + swIf0.supSwIfIndex = 0; + swIf0.interfaceName = IFACE0_NAME.getBytes(); + final SwInterfaceDetails swIf1 = new SwInterfaceDetails(); + swIf1.swIfIndex = 1; + swIf1.supSwIfIndex = 1; + swIf1.interfaceName = IFACE1_NAME.getBytes(); + final SwInterfaceDetails swSubIf1 = new SwInterfaceDetails(); + swSubIf1.swIfIndex = 2; + swSubIf1.subId = 1; + swSubIf1.supSwIfIndex = 1; + swSubIf1.interfaceName = SUB_IFACE_NAME.getBytes(); + when(dumpCacheManager.getInterfaces(id, ctx)).thenReturn(Stream.of(swIf0, swIf1, swSubIf1)); + + final List expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME), new InterfaceKey( + IFACE1_NAME)); + final List actualIds = getCustomizer().getAllIds(id, ctx); + + final SwInterfaceDump request = new SwInterfaceDump(); + request.swIfIndex = new InterfaceIndex(); + request.swIfIndex.interfaceindex = ~0; + request.nameFilter = "".getBytes(); + request.nameFilterValid = 0; + + // sub-interface should not be on the list + assertEquals(expectedIds, actualIds); + verify(dumpCacheManager, times(1)).getInterfaces(id, ctx); + } + + @Test + public void testGetAllIdsWithDisabled() throws Exception { + final InstanceIdentifier id = InstanceIdentifier.create(Interfaces.class) + .child(Interface.class); + + doReturn(true).when(interfaceDisableContext).isInterfaceDisabled(1, mappingContext); + + final SwInterfaceDetails swIf0 = new SwInterfaceDetails(); + swIf0.swIfIndex = 0; + swIf0.interfaceName = IFACE0_NAME.getBytes(); + final SwInterfaceDetails swIf1 = new SwInterfaceDetails(); + swIf1.swIfIndex = 1; + swIf1.interfaceName = IFACE1_NAME.getBytes(); + when(dumpCacheManager.getInterfaces(id, ctx)).thenReturn(Stream.of(swIf0, swIf1)); + + final List expectedIds = Arrays.asList(new InterfaceKey(IFACE0_NAME)); + final List actualIds = getCustomizer().getAllIds(id, ctx); + + // disabled interface should not be on the list + assertEquals(expectedIds, actualIds); + verify(dumpCacheManager, times(1)).getInterfaces(id, ctx); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/InterfaceDataTranslatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/InterfaceDataTranslatorTest.java new file mode 100644 index 000000000..6022f733c --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/InterfaceDataTranslatorTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import java.nio.charset.StandardCharsets; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.AfPacket; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.TapV2; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUser; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeTunnel; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanTunnel; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev180703.EthernetCsmacd; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceDataTranslatorTest implements InterfaceDataTranslator { + + @Test + public void testVppPhysAddrToYang() throws Exception { + assertEquals("01:02:03:04:05:06", vppPhysAddrToYang(new byte[] {1, 2, 3, 4, 5, 6})); + // Extended (64-bit) MAC addresses are currently not supported (it might require yang model update), + // so test if extended part is ignored + assertEquals("0a:0b:0c:0d:0e:0f", vppPhysAddrToYang(new byte[] {0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 0})); + } + + @Test(expected = NullPointerException.class) + public void testVppPhysAddrToYangFailNullArgument() throws Exception { + vppPhysAddrToYang(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testVppPhysAddrToYangInvalidByteArrayLength() throws Exception { + vppPhysAddrToYang(new byte[] {1, 2, 3, 4, 5}); + } + + @Test + public void testGetInterfaceType() { + assertEquals(TapV2.class, getInterfaceType("tap0")); + assertEquals(VxlanTunnel.class, getInterfaceType("vxlan0")); + assertEquals(VxlanGpeTunnel.class, getInterfaceType("vxlan_gpe0")); + assertEquals(VhostUser.class, getInterfaceType("VirtualEthernet0/0/0")); + assertEquals(AfPacket.class, getInterfaceType("host-veth0")); + assertEquals(EthernetCsmacd.class, getInterfaceType("eth0.0")); + assertEquals(EthernetCsmacd.class, getInterfaceType("local0")); + } + + @Test + public void testIsInterfaceOfType() { + assertTrue(isInterfaceOfType(TapV2.class, interfaceDetails("tap0"))); + assertTrue(isInterfaceOfType(VxlanTunnel.class, interfaceDetails("vxlan0"))); + assertTrue(isInterfaceOfType(VxlanGpeTunnel.class, interfaceDetails("vxlan_gpe0"))); + assertTrue(isInterfaceOfType(VhostUser.class, interfaceDetails("VirtualEthernet0/0/0"))); + assertTrue(isInterfaceOfType(AfPacket.class, interfaceDetails("host-veth0"))); + assertTrue(isInterfaceOfType(EthernetCsmacd.class, interfaceDetails("eth0.0"))); + assertTrue(isInterfaceOfType(EthernetCsmacd.class, interfaceDetails("local0"))); + } + + @Test + public void testIsInterfaceOfTypeMissingIfc() throws ReadFailedException { + final InterfaceCacheDumpManager dumpManager = mock(InterfaceCacheDumpManager.class); + final ReadContext ctx = mock(ReadContext.class); + final String ifcName = "tapThatDoesNotExists"; + final InstanceIdentifier id = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(ifcName)); + + when(dumpManager.getInterfaceDetail(id, ctx, ifcName)).thenReturn(null); + + assertFalse(isInterfaceOfType(dumpManager, id, ctx, TapV2.class)); + } + + private SwInterfaceDetails interfaceDetails(final String interfaceName) { + final SwInterfaceDetails details = new SwInterfaceDetails(); + details.interfaceName = interfaceName.getBytes(StandardCharsets.UTF_8); + return details; + } + + +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/InterfaceRoutingCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/InterfaceRoutingCustomizerTest.java new file mode 100644 index 000000000..290836bf3 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/InterfaceRoutingCustomizerTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.core.dto.SwInterfaceGetTableReply; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Routing; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.RoutingBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceRoutingCustomizerTest extends ReaderCustomizerTest { + + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IF_NAME = "local0"; + private static final int IF_ID = 1; + private static final Long IP4_VRF_ID = 1L; + private static final Long IP6_VRF_ID = 2L; + + private NamingContext interfacesContext; + + public InterfaceRoutingCustomizerTest() { + super(Routing.class, VppInterfaceAugmentationBuilder.class); + } + + @Override + public void setUp() { + interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_ID, IFC_CTX_NAME); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new InterfaceRoutingCustomizer(api, interfacesContext); + } + + private InstanceIdentifier getRoutingId(final String name) { + return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)) + .augmentation(VppInterfaceAugmentation.class).child(Routing.class); + } + + @Test + public void testRead() throws Exception { + final RoutingBuilder builder = mock(RoutingBuilder.class); + when(api.swInterfaceGetTable(any())).thenReturn(future(tableReply(IP4_VRF_ID))).thenReturn(future(tableReply(IP6_VRF_ID))); + getCustomizer().readCurrentAttributes(getRoutingId(IF_NAME), builder, ctx); + + verify(builder).setIpv4VrfId(new VniReference(IP4_VRF_ID)); + verify(builder).setIpv6VrfId(new VniReference(IP6_VRF_ID)); + } + + @Test + public void testReadRoutingNotDefined() throws Exception { + final RoutingBuilder builder = mock(RoutingBuilder.class); + final Long vrfId = 0L; + when(api.swInterfaceGetTable(any())).thenReturn(future(tableReply(vrfId))); + getCustomizer().readCurrentAttributes(getRoutingId(IF_NAME), builder, ctx); + verifyZeroInteractions(builder); + } + + private SwInterfaceGetTableReply tableReply(final Long vrfId) { + final SwInterfaceGetTableReply reply = new SwInterfaceGetTableReply(); + reply.vrfId = vrfId.intValue(); + return reply; + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/InterfaceStatisticsCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/InterfaceStatisticsCustomizerTest.java new file mode 100644 index 000000000..fc4e99d9c --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/InterfaceStatisticsCustomizerTest.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2019 PANTHEON.tech. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceStatisticsManager; +import io.fd.hc2vpp.v3po.read.cache.InterfaceStatisticsManagerImpl; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.stats.dto.InterfaceStatistics; +import io.fd.jvpp.stats.dto.InterfaceStatisticsDetails; +import io.fd.jvpp.stats.dto.InterfaceStatisticsDetailsReplyDump; +import io.fd.jvpp.stats.future.FutureJVppStatsFacade; +import java.util.Optional; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.naming.context.rev160513.contexts.naming.context.mappings.MappingBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces._interface.Statistics; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces._interface.StatisticsBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceStatisticsCustomizerTest extends ReaderCustomizerTest { + + private static final String IFC_CTX_NAME = "ifc-test-stats-instance"; + private static final String IF_NAME = "testIfc"; + private static final int SW_IF_INDEX = 1; + private static final int OUT_ERRORS = 2; + private static final int OUT_MULTI = 3; + private static final int OUT_UNI = 4; + private static final int OUT_BROAD = 5; + private static final int OUT_BYTES = 6; + private static final int IN_ERRORS = 22; + private static final int IN_MULTI = 33; + private static final int IN_UNI = 44; + private static final int IN_BROAD = 55; + private static final int IN_BYTES = 66; + private NamingContext interfaceContext; + private static final InstanceIdentifier IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .child(Statistics.class); + @Mock + private FutureJVppStatsFacade jvppStats; + + private InterfaceStatisticsManager statisticsManager; + + public InterfaceStatisticsCustomizerTest() { + super(Statistics.class, InterfaceBuilder.class); + } + + @Override + public void setUp() { + interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + interfaceContext.addName(1, IF_NAME, ctx.getMappingContext()); + } + + @Override + protected ReaderCustomizer initCustomizer() { + statisticsManager = new InterfaceStatisticsManagerImpl(); + return new InterfaceStatisticsCustomizer(interfaceContext, jvppStats, statisticsManager); + } + + @Test + public void testReadStatistics() throws Exception { + statisticsManager.enableStatistics(); + when(ctx.getMappingContext().read(any())) + .thenReturn(Optional.of(new MappingBuilder().setName(IF_NAME).setIndex(SW_IF_INDEX).build())); + when(jvppStats.interfaceStatisticsDump(any())).thenReturn(future(getStatistics())); + StatisticsBuilder statBuilder = new StatisticsBuilder(); + getCustomizer().readCurrentAttributes(IID, statBuilder, ctx); + Statistics stat = statBuilder.build(); + int[] expected = new int[]{SW_IF_INDEX, OUT_ERRORS, OUT_MULTI, OUT_UNI, OUT_BROAD, + OUT_BYTES, IN_ERRORS, IN_MULTI, IN_UNI, IN_BROAD, IN_BYTES}; + int[] actual = new int[]{interfaceContext.getIndex(IF_NAME, ctx.getMappingContext()), + stat.getOutErrors().getValue().intValue(), stat.getOutMulticastPkts().getValue().intValue(), + stat.getOutUnicastPkts().getValue().intValue(), stat.getOutBroadcastPkts().getValue().intValue(), + stat.getOutOctets().getValue().intValue(), stat.getInErrors().getValue().intValue(), + stat.getInMulticastPkts().getValue().intValue(), stat.getInUnicastPkts().getValue().intValue(), + stat.getInBroadcastPkts().getValue().intValue(), stat.getInOctets().getValue().intValue()}; + + Assert.assertArrayEquals(expected, actual); + } + + @Test(expected = ReadFailedException.class) + public void testReadStatisticsFailed() throws Exception { + statisticsManager.enableStatistics(); + when(ctx.getMappingContext().read(any())) + .thenReturn(Optional.of(new MappingBuilder().setName(IF_NAME).setIndex(SW_IF_INDEX).build())); + when(jvppStats.interfaceStatisticsDump(any())).thenReturn(future(null)); + StatisticsBuilder statBuilder = new StatisticsBuilder(); + getCustomizer().readCurrentAttributes(IID, statBuilder, ctx); + } + + private InterfaceStatisticsDetailsReplyDump getStatistics() { + InterfaceStatisticsDetailsReplyDump dumpReply = new InterfaceStatisticsDetailsReplyDump(); + dumpReply.interfaceStatisticsDetails = new InterfaceStatisticsDetails(1, 1); + dumpReply.interfaceStatisticsDetails.interfaceStatistics[0] = + new InterfaceStatistics(SW_IF_INDEX, OUT_ERRORS, OUT_MULTI, OUT_UNI, OUT_BROAD, + OUT_BYTES, IN_ERRORS, IN_MULTI, IN_UNI, IN_BROAD, IN_BYTES); + return dumpReply; + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/L2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/L2CustomizerTest.java new file mode 100644 index 000000000..7e1de173f --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/L2CustomizerTest.java @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.core.dto.BridgeDomainDetails; +import io.fd.jvpp.core.dto.BridgeDomainDetailsReplyDump; +import io.fd.jvpp.core.dto.BridgeDomainDump; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import io.fd.jvpp.core.types.BridgeDomainSwIf; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2Builder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.Interconnection; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.BridgeBasedBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class L2CustomizerTest extends ReaderCustomizerTest { + + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String BD_CTX_NAME = "bd-test-instance"; + private NamingContext interfaceContext; + private NamingContext bridgeDomainContext; + + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + + public L2CustomizerTest() { + super(L2.class, VppInterfaceAugmentationBuilder.class); + } + + @Override + public void setUp() { + interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + bridgeDomainContext = new NamingContext("generatedBDName", BD_CTX_NAME); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new L2Customizer(api, interfaceContext, bridgeDomainContext, dumpCacheManager); + } + + private InstanceIdentifier getL2Id(final String name) { + return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)) + .augmentation(VppInterfaceAugmentation.class).child(L2.class); + } + + private void whenBridgeDomainDumpThenReturn(final List bridgeDomainDetails) { + final BridgeDomainDetailsReplyDump reply = new BridgeDomainDetailsReplyDump(); + reply.bridgeDomainDetails = bridgeDomainDetails; + when(api.bridgeDomainDump(any(BridgeDomainDump.class))).thenReturn(future(reply)); + } + + + private BridgeDomainSwIf generateBdSwIfDetails(final int ifId) { + final BridgeDomainSwIf bdSwIfDetails = new BridgeDomainSwIf(); + bdSwIfDetails.swIfIndex = ifId; + bdSwIfDetails.shg = 1; + return bdSwIfDetails; + } + + private Interconnection generateInterconnection(final String bdName, final Boolean bvi) { + final BridgeBasedBuilder bbBuilder = new BridgeBasedBuilder(); + bbBuilder.setBridgeDomain(bdName); + bbBuilder.setSplitHorizonGroup((short) 1); + if (bvi != null) { + bbBuilder.setBridgedVirtualInterface(bvi); + } else { + bbBuilder.setBridgedVirtualInterface(false); // false is default + } + return bbBuilder.build(); + } + + @Test + public void testReadBvi() throws Exception { + final int ifId = 1; + final int bdId = 1; + final String bdName = "bd001"; + final String ifName = "eth0.sub0"; + defineMapping(mappingContext, ifName, ifId, IFC_CTX_NAME); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + + final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); + ifaceDetails.subId = ifId; + + // BVIinterfaceContext + whenBridgeDomainDumpThenReturn(Collections.singletonList(generateBdDetails(ifId, ifId, bdId))); + + L2Builder builder = mock(L2Builder.class); + getCustomizer().readCurrentAttributes(getL2Id(ifName), builder, ctx); + + verify(builder).setInterconnection(generateInterconnection(bdName, true)); + } + + // split to separate test to avoid using cached value from previous run(cannot mock cache) + @Test + public void testReadNoBvi() throws Exception { + final Map cachedInterfaceDump = new HashMap<>(); + final int ifId = 1; + final int bdId = 1; + final String bdName = "bd001"; + final String ifName = "eth0.sub0"; + defineMapping(mappingContext, ifName, ifId, IFC_CTX_NAME); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + + final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); + ifaceDetails.subId = ifId; + cachedInterfaceDump.put(ifId, ifaceDetails); + + // Not BVI + whenBridgeDomainDumpThenReturn(Collections + .singletonList(generateBdDetails(ifId, 99 /* Different ifc is marked as BVI in bd details */, bdId))); + + L2Builder builder = mock(L2Builder.class); + getCustomizer().readCurrentAttributes(getL2Id(ifName), builder, ctx); + + verify(builder).setInterconnection(generateInterconnection(bdName, null)); + } + + private BridgeDomainDetails generateBdDetails(final int ifId, final int bviSwIfIndex, int bdId) { + final BridgeDomainDetails bridgeDomainDetails = new BridgeDomainDetails(); + bridgeDomainDetails.bviSwIfIndex = bviSwIfIndex; + bridgeDomainDetails.bdId = bdId; + bridgeDomainDetails.swIfDetails = new BridgeDomainSwIf[]{generateBdSwIfDetails(ifId)}; + return bridgeDomainDetails; + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/RewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/RewriteCustomizerTest.java new file mode 100644 index 000000000..e27ef691b --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/RewriteCustomizerTest.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.common.translate.util.TagRewriteOperation; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import java.util.List; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319._802dot1q; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.Rewrite; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.RewriteBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2Builder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.tag.rewrite.PushTags; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class RewriteCustomizerTest extends ReaderCustomizerTest { + + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IF_NAME = "local0"; + private static final String VLAN_IF_NAME = "local0.1"; + private static final int VLAN_IF_INDEX = 11; + private static final int VLAN_ID = 1; + + private NamingContext interfacesContext; + + @Captor + private ArgumentCaptor> captor; + + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + + public RewriteCustomizerTest() { + super(Rewrite.class, L2Builder.class); + } + + @Override + public void setUp() { + interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new RewriteCustomizer(dumpCacheManager); + } + + private InstanceIdentifier getVlanTagRewriteId(final String name, final long index) { + final Class> child = (Class) Rewrite.class; + final InstanceIdentifier id = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)) + .augmentation( + SubinterfaceAugmentation.class).child(SubInterfaces.class) + .child(SubInterface.class, new SubInterfaceKey(index)) + .child(child); + return id; + } + + @Test + public void testRead() throws ReadFailedException { + final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); + ifaceDetails.subId = VLAN_ID; + ifaceDetails.interfaceName = VLAN_IF_NAME.getBytes(); + ifaceDetails.vtrOp = TagRewriteOperation.translate_2_to_2.ordinal(); + ifaceDetails.subNumberOfTags = 2; + ifaceDetails.vtrTag1 = 123; + ifaceDetails.vtrTag2 = 321; + ifaceDetails.vtrPushDot1Q = 1; + ifaceDetails.swIfIndex = VLAN_IF_INDEX; + ifaceDetails.supSwIfIndex = 2; + + final RewriteBuilder builder = mock(RewriteBuilder.class); + final InstanceIdentifier vlanTagRewriteId = getVlanTagRewriteId(IF_NAME, VLAN_ID); + when(dumpCacheManager.getInterfaceDetail(vlanTagRewriteId, ctx, VLAN_IF_NAME)).thenReturn(ifaceDetails); + getCustomizer().readCurrentAttributes(vlanTagRewriteId, builder, ctx); + + verify(builder).setVlanType(_802dot1q.class); + verify(builder).setPopTags((short) 2); + + verify(builder).setPushTags(captor.capture()); + final List tags = captor.getValue(); + assertEquals(ifaceDetails.subNumberOfTags, tags.size()); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/SubInterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/SubInterfaceCustomizerTest.java new file mode 100644 index 000000000..2ce6cd712 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/SubInterfaceCustomizerTest.java @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; +import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import java.util.List; +import java.util.stream.Stream; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfacesBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.VlanTagged; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.Match; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.Tags; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceCustomizerTest + extends ListReaderCustomizerTest implements + InterfaceDumpHelper { + + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String SUPER_IF_NAME = "local0"; + private static final int SUPER_IF_INDEX = 1; + private static final String VLAN_IF_NAME = "local0.1"; + private static final int VLAN_IF_ID = 1; + private static final int VLAN_IF_INDEX = 11; + + private NamingContext interfacesContext; + + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + + public SubInterfaceCustomizerTest() { + super(SubInterface.class, SubInterfacesBuilder.class); + } + + @Override + public void setUp() { + interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + defineMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_INDEX, IFC_CTX_NAME); + defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new SubInterfaceCustomizer(api, interfacesContext, dumpCacheManager); + } + + private InstanceIdentifier getSubInterfaceId(final String name, final long id) { + return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)) + .augmentation( + SubinterfaceAugmentation.class).child( + SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(id)); + } + + @Test + public void testRead() throws ReadFailedException { + + final SwInterfaceDetails ifaceDetails = new SwInterfaceDetails(); + ifaceDetails.subId = VLAN_IF_ID; + ifaceDetails.interfaceName = VLAN_IF_NAME.getBytes(); + ifaceDetails.swIfIndex = 2; + ifaceDetails.supSwIfIndex = SUPER_IF_INDEX; + defineMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_INDEX, IFC_CTX_NAME); + defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_CTX_NAME); + ifaceDetails.subNumberOfTags = 2; + ifaceDetails.subOuterVlanIdAny = 1; + ifaceDetails.subInnerVlanIdAny = 1; + ifaceDetails.subExactMatch = 1; + + final SubInterfaceBuilder builder = mock(SubInterfaceBuilder.class); + final InstanceIdentifier subInterfaceId = getSubInterfaceId(SUPER_IF_NAME, VLAN_IF_ID); + + when(dumpCacheManager.getInterfaceDetail(subInterfaceId, ctx, VLAN_IF_NAME)).thenReturn(ifaceDetails); + getCustomizer().readCurrentAttributes(subInterfaceId, builder, ctx); + + verify(builder).setIdentifier((long) VLAN_IF_ID); + + ArgumentCaptor tagCaptor = ArgumentCaptor.forClass(Tags.class); + verify(builder).setTags(tagCaptor.capture()); + assertEquals(ifaceDetails.subNumberOfTags, tagCaptor.getValue().getTag().size()); + + ArgumentCaptor matchCaptor = ArgumentCaptor.forClass(Match.class); + verify(builder).setMatch(matchCaptor.capture()); + final VlanTagged matchType = (VlanTagged) matchCaptor.getValue().getMatchType(); + assertTrue(matchType.getVlanTagged().isMatchExactTags()); + } + + @Test + public void testGetAllIds() throws Exception { + final SwInterfaceDetails iface = new SwInterfaceDetails(); + iface.interfaceName = VLAN_IF_NAME.getBytes(); + iface.swIfIndex = VLAN_IF_INDEX; + iface.subId = VLAN_IF_ID; + iface.supSwIfIndex = SUPER_IF_INDEX; + + final InstanceIdentifier subInterfaceId = getSubInterfaceId(SUPER_IF_NAME, VLAN_IF_ID); + when(dumpCacheManager.getInterfaces(subInterfaceId, ctx)).thenReturn(Stream.of(iface)); + final List allIds = + getCustomizer().getAllIds(subInterfaceId, ctx); + + assertEquals(1, allIds.size()); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/SubInterfaceL2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/SubInterfaceL2CustomizerTest.java new file mode 100644 index 000000000..53be88c43 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/SubInterfaceL2CustomizerTest.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceL2CustomizerTest extends ReaderCustomizerTest { + + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String BD_CTX_NAME = "bd-test-instance"; + private NamingContext interfaceContext; + private NamingContext bridgeDomainContext; + + private static final String IF_NAME = "local0"; + private static final int IF_INDEX = 1; + private static final String SUB_IF_NAME = "local0.1"; + private static final long SUB_IF_ID = 1; + private static final int SUB_IF_INDEX = 11; + private InstanceIdentifier IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(SubinterfaceAugmentation.class) + .child(SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)) + .child(L2.class); + + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + + public SubInterfaceL2CustomizerTest() { + super(L2.class, SubInterfaceBuilder.class); + } + + @Override + protected void setUp() { + interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + bridgeDomainContext = new NamingContext("generatedBDName", BD_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); + defineMapping(mappingContext, SUB_IF_NAME, SUB_IF_INDEX, IFC_CTX_NAME); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new SubInterfaceL2Customizer(api, interfaceContext, bridgeDomainContext, dumpCacheManager); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/SubInterfaceRoutingCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/SubInterfaceRoutingCustomizerTest.java new file mode 100644 index 000000000..57daac3c4 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/SubInterfaceRoutingCustomizerTest.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.core.dto.SwInterfaceGetTable; +import io.fd.jvpp.core.dto.SwInterfaceGetTableReply; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.Routing; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.RoutingBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceRoutingCustomizerTest extends ReaderCustomizerTest implements + ByteDataTranslator { + + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IF_NAME = "local0"; + private static final int IF_ID = 1; + private static final String SUBIF_NAME = "local0.4"; + private static final int SUBIF_ID = 4; + private static final InstanceIdentifier VALID_ID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(SubinterfaceAugmentation.class) + .child(SubInterfaces.class) + .child(SubInterface.class, new SubInterfaceKey((long) SUBIF_ID)) + .child(Routing.class); + private static final int IPV4_VRF = 4; + private static final int IPV6_VRF = 6; + private static final int NO_VRF = 0; + + private NamingContext interfacesContext; + + public SubInterfaceRoutingCustomizerTest() { + super(Routing.class, SubInterfaceBuilder.class); + } + + @Override + protected void setUp() throws Exception { + interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_ID, IFC_CTX_NAME); + defineMapping(mappingContext, SUBIF_NAME, SUBIF_ID, IFC_CTX_NAME); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new SubInterfaceRoutingCustomizer(api, interfacesContext); + } + + @Test + public void testReadAttributesAllDefined() throws ReadFailedException { + when(api.swInterfaceGetTable(request(false, SUBIF_ID))).thenReturn(future(reply(IPV4_VRF))); + when(api.swInterfaceGetTable(request(true, SUBIF_ID))).thenReturn(future(reply(IPV6_VRF))); + final RoutingBuilder routingBuilder = new RoutingBuilder(); + getCustomizer().readCurrentAttributes(VALID_ID, routingBuilder, ctx); + assertEquals(IPV4_VRF, routingBuilder.getIpv4VrfId().getValue().intValue()); + assertEquals(IPV6_VRF, routingBuilder.getIpv6VrfId().getValue().intValue()); + } + + @Test + public void testReadAttributesOneDefined() throws ReadFailedException { + when(api.swInterfaceGetTable(request(false, SUBIF_ID))).thenReturn(future(reply(IPV4_VRF))); + when(api.swInterfaceGetTable(request(true, SUBIF_ID))).thenReturn(future(reply(NO_VRF))); + final RoutingBuilder routingBuilder = new RoutingBuilder(); + getCustomizer().readCurrentAttributes(VALID_ID, routingBuilder, ctx); + assertEquals(IPV4_VRF, routingBuilder.getIpv4VrfId().getValue().intValue()); + assertNull(routingBuilder.getIpv6VrfId()); + } + + @Test + public void testReadAttributesNoDefined() throws ReadFailedException { + when(api.swInterfaceGetTable(any())).thenReturn(future(reply(NO_VRF))); + final RoutingBuilder routingBuilder = new RoutingBuilder(); + getCustomizer().readCurrentAttributes(VALID_ID, routingBuilder, ctx); + assertNull(routingBuilder.getIpv4VrfId()); + assertNull(routingBuilder.getIpv6VrfId()); + } + + private SwInterfaceGetTable request(final boolean ipv6, final int index) { + SwInterfaceGetTable request = new SwInterfaceGetTable(); + request.isIpv6 = booleanToByte(ipv6); + request.swIfIndex = index; + return request; + } + + private SwInterfaceGetTableReply reply(final int vrf) { + SwInterfaceGetTableReply reply = new SwInterfaceGetTableReply(); + reply.vrfId = vrf; + return reply; + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/TapV2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/TapV2CustomizerTest.java new file mode 100644 index 000000000..66d7c3268 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/TapV2CustomizerTest.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2018 Pantheon Technologies and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; +import io.fd.hc2vpp.common.translate.util.Ipv4Translator; +import io.fd.hc2vpp.common.translate.util.Ipv6Translator; +import io.fd.hc2vpp.common.translate.util.MacTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import io.fd.jvpp.core.dto.SwInterfaceTapV2Details; +import io.fd.jvpp.core.dto.SwInterfaceTapV2DetailsReplyDump; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class TapV2CustomizerTest extends ReaderCustomizerTest implements InterfaceDumpHelper, + Ipv4Translator, Ipv6Translator, MacTranslator { + + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IF_NAME = "tapV21"; + private static final String DEVICE_NAME = "testTapV2Device"; + private static final int IF_INDEX = 1; + private static final String HOST_BRIDGE = "TestBridge"; + private static final String HOST_IPV4_PREFIX = "192.168.255.100"; + private static final byte HOST_IPV4_PREFIX_LEN = 24; + private static final String HOST_IPV6_PREFIX = "a::100"; + private static final byte HOST_IPV6_PREFIX_LEN = -128; + private static final int HOST_IPV6_PREFIX_LEN_EXP = 128; + private static final int RX_TX_RING_SIZE = 512; + private static final String HOST_MAC = "00:ee:ee:ee:ee:ee"; + private static final String HOST_NAMESPACE = "testHostNS"; + + private static final InstanceIdentifier IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(TapV2.class); + private NamingContext interfaceContext; + + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + + public TapV2CustomizerTest() { + super(TapV2.class, VppInterfaceAugmentationBuilder.class); + } + + @Override + protected void setUp() throws Exception { + interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); + when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)).thenReturn(ifaceDetails()); + } + + private SwInterfaceDetails ifaceDetails() { + final SwInterfaceDetails details = new SwInterfaceDetails(); + details.swIfIndex = IF_INDEX; + details.interfaceName = IF_NAME.getBytes(); + details.tag = new byte[64]; + return details; + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new TapV2Customizer(api, interfaceContext, dumpCacheManager); + } + + @Test + public void testRead() throws ReadFailedException { + final TapV2Builder builder = mock(TapV2Builder.class); + when(api.swInterfaceTapV2Dump(any())).thenReturn(future(tapDump())); + getCustomizer().readCurrentAttributes(IID, builder, ctx); + verify(builder).setHostInterfaceName(IF_NAME); + verify(builder).setDeviceName(DEVICE_NAME); + verify(builder).setHostBridge(HOST_BRIDGE); + verify(builder) + .setHostIpv4Address(new Ipv4Prefix(String.format("%s/%d", HOST_IPV4_PREFIX, HOST_IPV4_PREFIX_LEN))); + verify(builder) + .setHostIpv6Address(new Ipv6Prefix(String.format("%s/%d", HOST_IPV6_PREFIX, HOST_IPV6_PREFIX_LEN_EXP))); + verify(builder).setTxRingSize(RX_TX_RING_SIZE); + verify(builder).setRxRingSize(RX_TX_RING_SIZE); + verify(builder).setHostNamespace(HOST_NAMESPACE); + verify(builder).setHostMac(new PhysAddress(HOST_MAC)); + } + + @Test(expected = ReadFailedException.class) + public void testReadFailed() throws ReadFailedException { + when(api.swInterfaceTapV2Dump(any())).thenReturn(failedFuture()); + getCustomizer().readCurrentAttributes(IID, mock(TapV2Builder.class), ctx); + } + + private SwInterfaceTapV2DetailsReplyDump tapDump() { + final SwInterfaceTapV2DetailsReplyDump reply = new SwInterfaceTapV2DetailsReplyDump(); + final SwInterfaceTapV2Details details = new SwInterfaceTapV2Details(); + details.devName = DEVICE_NAME.getBytes(UTF_8); + details.swIfIndex = IF_INDEX; + details.hostBridge = HOST_BRIDGE.getBytes(UTF_8); + details.hostNamespace = HOST_NAMESPACE.getBytes(UTF_8); + details.hostIfName = IF_NAME.getBytes(UTF_8); + details.hostIp4PrefixLen = HOST_IPV4_PREFIX_LEN; + details.hostIp4Addr = ipv4AddressNoZoneToArray(HOST_IPV4_PREFIX); + details.hostIp6Addr = ipv6AddressNoZoneToArray(new Ipv6AddressNoZone(HOST_IPV6_PREFIX)); + details.hostIp6PrefixLen = HOST_IPV6_PREFIX_LEN; + details.hostMacAddr = parseMac(HOST_MAC); + details.txRingSz = details.rxRingSz = RX_TX_RING_SIZE; + reply.swInterfaceTapV2Details.add(details); + return reply; + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/VhostUserCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/VhostUserCustomizerTest.java new file mode 100644 index 000000000..193676b92 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/VhostUserCustomizerTest.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.test.util.InterfaceDumpHelper; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import io.fd.jvpp.core.dto.SwInterfaceVhostUserDetails; +import io.fd.jvpp.core.dto.SwInterfaceVhostUserDetailsReplyDump; +import java.math.BigInteger; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUserRole; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUser; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUserBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VhostUserCustomizerTest extends ReaderCustomizerTest implements + InterfaceDumpHelper { + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IF_NAME = "VirtualEthernet1"; + private static final int IF_INDEX = 1; + private static final InstanceIdentifier IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(VhostUser.class); + + private NamingContext interfaceContext; + + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + + public VhostUserCustomizerTest() { + super(VhostUser.class, VppInterfaceAugmentationBuilder.class); + } + + @Override + protected void setUp() throws Exception { + interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); + when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)).thenReturn(ifaceDetails()); + } + + private SwInterfaceDetails ifaceDetails() { + final SwInterfaceDetails details = new SwInterfaceDetails(); + details.swIfIndex = IF_INDEX; + details.interfaceName = IF_NAME.getBytes(); + details.tag = new byte[64]; + return details; + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new VhostUserCustomizer(api, interfaceContext, dumpCacheManager); + } + + @Test + public void testRead() throws ReadFailedException { + final VhostUserBuilder builder = mock(VhostUserBuilder.class); + when(api.swInterfaceVhostUserDump(any())).thenReturn(future(vhostDump())); + getCustomizer().readCurrentAttributes(IID, builder, ctx); + verifyVhostBuilder(builder); + } + + @Test(expected = ReadFailedException.class) + public void testReadFailed() throws ReadFailedException { + when(api.swInterfaceVhostUserDump(any())).thenReturn(failedFuture()); + getCustomizer().readCurrentAttributes(IID, mock(VhostUserBuilder.class), ctx); + } + + private SwInterfaceVhostUserDetailsReplyDump vhostDump() { + final SwInterfaceVhostUserDetailsReplyDump reply = new SwInterfaceVhostUserDetailsReplyDump(); + final SwInterfaceVhostUserDetails details = new SwInterfaceVhostUserDetails(); + details.swIfIndex = IF_INDEX; + details.interfaceName = IF_NAME.getBytes(); + details.isServer = 1; + details.features = 2; + details.numRegions = 3; + details.sockFilename = "socketName".getBytes(); + details.virtioNetHdrSz = 4; + details.sockErrno = 5; + reply.swInterfaceVhostUserDetails.add(details); + return reply; + } + + private void verifyVhostBuilder(final VhostUserBuilder builder) { + verify(builder).setRole(VhostUserRole.Server); + verify(builder).setFeatures(BigInteger.valueOf(2)); + verify(builder).setNumMemoryRegions(3L); + verify(builder).setSocket("socketName"); + verify(builder).setVirtioNetHdrSize(4L); + verify(builder).setConnectError("5"); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/VxlanCustomizerTest.java new file mode 100644 index 000000000..482b7d4ac --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/VxlanCustomizerTest.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +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.Mockito.doReturn; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; + +import com.google.common.collect.Lists; +import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.VppInvocationException; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import io.fd.jvpp.core.dto.VxlanTunnelDetails; +import io.fd.jvpp.core.dto.VxlanTunnelDetailsReplyDump; +import io.fd.jvpp.core.dto.VxlanTunnelDump; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.L2Input; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Vxlan; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VxlanCustomizerTest extends ReaderCustomizerTest { + + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IF_NAME = "ifc1"; + private static final int IF_INDEX = 0; + + private NamingContext interfacesContext; + static final InstanceIdentifier IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(Vxlan.class); + + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + + public VxlanCustomizerTest() { + super(Vxlan.class, VppInterfaceAugmentationBuilder.class); + } + + @Override + public void setUp() throws VppInvocationException, ReadFailedException { + interfacesContext = new NamingContext("vxlan-tunnel", IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); + + final SwInterfaceDetails v = new SwInterfaceDetails(); + v.interfaceName = "vxlan-tunnel4".getBytes(); + + when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)).thenReturn(v); + doReturn(future(getVxlanTunnelDetailsReplyDump(55))).when(api).vxlanTunnelDump(any(VxlanTunnelDump.class)); + } + + @Test + public void testRead() throws Exception { + final VxlanBuilder builder = getCustomizer().getBuilder(IID); + getCustomizer().readCurrentAttributes(IID, builder, ctx); + + assertEquals(9, builder.getVni().getValue().intValue()); + assertEquals(55, builder.getEncapVrfId().getValue().intValue()); + assertEquals(L2Input.class, builder.getDecapNext()); + + assertNull(builder.getSrc().getIpv6AddressNoZone()); + assertNotNull(builder.getSrc().getIpv4AddressNoZone()); + assertEquals("1.2.3.5", builder.getSrc().getIpv4AddressNoZone().getValue()); + + assertNull(builder.getDst().getIpv6AddressNoZone()); + assertNotNull(builder.getDst().getIpv4AddressNoZone()); + assertEquals("1.2.3.4", builder.getDst().getIpv4AddressNoZone().getValue()); + + verify(api).vxlanTunnelDump(any(VxlanTunnelDump.class)); + } + + @Test + public void testReadVniOverflow() throws Exception { + final long encapVrfId = 4294967295L; + doReturn(future(getVxlanTunnelDetailsReplyDump((int) encapVrfId))).when(api) + .vxlanTunnelDump(any(VxlanTunnelDump.class)); + final VxlanBuilder builder = getCustomizer().getBuilder(IID); + getCustomizer().readCurrentAttributes(IID, builder, ctx); + + assertEquals(encapVrfId, builder.getEncapVrfId().getValue().longValue()); + verify(api).vxlanTunnelDump(any(VxlanTunnelDump.class)); + } + + @Test(expected = IllegalArgumentException.class) + public void testReadVppNameNotCached() throws Exception { + when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)) + .thenThrow(new IllegalArgumentException("Detail for interface not found")); + + final VxlanBuilder builder = getCustomizer().getBuilder(IID); + getCustomizer().readCurrentAttributes(IID, builder, ctx); + } + + @Test + public void testReadWrongType() throws Exception { + final SwInterfaceDetails v = new SwInterfaceDetails(); + v.interfaceName = "tap-2".getBytes(); + + when(dumpCacheManager.getInterfaceDetail(IID, ctx, IF_NAME)).thenReturn(v); + + final VxlanBuilder builder = getCustomizer().getBuilder(IID); + getCustomizer().readCurrentAttributes(IID, builder, ctx); + + // Should be ignored + verifyZeroInteractions(api); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new VxlanCustomizer(api, interfacesContext, dumpCacheManager); + } + + private static VxlanTunnelDetailsReplyDump getVxlanTunnelDetailsReplyDump(final int encapVrfId) { + final VxlanTunnelDetailsReplyDump replyDump = new VxlanTunnelDetailsReplyDump(); + final VxlanTunnelDetails vxlanTunnelDetails = new VxlanTunnelDetails(); + vxlanTunnelDetails.isIpv6 = 0; + vxlanTunnelDetails.dstAddress = AddressTranslator.INSTANCE.ipv4AddressNoZoneToArray("1.2.3.4"); + vxlanTunnelDetails.srcAddress = AddressTranslator.INSTANCE.ipv4AddressNoZoneToArray("1.2.3.5"); + vxlanTunnelDetails.encapVrfId = encapVrfId; + vxlanTunnelDetails.swIfIndex = 0; + vxlanTunnelDetails.vni = 9; + vxlanTunnelDetails.decapNextIndex = 1; + replyDump.vxlanTunnelDetails = Lists.newArrayList(vxlanTunnelDetails); + return replyDump; + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/VxlanGpeCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/VxlanGpeCustomizerTest.java new file mode 100644 index 000000000..829573877 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/VxlanGpeCustomizerTest.java @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.matches; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; + +import com.google.common.collect.Lists; +import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManager; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.VppBaseCallException; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import io.fd.jvpp.core.dto.VxlanGpeTunnelDetails; +import io.fd.jvpp.core.dto.VxlanGpeTunnelDetailsReplyDump; +import io.fd.jvpp.core.dto.VxlanGpeTunnelDump; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpe; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpeBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VxlanGpeCustomizerTest extends ReaderCustomizerTest + implements AddressTranslator { + + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IF_NAME = "ifc2"; + private static final int IF_INDEX = 0; + + private NamingContext interfacesContext; + private static final InstanceIdentifier VXLAN_GPE_ID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(VxlanGpe.class); + + @Mock + private InterfaceCacheDumpManager dumpCacheManager; + + public VxlanGpeCustomizerTest() { + super(VxlanGpe.class, VppInterfaceAugmentationBuilder.class); + } + + @Override + public void setUp() throws VppBaseCallException, ReadFailedException { + interfacesContext = new NamingContext("vxlan_gpe_inf", IFC_CTX_NAME); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); + + final SwInterfaceDetails v = new SwInterfaceDetails(); + v.interfaceName = "vxlan_gpe_inf2".getBytes(); + + when(dumpCacheManager.getInterfaceDetail(any(), any(), matches(IF_NAME))).thenReturn(v); + + final VxlanGpeTunnelDetailsReplyDump value = new VxlanGpeTunnelDetailsReplyDump(); + final VxlanGpeTunnelDetails vxlanGpeTunnelDetails = new VxlanGpeTunnelDetails(); + vxlanGpeTunnelDetails.isIpv6 = 0; + vxlanGpeTunnelDetails.local = ipv4AddressNoZoneToArray("1.2.3.4"); + vxlanGpeTunnelDetails.remote = ipv4AddressNoZoneToArray("1.2.3.5"); + vxlanGpeTunnelDetails.vni = 9; + vxlanGpeTunnelDetails.protocol = 1; + vxlanGpeTunnelDetails.encapVrfId = 55; + vxlanGpeTunnelDetails.decapVrfId = 66; + vxlanGpeTunnelDetails.swIfIndex = 0; + value.vxlanGpeTunnelDetails = Lists.newArrayList(vxlanGpeTunnelDetails); + doReturn(future(value)).when(api).vxlanGpeTunnelDump(any(VxlanGpeTunnelDump.class)); + } + + @Test + public void testReadCurrentAttributes() throws Exception { + final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID); + getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx); + + assertNull(builder.getLocal().getIpv6AddressNoZone()); + assertNotNull(builder.getLocal().getIpv4AddressNoZone()); + assertEquals("1.2.3.4", builder.getLocal().getIpv4AddressNoZone().getValue()); + + assertNull(builder.getRemote().getIpv6AddressNoZone()); + assertNotNull(builder.getRemote().getIpv4AddressNoZone()); + assertEquals("1.2.3.5", builder.getRemote().getIpv4AddressNoZone().getValue()); + + assertEquals(9, builder.getVni().getValue().intValue()); + assertEquals(1, builder.getNextProtocol().getIntValue()); + assertEquals(55, builder.getEncapVrfId().intValue()); + assertEquals(66, builder.getDecapVrfId().intValue()); + + verify(api).vxlanGpeTunnelDump(any(VxlanGpeTunnelDump.class)); + } + + @Test(expected = IllegalArgumentException.class) + public void testReadCurrentAttributesVppNameNotCached() throws Exception { + when(dumpCacheManager.getInterfaceDetail(VXLAN_GPE_ID, ctx, IF_NAME)) + .thenThrow(new IllegalArgumentException("Detail for interface not found")); + + final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID); + getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx); + } + + @Test + public void testReadCurrentAttributesWrongType() throws Exception { + final SwInterfaceDetails v = new SwInterfaceDetails(); + v.interfaceName = "tap-3".getBytes(); + + when(dumpCacheManager.getInterfaceDetail(VXLAN_GPE_ID, ctx, IF_NAME)).thenReturn(v); + + final VxlanGpeBuilder builder = getCustomizer().getBuilder(VXLAN_GPE_ID); + getCustomizer().readCurrentAttributes(VXLAN_GPE_ID, builder, ctx); + verifyZeroInteractions(api); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new VxlanGpeCustomizer(api, interfacesContext, dumpCacheManager); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerImplTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerImplTest.java new file mode 100644 index 000000000..04b1d999e --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/cache/InterfaceCacheDumpManagerImplTest.java @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read.cache; + +import static io.fd.hc2vpp.v3po.read.cache.InterfaceCacheDumpManagerImpl.BY_NAME_INDEX_KEY; +import static org.junit.Assert.assertEquals; +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 static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.test.util.FutureProducer; +import io.fd.hc2vpp.common.test.util.NamingContextHelper; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.jvpp.core.dto.SwInterfaceDetails; +import io.fd.jvpp.core.dto.SwInterfaceDetailsReplyDump; +import io.fd.jvpp.core.dto.SwInterfaceDump; +import io.fd.jvpp.core.future.FutureJVppCore; +import io.fd.jvpp.core.types.InterfaceIndex; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.stream.Collectors; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceCacheDumpManagerImplTest implements NamingContextHelper, FutureProducer { + + private static final String IFACE_0 = "iface-0"; + private static final String IFACE_1 = "iface-1"; + private static final String IFACE_2 = "iface-2"; + private static final String IFACE_3 = "iface-3"; + + @Mock + private FutureJVppCore jvpp; + @Mock + private ReadContext ctx; + @Mock + private MappingContext mappingContext; + + private InstanceIdentifier identifier; + private InstanceIdentifier identifierThree; + private NamingContext namingContext; + private ModificationCache cache; + private InterfaceCacheDumpManagerImpl manager; + + @Before + public void setUp() throws Exception { + initMocks(this); + namingContext = new NamingContext("interface-", "interface-context"); + cache = new ModificationCache(); + manager = new InterfaceCacheDumpManagerImpl(jvpp, namingContext); + when(ctx.getModificationCache()).thenReturn(cache); + when(ctx.getMappingContext()).thenReturn(mappingContext); + identifier = InstanceIdentifier.create(Interfaces.class) + .child(Interface.class, new InterfaceKey(IFACE_0)); + + identifierThree = InstanceIdentifier.create(Interfaces.class) + .child(Interface.class, new InterfaceKey(IFACE_3)); + + when(jvpp.swInterfaceDump(fullRequest())).thenReturn(future(fullReply())); + + // this one is not in full dump + when(jvpp.swInterfaceDump(specificRequest(IFACE_3))).thenReturn(future(specificReplyThree())); + defineMapping(mappingContext, IFACE_0, 0, "interface-context"); + defineMapping(mappingContext, IFACE_1, 1, "interface-context"); + defineMapping(mappingContext, IFACE_2, 2, "interface-context"); + defineMapping(mappingContext, IFACE_3, 3, "interface-context"); + } + + @Test + public void getInterfaces() throws Exception { + assertFalse(cache.containsKey(BY_NAME_INDEX_KEY)); + final List interfaces = manager.getInterfaces(identifier, ctx).collect(Collectors.toList()); + assertEquals(3, interfaces.size()); + assertTrue(interfaces.contains(detailZero())); + assertTrue(interfaces.contains(detailOne())); + assertTrue(interfaces.contains(detailTwo())); + + // first request must call jvpp + verify(jvpp, times(1)).swInterfaceDump(fullRequest()); + assertTrue(cache.containsKey(BY_NAME_INDEX_KEY)); + + // then cached value should be returned + final List cachedInterfaces = + manager.getInterfaces(identifier, ctx).collect(Collectors.toList()); + assertEquals(3, cachedInterfaces.size()); + assertTrue(cachedInterfaces.contains(detailZero())); + assertTrue(cachedInterfaces.contains(detailOne())); + assertTrue(cachedInterfaces.contains(detailTwo())); + + //verify that dump wasn't invoked again + verifyNoMoreInteractions(jvpp); + } + + @Test + public void getInterfaceDetailFromCache() throws Exception { + final HashMap cachedMap = new HashMap<>(); + final SwInterfaceDetails detailZero = detailZero(); + cachedMap.put(IFACE_0, detailZero); + cache.put(BY_NAME_INDEX_KEY, cachedMap); + when(jvpp.swInterfaceDump(specificRequest(IFACE_0))).thenReturn(future(specificReplyZero())); + final SwInterfaceDetails interfaceDetail = manager.getInterfaceDetail(identifier, ctx, IFACE_0); + assertEquals(detailZero, interfaceDetail); + + // must not call jvpp, just get it from cache + verifyZeroInteractions(jvpp); + } + + @Test + public void getInterfaceDetailNotInFullDump() throws Exception { + assertFalse(cache.containsKey(BY_NAME_INDEX_KEY)); + final SwInterfaceDetails specificDetail = manager.getInterfaceDetail(identifierThree, ctx, IFACE_3); + assertEquals(detailThree(), specificDetail); + + verify(jvpp, times(1)).swInterfaceDump(specificRequest(IFACE_3)); + } + + private SwInterfaceDetailsReplyDump fullReply() { + final SwInterfaceDetailsReplyDump reply = new SwInterfaceDetailsReplyDump(); + reply.swInterfaceDetails = Arrays.asList(detailZero(), detailOne(), detailTwo()); + return reply; + } + + private static SwInterfaceDetails detailTwo() { + SwInterfaceDetails detail3 = new SwInterfaceDetails(); + detail3.swIfIndex = 2; + detail3.interfaceName = IFACE_2.getBytes(); + return detail3; + } + + private static SwInterfaceDetails detailOne() { + SwInterfaceDetails detail2 = new SwInterfaceDetails(); + detail2.swIfIndex = 1; + detail2.interfaceName = IFACE_1.getBytes(); + return detail2; + } + + private static SwInterfaceDetails detailThree() { + SwInterfaceDetails detail2 = new SwInterfaceDetails(); + detail2.swIfIndex = 3; + detail2.interfaceName = IFACE_3.getBytes(); + return detail2; + } + + private static SwInterfaceDetails detailZero() { + SwInterfaceDetails detail1 = new SwInterfaceDetails(); + detail1.swIfIndex = 0; + detail1.interfaceName = IFACE_0.getBytes(); + return detail1; + } + + private SwInterfaceDetailsReplyDump specificReplyThree() { + final SwInterfaceDetailsReplyDump reply = new SwInterfaceDetailsReplyDump(); + reply.swInterfaceDetails = Arrays.asList(detailThree()); + return reply; + } + + private SwInterfaceDetailsReplyDump specificReplyZero() { + final SwInterfaceDetailsReplyDump reply = new SwInterfaceDetailsReplyDump(); + reply.swInterfaceDetails = Arrays.asList(detailZero()); + return reply; + } + + private static SwInterfaceDump specificRequest(final String ifaceName) { + final SwInterfaceDump specificRequest = new SwInterfaceDump(); + specificRequest.swIfIndex = new InterfaceIndex(); + specificRequest.swIfIndex.interfaceindex =~0; + specificRequest.nameFilterValid = 1; + specificRequest.nameFilter = ifaceName.getBytes(); + return specificRequest; + } + + private static SwInterfaceDump fullRequest() { + final SwInterfaceDump fullRequest = new SwInterfaceDump(); + fullRequest.swIfIndex = new InterfaceIndex(); + fullRequest.swIfIndex.interfaceindex = ~0; + fullRequest.nameFilterValid = 0; + fullRequest.nameFilter = "".getBytes(); + return fullRequest; + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/pbb/PbbRewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/pbb/PbbRewriteCustomizerTest.java new file mode 100644 index 000000000..7a5213585 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/pbb/PbbRewriteCustomizerTest.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read.pbb; + +import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.PbbRewriteInterfaceAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewrite; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewriteBuilder; + +public class PbbRewriteCustomizerTest extends ReaderCustomizerTest { + + public PbbRewriteCustomizerTest() { + super(PbbRewrite.class, PbbRewriteInterfaceAugmentationBuilder.class); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new PbbRewriteCustomizer(api); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/span/MirroredInterfacesCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/span/MirroredInterfacesCustomizerTest.java new file mode 100644 index 000000000..eec044bc2 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/read/span/MirroredInterfacesCustomizerTest.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.read.span; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.hasSize; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.jvpp.core.dto.SwInterfaceSpanDetails; +import io.fd.jvpp.core.dto.SwInterfaceSpanDetailsReplyDump; +import java.util.Arrays; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.SpanState; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Span; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.SpanBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfacesBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + + +public class MirroredInterfacesCustomizerTest + extends ReaderCustomizerTest { + + private static final String IFACE_NAME = "iface"; + + private static final String SRC_IFACE_NAME_1 = "src-one"; + private static final String SRC_IFACE_NAME_2 = "src-two"; + private static final String SRC_IFACE_NAME_3 = "src-three"; + + private static final int IFACE_INDEX = 3; + + private NamingContext interfaceContext; + private InstanceIdentifier validId; + private MirroredInterface validData; + + public MirroredInterfacesCustomizerTest() { + super(MirroredInterfaces.class, SpanBuilder.class); + } + + @Override + protected void setUp() throws Exception { + interfaceContext = new NamingContext("iface", "iface-context"); + defineMapping(mappingContext, IFACE_NAME, IFACE_INDEX, "iface-context"); + defineMapping(mappingContext, SRC_IFACE_NAME_1, 1, "iface-context"); + defineMapping(mappingContext, SRC_IFACE_NAME_2, 2, "iface-context"); + defineMapping(mappingContext, SRC_IFACE_NAME_3, 3, "iface-context"); + + validId = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(Span.class) + .child(MirroredInterfaces.class); + + SwInterfaceSpanDetailsReplyDump dump = new SwInterfaceSpanDetailsReplyDump(); + SwInterfaceSpanDetails detail1 = new SwInterfaceSpanDetails(); + + detail1.swIfIndexTo = IFACE_INDEX; + detail1.swIfIndexFrom = 1; + detail1.state = 1; + + SwInterfaceSpanDetails detail2 = new SwInterfaceSpanDetails(); + + detail2.swIfIndexTo = IFACE_INDEX; + detail2.swIfIndexFrom = 2; + detail2.state = 3; + + SwInterfaceSpanDetails detail3 = new SwInterfaceSpanDetails(); + + detail3.swIfIndexTo = IFACE_INDEX; + detail3.swIfIndexFrom = 3; + detail3.state = 0; + + dump.swInterfaceSpanDetails = Arrays.asList(detail1, detail2, detail3); + + when(api.swInterfaceSpanDump(any())).thenReturn(future(dump)); + } + + @Test + public void readCurrentAttributes() throws Exception { + MirroredInterfacesBuilder builder = new MirroredInterfacesBuilder(); + getCustomizer().readCurrentAttributes(validId, builder, ctx); + + final MirroredInterfaces data = builder.build(); + // 1,2 should be returned,0 should be filtered out because of disabled state + + assertThat(data.getMirroredInterface(), hasSize(2)); + assertThat(data.getMirroredInterface(), containsInAnyOrder( + mirroredInterface(SRC_IFACE_NAME_1, SpanState.Receive), + mirroredInterface(SRC_IFACE_NAME_2, SpanState.Both))); + } + + private MirroredInterface mirroredInterface(final String ifaceName, final SpanState state) { + return new MirroredInterfaceBuilder() + .setIfaceRef(ifaceName) + .withKey(new MirroredInterfaceKey(ifaceName)) + .setState(state) + .build(); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new InterfaceMirroredInterfacesCustomizer(api, interfaceContext); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/AbstractUnnumberedCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/AbstractUnnumberedCustomizerTest.java new file mode 100644 index 000000000..bc7b6164a --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/AbstractUnnumberedCustomizerTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.jvpp.core.dto.SwInterfaceSetUnnumbered; +import io.fd.jvpp.core.dto.SwInterfaceSetUnnumberedReply; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.UnnumberedBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +abstract class AbstractUnnumberedCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { + + protected static final String IFC_CTX_NAME = "ifc-ctx"; + private AbstractUnnumberedCustomizer customizer; + private static final String TARGET_IFC0_NAME = "eth0"; + private static final int TARGET_IFC0_ID = 0; + private static final String TARGET_IFC1_NAME = "eth1"; + private static final int TARGET_IFC1_ID = 1; + + + @Override + public void setUpTest() { + customizer = getCustomizer(); + defineMapping(mappingContext, TARGET_IFC0_NAME, TARGET_IFC0_ID, IFC_CTX_NAME); + defineMapping(mappingContext, TARGET_IFC1_NAME, TARGET_IFC1_ID, IFC_CTX_NAME); + defineMapping(mappingContext, getUnnumberedIfcName(), getUnnumberedIfcId(), IFC_CTX_NAME); + when(api.swInterfaceSetUnnumbered(any())).thenReturn(future(new SwInterfaceSetUnnumberedReply())); + } + + protected abstract int getUnnumberedIfcId(); + + protected abstract String getUnnumberedIfcName(); + + protected abstract InstanceIdentifier getUnnumberedIfcIId(); + + protected abstract AbstractUnnumberedCustomizer getCustomizer(); + + @Test + public void testWrite() throws Exception { + final Unnumbered data = new UnnumberedBuilder().setUse(TARGET_IFC0_NAME).build(); + customizer.writeCurrentAttributes(getUnnumberedIfcIId(), data, writeContext); + verify(api).swInterfaceSetUnnumbered(expectedRequest(true, TARGET_IFC0_ID)); + } + @Test + public void testUpdate() throws Exception { + final Unnumbered before = new UnnumberedBuilder().setUse(TARGET_IFC0_NAME).build(); + final Unnumbered after = new UnnumberedBuilder().setUse(TARGET_IFC1_NAME).build(); + customizer.updateCurrentAttributes(getUnnumberedIfcIId(), before, after, writeContext); + verify(api).swInterfaceSetUnnumbered(expectedRequest(true, TARGET_IFC1_ID)); + } + + @Test + public void testDelete() throws Exception { + final Unnumbered data = new UnnumberedBuilder().setUse(TARGET_IFC0_NAME).build(); + customizer.deleteCurrentAttributes(getUnnumberedIfcIId(), data, writeContext); + verify(api).swInterfaceSetUnnumbered(expectedRequest(false, TARGET_IFC0_ID)); + } + + private SwInterfaceSetUnnumbered expectedRequest(final boolean isAdd, int swIfIntex) { + final SwInterfaceSetUnnumbered request = new SwInterfaceSetUnnumbered(); + request.swIfIndex = swIfIntex; + request.unnumberedSwIfIndex = getUnnumberedIfcId(); + request.isAdd = booleanToByte(isAdd); + return request; + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/AfPacketCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/AfPacketCustomizerTest.java new file mode 100644 index 000000000..33125f182 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/AfPacketCustomizerTest.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2018 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +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 io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.Ipv4Translator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.AfPacketCreate; +import io.fd.jvpp.core.dto.AfPacketCreateReply; +import io.fd.jvpp.core.dto.AfPacketDelete; +import io.fd.jvpp.core.dto.AfPacketDeleteReply; +import java.nio.charset.StandardCharsets; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacket; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacketBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class AfPacketCustomizerTest extends WriterCustomizerTest implements Ipv4Translator { + + private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; + private static final int IFACE_ID = 1; + private static final String IFACE_NAME = "veth1"; + private static final InstanceIdentifier ID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(AfPacket.class); + private AfPacketCustomizer customizer; + + @Override + public void setUpTest() throws Exception { + InterfaceTypeTestUtils.setupWriteContext(writeContext, + org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.AfPacket.class); + customizer = new AfPacketCustomizer(api, new NamingContext("generatedInterfaceName", IFC_TEST_INSTANCE)); + + final AfPacketCreateReply createReply = new AfPacketCreateReply(); + createReply.swIfIndex = IFACE_ID; + when(api.afPacketCreate(any())).thenReturn(future(createReply)); + when(api.afPacketDelete(any())).thenReturn(future(new AfPacketDeleteReply())); + } + + @Test + public void testWriteRandomMac() throws WriteFailedException { + final AfPacketCreate expectedCreateRequest = new AfPacketCreate(); + expectedCreateRequest.hostIfName = IFACE_NAME.getBytes(StandardCharsets.UTF_8); + expectedCreateRequest.useRandomHwAddr = 1; + expectedCreateRequest.hwAddr = new byte[6]; + + customizer.writeCurrentAttributes(ID, afPacket(), writeContext); + + verify(api).afPacketCreate(expectedCreateRequest); + verify(mappingContext).put(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE), mapping(IFACE_NAME, IFACE_ID).get()); + } + + @Test + public void testWriteExplicitMac() throws WriteFailedException { + final AfPacket afPacket = afPacket("01:02:03:04:05:06"); + + final AfPacketCreate expectedCreateRequest = new AfPacketCreate(); + expectedCreateRequest.hostIfName = IFACE_NAME.getBytes(StandardCharsets.UTF_8); + expectedCreateRequest.useRandomHwAddr = 0; + expectedCreateRequest.hwAddr = new byte[] {1, 2, 3, 4, 5, 6}; + + customizer.writeCurrentAttributes(ID, afPacket, writeContext); + + verify(api).afPacketCreate(expectedCreateRequest); + verify(mappingContext).put(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE), mapping(IFACE_NAME, IFACE_ID).get()); + } + + @Test + public void testDelete() throws WriteFailedException { + final AfPacket afPacket = afPacket("02:03:04:05:06:07"); + final AfPacketDelete expectedDeleteRequest = new AfPacketDelete(); + expectedDeleteRequest.hostIfName = IFACE_NAME.getBytes(StandardCharsets.UTF_8); + + customizer.deleteCurrentAttributes(ID, afPacket, writeContext); + + verify(api).afPacketDelete(expectedDeleteRequest); + verify(mappingContext).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE))); + } + + private static AfPacket afPacket() { + return new AfPacketBuilder().setHostInterfaceName(IFACE_NAME).build(); + } + + private static AfPacket afPacket(String mac) { + return new AfPacketBuilder().setHostInterfaceName(IFACE_NAME).setMac(new PhysAddress(mac)).build(); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/AfPacketValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/AfPacketValidatorTest.java new file mode 100644 index 000000000..bdc1bdb31 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/AfPacketValidatorTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; +import io.fd.honeycomb.translate.write.WriteContext; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacket; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.AfPacketBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class AfPacketValidatorTest { + + private AfPacketValidator validator; + + @Mock + private WriteContext writeContext; + + private final String IFACE_NAME = "veth1"; + private final InstanceIdentifier ID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(AfPacket.class); + + @Before + public void setUp() { + initMocks(this); + NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); + validator = new AfPacketValidator(ifcContext); + } + + @Test + public void testWriteSuccessful() throws CreateValidationFailedException { + validator.validateWrite(ID, afPacket(IFACE_NAME), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoHostName() throws CreateValidationFailedException { + validator.validateWrite(ID, afPacket(null), writeContext); + } + + @Test(expected = IllegalArgumentException.class) + public void testWriteFailedLongHostName() throws CreateValidationFailedException { + validator.validateWrite(ID, + afPacket(IntStream.range(1, 64).boxed().map(i -> i.toString()).collect(Collectors.joining(","))), + writeContext); + } + + @Test + public void testUpdateSuccessful() throws UpdateValidationFailedException { + validator.validateUpdate(ID, afPacket(IFACE_NAME), afPacket(IFACE_NAME), writeContext); + } + + @Test + public void testDeleteSuccessful() throws DeleteValidationFailedException { + validator.validateDelete(ID, afPacket(IFACE_NAME), writeContext); + } + + private AfPacket afPacket(String name) { + return new AfPacketBuilder().setHostInterfaceName(name).build(); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/EthernetCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/EthernetCustomizerTest.java new file mode 100644 index 000000000..2ad687c68 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/EthernetCustomizerTest.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.HwInterfaceSetMtu; +import io.fd.jvpp.core.dto.HwInterfaceSetMtuReply; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Ethernet; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev180703.EthernetCsmacd; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class EthernetCustomizerTest extends WriterCustomizerTest { + + private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; + private static final String IF_NAME = "eth0"; + private static final int IF_INDEX = 1; + private static final InstanceIdentifier IF_IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation( + VppInterfaceAugmentation.class).child(Ethernet.class); + private EthernetCustomizer customizer; + + @Override + public void setUpTest() throws Exception { + InterfaceTypeTestUtils.setupWriteContext(writeContext, EthernetCsmacd.class); + customizer = new EthernetCustomizer(api, new NamingContext("ifcintest", IFC_TEST_INSTANCE)); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_TEST_INSTANCE); + } + + @Test + public void testWrite() throws WriteFailedException { + when(api.hwInterfaceSetMtu(any())).thenReturn(future(new HwInterfaceSetMtuReply())); + final int mtu = 1234; + customizer.writeCurrentAttributes(IF_IID, EthernetValidatorTest.ethernet(mtu), writeContext); + verify(api).hwInterfaceSetMtu(mtuSetRequest(mtu)); + } + + @Test + public void testUpdate() throws WriteFailedException { + when(api.hwInterfaceSetMtu(any())).thenReturn(future(new HwInterfaceSetMtuReply())); + final int mtu = 5678; + customizer.updateCurrentAttributes(IF_IID, mock(Ethernet.class), EthernetValidatorTest.ethernet(mtu), writeContext); + verify(api).hwInterfaceSetMtu(mtuSetRequest(mtu)); + } + + private HwInterfaceSetMtu mtuSetRequest(final int mtu) { + final HwInterfaceSetMtu request = new HwInterfaceSetMtu(); + request.swIfIndex = IF_INDEX; + request.mtu = (short)mtu; + return request; + } + + @Test(expected = WriteFailedException.class) + public void testDelete() throws WriteFailedException { + customizer.deleteCurrentAttributes(IF_IID, mock(Ethernet.class), writeContext); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/EthernetValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/EthernetValidatorTest.java new file mode 100644 index 000000000..1c199d304 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/EthernetValidatorTest.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; +import io.fd.honeycomb.translate.write.WriteContext; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Ethernet; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.EthernetBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class EthernetValidatorTest { + + private EthernetValidator validator; + + @Mock + private WriteContext writeContext; + + private static final String IF_NAME = "eth0"; + private static final int IF_MTU = 1234; + private static final InstanceIdentifier ID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation( + VppInterfaceAugmentation.class).child(Ethernet.class); + + @Before + public void setUp() { + initMocks(this); + NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); + validator = new EthernetValidator(ifcContext); + } + + @Test + public void testWriteSuccessful() throws CreateValidationFailedException { + validator.validateWrite(ID, ethernet(IF_MTU), writeContext); + } + + @Test(expected = NullPointerException.class) + public void testWriteFailedNoMTU() throws CreateValidationFailedException { + validator.validateWrite(ID, ethernet(null), writeContext); + } + + @Test + public void testUpdateSuccessful() throws UpdateValidationFailedException { + validator.validateUpdate(ID, ethernet(IF_MTU), ethernet(IF_MTU + 1), writeContext); + } + + static Ethernet ethernet(final Integer mtu) { + final EthernetBuilder ethernet = new EthernetBuilder(); + ethernet.setMtu(mtu); + return ethernet.build(); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/GreCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/GreCustomizerTest.java new file mode 100644 index 000000000..55f0ab488 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/GreCustomizerTest.java @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.VppBaseCallException; +import io.fd.jvpp.VppInvocationException; +import io.fd.jvpp.core.dto.GreTunnelAddDel; +import io.fd.jvpp.core.dto.GreTunnelAddDelReply; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Gre; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.GreBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class GreCustomizerTest extends WriterCustomizerTest implements AddressTranslator { + + private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; + private static final byte ADD_GRE = 1; + private static final byte DEL_GRE = 0; + private final String IFACE_NAME = "eth0"; + private final int IFACE_ID = 1; + private InstanceIdentifier id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(Gre.class); + private GreCustomizer customizer; + + private static Gre generateGre() { + final GreBuilder builder = new GreBuilder(); + builder.setSrc(new IpAddressNoZone(new Ipv4AddressNoZone("192.168.20.10"))); + builder.setDst(new IpAddressNoZone(new Ipv4AddressNoZone("192.168.20.11"))); + builder.setOuterFibId(Long.valueOf(123)); + return builder.build(); + } + + @Override + public void setUpTest() throws Exception { + InterfaceTypeTestUtils.setupWriteContext(writeContext, + org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.GreTunnel.class); + customizer = new GreCustomizer(api, new NamingContext("generateInterfaceNAme", IFC_TEST_INSTANCE)); + } + + private void whenGreAddDelTunnelThenSuccess() { + final GreTunnelAddDelReply reply = new GreTunnelAddDelReply(); + reply.swIfIndex = IFACE_ID; + doReturn(future(reply)).when(api).greTunnelAddDel(any(GreTunnelAddDel.class)); + } + + private void whenGreAddDelTunnelThenFailure() { + doReturn(failedFuture()).when(api).greTunnelAddDel(any(GreTunnelAddDel.class)); + } + + private GreTunnelAddDel verifyGreAddDelTunnelWasInvoked(final Gre gre) throws VppInvocationException { + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(GreTunnelAddDel.class); + verify(api).greTunnelAddDel(argumentCaptor.capture()); + final GreTunnelAddDel actual = argumentCaptor.getValue(); + assertEquals(0, actual.tunnel.isIpv6); + assertArrayEquals(ipAddressToArray(gre.getSrc()), actual.tunnel.src.un.getIp4().ip4Address); + assertArrayEquals(ipAddressToArray(gre.getDst()), actual.tunnel.dst.un.getIp4().ip4Address); + assertEquals(gre.getOuterFibId().intValue(), actual.tunnel.outerFibId); + return actual; + } + + private void verifyGreAddWasInvoked(final Gre gre) throws VppInvocationException { + final GreTunnelAddDel actual = verifyGreAddDelTunnelWasInvoked(gre); + assertEquals(ADD_GRE, actual.isAdd); + } + + private void verifyGreDeleteWasInvoked(final Gre gre) throws VppInvocationException { + final GreTunnelAddDel actual = verifyGreAddDelTunnelWasInvoked(gre); + assertEquals(DEL_GRE, actual.isAdd); + } + + @Test + public void testWriteCurrentAttributes() throws Exception { + final Gre gre = generateGre(); + + whenGreAddDelTunnelThenSuccess(); + + noMappingDefined(mappingContext, IFACE_NAME, IFC_TEST_INSTANCE); + + customizer.writeCurrentAttributes(id, gre, writeContext); + verifyGreAddWasInvoked(gre); + verify(mappingContext).put(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), + eq(mapping(IFACE_NAME, IFACE_ID).get())); + } + + @Test + public void testWriteCurrentAttributesMappingAlreadyPresent() throws Exception { + final Gre gre = generateGre(); + + whenGreAddDelTunnelThenSuccess(); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE); + + customizer.writeCurrentAttributes(id, gre, writeContext); + verifyGreAddWasInvoked(gre); + + // Remove the first mapping before putting in the new one + verify(mappingContext).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE))); + verify(mappingContext).put(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(mapping(IFACE_NAME, IFACE_ID).get())); + } + + @Test + public void testWriteCurrentAttributesFailed() throws Exception { + final Gre gre = generateGre(); + + whenGreAddDelTunnelThenFailure(); + + try { + customizer.writeCurrentAttributes(id, gre, writeContext); + } catch (WriteFailedException.CreateFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyGreAddWasInvoked(gre); + // Mapping not stored due to failure + verify(mappingContext, times(0)).put(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE)), eq(mapping( + IFACE_NAME, 0).get())); + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test(expected = UnsupportedOperationException.class) + public void testUpdateCurrentAttributes() throws Exception { + customizer.updateCurrentAttributes(id, generateGre(), generateGre(), writeContext); + } + + @Test + public void testDeleteCurrentAttributes() throws Exception { + final Gre gre = generateGre(); + + whenGreAddDelTunnelThenSuccess(); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE); + + customizer.deleteCurrentAttributes(id, gre, writeContext); + verifyGreDeleteWasInvoked(gre); + verify(mappingContext).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE))); + } + + @Test + public void testDeleteCurrentAttributesaFailed() throws Exception { + final Gre gre = generateGre(); + + whenGreAddDelTunnelThenFailure(); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_TEST_INSTANCE); + + try { + customizer.deleteCurrentAttributes(id, gre, writeContext); + } catch (WriteFailedException.DeleteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyGreDeleteWasInvoked(gre); + verify(mappingContext, times(0)).delete(eq(mappingIid(IFACE_NAME, IFC_TEST_INSTANCE))); + return; + } + fail("WriteFailedException.DeleteFailedException was expected"); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/GreValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/GreValidatorTest.java new file mode 100644 index 000000000..d8f460284 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/GreValidatorTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; +import io.fd.honeycomb.translate.write.WriteContext; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Gre; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.GreBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class GreValidatorTest { + + private GreValidator validator; + + @Mock + private WriteContext writeContext; + + private static final String IPV6 = "a::100"; + private static final String IPV4_1 = "192.168.20.10"; + private static final String IPV4_2 = "192.168.20.11"; + private static final Long OUT_FIB_ID = Long.valueOf(123); + private static final String IFACE_NAME = "eth0"; + private static final InstanceIdentifier ID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(Gre.class); + + @Before + public void setUp() { + initMocks(this); + NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); + validator = new GreValidator(ifcContext); + } + + @Test + public void testWriteSuccessful() throws CreateValidationFailedException { + validator.validateWrite(ID, generateCorrectGre(), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedMixedIpv4Ipv6() throws CreateValidationFailedException { + validator.validateWrite(ID, generateGre(ip4(IPV4_1), ip6(IPV6), OUT_FIB_ID), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoSrcAddr() throws CreateValidationFailedException { + validator.validateWrite(ID, generateGre(null, ip6(IPV6), OUT_FIB_ID), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoDstAddr() throws CreateValidationFailedException { + validator.validateWrite(ID, generateGre(ip4(IPV4_1), null, OUT_FIB_ID), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoOutFibId() throws CreateValidationFailedException { + validator.validateWrite(ID, generateGre(ip4(IPV4_1), ip4(IPV4_2), null), writeContext); + } + + @Test + public void testDeleteSuccessful() throws DeleteValidationFailedException { + validator.validateDelete(ID, generateCorrectGre(), writeContext); + } + + private Gre generateCorrectGre() { + return generateGre(ip4(IPV4_1), ip4(IPV4_2), OUT_FIB_ID); + } + + private Gre generateGre(final IpAddressNoZone srcAddr, final IpAddressNoZone dstAddr, final Long outerFibId) { + final GreBuilder builder = new GreBuilder(); + builder.setSrc(srcAddr); + builder.setDst(dstAddr); + builder.setOuterFibId(outerFibId); + return builder.build(); + } + + private IpAddressNoZone ip4(String addr) { + return new IpAddressNoZone(new Ipv4AddressNoZone(addr)); + } + + private IpAddressNoZone ip6(String addr) { + return new IpAddressNoZone(new Ipv6AddressNoZone(addr)); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceCustomizerTest.java new file mode 100644 index 000000000..c7fd7b970 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceCustomizerTest.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.VppBaseCallException; +import io.fd.jvpp.core.dto.SwInterfaceSetFlags; +import io.fd.jvpp.core.dto.SwInterfaceSetFlagsReply; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { + private static final String IFACE_CTX_NAME = "interface-ctx"; + private static final String IF_NAME = "eth1"; + private static final int IF_INDEX = 1; + + private static final InstanceIdentifier IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)); + + private static final String LOCAL0_IFC_NAME = "local0"; + private static final InstanceIdentifier LOCAL0_IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(LOCAL0_IFC_NAME)); + private InterfaceCustomizer customizer; + + @Override + protected void setUpTest() throws Exception { + customizer = new InterfaceCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME)); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME); + } + + @Test + public void testWrite() throws WriteFailedException { + final boolean enabled = true; + when(api.swInterfaceSetFlags(any())).thenReturn(future(new SwInterfaceSetFlagsReply())); + customizer.writeCurrentAttributes(IID, iface(enabled), writeContext); + verify(api).swInterfaceSetFlags(expectedRequest(enabled)); + } + + @Test + public void testWriteFailed() { + final boolean enabled = false; + when(api.swInterfaceSetFlags(any())).thenReturn(failedFuture()); + try { + customizer.writeCurrentAttributes(IID, iface(enabled), writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verify(api).swInterfaceSetFlags(expectedRequest(enabled)); + return; + } + fail("WriteFailedException expected"); + } + + @Test + public void testUpdate() throws WriteFailedException { + when(api.swInterfaceSetFlags(any())).thenReturn(future(new SwInterfaceSetFlagsReply())); + customizer.updateCurrentAttributes(IID, iface(false), iface(true), writeContext); + verify(api).swInterfaceSetFlags(expectedRequest(true)); + } + + @Test + public void testUpdateFailed() { + when(api.swInterfaceSetFlags(any())).thenReturn(failedFuture()); + try { + customizer.updateCurrentAttributes(IID, iface(false), iface(true), writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verify(api).swInterfaceSetFlags(expectedRequest(true)); + return; + } + fail("WriteFailedException expected"); + } + + @Test + public void testDelete() throws WriteFailedException { + customizer.deleteCurrentAttributes(IID, mock(Interface.class), writeContext); + verifyZeroInteractions(api); + } + + @Test(expected = WriteFailedException.DeleteFailedException.class) + public void testDeleteLocal0() throws WriteFailedException { + final Interface ifc = mock(Interface.class); + when(ifc.getName()).thenReturn(LOCAL0_IFC_NAME); + customizer.deleteCurrentAttributes(LOCAL0_IID, ifc, writeContext); + } + + private Interface iface(final boolean enabled) { + return new InterfaceBuilder().setName(IF_NAME).setEnabled(enabled).build(); + } + + private SwInterfaceSetFlags expectedRequest(final boolean enabled) { + final SwInterfaceSetFlags request = new SwInterfaceSetFlags(); + request.adminUpDown = booleanToByte(enabled); + request.swIfIndex = IF_INDEX; + return request; + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceRoutingCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceRoutingCustomizerTest.java new file mode 100644 index 000000000..4615a600b --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceRoutingCustomizerTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.SwInterfaceSetTable; +import io.fd.jvpp.core.dto.SwInterfaceSetTableReply; +import java.util.Optional; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Routing; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.RoutingBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceRoutingCustomizerTest extends WriterCustomizerTest { + private static final String IFACE_CTX_NAME = "interface-ctx"; + private static final String IF_NAME = "eth1"; + private static final int IF_INDEX = 1; + private static final InstanceIdentifier IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(Routing.class); + + private InterfaceRoutingCustomizer customizer; + + @Override + protected void setUpTest() throws Exception { + customizer = new InterfaceRoutingCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME)); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME); + } + + @Test + public void testWrite() throws WriteFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + final int vrfId = 123; + when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply())); + customizer.writeCurrentAttributes(IID, routing(vrfId), writeContext); + verify(api).swInterfaceSetTable(expectedRequest(vrfId)); + } + + @Test(expected = WriteFailedException.class) + public void testWriteFailed() throws WriteFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + when(api.swInterfaceSetTable(any())).thenReturn(failedFuture()); + customizer.writeCurrentAttributes(IID, routing(213), writeContext); + } + + @Test + public void testWriteEmptyIfaceData() throws WriteFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))) + .thenReturn(Optional.of(new InterfaceBuilder().build())); + final int vrfId = 123; + when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply())); + customizer.writeCurrentAttributes(IID, routing(vrfId), writeContext); + verify(api).swInterfaceSetTable(expectedRequest(vrfId)); + } + + @Test(expected = WriteFailedException.class) + public void testUpdateFailed() throws WriteFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + when(api.swInterfaceSetTable(any())).thenReturn(failedFuture()); + customizer.updateCurrentAttributes(IID, routing(123L), routing(321L), writeContext); + } + + @Test + public void testDelete() throws WriteFailedException { + when(writeContext.readAfter(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply())); + customizer.deleteCurrentAttributes(IID, routing(123), writeContext); + verify(api).swInterfaceSetTable(expectedRequest(0)); + } + + @Test(expected = WriteFailedException.DeleteFailedException.class) + public void testDeleteFailed() throws WriteFailedException { + when(writeContext.readAfter(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + when(api.swInterfaceSetTable(any())).thenReturn(failedFuture()); + customizer.deleteCurrentAttributes(IID, routing(123), writeContext); + } + + private Routing routing(final long vrfId) { + return new RoutingBuilder().setIpv4VrfId(new VniReference(vrfId)).build(); + } + + private SwInterfaceSetTable expectedRequest(final int vrfId) { + final SwInterfaceSetTable request = new SwInterfaceSetTable(); + request.isIpv6 = 0; + request.swIfIndex = IF_INDEX; + request.vrfId = vrfId; + return request; + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceRoutingValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceRoutingValidatorTest.java new file mode 100644 index 000000000..7cefb112b --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceRoutingValidatorTest.java @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; +import io.fd.honeycomb.translate.write.WriteContext; +import java.util.Collections; +import java.util.Optional; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Routing; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.RoutingBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.Interface1Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.Ipv6Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv4.AddressBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceRoutingValidatorTest { + + private InterfaceRoutingValidator validator; + + @Mock + private WriteContext writeContext; + + private static final String IF_NAME = "eth1"; + private static final Long VRF_ID = Long.valueOf(123); + + private static final InstanceIdentifier ID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(Routing.class); + + @Before + public void setUp() { + initMocks(this); + NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); + validator = new InterfaceRoutingValidator(ifcContext); + } + + @Test + public void testWriteSuccessful() throws CreateValidationFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + validator.validateWrite(ID, routing(VRF_ID, true, false), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoFrfIds() throws CreateValidationFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + validator.validateWrite(ID, routing(null, true, true), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedWithV4Address() throws CreateValidationFailedException { + when(writeContext.readBefore(RWUtils.cutId(ID, Interface.class))) + .thenReturn(Optional.of(ifaceWithV4Address())); + validator.validateWrite(ID, routing(VRF_ID, true, false), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedWithV6Address() throws CreateValidationFailedException { + when(writeContext.readBefore(RWUtils.cutId(ID, Interface.class))) + .thenReturn(Optional.of(ifaceWithV6Address())); + validator.validateWrite(ID, routing(VRF_ID, true, false), writeContext); + } + + @Test + public void testUpdateSuccessful() throws UpdateValidationFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + validator.validateUpdate(ID, routing(VRF_ID, true, false), + routing(VRF_ID, true, true), writeContext); + } + + @Test + public void testDeleteSuccessful() throws DeleteValidationFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + validator.validateDelete(ID, routing(VRF_ID, true, false), writeContext); + } + + private Routing routing(final Long vrfId, final boolean hasIpv4, final boolean hasIpv6) { + VniReference vni = null; + if (vrfId != null) { + vni = new VniReference(vrfId); + } + + RoutingBuilder builder = new RoutingBuilder(); + if (hasIpv4) { + builder.setIpv4VrfId(vni); + } + if (hasIpv6) { + builder.setIpv6VrfId(vni); + } + return builder.build(); + } + + private Interface ifaceWithV4Address() { + return new InterfaceBuilder() + .addAugmentation(Interface1.class, new Interface1Builder() + .setIpv4(new Ipv4Builder() + .setAddress(Collections.singletonList(new AddressBuilder().build())) + .build()) + .build()) + .build(); + } + + private Interface ifaceWithV6Address() { + return new InterfaceBuilder() + .addAugmentation(Interface1.class, new Interface1Builder() + .setIpv6(new Ipv6Builder() + .setAddress(Collections.singletonList( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev180222.interfaces._interface.ipv6.AddressBuilder() + .build())) + .build()) + .build()) + .build(); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceTypeTestUtils.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceTypeTestUtils.java new file mode 100644 index 000000000..c8e2e490e --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceTypeTestUtils.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.Mockito.doReturn; + +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.write.WriteContext; +import java.util.Optional; +import org.mockito.Matchers; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfaceType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +final class InterfaceTypeTestUtils { + + private InterfaceTypeTestUtils() {} + + static void setupWriteContext(final WriteContext writeContext, final Class ifcType) { + doReturn(new ModificationCache()).when(writeContext).getModificationCache(); + doReturn(Optional.of(new InterfaceBuilder() + .setType(ifcType) + .build())).when(writeContext).readAfter(Matchers.any(InstanceIdentifier.class)); + } + +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceUnnumberedCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceUnnumberedCustomizerTest.java new file mode 100644 index 000000000..54267d02b --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceUnnumberedCustomizerTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.InterfaceUnnumberedAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceUnnumberedCustomizerTest extends AbstractUnnumberedCustomizerTest { + private static final String UNNUMBERED_IFC_NAME = "eth2"; + private static final int UNNUMBERED_IFC_ID = 2; + private static final InstanceIdentifier UNNUMBERED_IFC_IID = InstanceIdentifier.create(Interfaces.class) + .child(Interface.class, new InterfaceKey(UNNUMBERED_IFC_NAME)) + .augmentation(InterfaceUnnumberedAugmentation.class) + .child(Unnumbered.class); + + @Override + protected int getUnnumberedIfcId() { + return UNNUMBERED_IFC_ID; + } + + @Override + protected String getUnnumberedIfcName() { + return UNNUMBERED_IFC_NAME; + } + + @Override + protected InstanceIdentifier getUnnumberedIfcIId() { + return UNNUMBERED_IFC_IID; + } + + @Override + protected AbstractUnnumberedCustomizer getCustomizer() { + return new InterfaceUnnumberedCustomizer(api, new NamingContext("ifc-prefix", IFC_CTX_NAME)); + } + +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceUnnumberedValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceUnnumberedValidatorTest.java new file mode 100644 index 000000000..1d080e632 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceUnnumberedValidatorTest.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; +import io.fd.honeycomb.translate.write.WriteContext; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.InterfaceUnnumberedAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.UnnumberedBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceUnnumberedValidatorTest { + + private InterfaceUnnumberedValidator validator; + + @Mock + private WriteContext writeContext; + + private static final String IF_NAME = "eth2"; + private static final String TARGET_IFC0_NAME = "eth0"; + private static final InstanceIdentifier ID = InstanceIdentifier.create(Interfaces.class) + .child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(InterfaceUnnumberedAugmentation.class) + .child(Unnumbered.class); + + @Before + public void setUp() { + initMocks(this); + NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); + validator = new InterfaceUnnumberedValidator(ifcContext); + } + + @Test + public void testWriteSuccessful() throws CreateValidationFailedException { + validator.validateWrite(ID, getUnnumberedIfc(TARGET_IFC0_NAME), writeContext); + } + + @Test(expected = NullPointerException.class) + public void testWriteFailedNoUse() throws CreateValidationFailedException { + validator.validateWrite(ID, getUnnumberedIfc(null), writeContext); + } + + @Test + public void testUpdateSuccessful() throws UpdateValidationFailedException { + validator.validateUpdate(ID, getUnnumberedIfc(TARGET_IFC0_NAME), getUnnumberedIfc(TARGET_IFC0_NAME), + writeContext); + } + + @Test + public void testDeleteeSuccessful() throws DeleteValidationFailedException { + validator.validateDelete(ID, getUnnumberedIfc(TARGET_IFC0_NAME), writeContext); + } + + private Unnumbered getUnnumberedIfc(String use) { + return new UnnumberedBuilder().setUse(use).build(); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceValidatorTest.java new file mode 100644 index 000000000..38e985844 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfaceValidatorTest.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; +import io.fd.honeycomb.translate.write.WriteContext; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceValidatorTest { + + private InterfaceValidator validator; + + @Mock + private WriteContext writeContext; + + private static final String IF_NAME = "eth0"; + private static final InstanceIdentifier ID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)); + + @Before + public void setUp() { + initMocks(this); + NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); + validator = new InterfaceValidator(ifcContext); + } + + @Test + public void testWriteSuccessful() throws CreateValidationFailedException { + validator.validateWrite(ID, getInterface(true), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoName() throws CreateValidationFailedException { + validator.validateWrite(ID, getInterface(null, true), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoEnableFlag() throws CreateValidationFailedException { + validator.validateWrite(ID, getInterface(null), writeContext); + } + + @Test + public void testUpdateSuccessful() throws UpdateValidationFailedException { + validator.validateUpdate(ID, getInterface(true), getInterface(true), writeContext); + } + + @Test + public void testDeleteSuccessful() throws DeleteValidationFailedException { + validator.validateDelete(ID, getInterface(true), writeContext); + } + + private Interface getInterface(final String name, final Boolean enabled) { + return new InterfaceBuilder().setName(name).setEnabled(enabled).build(); + } + + private Interface getInterface(final Boolean enabled) { + return new InterfaceBuilder().setName(IF_NAME).setEnabled(enabled).build(); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfacesStatisticsCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfacesStatisticsCustomizerTest.java new file mode 100644 index 000000000..0a2b8e428 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/InterfacesStatisticsCustomizerTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2019 PANTHEON.tech. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.v3po.read.cache.InterfaceStatisticsManager; +import io.fd.hc2vpp.v3po.read.cache.InterfaceStatisticsManagerImpl; +import io.fd.honeycomb.translate.write.WriteFailedException; +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfacesStatsAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.Statistics; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces.StatisticsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfacesStatisticsCustomizerTest extends WriterCustomizerTest { + + public static final InstanceIdentifier IID = + InstanceIdentifier.create(Interfaces.class).augmentation(VppInterfacesStatsAugmentation.class) + .child(Statistics.class); + + private InterfacesStatisticsCustomizer customizer; + private InterfaceStatisticsManager statsManager; + + @Override + protected void setUpTest() throws Exception { + statsManager = new InterfaceStatisticsManagerImpl(); + customizer = new InterfacesStatisticsCustomizer(statsManager); + } + + @Test + public void testWrite() throws WriteFailedException { + customizer.writeCurrentAttributes(IID, enableStats(true), writeContext); + Assert.assertTrue(statsManager.isStatisticsEnabled()); + } + + @Test + public void testUpdatetoEnabled() throws WriteFailedException { + customizer.updateCurrentAttributes(IID, enableStats(true), enableStats(false), writeContext); + Assert.assertFalse(statsManager.isStatisticsEnabled()); + } + + @Test + public void testUpdateToDisabled() throws WriteFailedException { + customizer.updateCurrentAttributes(IID, enableStats(false), enableStats(true), writeContext); + Assert.assertTrue(statsManager.isStatisticsEnabled()); + } + + @Test + public void testDelete() throws WriteFailedException { + customizer.deleteCurrentAttributes(IID, enableStats(true), writeContext); + Assert.assertFalse(statsManager.isStatisticsEnabled()); + } + + private Statistics enableStats(final boolean enabled) { + StatisticsBuilder builder = new StatisticsBuilder(); + return builder.setEnabled(enabled).build(); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/L2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/L2CustomizerTest.java new file mode 100644 index 000000000..6b2c89824 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/L2CustomizerTest.java @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.VppBaseCallException; +import io.fd.jvpp.core.dto.SwInterfaceSetL2Bridge; +import io.fd.jvpp.core.dto.SwInterfaceSetL2BridgeReply; +import io.fd.jvpp.core.dto.SwInterfaceSetL2Xconnect; +import io.fd.jvpp.core.dto.SwInterfaceSetL2XconnectReply; +import io.fd.jvpp.core.types.L2PortType; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.L2Builder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.Interconnection; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.BridgeBased; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.BridgeBasedBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.XconnectBased; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.XconnectBasedBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class L2CustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { + private static final String IFACE_CTX_NAME = "interface-ctx"; + private static final String BD_CTX_NAME = "bd-ctx"; + private static final String IF1_NAME = "eth1"; + private static final int IF1_INDEX = 1; + private static final String IF2_NAME = "eth2"; + private static final int IF2_INDEX = 2; + private static final InstanceIdentifier IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF1_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(L2.class); + private static final String BD_NAME = "test_bd"; + private static final int BD_INDEX = 13; + + private L2Customizer customizer; + + @Override + protected void setUpTest() throws Exception { + customizer = new L2Customizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME), + new NamingContext("bdPrefix", BD_CTX_NAME)); + defineMapping(mappingContext, IF1_NAME, IF1_INDEX, IFACE_CTX_NAME); + defineMapping(mappingContext, IF2_NAME, IF2_INDEX, IFACE_CTX_NAME); + defineMapping(mappingContext, BD_NAME, BD_INDEX, BD_CTX_NAME); + } + + @Test + public void testWrite() throws WriteFailedException { + when(api.swInterfaceSetL2Xconnect(any())).thenReturn(future(new SwInterfaceSetL2XconnectReply())); + customizer.writeCurrentAttributes(IID, l2(xconnectBased()), writeContext); + verify(api).swInterfaceSetL2Xconnect(xconnectRequest(true)); + } + + @Test + public void testWriteFailed() { + when(api.swInterfaceSetL2Bridge(any())).thenReturn(failedFuture()); + try { + customizer.writeCurrentAttributes(IID, l2(bridgeBased(false)), writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verify(api).swInterfaceSetL2Bridge(bridgeRequest(false, true)); + return; + } + fail("WriteFailedException expected"); + } + + @Test + public void testUpdate() throws WriteFailedException { + when(api.swInterfaceSetL2Bridge(any())).thenReturn(future(new SwInterfaceSetL2BridgeReply())); + customizer.updateCurrentAttributes(IID, l2(bridgeBased(false)), l2(bridgeBased(true)), writeContext); + verify(api).swInterfaceSetL2Bridge(bridgeRequest(true, true)); + } + + @Test + public void testDelete() throws WriteFailedException { + when(api.swInterfaceSetL2Xconnect(any())).thenReturn(future(new SwInterfaceSetL2XconnectReply())); + customizer.deleteCurrentAttributes(IID, l2(xconnectBased()), writeContext); + verify(api).swInterfaceSetL2Xconnect(xconnectRequest(false)); + } + + @Test + public void testDeleteFailed() { + when(api.swInterfaceSetL2Bridge(any())).thenReturn(failedFuture()); + try { + customizer.deleteCurrentAttributes(IID, l2(bridgeBased(true)), writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verify(api).swInterfaceSetL2Bridge(bridgeRequest(true, false)); + return; + } + fail("WriteFailedException expected"); + } + + private XconnectBased xconnectBased() { + return new XconnectBasedBuilder().setXconnectOutgoingInterface(IF2_NAME).build(); + } + + private SwInterfaceSetL2Xconnect xconnectRequest(final boolean enable) { + final SwInterfaceSetL2Xconnect request = new SwInterfaceSetL2Xconnect(); + request.rxSwIfIndex = IF1_INDEX; + request.txSwIfIndex = IF2_INDEX; + request.enable = booleanToByte(enable); + return request; + } + + private BridgeBased bridgeBased(final boolean bvi) { + return new BridgeBasedBuilder().setBridgedVirtualInterface(bvi) + .setBridgeDomain(BD_NAME).setSplitHorizonGroup((short) 123).build(); + } + + private SwInterfaceSetL2Bridge bridgeRequest(final boolean bvi, final boolean enable) { + final SwInterfaceSetL2Bridge request = new SwInterfaceSetL2Bridge(); + request.bdId = BD_INDEX; + request.rxSwIfIndex = IF1_INDEX; + request.portType = bvi ? L2PortType.L2_API_PORT_TYPE_BVI : L2PortType.L2_API_PORT_TYPE_NORMAL; + request.enable = booleanToByte(enable); + request.shg = 123; + return request; + } + + + private L2 l2(final Interconnection interconnection) { + return new L2Builder().setInterconnection(interconnection).build(); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/LoopbackCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/LoopbackCustomizerTest.java new file mode 100644 index 000000000..3694dbebd --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/LoopbackCustomizerTest.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.jvpp.core.dto.CreateLoopback; +import io.fd.jvpp.core.dto.CreateLoopbackReply; +import io.fd.jvpp.core.dto.DeleteLoopback; +import io.fd.jvpp.core.dto.DeleteLoopbackReply; +import org.junit.Test; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Loopback; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.LoopbackBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class LoopbackCustomizerTest extends WriterCustomizerTest { + + private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; + private LoopbackCustomizer loopCustomizer; + + @Override + public void setUpTest() throws Exception { + InterfaceTypeTestUtils.setupWriteContext(writeContext, + org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.Loopback.class); + loopCustomizer = new LoopbackCustomizer(api, new NamingContext("ifcintest", IFC_TEST_INSTANCE)); + } + + @Test + public void testCreate() throws Exception { + doAnswer(new Answer() { + + int idx = 0; + + @Override + public Object answer(final InvocationOnMock invocation) throws Throwable { + final CreateLoopbackReply t = new CreateLoopbackReply(); + t.swIfIndex = idx++; + return future(t); + } + }).when(api).createLoopback(any(CreateLoopback.class)); + + loopCustomizer.writeCurrentAttributes(getLoopbackId("loop"), getLoopbackData("ff:ff:ff:ff:ff:ff"), writeContext); + loopCustomizer.writeCurrentAttributes(getLoopbackId("loop2"), getLoopbackData("ff:ff:ff:ff:ff:ff"), writeContext); + + verify(api, times(2)).createLoopback(any(CreateLoopback.class)); + verify(mappingContext).put(eq(mappingIid("loop", IFC_TEST_INSTANCE)), eq( + mapping("loop", 0).get())); + verify(mappingContext).put(eq(mappingIid("loop2", IFC_TEST_INSTANCE)), eq( + mapping("loop2", 1).get())); + } + + @Test + public void testDelete() throws Exception { + final CreateLoopbackReply t = new CreateLoopbackReply(); + t.swIfIndex = 0; + doReturn(future(t)).when(api).createLoopback(any(CreateLoopback.class)); + + doReturn(future(new DeleteLoopbackReply())).when(api).deleteLoopback(any(DeleteLoopback.class)); + + loopCustomizer.writeCurrentAttributes(getLoopbackId("loop"), getLoopbackData("ff:ff:ff:ff:ff:ff"), writeContext); + defineMapping(mappingContext, "loop", 1, IFC_TEST_INSTANCE); + loopCustomizer.deleteCurrentAttributes(getLoopbackId("loop"), getLoopbackData("ff:ff:ff:ff:ff:ff"), writeContext); + + verify(api).createLoopback(any(CreateLoopback.class)); + verify(api).deleteLoopback(any(DeleteLoopback.class)); + verify(mappingContext).delete(eq(mappingIid("loop", IFC_TEST_INSTANCE))); + } + + private InstanceIdentifier getLoopbackId(final String loop) { + return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(loop)).augmentation( + VppInterfaceAugmentation.class).child(Loopback.class); + } + + private Loopback getLoopbackData(final String mac) { + return new LoopbackBuilder().setMac(new PhysAddress(mac)).build(); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/RewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/RewriteCustomizerTest.java new file mode 100644 index 000000000..5202a19ee --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/RewriteCustomizerTest.java @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.common.translate.util.TagRewriteOperation; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.VppBaseCallException; +import io.fd.jvpp.VppInvocationException; +import io.fd.jvpp.core.dto.L2InterfaceVlanTagRewrite; +import io.fd.jvpp.core.dto.L2InterfaceVlanTagRewriteReply; +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319._802dot1q; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.Rewrite; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.rewrite.attributes.RewriteBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class RewriteCustomizerTest extends WriterCustomizerTest { + + private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; + private static final String IF_NAME = "local0"; + private static final String VLAN_IF_NAME = "local0.1"; + private static final int VLAN_IF_ID = 1; + private static final int VLAN_IF_INDEX = 11; + private NamingContext namingContext; + private RewriteCustomizer customizer; + private InstanceIdentifier VLAN_IID; + + private static InstanceIdentifier getVlanTagRewriteId(final String name, final long index) { + final Class> child = (Class) Rewrite.class; + final InstanceIdentifier id = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)).augmentation( + SubinterfaceAugmentation.class).child(SubInterfaces.class) + .child(SubInterface.class, new SubInterfaceKey(index)) + .child(child); + return id; + } + + @Override + public void setUpTest() throws Exception { + namingContext = new NamingContext("generatedSubInterfaceName", IFC_TEST_INSTANCE); + customizer = new RewriteCustomizer(api, namingContext); + VLAN_IID = getVlanTagRewriteId(IF_NAME, VLAN_IF_ID); + defineMapping(mappingContext, VLAN_IF_NAME, VLAN_IF_INDEX, IFC_TEST_INSTANCE); + } + + private Rewrite generateRewrite(final TagRewriteOperation op) { + final RewriteBuilder builder = new RewriteBuilder(); + builder.setPopTags((short) op.getPopTags()); + builder.setVlanType(_802dot1q.class); + return builder.build(); + } + + private L2InterfaceVlanTagRewrite generateL2InterfaceVlanTagRewrite(final int swIfIndex, + final TagRewriteOperation op) { + final L2InterfaceVlanTagRewrite request = new L2InterfaceVlanTagRewrite(); + request.swIfIndex = swIfIndex; + request.vtrOp = op.ordinal(); + request.pushDot1Q = 1; + return request; + } + + /** + * Positive response + */ + private void whenL2InterfaceVlanTagRewriteThenSuccess() { + doReturn(future(new L2InterfaceVlanTagRewriteReply())).when(api) + .l2InterfaceVlanTagRewrite(any(L2InterfaceVlanTagRewrite.class)); + } + + /** + * Failure response send + */ + private void whenL2InterfaceVlanTagRewriteThenFailure() { + doReturn(failedFuture()).when(api).l2InterfaceVlanTagRewrite(any(L2InterfaceVlanTagRewrite.class)); + } + + private void verifyL2InterfaceVlanTagRewriteDeleteWasInvoked() throws VppInvocationException { + final L2InterfaceVlanTagRewrite request = new L2InterfaceVlanTagRewrite(); + request.swIfIndex = VLAN_IF_INDEX; + verify(api).l2InterfaceVlanTagRewrite(request); + } + + @Test + public void testCreate() throws Exception { + final TagRewriteOperation op = TagRewriteOperation.pop_2; + final Rewrite vlanTagRewrite = generateRewrite(op); + + whenL2InterfaceVlanTagRewriteThenSuccess(); + + customizer.writeCurrentAttributes(VLAN_IID, vlanTagRewrite, writeContext); + + verify(api).l2InterfaceVlanTagRewrite(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, op)); + } + + @Test + public void testCreateFailed() throws Exception { + final TagRewriteOperation op = TagRewriteOperation.pop_2; + final Rewrite vlanTagRewrite = generateRewrite(op); + + whenL2InterfaceVlanTagRewriteThenFailure(); + + try { + customizer.writeCurrentAttributes(VLAN_IID, vlanTagRewrite, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verify(api).l2InterfaceVlanTagRewrite(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, op)); + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test + public void testUpdate() throws Exception { + final Rewrite before = generateRewrite(TagRewriteOperation.pop_2); + final Rewrite after = generateRewrite(TagRewriteOperation.pop_1); + + whenL2InterfaceVlanTagRewriteThenSuccess(); + + customizer.updateCurrentAttributes(VLAN_IID, before, after, writeContext); + + verify(api) + .l2InterfaceVlanTagRewrite(generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1)); + } + + @Test + public void testUpdateFailed() throws Exception { + final Rewrite before = generateRewrite(TagRewriteOperation.pop_2); + final Rewrite after = generateRewrite(TagRewriteOperation.pop_1); + + whenL2InterfaceVlanTagRewriteThenFailure(); + + try { + customizer.updateCurrentAttributes(VLAN_IID, before, after, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verify(api) + .l2InterfaceVlanTagRewrite( + generateL2InterfaceVlanTagRewrite(VLAN_IF_INDEX, TagRewriteOperation.pop_1)); + return; + } + fail("WriteFailedException.UpdateFailedException was expected"); + } + + @Test + public void testDelete() throws Exception { + whenL2InterfaceVlanTagRewriteThenSuccess(); + + customizer.deleteCurrentAttributes(VLAN_IID, null, writeContext); + + verifyL2InterfaceVlanTagRewriteDeleteWasInvoked(); + } + + @Test + public void testDeleteFailed() throws Exception { + whenL2InterfaceVlanTagRewriteThenFailure(); + + try { + customizer.deleteCurrentAttributes(VLAN_IID, null, writeContext); + } catch (WriteFailedException e) { + Assert.assertTrue(e.getCause() instanceof VppBaseCallException); + verifyL2InterfaceVlanTagRewriteDeleteWasInvoked(); + return; + } + fail("WriteFailedException.DeleteFailedException was expected"); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceCustomizerTest.java new file mode 100644 index 000000000..923db9b88 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceCustomizerTest.java @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.VppBaseCallException; +import io.fd.jvpp.core.dto.CreateSubif; +import io.fd.jvpp.core.dto.CreateSubifReply; +import io.fd.jvpp.core.dto.SwInterfaceSetFlags; +import io.fd.jvpp.core.dto.SwInterfaceSetFlagsReply; +import java.util.Arrays; +import java.util.List; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319._802dot1ad; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.vlan.tagged.VlanTaggedBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.Match; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.MatchBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.TagsBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.tags.Tag; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.tags.TagBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.tags.TagKey; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.CVlan; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qTagVlanType; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.Dot1qVlanId; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.SVlan; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag; +import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTagBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceCustomizerTest extends WriterCustomizerTest { + + private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; + private static final String SUPER_IF_NAME = "local0"; + private static final int SUPER_IF_ID = 1; + private static final String SUB_IFACE_NAME = "local0.11"; + private static final int SUBIF_INDEX = 11; + private static final short STAG_ID = 100; + private static final short CTAG_ID = 200; + private static final short CTAG_ANY_ID = 0; // only the *IdAny flag is set + private final Tag STAG_100; + private final Tag CTAG_200; + private final Tag CTAG_ANY; + private NamingContext namingContext; + private SubInterfaceCustomizer customizer; + + public SubInterfaceCustomizerTest() { + STAG_100 = generateTag((short) 0, SVlan.class, new Dot1qTag.VlanId(new Dot1qVlanId((int) STAG_ID))); + CTAG_200 = generateTag((short) 1, CVlan.class, new Dot1qTag.VlanId(new Dot1qVlanId(200))); + CTAG_ANY = generateTag((short) 1, CVlan.class, new Dot1qTag.VlanId(Dot1qTag.VlanId.Enumeration.Any)); + } + + private static Tag generateTag(final short index, final Class tagType, + final Dot1qTag.VlanId vlanId) { + TagBuilder tag = new TagBuilder(); + tag.setIndex(index); + tag.withKey(new TagKey(index)); + final Dot1qTagBuilder dtag = new Dot1qTagBuilder(); + dtag.setTagType(tagType); + dtag.setVlanId(vlanId); + tag.setDot1qTag(dtag.build()); + return tag.build(); + } + + static Match generateMatch() { + final MatchBuilder match = new MatchBuilder(); + final VlanTaggedBuilder tagged = new VlanTaggedBuilder(); + tagged.setMatchExactTags(true); + match.setMatchType( + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.match.attributes.match.type.VlanTaggedBuilder() + .setVlanTagged(tagged.build()).build()); + return match.build(); + } + + @Override + public void setUpTest() throws Exception { + namingContext = new NamingContext("generatedSubInterfaceName", IFC_TEST_INSTANCE); + customizer = new SubInterfaceCustomizer(api, namingContext); + defineMapping(mappingContext, SUB_IFACE_NAME, SUBIF_INDEX, IFC_TEST_INSTANCE); + defineMapping(mappingContext, SUPER_IF_NAME, SUPER_IF_ID, IFC_TEST_INSTANCE); + } + + private SubInterface generateSubInterface(final boolean enabled, final List tagList) { + SubInterfaceBuilder builder = new SubInterfaceBuilder(); + builder.setVlanType(_802dot1ad.class); + builder.setIdentifier(11L); + final TagsBuilder tags = new TagsBuilder(); + + tags.setTag(tagList); + + builder.setTags(tags.build()); + + builder.setMatch(generateMatch()); + builder.setEnabled(enabled); + return builder.build(); + } + + private CreateSubif generateSubInterfaceRequest(final int superIfId, final short innerVlanId, + final boolean isInnerAny) { + CreateSubif request = new CreateSubif(); + request.subId = 11; + request.swIfIndex = superIfId; + request.twoTags = 1; + request.innerVlanId = innerVlanId; + request.innerVlanIdAny = (byte) (isInnerAny + ? 1 + : 0); + request.dot1Ad = 1; + request.outerVlanId = STAG_ID; + request.exactMatch = 1; + return request; + } + + private SwInterfaceSetFlags generateSwInterfaceEnableRequest(final int swIfIndex) { + SwInterfaceSetFlags request = new SwInterfaceSetFlags(); + request.swIfIndex = swIfIndex; + request.adminUpDown = 1; + return request; + } + + private InstanceIdentifier getSubInterfaceId(final String name, final long index) { + return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(name)).augmentation( + SubinterfaceAugmentation.class).child(SubInterfaces.class) + .child(SubInterface.class, new SubInterfaceKey(index)); + } + + private void whenCreateSubifThenSuccess() { + doReturn(future(new CreateSubifReply())).when(api).createSubif(any(CreateSubif.class)); + } + + /** + * Failure response send + */ + private void whenCreateSubifThenFailure() { + doReturn(failedFuture()).when(api).createSubif(any(CreateSubif.class)); + } + + private void whenSwInterfaceSetFlagsThenSuccess() { + doReturn(future(new SwInterfaceSetFlagsReply())).when(api).swInterfaceSetFlags(any(SwInterfaceSetFlags.class)); + } + + private SwInterfaceSetFlags verifySwInterfaceSetFlagsWasInvoked(final SwInterfaceSetFlags expected) + throws VppBaseCallException { + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(SwInterfaceSetFlags.class); + verify(api).swInterfaceSetFlags(argumentCaptor.capture()); + final SwInterfaceSetFlags actual = argumentCaptor.getValue(); + + assertEquals(expected.swIfIndex, actual.swIfIndex); + assertEquals(expected.adminUpDown, actual.adminUpDown); + return actual; + } + + @Test + public void testCreateTwoTags() throws Exception { + final SubInterface subInterface = generateSubInterface(false, Arrays.asList(STAG_100, CTAG_200)); + final InstanceIdentifier id = getSubInterfaceId(SUPER_IF_NAME, SUBIF_INDEX); + + whenCreateSubifThenSuccess(); + whenSwInterfaceSetFlagsThenSuccess(); + + customizer.writeCurrentAttributes(id, subInterface, writeContext); + + verify(api).createSubif(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ID, false)); + verify(mappingContext) + .put(eq(mappingIid(SUB_IFACE_NAME, IFC_TEST_INSTANCE)), eq( + mapping(SUB_IFACE_NAME, 0).get())); + } + + @Test + public void testCreateDot1qAnyTag() throws Exception { + final SubInterface subInterface = generateSubInterface(false, Arrays.asList(STAG_100, CTAG_ANY)); + final InstanceIdentifier id = getSubInterfaceId(SUPER_IF_NAME, SUBIF_INDEX); + + whenCreateSubifThenSuccess(); + whenSwInterfaceSetFlagsThenSuccess(); + + customizer.writeCurrentAttributes(id, subInterface, writeContext); + + verify(api).createSubif(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ANY_ID, true)); + verify(mappingContext) + .put(eq(mappingIid(SUB_IFACE_NAME, IFC_TEST_INSTANCE)), eq( + mapping(SUB_IFACE_NAME, 0).get())); + } + + @Test + public void testCreateFailed() throws Exception { + final SubInterface subInterface = generateSubInterface(false, Arrays.asList(STAG_100, CTAG_200)); + final InstanceIdentifier id = getSubInterfaceId(SUPER_IF_NAME, SUBIF_INDEX); + + whenCreateSubifThenFailure(); + + try { + customizer.writeCurrentAttributes(id, subInterface, writeContext); + } catch (WriteFailedException.CreateFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verify(api).createSubif(generateSubInterfaceRequest(SUPER_IF_ID, CTAG_ID, false)); + verify(mappingContext, times(0)).put( + eq(mappingIid(SUPER_IF_NAME, IFC_TEST_INSTANCE)), + eq(mapping(SUPER_IF_NAME, 0).get())); + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test + public void testUpdate() throws Exception { + final List tags = Arrays.asList(STAG_100, CTAG_200); + final SubInterface before = generateSubInterface(false, tags); + final SubInterface after = generateSubInterface(true, tags); + final InstanceIdentifier id = getSubInterfaceId(SUPER_IF_NAME, SUBIF_INDEX); + + whenSwInterfaceSetFlagsThenSuccess(); + customizer.updateCurrentAttributes(id, before, after, writeContext); + + verifySwInterfaceSetFlagsWasInvoked(generateSwInterfaceEnableRequest(SUBIF_INDEX)); + } + + @Test(expected = UnsupportedOperationException.class) + public void testDelete() throws Exception { + final SubInterface subInterface = generateSubInterface(false, Arrays.asList(STAG_100, CTAG_200)); + customizer.deleteCurrentAttributes(null, subInterface, writeContext); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceL2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceL2CustomizerTest.java new file mode 100644 index 000000000..7812b813e --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceL2CustomizerTest.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.SwInterfaceSetL2Bridge; +import io.fd.jvpp.core.dto.SwInterfaceSetL2BridgeReply; +import io.fd.jvpp.core.types.L2PortType; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.l2.config.attributes.interconnection.BridgeBasedBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.l2.config.attributes.L2Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceL2CustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { + private static final String IFACE_CTX_NAME = "interface-ctx"; + private static final String IF_NAME = "local0"; + private static final int IF_INDEX = 1; + private static final String SUBIF_NAME = "local0.0"; + private static final int SUBIF_INDEX = 11; + private static final long SUBIF_ID = 0; + + private static final InstanceIdentifier IID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)).augmentation( + SubinterfaceAugmentation.class).child(SubInterfaces.class) + .child(SubInterface.class, new SubInterfaceKey(SUBIF_ID)).child(L2.class); + + + private static final String BD_CTX_NAME = "bd-ctx"; + private static final String BD_NAME = "test_bd"; + private static final int BD_INDEX = 13; + + private SubInterfaceL2Customizer customizer; + + @Override + protected void setUpTest() throws Exception { + customizer = new SubInterfaceL2Customizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME), + new NamingContext("bdPrefix", BD_CTX_NAME)); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME); + defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFACE_CTX_NAME); + defineMapping(mappingContext, BD_NAME, BD_INDEX, BD_CTX_NAME); + } + + @Test + public void testWrite() throws WriteFailedException { + final boolean bvi = true; + when(api.swInterfaceSetL2Bridge(any())).thenReturn(future(new SwInterfaceSetL2BridgeReply())); + customizer.writeCurrentAttributes(IID, l2(bvi), writeContext); + verify(api).swInterfaceSetL2Bridge(bridgeRequest(bvi, true)); + } + + @Test + public void testUpdate() throws WriteFailedException { + final boolean bvi = false; + when(api.swInterfaceSetL2Bridge(any())).thenReturn(future(new SwInterfaceSetL2BridgeReply())); + customizer.updateCurrentAttributes(IID, l2(true), l2(bvi), writeContext); + verify(api).swInterfaceSetL2Bridge(bridgeRequest(bvi, true)); + } + + @Test + public void testDelete() throws WriteFailedException { + final boolean bvi = true; + when(api.swInterfaceSetL2Bridge(any())).thenReturn(future(new SwInterfaceSetL2BridgeReply())); + customizer.deleteCurrentAttributes(IID, l2(bvi), writeContext); + verify(api).swInterfaceSetL2Bridge(bridgeRequest(bvi, false)); + } + + private L2 l2(final boolean bvi) { + return new L2Builder().setInterconnection(new BridgeBasedBuilder().setBridgedVirtualInterface(bvi) + .setBridgeDomain(BD_NAME).setSplitHorizonGroup((short) 123).build()).build(); + } + + private SwInterfaceSetL2Bridge bridgeRequest(final boolean bvi, final boolean enable) { + final SwInterfaceSetL2Bridge request = new SwInterfaceSetL2Bridge(); + request.bdId = BD_INDEX; + request.rxSwIfIndex = SUBIF_INDEX; + request.portType = bvi ? L2PortType.L2_API_PORT_TYPE_BVI : L2PortType.L2_API_PORT_TYPE_NORMAL; + request.enable = booleanToByte(enable); + request.shg = 123; + return request; + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceRoutingCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceRoutingCustomizerTest.java new file mode 100644 index 000000000..a80bbd750 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceRoutingCustomizerTest.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.google.common.collect.ImmutableSet; +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.core.dto.SwInterfaceSetTable; +import io.fd.jvpp.core.dto.SwInterfaceSetTableReply; +import java.util.Collections; +import java.util.Optional; +import java.util.Set; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.Routing; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.RoutingBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceRoutingCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { + + private static final String IFACE_CTX_NAME = "interface-ctx"; + private static final String IF_NAME = "eth1"; + private static final String SUBIF_NAME = "eth1.0"; + private static final int IF_INDEX = 1; + private static final int SUBIF_INDEX = 0; + private static final InstanceIdentifier VALID_ID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(SubinterfaceAugmentation.class) + .child(SubInterfaces.class) + .child(SubInterface.class, new SubInterfaceKey((long) SUBIF_INDEX)) + .child(Routing.class); + private static final int DISABLE_VRF = 0; + + @Captor + private ArgumentCaptor requestCaptor; + + + private SubInterfaceRoutingCustomizer customizer; + + @Override + protected void setUpTest() throws Exception { + customizer = new SubInterfaceRoutingCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME)); + defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME); + defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFACE_CTX_NAME); + when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply())); + when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply())); + } + + @Test + public void testWriteIpv4Vrf() throws WriteFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + final Routing v4Routing = new RoutingBuilder().setIpv4VrfId(new VniReference(4L)).build(); + customizer.writeCurrentAttributes(VALID_ID, v4Routing, writeContext); + verifySetTableRequest(1, Collections.singleton(request(false, SUBIF_INDEX, 4))); + } + + @Test + public void testWriteIpv6Vrf() throws WriteFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + final Routing v6Routing = new RoutingBuilder().setIpv6VrfId(new VniReference(3L)).build(); + customizer.writeCurrentAttributes(VALID_ID, v6Routing, writeContext); + verifySetTableRequest(1, Collections.singleton(request(true, SUBIF_INDEX, 3))); + } + + @Test + public void testUpdateIpv4Vrf() throws WriteFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + final Routing routingBefore = new RoutingBuilder().setIpv6VrfId(new VniReference(3L)) + .setIpv4VrfId(new VniReference(4L)).build(); + final Routing routingAfter = new RoutingBuilder().setIpv6VrfId(new VniReference(3L)) + .setIpv4VrfId(new VniReference(5L)).build(); + customizer.updateCurrentAttributes(VALID_ID, routingBefore, routingAfter, writeContext); + verifySetTableRequest(2, ImmutableSet.of(request(false, SUBIF_INDEX, 5), + request(true, SUBIF_INDEX, 3))); + } + + @Test + public void testUpdateIpv6Vrf() throws WriteFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + final Routing routingBefore = new RoutingBuilder().setIpv6VrfId(new VniReference(3L)) + .setIpv4VrfId(new VniReference(4L)).build(); + final Routing routingAfter = new RoutingBuilder().setIpv6VrfId(new VniReference(8L)) + .setIpv4VrfId(new VniReference(4L)).build(); + customizer.updateCurrentAttributes(VALID_ID, routingBefore, routingAfter, writeContext); + verifySetTableRequest(2, ImmutableSet.of(request(false, SUBIF_INDEX, 4), + request(true, SUBIF_INDEX, 8))); + } + + @Test + public void testDeleteIpv4Vrf() throws WriteFailedException { + when(writeContext.readAfter(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + final Routing v4Routing = new RoutingBuilder().setIpv4VrfId(new VniReference(4L)).build(); + customizer.deleteCurrentAttributes(VALID_ID, v4Routing, writeContext); + verifySetTableRequest(1, Collections.singleton(request(false, SUBIF_INDEX, DISABLE_VRF))); + } + + + @Test + public void testDeleteIpv6Vrf() throws WriteFailedException { + when(writeContext.readAfter(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + final Routing v6Routing = new RoutingBuilder().setIpv6VrfId(new VniReference(3L)).build(); + customizer.deleteCurrentAttributes(VALID_ID, v6Routing, writeContext); + verifySetTableRequest(1, Collections.singleton(request(true, SUBIF_INDEX, DISABLE_VRF))); + } + + private SwInterfaceSetTable request(final boolean ipv6, final int index, final int vrf) { + final SwInterfaceSetTable request = new SwInterfaceSetTable(); + request.vrfId = vrf; + request.swIfIndex = index; + request.isIpv6 = booleanToByte(ipv6); + return request; + } + + private void verifySetTableRequest(final int times, final Set requests) { + verify(api, times(times)).swInterfaceSetTable(requestCaptor.capture()); + requestCaptor.getAllValues().containsAll(requests); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceRoutingValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceRoutingValidatorTest.java new file mode 100644 index 000000000..f24b5a607 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceRoutingValidatorTest.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; +import io.fd.honeycomb.translate.write.WriteContext; +import java.util.Collections; +import java.util.Optional; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.Ipv4Builder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip4.attributes.ipv4.AddressBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.Ipv6Builder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.Routing; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.routing.attributes.RoutingBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceRoutingValidatorTest { + + private SubInterfaceRoutingValidator validator; + + @Mock + private WriteContext writeContext; + + private static final String IF_NAME = "eth1"; + private static final int SUBIF_INDEX = 0; + private static final InstanceIdentifier ID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(SubinterfaceAugmentation.class) + .child(SubInterfaces.class) + .child(SubInterface.class, new SubInterfaceKey((long) SUBIF_INDEX)) + .child(Routing.class); + + @Before + public void setUp() { + initMocks(this); + NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); + validator = new SubInterfaceRoutingValidator(ifcContext); + } + + @Test + public void testWriteSuccessful() throws CreateValidationFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + validator.validateWrite(ID, getRouting(), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedV4AddressPresent() throws CreateValidationFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.of(v4AddressPresent())); + validator.validateWrite(ID, getRouting(), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedV6AddressPresent() throws CreateValidationFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.of(v6AddressPresent())); + validator.validateWrite(ID, getRouting(), writeContext); + } + + @Test + public void testUpdateSuccessful() throws UpdateValidationFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + validator.validateUpdate(ID, getRouting(), getRouting(), writeContext); + } + + @Test + public void testDeleteSuccessful() throws DeleteValidationFailedException { + when(writeContext.readBefore(any(InstanceIdentifier.class))).thenReturn(Optional.empty()); + validator.validateDelete(ID, getRouting(), writeContext); + } + + private Routing getRouting() { + return new RoutingBuilder().setIpv4VrfId(new VniReference(4L)).build(); + } + + private SubInterface v4AddressPresent() { + return new SubInterfaceBuilder() + .setIpv4(new Ipv4Builder() + .setAddress(Collections.singletonList(new AddressBuilder().build())) + .build()) + .build(); + } + + private SubInterface v6AddressPresent() { + return new SubInterfaceBuilder() + .setIpv6(new Ipv6Builder() + .setAddress(Collections.singletonList( + new org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.ip6.attributes.ipv6.AddressBuilder() + .build())) + .build()) + .build(); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceUnnumberedCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceUnnumberedCustomizerTest.java new file mode 100644 index 000000000..2be05ec00 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceUnnumberedCustomizerTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.SubinterfaceUnnumberedAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceUnnumberedCustomizerTest extends AbstractUnnumberedCustomizerTest { + private static final String PARENT_IFC_NAME = "eth2"; + private static final String UNNUMBERED_IFC_NAME = "eth2.123"; + private static final int UNNUMBERED_IFC_ID = 2; + private static final long UNNUMBERED_IFC_NUMBER = 123; + private static final InstanceIdentifier UNNUMBERED_IFC_IID = InstanceIdentifier.create(Interfaces.class) + .child(Interface.class, new InterfaceKey(PARENT_IFC_NAME)) + .augmentation(SubinterfaceAugmentation.class).child(SubInterfaces.class) + .child(SubInterface.class, new SubInterfaceKey(UNNUMBERED_IFC_NUMBER)) + .augmentation(SubinterfaceUnnumberedAugmentation.class).child(Unnumbered.class); + + @Override + protected int getUnnumberedIfcId() { + return UNNUMBERED_IFC_ID; + } + + @Override + protected String getUnnumberedIfcName() { + return UNNUMBERED_IFC_NAME; + } + + @Override + protected InstanceIdentifier getUnnumberedIfcIId() { + return UNNUMBERED_IFC_IID; + } + + @Override + protected AbstractUnnumberedCustomizer getCustomizer() { + return new SubInterfaceUnnumberedCustomizer(api, new NamingContext("ifc-prefix", IFC_CTX_NAME)); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceUnnumberedValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceUnnumberedValidatorTest.java new file mode 100644 index 000000000..a99f1b673 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceUnnumberedValidatorTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.WriteContext; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.InterfaceUnnumberedAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.Unnumbered; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.unnumbered.interfaces.rev180103.unnumbered.config.attributes.UnnumberedBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceUnnumberedValidatorTest { + + private SubInterfaceUnnumberedValidator validator; + + @Mock + private WriteContext writeContext; + + private static final String IF_NAME = "eth2"; + private static final String TARGET_IFC0_NAME = "eth0"; + private static final InstanceIdentifier ID = InstanceIdentifier.create(Interfaces.class) + .child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(InterfaceUnnumberedAugmentation.class) + .child(Unnumbered.class); + + @Before + public void setUp() { + initMocks(this); + NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); + validator = new SubInterfaceUnnumberedValidator(ifcContext); + } + + @Test + public void testWriteSuccessful() throws DataValidationFailedException.CreateValidationFailedException { + validator.validateWrite(ID, getUnnumberedIfc(TARGET_IFC0_NAME), writeContext); + } + + @Test(expected = NullPointerException.class) + public void testWriteFailedNoUse() throws DataValidationFailedException.CreateValidationFailedException { + validator.validateWrite(ID, getUnnumberedIfc(null), writeContext); + } + + @Test + public void testUpdateSuccessful() throws DataValidationFailedException.UpdateValidationFailedException { + validator.validateUpdate(ID, getUnnumberedIfc(TARGET_IFC0_NAME), getUnnumberedIfc(TARGET_IFC0_NAME), + writeContext); + } + + @Test + public void testDeleteeSuccessful() throws DataValidationFailedException.DeleteValidationFailedException { + validator.validateDelete(ID, getUnnumberedIfc(TARGET_IFC0_NAME), writeContext); + } + + private Unnumbered getUnnumberedIfc(String use) { + return new UnnumberedBuilder().setUse(use).build(); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceValidatorTest.java new file mode 100644 index 000000000..dce773b33 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/SubInterfaceValidatorTest.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; +import io.fd.honeycomb.translate.write.WriteContext; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.sub._interface.base.attributes.Match; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceValidatorTest { + + private SubInterfaceValidator validator; + + @Mock + private WriteContext writeContext; + + private static final String SUPER_IF_NAME = "local0"; + private static final String SUB_IFACE_NAME = "local0.11"; + private static final long SUBIF_INDEX = 11; + private static final InstanceIdentifier ID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(SUPER_IF_NAME)) + .augmentation( + SubinterfaceAugmentation.class).child(SubInterfaces.class) + .child(SubInterface.class, new SubInterfaceKey(SUBIF_INDEX)); + + @Before + public void setUp() { + initMocks(this); + NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); + validator = new SubInterfaceValidator(ifcContext); + } + + @Test + public void testWriteSuccessful() throws CreateValidationFailedException { + validator + .validateWrite(ID, generateSubInterface(11L, SubInterfaceCustomizerTest.generateMatch()), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoIdentifier() throws CreateValidationFailedException { + validator.validateWrite(ID, generateSubInterface(null, SubInterfaceCustomizerTest.generateMatch()), + writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoMatch() throws CreateValidationFailedException { + validator.validateWrite(ID, generateSubInterface(11L, null), writeContext); + } + + private SubInterface generateSubInterface(final Long identifier, final Match match) { + return new SubInterfaceBuilder() + .setIdentifier(identifier) + .setMatch(match) + .setEnabled(true) + .build(); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/TapV2CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/TapV2CustomizerTest.java new file mode 100644 index 000000000..e7ba2fdce --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/TapV2CustomizerTest.java @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2018 Pantheon Technologies and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.Ipv4Translator; +import io.fd.hc2vpp.common.translate.util.Ipv6Translator; +import io.fd.hc2vpp.common.translate.util.MacTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.jvpp.core.dto.TapCreateV2; +import io.fd.jvpp.core.dto.TapCreateV2Reply; +import io.fd.jvpp.core.dto.TapDeleteV2; +import io.fd.jvpp.core.dto.TapDeleteV2Reply; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.TapV2Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class TapV2CustomizerTest extends WriterCustomizerTest + implements Ipv4Translator, Ipv6Translator, MacTranslator { + + private static final String IFC_TEST_INSTANCE = "ifc-test-instance"; + private TapV2Customizer tapCustomizer; + private static final String HOST_IF_NAME = "tapV21"; + private static final String HOST_BRIDGE = "TestBridge"; + private static final String HOST_IPV4_PREFIX = "192.168.255.100"; + private static final byte HOST_IPV4_PREFIX_LEN = 24; + private static final String HOST_IPV4_GW = "192.168.255.1"; + private static final String HOST_IPV6_PREFIX = "a::100"; + private static final String HOST_IPV6_GW = "a::1"; + private static final byte HOST_IPV6_PREFIX_LEN = -128; + private static final int HOST_IPV6_PREFIX_LEN_EXP = 128; + private static final int RX_TX_RING_SIZE = 512; + private static final String HOST_MAC = "00:ee:ee:ee:ee:ee"; + private static final String HOST_NAMESPACE = "testHostNS"; + + @Override + public void setUpTest() throws Exception { + InterfaceTypeTestUtils.setupWriteContext(writeContext, + org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.TapV2.class); + tapCustomizer = new TapV2Customizer(api, new NamingContext("ifcintest", IFC_TEST_INSTANCE)); + } + + @Test + public void testCreate() throws Exception { + final AtomicInteger idx = new AtomicInteger(0); + doAnswer((i) -> { + final TapCreateV2 tapData = i.getArgument(0); + if (tapData == null) { + return failedFuture(); + } + + Assert.assertArrayEquals(tapData.hostBridge, HOST_BRIDGE.getBytes()); + Assert.assertEquals(tapData.hostBridgeSet, 1); + Assert.assertArrayEquals(tapData.hostIfName, HOST_IF_NAME.getBytes()); + Assert.assertEquals(tapData.hostIfNameSet, 1); + Assert.assertArrayEquals(tapData.hostNamespace, HOST_NAMESPACE.getBytes()); + Assert.assertEquals(tapData.hostNamespaceSet, 1); + Assert.assertArrayEquals(tapData.hostIp4Addr, ipv4AddressPrefixToArray( + new Ipv4Prefix(String.format("%s/%d", HOST_IPV4_PREFIX, HOST_IPV4_PREFIX_LEN)))); + Assert.assertEquals(tapData.hostIp4AddrSet, 1); + Assert.assertEquals(tapData.hostIp4PrefixLen, HOST_IPV4_PREFIX_LEN); + Assert.assertArrayEquals(tapData.hostIp6Addr, ipv6AddressPrefixToArray( + new Ipv6Prefix(String.format("%s/%d", HOST_IPV6_PREFIX, HOST_IPV6_PREFIX_LEN_EXP)))); + Assert.assertEquals(tapData.hostIp6AddrSet, 1); + Assert.assertEquals(tapData.hostIp6PrefixLen, HOST_IPV6_PREFIX_LEN); + Assert.assertArrayEquals(tapData.hostIp4Gw, ipv4AddressPrefixToArray( + new Ipv4Prefix(String.format("%s/%d", HOST_IPV4_GW, 24)))); + Assert.assertEquals(tapData.hostIp4GwSet, 1); + Assert.assertArrayEquals(tapData.hostIp6Gw, ipv6AddressPrefixToArray( + new Ipv6Prefix(String.format("%s/%d", HOST_IPV6_GW, 96)))); + Assert.assertEquals(tapData.hostIp6GwSet, 1); + Assert.assertArrayEquals(tapData.hostMacAddr, parseMac(HOST_MAC)); + Assert.assertEquals(tapData.hostMacAddrSet, 1); + Assert.assertEquals(tapData.rxRingSz, RX_TX_RING_SIZE); + Assert.assertEquals(tapData.txRingSz, RX_TX_RING_SIZE); + final TapCreateV2Reply t = new TapCreateV2Reply(); + t.swIfIndex = idx.getAndIncrement(); + return future(t); + + }).when(api).tapCreateV2(any(TapCreateV2.class)); + + tapCustomizer.writeCurrentAttributes(getTapId("tap"), getTapData("tap"), writeContext); + tapCustomizer.writeCurrentAttributes(getTapId("tap2"), getTapData("tap2"), writeContext); + + verify(api, times(2)).tapCreateV2(any(TapCreateV2.class)); + verify(mappingContext).put(eq(mappingIid("tap", IFC_TEST_INSTANCE)), eq( + mapping("tap", 0).get())); + verify(mappingContext).put(eq(mappingIid("tap2", IFC_TEST_INSTANCE)), eq( + mapping("tap2", 1).get())); + } + + @Test + public void testDelete() throws Exception { + final TapCreateV2Reply t = new TapCreateV2Reply(); + t.swIfIndex = 0; + doReturn(future(t)).when(api).tapCreateV2(any(TapCreateV2.class)); + + doReturn(future(new TapDeleteV2Reply())).when(api).tapDeleteV2(any(TapDeleteV2.class)); + tapCustomizer.writeCurrentAttributes(getTapId("tap-v2"), getTapData("tap-v2"), writeContext); + defineMapping(mappingContext, "tap-v2", 1, IFC_TEST_INSTANCE); + tapCustomizer.deleteCurrentAttributes(getTapId("tap-v2"), getTapData("tap-v2"), writeContext); + + verify(api).tapCreateV2(any(TapCreateV2.class)); + verify(api).tapDeleteV2(any(TapDeleteV2.class)); + verify(mappingContext).delete(eq(mappingIid("tap-v2", IFC_TEST_INSTANCE))); + } + + private InstanceIdentifier getTapId(final String tap) { + return InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(tap)).augmentation( + VppInterfaceAugmentation.class).child(TapV2.class); + } + + private TapV2 getTapData(final String tap) { + return new TapV2Builder() + .setHostInterfaceName(HOST_IF_NAME) + .setMac(new PhysAddress(HOST_MAC)) + .setTag(tap + "_tag") + .setHostBridge(HOST_BRIDGE) + .setHostIpv4Address(new Ipv4Prefix(String.format("%s/%s", HOST_IPV4_PREFIX, HOST_IPV4_PREFIX_LEN))) + .setHostIpv4Gateway(new Ipv4Address(HOST_IPV4_GW)) + .setHostIpv6Address(new Ipv6Prefix(String.format("%s/%s", HOST_IPV6_PREFIX, HOST_IPV6_PREFIX_LEN_EXP))) + .setHostIpv6Gateway(new Ipv6Address(HOST_IPV6_GW)) + .setRxRingSize(RX_TX_RING_SIZE) + .setTxRingSize(RX_TX_RING_SIZE) + .setHostMac(new PhysAddress(HOST_MAC)) + .setHostNamespace(HOST_NAMESPACE) + .build(); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VhostUserCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VhostUserCustomizerTest.java new file mode 100644 index 000000000..0b4d1bce9 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VhostUserCustomizerTest.java @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.Ipv4Translator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.VppBaseCallException; +import io.fd.jvpp.VppInvocationException; +import io.fd.jvpp.core.dto.CreateVhostUserIf; +import io.fd.jvpp.core.dto.CreateVhostUserIfReply; +import io.fd.jvpp.core.dto.DeleteVhostUserIf; +import io.fd.jvpp.core.dto.DeleteVhostUserIfReply; +import io.fd.jvpp.core.dto.ModifyVhostUserIf; +import io.fd.jvpp.core.dto.ModifyVhostUserIfReply; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUserRole; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUser; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUserBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VhostUserCustomizerTest extends WriterCustomizerTest implements Ipv4Translator { + + private static final int IFACE_ID = 1; + private static final String IFACE_NAME = "eth0"; + private static final InstanceIdentifier ID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(VhostUser.class); + private VhostUserCustomizer customizer; + + static VhostUser generateVhostUser(final VhostUserRole role, final String socketName) { + VhostUserBuilder builder = new VhostUserBuilder(); + builder.setRole(role); + builder.setSocket(socketName); + return builder.build(); + } + + @Override + public void setUpTest() throws Exception { + InterfaceTypeTestUtils.setupWriteContext(writeContext, + org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUser.class); + customizer = new VhostUserCustomizer(api, new NamingContext("generatedInterfaceName", "test-instance")); + } + + private CreateVhostUserIf verifyCreateVhostUserIfWasInvoked(final VhostUser vhostUser) + throws VppInvocationException { + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(CreateVhostUserIf.class); + verify(api).createVhostUserIf(argumentCaptor.capture()); + final CreateVhostUserIf actual = argumentCaptor.getValue(); + assertEquals(0, actual.customDevInstance); + + assertEquals(booleanToByte(VhostUserRole.Server.equals(vhostUser.getRole())), actual.isServer); + assertEquals(0, actual.renumber); + assertEquals(0, actual.useCustomMac); + assertArrayEquals(vhostUser.getSocket().getBytes(), actual.sockFilename); + assertNotNull(actual.macAddress); + return actual; + } + + private ModifyVhostUserIf verifyModifyVhostUserIfWasInvoked(final VhostUser vhostUser, final int swIfIndex) + throws VppInvocationException { + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(ModifyVhostUserIf.class); + verify(api).modifyVhostUserIf(argumentCaptor.capture()); + final ModifyVhostUserIf actual = argumentCaptor.getValue(); + assertEquals(0, actual.customDevInstance); + + assertEquals(booleanToByte(VhostUserRole.Server.equals(vhostUser.getRole())), actual.isServer); + assertEquals(0, actual.renumber); + assertEquals(swIfIndex, actual.swIfIndex); + assertArrayEquals(vhostUser.getSocket().getBytes(), actual.sockFilename); + return actual; + } + + private DeleteVhostUserIf verifyDeleteVhostUserIfWasInvoked(final int swIfIndex) throws VppInvocationException { + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(DeleteVhostUserIf.class); + verify(api).deleteVhostUserIf(argumentCaptor.capture()); + final DeleteVhostUserIf actual = argumentCaptor.getValue(); + assertEquals(swIfIndex, actual.swIfIndex); + return actual; + } + + @Test + public void testWriteCurrentAttributes() throws Exception { + final VhostUser vhostUser = generateVhostUser(VhostUserRole.Server, "socketName"); + + when(api.createVhostUserIf(any(CreateVhostUserIf.class))).thenReturn(future(new CreateVhostUserIfReply())); + + customizer.writeCurrentAttributes(ID, vhostUser, writeContext); + verifyCreateVhostUserIfWasInvoked(vhostUser); + verify(mappingContext).put(eq(mappingIid(IFACE_NAME, "test-instance")), eq( + mapping(IFACE_NAME, 0).get())); + } + + @Test + public void testWriteCurrentAttributesFailed() throws Exception { + final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName"); + + doReturn(failedFuture()).when(api).createVhostUserIf(any(CreateVhostUserIf.class)); + + try { + customizer.writeCurrentAttributes(ID, vhostUser, writeContext); + } catch (WriteFailedException.CreateFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyCreateVhostUserIfWasInvoked(vhostUser); + verifyZeroInteractions(mappingContext); + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test + public void testUpdateCurrentAttributes() throws Exception { + final VhostUser vhostUserBefore = generateVhostUser(VhostUserRole.Client, "socketName0"); + final VhostUser vhostUserAfter = generateVhostUser(VhostUserRole.Server, "socketName1"); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); + + when(api.modifyVhostUserIf(any(ModifyVhostUserIf.class))).thenReturn(future(new ModifyVhostUserIfReply())); + + customizer.updateCurrentAttributes(ID, vhostUserBefore, vhostUserAfter, writeContext); + verifyModifyVhostUserIfWasInvoked(vhostUserAfter, IFACE_ID); + } + + @Test + public void testUpdateCurrentAttributesFailed() throws Exception { + final VhostUser vhostUserBefore = generateVhostUser(VhostUserRole.Client, "socketName0"); + final VhostUser vhostUserAfter = generateVhostUser(VhostUserRole.Server, "socketName1"); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); + + doReturn(failedFuture()).when(api).modifyVhostUserIf(any(ModifyVhostUserIf.class)); + + try { + customizer.updateCurrentAttributes(ID, vhostUserBefore, vhostUserAfter, writeContext); + } catch (WriteFailedException.UpdateFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyModifyVhostUserIfWasInvoked(vhostUserAfter, IFACE_ID); + return; + } + fail("WriteFailedException.UpdateFailedException was expected"); + } + + @Test + public void testDeleteCurrentAttributes() throws Exception { + final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName"); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); + + when(api.deleteVhostUserIf(any(DeleteVhostUserIf.class))).thenReturn(future(new DeleteVhostUserIfReply())); + + customizer.deleteCurrentAttributes(ID, vhostUser, writeContext); + verifyDeleteVhostUserIfWasInvoked(IFACE_ID); + verify(mappingContext).delete(eq(mappingIid(IFACE_NAME, "test-instance"))); + } + + @Test + public void testDeleteCurrentAttributesFailed() throws Exception { + final VhostUser vhostUser = generateVhostUser(VhostUserRole.Client, "socketName"); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, "test-instance"); + + doReturn(failedFuture()).when(api).deleteVhostUserIf(any(DeleteVhostUserIf.class)); + + try { + customizer.deleteCurrentAttributes(ID, vhostUser, writeContext); + } catch (WriteFailedException.DeleteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyDeleteVhostUserIfWasInvoked(IFACE_ID); + // Delete from context not invoked if delete from VPP failed + verify(mappingContext, times(0)).delete(eq(mappingIid(IFACE_NAME, "test-instance"))); + verify(mappingContext).read(eq(mappingIid(IFACE_NAME, "test-instance"))); + return; + } + fail("WriteFailedException.DeleteFailedException was expected"); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VhostUserValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VhostUserValidatorTest.java new file mode 100644 index 000000000..a5a89a214 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VhostUserValidatorTest.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.WriteContext; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VhostUserRole; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VhostUser; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VhostUserValidatorTest { + + private VhostUserValidator validator; + + @Mock + private WriteContext writeContext; + + private static final String SOCKET = "testSocket"; + private static final String IFACE_NAME = "eth0"; + private static final InstanceIdentifier ID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(VhostUser.class); + + @Before + public void setUp() { + initMocks(this); + NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); + validator = new VhostUserValidator(ifcContext); + } + + @Test + public void testWriteSuccessful() throws DataValidationFailedException.CreateValidationFailedException { + validator.validateWrite(ID, getVhostUser(SOCKET), writeContext); + } + + @Test(expected = NullPointerException.class) + public void testWriteFailedNoSocket() throws DataValidationFailedException.CreateValidationFailedException { + validator.validateWrite(ID, getVhostUser(null), writeContext); + } + + @Test + public void testUpdateSuccessful() throws DataValidationFailedException.UpdateValidationFailedException { + validator.validateUpdate(ID, getVhostUser(SOCKET), + getVhostUser(SOCKET), writeContext); + } + + @Test + public void testDeleteeSuccessful() throws DataValidationFailedException.DeleteValidationFailedException { + validator.validateDelete(ID, getVhostUser(SOCKET), writeContext); + } + + private VhostUser getVhostUser(final String socketName) { + return VhostUserCustomizerTest.generateVhostUser(VhostUserRole.Client, socketName); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VxlanCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VxlanCustomizerTest.java new file mode 100644 index 000000000..44c8a2ee7 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VxlanCustomizerTest.java @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.DisabledInterfacesManager; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.VppBaseCallException; +import io.fd.jvpp.VppInvocationException; +import io.fd.jvpp.core.dto.VxlanAddDelTunnel; +import io.fd.jvpp.core.dto.VxlanAddDelTunnelReply; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.L2Input; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanVni; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Vxlan; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VxlanCustomizerTest extends WriterCustomizerTest implements AddressTranslator { + + private static final byte ADD_VXLAN = 1; + private static final byte DEL_VXLAN = 0; + + @Mock + private DisabledInterfacesManager disableContext; + + private VxlanCustomizer customizer; + private String ifaceName; + private InstanceIdentifier id; + + private static Vxlan generateVxlan(long vni) { + final VxlanBuilder builder = new VxlanBuilder(); + builder.setSrc(new IpAddressNoZone(new Ipv4AddressNoZone("192.168.20.10"))); + builder.setDst(new IpAddressNoZone(new Ipv4AddressNoZone("192.168.20.11"))); + builder.setEncapVrfId(new VniReference(123L)); + builder.setVni(new VxlanVni(Long.valueOf(vni))); + builder.setDecapNext(L2Input.class); + return builder.build(); + } + + private static Vxlan generateVxlan() { + return generateVxlan(Long.valueOf(11)); + } + + @Override + public void setUpTest() throws Exception { + InterfaceTypeTestUtils.setupWriteContext(writeContext, + org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanTunnel.class); + + customizer = + new VxlanCustomizer(api, new NamingContext("generateInterfaceNAme", "test-instance"), disableContext); + + ifaceName = "eth0"; + id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(ifaceName)) + .augmentation(VppInterfaceAugmentation.class).child(Vxlan.class); + } + + private void whenVxlanAddDelTunnelThenSuccess() { + when(api.vxlanAddDelTunnel(any(VxlanAddDelTunnel.class))).thenReturn(future(new VxlanAddDelTunnelReply())); + } + + private void whenVxlanAddDelTunnelThenFailure() { + doReturn(failedFuture()).when(api).vxlanAddDelTunnel(any(VxlanAddDelTunnel.class)); + } + + private VxlanAddDelTunnel verifyVxlanAddDelTunnelWasInvoked(final Vxlan vxlan) throws VppInvocationException { + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(VxlanAddDelTunnel.class); + verify(api).vxlanAddDelTunnel(argumentCaptor.capture()); + final VxlanAddDelTunnel actual = argumentCaptor.getValue(); + assertEquals(0, actual.isIpv6); + assertEquals(1, actual.decapNextIndex); + + assertArrayEquals(ipAddressToArray(vxlan.getSrc()), actual.srcAddress); + assertArrayEquals(ipAddressToArray(vxlan.getDst()), actual.dstAddress); + assertEquals(vxlan.getEncapVrfId().getValue().intValue(), actual.encapVrfId); + assertEquals(vxlan.getVni().getValue().intValue(), actual.vni); + return actual; + } + + private void verifyVxlanAddWasInvoked(final Vxlan vxlan) throws VppInvocationException { + final VxlanAddDelTunnel actual = verifyVxlanAddDelTunnelWasInvoked(vxlan); + assertEquals(ADD_VXLAN, actual.isAdd); + } + + private void verifyVxlanDeleteWasInvoked(final Vxlan vxlan) throws VppInvocationException { + final VxlanAddDelTunnel actual = verifyVxlanAddDelTunnelWasInvoked(vxlan); + assertEquals(DEL_VXLAN, actual.isAdd); + } + + @Test + public void testWriteCurrentAttributes() throws Exception { + final Vxlan vxlan = generateVxlan(); + + whenVxlanAddDelTunnelThenSuccess(); + noMappingDefined(mappingContext, ifaceName, "test-instance"); + + customizer.writeCurrentAttributes(id, vxlan, writeContext); + verifyVxlanAddWasInvoked(vxlan); + verify(mappingContext).put(eq(mappingIid(ifaceName, "test-instance")), eq(mapping(ifaceName, 0).get())); + } + + @Test + public void testWriteCurrentAttributesWithExistingVxlanPlaceholder() throws Exception { + final Vxlan vxlan = generateVxlan(); + + whenVxlanAddDelTunnelThenSuccess(); + noMappingDefined(mappingContext, ifaceName, "test-instance"); + doReturn(true).when(disableContext).isInterfaceDisabled(0, mappingContext); + + customizer.writeCurrentAttributes(id, vxlan, writeContext); + verifyVxlanAddWasInvoked(vxlan); + verify(mappingContext).put(eq(mappingIid(ifaceName, "test-instance")), eq(mapping(ifaceName, 0).get())); + verify(disableContext).removeDisabledInterface(0, mappingContext); + } + + @Test + public void testWriteCurrentAttributesMappingAlreadyPresent() throws Exception { + final Vxlan vxlan = generateVxlan(); + final int ifaceId = 0; + + whenVxlanAddDelTunnelThenSuccess(); + defineMapping(mappingContext, ifaceName, ifaceId, "test-instance"); + + customizer.writeCurrentAttributes(id, vxlan, writeContext); + verifyVxlanAddWasInvoked(vxlan); + + // Remove the first mapping before putting in the new one + verify(mappingContext).delete(eq(mappingIid(ifaceName, "test-instance"))); + verify(mappingContext) + .put(eq(mappingIid(ifaceName, "test-instance")), eq(mapping(ifaceName, ifaceId).get())); + } + + @Test + public void testWriteCurrentAttributesFailed() throws Exception { + final Vxlan vxlan = generateVxlan(); + + whenVxlanAddDelTunnelThenFailure(); + + try { + customizer.writeCurrentAttributes(id, vxlan, writeContext); + } catch (WriteFailedException.CreateFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyVxlanAddWasInvoked(vxlan); + // Mapping not stored due to failure + verify(mappingContext, times(0)) + .put(eq(mappingIid(ifaceName, "test-instance")), eq(mapping(ifaceName, 0).get())); + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test(expected = UnsupportedOperationException.class) + public void testUpdateCurrentAttributes() throws Exception { + customizer.updateCurrentAttributes(id, generateVxlan(10), generateVxlan(11), writeContext); + } + + @Test + public void testDeleteCurrentAttributes() throws Exception { + final Vxlan vxlan = generateVxlan(); + + whenVxlanAddDelTunnelThenSuccess(); + defineMapping(mappingContext, ifaceName, 1, "test-instance"); + + customizer.deleteCurrentAttributes(id, vxlan, writeContext); + verifyVxlanDeleteWasInvoked(vxlan); + verify(mappingContext).delete(eq(mappingIid(ifaceName, "test-instance"))); + verify(disableContext).disableInterface(1, mappingContext); + } + + @Test + public void testDeleteCurrentAttributesaFailed() throws Exception { + final Vxlan vxlan = generateVxlan(); + + whenVxlanAddDelTunnelThenFailure(); + defineMapping(mappingContext, ifaceName, 1, "test-instance"); + + try { + customizer.deleteCurrentAttributes(id, vxlan, writeContext); + } catch (WriteFailedException.DeleteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyVxlanDeleteWasInvoked(vxlan); + verify(mappingContext, times(0)).delete(eq(mappingIid(ifaceName, "test-instance"))); + return; + } + fail("WriteFailedException.DeleteFailedException was expected"); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VxlanGpeCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VxlanGpeCustomizerTest.java new file mode 100644 index 000000000..9d1581551 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VxlanGpeCustomizerTest.java @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.DisabledInterfacesManager; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.VppBaseCallException; +import io.fd.jvpp.core.dto.VxlanGpeAddDelTunnel; +import io.fd.jvpp.core.dto.VxlanGpeAddDelTunnelReply; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeNextProtocol; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeVni; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpe; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpeBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VxlanGpeCustomizerTest extends WriterCustomizerTest implements AddressTranslator { + + private static final byte ADD_VXLAN_GPE = 1; + private static final byte DEL_VXLAN_GPE = 0; + + @Mock + private DisabledInterfacesManager interfaceDisableContext; + + private VxlanGpeCustomizer customizer; + private String ifaceName; + private InstanceIdentifier id; + + private static VxlanGpe generateVxlanGpe(long vni) { + final VxlanGpeBuilder builder = new VxlanGpeBuilder(); + builder.setLocal(new IpAddressNoZone(new Ipv4AddressNoZone("192.168.20.10"))); + builder.setRemote(new IpAddressNoZone(new Ipv4AddressNoZone("192.168.20.11"))); + builder.setVni(new VxlanGpeVni(Long.valueOf(vni))); + builder.setNextProtocol(VxlanGpeNextProtocol.forValue(1)); + builder.setEncapVrfId(Long.valueOf(123)); + builder.setDecapVrfId(Long.valueOf(456)); + return builder.build(); + } + + private static VxlanGpe generateVxlanGpe() { + return generateVxlanGpe(Long.valueOf(11)); + } + + @Override + public void setUpTest() throws Exception { + InterfaceTypeTestUtils.setupWriteContext(writeContext, + org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeTunnel.class); + NamingContext namingContext = new NamingContext("generateInterfaceName", "test-instance"); + customizer = new VxlanGpeCustomizer(api, namingContext, interfaceDisableContext); + + ifaceName = "elth0"; + id = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(ifaceName)) + .augmentation(VppInterfaceAugmentation.class).child(VxlanGpe.class); + } + + private void whenVxlanGpeAddDelTunnelThenSuccess() { + when(api.vxlanGpeAddDelTunnel(any(VxlanGpeAddDelTunnel.class))) + .thenReturn(future(new VxlanGpeAddDelTunnelReply())); + } + + private void whenVxlanGpeAddDelTunnelThenFailure() { + doReturn(failedFuture()).when(api).vxlanGpeAddDelTunnel(any(VxlanGpeAddDelTunnel.class)); + } + + private VxlanGpeAddDelTunnel verifyVxlanGpeAddDelTunnelWasInvoked(final VxlanGpe vxlanGpe) + throws VppBaseCallException { + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(VxlanGpeAddDelTunnel.class); + verify(api).vxlanGpeAddDelTunnel(argumentCaptor.capture()); + final VxlanGpeAddDelTunnel actual = argumentCaptor.getValue(); + assertEquals(0, actual.isIpv6); + assertArrayEquals(ipAddressToArray(vxlanGpe.getLocal()), actual.local); + assertArrayEquals(ipAddressToArray(vxlanGpe.getRemote()), actual.remote); + assertEquals(vxlanGpe.getVni().getValue().intValue(), actual.vni); + assertEquals(vxlanGpe.getNextProtocol().getIntValue(), actual.protocol); + assertEquals(vxlanGpe.getEncapVrfId().intValue(), actual.encapVrfId); + assertEquals(vxlanGpe.getDecapVrfId().intValue(), actual.decapVrfId); + return actual; + } + + private void verifyVxlanGpeAddWasInvoked(final VxlanGpe vxlanGpe) throws VppBaseCallException { + final VxlanGpeAddDelTunnel actual = verifyVxlanGpeAddDelTunnelWasInvoked(vxlanGpe); + assertEquals(ADD_VXLAN_GPE, actual.isAdd); + } + + private void verifyVxlanGpeDeleteWasInvoked(final VxlanGpe vxlanGpe) throws VppBaseCallException { + final VxlanGpeAddDelTunnel actual = verifyVxlanGpeAddDelTunnelWasInvoked(vxlanGpe); + assertEquals(DEL_VXLAN_GPE, actual.isAdd); + } + + @Test + public void testWriteCurrentAttributes() throws Exception { + final VxlanGpe vxlanGpe = generateVxlanGpe(); + + whenVxlanGpeAddDelTunnelThenSuccess(); + noMappingDefined(mappingContext, ifaceName, "test-instance"); + + customizer.writeCurrentAttributes(id, vxlanGpe, writeContext); + verifyVxlanGpeAddWasInvoked(vxlanGpe); + verify(mappingContext).put(eq(mappingIid(ifaceName, "test-instance")), eq( + mapping(ifaceName, 0).get())); + } + + @Test + public void testWriteCurrentAttributesMappingAlreadyPresent() throws Exception { + final VxlanGpe vxlanGpe = generateVxlanGpe(); + final int ifaceId = 0; + + whenVxlanGpeAddDelTunnelThenSuccess(); + defineMapping(mappingContext, ifaceName, ifaceId, "test-instance"); + + customizer.writeCurrentAttributes(id, vxlanGpe, writeContext); + verifyVxlanGpeAddWasInvoked(vxlanGpe); + + // Remove the first mapping before putting in the new one + verify(mappingContext).delete(eq(mappingIid(ifaceName, "test-instance"))); + verify(mappingContext).put(eq(mappingIid(ifaceName, "test-instance")), + eq(mapping(ifaceName, ifaceId).get())); + } + + @Test + public void testWriteCurrentAttributesFailed() throws Exception { + final VxlanGpe vxlanGpe = generateVxlanGpe(); + + whenVxlanGpeAddDelTunnelThenFailure(); + + try { + customizer.writeCurrentAttributes(id, vxlanGpe, writeContext); + } catch (WriteFailedException.CreateFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyVxlanGpeAddWasInvoked(vxlanGpe); + // Mapping not stored due to failure + verify(mappingContext, times(0)) + .put(eq(mappingIid(ifaceName, "test-instance")), eq( + mapping(ifaceName, 0).get())); + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test(expected = UnsupportedOperationException.class) + public void testUpdateCurrentAttributes() throws Exception { + customizer.updateCurrentAttributes(id, generateVxlanGpe(10), generateVxlanGpe(11), writeContext); + } + + @Test + public void testDeleteCurrentAttributes() throws Exception { + final VxlanGpe vxlanGpe = generateVxlanGpe(); + + whenVxlanGpeAddDelTunnelThenSuccess(); + defineMapping(mappingContext, ifaceName, 1, "test-instance"); + + customizer.deleteCurrentAttributes(id, vxlanGpe, writeContext); + verifyVxlanGpeDeleteWasInvoked(vxlanGpe); + verify(mappingContext).delete(eq(mappingIid(ifaceName, "test-instance"))); + } + + @Test + public void testDeleteCurrentAttributesaFailed() throws Exception { + final VxlanGpe vxlanGpe = generateVxlanGpe(); + + whenVxlanGpeAddDelTunnelThenFailure(); + defineMapping(mappingContext, ifaceName, 1, "test-instance"); + + try { + customizer.deleteCurrentAttributes(id, vxlanGpe, writeContext); + } catch (WriteFailedException.DeleteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyVxlanGpeDeleteWasInvoked(vxlanGpe); + verify(mappingContext, times(0)).delete(eq(mappingIid(ifaceName, "test-instance"))); + return; + } + fail("WriteFailedException.DeleteFailedException was expected"); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VxlanGpeValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VxlanGpeValidatorTest.java new file mode 100644 index 000000000..aad110388 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VxlanGpeValidatorTest.java @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.DisabledInterfacesManager; +import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; +import io.fd.honeycomb.translate.write.WriteContext; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeNextProtocol; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanGpeVni; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpe; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanGpeBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VxlanGpeValidatorTest { + + private VxlanGpeValidator validator; + + @Mock + private WriteContext writeContext; + @Mock + private DisabledInterfacesManager interfaceDisableContext; + + private static final String IPV6 = "a::100"; + private static final String IPV4_1 = "192.168.20.10"; + private static final String IPV4_2 = "192.168.20.11"; + private static final Long VNI = Long.valueOf(11); + private static final Long ENCAP = Long.valueOf(123); + private static final Long DECAP = Long.valueOf(321); + private static final String IFACE_NAME = "eth0"; + private static final InstanceIdentifier ID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(VxlanGpe.class); + + @Before + public void setUp() { + initMocks(this); + NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); + validator = new VxlanGpeValidator(ifcContext, interfaceDisableContext); + } + + @Test + public void testWriteSuccessful() throws CreateValidationFailedException { + validator.validateWrite(ID, generateVxlanCorrect(), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedMixedIpFamilies() throws CreateValidationFailedException { + validator.validateWrite(ID, generateVxlanMixedIpFamilies(), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoLocal() throws CreateValidationFailedException { + validator.validateWrite(ID, generateVxlanSetFields(false, true, true, true, true, true), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoRemote() throws CreateValidationFailedException { + validator.validateWrite(ID, generateVxlanSetFields(true, false, true, true, true, true), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoEncapVrfId() throws CreateValidationFailedException { + validator.validateWrite(ID, generateVxlanSetFields(true, true, false, true, true, true), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoDecapVrfId() throws CreateValidationFailedException { + validator.validateWrite(ID, generateVxlanSetFields(true, true, true, false, true, true), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoVNI() throws CreateValidationFailedException { + validator.validateWrite(ID, generateVxlanSetFields(true, true, true, true, false, true), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoNextProtocol() throws CreateValidationFailedException { + validator.validateWrite(ID, generateVxlanSetFields(true, true, true, true, true, false), writeContext); + } + + @Test + public void testDeleteSuccessful() throws DeleteValidationFailedException { + validator.validateDelete(ID, generateVxlanCorrect(), writeContext); + } + + private VxlanGpe generateVxlanSetFields(final boolean src, final boolean dst, final boolean encapVrfId, + final boolean decapVrfId, final boolean vni, final boolean protocol) { + final VxlanGpeBuilder builder = new VxlanGpeBuilder(); + builder.setLocal(src + ? new IpAddressNoZone(new Ipv4AddressNoZone(IPV4_1)) + : null); + builder.setRemote(dst + ? new IpAddressNoZone(new Ipv4AddressNoZone(IPV4_2)) + : null); + builder.setEncapVrfId(encapVrfId + ? ENCAP + : null); + builder.setDecapVrfId(decapVrfId + ? DECAP + : null); + builder.setVni(vni + ? new VxlanGpeVni(VNI) + : null); + builder.setNextProtocol(protocol + ? VxlanGpeNextProtocol.forValue(1) + : null); + return builder.build(); + } + + private VxlanGpe generateVxlanCorrect() { + return generateVxlanSetFields(true, true, true, true, true, true); + } + + private VxlanGpe generateVxlanMixedIpFamilies() { + return new VxlanGpeBuilder() + .setLocal(new IpAddressNoZone(new Ipv6AddressNoZone(IPV6))) + .setRemote(new IpAddressNoZone(new Ipv4AddressNoZone(IPV4_1))) + .setEncapVrfId(ENCAP).setDecapVrfId(DECAP) + .setVni(new VxlanGpeVni(VNI)) + .setNextProtocol(VxlanGpeNextProtocol.forValue(1)) + .build(); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VxlanValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VxlanValidatorTest.java new file mode 100644 index 000000000..be8ae4694 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/VxlanValidatorTest.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write; + +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.DisabledInterfacesManager; +import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; +import io.fd.honeycomb.translate.write.WriteContext; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.L2Input; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VxlanVni; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Vxlan; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.VxlanBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VxlanValidatorTest { + + private VxlanValidator validator; + + @Mock + private WriteContext writeContext; + @Mock + private DisabledInterfacesManager interfaceDisableContext; + + private static final String IPV6 = "a::100"; + private static final String IPV4_1 = "192.168.20.10"; + private static final String IPV4_2 = "192.168.20.11"; + private static final Long VNI = Long.valueOf(11); + private static final Long ENCAP = Long.valueOf(123); + private static final String IFACE_NAME = "eth0"; + private static final InstanceIdentifier ID = + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(Vxlan.class); + + @Before + public void setUp() { + initMocks(this); + NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); + validator = new VxlanValidator(ifcContext, interfaceDisableContext); + } + + @Test + public void testWriteSuccessful() throws CreateValidationFailedException { + validator.validateWrite(ID, generateVxlanCorrect(), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedMixedIpFamilies() throws CreateValidationFailedException { + validator.validateWrite(ID, generateVxlanMixedIpFamilies(), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoSrc() throws CreateValidationFailedException { + validator.validateWrite(ID, generateVxlanSetFields(false, true, true, true), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoDst() throws CreateValidationFailedException { + validator.validateWrite(ID, generateVxlanSetFields(true, false, true, true), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoEncap() throws CreateValidationFailedException { + validator.validateWrite(ID, generateVxlanSetFields(true, true, false, true), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedNoVNI() throws CreateValidationFailedException { + validator.validateWrite(ID, generateVxlanSetFields(true, true, true, false), writeContext); + } + + @Test + public void testDeleteSuccessful() throws DeleteValidationFailedException { + validator.validateDelete(ID, generateVxlanCorrect(), writeContext); + } + + private Vxlan generateVxlan(final IpAddressNoZone src, final IpAddressNoZone dst, final VniReference encapVrfId, + final long vni) { + final VxlanBuilder builder = new VxlanBuilder(); + builder.setSrc(src); + builder.setDst(dst); + builder.setEncapVrfId(encapVrfId); + builder.setVni(new VxlanVni(vni)); + builder.setDecapNext(L2Input.class); + return builder.build(); + } + + private Vxlan generateVxlanSetFields(final boolean src, final boolean dst, final boolean encapVrfId, + final boolean vni) { + final VxlanBuilder builder = new VxlanBuilder(); + builder.setSrc(src + ? new IpAddressNoZone(new Ipv4AddressNoZone(IPV4_1)) + : null); + builder.setDst(dst + ? new IpAddressNoZone(new Ipv4AddressNoZone(IPV4_2)) + : null); + builder.setEncapVrfId(encapVrfId + ? new VniReference(ENCAP) + : null); + builder.setVni(vni + ? new VxlanVni(VNI) + : null); + builder.setDecapNext(L2Input.class); + return builder.build(); + } + + private Vxlan generateVxlanCorrect() { + return generateVxlanSetFields(true, true, true, true); + } + + private Vxlan generateVxlanMixedIpFamilies() { + return generateVxlan(new IpAddressNoZone(new Ipv6AddressNoZone(IPV6)), + new IpAddressNoZone(new Ipv4AddressNoZone(IPV4_2)), new VniReference(ENCAP), VNI); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/pbb/PbbRewriteCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/pbb/PbbRewriteCustomizerTest.java new file mode 100644 index 000000000..1591b8e6a --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/pbb/PbbRewriteCustomizerTest.java @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write.pbb; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.jvpp.VppCallbackException; +import io.fd.jvpp.core.dto.L2InterfacePbbTagRewrite; +import io.fd.jvpp.core.dto.L2InterfacePbbTagRewriteReply; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.pbb.types.rev161214.Operation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.PbbRewriteInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewrite; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class PbbRewriteCustomizerTest extends WriterCustomizerTest { + + @Captor + private ArgumentCaptor rewriteArgumentCaptor; + + private NamingContext interfaceContext; + private PbbRewriteCustomizer customizer; + private InstanceIdentifier validId; + private InstanceIdentifier invalidId; + + @Override + protected void setUpTest() throws Exception { + interfaceContext = new NamingContext("interface", "interface-context"); + customizer = new PbbRewriteCustomizer(api, interfaceContext); + + defineMapping(mappingContext, "pbb-interface", 1, "interface-context"); + validId = InstanceIdentifier.create(Interfaces.class) + .child(Interface.class, new InterfaceKey("pbb-interface")) + .augmentation(PbbRewriteInterfaceAugmentation.class) + .child(PbbRewrite.class); + + invalidId = InstanceIdentifier.create(PbbRewrite.class); + } + + @Test + public void testWrite() throws WriteFailedException { + whenRewriteThenSuccess(); + customizer.writeCurrentAttributes(validId, PbbRewriteValidatorTest.validData(), writeContext); + verifyRewriteRequest(desiredSetResult()); + } + + @Test + public void testWriteFailedCallFailed() { + whenRewriteThenFail(); + final PbbRewrite validData = PbbRewriteValidatorTest.validData(); + try { + customizer.writeCurrentAttributes(validId, validData, writeContext); + } catch (Exception e) { + assertTrue(e instanceof WriteFailedException.CreateFailedException); + assertTrue(e.getCause() instanceof VppCallbackException); + + final WriteFailedException.CreateFailedException ex = ((WriteFailedException.CreateFailedException) e); + assertEquals(validId, ex.getFailedId()); + assertEquals(validData, ex.getData()); + return; + } + + fail("Test should have failed"); + } + + @Test + public void testUpdate() throws WriteFailedException { + whenRewriteThenSuccess(); + final PbbRewrite rewrite = PbbRewriteValidatorTest.validData(); + customizer.updateCurrentAttributes(validId, rewrite, rewrite, writeContext); + verifyRewriteRequest(desiredSetResult()); + } + + @Test + public void testUpdateFailedCallFailed() { + whenRewriteThenFail(); + final PbbRewrite invalidData = PbbRewriteValidatorTest.invalidDataNoVlan(); + final PbbRewrite validData = PbbRewriteValidatorTest.validData(); + try { + customizer.updateCurrentAttributes(validId, invalidData, validData, writeContext); + } catch (Exception e) { + assertTrue(e instanceof WriteFailedException.UpdateFailedException); + assertTrue(e.getCause() instanceof VppCallbackException); + + final WriteFailedException.UpdateFailedException ex = ((WriteFailedException.UpdateFailedException) e); + assertEquals(validId, ex.getFailedId()); + assertEquals(invalidData, ex.getDataBefore()); + assertEquals(validData, ex.getDataAfter()); + return; + } + + fail("Test should have failed"); + } + + @Test + public void testDelete() throws WriteFailedException { + whenRewriteThenSuccess(); + customizer.deleteCurrentAttributes(validId, PbbRewriteValidatorTest.validData(), writeContext); + verifyRewriteRequest(desiredDisableResult()); + } + + @Test + public void testDeleteFailedCallFailed() { + whenRewriteThenFail(); + final PbbRewrite validData = PbbRewriteValidatorTest.validData(); + try { + customizer.deleteCurrentAttributes(validId, validData, writeContext); + } catch (Exception e) { + assertTrue(e instanceof WriteFailedException.DeleteFailedException); + assertTrue(e.getCause() instanceof VppCallbackException); + assertEquals(validId, ((WriteFailedException.DeleteFailedException) e).getFailedId()); + return; + } + + fail("Test should have failed"); + } + + private void whenRewriteThenSuccess() { + when(api.l2InterfacePbbTagRewrite(any())).thenReturn(future(new L2InterfacePbbTagRewriteReply())); + } + + private void whenRewriteThenFail() { + when(api.l2InterfacePbbTagRewrite(any())).thenReturn(failedFuture()); + } + + private L2InterfacePbbTagRewrite desiredSetResult() { + final L2InterfacePbbTagRewrite desiredResult = new L2InterfacePbbTagRewrite(); + desiredResult.swIfIndex = 1; + desiredResult.vtrOp = Operation.Pop2.getIntValue(); + desiredResult.bDmac = new byte[]{-69, -69, -69, -69, -69, -69}; + desiredResult.bSmac = new byte[]{-86, -86, -86, -86, -86, -86}; + desiredResult.bVlanid = 1234; + desiredResult.iSid = 2; + + return desiredResult; + } + + private L2InterfacePbbTagRewrite desiredDisableResult() { + final L2InterfacePbbTagRewrite desiredResult = new L2InterfacePbbTagRewrite(); + desiredResult.swIfIndex = 1; + desiredResult.vtrOp = 0; + desiredResult.bDmac = new byte[]{-69, -69, -69, -69, -69, -69}; + desiredResult.bSmac = new byte[]{-86, -86, -86, -86, -86, -86}; + desiredResult.bVlanid = 1234; + desiredResult.iSid = 2; + + return desiredResult; + } + + private void verifyRewriteRequest(final L2InterfacePbbTagRewrite desiredResult) { + verify(api, times(1)).l2InterfacePbbTagRewrite(rewriteArgumentCaptor.capture()); + + final L2InterfacePbbTagRewrite actualRequest = rewriteArgumentCaptor.getValue(); + + assertNotNull(actualRequest); + assertEquals(actualRequest.bVlanid, desiredResult.bVlanid); + assertEquals(actualRequest.iSid, desiredResult.iSid); + assertEquals(actualRequest.vtrOp, desiredResult.vtrOp); + assertEquals(actualRequest.outerTag, desiredResult.outerTag); + assertArrayEquals(actualRequest.bDmac, desiredResult.bDmac); + assertArrayEquals(actualRequest.bSmac, desiredResult.bSmac); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/pbb/PbbRewriteValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/pbb/PbbRewriteValidatorTest.java new file mode 100644 index 000000000..c559953ad --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/pbb/PbbRewriteValidatorTest.java @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write.pbb; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException.CreateValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.DeleteValidationFailedException; +import io.fd.honeycomb.translate.write.DataValidationFailedException.UpdateValidationFailedException; +import io.fd.honeycomb.translate.write.WriteContext; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.pbb.types.rev161214.Operation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.PbbRewriteInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewrite; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewriteBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class PbbRewriteValidatorTest { + + private PbbRewriteValidator validator; + private InstanceIdentifier validId; + private InstanceIdentifier invalidId; + + @Mock + private WriteContext writeContext; + + @Before + public void setUp() { + initMocks(this); + NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); + validator = new PbbRewriteValidator(ifcContext); + validId = InstanceIdentifier.create(Interfaces.class) + .child(Interface.class, new InterfaceKey("pbb-interface")) + .augmentation(PbbRewriteInterfaceAugmentation.class) + .child(PbbRewrite.class); + + invalidId = InstanceIdentifier.create(PbbRewrite.class); + } + + @Test + public void testWriteSuccessful() + throws CreateValidationFailedException { + validator.validateWrite(validId, validData(), writeContext); + } + + @Test(expected = CreateValidationFailedException.class) + public void testWriteFailedInvalidIID() + throws CreateValidationFailedException { + validator.validateWrite(invalidId, validData(), writeContext); + } + + @Test + public void testWriteFailedInvalidData() { + verifyInvalidWriteDataCombination(invalidDataNoDestination()); + verifyInvalidWriteDataCombination(invalidDataNoSource()); + verifyInvalidWriteDataCombination(invalidDataNoItag()); + verifyInvalidWriteDataCombination(invalidDataNoOperation()); + verifyInvalidWriteDataCombination(invalidDataNoVlan()); + } + + @Test + public void testUpdateFailedInvalidData() { + verifyInvalidUpdateDataCombination(invalidDataNoDestination()); + verifyInvalidUpdateDataCombination(invalidDataNoSource()); + verifyInvalidUpdateDataCombination(invalidDataNoItag()); + verifyInvalidUpdateDataCombination(invalidDataNoOperation()); + verifyInvalidUpdateDataCombination(invalidDataNoVlan()); + } + + @Test + public void testDeleteFailedInvalidData() { + verifyInvalidDeleteDataCombination(invalidDataNoDestination()); + verifyInvalidDeleteDataCombination(invalidDataNoSource()); + verifyInvalidDeleteDataCombination(invalidDataNoItag()); + verifyInvalidDeleteDataCombination(invalidDataNoOperation()); + verifyInvalidDeleteDataCombination(invalidDataNoVlan()); + } + + private void verifyInvalidWriteDataCombination(final PbbRewrite invalidData) { + try { + validator.validateWrite(validId, invalidData, writeContext); + } catch (Exception e) { + assertTrue(e instanceof CreateValidationFailedException); + return; + } + + fail("Verifying of invalid combination failed"); + } + + private void verifyInvalidUpdateDataCombination(final PbbRewrite invalidData) { + try { + validator.validateUpdate(validId, validData(), invalidData, writeContext); + } catch (Exception e) { + assertTrue(e instanceof UpdateValidationFailedException); + return; + } + + fail("Verifying of invalid combination failed"); + } + + private void verifyInvalidDeleteDataCombination(final PbbRewrite invalidData) { + try { + validator.validateDelete(validId, invalidData, writeContext); + } catch (Exception e) { + assertTrue(e instanceof DeleteValidationFailedException); + return; + } + + fail("Verifying of invalid combination failed"); + } + + static PbbRewrite invalidDataNoDestination() { + return new PbbRewriteBuilder() + .setBVlanTagVlanId(1234) + .setITagIsid(2L) + .setSourceAddress(new MacAddress("aa:aa:aa:aa:aa:aa")) + .setInterfaceOperation(Operation.Pop2) + .build(); + } + + static PbbRewrite invalidDataNoSource() { + return new PbbRewriteBuilder() + .setBVlanTagVlanId(1234) + .setITagIsid(2L) + .setDestinationAddress(new MacAddress("bb:bb:bb:bb:bb:bb")) + .setInterfaceOperation(Operation.Pop2) + .build(); + } + + static PbbRewrite invalidDataNoItag() { + return new PbbRewriteBuilder() + .setBVlanTagVlanId(1234) + .setSourceAddress(new MacAddress("aa:aa:aa:aa:aa:aa")) + .setDestinationAddress(new MacAddress("bb:bb:bb:bb:bb:bb")) + .setInterfaceOperation(Operation.Pop2) + .build(); + } + + static PbbRewrite invalidDataNoVlan() { + return new PbbRewriteBuilder() + .setITagIsid(2L) + .setSourceAddress(new MacAddress("aa:aa:aa:aa:aa:aa")) + .setDestinationAddress(new MacAddress("bb:bb:bb:bb:bb:bb")) + .setInterfaceOperation(Operation.Pop2) + .build(); + } + + static PbbRewrite invalidDataNoOperation() { + return new PbbRewriteBuilder() + .setITagIsid(2L) + .setSourceAddress(new MacAddress("aa:aa:aa:aa:aa:aa")) + .setDestinationAddress(new MacAddress("bb:bb:bb:bb:bb:bb")) + .setInterfaceOperation(Operation.Pop2) + .build(); + } + + static PbbRewrite validData() { + return new PbbRewriteBuilder() + .setBVlanTagVlanId(1234) + .setITagIsid(2L) + .setSourceAddress(new MacAddress("aa:aa:aa:aa:aa:aa")) + .setDestinationAddress(new MacAddress("bb:bb:bb:bb:bb:bb")) + .setInterfaceOperation(Operation.Pop2) + .build(); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/span/MirroredInterfacesCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/span/MirroredInterfacesCustomizerTest.java new file mode 100644 index 000000000..879e8c08e --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/span/MirroredInterfacesCustomizerTest.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write.span; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.jvpp.core.dto.SwInterfaceSpanEnableDisable; +import io.fd.jvpp.core.dto.SwInterfaceSpanEnableDisableReply; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.SpanState; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Span; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class MirroredInterfacesCustomizerTest extends WriterCustomizerTest { + + private static final String IFACE_NAME = "iface"; + private static final int IFACE_INDEX = 3; + private static final String SRC_IFACE_NAME = "src-iface"; + private static final int SRC_IFACE_INDEX = 5; + + private NamingContext interfaceContext; + private MirroredInterfaceCustomizer customizer; + + private InstanceIdentifier validId; + private MirroredInterface validData; + + @Captor + private ArgumentCaptor requestCaptor; + + @Override + public void setUpTest() { + interfaceContext = new NamingContext("iface", "iface-context"); + customizer = + new MirroredInterfaceCustomizer(api, interfaceContext, id -> id.firstKeyOf(Interface.class).getName()); + defineMapping(mappingContext, IFACE_NAME, IFACE_INDEX, "iface-context"); + defineMapping(mappingContext, SRC_IFACE_NAME, SRC_IFACE_INDEX, "iface-context"); + + validId = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(Span.class) + .child(MirroredInterfaces.class) + .child(MirroredInterface.class); + + validData = new MirroredInterfaceBuilder() + .setIfaceRef(SRC_IFACE_NAME) + .setState(SpanState.Receive) + .build(); + + when(api.swInterfaceSpanEnableDisable(any())).thenReturn(future(new SwInterfaceSpanEnableDisableReply())); + } + + @Test + public void writeCurrentAttributes() throws Exception { + customizer.writeCurrentAttributes(validId, validData, writeContext); + verify(api, times(1)).swInterfaceSpanEnableDisable(requestCaptor.capture()); + assertCreateRequest(requestCaptor.getValue()); + } + + @Test(expected = UnsupportedOperationException.class) + public void updateCurrentAttributes() throws Exception { + customizer.updateCurrentAttributes(validId, validData, validData, writeContext); + } + + @Test + public void deleteCurrentAttributes() throws Exception { + customizer.deleteCurrentAttributes(validId, validData, writeContext); + verify(api, times(1)).swInterfaceSpanEnableDisable(requestCaptor.capture()); + assertDeleteRequest(requestCaptor.getValue()); + } + + private static void assertCreateRequest(final SwInterfaceSpanEnableDisable createRequest) { + assertNotNull(createRequest); + assertEquals(1, createRequest.state); + assertEquals(IFACE_INDEX, createRequest.swIfIndexTo); + assertEquals(SRC_IFACE_INDEX, createRequest.swIfIndexFrom); + } + + private static void assertDeleteRequest(final SwInterfaceSpanEnableDisable deleteRequest) { + assertNotNull(deleteRequest); + assertEquals(0, deleteRequest.state); + assertEquals(IFACE_INDEX, deleteRequest.swIfIndexTo); + assertEquals(SRC_IFACE_INDEX, deleteRequest.swIfIndexFrom); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/span/MirroredInterfacesValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/span/MirroredInterfacesValidatorTest.java new file mode 100644 index 000000000..4bf1230f5 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/write/span/MirroredInterfacesValidatorTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.write.span; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.WriteContext; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.SpanState; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.interfaces._interface.Span; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.MirroredInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.v3po.rev190502.span.attributes.mirrored.interfaces.MirroredInterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class MirroredInterfacesValidatorTest { + + private InstanceIdentifier validId; + private MirroredInterfaceValidator validator; + private static final String IFACE_NAME = "iface"; + private static final String SRC_IFACE_NAME = "src-iface"; + + @Mock + private WriteContext writeContext; + + @Before + public void setUp() { + initMocks(this); + NamingContext ifcContext = new NamingContext("testInterfaceContext", "testInterfaceContext"); + validator = new MirroredInterfaceValidator(ifcContext, id -> id.firstKeyOf(Interface.class).getName()); + validId = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) + .augmentation(VppInterfaceAugmentation.class).child(Span.class) + .child(MirroredInterfaces.class) + .child(MirroredInterface.class); + } + + @Test + public void testWriteSuccessful() + throws DataValidationFailedException.CreateValidationFailedException { + validator.validateWrite(validId, validData(), writeContext); + } + + @Test + public void testWriteFailed() { + validateWritingIncorrectData(incorrectDataNoIfaceRef()); + validateWritingIncorrectData(incorrectDataNoSpanState()); + } + + @Test + public void testUpdateSuccessful() + throws DataValidationFailedException.UpdateValidationFailedException { + validator.validateUpdate(validId, validData(), validData(), writeContext); + } + + @Test + public void testDeleteSuccessful() + throws DataValidationFailedException.DeleteValidationFailedException { + validator.validateDelete(validId, validData(), writeContext); + } + + private void validateWritingIncorrectData(final MirroredInterface data) { + try { + validator.validateWrite(validId, data, writeContext); + } catch (DataValidationFailedException.CreateValidationFailedException e) { + assertTrue(e instanceof DataValidationFailedException.CreateValidationFailedException); + return; + } + fail("Verifying of invalid combination failed"); + } + + private MirroredInterface incorrectDataNoIfaceRef() { + return new MirroredInterfaceBuilder() + .setIfaceRef(null) + .setState(SpanState.Receive) + .build(); + } + + private MirroredInterface incorrectDataNoSpanState() { + return new MirroredInterfaceBuilder() + .setIfaceRef(SRC_IFACE_NAME) + .setState(null) + .build(); + } + + private MirroredInterface validData() { + return new MirroredInterfaceBuilder() + .setIfaceRef(SRC_IFACE_NAME) + .setState(SpanState.Receive) + .build(); + } +} diff --git a/vpp-classifier/api/src/main/yang/interface-policer@2017-03-15.yang b/vpp-classifier/api/src/main/yang/interface-policer@2017-03-15.yang index 1ff9e231d..2220ea412 100644 --- a/vpp-classifier/api/src/main/yang/interface-policer@2017-03-15.yang +++ b/vpp-classifier/api/src/main/yang/interface-policer@2017-03-15.yang @@ -75,10 +75,4 @@ module interface-policer { uses interface-policer-attributes; } - - augment /if:interfaces-state/if:interface { - ext:augment-identifier "policer-interface-state-augmentation"; - - uses interface-policer-attributes; - } } diff --git a/vpp-classifier/api/src/main/yang/vpp-interface-acl@2017-03-15.yang b/vpp-classifier/api/src/main/yang/vpp-interface-acl@2017-03-15.yang index 7c0f4ca1d..dc976a81d 100644 --- a/vpp-classifier/api/src/main/yang/vpp-interface-acl@2017-03-15.yang +++ b/vpp-classifier/api/src/main/yang/vpp-interface-acl@2017-03-15.yang @@ -50,9 +50,4 @@ module vpp-interface-acl { ext:augment-identifier "vpp-interface-acl-augmentation"; uses vpp-classifier-acl:vpp-acl-attributes; } - - augment /if:interfaces-state/if:interface { - ext:augment-identifier "vpp-interface-acl-state-augmentation"; - uses vpp-classifier-acl:vpp-acl-attributes; - } } diff --git a/vpp-classifier/api/src/main/yang/vpp-subinterface-acl@2017-03-15.yang b/vpp-classifier/api/src/main/yang/vpp-subinterface-acl@2017-03-15.yang index 6c0c77d65..ff2e32227 100644 --- a/vpp-classifier/api/src/main/yang/vpp-subinterface-acl@2017-03-15.yang +++ b/vpp-classifier/api/src/main/yang/vpp-subinterface-acl@2017-03-15.yang @@ -54,9 +54,4 @@ module vpp-subinterface-acl { ext:augment-identifier "vpp-subinterface-acl-augmentation"; uses vpp-classifier-acl:vpp-acl-attributes; } - - augment /if:interfaces-state/if:interface/vpp-vlan:sub-interfaces/vpp-vlan:sub-interface { - ext:augment-identifier "vpp-subinterface-acl-state-augmentation"; - uses vpp-classifier-acl:vpp-acl-attributes; - } } diff --git a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/policer/read/InterfacePolicerCustomizer.java b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/policer/read/InterfacePolicerCustomizer.java index 9c3f39920..5620af9e7 100644 --- a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/policer/read/InterfacePolicerCustomizer.java +++ b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/policer/read/InterfacePolicerCustomizer.java @@ -34,10 +34,10 @@ import io.fd.jvpp.core.dto.PolicerClassifyDump; import io.fd.jvpp.core.future.FutureJVppCore; import java.util.Optional; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.policer.rev170315.PolicerInterfaceStateAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.policer.rev170315.PolicerInterfaceAugmentationBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.policer.rev170315._interface.policer.attributes.Policer; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.policer.rev170315._interface.policer.attributes.PolicerBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -115,6 +115,6 @@ final class InterfacePolicerCustomizer extends FutureJVppCustomizer @Override public void merge(@Nonnull final Builder builder, @Nonnull final Policer policer) { - ((PolicerInterfaceStateAugmentationBuilder) builder).setPolicer(policer); + ((PolicerInterfaceAugmentationBuilder) builder).setPolicer(policer); } } diff --git a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/policer/read/InterfacePolicerReaderFactory.java b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/policer/read/InterfacePolicerReaderFactory.java index e5b0b5106..2e70eb632 100644 --- a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/policer/read/InterfacePolicerReaderFactory.java +++ b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/policer/read/InterfacePolicerReaderFactory.java @@ -25,18 +25,18 @@ import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; import io.fd.jvpp.core.future.FutureJVppCore; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.policer.rev170315.PolicerInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.policer.rev170315.PolicerInterfaceStateAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.policer.rev170315.PolicerInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.policer.rev170315.PolicerInterfaceAugmentationBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang._interface.policer.rev170315._interface.policer.attributes.Policer; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class InterfacePolicerReaderFactory implements ReaderFactory { private static final InstanceIdentifier IFC_ID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class); - private static final InstanceIdentifier POLICER_IFC_ID = - IFC_ID.augmentation(PolicerInterfaceStateAugmentation.class); + InstanceIdentifier.create(Interfaces.class).child(Interface.class); + private static final InstanceIdentifier POLICER_IFC_ID = + IFC_ID.augmentation(PolicerInterfaceAugmentation.class); private static final InstanceIdentifier POLICER_IID = POLICER_IFC_ID.child(Policer.class); @@ -51,7 +51,7 @@ public class InterfacePolicerReaderFactory implements ReaderFactory { @Override public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { - registry.addStructuralReader(POLICER_IFC_ID, PolicerInterfaceStateAugmentationBuilder.class); + registry.addStructuralReader(POLICER_IFC_ID, PolicerInterfaceAugmentationBuilder.class); registry.add( new GenericReader<>(POLICER_IID, new InterfacePolicerCustomizer(vppApi, ifcContext, classifyTableContext))); } diff --git a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/factory/read/InterfaceAclReaderFactory.java b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/factory/read/InterfaceAclReaderFactory.java index 27a2cb12e..50a70cd03 100644 --- a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/factory/read/InterfaceAclReaderFactory.java +++ b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/factory/read/InterfaceAclReaderFactory.java @@ -27,8 +27,8 @@ import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; import io.fd.jvpp.core.future.FutureJVppCore; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp._interface.acl.rev170315.VppInterfaceAclStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp._interface.acl.rev170315.VppInterfaceAclStateAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp._interface.acl.rev170315.VppInterfaceAclAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp._interface.acl.rev170315.VppInterfaceAclAugmentationBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.Ip4Acl; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.Ip6Acl; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.L2Acl; @@ -36,16 +36,16 @@ import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.re import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.AclBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.Ingress; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.IngressBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class InterfaceAclReaderFactory implements ReaderFactory{ private static final InstanceIdentifier IFC_ID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class); - private static final InstanceIdentifier VPP_IFC_AUG_ID = - IFC_ID.augmentation(VppInterfaceAclStateAugmentation.class); + InstanceIdentifier.create(Interfaces.class).child(Interface.class); + private static final InstanceIdentifier VPP_IFC_AUG_ID = + IFC_ID.augmentation(VppInterfaceAclAugmentation.class); @Inject private FutureJVppCore jvpp; @@ -61,7 +61,7 @@ public class InterfaceAclReaderFactory implements ReaderFactory{ @Override public void init(@Nonnull ModifiableReaderRegistryBuilder registry) { // Acl augmentation(structural) - registry.addStructuralReader(VPP_IFC_AUG_ID, VppInterfaceAclStateAugmentationBuilder.class); + registry.addStructuralReader(VPP_IFC_AUG_ID, VppInterfaceAclAugmentationBuilder.class); // Acl(Structural) final InstanceIdentifier aclIid = VPP_IFC_AUG_ID.child(Acl.class); registry.addStructuralReader(aclIid, AclBuilder.class); diff --git a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/factory/read/SubInterfaceAclReaderFactory.java b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/factory/read/SubInterfaceAclReaderFactory.java index 504573ea2..cac5e2a72 100644 --- a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/factory/read/SubInterfaceAclReaderFactory.java +++ b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/factory/read/SubInterfaceAclReaderFactory.java @@ -33,26 +33,26 @@ import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.re import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.Acl; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.AclBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.Ingress; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.subinterface.acl.rev170315.VppSubinterfaceAclStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.subinterface.acl.rev170315.VppSubinterfaceAclStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.subinterface.acl.rev170315.VppSubinterfaceAclAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.subinterface.acl.rev170315.VppSubinterfaceAclAugmentationBuilder; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class SubInterfaceAclReaderFactory implements ReaderFactory { - static final InstanceIdentifier IFC_STATE_ID = - InstanceIdentifier.create(InterfacesState.class); + static final InstanceIdentifier IFC_STATE_ID = + InstanceIdentifier.create(Interfaces.class); static final InstanceIdentifier IFC_ID = IFC_STATE_ID.child(Interface.class); - private static final InstanceIdentifier SUB_IFC_AUG_ID = - IFC_ID.augmentation(SubinterfaceStateAugmentation.class) + private static final InstanceIdentifier SUB_IFC_AUG_ID = + IFC_ID.augmentation(SubinterfaceAugmentation.class) .child(SubInterfaces.class) .child(SubInterface.class) - .augmentation(VppSubinterfaceAclStateAugmentation.class); + .augmentation(VppSubinterfaceAclAugmentation.class); @Inject private FutureJVppCore jvpp; @@ -68,7 +68,7 @@ public class SubInterfaceAclReaderFactory implements ReaderFactory { @Override public void init(@Nonnull ModifiableReaderRegistryBuilder registry) { // Aug readed(Structural) - registry.addStructuralReader(SUB_IFC_AUG_ID, VppSubinterfaceAclStateAugmentationBuilder.class); + registry.addStructuralReader(SUB_IFC_AUG_ID, VppSubinterfaceAclAugmentationBuilder.class); // Acl(Structural) final InstanceIdentifier aclIid = SUB_IFC_AUG_ID.child(Acl.class); registry.addStructuralReader(aclIid, AclBuilder.class); diff --git a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/read/ClassifySessionReader.java b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/read/ClassifySessionReader.java index 9c69433f0..6c9fe8a0c 100644 --- a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/read/ClassifySessionReader.java +++ b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/read/ClassifySessionReader.java @@ -18,12 +18,11 @@ package io.fd.hc2vpp.vpp.classifier.read; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Optional; import com.google.common.base.Preconditions; import com.google.common.primitives.UnsignedInts; import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceDataTranslator; +import io.fd.hc2vpp.v3po.read.InterfaceDataTranslator; import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.read.ReadContext; @@ -36,6 +35,7 @@ import io.fd.jvpp.core.future.FutureJVppCore; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import javax.annotation.Nonnull; import javax.annotation.Nullable; diff --git a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/read/ClassifyTableReader.java b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/read/ClassifyTableReader.java index 61859b16a..b4378da70 100644 --- a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/read/ClassifyTableReader.java +++ b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/read/ClassifyTableReader.java @@ -18,13 +18,12 @@ package io.fd.hc2vpp.vpp.classifier.read; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Optional; import com.google.common.base.Preconditions; import com.google.common.primitives.UnsignedInts; import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.MacTranslator; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceDataTranslator; +import io.fd.hc2vpp.v3po.read.InterfaceDataTranslator; import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; @@ -38,6 +37,7 @@ import io.fd.jvpp.core.future.FutureJVppCore; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.rev170327.VppClassifier; diff --git a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/read/acl/AclCustomizer.java b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/read/acl/AclCustomizer.java index f96b3df9d..f15a3d2fd 100644 --- a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/read/acl/AclCustomizer.java +++ b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/read/acl/AclCustomizer.java @@ -22,7 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceCustomizer; +import io.fd.hc2vpp.v3po.read.InterfaceCustomizer; import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; @@ -38,8 +38,8 @@ import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.re import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.AclBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.Ingress; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.IngressBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/read/acl/SubInterfaceAclCustomizer.java b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/read/acl/SubInterfaceAclCustomizer.java index 327af1436..08edecc8b 100644 --- a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/read/acl/SubInterfaceAclCustomizer.java +++ b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/read/acl/SubInterfaceAclCustomizer.java @@ -23,7 +23,7 @@ import static io.fd.hc2vpp.v3po.util.SubInterfaceUtils.getSubInterfaceName; import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceCustomizer; +import io.fd.hc2vpp.v3po.read.SubInterfaceCustomizer; import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; @@ -39,10 +39,10 @@ import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.re import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.Ingress; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.IngressBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.subinterface.acl.rev170315.VppSubinterfaceAclAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/acl/AclCustomizerTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/acl/AclCustomizerTest.java index 539df3010..a04bf2bf2 100644 --- a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/acl/AclCustomizerTest.java +++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/acl/AclCustomizerTest.java @@ -29,15 +29,15 @@ import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.jvpp.core.dto.ClassifyTableByInterfaceReply; import org.junit.Test; import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp._interface.acl.rev170315.VppInterfaceAclStateAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp._interface.acl.rev170315.VppInterfaceAclAugmentation; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.acl.base.attributes.L2AclBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.Acl; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.AclBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.Ingress; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.IngressBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class AclCustomizerTest extends ReaderCustomizerTest { @@ -47,8 +47,8 @@ public class AclCustomizerTest extends ReaderCustomizerTest IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(VppInterfaceAclStateAugmentation.class).child(Acl.class).child(Ingress.class); + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(VppInterfaceAclAugmentation.class).child(Acl.class).child(Ingress.class); private static final String IFC_CTX_NAME = "ifc-test-instance"; diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/acl/SubInterfaceAclCustomizerTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/acl/SubInterfaceAclCustomizerTest.java index 3e39a9cd0..4f6f630cb 100644 --- a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/acl/SubInterfaceAclCustomizerTest.java +++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/read/acl/SubInterfaceAclCustomizerTest.java @@ -35,14 +35,14 @@ import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.re import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.AclBuilder; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.Ingress; import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.classifier.acl.rev170503.vpp.acl.attributes.acl.IngressBuilder; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.subinterface.acl.rev170315.VppSubinterfaceAclStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.SubInterfaces; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces.state._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.state.InterfaceKey; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.subinterface.acl.rev170315.VppSubinterfaceAclAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.SubinterfaceAugmentation; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.vlan.rev180319.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.InterfaceKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class SubInterfaceAclCustomizerTest extends ReaderCustomizerTest { @@ -56,10 +56,10 @@ public class SubInterfaceAclCustomizerTest extends ReaderCustomizerTest IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(SubinterfaceStateAugmentation.class).child(SubInterfaces.class) + InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) + .augmentation(SubinterfaceAugmentation.class).child(SubInterfaces.class) .child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)) - .augmentation(VppSubinterfaceAclStateAugmentation.class) + .augmentation(VppSubinterfaceAclAugmentation.class) .child(Acl.class).child(Ingress.class); private NamingContext interfaceContext; diff --git a/vpp-classifier/policer_postman_collection.json b/vpp-classifier/policer_postman_collection.json index 9a8852755..ca7c97c0b 100644 --- a/vpp-classifier/policer_postman_collection.json +++ b/vpp-classifier/policer_postman_collection.json @@ -287,7 +287,7 @@ "raw": "{\n \"interface-policer:policer\": {\n\t\t\"ip4-table\": \"table0\"\n }\n}" }, "url": { - "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces-state/interface/local0/", + "raw": "http://localhost:8183/restconf/operational/ietf-interfaces:interfaces/interface/local0/", "protocol": "http", "host": [ "localhost" @@ -296,7 +296,7 @@ "path": [ "restconf", "operational", - "ietf-interfaces:interfaces-state", + "ietf-interfaces:interfaces", "interface", "local0", "" -- cgit 1.2.3-korg