Merge "Fix junit dependencies in poms. Reuse existing from parent, add missing ones."
authorDana Kutenicsova <dkutenic@cisco.com>
Sat, 2 Nov 2013 12:33:12 +0000 (12:33 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Sat, 2 Nov 2013 12:33:12 +0000 (12:33 +0000)
268 files changed:
bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/ASSpecificExtendedCommunityTest.java [deleted file]
bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/ClusterIdentifierTest.java [deleted file]
bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/Inet4SpecificExtendedCommunityTest.java [deleted file]
bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/OpaqueExtendedCommunityTest.java [deleted file]
bgp/linkstate/pom.xml
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/Activator.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParser.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParser.java
bgp/linkstate/src/main/yang/bgp-linkstate.yang
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/ActivatorTest.java [new file with mode: 0644]
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/AreaIdentifierTest.java [deleted file]
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParserTest.java [new file with mode: 0644]
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParserTest.java [new file with mode: 0644]
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/TopologyIdentifierTest.java [deleted file]
bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/BGPDocumentedException.java
bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/BGPError.java
bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/BgpTableTypeImpl.java
bgp/parser-api/src/test/java/org/opendaylight/protocol/bgp/parser/APITest.java
bgp/parser-impl/pom.xml
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/Activator.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/BGPMessageFactoryImpl.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/BundleActivator.java [moved from bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/OSGiActivator.java with 91% similarity]
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPKeepAliveMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPNotificationMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPOpenMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPUpdateMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/As4CapabilityHandler.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/GracefulCapabilityHandler.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/MultiProtocolCapabilityHandler.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AsPathSegmentParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/ClusterIdAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunitiesParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunityUtil.java [moved from bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/CommunityUtil.java with 96% similarity]
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/ExtendedCommunitiesAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/OriginatorIdAttributeParser.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/CommunityTest.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ComplementaryTest.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/OpenTest.java [new file with mode: 0644]
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ParserTest.java [moved from bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserTest.java with 80% similarity]
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/PathAttributeParserTest.java
bgp/parser-mock/src/test/java/org/opendaylight/protocol/bgp/parser/mock/BGPMessageParserMockTest.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/CapabilityUtil.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/MessageUtil.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/NlriRegistry.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/NlriUtil.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/ParameterUtil.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/osgi/OSGiBGPExtensionConsumerContext.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/AbstractMessageRegistry.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/ServiceLoaderBGPExtensionProviderContext.java [new file with mode: 0644]
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleAddressFamilyRegistry.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleAttributeRegistry.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleBGPExtensionConsumerContext.java [new file with mode: 0644]
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleBGPExtensionProviderContext.java [moved from bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/BGPExtensionConsumerContextImpl.java with 60% similarity]
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleCapabilityRegistry.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleParameterRegistry.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleSubsequentAddressFamilyRegistry.java
bgp/parser-spi/src/test/java/org/opendaylight/protocol/bgp/parser/spi/UtilsTest.java [new file with mode: 0644]
bgp/rib-api/src/main/yang/bgp-rib.yang
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/Activator.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AdjRIBsInFactoryRegistryImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPMessageHeaderDecoder.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPObjectComparator.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionNegotiator.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionProposalImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSynchronization.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RIBImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/spi/BGPDispatcher.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationTest.java
bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/BGPMock.java
bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/EventBusRegistration.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AbstractAdjRIBsIn.java
bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/Main.java
bgp/testtool/src/test/java/org/opendaylight/protocol/bgp/testtool/BGPSpeakerMock.java
bgp/util/src/main/java/org/opendaylight/protocol/bgp/util/BinaryBGPDumpFileParser.java
bgp/util/src/main/java/org/opendaylight/protocol/bgp/util/HexDumpBGPFileParser.java
bgp/util/src/test/java/org/opendaylight/protocol/bgp/util/BGPHexFileParserTest.java
concepts/src/main/java/org/opendaylight/protocol/concepts/HandlerRegistry.java
concepts/src/main/java/org/opendaylight/protocol/concepts/Ipv4Util.java
concepts/src/main/java/org/opendaylight/protocol/concepts/Ipv6Util.java
concepts/src/main/java/org/opendaylight/protocol/concepts/MultiRegistry.java [new file with mode: 0644]
concepts/src/main/yang/nps-concepts.yang
concepts/src/test/java/org/opendaylight/protocol/concepts/IPAddressesAndPrefixesTest.java
integration-tests/pom.xml
integration-tests/src/test/java/org/opendaylight/protocol/integration/BgpLinkstateBundleTest.java
pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPSession.java
pcep/api/src/main/yang/pcep-types.yang
pcep/impl/pom.xml
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/Activator.java [new file with mode: 0644]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/BundleActivator.java [new file with mode: 0644]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPImplActivator.java [deleted file]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageFactory.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageHeader.java [deleted file]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SingletonPCEPProviderContext.java [deleted file]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/Util.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractObjectWithTlvsParser.java [moved from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/AbstractObjectWithTlvsParser.java with 96% similarity]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractXROWithSubobjectsParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPBandwidthObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPClassTypeObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPCloseObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPErrorObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPGlobalConstraintsObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLoadBalancingObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspaObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPMetricObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNoPathObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNotificationObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPObjectiveFunctionObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPOpenObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPPathKeyObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPRequestParameterObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSrpObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSvecObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROAsNumberSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROExplicitExclusionRouteSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROIpPrefixSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROLabelSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROPathKeySubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROUnnumberedInterfaceSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/GeneralizedLabelChannelSetParser.java [deleted file]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/GeneralizedLabelParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROAsNumberSubobjectParser.java [deleted file]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROIpPrefixSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROLabelSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROPathKeySubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROUnnumberedInterfaceSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/Type1LabelParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/WavebandSwitchingLabelParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROAsNumberSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROIpPrefixSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROPathKeySubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROSRLGSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROUnnumberedInterfaceSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierIPv4TlvParser.java [deleted file]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierIPv6TlvParser.java [deleted file]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierTlvParser.java [new file with mode: 0644]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspDbVersionTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspSymbolicNameTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspUpdateErrorTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/NoPathVectorTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OFListTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OrderTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OverloadedDurationTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/PCEStatefulCapabilityTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/RSVPErrorSpecTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/ReqMissingTlvParser.java
pcep/impl/src/main/resources/META-INF/services/org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator [new file with mode: 0644]
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/LabelSubobjectParserTest.java [new file with mode: 0644]
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java [new file with mode: 0644]
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPRROSubobjectParserTest.java [new file with mode: 0644]
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPSubobjectParserTest.java [deleted file]
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParserTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPXROSubobjectParserTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/ServerSessionMock.java
pcep/impl/src/test/resources/LSPStateDBVersionTlv1.bin [deleted file]
pcep/impl/src/test/resources/LSPStateDBVersionTlv2.bin [deleted file]
pcep/impl/src/test/resources/LSPStateDBVersionTlvInvalid1.bin [deleted file]
pcep/impl/src/test/resources/NoPathObject1WithTLV.bin [deleted file]
pcep/impl/src/test/resources/NoPathObject2WithoutTLV.bin [deleted file]
pcep/impl/src/test/resources/PCEPBandwidthObject1LowerBounds.bin
pcep/impl/src/test/resources/PCEPBandwidthObject2UpperBounds.bin
pcep/impl/src/test/resources/PCEPCloseObject1.bin
pcep/impl/src/test/resources/PCEPEndPointsObject1IPv4.bin
pcep/impl/src/test/resources/PCEPEndPointsObject2IPv6.bin
pcep/impl/src/test/resources/PCEPGlobalConstraintsObject.1.bin
pcep/impl/src/test/resources/PCEPKeepAliveMessage1.bin [deleted file]
pcep/impl/src/test/resources/PCEPLoadBalancingObject1.bin
pcep/impl/src/test/resources/PCEPLspaObject1LowerBounds.bin
pcep/impl/src/test/resources/PCEPLspaObject2UpperBounds.bin
pcep/impl/src/test/resources/PCEPLspaObject3RandVals.bin
pcep/impl/src/test/resources/PCEPMetricObject1LowerBounds.bin
pcep/impl/src/test/resources/PCEPMetricObject2UpperBounds.bin
pcep/impl/src/test/resources/PCEPObjectiveFunctionObject.1.bin
pcep/impl/src/test/resources/PCEPSvecObject1_10ReqIDs.bin
pcep/impl/src/test/resources/PCEPSvecObject2.bin
pcep/impl/src/test/resources/PCEStatefulCapabilityTlv1.bin [deleted file]
pcep/impl/src/test/resources/PCEStatefulCapabilityTlv2.bin [deleted file]
pcep/impl/src/test/resources/PCEStatefulCapabilityTlvInvalid1.bin [deleted file]
pcep/impl/src/test/resources/PackOfSubobjects.bin [deleted file]
pcep/impl/src/test/resources/PackOfTlvs.bin [deleted file]
pcep/impl/src/test/resources/PackOfXROSubobjects.bin [deleted file]
pcep/spi/pom.xml
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/EROSubobjectHandlerRegistry.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelHandlerRegistry.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelSerializer.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageHandlerRegistry.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectHandlerRegistry.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPExtensionConsumerActivator.java [moved from pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPProviderActivator.java with 77% similarity]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPExtensionConsumerContext.java [moved from pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPProviderContext.java with 94% similarity]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPExtensionProviderActivator.java [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPExtensionProviderContext.java [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RROSubobjectHandlerRegistry.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvHandlerRegistry.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/XROSubobjectHandlerRegistry.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/osgi/AbstractOSGiPCEPExtensionConsumerActivator.java [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/osgi/AbstractOSGiPCEPExtensionProviderActivator.java [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/osgi/OSGiPCEPExtensionConsumerContext.java [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/osgi/OSGiPCEPExtensionProviderContext.java [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/PCEPExtensionProviderContextImpl.java [new file with mode: 0644]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleEROSubobjectHandlerRegistry.java [moved from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleEROSubobjectHandlerFactory.java with 87% similarity]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleLabelHandlerRegistry.java [moved from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleLabelHandlerRegistry.java with 63% similarity]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleMessageHandlerRegistry.java [moved from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleMessageHandlerRegistry.java with 91% similarity]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleObjectHandlerRegistry.java [moved from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleObjectHandlerRegistry.java with 76% similarity]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleRROSubobjectHandlerRegistry.java [moved from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleRROSubobjectHandlerFactory.java with 87% similarity]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleTlvHandlerRegistry.java [moved from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleTlvHandlerRegistry.java with 75% similarity]
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleXROSubobjectHandlerRegistry.java [moved from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleXROSubobjectHandlerFactory.java with 87% similarity]
pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java
pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/SimpleSessionListener.java
pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/TestingSessionListener.java
pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java
pom.xml
programming/api/src/main/yang/programming.yang
programming/impl/.project [new file with mode: 0644]
programming/impl/pom.xml [new file with mode: 0644]
programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/BundleActivator.java [new file with mode: 0644]
programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/Instruction.java [new file with mode: 0644]
programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/ProgrammingServiceImpl.java [new file with mode: 0644]
programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/SuccessfulRpcResult.java [new file with mode: 0644]
programming/pom.xml
programming/spi/.project [new file with mode: 0644]
programming/spi/pom.xml [new file with mode: 0644]
programming/spi/src/main/java/org/opendaylight/bgpcep/programming/spi/ExecutionResult.java [new file with mode: 0644]
programming/spi/src/main/java/org/opendaylight/bgpcep/programming/spi/InstructionExecutor.java [new file with mode: 0644]
programming/spi/src/main/java/org/opendaylight/bgpcep/programming/spi/InstructionExecutorRegistry.java [new file with mode: 0644]
programming/tunnel-api/src/main/yang/topology-tunnel-programming.yang
rsvp/api/src/main/yang/rsvp.yang
topology/api/src/main/yang/isis-topology.yang
topology/api/src/main/yang/l3-unicast-igp-topology.yang
topology/api/src/main/yang/network-topology.yang
topology/api/src/main/yang/ospf-topology.yang
topology/api/src/main/yang/ted.yang
topology/pcep-api/.project [new file with mode: 0644]
topology/pcep-api/pom.xml [new file with mode: 0644]
topology/pcep-api/src/main/yang/inventory-pcep.yang [new file with mode: 0644]
topology/pcep-api/src/main/yang/network-topology-pcep.yang [new file with mode: 0644]
topology/pom.xml
topology/provider-bgp/.project [new file with mode: 0644]
topology/provider-bgp/pom.xml [new file with mode: 0644]
topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/LocRIBListener.java [new file with mode: 0644]
topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/LocRIBListeners.java [new file with mode: 0644]
topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/impl/Activator.java [new file with mode: 0644]
topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/impl/LocRIBListenerSubscriptionTracker.java [new file with mode: 0644]
topology/provider-pcep/.project [new file with mode: 0644]
topology/provider-pcep/pom.xml [new file with mode: 0644]
topology/provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/provider/pcep/BundleActivator.java [new file with mode: 0644]
topology/provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/provider/pcep/ServerSessionManager.java [new file with mode: 0644]
topology/provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/provider/pcep/TopologyExporter.java [new file with mode: 0644]
topology/segment-routing/src/main/yang/network-topology-sr.yang
topology/segment-routing/src/main/yang/topology-tunnel-sr.yang
topology/tunnel-api/src/main/yang/topology-tunnel-p2p.yang
topology/tunnel-api/src/main/yang/topology-tunnel.yang
topology/tunnel-pcep-api/.project [moved from topology/tunnel-pcep/.project with 100% similarity]
topology/tunnel-pcep-api/pom.xml [moved from topology/tunnel-pcep/pom.xml with 97% similarity]
topology/tunnel-pcep-api/src/main/yang/topology-tunnel-pcep.yang [moved from topology/tunnel-pcep/src/main/yang/topology-tunnel-pcep.yang with 82% similarity]
topology/tunnel-provider-pcep/.project [new file with mode: 0644]
topology/tunnel-provider-pcep/pom.xml [new file with mode: 0644]
topology/tunnel-provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/tunnel/provider/pcep/BundleActivator.java [new file with mode: 0644]
topology/tunnel-provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/tunnel/provider/pcep/NodeChangedListener.java [new file with mode: 0644]
topology/tunnel-provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/tunnel/provider/pcep/TunnelTopologyExporter.java [new file with mode: 0644]
util/src/main/java/org/opendaylight/protocol/util/DefaultingTypesafeContainer.java [deleted file]
util/src/main/java/org/opendaylight/protocol/util/Util.java [new file with mode: 0644]

diff --git a/bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/ASSpecificExtendedCommunityTest.java b/bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/ASSpecificExtendedCommunityTest.java
deleted file mode 100644 (file)
index 9b5ed81..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.concepts;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import org.junit.Ignore;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.as.specific.extended.community.AsSpecificExtendedCommunity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.as.specific.extended.community.AsSpecificExtendedCommunityBuilder;
-
-public class ASSpecificExtendedCommunityTest {
-
-       private final boolean transitive = true;
-       private final AsNumber globalAdmin = new AsNumber(429496729800L);
-
-       @Test
-       @Ignore
-       // FIXME: length is not implemented
-       public void testOverflows() {
-               try {
-                       new AsSpecificExtendedCommunityBuilder().setTransitive(this.transitive).setGlobalAdministrator(this.globalAdmin).setLocalAdministrator(
-                                       new byte[] {}).build();
-                       fail("Local Administrator has illegal length!");
-               } catch (final IllegalArgumentException e) {
-                       assertEquals("Invalid Local Administrator", e.getMessage());
-               }
-       }
-
-       @Test
-       public void testGetters() {
-               final AsSpecificExtendedCommunity asSpecExCom = new AsSpecificExtendedCommunityBuilder().setTransitive(this.transitive).setGlobalAdministrator(
-                               this.globalAdmin).setLocalAdministrator(new byte[] { 10, 0, 0, 1 }).build();
-               assertEquals(new AsNumber(429496729800L), asSpecExCom.getGlobalAdministrator());
-               assertArrayEquals(new byte[] { 10, 0, 0, 1 }, asSpecExCom.getLocalAdministrator());
-       }
-}
diff --git a/bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/ClusterIdentifierTest.java b/bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/ClusterIdentifierTest.java
deleted file mode 100644 (file)
index 3d1f2d1..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.concepts;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
-
-public class ClusterIdentifierTest {
-
-       @Test
-       public void testClusterIdentifier() {
-               final ClusterIdentifier id = new ClusterIdentifier(new byte[] { 13, 14, 15, 16 });
-               // FIXME: uncomment, once the generated code has length precondition
-               // try {
-               // new ClusterIdentifier(new byte[] { 5, 6 });
-               // fail("Cluster ID is invalid!");
-               // } catch (final IllegalArgumentException e) {
-               // assertEquals("Invalid Cluster ID", e.getMessage());
-               // }
-
-               final ClusterIdentifier id1 = new ClusterIdentifier(new byte[] { 13, 14, 15, 16 });
-
-               assertEquals(id1.toString(), id.toString());
-
-               assertArrayEquals(id1.getValue(), new byte[] { 13, 14, 15, 16 });
-       }
-
-       @Test
-       public void testOrigin() {
-               final BgpOrigin or = BgpOrigin.Egp;
-               assertEquals(or.name(), "Egp");
-       }
-}
diff --git a/bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/Inet4SpecificExtendedCommunityTest.java b/bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/Inet4SpecificExtendedCommunityTest.java
deleted file mode 100644 (file)
index 6f55dff..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.concepts;
-
-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 org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.inet4.specific.extended.community.Inet4SpecificExtendedCommunity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.inet4.specific.extended.community.Inet4SpecificExtendedCommunityBuilder;
-
-public class Inet4SpecificExtendedCommunityTest {
-
-       private boolean transitive;
-       private Ipv4Address globalAdmin;
-       private byte[] localAdmin;
-
-       private Inet4SpecificExtendedCommunity community;
-
-       @Before
-       public void init() {
-               this.transitive = true;
-               this.globalAdmin = new Ipv4Address("10.0.0.1");
-               this.localAdmin = new byte[] { 10, 1 };
-               this.community = new Inet4SpecificExtendedCommunityBuilder().setTransitive(this.transitive).setGlobalAdministrator(this.globalAdmin).setLocalAdministrator(
-                               this.localAdmin).build();
-       }
-
-       @Test
-       @Ignore
-       // FIXME: length is not implemented
-       public void testOverflows() {
-               try {
-                       new Inet4SpecificExtendedCommunityBuilder().setTransitive(this.transitive).setGlobalAdministrator(this.globalAdmin).setLocalAdministrator(
-                                       new byte[] { 10, 0, 1 }).build();
-                       fail("Invalid length of local administrator!");
-               } catch (final IllegalArgumentException e) {
-                       assertEquals("Invalid Local Administrator", e.getMessage());
-               }
-       }
-
-       @Test
-       public void testGetGlobalAdmin() {
-               final Ipv4Address globalAdmin = new Ipv4Address("10.0.0.1");
-               assertEquals(globalAdmin, this.community.getGlobalAdministrator());
-       }
-
-       @Test
-       public void testGetLocalAdmin() {
-               final byte[] localAdmin = new byte[] { 10, 1 };
-               assertArrayEquals(localAdmin, this.community.getLocalAdministrator());
-       }
-
-       @Test
-       public void testIsTransitive() {
-               assertTrue(this.community.isTransitive());
-       }
-}
diff --git a/bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/OpaqueExtendedCommunityTest.java b/bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/OpaqueExtendedCommunityTest.java
deleted file mode 100644 (file)
index d4e3c0e..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.concepts;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.opaque.extended.community.OpaqueExtendedCommunity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.opaque.extended.community.OpaqueExtendedCommunityBuilder;
-
-public class OpaqueExtendedCommunityTest {
-
-       private boolean transitive;
-       private byte[] value;
-
-       private OpaqueExtendedCommunity community;
-
-       @Before
-       public void init() {
-               this.transitive = true;
-               this.value = new byte[] { 1, 5, 9, 3, 5, 7 };
-               this.community = new OpaqueExtendedCommunityBuilder().setTransitive(this.transitive).setValue(this.value).build();
-       }
-
-       @Test
-       @Ignore
-       // FIXME: when length is implemented
-       public void testOverflows() {
-               try {
-                       new OpaqueExtendedCommunityBuilder().setTransitive(this.transitive).setValue(new byte[] { 0, 1, 2, 3, 4, 5, 6, }).build();
-                       fail("Constructor successful unexpectedly");
-               } catch (final IllegalArgumentException e) {
-                       assertEquals("Invalid value", e.getMessage());
-               }
-       }
-
-       @Test
-       public void testGetValue() {
-               assertArrayEquals(new byte[] { 1, 5, 9, 3, 5, 7 }, this.community.getValue());
-       }
-
-       @Test
-       public void testIsTransitive() {
-               assertTrue(this.community.isTransitive());
-       }
-
-       @Test
-       public void testToString() {
-               final OpaqueExtendedCommunity c = new OpaqueExtendedCommunityBuilder().setTransitive(false).setValue(this.value).build();
-               assertNotSame(c.toString(), this.community.toString());
-       }
-}
index 526f4bd8c0255d841323ade94ebade9975b84b58..3c4fa43605503b639198db6e5f264b02c03e084e 100644 (file)
                <dependency>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>bgp-parser-spi</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>bgp-rib-api</artifactId>
             <version>${project.version}</version>
                </dependency>
                <dependency>
index 7b3e1558bd097b5a6db082078d0f5932d349159c..083232da4edc535ac7f725af26687f13eb4177b4 100644 (file)
@@ -13,19 +13,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
 
-/**
- *
- */
 public final class Activator implements BGPExtensionProviderActivator {
        @Override
        public void start(final BGPExtensionProviderContext context) throws Exception {
                context.registerAddressFamily(LinkstateAddressFamily.class, 16388);
                context.registerSubsequentAddressFamily(LinkstateSubsequentAddressFamily.class, 71);
 
-               context.registerNlriParser(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class,
-                               new LinkstateNlriParser(false));
-               context.registerNlriParser(LinkstateAddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class,
-                               new LinkstateNlriParser(true));
+               context.registerNlriParser(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class, new LinkstateNlriParser(false));
+               context.registerNlriParser(LinkstateAddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class, new LinkstateNlriParser(true));
 
                context.registerAttributeParser(LinkstateAttributeParser.TYPE, new LinkstateAttributeParser());
        }
index 23b1b81ec9536e749f25a50e6414bff822260358..767dd9da0eba0f86a0f8fc17b0a53ae305e09732 100644 (file)
@@ -61,7 +61,7 @@ import com.google.common.primitives.UnsignedBytes;
 /**
  * Parser for Link State information.
  * 
- * @see <a href="http://tools.ietf.org/html/draft-gredler-idr-ls-distribution-01">BGP-LS draft</a>
+ * @see <a href="http://tools.ietf.org/html/draft-gredler-idr-ls-distribution-03">BGP-LS draft</a>
  */
 public class LinkstateAttributeParser implements AttributeParser {
        // FIXME: update to IANA number once it is known
@@ -73,12 +73,12 @@ public class LinkstateAttributeParser implements AttributeParser {
 
        private static final int LENGTH_SIZE = 2;
 
-       private static final Set<Integer> nodeTlvs = Sets.newHashSet(263, 1024, 1025, 1026, 1027, 1028, 1029);
+       private static final Set<Integer> NODE_TLVS = Sets.newHashSet(263, 1024, 1025, 1026, 1027, 1028, 1029);
 
-       private static final Set<Integer> linkTlvs = Sets.newHashSet(1028, 1029, 1030, 1031, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095,
+       private static final Set<Integer> LINK_TLVS = Sets.newHashSet(1028, 1029, 1030, 1031, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095,
                        1096, 1097, 1098);
 
-       private static final Set<Integer> prefixTlvs = Sets.newHashSet(1152, 1153, 1154, 1155, 1156, 1157);
+       private static final Set<Integer> PREFIX_TLVS = Sets.newHashSet(1152, 1153, 1154, 1155, 1156, 1157);
 
        @Override
        public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) throws BGPParsingException {
@@ -86,10 +86,9 @@ public class LinkstateAttributeParser implements AttributeParser {
                builder.addAugmentation(PathAttributes1.class, a);
        }
 
-
-       public static boolean verifyLink(final Set<Integer> keys) {
+       private static boolean verifyLink(final Set<Integer> keys) {
                for (final Integer i : keys) {
-                       if (!linkTlvs.contains(i)) {
+                       if (!LINK_TLVS.contains(i)) {
                                logger.warn("Invalid link attribute {}", i);
                                return false;
                        }
@@ -97,9 +96,9 @@ public class LinkstateAttributeParser implements AttributeParser {
                return true;
        }
 
-       public static boolean verifyNode(final Set<Integer> keys) {
+       private static boolean verifyNode(final Set<Integer> keys) {
                for (final Integer i : keys) {
-                       if (!nodeTlvs.contains(i)) {
+                       if (!NODE_TLVS.contains(i)) {
                                logger.warn("Invalid node attribute {}", i);
                                return false;
                        }
@@ -107,9 +106,9 @@ public class LinkstateAttributeParser implements AttributeParser {
                return true;
        }
 
-       public static boolean verifyPrefix(final Set<Integer> keys) {
+       private static boolean verifyPrefix(final Set<Integer> keys) {
                for (final Integer i : keys) {
-                       if (!prefixTlvs.contains(i)) {
+                       if (!PREFIX_TLVS.contains(i)) {
                                logger.warn("Invalid prefix attribute {}", i);
                                return false;
                        }
@@ -117,7 +116,7 @@ public class LinkstateAttributeParser implements AttributeParser {
                return true;
        }
 
-       protected static LinkstatePathAttribute parseLinkState(final byte[] bytes) throws BGPParsingException {
+       private static LinkstatePathAttribute parseLinkState(final byte[] bytes) throws BGPParsingException {
                final Map<Integer, ByteList> map = new HashMap<Integer, ByteList>();
                int byteOffset = 0;
                while (byteOffset != bytes.length) {
@@ -126,7 +125,7 @@ public class LinkstateAttributeParser implements AttributeParser {
                        final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
                        byteOffset += LENGTH_SIZE;
                        final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
-                       ByteList values = map.containsKey(type) ? values = map.get(type) : new ByteList();
+                       final ByteList values = map.containsKey(type) ? map.get(type) : new ByteList();
                        values.add(value);
                        map.put(type, values);
                        byteOffset += length;
@@ -149,11 +148,11 @@ public class LinkstateAttributeParser implements AttributeParser {
         * @return {@link LinkAttributes}
         * @throws BGPParsingException if a link attribute is not recognized
         */
-       public static LinkAttributes parseLinkAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
+       private static LinkAttributes parseLinkAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
 
                final LinkAttributesBuilder builder = new LinkAttributesBuilder();
                for (final Entry<Integer, ByteList> entry : attributes.entrySet()) {
-                       logger.debug("Link attribute TLV {}", entry.getKey());
+                       logger.trace("Link attribute TLV {}", entry.getKey());
 
                        for (final byte[] value : entry.getValue().getBytes()) {
 
@@ -161,34 +160,34 @@ public class LinkstateAttributeParser implements AttributeParser {
                                case 1028:
                                        final Ipv4RouterIdentifier lipv4 = new Ipv4RouterIdentifier(Ipv4Util.addressForBytes(value));
                                        builder.setLocalIpv4RouterId(lipv4);
-                                       logger.trace("Parsed IPv4 Router-ID of local node: {}", lipv4);
+                                       logger.debug("Parsed IPv4 Router-ID of local node: {}", lipv4);
                                        break;
                                case 1029:
                                        final Ipv6RouterIdentifier lipv6 = new Ipv6RouterIdentifier(Ipv6Util.addressForBytes(value));
                                        builder.setLocalIpv6RouterId(lipv6);
-                                       logger.trace("Parsed IPv6 Router-ID of local node: {}", lipv6);
+                                       logger.debug("Parsed IPv6 Router-ID of local node: {}", lipv6);
                                        break;
                                case 1030:
                                        final Ipv4RouterIdentifier ripv4 = new Ipv4RouterIdentifier(Ipv4Util.addressForBytes(value));
                                        builder.setRemoteIpv4RouterId(ripv4);
-                                       logger.trace("Parsed IPv4 Router-ID of remote node: {}", ripv4);
+                                       logger.debug("Parsed IPv4 Router-ID of remote node: {}", ripv4);
                                        break;
                                case 1031:
                                        final Ipv6RouterIdentifier ripv6 = new Ipv6RouterIdentifier(Ipv6Util.addressForBytes(value));
                                        builder.setRemoteIpv6RouterId(ripv6);
-                                       logger.trace("Parsed IPv6 Router-ID of remote node: {}", ripv6);
+                                       logger.debug("Parsed IPv6 Router-ID of remote node: {}", ripv6);
                                        break;
                                case 1088:
                                        builder.setAdminGroup(new AdministrativeGroup(ByteArray.bytesToLong(value)));
-                                       logger.trace("Parsed Administrative Group {}", builder.getAdminGroup());
+                                       logger.debug("Parsed Administrative Group {}", builder.getAdminGroup());
                                        break;
                                case 1089:
                                        builder.setMaxLinkBandwidth(new Bandwidth(value));
-                                       logger.trace("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
+                                       logger.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
                                        break;
                                case 1090:
                                        builder.setMaxReservableBandwidth(new Bandwidth(value));
-                                       logger.trace("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
+                                       logger.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
                                        break;
                                case 1091:
                                        int index = 0;
@@ -199,11 +198,11 @@ public class LinkstateAttributeParser implements AttributeParser {
                                                index += 4;
                                        }
                                        builder.setUnreservedBandwidth(unreservedBandwidth);
-                                       logger.trace("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth());
+                                       logger.debug("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth());
                                        break;
                                case 1092:
                                        builder.setTeMetric(new TeMetric(ByteArray.bytesToLong(value)));
-                                       logger.trace("Parsed Metric {}", builder.getTeMetric());
+                                       logger.debug("Parsed Metric {}", builder.getTeMetric());
                                        break;
                                case 1093:
                                        final LinkProtectionType lpt = LinkProtectionType.forValue(UnsignedBytes.toInt(value[0]));
@@ -211,16 +210,16 @@ public class LinkstateAttributeParser implements AttributeParser {
                                                throw new BGPParsingException("Link Protection Type not recognized: " + UnsignedBytes.toInt(value[0]));
                                        }
                                        builder.setLinkProtection(lpt);
-                                       logger.trace("Parsed Link Protection Type {}", lpt);
+                                       logger.debug("Parsed Link Protection Type {}", lpt);
                                        break;
                                case 1094:
                                        final boolean[] bits = ByteArray.parseBits(value[0]);
                                        builder.setMplsProtocol(new MplsProtocolMask(bits[0], bits[1]));
-                                       logger.trace("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
+                                       logger.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
                                        break;
                                case 1095:
                                        builder.setMetric(new Metric(ByteArray.bytesToLong(value)));
-                                       logger.trace("Parsed Metric {}", builder.getMetric());
+                                       logger.debug("Parsed Metric {}", builder.getMetric());
                                        break;
                                case 1096:
                                        int i = 0;
@@ -230,23 +229,23 @@ public class LinkstateAttributeParser implements AttributeParser {
                                                i += 4;
                                        }
                                        builder.setSharedRiskLinkGroups(sharedRiskLinkGroups);
-                                       logger.trace("Parsed Shared Risk Link Groups {}", Arrays.toString(sharedRiskLinkGroups.toArray()));
+                                       logger.debug("Parsed Shared Risk Link Groups {}", Arrays.toString(sharedRiskLinkGroups.toArray()));
                                        break;
                                case 1097:
                                        final byte[] opaque = value;
-                                       logger.trace("Parsed Opaque value : {}", Arrays.toString(opaque));
+                                       logger.debug("Parsed Opaque value : {}", Arrays.toString(opaque));
                                        break;
                                case 1098:
                                        final String name = new String(value, Charsets.US_ASCII);
                                        builder.setLinkName(name);
-                                       logger.trace("Parsed Link Name : ", name);
+                                       logger.debug("Parsed Link Name : {}", name);
                                        break;
                                default:
                                        throw new BGPParsingException("Link Attribute not recognized, type: " + entry.getKey());
                                }
                        }
                }
-               logger.debug("Finished parsing Link Attributes.");
+               logger.trace("Finished parsing Link Attributes.");
                return builder.build();
        }
 
@@ -257,12 +256,12 @@ public class LinkstateAttributeParser implements AttributeParser {
         * @return {@link NodeAttributes}
         * @throws BGPParsingException if a node attribute is not recognized
         */
-       public static NodeAttributes parseNodeAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
+       private static NodeAttributes parseNodeAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
                final List<TopologyIdentifier> topologyMembership = Lists.newArrayList();
                final List<IsisAreaIdentifier> areaMembership = Lists.newArrayList();
                final NodeAttributesBuilder builder = new NodeAttributesBuilder();
                for (final Entry<Integer, ByteList> entry : attributes.entrySet()) {
-                       logger.debug("Node attribute TLV {}", entry.getKey());
+                       logger.trace("Node attribute TLV {}", entry.getKey());
                        for (final byte[] value : entry.getValue().getBytes()) {
                                switch (entry.getKey()) {
                                case 263:
@@ -270,36 +269,36 @@ public class LinkstateAttributeParser implements AttributeParser {
                                        while (i != value.length) {
                                                final TopologyIdentifier topId = new TopologyIdentifier(ByteArray.bytesToInt(ByteArray.subByte(value, i, 2)) & 0x3fff);
                                                topologyMembership.add(topId);
-                                               logger.trace("Parsed Topology Identifier: {}", topId);
+                                               logger.debug("Parsed Topology Identifier: {}", topId);
                                                i += 2;
                                        }
                                        break;
                                case 1024:
                                        final boolean[] flags = ByteArray.parseBits(value[0]);
                                        builder.setNodeFlags(new NodeFlagBits(flags[0], flags[1], flags[2], flags[3]));
-                                       logger.trace("Parsed External bit {}, area border router {}.", flags[2], flags[3]);
+                                       logger.debug("Parsed External bit {}, area border router {}.", flags[2], flags[3]);
                                        break;
                                case 1025:
                                        logger.debug("Ignoring opaque value: {}.", Arrays.toString(value));
                                        break;
                                case 1026:
                                        builder.setDynamicHostname(new String(value, Charsets.US_ASCII));
-                                       logger.trace("Parsed Node Name {}", builder.getDynamicHostname());
+                                       logger.debug("Parsed Node Name {}", builder.getDynamicHostname());
                                        break;
                                case 1027:
                                        final IsisAreaIdentifier ai = new IsisAreaIdentifier(value);
                                        areaMembership.add(ai);
-                                       logger.trace("Parsed AreaIdentifier {}", ai);
+                                       logger.debug("Parsed AreaIdentifier {}", ai);
                                        break;
                                case 1028:
                                        final Ipv4RouterIdentifier ip4 = new Ipv4RouterIdentifier(Ipv4Util.addressForBytes(value));
                                        builder.setIpv4RouterId(ip4);
-                                       logger.trace("Parsed IPv4 Router Identifier {}", ip4);
+                                       logger.debug("Parsed IPv4 Router Identifier {}", ip4);
                                        break;
                                case 1029:
                                        final Ipv6RouterIdentifier ip6 = new Ipv6RouterIdentifier(Ipv6Util.addressForBytes(value));
                                        builder.setIpv6RouterId(ip6);
-                                       logger.trace("Parsed IPv6 Router Identifier {}", ip6);
+                                       logger.debug("Parsed IPv6 Router Identifier {}", ip6);
                                        break;
                                default:
                                        throw new BGPParsingException("Node Attribute not recognized, type: " + entry.getKey());
@@ -308,7 +307,7 @@ public class LinkstateAttributeParser implements AttributeParser {
                }
                builder.setTopologyIdentifier(topologyMembership);
                builder.setIsisAreaId(areaMembership);
-               logger.debug("Finished parsing Node Attributes.");
+               logger.trace("Finished parsing Node Attributes.");
                return builder.build();
        }
 
@@ -319,7 +318,7 @@ public class LinkstateAttributeParser implements AttributeParser {
         * @return {@link PrefixAttributes}
         * @throws BGPParsingException if some prefix attributes is not recognized
         */
-       public static PrefixAttributes parsePrefixAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
+       private static PrefixAttributes parsePrefixAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
                final PrefixAttributesBuilder builder = new PrefixAttributesBuilder();
                final List<RouteTag> routeTags = Lists.newArrayList();
                final List<ExtendedRouteTag> exRouteTags = Lists.newArrayList();
index b2917d5bcc7fe37d784a5070449a301e3a578c77..91dcac7b5f5455d123a7601f529242891377cadc 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.bgp.linkstate;
 
 import java.math.BigInteger;
 import java.util.Arrays;
+import java.util.List;
 
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
@@ -41,6 +42,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.PrefixDescriptors;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.PrefixDescriptorsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.CRouterIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.CIsisNodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.CIsisPseudonodeBuilder;
@@ -51,7 +53,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.node.OspfNodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.pseudonode.OspfPseudonodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.DestinationType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpUnreachNlriBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
@@ -60,6 +61,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.conc
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Lists;
 import com.google.common.primitives.UnsignedBytes;
 
 public final class LinkstateNlriParser implements NlriParser {
@@ -85,7 +87,8 @@ public final class LinkstateNlriParser implements NlriParser {
                byteOffset += LENGTH_SIZE;
                final NodeIdentifier remote = null;
                if (type == 257) {
-                       builder.setRemoteNodeDescriptors((RemoteNodeDescriptors) parseNodeDescriptors(ByteArray.subByte(bytes, byteOffset, length)));
+                       builder.setRemoteNodeDescriptors((RemoteNodeDescriptors) parseNodeDescriptors(ByteArray.subByte(bytes, byteOffset, length),
+                                       false));
                        byteOffset += length;
                }
                builder.setLinkDescriptors(parseLinkDescriptors(ByteArray.subByte(bytes, byteOffset, bytes.length - byteOffset)));
@@ -101,49 +104,49 @@ public final class LinkstateNlriParser implements NlriParser {
                        final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
                        byteOffset += LENGTH_SIZE;
                        final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
-                       logger.debug("Parsing Link Descriptor: {}", Arrays.toString(value));
+                       logger.trace("Parsing Link Descriptor: {}", Arrays.toString(value));
                        switch (type) {
                        case 258:
                                builder.setLinkLocalIdentifier(ByteArray.subByte(value, 0, 4));
                                builder.setLinkRemoteIdentifier(ByteArray.subByte(value, 4, 4));
-                               logger.trace("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
+                               logger.debug("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
                                                builder.getLinkRemoteIdentifier());
                                break;
                        case 259:
                                final Ipv4InterfaceIdentifier lipv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForBytes(value));
                                builder.setIpv4InterfaceAddress(lipv4);
-                               logger.trace("Parsed IPv4 interface address {}.", lipv4);
+                               logger.debug("Parsed IPv4 interface address {}.", lipv4);
                                break;
                        case 260:
                                final Ipv4InterfaceIdentifier ripv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForBytes(value));
                                builder.setIpv4NeighborAddress(ripv4);
-                               logger.trace("Parsed IPv4 neighbor address {}.", ripv4);
+                               logger.debug("Parsed IPv4 neighbor address {}.", ripv4);
                                break;
                        case 261:
                                final Ipv6InterfaceIdentifier lipv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForBytes(value));
                                builder.setIpv6InterfaceAddress(lipv6);
-                               logger.trace("Parsed IPv6 interface address {}.", lipv6);
+                               logger.debug("Parsed IPv6 interface address {}.", lipv6);
                                break;
                        case 262:
                                final Ipv6InterfaceIdentifier ripv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForBytes(value));
                                builder.setIpv6NeighborAddress(ripv6);
-                               logger.trace("Parsed IPv6 neighbor address {}.", ripv6);
+                               logger.debug("Parsed IPv6 neighbor address {}.", ripv6);
                                break;
                        case 263:
                                final TopologyIdentifier topId = new TopologyIdentifier(ByteArray.bytesToInt(value) & 0x3fff);
                                builder.setMultiTopologyId(topId);
-                               logger.trace("Parsed topology identifier {}.", topId);
+                               logger.debug("Parsed topology identifier {}.", topId);
                                break;
                        default:
                                throw new BGPParsingException("Link Descriptor not recognized, type: " + type);
                        }
                        byteOffset += length;
                }
-               logger.debug("Finished parsing Link descriptors.");
+               logger.trace("Finished parsing Link descriptors.");
                return builder.build();
        }
 
-       private static NodeIdentifier parseNodeDescriptors(final byte[] bytes) throws BGPParsingException {
+       private static NodeIdentifier parseNodeDescriptors(final byte[] bytes, final boolean local) throws BGPParsingException {
                int byteOffset = 0;
                AsNumber asnumber = null;
                DomainIdentifier bgpId = null;
@@ -155,57 +158,65 @@ public final class LinkstateNlriParser implements NlriParser {
                        final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
                        byteOffset += LENGTH_SIZE;
                        final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
-                       logger.debug("Parsing Node Descriptor: {}", Arrays.toString(value));
+                       logger.trace("Parsing Node Descriptor: {}", Arrays.toString(value));
                        switch (type) {
                        case 512:
                                asnumber = new AsNumber(ByteArray.bytesToLong(value));
-                               logger.trace("Parsed AS number {}", asnumber);
+                               logger.debug("Parsed {}", asnumber);
                                break;
                        case 513:
                                bgpId = new DomainIdentifier(value);
-                               logger.trace("Parsed bgpId {}", bgpId);
+                               logger.debug("Parsed {}", bgpId);
                                break;
                        case 514:
                                ai = new AreaIdentifier(value);
-                               logger.trace("Parsed area identifier {}", ai);
+                               logger.debug("Parsed area identifier {}", ai);
                                break;
                        case 515:
-                               if (value.length == 6) {
-                                       routerId = new CIsisNodeBuilder().setIsisNode(
-                                                       new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build()).build();
-                               } else if (value.length == 7) {
-                                       if (value[6] == 0) {
-                                               logger.warn("PSN octet is 0. Ignoring System ID.");
-                                               routerId = new CIsisNodeBuilder().setIsisNode(
-                                                               new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build()).build();
-                                               break;
-                                       } else {
-                                               final IsIsRouterIdentifier iri = new IsIsRouterIdentifierBuilder().setIsoSystemId(
-                                                               new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build();
-                                               routerId = new CIsisPseudonodeBuilder().setIsisPseudonode(
-                                                               new IsisPseudonodeBuilder().setIsIsRouterIdentifier(iri).setPsn((short) UnsignedBytes.toInt(value[6])).build()).build();
-                                       }
-                               } else if (value.length == 4) {
-                                       routerId = new COspfNodeBuilder().setOspfNode(
-                                                       new OspfNodeBuilder().setOspfRouterId(ByteArray.subByte(value, 0, 4)).build()).build();
-                               } else if (value.length == 8) {
-                                       final byte[] o = ByteArray.subByte(value, 0, 4); // FIXME: OSPFv3 vs OSPFv2
-                                       final OspfInterfaceIdentifier a = new OspfInterfaceIdentifier(ByteArray.subByte(value, 4, 4));
-                                       routerId = new COspfPseudonodeBuilder().setOspfPseudonode(
-                                                       new OspfPseudonodeBuilder().setOspfRouterId(o).setLanInterface(a).build()).build();
-                               }
-                               logger.trace("Parsed Router Identifier {}", routerId);
+                               routerId = parseRouterId(value);
+                               logger.debug("Parsed Router Identifier {}", routerId);
                                break;
                        default:
                                throw new BGPParsingException("Node Descriptor not recognized, type: " + type);
                        }
                        byteOffset += length;
                }
-               logger.debug("Finished parsing Node descriptors.");
-               return new LocalNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
+               logger.trace("Finished parsing Node descriptors.");
+               return (local) ? new LocalNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(
+                               routerId).build()
+                               : new RemoteNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
+       }
+
+       private static CRouterIdentifier parseRouterId(final byte[] value) throws BGPParsingException {
+               if (value.length == 6) {
+                       return new CIsisNodeBuilder().setIsisNode(
+                                       new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build()).build();
+               }
+               if (value.length == 7) {
+                       if (value[6] == 0) {
+                               logger.warn("PSN octet is 0. Ignoring System ID.");
+                               return new CIsisNodeBuilder().setIsisNode(
+                                               new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build()).build();
+                       } else {
+                               final IsIsRouterIdentifier iri = new IsIsRouterIdentifierBuilder().setIsoSystemId(
+                                               new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build();
+                               return new CIsisPseudonodeBuilder().setIsisPseudonode(
+                                               new IsisPseudonodeBuilder().setIsIsRouterIdentifier(iri).setPsn((short) UnsignedBytes.toInt(value[6])).build()).build();
+                       }
+               }
+               if (value.length == 4) {
+                       return new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(ByteArray.subByte(value, 0, 4)).build()).build();
+               }
+               if (value.length == 8) {
+                       final byte[] o = ByteArray.subByte(value, 0, 4); // FIXME: OSPFv3 vs OSPFv2
+                       final OspfInterfaceIdentifier a = new OspfInterfaceIdentifier(ByteArray.subByte(value, 4, 4));
+                       return new COspfPseudonodeBuilder().setOspfPseudonode(new OspfPseudonodeBuilder().setOspfRouterId(o).setLanInterface(a).build()).build();
+               }
+               throw new BGPParsingException("Router Id of invalid length " + value.length);
        }
 
-       private static PrefixDescriptors parsePrefixDescriptors(final NodeIdentifier localDescriptor, final byte[] bytes) throws BGPParsingException {
+       private static PrefixDescriptors parsePrefixDescriptors(final NodeIdentifier localDescriptor, final byte[] bytes)
+                       throws BGPParsingException {
                int byteOffset = 0;
                final PrefixDescriptorsBuilder builder = new PrefixDescriptorsBuilder();
                while (byteOffset != bytes.length) {
@@ -262,15 +273,18 @@ public final class LinkstateNlriParser implements NlriParser {
         * @return BGPLinkMP or BGPNodeMP
         * @throws BGPParsingException
         */
-       private final CLinkstateDestination parseNlri(final byte[] nlri) throws BGPParsingException {
+       private List<CLinkstateDestination> parseNlri(final byte[] nlri) throws BGPParsingException {
                if (nlri.length == 0) {
                        return null;
                }
                int byteOffset = 0;
 
-               final CLinkstateDestinationBuilder builder = new CLinkstateDestinationBuilder();
+               final List<CLinkstateDestination> dests = Lists.newArrayList();
+
+               CLinkstateDestinationBuilder builder = null;
 
                while (byteOffset != nlri.length) {
+                       builder = new CLinkstateDestinationBuilder();
                        final NlriType type = NlriType.forValue(ByteArray.bytesToInt(ByteArray.subByte(nlri, byteOffset, TYPE_LENGTH)));
                        builder.setNlriType(type);
 
@@ -279,7 +293,7 @@ public final class LinkstateNlriParser implements NlriParser {
                        final int length = ByteArray.bytesToInt(ByteArray.subByte(nlri, byteOffset, LENGTH_SIZE));
                        byteOffset += LENGTH_SIZE;
                        RouteDistinguisher distinguisher = null;
-                       if (isVpn) {
+                       if (this.isVpn) {
                                // this parses route distinguisher
                                distinguisher = new RouteDistinguisher(BigInteger.valueOf(ByteArray.bytesToLong(ByteArray.subByte(nlri, byteOffset,
                                                ROUTE_DISTINGUISHER_LENGTH))));
@@ -305,13 +319,13 @@ public final class LinkstateNlriParser implements NlriParser {
                        locallength = ByteArray.bytesToInt(ByteArray.subByte(nlri, byteOffset, LENGTH_SIZE));
                        byteOffset += LENGTH_SIZE;
                        if (localtype == 256) {
-                               localDescriptor = parseNodeDescriptors(ByteArray.subByte(nlri, byteOffset, locallength));
+                               localDescriptor = parseNodeDescriptors(ByteArray.subByte(nlri, byteOffset, locallength), true);
                        }
                        byteOffset += locallength;
                        builder.setLocalNodeDescriptors((LocalNodeDescriptors) localDescriptor);
-                       final int restLength = length - (isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0)
-                                       - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH - TYPE_LENGTH - LENGTH_SIZE - locallength;
-                       logger.debug("Restlength {}", restLength);
+                       final int restLength = length - (this.isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH
+                                       - TYPE_LENGTH - LENGTH_SIZE - locallength;
+                       logger.trace("Restlength {}", restLength);
                        switch (type) {
                        case Link:
                                parseLink(builder, ByteArray.subByte(nlri, byteOffset, restLength));
@@ -325,28 +339,28 @@ public final class LinkstateNlriParser implements NlriParser {
                                break;
                        }
                        byteOffset += restLength;
+                       dests.add(builder.build());
                }
-               return builder.build();
+               return dests;
        }
 
        @Override
        public final void parseNlri(final byte[] nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
-               final CLinkstateDestination dst = parseNlri(nlri);
-
-               // FIXME: This cast is because of a bug in yangtools (augmented choice has no relationship with base choice)
-               final DestinationType s = (DestinationType)new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build();
+               if (nlri.length == 0) {
+                       return;
+               }
+               final List<CLinkstateDestination> dst = parseNlri(nlri);
 
-               builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(s).build());
+               builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
+                               new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build());
        }
 
        @Override
-       public final void parseNlri(final byte[] nlri, final byte[] nextHop, final MpReachNlriBuilder builder) throws BGPParsingException {
-               final CLinkstateDestination dst = parseNlri(nlri);
-
-               // FIXME: This cast is because of a bug in yangtools (augmented choice has no relationship with base choice)
-               final DestinationType s = (DestinationType)new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build();
+       public void parseNlri(final byte[] nlri, final byte[] nextHop, final MpReachNlriBuilder builder) throws BGPParsingException {
+               final List<CLinkstateDestination> dst = parseNlri(nlri);
 
-               builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(s).build());
+               builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
+                               new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build());
                NlriUtil.parseNextHop(nextHop, builder);
        }
-}
\ No newline at end of file
+}
index 131bf9013d1b755ecf48df62ecd75407a4b219e4..81c424f8293acfe9cea0ff82245b9e5a18ce5137 100644 (file)
@@ -7,9 +7,10 @@ module bgp-linkstate {
                prefix inet;
                revision-date 2010-09-24;
        }
-       import bgp-message { prefix bgp-msg;}
-       import bgp-multiprotocol { prefix bgp-mp;}
-       import bgp-types { prefix bgp-t;}
+       import bgp-message { prefix bgp-msg; }
+       import bgp-multiprotocol { prefix bgp-mp; }
+       import bgp-rib { prefix bgp-rib; }
+       import bgp-types { prefix bgp-t; }
        import nps-concepts { prefix nps-c;}
        import rsvp { prefix rsvp; revision-date 2013-08-20; }
 
@@ -260,7 +261,7 @@ module bgp-linkstate {
        }
 
        grouping linkstate-destination {
-               container c-linkstate-destination {
+               list c-linkstate-destination {
                        leaf nlri-type {
                                type nlri-type;
                        }
@@ -544,4 +545,68 @@ module bgp-linkstate {
                        }
                }
        }
+
+       augment "/bgp-rib:loc-rib/bgp-rib:tables/bgp-rib:routes" {
+               case linkstate-routes {
+                       container linkstate-routes {
+                               leaf distinguisher {
+                                       type bgp-ls:route-distinguisher;
+                               }
+                               leaf protocol-id {
+                                       type bgp-ls:protocol-id;
+                               }
+                               leaf identifier {
+                                       type bgp-ls:identifier;
+                               }
+
+                               choice object-type {
+                                       case node {
+                                               container node-descriptors {
+                                                       uses bgp-ls:node-identifier;
+                                               }
+                                       }
+                                       case link {
+                                               container local-node-descriptors {
+                                                       uses bgp-ls:node-identifier;
+                                               }
+                                               container remote-node-descriptors {
+                                                       uses bgp-ls:node-identifier;
+                                               }
+                                               container link-descriptors {
+                                                       uses bgp-ls:link-identifiers;
+                                                       leaf ipv4-interface-address {
+                                                               type bgp-ls:ipv4-interface-identifier;
+                                                       }
+                                                       leaf ipv6-interface-address {
+                                                               type bgp-ls:ipv6-interface-identifier;
+                                                       }
+                                                       leaf ipv4-neighbor-address {
+                                                               type bgp-ls:ipv4-interface-identifier;
+                                                       }
+                                                       leaf ipv6-neighbor-address {
+                                                               type bgp-ls:ipv6-interface-identifier;
+                                                       }
+                                                       leaf multi-topology-id {
+                                                               type bgp-ls:topology-identifier;
+                                                       }
+                                               }
+                                       }
+                                       case prefix {
+                                               leaf multi-topology-id {
+                                                       type bgp-ls:topology-identifier;
+                                               }
+                                               leaf ospf-route-type {
+                                                       when "../../protocol-id = 'ospf'";
+                                                       type bgp-ls:ospf-route-type;
+                                               }
+                                               leaf ip-reachability-information {
+                                                       type inet:ip-prefix;
+                                               }
+                                       }
+                               }
+
+                               uses bgp-rib:route;
+                       }
+               }
+       }
 }
diff --git a/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/ActivatorTest.java b/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/ActivatorTest.java
new file mode 100644 (file)
index 0000000..74c029e
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import org.junit.After;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
+
+public class ActivatorTest {
+
+       private final Activator act = new Activator();
+
+       @Test
+       public void testActivator() throws Exception {
+               final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
+
+               assertNull(context.getAddressFamilyRegistry().classForFamily(16388));
+               assertNull(context.getSubsequentAddressFamilyRegistry().classForFamily(71));
+
+               this.act.start(context);
+
+               assertEquals(LinkstateAddressFamily.class, context.getAddressFamilyRegistry().classForFamily(16388));
+               assertEquals(LinkstateSubsequentAddressFamily.class, context.getSubsequentAddressFamilyRegistry().classForFamily(71));
+       }
+
+       @After
+       public void tearDown() {
+               try {
+                       this.act.stop();
+               } catch (final Exception e) {
+                       fail("This exception should not occurr.");
+               }
+       }
+}
diff --git a/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/AreaIdentifierTest.java b/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/AreaIdentifierTest.java
deleted file mode 100644 (file)
index 14b99fa..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.linkstate;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.AreaIdentifier;
-
-public class AreaIdentifierTest {
-
-       private AreaIdentifier identifier;
-
-       @Before
-       public void init() {
-               final byte[] id = new byte[] {10,0,0,1};
-               this.identifier = new AreaIdentifier(id);
-       }
-
-       @Test
-       public void testGetBytes() {
-               final byte[] id = new byte[] {10,0,0,1};
-               assertArrayEquals(id, this.identifier.getValue());
-       }
-
-       @Test
-       public void testToString(){
-               final byte[] id1 = new byte[] {10,0,0,1};
-               final AreaIdentifier l1 = new AreaIdentifier(id1);
-               final String s1 = "AreaIdentifier [_value=[10, 0, 0, 1]]";
-               assertEquals(s1, l1.toString());
-       }
-}
diff --git a/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParserTest.java b/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParserTest.java
new file mode 100644 (file)
index 0000000..5b68935
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.linkstate.path.attribute.link.state.attribute.NodeAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
+
+public class LinkstateAttributeParserTest {
+
+       private static final byte[] LINK_ATTR = new byte[] { (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0x2a, (byte) 0x2a,
+                       (byte) 0x2a, (byte) 0x2a, (byte) 0x04, (byte) 0x06, (byte) 0x00, (byte) 0x04, (byte) 0x2b, (byte) 0x2b, (byte) 0x2b,
+                       (byte) 0x2b, (byte) 0x04, (byte) 0x40, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x04, (byte) 0x41, (byte) 0x00, (byte) 0x04, (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80, (byte) 0x04,
+                       (byte) 0x42, (byte) 0x00, (byte) 0x04, (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00, (byte) 0x04, (byte) 0x43,
+                       (byte) 0x00, (byte) 0x20, (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00, (byte) 0x46, (byte) 0x43, (byte) 0x50,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x44,
+                       (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x47, (byte) 0x00, (byte) 0x03,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x0a };
+
+       private static final byte[] NODE_ATTR = new byte[] { (byte) 0x04, (byte) 0x02, (byte) 0x00, (byte) 0x05, (byte) 0x31, (byte) 0x32,
+                       (byte) 0x4b, (byte) 0x2d, (byte) 0x32, (byte) 0x04, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x72, (byte) 0x04,
+                       (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0x29, (byte) 0x29, (byte) 0x29, (byte) 0x29 };
+
+       private final LinkstateAttributeParser parser = new LinkstateAttributeParser();
+
+       @Test
+       public void testPositiveLinks() {
+               final PathAttributesBuilder builder = new PathAttributesBuilder();
+               try {
+                       this.parser.parseAttribute(LINK_ATTR, builder);
+               } catch (final BGPParsingException e) {
+                       fail("No exception should occur.");
+               }
+               final PathAttributes1 attrs = builder.getAugmentation(PathAttributes1.class);
+               final LinkAttributes ls = (LinkAttributes) attrs.getLinkstatePathAttribute().getLinkStateAttribute();
+               assertNotNull(ls);
+
+               assertEquals("42.42.42.42", ls.getLocalIpv4RouterId().getValue());
+               assertEquals(new Long(10), ls.getMetric().getValue());
+               assertEquals(new Long(0), ls.getAdminGroup().getValue());
+               assertEquals("43.43.43.43", ls.getRemoteIpv4RouterId().getValue());
+               assertArrayEquals(new byte[] { (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80 }, ls.getMaxLinkBandwidth().getValue());
+               assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 }, ls.getMaxReservableBandwidth().getValue());
+               assertNotNull(ls.getUnreservedBandwidth());
+               assertEquals(8, ls.getUnreservedBandwidth().size());
+       }
+
+       @Test
+       public void testPositiveNodes() {
+               final PathAttributesBuilder builder = new PathAttributesBuilder();
+               try {
+                       this.parser.parseAttribute(NODE_ATTR, builder);
+               } catch (final BGPParsingException e) {
+                       fail("No exception should occur.");
+               }
+               final PathAttributes1 attrs = builder.getAugmentation(PathAttributes1.class);
+               final NodeAttributes ls = (NodeAttributes) attrs.getLinkstatePathAttribute().getLinkStateAttribute();
+               assertNotNull(ls);
+
+               assertEquals("12K-2", ls.getDynamicHostname());
+               assertEquals(1, ls.getIsisAreaId().size());
+               assertArrayEquals(new byte[] { 114 }, ls.getIsisAreaId().get(0).getValue());
+               assertEquals("41.41.41.41", ls.getIpv4RouterId().getValue());
+       }
+}
diff --git a/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParserTest.java b/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParserTest.java
new file mode 100644 (file)
index 0000000..f545743
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.math.BigInteger;
+
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.DomainIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.NlriType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestination;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LinkDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LocalNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.CIsisNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.isis.node.IsisNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHop;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.IsoSystemIdentifier;
+
+public class LinkstateNlriParserTest {
+
+       private final byte[] nodeNlri = new byte[] { (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x27, (byte) 0x02, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
+                       (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02,
+                       (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x39 };
+
+       private final byte[] linkNlri = new byte[] { (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x55, (byte) 0x02, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
+                       (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02,
+                       (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42,
+                       (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28,
+                       (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14,
+                       (byte) 0xa0, (byte) 0x2a, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0,
+                       (byte) 0x28 };
+
+       private final byte[] nextHop = new byte[] { (byte) 0x0a, (byte) 0x19, (byte) 0x02, (byte) 0x1b };
+
+       @Test
+       public void testNodeNlri() throws BGPParsingException {
+               final LinkstateNlriParser parser = new LinkstateNlriParser(false);
+               final MpReachNlriBuilder builder = new MpReachNlriBuilder();
+               parser.parseNlri(this.nodeNlri, this.nextHop, builder);
+
+               assertEquals("10.25.2.27", ((CIpv4NextHop) builder.getCNextHop()).getIpv4NextHop().getGlobal().getValue());
+
+               final DestinationLinkstate ls = (DestinationLinkstate) builder.getAdvertizedRoutes().getDestinationType();
+
+               assertEquals(1, ls.getCLinkstateDestination().size());
+
+               final CLinkstateDestination dest = ls.getCLinkstateDestination().get(0);
+
+               assertEquals(NlriType.Node, dest.getNlriType());
+               assertNull(dest.getDistinguisher());
+               assertEquals(ProtocolId.IsisLevel2, dest.getProtocolId());
+               assertEquals(BigInteger.ONE, dest.getIdentifier().getValue());
+
+               final LocalNodeDescriptors nodeD = dest.getLocalNodeDescriptors();
+               assertEquals(new AsNumber(72L), nodeD.getAsNumber());
+               assertEquals(new DomainIdentifier(new byte[] { (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28 }), nodeD.getDomainId());
+               assertEquals(
+                               new CIsisNodeBuilder().setIsisNode(
+                                               new IsisNodeBuilder().setIsoSystemId(
+                                                               new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                                                               (byte) 0x39 })).build()).build(), nodeD.getCRouterIdentifier());
+
+               assertNull(dest.getRemoteNodeDescriptors());
+       }
+
+       @Test
+       public void testLinkNlri() throws BGPParsingException {
+               final LinkstateNlriParser parser = new LinkstateNlriParser(false);
+               final MpReachNlriBuilder builder = new MpReachNlriBuilder();
+               parser.parseNlri(this.linkNlri, this.nextHop, builder);
+
+               assertEquals("10.25.2.27", ((CIpv4NextHop) builder.getCNextHop()).getIpv4NextHop().getGlobal().getValue());
+
+               final DestinationLinkstate ls = (DestinationLinkstate) builder.getAdvertizedRoutes().getDestinationType();
+
+               assertEquals(1, ls.getCLinkstateDestination().size());
+
+               final CLinkstateDestination dest = ls.getCLinkstateDestination().get(0);
+
+               assertEquals(NlriType.Link, dest.getNlriType());
+               assertNull(dest.getDistinguisher());
+               assertEquals(ProtocolId.IsisLevel2, dest.getProtocolId());
+               assertEquals(BigInteger.ONE, dest.getIdentifier().getValue());
+
+               final LocalNodeDescriptors local = dest.getLocalNodeDescriptors();
+               assertEquals(new AsNumber(72L), local.getAsNumber());
+               assertEquals(new DomainIdentifier(new byte[] { (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28 }), local.getDomainId());
+               assertEquals(
+                               new CIsisNodeBuilder().setIsisNode(
+                                               new IsisNodeBuilder().setIsoSystemId(
+                                                               new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                                                               (byte) 0x42 })).build()).build(), local.getCRouterIdentifier());
+               final RemoteNodeDescriptors remote = dest.getRemoteNodeDescriptors();
+               assertEquals(new AsNumber(72L), remote.getAsNumber());
+               assertEquals(new DomainIdentifier(new byte[] { (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28 }), remote.getDomainId());
+               assertEquals(
+                               new CIsisNodeBuilder().setIsisNode(
+                                               new IsisNodeBuilder().setIsoSystemId(
+                                                               new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                                                               (byte) 0x40 })).build()).build(), remote.getCRouterIdentifier());
+               final LinkDescriptors ld = dest.getLinkDescriptors();
+               assertEquals("197.20.160.42", ld.getIpv4InterfaceAddress().getValue());
+               assertEquals("197.20.160.40", ld.getIpv4NeighborAddress().getValue());
+       }
+}
diff --git a/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/TopologyIdentifierTest.java b/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/TopologyIdentifierTest.java
deleted file mode 100644 (file)
index 25507ef..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.linkstate;
-
-import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.TopologyIdentifier;
-
-public class TopologyIdentifierTest {
-
-       private TopologyIdentifier identifier;
-
-       @Before
-       public void init() {
-               this.identifier = new TopologyIdentifier(23);
-       }
-
-       @Test
-       public void testLinkAreaIdentifier() {
-               try {
-                       new TopologyIdentifier(4096);
-               } catch (final Exception e) {
-                       assertTrue(e instanceof IllegalArgumentException);
-               }
-               try {
-                       new TopologyIdentifier(-2);
-               } catch (final Exception e) {
-                       assertTrue(e instanceof IllegalArgumentException);
-               }
-
-       }
-
-       @Test
-       public void testGetId() {
-               assertEquals(23, this.identifier.getValue().intValue());
-       }
-
-       @Test
-       public void testEquals() {
-               assertThat(this.identifier, not(new Object()));
-
-               final TopologyIdentifier testIdentifier = new TopologyIdentifier(23);
-               assertEquals(this.identifier, testIdentifier);
-       }
-
-       @Test
-       public void testToString() {
-               assertEquals("TopologyIdentifier [_value=23]", this.identifier.toString());
-               final TopologyIdentifier id = new TopologyIdentifier(3);
-               assertEquals("TopologyIdentifier [_value=3]", id.toString());
-       }
-}
index 7b1c69771be1a45b474406dc95ef8923b49fcedf..ad1fba76e7413bff3d4f66146e3c26ee2786d5c5 100644 (file)
@@ -45,7 +45,7 @@ public final class BGPDocumentedException extends DocumentedException {
         * @param error specific documented error
         * @param cause cause for the error
         */
-       public BGPDocumentedException(final String message, final BGPError error, final Throwable cause) {
+       public BGPDocumentedException(final String message, final BGPError error, final Exception cause) {
                this(message, error, null, cause);
        }
 
@@ -68,8 +68,8 @@ public final class BGPDocumentedException extends DocumentedException {
         * @param data data associated with the error
         * @param cause cause for the error
         */
-       public BGPDocumentedException(final String message, final BGPError error, final byte[] data, final Throwable cause) {
-               super(message);
+       public BGPDocumentedException(final String message, final BGPError error, final byte[] data, final Exception cause) {
+               super(message, cause);
                this.error = error;
                this.data = data;
                logger.error("Error = " + error, this);
@@ -96,8 +96,8 @@ public final class BGPDocumentedException extends DocumentedException {
        public static BGPDocumentedException badMessageLength(final String message, final int length) {
                Preconditions.checkArgument(length >= 0 && length <= 65535);
 
-               return new BGPDocumentedException(message, BGPError.BAD_MSG_LENGTH, new byte[] {
-                               UnsignedBytes.checkedCast(length / 256), UnsignedBytes.checkedCast(length % 256) });
+               return new BGPDocumentedException(message, BGPError.BAD_MSG_LENGTH, new byte[] { UnsignedBytes.checkedCast(length / 256),
+                               UnsignedBytes.checkedCast(length % 256) });
 
        }
 }
index b08b25e878f33595f7210ddf641bb49d8eeff8a5..60d090362b8d9f88eaf1f76b579ad992cf13550b 100644 (file)
@@ -122,52 +122,72 @@ public enum BGPError {
 
        public static BGPError forValue(final int e, final int s) {
                if (e == 1) {
-                       if (s == 1)
+                       if (s == 1) {
                                return BGPError.CONNECTION_NOT_SYNC;
-                       if (s == 2)
+                       }
+                       if (s == 2) {
                                return BGPError.BAD_MSG_LENGTH;
-                       if (s == 3)
+                       }
+                       if (s == 3) {
                                return BGPError.BAD_MSG_TYPE;
+                       }
                } else if (e == 2) {
-                       if (s == 0)
+                       if (s == 0) {
                                return BGPError.UNSPECIFIC_OPEN_ERROR;
-                       if (s == 1)
+                       }
+                       if (s == 1) {
                                return BGPError.VERSION_NOT_SUPPORTED;
-                       if (s == 2)
+                       }
+                       if (s == 2) {
                                return BGPError.BAD_PEER_AS;
-                       if (s == 3)
+                       }
+                       if (s == 3) {
                                return BGPError.BAD_BGP_ID;
-                       if (s == 4)
+                       }
+                       if (s == 4) {
                                return BGPError.OPT_PARAM_NOT_SUPPORTED;
-                       if (s == 6)
+                       }
+                       if (s == 6) {
                                return BGPError.HOLD_TIME_NOT_ACC;
+                       }
                } else if (e == 3) {
-                       if (s == 1)
+                       if (s == 1) {
                                return BGPError.MALFORMED_ATTR_LIST;
-                       if (s == 2)
+                       }
+                       if (s == 2) {
                                return BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED;
-                       if (s == 3)
+                       }
+                       if (s == 3) {
                                return BGPError.WELL_KNOWN_ATTR_MISSING;
-                       if (s == 4)
+                       }
+                       if (s == 4) {
                                return BGPError.ATTR_FLAGS_MISSING;
-                       if (s == 5)
+                       }
+                       if (s == 5) {
                                return BGPError.ATTR_LENGTH_ERROR;
-                       if (s == 6)
+                       }
+                       if (s == 6) {
                                return BGPError.ORIGIN_ATTR_NOT_VALID;
-                       if (s == 8)
+                       }
+                       if (s == 8) {
                                return BGPError.NEXT_HOP_NOT_VALID;
-                       if (s == 9)
+                       }
+                       if (s == 9) {
                                return BGPError.OPT_ATTR_ERROR;
-                       if (s == 10)
+                       }
+                       if (s == 10) {
                                return BGPError.NETWORK_NOT_VALID;
-                       if (s == 11)
+                       }
+                       if (s == 11) {
                                return BGPError.AS_PATH_MALFORMED;
-               } else if (e == 4)
+                       }
+               } else if (e == 4) {
                        return BGPError.HOLD_TIMER_EXPIRED;
-               else if (e == 5)
+               } else if (e == 5) {
                        return BGPError.FSM_ERROR;
-               else if (e == 6)
+               } else if (e == 6) {
                        return BGPError.CEASE;
+               }
                throw new IllegalArgumentException("BGP Error code " + e + " and subcode " + s + " not recognized.");
        }
 }
index 03763d5464233832881e8a4602926f7994f768df..1e6b430447cdb23196b04754e33f161d43c3fea0 100644 (file)
@@ -47,7 +47,7 @@ public final class BgpTableTypeImpl implements BgpTableType {
 
        @Override
        public boolean equals(final Object obj) {
-               if (obj != null && obj instanceof BgpTableTypeImpl) {
+               if (obj instanceof BgpTableTypeImpl) {
                        final BgpTableTypeImpl o = (BgpTableTypeImpl) obj;
                        return this.afi.equals(o.afi) && this.safi.equals(o.safi);
                }
index 6cd82982b1550d4f36b56991e3d2ea714618761a..db2485088c83a36cb3fdb7823bf32478b54b56bc 100644 (file)
@@ -8,20 +8,11 @@
 package org.opendaylight.protocol.bgp.parser;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
+import org.opendaylight.protocol.framework.DeserializerException;
 import org.opendaylight.protocol.framework.DocumentedException;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Keepalive;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.KeepaliveBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Notify;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.NotifyBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.OpenBuilder;
-import org.opendaylight.yangtools.yang.binding.Notification;
-
 
 public class APITest {
 
@@ -34,32 +25,18 @@ public class APITest {
        }
 
        @Test
-       public void testBGPKeepAliveMessage() {
-               final Notification msg = new KeepaliveBuilder().build();
-               assertTrue(msg instanceof Keepalive);
-       }
-
-       @Test
-       public void testBGPNotificationMessage() {
-               final Notify msg = new NotifyBuilder().setErrorCode(BGPError.AS_PATH_MALFORMED.getCode()).setErrorSubcode(
-                               BGPError.AS_PATH_MALFORMED.getSubcode()).build();
-               assertTrue(msg instanceof Notify);
-               assertEquals(BGPError.AS_PATH_MALFORMED.getCode(), msg.getErrorCode().shortValue());
-               assertEquals(BGPError.AS_PATH_MALFORMED.getSubcode(), msg.getErrorSubcode().shortValue());
-               assertNull(msg.getData());
+       public void testParsingException() {
+               final DeserializerException de = new BGPParsingException("Some message");
+               assertEquals("Some message", de.getMessage());
        }
 
        @Test
-       public void testBGPOpenMessage() {
-               final Notification msg = new OpenBuilder().setMyAsNumber(58).setHoldTimer(5).build();
-               assertNull(((Open) msg).getBgpParameters());
+       public void testBGPError() {
+               assertEquals(BGPError.BAD_MSG_TYPE, BGPError.forValue(1, 3));
        }
 
        @Test
-       public void testToString() {
-               final Notification o = new OpenBuilder().setMyAsNumber(58).setHoldTimer(5).build();
-               final Notification n = new NotifyBuilder().setErrorCode(BGPError.AS_PATH_MALFORMED.getCode()).setErrorSubcode(
-                               BGPError.AS_PATH_MALFORMED.getSubcode()).build();
-               assertNotSame(o.toString(), n.toString());
+       public void testTerminationReason() {
+               assertEquals(BGPError.BAD_PEER_AS.toString(), new BGPTerminationReason(BGPError.BAD_PEER_AS).getErrorMessage());
        }
 }
index 959ff937d4182f671616fe8321af77f91f5e51a9..85d3ad02012fefd5049416ad0fc62d0dc8234020 100644 (file)
                                                <Export-Package>
                                                        org.opendaylight.protocol.bgp.parser.impl.*
                                                </Export-Package>
-                        <Activator>org.opendaylight.protocol.bgp.parser.impl.OSGiActivator</Activator>
+                        <Activator>org.opendaylight.protocol.bgp.parser.impl.BundleActivator</Activator>
                                        </instructions>
                                </configuration>
                        </plugin>
index 82162a9130866c6d7d336bf60c29dbc53f74c5a6..077a3fe7105c46febc157d984b3e6d01ae096a02 100644 (file)
@@ -63,7 +63,7 @@ public final class Activator implements BGPExtensionProviderActivator {
 
        @Override
        public synchronized void start(final BGPExtensionProviderContext context) {
-               Preconditions.checkState(registrations == null);
+               Preconditions.checkState(this.registrations == null);
                final List<AutoCloseable> regs = new ArrayList<>();
 
                final AddressFamilyRegistry afiReg = context.getAddressFamilyRegistry();
@@ -75,17 +75,14 @@ public final class Activator implements BGPExtensionProviderActivator {
                regs.add(context.registerSubsequentAddressFamily(MplsLabeledVpnSubsequentAddressFamily.class, 128));
 
                final NlriRegistry nlriReg = context.getNlriRegistry();
-               regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
-                               new Ipv4NlriParser()));
-               regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class,
-                               new Ipv6NlriParser()));
+               regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv4NlriParser()));
+               regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv6NlriParser()));
 
                final AttributeRegistry attrReg = context.getAttributeRegistry();
                regs.add(context.registerAttributeParser(OriginAttributeParser.TYPE, new OriginAttributeParser()));
                regs.add(context.registerAttributeParser(AsPathAttributeParser.TYPE, new AsPathAttributeParser()));
                regs.add(context.registerAttributeParser(NextHopAttributeParser.TYPE, new NextHopAttributeParser()));
-               regs.add(context.registerAttributeParser(MultiExitDiscriminatorAttributeParser.TYPE,
-                               new MultiExitDiscriminatorAttributeParser()));
+               regs.add(context.registerAttributeParser(MultiExitDiscriminatorAttributeParser.TYPE, new MultiExitDiscriminatorAttributeParser()));
                regs.add(context.registerAttributeParser(LocalPreferenceAttributeParser.TYPE, new LocalPreferenceAttributeParser()));
                regs.add(context.registerAttributeParser(AtomicAggregateAttributeParser.TYPE, new AtomicAggregateAttributeParser()));
                regs.add(context.registerAttributeParser(AggregatorAttributeParser.TYPE, new AggregatorAttributeParser()));
@@ -119,7 +116,6 @@ public final class Activator implements BGPExtensionProviderActivator {
                final BGPUpdateMessageParser ump = new BGPUpdateMessageParser(attrReg);
                regs.add(context.registerMessageParser(BGPUpdateMessageParser.TYPE, ump));
                // Serialization of Update message is not supported
-               // regs.add(msgReg.registerMessageSerializer(Update.class, ump));
 
                final BGPNotificationMessageParser nmp = new BGPNotificationMessageParser();
                regs.add(context.registerMessageParser(BGPNotificationMessageParser.TYPE, nmp));
@@ -129,21 +125,21 @@ public final class Activator implements BGPExtensionProviderActivator {
                regs.add(context.registerMessageParser(BGPKeepAliveMessageParser.TYPE, kamp));
                regs.add(context.registerMessageSerializer(Keepalive.class, kamp));
 
-               registrations = regs;
+               this.registrations = regs;
        }
 
        @Override
        public synchronized void stop() {
-               Preconditions.checkState(registrations != null);
+               Preconditions.checkState(this.registrations != null);
 
-               for (AutoCloseable r : registrations) {
+               for (final AutoCloseable r : this.registrations) {
                        try {
                                r.close();
-                       } catch (Exception e) {
+                       } catch (final Exception e) {
                                logger.warn("Failed to close registration", e);
                        }
                }
 
-               registrations = null;
+               this.registrations = null;
        }
 }
index a67f014e11b26198e6b16ed5a298bbadc95d4273..15eca5fe03a9e6bcdf877464407d13ef5716851d 100644 (file)
@@ -27,12 +27,12 @@ public final class BGPMessageFactoryImpl implements BGPMessageFactory {
         * @see org.opendaylight.protocol.bgp.parser.BGPMessageParser#parse(byte[])
         */
        @Override
-       public final Notification parse(final byte[] bytes) throws DeserializerException, DocumentedException {
+       public Notification parse(final byte[] bytes) throws DeserializerException, DocumentedException {
                return this.registry.parseMessage(bytes);
        }
 
        @Override
-       public final byte[] put(final Notification msg) {
+       public byte[] put(final Notification msg) {
                return this.registry.serializeMessage(msg);
        }
 }
similarity index 91%
rename from bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/OSGiActivator.java
rename to bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/BundleActivator.java
index c07792e848f0f01f3ffe9e74f6f58773fc74615c..b528a0da903ce1cafa5e74e2ecf3db7eba5528df 100644 (file)
@@ -11,7 +11,7 @@ import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.parser.spi.osgi.AbstractOSGiBGPExtensionProviderActivator;
 
-public final class OSGiActivator extends AbstractOSGiBGPExtensionProviderActivator {
+public final class BundleActivator extends AbstractOSGiBGPExtensionProviderActivator {
        private final BGPExtensionProviderActivator activator = new Activator();
 
        @Override
index efc9adc4da4248e4c4aca07a5b688b313e0c4930..dd3c9fbb3ef670793037888f56a4df370cc386b3 100644 (file)
@@ -13,21 +13,20 @@ import com.google.common.base.Preconditions;
 public class BGPKeepAliveMessageParser implements MessageParser, MessageSerializer {
        public static final int TYPE = 4;
 
-       private static final Keepalive msg = new KeepaliveBuilder().build();
-       private static final byte[] bytes = MessageUtil.formatMessage(TYPE, new byte[0]);
+       private final Keepalive msg = new KeepaliveBuilder().build();
+       private final byte[] bytes = MessageUtil.formatMessage(TYPE, new byte[0]);
 
        @Override
        public Keepalive parseMessageBody(final byte[] body, final int messageLength) throws BGPDocumentedException {
                if (body.length != 0) {
-                       throw  BGPDocumentedException.badMessageLength("Message length field not within valid range.", messageLength);
+                       throw BGPDocumentedException.badMessageLength("Message length field not within valid range.", messageLength);
                }
-
-               return msg;
+               return this.msg;
        }
 
        @Override
        public byte[] serializeMessage(final Notification message) {
                Preconditions.checkArgument(message instanceof Keepalive);
-               return bytes;
+               return this.bytes;
        }
 }
index 123c4e060241a94ebec33dfdf5f63043dd3578b8..54b92d3e9fe2d4f13acb3e65292709ba5ba36d43 100644 (file)
@@ -31,7 +31,7 @@ public final class BGPNotificationMessageParser implements MessageParser, Messag
 
        private static final Logger logger = LoggerFactory.getLogger(BGPNotificationMessageParser.class);
 
-       private static final int ERROR_SIZE = 2; // bytes
+       private static final int ERROR_SIZE = 2;
 
        /**
         * Serializes BGP Notification message.
@@ -45,7 +45,7 @@ public final class BGPNotificationMessageParser implements MessageParser, Messag
                        throw new IllegalArgumentException("BGP Notification message cannot be null");
                }
 
-               final Notify ntf = (Notify)msg;
+               final Notify ntf = (Notify) msg;
                logger.trace("Started serializing Notification message: {}", ntf);
 
                final byte[] msgBody = (ntf.getData() == null) ? new byte[ERROR_SIZE] : new byte[ERROR_SIZE + ntf.getData().length];
index a335b6dcf0aa0aede17bc69fae1db24c1b719265..3eced158a9eb78eed255223cec4701c22d7326a0 100644 (file)
@@ -21,6 +21,7 @@ import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
 import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
 import org.opendaylight.protocol.concepts.Ipv4Util;
 import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
@@ -53,6 +54,8 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
 
        private static final int BGP_VERSION = 4;
 
+       private static final int AS_TRANS = 2345;
+
        private final ParameterRegistry reg;
 
        public BGPOpenMessageParser(final ParameterRegistry reg) {
@@ -79,7 +82,7 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
 
                if (open.getBgpParameters() != null) {
                        for (final BgpParameters param : open.getBgpParameters()) {
-                               final byte[] p = reg.serializeParameter(param);
+                               final byte[] p = this.reg.serializeParameter(param);
                                if (p != null) {
                                        optParams.put(p, p.length);
                                        optParamsLength += p.length;
@@ -96,8 +99,8 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
 
                // When our AS number does not fit into two bytes, we report it as AS_TRANS
                int openAS = open.getMyAsNumber();
-               if (openAS > 65535) {
-                       openAS = 2345;
+               if (openAS > Util.UNSIGNED_SHORT_MAX_VALUE) {
+                       openAS = AS_TRANS;
                }
 
                System.arraycopy(ByteArray.longToBytes(openAS), 6, msgBody, offset, AS_SIZE);
@@ -162,13 +165,13 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
                try {
                        bgpId = Ipv4Util.addressForBytes(ByteArray.subByte(body, offset, BGP_ID_SIZE));
                } catch (final IllegalArgumentException e) {
-                       throw new BGPDocumentedException("BGP Identifier is not a valid IPv4 Address", BGPError.BAD_BGP_ID);
+                       throw new BGPDocumentedException("BGP Identifier is not a valid IPv4 Address", BGPError.BAD_BGP_ID, e);
                }
                offset += BGP_ID_SIZE;
 
                final int optLength = UnsignedBytes.toInt(body[offset]);
 
-               List<BgpParameters> optParams = Lists.newArrayList();
+               final List<BgpParameters> optParams = Lists.newArrayList();
                if (optLength > 0) {
                        fillParams(ByteArray.subByte(body, MIN_MSG_LENGTH, optLength), optParams);
                }
@@ -197,7 +200,7 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
 
                        final BgpParameters param;
                        try {
-                               param = reg.parseParameter(paramType, paramBody);
+                               param = this.reg.parseParameter(paramType, paramBody);
                        } catch (final BGPParsingException e) {
                                throw new BGPDocumentedException("Optional parameter not parsed", BGPError.UNSPECIFIC_OPEN_ERROR, e);
                        }
index 7f107a6ae3ebbcb9162f8cf533cc2577252259aa..2f2fba196de6a82312259a893a15d50ae484c024 100644 (file)
@@ -92,8 +92,7 @@ public class BGPUpdateMessageParser implements MessageParser {
 
                if (totalPathAttrLength > 0) {
                        try {
-                               final PathAttributes pathAttributes = reg.parseAttributes(ByteArray.subByte(body, byteOffset,
-                                               totalPathAttrLength));
+                               final PathAttributes pathAttributes = reg.parseAttributes(ByteArray.subByte(body, byteOffset, totalPathAttrLength));
                                byteOffset += totalPathAttrLength;
                                eventBuilder.setPathAttributes(pathAttributes);
                        } catch (final BGPParsingException e) {
@@ -103,8 +102,9 @@ public class BGPUpdateMessageParser implements MessageParser {
                }
 
                final List<Ipv4Prefix> nlri = Ipv4Util.prefixListForBytes(ByteArray.subByte(body, byteOffset, body.length - byteOffset));
-               eventBuilder.setNlri(new NlriBuilder().setNlri(nlri).build());
-
+               if (nlri != null && !nlri.isEmpty()) {
+                       eventBuilder.setNlri(new NlriBuilder().setNlri(nlri).build());
+               }
                logger.trace("Update message was parsed.");
                return eventBuilder.build();
        }
index 9b9d431ccc05a0bc5be771d8b20264943a86df83..f976affd6f74135f1dfe89af4cde528c043deded 100644 (file)
@@ -22,11 +22,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 public final class As4CapabilityHandler implements CapabilityParser, CapabilitySerializer {
        public static final int CODE = 65;
 
+       private static final int AS4_LENGTH = 4;
+
        @Override
        public CParameters parseCapability(final byte[] bytes) throws BGPDocumentedException, BGPParsingException {
                return new CAs4BytesBuilder().setAs4BytesCapability(
                                new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(ByteArray.bytesToLong(bytes))).build()).build();
-
        }
 
        @Override
@@ -35,6 +36,7 @@ public final class As4CapabilityHandler implements CapabilityParser, CapabilityS
        }
 
        private static byte[] putAS4BytesParameterValue(final CAs4Bytes param) {
-               return ByteArray.subByte(ByteArray.longToBytes(param.getAs4BytesCapability().getAsNumber().getValue()), 4, 4);
+               return ByteArray.subByte(ByteArray.longToBytes(param.getAs4BytesCapability().getAsNumber().getValue()), Long.SIZE / Byte.SIZE
+                               - AS4_LENGTH, AS4_LENGTH);
        }
 }
\ No newline at end of file
index d1c16ce30c45fd1818821130362b25f16be0fbbd..50073f29eff5dee5f6cb3884874148dd06806d4f 100644 (file)
@@ -25,7 +25,8 @@ final class GracefulCapabilityHandler implements CapabilitySerializer {
                final byte[] bytes = null;
 
                // final GracefulCapability param = (GracefulCapability) capability;
-               // final byte[] bytes = new byte[(RESTART_FLAGS_SIZE + TIMER_SIZE + (AFI_SIZE * Byte.SIZE + SAFI_SIZE * Byte.SIZE +
+               // final byte[] bytes = new byte[(RESTART_FLAGS_SIZE + TIMER_SIZE + (AFI_SIZE * Byte.SIZE + SAFI_SIZE *
+               // Byte.SIZE +
                // AF_FLAGS_SIZE
                // * Byte.SIZE)
                // * param.getTableTypes().size())
index 8d218d3afad737f1e26d6ba1bd172113103f60ae..8016ce4b68a85b6e4a81c5af8c2537faf58cc160 100644 (file)
@@ -28,8 +28,8 @@ import com.google.common.primitives.UnsignedBytes;
 public final class MultiProtocolCapabilityHandler implements CapabilityParser, CapabilitySerializer {
        public static final int CODE = 1;
 
-       private static final int AFI_SIZE = 2; // bytes
-       private static final int SAFI_SIZE = 1; // bytes
+       private static final int AFI_SIZE = 2;
+       private static final int SAFI_SIZE = 1;
 
        private final AddressFamilyRegistry afiReg;
        private final SubsequentAddressFamilyRegistry safiReg;
@@ -42,13 +42,13 @@ public final class MultiProtocolCapabilityHandler implements CapabilityParser, C
        @Override
        public CMultiprotocol parseCapability(final byte[] bytes) throws BGPDocumentedException, BGPParsingException {
                final int afiVal = ByteArray.bytesToInt(ByteArray.subByte(bytes, 0, AFI_SIZE));
-               final Class<? extends AddressFamily> afi = afiReg.classForFamily(afiVal);
+               final Class<? extends AddressFamily> afi = this.afiReg.classForFamily(afiVal);
                if (afi == null) {
                        throw new BGPParsingException("Address Family Identifier: '" + afiVal + "' not supported.");
                }
 
                final int safiVal = ByteArray.bytesToInt(ByteArray.subByte(bytes, AFI_SIZE + 1, SAFI_SIZE));
-               final Class<? extends SubsequentAddressFamily> safi = safiReg.classForFamily(safiVal);
+               final Class<? extends SubsequentAddressFamily> safi = this.safiReg.classForFamily(safiVal);
                if (safi == null) {
                        throw new BGPParsingException("Subsequent Address Family Identifier: '" + safiVal + "' not supported.");
                }
@@ -62,18 +62,16 @@ public final class MultiProtocolCapabilityHandler implements CapabilityParser, C
                final CMultiprotocol mp = (CMultiprotocol) capability;
 
                final Class<? extends AddressFamily> afi = mp.getMultiprotocolCapability().getAfi();
-               final Integer afival = afiReg.numberForClass(afi);
+               final Integer afival = this.afiReg.numberForClass(afi);
                Preconditions.checkArgument(afival != null, "Unhandled address family " + afi);
 
                final Class<? extends SubsequentAddressFamily> safi = mp.getMultiprotocolCapability().getSafi();
-               final Integer safival = safiReg.numberForClass(safi);
+               final Integer safival = this.safiReg.numberForClass(safi);
                Preconditions.checkArgument(safival != null, "Unhandled subsequent address family " + safi);
 
-               return CapabilityUtil.formatCapability(CODE, new byte[] {
-                               UnsignedBytes.checkedCast(afival / 256),
-                               UnsignedBytes.checkedCast(afival % 256),
-                               0,
-                               UnsignedBytes.checkedCast(safival)
-               });
+               return CapabilityUtil.formatCapability(
+                               CODE,
+                               new byte[] { UnsignedBytes.checkedCast(afival / 256), UnsignedBytes.checkedCast(afival % 256), 0,
+                                               UnsignedBytes.checkedCast(safival) });
        }
 }
\ No newline at end of file
index 1007e3e75fd26c8cd40cde0ee60709865e6a4501..9bd7009c014b95a8e13f17acd7d04b43fb809683 100644 (file)
@@ -23,13 +23,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
  * the collection is a Set.
  * 
  */
-public class AsPathSegmentParser {
+public final class AsPathSegmentParser {
 
-       public static final int TYPE_LENGTH = 1; // bytes
+       public static final int TYPE_LENGTH = 1;
 
-       public static final int LENGTH_SIZE = 1; // bytes
+       public static final int LENGTH_SIZE = 1;
 
-       public static final int AS_NUMBER_LENGTH = 4; // bytes
+       public static final int AS_NUMBER_LENGTH = 4;
 
        /**
         * Possible types of AS Path segments.
index 0e568b19d11f471fba382a9b8cce8e0481e625aa..df13f75767f08d44682b2668fc57f41dba33d21a 100644 (file)
@@ -19,13 +19,15 @@ import com.google.common.collect.Lists;
 public final class ClusterIdAttributeParser implements AttributeParser {
        public static final int TYPE = 10;
 
+       private static final int CLUSTER_LENGTH = 4;
+
        @Override
        public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) {
                final List<ClusterIdentifier> list = Lists.newArrayList();
                int i = 0;
                while (i < bytes.length) {
-                       list.add(new ClusterIdentifier(ByteArray.subByte(bytes, i, 4)));
-                       i += 4;
+                       list.add(new ClusterIdentifier(ByteArray.subByte(bytes, i, CLUSTER_LENGTH)));
+                       i += CLUSTER_LENGTH;
                }
 
                builder.setClusterId(list);
index 999038d96fa0014bc87e282fc698801b92cbf543..5a73c6b34737ce97f53cb28e443099b184475f1f 100644 (file)
@@ -12,7 +12,6 @@ import java.util.Arrays;
 
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
-import org.opendaylight.protocol.bgp.parser.impl.CommunityUtil;
 import org.opendaylight.protocol.concepts.Ipv4Util;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
@@ -35,17 +34,17 @@ import com.google.common.primitives.UnsignedBytes;
 /**
  * Parser for Extended Communities Path Attribute.
  */
-public class CommunitiesParser {
+public final class CommunitiesParser {
 
-       public static final int EXTENDED_COMMUNITY_LENGTH = 8; // bytes
+       public static final int EXTENDED_COMMUNITY_LENGTH = 8;
 
-       public static final int COMMUNITY_LENGTH = 4; // bytes
+       public static final int COMMUNITY_LENGTH = 4;
 
-       private static final int TYPE_LENGTH = 2; // bytes
+       private static final int TYPE_LENGTH = 2;
 
-       private static final int AS_NUMBER_LENGTH = 2; // bytes
+       private static final int AS_NUMBER_LENGTH = 2;
 
-       private static final int AS_LOCAL_ADMIN_LENGTH = 4; // bytes
+       private static final int AS_LOCAL_ADMIN_LENGTH = 4;
 
        private CommunitiesParser() {
 
@@ -81,6 +80,7 @@ public class CommunitiesParser {
         * @throws BGPDocumentedException if the type is not recognized
         */
        @VisibleForTesting
+       // FIXME: switch to return ExtendedCommunities with setType and subtype
        public static ExtendedCommunity parseExtendedCommunity(final byte[] bytes) throws BGPDocumentedException {
                final int type = UnsignedBytes.toInt(bytes[0]);
                final int subType = UnsignedBytes.toInt(bytes[1]);
@@ -92,34 +92,34 @@ public class CommunitiesParser {
                                return new CRouteTargetExtendedCommunityBuilder().setRouteTargetExtendedCommunity(
                                                new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(
                                                                new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
-                                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                        } else if (subType == 3) {
                                return new CRouteOriginExtendedCommunityBuilder().setRouteOriginExtendedCommunity(
                                                new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(
                                                                new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
-                                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                        } else {
                                return new CAsSpecificExtendedCommunityBuilder().setAsSpecificExtendedCommunity(
                                                new AsSpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
                                                                new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
-                                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                        }
-               case 40: // 01000000
+               case 40:
                        return new CAsSpecificExtendedCommunityBuilder().setAsSpecificExtendedCommunity(
                                        new AsSpecificExtendedCommunityBuilder().setTransitive(true).setGlobalAdministrator(
                                                        new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
-                                                                       ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+                                                       ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                case 2:
                        if (subType == 2) {
                                return new CRouteTargetExtendedCommunityBuilder().setRouteTargetExtendedCommunity(
                                                new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(
                                                                new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
-                                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                        } else if (subType == 3) {
                                return new CRouteOriginExtendedCommunityBuilder().setRouteOriginExtendedCommunity(
                                                new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(
                                                                new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
-                                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                        } else {
                                throw new BGPDocumentedException("Could not parse Extended Community subtype: " + subType, BGPError.OPT_ATTR_ERROR);
                        }
@@ -128,26 +128,26 @@ public class CommunitiesParser {
                                return new CRouteTargetExtendedCommunityBuilder().setRouteTargetExtendedCommunity(
                                                new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(
                                                                new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
-                                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                        } else if (subType == 3) {
                                return new CRouteOriginExtendedCommunityBuilder().setRouteOriginExtendedCommunity(
                                                new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(
                                                                new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
-                                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+                                                               ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                        } else {
                                return new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
                                                new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
                                                                Ipv4Util.addressForBytes(ByteArray.subByte(value, 0, 4))).setLocalAdministrator(
-                                                                               ByteArray.subByte(value, 4, 2)).build()).build();
+                                                               ByteArray.subByte(value, 4, 2)).build()).build();
                        }
-               case 41: // 01000001
+               case 41:
                        return new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
                                        new Inet4SpecificExtendedCommunityBuilder().setTransitive(true).setGlobalAdministrator(
                                                        Ipv4Util.addressForBytes(ByteArray.subByte(value, 0, 4))).setLocalAdministrator(ByteArray.subByte(value, 4, 2)).build()).build();
                case 3:
                        return new COpaqueExtendedCommunityBuilder().setOpaqueExtendedCommunity(
                                        new OpaqueExtendedCommunityBuilder().setTransitive(false).setValue(value).build()).build();
-               case 43: // 01000011
+               case 43:
                        return new COpaqueExtendedCommunityBuilder().setOpaqueExtendedCommunity(
                                        new OpaqueExtendedCommunityBuilder().setTransitive(true).setValue(value).build()).build();
                default:
similarity index 96%
rename from bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/CommunityUtil.java
rename to bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunityUtil.java
index 393862b65baa865eacfc7b6aae0776e28d659f68..c312b7a831e1d14fb2614cfba49cd6df251e6293 100644 (file)
@@ -5,7 +5,7 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.protocol.bgp.parser.impl;
+package org.opendaylight.protocol.bgp.parser.impl.message.update;
 
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.CommunitiesBuilder;
@@ -34,6 +34,10 @@ public final class CommunityUtil {
         */
        public static final Community NO_EXPORT_SUBCONFED = CommunityUtil.create(0xFFFF, 0xFF03);
 
+       private CommunityUtil() {
+
+       }
+
        /**
         * Creates a new Community given AS number value and semantics using generated CommunitiesBuilder.
         * 
index c094ed021ec8ea989d8510d2bd369b9c4156009f..9b29303abe4a0daf3e231c766ab13487c74735db 100644 (file)
@@ -13,7 +13,9 @@ import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.ExtendedCommunities;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.ExtendedCommunitiesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
 
 import com.google.common.collect.Lists;
 
@@ -25,9 +27,10 @@ public final class ExtendedCommunitiesAttributeParser implements AttributeParser
                final List<ExtendedCommunities> set = Lists.newArrayList();
                int i = 0;
                while (i < bytes.length) {
-                       set.add((ExtendedCommunities) CommunitiesParser.parseExtendedCommunity(ByteArray.subByte(bytes, i,
-                                       CommunitiesParser.EXTENDED_COMMUNITY_LENGTH)));
+                       ExtendedCommunity comm = CommunitiesParser.parseExtendedCommunity(ByteArray.subByte(bytes, i,
+                                       CommunitiesParser.EXTENDED_COMMUNITY_LENGTH));
                        i += CommunitiesParser.EXTENDED_COMMUNITY_LENGTH;
+                       set.add(new ExtendedCommunitiesBuilder().setExtendedCommunity(comm).build());
                }
 
                builder.setExtendedCommunities(set);
index d031ce6aa44cf8029b5a52015281e45e6d9d73df..8e2191ee7960f4cbc62d1adc393c1533677e9348 100644 (file)
@@ -13,12 +13,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 public final class OriginatorIdAttributeParser implements AttributeParser {
        public static final int TYPE = 9;
 
+       private static final int ORIGINATOR_LENGTH = 4;
+
        @Override
        public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) {
-               if (bytes.length != 4) {
-                       throw new IllegalArgumentException("Length of byte array for ORIGINATOR_ID should be 4, but is " + bytes.length);
+               if (bytes.length != ORIGINATOR_LENGTH) {
+                       throw new IllegalArgumentException("Length of byte array for ORIGINATOR_ID should be " + ORIGINATOR_LENGTH + ", but is "
+                                       + bytes.length);
                }
-
                builder.setOriginatorId(bytes);
        }
 }
\ No newline at end of file
index 6be820c6668b1e7b32b78017ae4020cff06e71cc..ea3831f1ad1f49b8dc09bb8bd55ec5146f60c151 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.protocol.bgp.parser.impl;
 
+import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
@@ -14,41 +15,81 @@ import static org.junit.Assert.assertNull;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.math.BigInteger;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunityUtil;
 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.BGPExtensionConsumerContextImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.AreaIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.DomainIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Identifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Ipv4InterfaceIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.NlriType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.OspfInterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestination;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestinationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.COspfNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.COspfPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.node.OspfNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.pseudonode.OspfPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.LinkstatePathAttributeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.UpdateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.Aggregator;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AggregatorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AsPathBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AtomicAggregateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.Communities;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.ExtendedCommunities;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.ExtendedCommunitiesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.LocalPrefBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.MultiExitDiscBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.OriginBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.Segments;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.SegmentsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.Nlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.NlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.WithdrawnRoutesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AsPathSegment;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpAggregator;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
@@ -57,7 +98,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CASetBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequence;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequenceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.CInet4SpecificExtendedCommunityBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.inet4.specific.extended.community.Inet4SpecificExtendedCommunityBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHop;
@@ -66,6 +106,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHopBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv4.next.hop.Ipv4NextHopBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv6.next.hop.Ipv6NextHopBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Metric;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
@@ -85,7 +126,7 @@ public class BGPParserTest {
 
        @BeforeClass
        public static void setUp() throws Exception {
-               updateParser = new BGPUpdateMessageParser(BGPExtensionConsumerContextImpl.getSingletonInstance().getAttributeRegistry());
+               updateParser = new BGPUpdateMessageParser(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getAttributeRegistry());
 
                for (int i = 1; i <= COUNTER; i++) {
                        final String name = "/up" + i + ".bin";
@@ -154,8 +195,6 @@ public class BGPParserTest {
         * 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
         */
        @Test
-       @Ignore
-       // FIXME: to be fixed in testing phase
        public void testGetUpdateMessage1() throws Exception {
 
                final byte[] body = ByteArray.cutBytes(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH);
@@ -170,71 +209,60 @@ public class BGPParserTest {
                // attributes
 
                final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65002L)).build());
-               final List<AsPathSegment> asPath = Lists.newArrayList();
+               final List<Segments> asPath = Lists.newArrayList();
                asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
 
                final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
                                new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
 
-               final Set<Community> comms = new HashSet<>();
-               comms.add(CommunityUtil.NO_EXPORT);
-               comms.add(CommunityUtil.NO_ADVERTISE);
-               comms.add(CommunityUtil.NO_EXPORT_SUBCONFED);
-               comms.add(CommunityUtil.create(0xFFFF, 0xFF10));
+               final List<Communities> comms = Lists.newArrayList();
+               comms.add((Communities) CommunityUtil.NO_EXPORT);
+               comms.add((Communities) CommunityUtil.NO_ADVERTISE);
+               comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
+               comms.add((Communities) CommunityUtil.create(0xFFFF, 0xFF10));
+
+               final UpdateBuilder builder = new UpdateBuilder();
+
+               // check nlri
+
+               final List<Ipv4Prefix> prefs = Lists.newArrayList();
+               prefs.add(new Ipv4Prefix("172.17.2.0/24"));
+               prefs.add(new Ipv4Prefix("172.17.1.0/24"));
+               prefs.add(new Ipv4Prefix("172.17.0.0/24"));
+
+               final Nlri nlri = new NlriBuilder().setNlri(prefs).build();
+
+               assertEquals(nlri, message.getNlri());
+
+               builder.setNlri(nlri);
 
                // check path attributes
 
-               // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
-               // true, false, false, BGPOrigin.IGP);
-               // assertEquals(originAttr, attrs.get(0));
-               //
-               // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
-               // true, false, false, asPath);
-               // assertEquals(asPathAttr, attrs.get(1));
-               //
-               // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
-               // true, false, false, nextHop);
-               // assertEquals(nextHopAttr, attrs.get(2));
-               //
-               // final PathAttribute multiExitDisc = new PathAttribute(
-               // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
-               // assertEquals(multiExitDisc, attrs.get(3));
-               //
-               // final PathAttribute atomic = new PathAttribute(TypeCode.ATOMIC_AGGREGATE, false,
-               // true, true, false, null);
-               // assertEquals(atomic, attrs.get(4));
-               //
-               // final PathAttribute comm = new PathAttribute(TypeCode.COMMUNITIES, false,
-               // true, true, false, comms);
-               // assertEquals(comm, attrs.get(5));
+               final PathAttributes attrs = message.getPathAttributes();
 
-               // check nlri
+               final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
 
-               // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1, pref2, pref3);
-               // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
+               paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
+               assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
 
-               // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
-               // final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, comms,
-               // Collections.<ExtendedCommunity> emptySet()), nextHop);
+               paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
+               assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
 
-               // check API message
+               paBuilder.setCNextHop(nextHop);
+               assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
+
+               paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
+               assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
+
+               paBuilder.setAtomicAggregate(new AtomicAggregateBuilder().build());
+               assertEquals(paBuilder.getAtomicAggregate(), attrs.getAtomicAggregate());
+
+               paBuilder.setCommunities(comms);
+               assertEquals(paBuilder.getCommunities(), attrs.getCommunities());
+
+               builder.setPathAttributes(paBuilder.build());
 
-               // final Set<BGPObject> addedObjects = Sets.newHashSet();
-               //
-               // final BGPRoute route1 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.2.0/24"), state,
-               // routeState);
-               //
-               // addedObjects.add(route1);
-               //
-               // final BGPRoute route2 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.1.0/24"), state,
-               // routeState);
-               //
-               // addedObjects.add(route2);
-               //
-               // final BGPRoute route3 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.0.0/24"), state,
-               // routeState);
-               //
-               // addedObjects.add(route3);
+               assertEquals(builder.build(), message);
        }
 
        /*
@@ -285,73 +313,74 @@ public class BGPParserTest {
         * 
         */
        @Test
-       @Ignore
-       // FIXME: to be fixed in testing phase
        public void testGetUpdateMessage2() throws Exception {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(1), MessageUtil.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), MessageUtil.MARKER_LENGTH,
                                MessageUtil.LENGTH_FIELD_LENGTH));
                final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
-               // check fields
 
+               // check fields
                assertNull(message.getWithdrawnRoutes());
 
+               final UpdateBuilder builder = new UpdateBuilder();
+
+               // check NLRI
+
+               final List<Ipv6Prefix> prefs = Lists.newArrayList();
+               prefs.add(new Ipv6Prefix("2001:db8:1:2::/64"));
+               prefs.add(new Ipv6Prefix("2001:db8:1:1::/64"));
+               prefs.add(new Ipv6Prefix("2001:db8:1::/64"));
+
+               assertNull(message.getNlri());
+
                // attributes
+
                final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(65001L)).build());
-               final List<AsPathSegment> asPath = Lists.newArrayList();
+               final List<Segments> asPath = Lists.newArrayList();
                asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
 
                final CIpv6NextHop nextHop = new CIpv6NextHopBuilder().setIpv6NextHop(
                                new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
 
-               // final List<ClusterIdentifier> clusters = Lists.newArrayList(
-               // new ClusterIdentifier(new byte[] { 1, 2, 3, 4}),
-               // new ClusterIdentifier(new byte[] { 5, 6, 7, 8}));
+               final List<ClusterIdentifier> clusters = Lists.newArrayList(new ClusterIdentifier(new byte[] { 1, 2, 3, 4 }),
+                               new ClusterIdentifier(new byte[] { 5, 6, 7, 8 }));
 
                // check path attributes
 
-               // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
-               // true, false, false, BGPOrigin.IGP);
-               // assertEquals(originAttr, attrs.get(0));
-               //
-               // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
-               // true, false, false, asPath);
-               // assertEquals(asPathAttr, attrs.get(1));
-               //
-               // final PathAttribute multiExitDisc = new PathAttribute(
-               // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
-               // assertEquals(multiExitDisc, attrs.get(2));
-               //
-               // final PathAttribute originatorAttr = new PathAttribute(
-               // TypeCode.ORIGINATOR_ID, true, false, false, false, IPv4.FAMILY.addressForString("127.0.0.1"));
-               // assertEquals(originatorAttr, attrs.get(3));
-               //
-               // final PathAttribute clusterAttr = new PathAttribute(
-               // TypeCode.CLUSTER_LIST, true, false, false, false, clusters);
-               // assertEquals(clusterAttr, attrs.get(4));
-
-               // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
-               // final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath,
-               // Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
+               final PathAttributes attrs = message.getPathAttributes();
+
+               final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+
+               paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
+               assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
+
+               paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
+               assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
+
+               paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
+               assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
+
+               paBuilder.setOriginatorId(new byte[] { 127, 0, 0, 1 });
+               assertArrayEquals(paBuilder.getOriginatorId(), attrs.getOriginatorId());
+
+               paBuilder.setClusterId(clusters);
+               assertEquals(paBuilder.getClusterId(), attrs.getClusterId());
+
+               final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+               mpBuilder.setAfi(Ipv6AddressFamily.class);
+               mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
+               mpBuilder.setCNextHop(nextHop);
+               mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
+                               new DestinationIpv6Builder().setIpv6Prefixes(prefs).build()).build());
+
+               paBuilder.addAugmentation(PathAttributes1.class, new PathAttributes1Builder().setMpReachNlri(mpBuilder.build()).build());
+               assertEquals(paBuilder.getAugmentation(PathAttributes1.class).getMpReachNlri(),
+                               attrs.getAugmentation(PathAttributes1.class).getMpReachNlri());
 
                // check API message
 
-               // final Set<BGPObject> addedObjects = Sets.newHashSet();
-               //
-               // final BGPRoute route1 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1:2::/64"), state,
-               // routeState);
-               //
-               // addedObjects.add(route1);
-               //
-               // final BGPRoute route2 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1:1::/64"), state,
-               // routeState);
-               //
-               // addedObjects.add(route2);
-               //
-               // final BGPRoute route3 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1::/64"), state,
-               // routeState);
-               //
-               // addedObjects.add(route3);
+               builder.setPathAttributes(paBuilder.build());
+               assertEquals(builder.build(), message);
        }
 
        /*
@@ -394,70 +423,59 @@ public class BGPParserTest {
         * 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
         */
        @Test
-       @Ignore
-       // FIXME: to be fixed in testing phase
        public void testGetUpdateMessage3() throws Exception {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH,
                                MessageUtil.LENGTH_FIELD_LENGTH));
                final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
 
+               final UpdateBuilder builder = new UpdateBuilder();
+
+               // check nlri
+               final Ipv4Prefix pref1 = new Ipv4Prefix("172.16.0.0/21");
+
+               final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1);
+               builder.setNlri(new NlriBuilder().setNlri(nlri).build());
+               assertEquals(builder.getNlri(), message.getNlri());
+
                // check fields
                assertNull(message.getWithdrawnRoutes());
 
                // attributes
-
                final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(30L)).build());
-               final List<AsPathSegment> asPath = Lists.newArrayList();
+               final List<Segments> asPath = Lists.newArrayList();
                asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
                asPath.add(new SegmentsBuilder().setCSegment(
                                new CASetBuilder().setAsSet(Lists.newArrayList(new AsNumber(10L), new AsNumber(20L))).build()).build());
 
-               final BgpAggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(
+               final Aggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(
                                new Ipv4Address("10.0.0.9")).build();
                final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
                                new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
 
-               // final IPv4Prefix pref1 = IPv4.FAMILY.prefixForString("172.16.0.0/21");
-
                // check path attributes
+               final PathAttributes attrs = message.getPathAttributes();
 
-               // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
-               // true, false, false, BGPOrigin.INCOMPLETE);
-               // assertEquals(originAttr, attrs.get(0));
-               //
-               // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
-               // true, false, false, asPath);
-               // assertEquals(asPathAttr, attrs.get(1));
-               //
-               // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
-               // true, false, false, nextHop);
-               // assertEquals(nextHopAttr, attrs.get(2));
-               //
-               // final PathAttribute multiExitDisc = new PathAttribute(
-               // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
-               // assertEquals(multiExitDisc, attrs.get(3));
-               //
-               // final PathAttribute agg = new PathAttribute(TypeCode.AGGREGATOR, true, true,
-               // false, false, aggregator);
-               // assertEquals(agg, attrs.get(4));
-               //
-               // // check nlri
-               //
-               // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1);
-               // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
-               //
-               // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Incomplete, aggregator);
-               // final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath,
-               // Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
+               final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
 
-               // check API message
+               paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Incomplete).build());
+               assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
+
+               paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
+               assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
+
+               paBuilder.setCNextHop(nextHop);
+               assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
+
+               paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
+               assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
+
+               paBuilder.setAggregator(aggregator);
+               assertEquals(paBuilder.getAggregator(), attrs.getAggregator());
 
-               // final Set<BGPObject> addedObjects = Sets.newHashSet();
-               //
-               // final BGPRoute route1 = new BGPIPv4RouteImpl(pref1, state, routeState);
-               //
-               // addedObjects.add(route1);
+               builder.setPathAttributes(paBuilder.build());
+
+               assertEquals(builder.build(), message);
        }
 
        /*
@@ -500,74 +518,64 @@ public class BGPParserTest {
         * 18 0a 1e 01 <- IPv4 Prefix (10.30.1.0 / 24)
         */
        @Test
-       @Ignore
-       // FIXME: to be fixed in testing phase
        public void testGetUpdateMessage4() throws Exception {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(3), MessageUtil.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(3), MessageUtil.MARKER_LENGTH,
                                MessageUtil.LENGTH_FIELD_LENGTH));
                final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
 
-               // check fields
+               final UpdateBuilder builder = new UpdateBuilder();
 
+               // check fields
                assertNull(message.getWithdrawnRoutes());
 
-               // attributes
+               // check nlri
+               final Ipv4Prefix pref1 = new Ipv4Prefix("10.30.3.0/24");
+               final Ipv4Prefix pref2 = new Ipv4Prefix("10.30.2.0/24");
+               final Ipv4Prefix pref3 = new Ipv4Prefix("10.30.1.0/24");
+
+               final List<Ipv4Prefix> nlri = Lists.newArrayList(pref1, pref2, pref3);
+               builder.setNlri(new NlriBuilder().setNlri(nlri).build());
+               assertEquals(builder.getNlri(), message.getNlri());
 
+               // attributes
                final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
                                new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("3.3.3.3")).build()).build();
 
-               final Set<ExtendedCommunity> comms = Sets.newHashSet();
-               comms.add(new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
-                               new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(new Ipv4Address("192.168.1.0")).setLocalAdministrator(
-                                               new byte[] { 0x12, 0x34 }).build()).build());
+               final List<ExtendedCommunities> comms = Lists.newArrayList();
+               comms.add(new ExtendedCommunitiesBuilder().setExtendedCommunity(
+                               new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
+                                               new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
+                                                               new Ipv4Address("192.168.1.0")).setLocalAdministrator(new byte[] { 0x12, 0x34 }).build()).build()).build());
+
+               final List<Segments> asPath = Lists.newArrayList();
 
                // check path attributes
+               final PathAttributes attrs = message.getPathAttributes();
 
-               // final PathAttribute originAttr = new PathAttribute(TypeCode.ORIGIN, false,
-               // true, false, false, BGPOrigin.EGP);
-               // assertEquals(originAttr, attrs.get(0));
-               //
-               // final PathAttribute asPathAttr = new PathAttribute(TypeCode.AS_PATH, false,
-               // true, false, false, asPath);
-               // assertEquals(asPathAttr, attrs.get(1));
-               //
-               // final PathAttribute nextHopAttr = new PathAttribute(TypeCode.NEXT_HOP, false,
-               // true, false, false, nextHop);
-               // assertEquals(nextHopAttr, attrs.get(2));
-               //
-               // final PathAttribute multiExitDisc = new PathAttribute(
-               // TypeCode.MULTI_EXIT_DISC, true, false, false, false, 0);
-               // assertEquals(multiExitDisc, attrs.get(3));
-               //
-               // final PathAttribute localPref = new PathAttribute(TypeCode.LOCAL_PREF, false,
-               // true, false, false, 100);
-               // assertEquals(localPref, attrs.get(4));
+               final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
 
-               // check nlri
-               //
-               // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1, pref2, pref3);
-               // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
+               paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
+               assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
 
-               // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Egp, null);
-               // final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(Collections.<AsPathSegment>
-               // emptyList(), Collections.<Community> emptySet(), comms), nextHop);
+               paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
+               assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
 
-               // check API message
+               paBuilder.setCNextHop(nextHop);
+               assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
+
+               paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
+               assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
+
+               paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
+               assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
 
-               // final Set<BGPObject> addedObjects = Sets.newHashSet();
-               //
-               // final BGPRoute route1 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.3.0/24"), state, routeState);
-               //
-               // addedObjects.add(route1);
-               //
-               // final BGPRoute route2 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.2.0/24"), state, routeState);
-               //
-               // addedObjects.add(route2);
-               //
-               // final BGPRoute route3 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.1.0/24"), state, routeState);
-               //
-               // addedObjects.add(route3);
+               paBuilder.setExtendedCommunities(comms);
+               assertEquals(paBuilder.getExtendedCommunities(), attrs.getExtendedCommunities());
+
+               // check API message
+               builder.setPathAttributes(paBuilder.build());
+               assertEquals(builder.build(), message);
        }
 
        /*
@@ -581,8 +589,6 @@ public class BGPParserTest {
         * 00 00 <- total path attribute length
         */
        @Test
-       @Ignore
-       // FIXME: to be fixed in testing phase
        public void testGetUpdateMessage5() throws Exception {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(4), MessageUtil.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(4), MessageUtil.MARKER_LENGTH,
@@ -590,20 +596,17 @@ public class BGPParserTest {
                final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
 
                // attributes
-
                final List<Ipv4Prefix> prefs = Lists.newArrayList(new Ipv4Prefix("172.16.0.4/30"));
 
                // check API message
-
                final Update expectedMessage = new UpdateBuilder().setWithdrawnRoutes(
                                new WithdrawnRoutesBuilder().setWithdrawnRoutes(prefs).build()).build();
 
-               assertEquals(expectedMessage.getWithdrawnRoutes().getWithdrawnRoutes().get(0).toString(),
-                               message.getWithdrawnRoutes().getWithdrawnRoutes().get(0).toString());
+               assertEquals(expectedMessage.getWithdrawnRoutes(), message.getWithdrawnRoutes());
        }
 
        /*
-        * Test EOR for IPv4.
+        * End of Rib for Ipv4.
         * 
         * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
         * 00 17 <- length (23) - including header
@@ -636,21 +639,17 @@ public class BGPParserTest {
         * 01 <- value (SAFI 1)
         */
        @Test
-       @Ignore
-       // FIXME: to be fixed in testing phase
        public void testEORIpv6() throws Exception {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(6), MessageUtil.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), MessageUtil.MARKER_LENGTH,
                                MessageUtil.LENGTH_FIELD_LENGTH));
                final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
 
-               // check fields
-
-               final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi();
-               final SubsequentAddressFamily safi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getSafi().newInstance();
+               final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getAfi();
+               final Class<? extends SubsequentAddressFamily> safi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getSafi();
 
                assertEquals(Ipv6AddressFamily.class, afi);
-               assertEquals(UnicastSubsequentAddressFamily.INSTANCE, safi);
+               assertEquals(UnicastSubsequentAddressFamily.class, safi);
        }
 
        /*
@@ -668,19 +667,17 @@ public class BGPParserTest {
         * 47 <- value (SAFI 71)
         */
        @Test
-       @Ignore
-       // FIXME: to be fixed in testing phase
        public void testEORLS() throws Exception {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(7), MessageUtil.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(7), MessageUtil.MARKER_LENGTH,
                                MessageUtil.LENGTH_FIELD_LENGTH));
                final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
 
-               final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi();
-               final SubsequentAddressFamily safi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getSafi().newInstance();
+               final Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getAfi();
+               final Class<? extends SubsequentAddressFamily> safi = message.getPathAttributes().getAugmentation(PathAttributes2.class).getMpUnreachNlri().getSafi();
 
                assertEquals(LinkstateAddressFamily.class, afi);
-               assertEquals(LinkstateSubsequentAddressFamily.INSTANCE, safi);
+               assertEquals(LinkstateSubsequentAddressFamily.class, safi);
        }
 
        /*
@@ -833,58 +830,123 @@ public class BGPParserTest {
                00 00 01 <- value
         */
        @Test
-       @Ignore
-       // FIXME: to be fixed in testing phase
        public void testBGPLink() throws Exception {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(8), MessageUtil.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(8), MessageUtil.MARKER_LENGTH,
                                MessageUtil.LENGTH_FIELD_LENGTH));
                final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
 
+               final UpdateBuilder builder = new UpdateBuilder();
+
                // check fields
 
                assertNull(message.getWithdrawnRoutes());
 
-               // network object state
-               // final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(),
-               // Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
-               // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
-
-               // network link state
-               // final DefaultingTypesafeContainer<Metric<?>> container = new DefaultingTypesafeContainer<Metric<?>>();
-               // container.setDefaultEntry(new IGPMetric(1));
-               // final NetworkLinkState linkState = new NetworkLinkState(objState, container, null,
-               // LinkProtectionType.UNPROTECTED, null, null, null);
-
-               // final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new
-               // DomainIdentifier(new byte[] { 25, 25,
-               // 25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
-               //
-               // final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new
-               // byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
-               // 0x0b, 0x0b, 0x0b, 0x03 })));
-               // final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
-               //
-               // final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
+               final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
+                               new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
+
+               final List<Segments> asPath = Lists.newArrayList();
+
+               final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
+                               new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
+                               new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+
+               final RemoteNodeDescriptorsBuilder rndBuilder = new RemoteNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
+                               new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
+                               new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+
+               final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
+               clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
+               clBuilder.setNlriType(NlriType.Link);
+               clBuilder.setProtocolId(ProtocolId.Ospf);
+
+               final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
+               final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+               mpBuilder.setAfi(LinkstateAddressFamily.class);
+               mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
+               mpBuilder.setCNextHop(nextHop);
+
+               final List<CLinkstateDestination> linkstates = Lists.newArrayList();
+               clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+                               new COspfPseudonodeBuilder().setOspfPseudonode(
+                                               new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
+                                                               new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+               clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
+                               new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).build()).build()).build());
+               clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
+                               new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.3"))).build());
+               linkstates.add(clBuilder.build());
+
+               clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+                               new COspfPseudonodeBuilder().setOspfPseudonode(
+                                               new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
+                                                               new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+               clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
+                               new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
+               clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
+                               new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
+               linkstates.add(clBuilder.build());
+
+               clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+                               new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
+               clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
+                               new COspfPseudonodeBuilder().setOspfPseudonode(
+                                               new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
+                                                               new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+               clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
+                               new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
+               linkstates.add(clBuilder.build());
+
+               lsBuilder.setMpReachNlri(mpBuilder.build());
 
-               // check API message
+               // check path attributes
+               final PathAttributes attrs = message.getPathAttributes();
+
+               final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+
+               paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
+               assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
+
+               paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
+               assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
 
-               // final LinkIdentifier linkId1 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new
-               // IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.3"))), new LinkAnchor(nodeid2, null));
-               // final LinkIdentifier linkId2 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new
-               // IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid3, null));
-               // final LinkIdentifier linkId3 = new LinkIdentifier(null, new LinkAnchor(nodeid3, new
-               // IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid1, null));
-               //
-               // final BGPLink link1 = new BGPLinkImpl(state, linkId1, linkState);
-               // final BGPLink link2 = new BGPLinkImpl(state, linkId2, linkState);
-               // final BGPLink link3 = new BGPLinkImpl(state, linkId3, linkState);
-               //
-               // final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) link1,
-               // (BGPObject) link2,
-               // (BGPObject) link3), Collections.<Identifier> emptySet());
-               //
-               // assertEquals(expectedMessage, message);
+               paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
+               assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
+
+               final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
+               assertEquals(mpBuilder.getAfi(), mp.getAfi());
+               assertEquals(mpBuilder.getSafi(), mp.getSafi());
+               assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
+
+               final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
+               dBuilder.setCLinkstateDestination(linkstates);
+
+               mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(dBuilder.build()).build());
+               lsBuilder.setMpReachNlri(mpBuilder.build());
+
+               paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
+
+               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1Builder lsAttrBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1Builder();
+
+               lsAttrBuilder.setLinkstatePathAttribute(new LinkstatePathAttributeBuilder().setLinkStateAttribute(
+                               new LinkAttributesBuilder().setMetric(new Metric(1L)).build()).build());
+               paBuilder.addAugmentation(
+                               org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1.class,
+                               lsAttrBuilder.build());
+
+               assertEquals(
+                               lsAttrBuilder.build().getLinkstatePathAttribute(),
+                               attrs.getAugmentation(
+                                               org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1.class).getLinkstatePathAttribute());
+
+               final List<CLinkstateDestination> dests = ((DestinationLinkstate) mp.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
+
+               assertEquals(linkstates.size(), dests.size());
+
+               assertEquals(linkstates, dests);
+               // check API message
+               builder.setPathAttributes(paBuilder.build());
+               assertEquals(builder.build(), message);
        }
 
        /*
@@ -900,11 +962,11 @@ public class BGPParserTest {
                04 <- next hop length
                19 19 19 01 - nexthop (25.25.25.1)
                00 <- reserved
+               
                00 01 <- NLRI type (1 - nodeNLRI)
                00 31 <- NLRI length (49)
                03 <- ProtocolID - OSPF
                00 00 00 00 00 00 00 01 <- identifier
-
                01 00 <- local node descriptor type (256)
                00 24 <- length (36)
                02 00 <- node descriptor type (member AS - 512)
@@ -924,7 +986,6 @@ public class BGPParserTest {
                00 2d <- NLRI length (45)
                03 <- ProtocolID - OSPF
                00 00 00 00 00 00 00 01 <- identifier
-
                01 00 <- local node descriptor type (256)
                00 20 <- length (32)
                02 00 <- node descriptor type (member AS - 512)
@@ -972,50 +1033,91 @@ public class BGPParserTest {
                00 00 00 64 <- value
         */
        @Test
-       @Ignore
-       // FIXME: to be fixed in testing phase
        public void testBGPNode() throws Exception {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(9), MessageUtil.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(9), MessageUtil.MARKER_LENGTH,
                                MessageUtil.LENGTH_FIELD_LENGTH));
                final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
 
+               final UpdateBuilder builder = new UpdateBuilder();
+
                // check fields
 
                assertNull(message.getWithdrawnRoutes());
 
-               // network object state
-               // final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(),
-               // Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
-               // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
-               // final NetworkNodeState nstate = new NetworkNodeState(objState, Collections.<TopologyIdentifier> emptySet(),
-               // Collections.<ISISAreaIdentifier> emptySet(), false, false, false, false, Collections.<RouterIdentifier>
-               // emptySet(), null);
-
-               // network link state
-
-               // final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new
-               // DomainIdentifier(new byte[] { 25, 25,
-               // 25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
-               //
-               // final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new
-               // byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
-               // 0x0b, 0x0b, 0x0b, 0x03 })));
-               // final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
-               //
-               // final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
+               // attributes
 
-               // check API message
+               final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
+                               new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
+
+               final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
+                               new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
+                               new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+
+               final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
+               clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
+               clBuilder.setNlriType(NlriType.Node);
+               clBuilder.setProtocolId(ProtocolId.Ospf);
+
+               final List<CLinkstateDestination> linkstates = Lists.newArrayList();
+               clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+                               new COspfPseudonodeBuilder().setOspfPseudonode(
+                                               new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
+                                                               new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+               linkstates.add(clBuilder.build());
+
+               clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+                               new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).build()).build()).build());
+               linkstates.add(clBuilder.build());
+
+               clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+                               new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
+               linkstates.add(clBuilder.build());
+
+               final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
+               final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+               mpBuilder.setAfi(LinkstateAddressFamily.class);
+               mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
+               mpBuilder.setCNextHop(nextHop);
+
+               final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
+               dBuilder.setCLinkstateDestination(linkstates);
+
+               mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(dBuilder.build()).build());
+               lsBuilder.setMpReachNlri(mpBuilder.build());
+
+               final List<Segments> asPath = Lists.newArrayList();
 
-               // final BGPNode node1 = new BGPNodeImpl(state, nodeid1, nstate);
-               // final BGPNode node2 = new BGPNodeImpl(state, nodeid2, nstate);
-               // final BGPNode node3 = new BGPNodeImpl(state, nodeid3, nstate);
-               //
-               // final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) node1,
-               // (BGPObject) node2,
-               // (BGPObject) node3), Collections.<Identifier> emptySet());
-               //
-               // assertEquals(expectedMessage, message);
+               // check path attributes
+               final PathAttributes attrs = message.getPathAttributes();
+
+               final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+
+               paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
+               assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
+
+               paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
+               assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
+
+               paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
+               assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
+
+               paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
+
+               final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
+               assertEquals(mpBuilder.getAfi(), mp.getAfi());
+               assertEquals(mpBuilder.getSafi(), mp.getSafi());
+               assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
+
+               final List<CLinkstateDestination> dests = ((DestinationLinkstate) mp.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
+
+               assertEquals(linkstates.size(), dests.size());
+
+               assertEquals(linkstates, dests);
+
+               // check API message
+               builder.setPathAttributes(paBuilder.build());
+               assertEquals(builder.build(), message);
        }
 
        /*
@@ -1058,7 +1160,7 @@ public class BGPParserTest {
         */
        @Test
        public void testOpenMessage() throws Exception {
-               final MessageRegistry msgReg = BGPExtensionConsumerContextImpl.getSingletonInstance().getMessageRegistry();
+               final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry();
                final Open open = (Open) msgReg.parseMessage(inputBytes.get(13));
                final Set<BgpTableType> types = Sets.newHashSet();
                for (final BgpParameters param : open.getBgpParameters()) {
index 94021ad5552d3df5a5d8871bc763372bdabdb069..3512abf39aeb7f9f3c94f65942929956ce4efad5 100644 (file)
@@ -13,6 +13,7 @@ import static org.junit.Assert.fail;
 
 import org.junit.Ignore;
 import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunityUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
 
 public class CommunityTest {
index a2e72b1b269d57e35b98f7caa57292766030d60d..3666ab7e8f7ed3bb88bd266456dab95c1c8f149f 100644 (file)
@@ -13,7 +13,6 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.fail;
 
-import java.io.IOException;
 import java.util.Map;
 
 import org.junit.Test;
@@ -21,7 +20,7 @@ import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunitiesParser;
 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.BGPExtensionConsumerContextImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
 import org.opendaylight.protocol.framework.DeserializerException;
 import org.opendaylight.protocol.framework.DocumentedException;
 import org.opendaylight.protocol.util.ByteList;
@@ -101,9 +100,9 @@ public class ComplementaryTest {
 
                assertEquals(40, ((CAs4Bytes) tlv4).getAs4BytesCapability().getAsNumber().getValue().longValue());
 
-               // FIXME: no generated toString
-               // assertEquals(new As4BytesBuilder().setCAs4Bytes(new CAs4BytesBuilder().setAsNumber(new AsNumber((long)
-               // 40)).build()).build().toString(), tlv4.toString());
+               assertEquals(
+                               new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber((long) 40)).build()).build(),
+                               tlv4);
        }
 
        @Test
@@ -220,8 +219,8 @@ public class ComplementaryTest {
        }
 
        @Test
-       public void testBGPHeaderParser() throws IOException {
-               final MessageRegistry msgReg = BGPExtensionConsumerContextImpl.getSingletonInstance().getMessageRegistry();
+       public void testBGPHeaderParser() throws Exception {
+               final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry();
                try {
                        msgReg.parseMessage(new byte[] { (byte) 0, (byte) 0 });
                        fail("Exception should have occured.");
@@ -249,8 +248,8 @@ public class ComplementaryTest {
        }
 
        @Test
-       public void testMessageParser() throws IOException {
-               final MessageRegistry msgReg = BGPExtensionConsumerContextImpl.getSingletonInstance().getMessageRegistry();
+       public void testMessageParser() throws Exception {
+               final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry();
                String ex = "";
                try {
                        msgReg.serializeMessage(null);
diff --git a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/OpenTest.java b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/OpenTest.java
new file mode 100644 (file)
index 0000000..60414e0
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.parser.impl;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.OpenBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.ProtocolVersion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParametersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.CAs4BytesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.c.as4.bytes.As4BytesCapabilityBuilder;
+
+import com.google.common.collect.Lists;
+
+public class OpenTest {
+
+       private final byte[] result = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                       (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                       (byte) 0x00, (byte) 0x25, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x1e, (byte) 0x00, (byte) 0x03, (byte) 0x7f,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x08, (byte) 0x02, (byte) 0x06, (byte) 0x41, (byte) 0x04, (byte) 0x00,
+                       (byte) 0x00, (byte) 0x03, (byte) 0xe8 };
+
+       @Test
+       public void testSerializeOpen() throws Exception {
+               final List<BgpParameters> tlvs = Lists.newArrayList();
+               tlvs.add(new BgpParametersBuilder().setCParameters(
+                               new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(1000L)).build()).build()).build());
+               final Open open = new OpenBuilder().setBgpIdentifier(new Ipv4Address("127.0.0.1")).setMyAsNumber(30).setHoldTimer(3).setVersion(
+                               new ProtocolVersion((short) 4)).setBgpParameters(tlvs).build();
+               final byte[] msg = new BGPOpenMessageParser(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getParameterRegistry()).serializeMessage(open);
+               assertArrayEquals(this.result, msg);
+       }
+}
similarity index 80%
rename from bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserTest.java
rename to bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ParserTest.java
index 4a4e5882448b47127316982f6e83fc8ae9464787..0ff66fc6d5a08f75103bca5b21925de22b2f04ef 100644 (file)
@@ -5,7 +5,7 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.protocol.bgp.rib.impl;
+package org.opendaylight.protocol.bgp.parser.impl;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
@@ -20,12 +20,14 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
+import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
-import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.BGPExtensionConsumerContextImpl;
+import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
 import org.opendaylight.protocol.framework.DeserializerException;
 import org.opendaylight.protocol.framework.DocumentedException;
 import org.opendaylight.protocol.util.ByteArray;
@@ -54,34 +56,38 @@ import com.google.common.collect.Maps;
 public class ParserTest {
 
        public static final byte[] openBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4,
-               (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
+                       (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                       (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4,
+                       (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
 
        public static final byte[] keepAliveBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0x00, (byte) 0x13, (byte) 0x04 };
+                       (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                       (byte) 0xff, (byte) 0x00, (byte) 0x13, (byte) 0x04 };
 
        public static final byte[] notificationBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x03, (byte) 0x02, (byte) 0x04, (byte) 0x04, (byte) 0x09 };
+                       (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                       (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x03, (byte) 0x02, (byte) 0x04, (byte) 0x04, (byte) 0x09 };
 
        public static final byte[] openWithCpblt1 = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4,
-               (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04,
-               (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x40,
-               (byte) 0x04, (byte) 0x00, (byte) 0x47 };
+                       (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                       (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4,
+                       (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04,
+                       (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x40,
+                       (byte) 0x04, (byte) 0x00, (byte) 0x47 };
 
        public static final byte[] openWithCpblt2 = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4,
-               (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04,
-               (byte) 0x40, (byte) 0x04, (byte) 0x00, (byte) 0x47, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x00,
-               (byte) 0x01, (byte) 0x00, (byte) 0x01 };
+                       (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                       (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4,
+                       (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04,
+                       (byte) 0x40, (byte) 0x04, (byte) 0x00, (byte) 0x47, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x00,
+                       (byte) 0x01, (byte) 0x00, (byte) 0x01 };
 
-       final MessageRegistry factory =
-                       BGPExtensionConsumerContextImpl.getSingletonInstance().getMessageRegistry();
+       static BGPMessageFactory factory;
+
+       @BeforeClass
+       public static void setupClass() throws Exception {
+               factory = new BGPMessageFactoryImpl(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry());
+       }
 
        @Test
        public void testHeaderErrors() throws DeserializerException, DocumentedException {
@@ -89,7 +95,7 @@ public class ParserTest {
                                (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00 };
                wrong = ByteArray.cutBytes(wrong, 16);
                try {
-                       this.factory.parseMessage(wrong);
+                       ParserTest.factory.parse(wrong);
                        fail("Exception should have occcured.");
                } catch (final IllegalArgumentException e) {
                        assertEquals("Too few bytes in passed array. Passed: " + wrong.length + ". Expected: >= 19.", e.getMessage());
@@ -104,7 +110,7 @@ public class ParserTest {
                                (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
                                (byte) 0x00, (byte) 0x13, (byte) 0x08 };
                try {
-                       this.factory.parseMessage(bytes);
+                       ParserTest.factory.parse(bytes);
                        fail("Exception should have occured.");
                } catch (final DocumentedException e) {
                        assertEquals(BGPError.BAD_MSG_TYPE, ((BGPDocumentedException) e).getError());
@@ -116,10 +122,10 @@ public class ParserTest {
        @Test
        public void testKeepAliveMsg() throws DeserializerException, DocumentedException {
                final Notification keepAlive = new KeepaliveBuilder().build();
-               final byte[] bytes = this.factory.serializeMessage(keepAlive);
+               final byte[] bytes = ParserTest.factory.put(keepAlive);
                assertArrayEquals(keepAliveBMsg, bytes);
 
-               final Notification m = this.factory.parseMessage(bytes);
+               final Notification m = ParserTest.factory.parse(bytes);
 
                assertTrue(m instanceof Keepalive);
        }
@@ -131,7 +137,7 @@ public class ParserTest {
                                (byte) 0x00, (byte) 0x14, (byte) 0x04, (byte) 0x05 };
 
                try {
-                       this.factory.parseMessage(bytes);
+                       ParserTest.factory.parse(bytes);
                        fail("Exception should have occured.");
                } catch (final DocumentedException e) {
                        assertThat(e.getMessage(), containsString("Message length field not within valid range."));
@@ -145,10 +151,10 @@ public class ParserTest {
        public void testOpenMessage() throws UnknownHostException, DeserializerException, DocumentedException {
                final Notification open = new OpenBuilder().setMyAsNumber(100).setHoldTimer(180).setBgpIdentifier(new Ipv4Address("20.20.20.20")).setVersion(
                                new ProtocolVersion((short) 4)).build();
-               final byte[] bytes = this.factory.serializeMessage(open);
+               final byte[] bytes = ParserTest.factory.put(open);
                assertArrayEquals(openBMsg, bytes);
 
-               final Notification m = this.factory.parseMessage(bytes);
+               final Notification m = ParserTest.factory.parse(bytes);
 
                assertTrue(m instanceof Open);
                assertEquals(100, ((Open) m).getMyAsNumber().intValue());
@@ -165,7 +171,7 @@ public class ParserTest {
                                (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
 
                try {
-                       this.factory.parseMessage(bMsg);
+                       ParserTest.factory.parse(bMsg);
                        fail("Exception should have occured.");
                } catch (final DocumentedException e) {
                        assertEquals("Hold time value not acceptable.", e.getMessage());
@@ -183,7 +189,7 @@ public class ParserTest {
                                (byte) 0xff, (byte) 0xff };
 
                try {
-                       this.factory.parseMessage(bMsg);
+                       ParserTest.factory.parse(bMsg);
                        fail("Exception should have occured.");
                } catch (final DocumentedException e) {
                        assertEquals("Open message too small.", e.getMessage());
@@ -199,7 +205,7 @@ public class ParserTest {
                                (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
 
                try {
-                       this.factory.parseMessage(bMsg);
+                       ParserTest.factory.parse(bMsg);
                        fail("Exception should have occured.");
                } catch (final DocumentedException e) {
                        assertEquals("BGP Protocol version 8 not supported.", e.getMessage());
@@ -213,10 +219,10 @@ public class ParserTest {
        public void testNotificationMsg() throws DeserializerException, DocumentedException {
                Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode()).setErrorSubcode(
                                BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
-               byte[] bytes = this.factory.serializeMessage(notMsg);
+               byte[] bytes = ParserTest.factory.put(notMsg);
                assertArrayEquals(notificationBMsg, bytes);
 
-               Notification m = this.factory.parseMessage(bytes);
+               Notification m = ParserTest.factory.parse(bytes);
 
                assertTrue(m instanceof Notify);
                assertEquals(BGPError.OPT_PARAM_NOT_SUPPORTED, BGPError.forValue(((Notify) m).getErrorCode(), ((Notify) m).getErrorSubcode()));
@@ -224,9 +230,9 @@ public class ParserTest {
 
                notMsg = new NotifyBuilder().setErrorCode(BGPError.CONNECTION_NOT_SYNC.getCode()).setErrorSubcode(
                                BGPError.CONNECTION_NOT_SYNC.getSubcode()).build();
-               bytes = this.factory.serializeMessage(notMsg);
+               bytes = ParserTest.factory.put(notMsg);
 
-               m = this.factory.parseMessage(bytes);
+               m = ParserTest.factory.parse(bytes);
 
                assertTrue(m instanceof Notify);
                assertEquals(BGPError.CONNECTION_NOT_SYNC, BGPError.forValue(((Notify) m).getErrorCode(), ((Notify) m).getErrorSubcode()));
@@ -240,7 +246,7 @@ public class ParserTest {
                                (byte) 0x00, (byte) 0x14, (byte) 0x03, (byte) 0x02 };
 
                try {
-                       this.factory.parseMessage(bMsg);
+                       ParserTest.factory.parse(bMsg);
                        fail("Exception should have occured.");
                } catch (final DocumentedException e) {
                        assertEquals("Notification message too small.", e.getMessage());
@@ -257,7 +263,7 @@ public class ParserTest {
                                (byte) 0x00, (byte) 0x15, (byte) 0x03, (byte) 0x02, (byte) 0xaa };
 
                try {
-                       this.factory.parseMessage(bMsg);
+                       ParserTest.factory.parse(bMsg);
                        fail("Exception should have occured.");
                } catch (final IllegalArgumentException e) {
                        assertEquals("BGP Error code 2 and subcode 170 not recognized.", e.getMessage());
@@ -288,7 +294,7 @@ public class ParserTest {
                final Open open = new OpenBuilder().setMyAsNumber(72).setHoldTimer(180).setBgpIdentifier(new Ipv4Address("172.20.160.170")).setVersion(
                                new ProtocolVersion((short) 4)).setBgpParameters(tlvs).build();
 
-               final byte[] result = this.factory.serializeMessage(open);
+               final byte[] result = ParserTest.factory.put(open);
 
                // the capabilities can be swapped.
                assertTrue(Arrays.equals(openWithCpblt1, result) || Arrays.equals(openWithCpblt2, result));
index 1b4a458edc36cff4882a6bb01cfde701a82ec814..edbabd5188eb073165bd7195e823b09a3592251d 100644 (file)
@@ -14,16 +14,16 @@ import static org.junit.Assert.fail;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.BGPExtensionConsumerContextImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
 
 /*
  * To test incorrect values.
  */
 public class PathAttributeParserTest {
        @Test
-       public void testOriginParser() {
+       public void testOriginParser() throws Exception {
                try {
-                       BGPExtensionConsumerContextImpl.getSingletonInstance().getAttributeRegistry().parseAttributes(new byte[] { 0x40, 0x01, 0x01, 0x04 });
+                       ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getAttributeRegistry().parseAttributes(new byte[] { 0x40, 0x01, 0x01, 0x04 });
                        fail("This needs to fail.");
                } catch (final BGPDocumentedException e) {
                        assertEquals("Unknown Origin type.", e.getMessage());
index 2191dc06510d53cfe09a1d5f690f1efa5d57c089..8ebe4c08deda0311b6d9a11c375e207831b5f6c4 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.protocol.bgp.parser.mock;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -18,11 +19,13 @@ import java.util.Map;
 import java.util.Set;
 
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
 import org.opendaylight.protocol.framework.DeserializerException;
 import org.opendaylight.protocol.framework.DocumentedException;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.OpenBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.ProtocolVersion;
@@ -31,12 +34,31 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParametersBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AsPathBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.OriginBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.Segments;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.SegmentsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocolBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.c.multiprotocol.MultiprotocolCapabilityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.CAListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequence;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.c.a.list.AsSequenceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHopBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv6.next.hop.Ipv6NextHopBuilder;
 import org.opendaylight.yangtools.yang.binding.Notification;
 
 import com.google.common.collect.Lists;
@@ -65,8 +87,6 @@ public class BGPMessageParserMockTest {
         * @throws IOException
         */
        @Test
-       @Ignore
-       // FIXME : BUG-94
        public void testGetUpdateMessage() throws DeserializerException, DocumentedException, IOException {
                final Map<byte[], Notification> updateMap = Maps.newHashMap();
                for (int i = 0; i < this.inputBytes.length; i++) {
@@ -78,7 +98,7 @@ public class BGPMessageParserMockTest {
                for (int i = 0; i < this.inputBytes.length; i++) {
                        assertEquals(this.messages.get(i), mockParser.parse(this.inputBytes[i]));
                }
-               // assertThat(this.messages.get(3), not(mockParser.parse(this.inputBytes[8]).get(0)));
+               assertNotSame(this.messages.get(3), mockParser.parse(this.inputBytes[8]));
        }
 
        /**
@@ -125,32 +145,34 @@ public class BGPMessageParserMockTest {
         */
        private Update fillMessages(final long asn) throws UnknownHostException {
 
-               // FIXME: to be fixed in testing phase
-               /*final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(asn)).build());
-               final List<AsPathSegment> asPath = Lists.newArrayList();
+               final UpdateBuilder builder = new UpdateBuilder();
+
+               final List<AsSequence> asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(asn)).build());
+               final List<Segments> asPath = Lists.newArrayList();
                asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build());
-               final CNextHop nextHop = new CIpv6NextHopBuilder().setIpv6NextHop(
+               final CNextHop nextHop = (CNextHop) new CIpv6NextHopBuilder().setIpv6NextHop(
                                new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
 
-               final Prefix<IPv6Address> pref1 = new IPv6Prefix(new IPv6Address(InetAddress.getByName("2001:db8:1:2::")), 64);
-               final Prefix<IPv6Address> pref2 = new IPv6Prefix(new IPv6Address(InetAddress.getByName("2001:db8:1:1::")), 64);
-               final Prefix<IPv6Address> pref3 = new IPv6Prefix(new IPv6Address(InetAddress.getByName("2001:db8:1::")), 64);
+               final Ipv6Prefix pref1 = new Ipv6Prefix("2001:db8:1:2::/64");
+               final Ipv6Prefix pref2 = new Ipv6Prefix("2001:db8:1:1::/64");
+               final Ipv6Prefix pref3 = new Ipv6Prefix("2001:db8:1::/64");
 
-               final Set<BGPObject> addedObjects = new HashSet<BGPObject>();
+               PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+               paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
+               paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
 
-               final NetworkRouteState nstate = new NetworkRouteState(new NetworkObjectState(asPath, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
-               final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
+               MpReachNlriBuilder mpReachBuilder = new MpReachNlriBuilder();
+               mpReachBuilder.setAfi(Ipv6AddressFamily.class);
+               mpReachBuilder.setSafi(UnicastSubsequentAddressFamily.class);
+               mpReachBuilder.setCNextHop(nextHop);
+               mpReachBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
+                               new DestinationIpv6Builder().setIpv6Prefixes(Lists.newArrayList(pref1, pref2, pref3)).build()).build());
 
-               final BGPRoute route1 = new BGPIPv6RouteImpl(pref1, state, nstate);
-               final BGPRoute route2 = new BGPIPv6RouteImpl(pref2, state, nstate);
-               final BGPRoute route3 = new BGPIPv6RouteImpl(pref3, state, nstate);
-               addedObjects.add(route1);
-               addedObjects.add(route2);
-               addedObjects.add(route3);
+               paBuilder.addAugmentation(PathAttributes1.class, new PathAttributes1Builder().setMpReachNlri(mpReachBuilder.build()).build());
 
-               return new BGPUpdateMessageImpl(addedObjects, Collections.<Identifier> emptySet());*/
+               builder.setPathAttributes(paBuilder.build());
 
-               return new UpdateBuilder().build();
+               return builder.build();
        }
 
        @Test
index 9fe27d022e76822103dd3c4440f7df61026a4fd5..67e527665247627122574c3c1e9d4ad54f565a81 100644 (file)
@@ -13,9 +13,7 @@ import com.google.common.primitives.UnsignedBytes;
 
 public final class CapabilityUtil {
 
-       public static final int CODE_SIZE = 1; // bytes
-       public static final int LENGTH_SIZE = 1; // bytes
-       private static final int HEADER_SIZE = CODE_SIZE + LENGTH_SIZE;
+       private static final int HEADER_SIZE = 2;
 
        private CapabilityUtil() {
 
index 16175b7ac0b5d83d8a05682e3933c25ce3dda727..890c5e4d22a8c72fc1066d2f7ce6813a20760712 100644 (file)
@@ -13,12 +13,11 @@ import org.opendaylight.protocol.util.ByteArray;
 
 import com.google.common.primitives.UnsignedBytes;
 
-
 public final class MessageUtil {
 
-       public static final int LENGTH_FIELD_LENGTH = 2; // bytes
-       public static final int MARKER_LENGTH = 16; // bytes
-       public static final int TYPE_FIELD_LENGTH = 1; // bytes
+       public static final int LENGTH_FIELD_LENGTH = 2;
+       public static final int MARKER_LENGTH = 16;
+       public static final int TYPE_FIELD_LENGTH = 1;
        public static final int COMMON_HEADER_LENGTH = LENGTH_FIELD_LENGTH + TYPE_FIELD_LENGTH + MARKER_LENGTH;
 
        private MessageUtil() {
@@ -36,9 +35,8 @@ public final class MessageUtil {
        public static byte[] formatMessage(final int type, final byte[] body) {
                final byte[] retBytes = new byte[COMMON_HEADER_LENGTH + body.length];
 
-               Arrays.fill(retBytes, 0, MARKER_LENGTH, (byte) 0xff);
-               System.arraycopy(ByteArray.intToBytes(body.length + COMMON_HEADER_LENGTH),
-                               Integer.SIZE / Byte.SIZE - LENGTH_FIELD_LENGTH,
+               Arrays.fill(retBytes, 0, MARKER_LENGTH, UnsignedBytes.MAX_VALUE);
+               System.arraycopy(ByteArray.intToBytes(body.length + COMMON_HEADER_LENGTH), Integer.SIZE / Byte.SIZE - LENGTH_FIELD_LENGTH,
                                retBytes, MARKER_LENGTH, LENGTH_FIELD_LENGTH);
 
                retBytes[MARKER_LENGTH + LENGTH_FIELD_LENGTH] = UnsignedBytes.checkedCast(type);
index d6d7f0bc76244c51a3501e1b6d22f11ce1871611..651107d9d4cd66910f2864b1d04033814f089841 100644 (file)
@@ -13,6 +13,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult
 
 public interface NlriRegistry {
        public MpUnreachNlri parseMpUnreach(final byte[] bytes) throws BGPParsingException;
+
        public MpReachNlri parseMpReach(final byte[] bytes) throws BGPParsingException;
-       //      public byte[] serializeNlri(DataObject attribute);
 }
index 452c5af27b847ba08e2e6823c599c7d6758ae6dd..ea3c63238e70e05befbb8eda113765bc61ab4ee9 100644 (file)
@@ -20,23 +20,22 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 
 public final class NlriUtil {
        private NlriUtil() {
-
        }
 
        public static void parseNextHop(final byte[] bytes, final MpReachNlriBuilder builder) throws BGPParsingException {
                final CNextHop addr;
 
                switch (bytes.length) {
-               case 4:
+               case Ipv4Util.IP4_LENGTH:
                        addr = new CIpv4NextHopBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(Ipv4Util.addressForBytes(bytes)).build()).build();
                        break;
-               case 16:
+               case Ipv6Util.IPV6_LENGTH:
                        addr = new CIpv6NextHopBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(Ipv6Util.addressForBytes(bytes)).build()).build();
                        break;
-               case 32:
+               case Ipv6Util.IPV6_LENGTH * 2:
                        addr = new CIpv6NextHopBuilder().setIpv6NextHop(
-                                       new Ipv6NextHopBuilder().setGlobal(Ipv6Util.addressForBytes(ByteArray.subByte(bytes, 0, 16))).setLinkLocal(
-                                                       Ipv6Util.addressForBytes(ByteArray.subByte(bytes, 16, 16))).build()).build();
+                                       new Ipv6NextHopBuilder().setGlobal(Ipv6Util.addressForBytes(ByteArray.subByte(bytes, 0, Ipv6Util.IPV6_LENGTH))).setLinkLocal(
+                                                       Ipv6Util.addressForBytes(ByteArray.subByte(bytes, Ipv6Util.IPV6_LENGTH, Ipv6Util.IPV6_LENGTH))).build()).build();
                        break;
                default:
                        throw new BGPParsingException("Cannot parse NEXT_HOP attribute. Wrong bytes length: " + bytes.length);
index a331666f784d378aced83a8b77cbff380fbbe4de..bc9e44689969094cda7d9021903d7f89c28b7f17 100644 (file)
@@ -10,15 +10,18 @@ package org.opendaylight.protocol.bgp.parser.spi;
 import com.google.common.primitives.UnsignedBytes;
 
 public final class ParameterUtil {
+
+       private static final int HEADER_SIZE = 2;
+
        private ParameterUtil() {
 
        }
 
        public static byte[] formatParameter(final int type, final byte[] value) {
-               final byte[] bytes = new byte[2 + value.length];
+               final byte[] bytes = new byte[HEADER_SIZE + value.length];
                bytes[0] = UnsignedBytes.checkedCast(type);
                bytes[1] = UnsignedBytes.checkedCast(value.length);
-               System.arraycopy(value, 0, bytes, 2, value.length);
+               System.arraycopy(value, 0, bytes, HEADER_SIZE, value.length);
                return bytes;
        }
 }
index 3954f68800c268a50160a54d4d898cadb9e11f96..1d34eb83fc17e7ab3bad9334a7af97e62cd4dbeb 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
 import org.opendaylight.protocol.concepts.AbstractRegistration;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
@@ -22,13 +23,14 @@ import org.osgi.framework.ServiceRegistration;
 import com.google.common.base.Preconditions;
 
 class OSGiBGPExtensionConsumerContext implements BGPExtensionConsumerContext {
+       protected final SimpleBGPExtensionProviderContext providerContext = new SimpleBGPExtensionProviderContext();
        protected final BundleContext bundleContext;
 
        OSGiBGPExtensionConsumerContext(final BundleContext context) {
                this.bundleContext = Preconditions.checkNotNull(context);
        }
 
-       protected <T> AutoCloseable register(final Class<T> clazz, final T object) {
+       protected final <T> AutoCloseable register(final Class<T> clazz, final T object) {
                final ServiceRegistration<T> reg = bundleContext.registerService(clazz, object, null);
 
                return new AbstractRegistration() {
@@ -39,50 +41,42 @@ class OSGiBGPExtensionConsumerContext implements BGPExtensionConsumerContext {
                };
        }
 
-       public BundleContext getBundleContext() {
+       public final BundleContext getBundleContext() {
                return bundleContext;
        }
 
        @Override
-       public AddressFamilyRegistry getAddressFamilyRegistry() {
-               // TODO Auto-generated method stub
-               return null;
+       public final AddressFamilyRegistry getAddressFamilyRegistry() {
+               return providerContext.getAddressFamilyRegistry();
        }
 
        @Override
-       public AttributeRegistry getAttributeRegistry() {
-               // TODO Auto-generated method stub
-               return null;
+       public final AttributeRegistry getAttributeRegistry() {
+               return providerContext.getAttributeRegistry();
        }
 
        @Override
-       public CapabilityRegistry getCapabilityRegistry() {
-               // TODO Auto-generated method stub
-               return null;
+       public final CapabilityRegistry getCapabilityRegistry() {
+               return providerContext.getCapabilityRegistry();
        }
 
        @Override
-       public MessageRegistry getMessageRegistry() {
-               // TODO Auto-generated method stub
-               return null;
+       public final MessageRegistry getMessageRegistry() {
+               return providerContext.getMessageRegistry();
        }
 
        @Override
-       public NlriRegistry getNlriRegistry() {
-               // TODO Auto-generated method stub
-               return null;
+       public final NlriRegistry getNlriRegistry() {
+               return providerContext.getNlriRegistry();
        }
 
        @Override
-       public ParameterRegistry getParameterRegistry() {
-               // TODO Auto-generated method stub
-               return null;
+       public final ParameterRegistry getParameterRegistry() {
+               return providerContext.getParameterRegistry();
        }
 
        @Override
-       public SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
-               // TODO Auto-generated method stub
-               return null;
+       public final SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
+               return providerContext.getSubsequentAddressFamilyRegistry();
        }
-
 }
index a1c4ed2c870f9635fe5507086b770a5db34c6cf1..6b6f0e7fc2ddaf99967aaebb9dbae70f06e3d22b 100644 (file)
@@ -25,6 +25,7 @@ abstract class AbstractMessageRegistry implements MessageRegistry {
        private final static Logger logger = LoggerFactory.getLogger(AbstractMessageRegistry.class);
 
        protected abstract Notification parseBody(final int type, final byte[] body, final int messageLength) throws BGPDocumentedException;
+
        protected abstract byte[] serializeMessageImpl(final Notification message);
 
        @Override
@@ -36,13 +37,13 @@ abstract class AbstractMessageRegistry implements MessageRegistry {
                        throw new IllegalArgumentException("Too few bytes in passed array. Passed: " + bytes.length + ". Expected: >= "
                                        + MessageUtil.COMMON_HEADER_LENGTH + ".");
                }
-               /*
-                * byte array starts with message length
-                */
-               // final byte[] ones = new byte[MARKER_LENGTH];
-               // Arrays.fill(ones, (byte)0xff);
-               // if (Arrays.equals(bytes, ones))
+               final byte[] marker = ByteArray.subByte(bytes, 0, MessageUtil.MARKER_LENGTH);
+               final byte[] ones = new byte[MessageUtil.MARKER_LENGTH];
+               Arrays.fill(ones, (byte) 0xff);
+               // TODO: possible refactor
+               // if (Arrays.equals(marker, ones)) {
                // throw new BGPDocumentedException("Marker not set to ones.", BGPError.CONNECTION_NOT_SYNC);
+               // }
                final byte[] bs = ByteArray.cutBytes(bytes, MessageUtil.MARKER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(bs, 0, MessageUtil.LENGTH_FIELD_LENGTH));
                final int messageType = UnsignedBytes.toInt(bs[MessageUtil.LENGTH_FIELD_LENGTH]);
diff --git a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/ServiceLoaderBGPExtensionProviderContext.java b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/ServiceLoaderBGPExtensionProviderContext.java
new file mode 100644 (file)
index 0000000..57a8a58
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.parser.spi.pojo;
+
+import java.util.ServiceLoader;
+
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
+
+public final class ServiceLoaderBGPExtensionProviderContext {
+       private ServiceLoaderBGPExtensionProviderContext() {
+
+       }
+
+       public static BGPExtensionConsumerContext createConsumerContext() throws Exception {
+               final BGPExtensionProviderContext ctx = new SimpleBGPExtensionProviderContext();
+
+               final ServiceLoader<BGPExtensionProviderActivator> loader = ServiceLoader.load(BGPExtensionProviderActivator.class);
+               for (BGPExtensionProviderActivator a : loader) {
+                       a.start(ctx);
+               }
+
+               return ctx;
+       }
+}
index a2e896deb76c016a2fc8129faa6444a0d1557815..463f172617731e4bbe5b6001394bb8c97f27ed15 100644 (file)
@@ -8,13 +8,14 @@
 package org.opendaylight.protocol.bgp.parser.spi.pojo;
 
 import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
 
 import com.google.common.base.Preconditions;
 
 final class SimpleAddressFamilyRegistry extends AbstractFamilyRegistry<AddressFamily, Integer> implements AddressFamilyRegistry {
        AutoCloseable registerAddressFamily(final Class<? extends AddressFamily> clazz, final int number) {
-               Preconditions.checkArgument(number >= 0 && number <= 65535);
+               Preconditions.checkArgument(number >= 0 && number <= Util.UNSIGNED_SHORT_MAX_VALUE);
                return super.registerFamily(clazz, number);
        }
 
index f46127c3db3efb38eff97416c08411266fdf2c9a..7fda5a50b1ad0701a3400654f1d59c1483381ad8 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
@@ -27,16 +28,16 @@ final class SimpleAttributeRegistry implements AttributeRegistry {
        private final HandlerRegistry<DataContainer, AttributeParser, AttributeSerializer> handlers = new HandlerRegistry<>();
 
        AutoCloseable registerAttributeParser(final int attributeType, final AttributeParser parser) {
-               Preconditions.checkArgument(attributeType >= 0 && attributeType <= 255);
-               return handlers.registerParser(attributeType, parser);
+               Preconditions.checkArgument(attributeType >= 0 && attributeType <= Util.UNSIGNED_BYTE_MAX_VALUE);
+               return this.handlers.registerParser(attributeType, parser);
        }
 
        AutoCloseable registerAttributeSerializer(final Class<? extends DataObject> paramClass, final AttributeSerializer serializer) {
-               return handlers.registerSerializer(paramClass, serializer);
+               return this.handlers.registerSerializer(paramClass, serializer);
        }
 
-       private int parseAttribute( final byte[] bytes, final int offset, final PathAttributesBuilder builder)
-                       throws BGPDocumentedException, BGPParsingException {
+       private int parseAttribute(final byte[] bytes, final int offset, final PathAttributesBuilder builder) throws BGPDocumentedException,
+                       BGPParsingException {
                // FIXME: validate minimum length
                final boolean[] flags = ByteArray.parseBits(bytes[offset]);
                final int type = UnsignedBytes.toInt(bytes[offset + 1]);
@@ -50,7 +51,7 @@ final class SimpleAttributeRegistry implements AttributeRegistry {
                        hdrlen = 3;
                }
 
-               final AttributeParser parser = handlers.getParser(type);
+               final AttributeParser parser = this.handlers.getParser(type);
                if (parser == null) {
                        if (!flags[0]) {
                                throw new BGPDocumentedException("Well known attribute not recognized.", BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED);
@@ -74,7 +75,7 @@ final class SimpleAttributeRegistry implements AttributeRegistry {
 
        @Override
        public byte[] serializeAttribute(final DataObject attribute) {
-               final AttributeSerializer serializer = handlers.getSerializer(attribute.getImplementedInterface());
+               final AttributeSerializer serializer = this.handlers.getSerializer(attribute.getImplementedInterface());
                if (serializer == null) {
                        return null;
                }
diff --git a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleBGPExtensionConsumerContext.java b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleBGPExtensionConsumerContext.java
new file mode 100644 (file)
index 0000000..5db9db4
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.parser.spi.pojo;
+
+import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
+import org.opendaylight.protocol.bgp.parser.spi.CapabilityRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
+
+class SimpleBGPExtensionConsumerContext implements BGPExtensionConsumerContext {
+       protected final SimpleAddressFamilyRegistry afiReg = new SimpleAddressFamilyRegistry();
+       protected final SimpleAttributeRegistry attrReg = new SimpleAttributeRegistry();
+       protected final SimpleCapabilityRegistry capReg = new SimpleCapabilityRegistry();
+       protected final SimpleMessageRegistry msgReg = new SimpleMessageRegistry();
+       protected final SimpleSubsequentAddressFamilyRegistry safiReg = new SimpleSubsequentAddressFamilyRegistry();
+       protected final SimpleParameterRegistry paramReg = new SimpleParameterRegistry();
+       protected final SimpleNlriRegistry nlriReg = new SimpleNlriRegistry(this.afiReg, this.safiReg);
+
+       @Override
+       public final AddressFamilyRegistry getAddressFamilyRegistry() {
+               return this.afiReg;
+       }
+
+       @Override
+       public final AttributeRegistry getAttributeRegistry() {
+               return this.attrReg;
+       }
+
+       @Override
+       public final CapabilityRegistry getCapabilityRegistry() {
+               return this.capReg;
+       }
+
+       @Override
+       public final MessageRegistry getMessageRegistry() {
+               return this.msgReg;
+       }
+
+       @Override
+       public final NlriRegistry getNlriRegistry() {
+               return this.nlriReg;
+       }
+
+       @Override
+       public final ParameterRegistry getParameterRegistry() {
+               return this.paramReg;
+       }
+
+       @Override
+       public final SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
+               return this.safiReg;
+       }
+}
@@ -7,28 +7,17 @@
  */
 package org.opendaylight.protocol.bgp.parser.spi.pojo;
 
-import java.util.ServiceLoader;
-
-import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
-import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
-import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
-import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator;
 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.parser.spi.CapabilityParser;
-import org.opendaylight.protocol.bgp.parser.spi.CapabilityRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.CapabilitySerializer;
 import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
-import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.MessageSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
-import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.ParameterParser;
-import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.ParameterSerializer;
-import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
@@ -36,61 +25,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.Notification;
 
-public final class BGPExtensionConsumerContextImpl implements BGPExtensionProviderContext {
-       private static final class Holder {
-               private static final BGPExtensionConsumerContext INSTANCE;
-
-               static {
-                       try {
-                               INSTANCE = BGPExtensionConsumerContextImpl.create();
-                       } catch (Exception e) {
-                               throw new ExceptionInInitializerError(e);
-                       }
-               }
-       }
-
-       private final SimpleAddressFamilyRegistry afiReg = new SimpleAddressFamilyRegistry();
-       private final SimpleAttributeRegistry attrReg = new SimpleAttributeRegistry();
-       private final SimpleCapabilityRegistry capReg = new SimpleCapabilityRegistry();
-       private final SimpleMessageRegistry msgReg = new SimpleMessageRegistry();
-       private final SimpleSubsequentAddressFamilyRegistry safiReg = new SimpleSubsequentAddressFamilyRegistry();
-       private final SimpleParameterRegistry paramReg = new SimpleParameterRegistry();
-       private final SimpleNlriRegistry nlriReg = new SimpleNlriRegistry(afiReg, safiReg);
-
-       private BGPExtensionConsumerContextImpl() {
-
-       }
-
-       public static BGPExtensionConsumerContext getSingletonInstance() {
-               return Holder.INSTANCE;
-       }
-
-       public static BGPExtensionConsumerContext create() throws Exception {
-               final BGPExtensionConsumerContextImpl ctx = new BGPExtensionConsumerContextImpl();
-
-               final ServiceLoader<BGPExtensionProviderActivator> loader = ServiceLoader.load(BGPExtensionProviderActivator.class);
-               for (BGPExtensionProviderActivator a : loader) {
-                       a.start(ctx);
-               }
-
-               return ctx;
-       }
-
-       @Override
-       public AddressFamilyRegistry getAddressFamilyRegistry() {
-               return afiReg;
-       }
-
+public final class SimpleBGPExtensionProviderContext extends SimpleBGPExtensionConsumerContext implements BGPExtensionProviderContext {
        @Override
        public AutoCloseable registerAddressFamily(final Class<? extends AddressFamily> clazz, final int number) {
                return afiReg.registerAddressFamily(clazz, number);
        }
 
-       @Override
-       public AttributeRegistry getAttributeRegistry() {
-               return attrReg;
-       }
-
        @Override
        public AutoCloseable registerAttributeParser(final int attributeType, final AttributeParser parser) {
                return attrReg.registerAttributeParser(attributeType, parser);
@@ -101,11 +41,6 @@ public final class BGPExtensionConsumerContextImpl implements BGPExtensionProvid
                return attrReg.registerAttributeSerializer(attributeClass, serializer);
        }
 
-       @Override
-       public CapabilityRegistry getCapabilityRegistry() {
-               return capReg;
-       }
-
        @Override
        public AutoCloseable registerCapabilityParser(final int capabilityType, final CapabilityParser parser) {
                return capReg.registerCapabilityParser(capabilityType, parser);
@@ -116,11 +51,6 @@ public final class BGPExtensionConsumerContextImpl implements BGPExtensionProvid
                return capReg.registerCapabilitySerializer(capabilityClass, serializer);
        }
 
-       @Override
-       public MessageRegistry getMessageRegistry() {
-               return msgReg;
-       }
-
        @Override
        public AutoCloseable registerMessageParser(final int messageType, final MessageParser parser) {
                return msgReg.registerMessageParser(messageType, parser);
@@ -131,11 +61,6 @@ public final class BGPExtensionConsumerContextImpl implements BGPExtensionProvid
                return msgReg.registerMessageSerializer(messageClass, serializer);
        }
 
-       @Override
-       public NlriRegistry getNlriRegistry() {
-               return nlriReg;
-       }
-
        @Override
        public AutoCloseable registerNlriParser(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi,
                        final NlriParser parser) {
@@ -147,11 +72,6 @@ public final class BGPExtensionConsumerContextImpl implements BGPExtensionProvid
                throw new UnsupportedOperationException("NLRI serialization not implemented");
        }
 
-       @Override
-       public ParameterRegistry getParameterRegistry() {
-               return paramReg;
-       }
-
        @Override
        public AutoCloseable registerParameterParser(final int parameterType, final ParameterParser parser) {
                return paramReg.registerParameterParser(parameterType, parser);
@@ -162,11 +82,6 @@ public final class BGPExtensionConsumerContextImpl implements BGPExtensionProvid
                return paramReg.registerParameterSerializer(paramClass, serializer);
        }
 
-       @Override
-       public SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
-               return safiReg;
-       }
-
        @Override
        public AutoCloseable registerSubsequentAddressFamily(final Class<? extends SubsequentAddressFamily> clazz, final int number) {
                return safiReg.registerSubsequentAddressFamily(clazz, number);
index d50dc5900c1fda499472456973fea99145e60876..71c33fcdb8c7447f854d1b7101bca800100562f9 100644 (file)
@@ -13,6 +13,7 @@ import org.opendaylight.protocol.bgp.parser.spi.CapabilityParser;
 import org.opendaylight.protocol.bgp.parser.spi.CapabilityRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.CapabilitySerializer;
 import org.opendaylight.protocol.concepts.HandlerRegistry;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
@@ -22,17 +23,17 @@ final class SimpleCapabilityRegistry implements CapabilityRegistry {
        private final HandlerRegistry<DataContainer, CapabilityParser, CapabilitySerializer> handlers = new HandlerRegistry<>();
 
        AutoCloseable registerCapabilityParser(final int messageType, final CapabilityParser parser) {
-               Preconditions.checkArgument(messageType >= 0 && messageType <= 255);
-               return handlers.registerParser(messageType, parser);
+               Preconditions.checkArgument(messageType >= 0 && messageType <= Util.UNSIGNED_BYTE_MAX_VALUE);
+               return this.handlers.registerParser(messageType, parser);
        }
 
        AutoCloseable registerCapabilitySerializer(final Class<? extends CParameters> paramClass, final CapabilitySerializer serializer) {
-               return handlers.registerSerializer(paramClass, serializer);
+               return this.handlers.registerSerializer(paramClass, serializer);
        }
 
        @Override
        public CParameters parseCapability(final int type, final byte[] bytes) throws BGPDocumentedException, BGPParsingException {
-               final CapabilityParser parser = handlers.getParser(type);
+               final CapabilityParser parser = this.handlers.getParser(type);
                if (parser == null) {
                        return null;
                }
@@ -42,7 +43,7 @@ final class SimpleCapabilityRegistry implements CapabilityRegistry {
 
        @Override
        public byte[] serializeCapability(final CParameters capability) {
-               final CapabilitySerializer serializer = handlers.getSerializer(capability.getImplementedInterface());
+               final CapabilitySerializer serializer = this.handlers.getSerializer(capability.getImplementedInterface());
                if (serializer == null) {
                        return null;
                }
index 57567134323f0f9a7654e0911e715eeed371a53a..9c5e943187cb251982ad747d4976efd801937743 100644 (file)
@@ -13,6 +13,7 @@ import org.opendaylight.protocol.bgp.parser.spi.ParameterParser;
 import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.ParameterSerializer;
 import org.opendaylight.protocol.concepts.HandlerRegistry;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
@@ -22,17 +23,17 @@ final class SimpleParameterRegistry implements ParameterRegistry {
        private final HandlerRegistry<DataContainer, ParameterParser, ParameterSerializer> handlers = new HandlerRegistry<>();
 
        AutoCloseable registerParameterParser(final int messageType, final ParameterParser parser) {
-               Preconditions.checkArgument(messageType >= 0 && messageType <= 255);
-               return handlers.registerParser(messageType, parser);
+               Preconditions.checkArgument(messageType >= 0 && messageType <= Util.UNSIGNED_BYTE_MAX_VALUE);
+               return this.handlers.registerParser(messageType, parser);
        }
 
        AutoCloseable registerParameterSerializer(final Class<? extends BgpParameters> paramClass, final ParameterSerializer serializer) {
-               return handlers.registerSerializer(paramClass, serializer);
+               return this.handlers.registerSerializer(paramClass, serializer);
        }
 
        @Override
        public BgpParameters parseParameter(final int parameterType, final byte[] bytes) throws BGPParsingException, BGPDocumentedException {
-               final ParameterParser parser = handlers.getParser(parameterType);
+               final ParameterParser parser = this.handlers.getParser(parameterType);
                if (parser == null) {
                        return null;
                }
@@ -42,7 +43,7 @@ final class SimpleParameterRegistry implements ParameterRegistry {
 
        @Override
        public byte[] serializeParameter(final BgpParameters parameter) {
-               final ParameterSerializer serializer = handlers.getSerializer(parameter.getImplementedInterface());
+               final ParameterSerializer serializer = this.handlers.getSerializer(parameter.getImplementedInterface());
                if (serializer == null) {
                        return null;
                }
index 2c88c22d34045557913143f175b38445ac9ef2ba..b8ce1b81434cea47f557918c3d1d4bdabb2c98e2 100644 (file)
@@ -8,13 +8,15 @@
 package org.opendaylight.protocol.bgp.parser.spi.pojo;
 
 import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
 
 import com.google.common.base.Preconditions;
 
-final class SimpleSubsequentAddressFamilyRegistry extends AbstractFamilyRegistry<SubsequentAddressFamily, Integer> implements SubsequentAddressFamilyRegistry {
+final class SimpleSubsequentAddressFamilyRegistry extends AbstractFamilyRegistry<SubsequentAddressFamily, Integer> implements
+               SubsequentAddressFamilyRegistry {
        AutoCloseable registerSubsequentAddressFamily(final Class<? extends SubsequentAddressFamily> clazz, final int number) {
-               Preconditions.checkArgument(number >= 0 && number <= 255);
+               Preconditions.checkArgument(number >= 0 && number <= Util.UNSIGNED_BYTE_MAX_VALUE);
                return super.registerFamily(clazz, number);
        }
 
diff --git a/bgp/parser-spi/src/test/java/org/opendaylight/protocol/bgp/parser/spi/UtilsTest.java b/bgp/parser-spi/src/test/java/org/opendaylight/protocol/bgp/parser/spi/UtilsTest.java
new file mode 100644 (file)
index 0000000..fe5974f
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.parser.spi;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHop;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHop;
+
+import com.google.common.primitives.UnsignedBytes;
+
+public class UtilsTest {
+
+       @Test
+       public void testCapabilityUtil() {
+               final byte[] result = new byte[] { 1, 2, 4, 8 };
+               assertArrayEquals(result, CapabilityUtil.formatCapability(1, new byte[] { 4, 8 }));
+       }
+
+       @Test
+       public void testMessageUtil() {
+               final byte[] result = new byte[] { UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE,
+                               UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE,
+                               UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE,
+                               UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE, UnsignedBytes.MAX_VALUE,
+                               UnsignedBytes.MAX_VALUE, 0, 23, 3, 32, 5, 14, 21 };
+               assertArrayEquals(result, MessageUtil.formatMessage(3, new byte[] { 32, 5, 14, 21 }));
+       }
+
+       @Test
+       public void testNlriUtil() {
+               final MpReachNlriBuilder builder = new MpReachNlriBuilder();
+               final byte[] ipv4 = new byte[] { 42, 42, 42, 42 };
+               try {
+                       NlriUtil.parseNextHop(ipv4, builder);
+               } catch (final BGPParsingException e) {
+                       fail("This exception should not happen");
+               }
+               CNextHop hop = builder.getCNextHop();
+               assertEquals("42.42.42.42", ((CIpv4NextHop) hop).getIpv4NextHop().getGlobal().getValue());
+
+               final byte[] ipv6 = new byte[] { (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 01 };
+               try {
+                       NlriUtil.parseNextHop(ipv6, builder);
+               } catch (final BGPParsingException e) {
+                       fail("This exception should not happen");
+               }
+               hop = builder.getCNextHop();
+               assertEquals("2001:db8::1", ((CIpv6NextHop) hop).getIpv6NextHop().getGlobal().getValue());
+               assertNull(((CIpv6NextHop) hop).getIpv6NextHop().getLinkLocal());
+
+               final byte[] ipv6l = new byte[] { (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00,
+                               01, (byte) 0xfe, (byte) 0x80, 00, 00, 00, 00, 00, 00, (byte) 0xc0, 01, 0x0b, (byte) 0xff, (byte) 0xfe, 0x7e, 00, 00 };
+               try {
+                       NlriUtil.parseNextHop(ipv6l, builder);
+               } catch (final BGPParsingException e) {
+                       fail("This exception should not happen");
+               }
+               hop = builder.getCNextHop();
+               assertEquals("2001:db8::1", ((CIpv6NextHop) hop).getIpv6NextHop().getGlobal().getValue());
+               assertEquals("fe80::c001:bff:fe7e:0", ((CIpv6NextHop) hop).getIpv6NextHop().getLinkLocal().getValue());
+
+               final byte[] wrong = new byte[] { (byte) 0x20, (byte) 0x01, (byte) 0x0d };
+               try {
+                       NlriUtil.parseNextHop(wrong, builder);
+                       fail("Exception should happen");
+               } catch (final BGPParsingException e) {
+                       assertEquals("Cannot parse NEXT_HOP attribute. Wrong bytes length: 3", e.getMessage());
+               }
+       }
+
+       @Test
+       public void testParameterUtil() {
+               final byte[] result = new byte[] { 1, 2, 4, 8 };
+               assertArrayEquals(result, ParameterUtil.formatParameter(1, new byte[] { 4, 8 }));
+       }
+}
index ac3b83181a8e8329e3babebae4e29b64c6aed87f..bd26e87db92be44ad44a39121a441b95af514aa0 100644 (file)
@@ -3,7 +3,6 @@ module bgp-rib {
         namespace "urn:opendaylight:params:xml:ns:yang:bgp-rib";
         prefix "rib";
 
-       import bgp-types { prefix bgp-t; revision-date 2013-09-19; }
        import bgp-message { prefix bgp-msg; revision-date 2013-09-18; }
        import bgp-multiprotocol { prefix bgp-mp; revision-date 2013-09-18; }
        import ietf-inet-types { prefix inet; revision-date 2010-09-24; }
@@ -45,44 +44,26 @@ module bgp-rib {
                        }
 
                        choice routes {
-                               list ipv4-routes {
-                                       when "../../afi = ipv4";
+                               case ipv4-routes {
+                                       list ipv4-routes {
+                                               when "../../afi = ipv4";
 
-                                       leaf prefix {
-                                               type inet:ipv4-prefix;
-                                       }
-                                       key prefix;
-
-                                       uses route;
-                               }
-                               list ipv6-routes {
-                                       when "../../afi = ipv6";
-
-                                       leaf prefix {
-                                               type inet:ipv6-prefix;
-                                       }
-                                       key prefix;
-
-                                       uses route;
-                               }
-                               case linkstate-routes {
-                                       list linkstate-links {
-                                               // FIXME: fill this out
+                                               leaf prefix {
+                                                       type inet:ipv4-prefix;
+                                               }
+                                               key prefix;
 
                                                uses route;
                                        }
-                                       list linkstate-nodes {
-                                               // FIXME: fill this out
-
-                                               uses route;
-                                       }
-                                       list linkstate-ipv4-prefixes {
-                                               // FIXME: fill this out
-
-                                               uses route;
-                                       }
-                                       list linkstate-ipv6-prefixes {
-                                               // FIXME: fill this out
+                               }
+                               case ipv6-routes {
+                                       list ipv6-routes {
+                                               when "../../afi = ipv6";
+
+                                               leaf prefix {
+                                                       type inet:ipv6-prefix;
+                                               }
+                                               key prefix;
 
                                                uses route;
                                        }
index 3c87f8ed5bc9402b5f9bd3b58acb0e7825d00de1..c62c9172ca99344ccf49797eddff0c05b6b629c5 100644 (file)
@@ -1,16 +1,15 @@
 package org.opendaylight.protocol.bgp.rib.impl;
 
 import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
 
 public final class Activator extends AbstractBindingAwareProvider {
+       @SuppressWarnings("unused")
        private RIBImpl rib;
 
-
        @Override
        public void onSessionInitiated(final ProviderContext session) {
-               rib = new RIBImpl(session.getSALService(DataProviderService.class));
+               this.rib = new RIBImpl(session.getSALService(DataProviderService.class));
        }
 }
index d574fcdb1b53a800b092579ff36e8e04e48736bd..81df32f3386920dc0114fe25c2095217e81c099a 100644 (file)
@@ -21,6 +21,7 @@ import org.opendaylight.protocol.concepts.AbstractRegistration;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateDestination;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestination;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.PathAttributes;
@@ -53,8 +54,7 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
                }
 
                @Override
-               public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath,
-                               final Ipv4Prefix key) {
+               public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath, final Ipv4Prefix key) {
                        final InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(basePath);
 
                        builder.node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.routes.Ipv4Routes.class);
@@ -65,7 +65,7 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
 
                @Override
                public void addRoutes(
-                               final DataModificationTransaction   trans,
+                               final DataModificationTransaction trans,
                                final Peer peer,
                                final MpReachNlri nlri,
                                final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes attributes) {
@@ -77,15 +77,14 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
                                }
                        };
 
-                       for (Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4)nlri.getAdvertizedRoutes().getDestinationType()).getIpv4Prefixes()) {
+                       for (final Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4) nlri.getAdvertizedRoutes().getDestinationType()).getIpv4Prefixes()) {
                                super.add(trans, peer, id, data);
                        }
                }
 
                @Override
-               public void removeRoutes(final DataModificationTransaction   trans, final Peer peer,
-                               final MpUnreachNlri nlri) {
-                       for (Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4)nlri.getWithdrawnRoutes().getDestinationType()).getIpv4Prefixes()) {
+               public void removeRoutes(final DataModificationTransaction trans, final Peer peer, final MpUnreachNlri nlri) {
+                       for (final Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4) nlri.getWithdrawnRoutes().getDestinationType()).getIpv4Prefixes()) {
                                super.remove(trans, peer, id);
                        }
                }
@@ -97,8 +96,7 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
                }
 
                @Override
-               public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath,
-                               final Ipv6Prefix key) {
+               public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath, final Ipv6Prefix key) {
                        final InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(basePath);
 
                        builder.node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.routes.Ipv6Routes.class);
@@ -109,7 +107,7 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
 
                @Override
                public void addRoutes(
-                               final DataModificationTransaction   trans,
+                               final DataModificationTransaction trans,
                                final Peer peer,
                                final MpReachNlri nlri,
                                final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes attributes) {
@@ -121,15 +119,14 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
                                }
                        };
 
-                       for (Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6)nlri.getAdvertizedRoutes().getDestinationType()).getIpv6Prefixes()) {
+                       for (final Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6) nlri.getAdvertizedRoutes().getDestinationType()).getIpv6Prefixes()) {
                                super.add(trans, peer, id, data);
                        }
                }
 
                @Override
-               public void removeRoutes(final DataModificationTransaction   trans, final Peer peer,
-                               final MpUnreachNlri nlri) {
-                       for (Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6)nlri.getWithdrawnRoutes().getDestinationType()).getIpv6Prefixes()) {
+               public void removeRoutes(final DataModificationTransaction trans, final Peer peer, final MpUnreachNlri nlri) {
+                       for (final Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6) nlri.getWithdrawnRoutes().getDestinationType()).getIpv6Prefixes()) {
                                super.remove(trans, peer, id);
                        }
                }
@@ -141,8 +138,7 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
                }
 
                @Override
-               public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath,
-                               final CLinkstateDestination key) {
+               public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath, final CLinkstateDestination key) {
                        final InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(basePath);
 
                        switch (key.getNlriType()) {
@@ -165,13 +161,11 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
 
                @Override
                public void addRoutes(
-                               final DataModificationTransaction   trans,
+                               final DataModificationTransaction trans,
                                final Peer peer,
                                final MpReachNlri nlri,
                                final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes attributes) {
-                       final CLinkstateDestination key =
-                                       ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.
-                                                       update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstate) nlri.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
+                       final CLinkstateDestination key = (CLinkstateDestination) ((LinkstateDestination) nlri.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
 
                        RIBEntryData data = null;
                        switch (key.getNlriType()) {
@@ -220,11 +214,8 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
                }
 
                @Override
-               public void removeRoutes(final DataModificationTransaction   trans, final Peer peer,
-                               final MpUnreachNlri nlri) {
-                       final CLinkstateDestination key =
-                                       ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.
-                                                       update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstate) nlri.getWithdrawnRoutes().getDestinationType()).getCLinkstateDestination();
+               public void removeRoutes(final DataModificationTransaction trans, final Peer peer, final MpUnreachNlri nlri) {
+                       final CLinkstateDestination key = (CLinkstateDestination) ((LinkstateDestination) nlri.getWithdrawnRoutes().getDestinationType()).getCLinkstateDestination();
 
                        super.remove(trans, peer, key);
                }
@@ -233,22 +224,19 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
        static {
                final AdjRIBsInFactoryRegistry reg = new AdjRIBsInFactoryRegistryImpl();
 
-               reg.registerAdjRIBsInFactory(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
-                               new AdjRIBsInFactory() {
+               reg.registerAdjRIBsInFactory(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new AdjRIBsInFactory() {
                        @Override
                        public AdjRIBsIn createAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
                                return new Ipv4AdjRIBsIn(comparator, key);
                        }
                });
-               reg.registerAdjRIBsInFactory(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class,
-                               new AdjRIBsInFactory() {
+               reg.registerAdjRIBsInFactory(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new AdjRIBsInFactory() {
                        @Override
                        public AdjRIBsIn createAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
                                return new Ipv6AdjRIBsIn(comparator, key);
                        }
                });
-               reg.registerAdjRIBsInFactory(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class,
-                               new AdjRIBsInFactory() {
+               reg.registerAdjRIBsInFactory(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class, new AdjRIBsInFactory() {
                        @Override
                        public AdjRIBsIn createAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
                                return new LinkstateAdjRIBsIn(comparator, key);
@@ -267,25 +255,26 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
                        final Class<? extends SubsequentAddressFamily> safi, final AdjRIBsInFactory factory) {
                final TablesKey key = new TablesKey(afi, safi);
 
-               if (factories.containsKey(key)) {
+               if (this.factories.containsKey(key)) {
                        throw new RuntimeException("Specified AFI/SAFI combination is already registered");
                }
 
-               factories.put(key, factory);
+               this.factories.put(key, factory);
 
                final Object lock = this;
                return new AbstractRegistration() {
                        @Override
                        protected void removeRegistration() {
                                synchronized (lock) {
-                                       factories.remove(key);
+                                       AdjRIBsInFactoryRegistryImpl.this.factories.remove(key);
                                }
                        }
                };
        }
 
        @Override
-       public synchronized AdjRIBsInFactory getAdjRIBsInFactory(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
-               return factories.get(new TablesKey(afi, safi));
+       public synchronized AdjRIBsInFactory getAdjRIBsInFactory(final Class<? extends AddressFamily> afi,
+                       final Class<? extends SubsequentAddressFamily> safi) {
+               return this.factories.get(new TablesKey(afi, safi));
        }
 }
index e4144ba9ef308f6955958d7b8d3e5a2dc66913fb..e71b445bce8fdca0aaeb88bb48a7e00066ea406a 100644 (file)
@@ -14,12 +14,14 @@ import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
  */
 public final class BGPMessageHeaderDecoder extends LengthFieldBasedFrameDecoder {
 
-       private static final int MAX_FRAME_SIZE = 4096; // min 19, max 4096
+       private static final int MAX_FRAME_SIZE = 4096;
 
        private static final int MARKER_SIZE = 16;
 
-       private static final int LENGTH_SIZE = 2; // the length field represents the length of the whole message including
-                                                                                               // the header
+       /*
+        * the length field represents the length of the whole message including the header
+        */
+       private static final int LENGTH_SIZE = 2;
 
        /*
                
@@ -27,11 +29,11 @@ public final class BGPMessageHeaderDecoder extends LengthFieldBasedFrameDecoder
          0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
          |                                                               |
-         +                                                               +
          |                                                               |
-         +                                                               +
+         |                                                               |
+         |                                                               |
          |                           Marker                              |
-         +                                                               +
+         |                                                               |
          |                                                               |
          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
          |          Length               |      Type     |
index 33fcf0e2614027168ce5258a6aa736ec7f12be38..767009bfecb2214597a3addf4d4e8f0c3dd727cf 100644 (file)
@@ -11,7 +11,6 @@ import java.util.Comparator;
 
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.PathAttributes;
 
-
 /**
  * This comparator is intended to implement BGP Best Path Selection algorithm, as described at
  * 
@@ -27,15 +26,15 @@ final class BGPObjectComparator implements Comparator<PathAttributes> {
 
        @Override
        public int compare(final PathAttributes o1, final PathAttributes o2) {
-               if (o1 == o2) {
-                       return 0;
-               }
                if (o1 == null) {
                        return 1;
                }
                if (o2 == null) {
                        return -1;
                }
+               if (o1.equals(o2)) {
+                       return 0;
+               }
 
                // FIXME: look at ASPath
                // FIXME: look at everything else :-)
index 42a8db6d4a906867b7f30f79db785cb00229c19a..10d3ab5965f94a012f361e6a2b29999d7ffea072 100644 (file)
@@ -42,7 +42,7 @@ public final class BGPPeer implements BGPSessionListener, Peer {
        @Override
        public void onMessage(final BGPSession session, final Notification message) {
                if (message instanceof Update) {
-                       this.rib.updateTables(this, (Update)message);
+                       this.rib.updateTables(this, (Update) message);
                } else {
                        logger.info("Ignoring unhandled message class " + message.getClass());
                }
@@ -52,8 +52,8 @@ public final class BGPPeer implements BGPSessionListener, Peer {
        public void onSessionUp(final BGPSession session) {
                logger.info("Session with peer {} went up with tables: {}", this.name, session.getAdvertisedTableTypes());
 
-               for (BgpTableType t : session.getAdvertisedTableTypes()) {
-                       tables.add(new TablesKey(t.getAfi(), t.getSafi()));
+               for (final BgpTableType t : session.getAdvertisedTableTypes()) {
+                       this.tables.add(new TablesKey(t.getAfi(), t.getSafi()));
                }
        }
 
@@ -64,7 +64,7 @@ public final class BGPPeer implements BGPSessionListener, Peer {
                        this.rib.clearTable(this, key);
                }
 
-               tables.clear();
+               this.tables.clear();
        }
 
        @Override
@@ -73,7 +73,7 @@ public final class BGPPeer implements BGPSessionListener, Peer {
        }
 
        @Override
-       public final String toString() {
+       public String toString() {
                return addToStringAttributes(Objects.toStringHelper(this)).toString();
        }
 
index 4824a52c09fa4d970bf51729d30abc18911c0b4a..032cea380d7856c8d2ff310f5fefacb9439e4c5e 100644 (file)
@@ -34,6 +34,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,11 +50,14 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
 
        private static final Logger logger = LoggerFactory.getLogger(BGPSessionImpl.class);
 
+       /*
+        * 240
+        */
        private static final int DEFAULT_HOLD_TIMER_VALUE = 15;
 
        private static final Notification keepalive = new KeepaliveBuilder().build();
 
-       public static int HOLD_TIMER_VALUE = DEFAULT_HOLD_TIMER_VALUE; // 240
+       private static int holdTimerValue = DEFAULT_HOLD_TIMER_VALUE;
 
        /**
         * Internal session state.
@@ -78,6 +82,7 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
        /**
         * System.nanoTime value about when was sent the last message Protected to be updated also in tests.
         */
+       @VisibleForTesting
        protected long lastMessageSentAt;
 
        /**
@@ -110,20 +115,23 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
                this.stateTimer = Preconditions.checkNotNull(timer);
                this.channel = Preconditions.checkNotNull(channel);
                this.keepAlive = remoteOpen.getHoldTimer() / 3;
+               holdTimerValue = remoteOpen.getHoldTimer();
 
-               final Set<BgpTableType> tts = Sets.newHashSet();
+               final Set<TablesKey> tts = Sets.newHashSet();
+               final Set<BgpTableType> tats = Sets.newHashSet();
                if (remoteOpen.getBgpParameters() != null) {
                        for (final BgpParameters param : remoteOpen.getBgpParameters()) {
                                if (param instanceof CParameters) {
                                        final CParameters cp = (CParameters) param;
-                                       final BgpTableType tt = new BgpTableTypeImpl(((CMultiprotocol) cp).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) cp).getMultiprotocolCapability().getSafi());
+                                       final TablesKey tt = new TablesKey(((CMultiprotocol) cp).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) cp).getMultiprotocolCapability().getSafi());
                                        tts.add(tt);
+                                       tats.add(new BgpTableTypeImpl(tt.getAfi(), tt.getSafi()));
                                }
                        }
                }
 
                this.sync = new BGPSynchronization(this, this.listener, tts);
-               this.tableTypes = tts;
+               this.tableTypes = tats;
 
                if (remoteOpen.getHoldTimer() != 0) {
                        this.stateTimer.newTimeout(new TimerTask() {
@@ -234,7 +242,7 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
                }
 
                final long ct = System.nanoTime();
-               final long nextHold = this.lastMessageReceivedAt + TimeUnit.SECONDS.toNanos(HOLD_TIMER_VALUE);
+               final long nextHold = this.lastMessageReceivedAt + TimeUnit.SECONDS.toNanos(holdTimerValue);
 
                if (ct >= nextHold) {
                        logger.debug("HoldTimer expired. " + new Date());
@@ -276,7 +284,7 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
        }
 
        @Override
-       final public String toString() {
+       public final String toString() {
                return addToStringAttributes(Objects.toStringHelper(this)).toString();
        }
 
index c837d15a25b0f22a400b7f1d1f35d4d0bc88b369..e536ba54f7e18157fc43767ae62a982063c34681 100644 (file)
@@ -119,9 +119,9 @@ public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notifi
                switch (this.state) {
                case Finished:
                case Idle:
-                       final Notify fsm_error = new NotifyBuilder().setErrorCode(BGPError.FSM_ERROR.getCode()).setErrorSubcode(
+                       final Notify fsmError = new NotifyBuilder().setErrorCode(BGPError.FSM_ERROR.getCode()).setErrorSubcode(
                                        BGPError.FSM_ERROR.getSubcode()).build();
-                       this.channel.writeAndFlush(fsm_error);
+                       this.channel.writeAndFlush(fsmError);
                case OpenConfirm:
                        if (msg instanceof Keepalive) {
                                negotiationSuccessful(this.session);
@@ -134,30 +134,7 @@ public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notifi
                case OpenSent:
                        if (msg instanceof Open) {
                                final Open openObj = (Open) msg;
-
-                               final List<BgpParameters> prefs = openObj.getBgpParameters();
-                               if (prefs != null && !prefs.isEmpty()) {
-                                       for (final BgpParameters param : openObj.getBgpParameters()) {
-                                               final CParameters cap = param.getCParameters();
-                                               if (cap instanceof CMultiprotocol) {
-                                                       if (((CMultiprotocol) cap).getMultiprotocolCapability().getAfi() == LinkstateAddressFamily.class
-                                                                       && ((CMultiprotocol) cap).getMultiprotocolCapability().getSafi() == LinkstateSubsequentAddressFamily.class) {
-                                                               this.remotePref = openObj;
-                                                               this.channel.writeAndFlush(new KeepaliveBuilder().build());
-                                                               this.session = new BGPSessionImpl(this.timer, this.listener, this.channel, this.remotePref);
-                                                               this.state = State.OpenConfirm;
-                                                               logger.debug("Channel {} moved to OpenConfirm state with remote proposal {}", this.channel, this.remotePref);
-                                                               return;
-                                                       }
-                                               }
-                                       }
-                               }
-                               final Notify ntf = new NotifyBuilder().setErrorCode(BGPError.UNSPECIFIC_OPEN_ERROR.getCode()).setErrorSubcode(
-                                               BGPError.UNSPECIFIC_OPEN_ERROR.getSubcode()).build();
-                               this.channel.writeAndFlush(ntf);
-                               negotiationFailed(new BGPDocumentedException("Linkstate capability is not configured on router. Check the configuration of BGP speaker.", BGPError.forValue(
-                                               ntf.getErrorCode(), ntf.getErrorSubcode())));
-                               this.state = State.Finished;
+                               handleOpen(openObj);
                                return;
                        }
                        break;
@@ -171,6 +148,31 @@ public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notifi
                this.state = State.Finished;
        }
 
+       private void handleOpen(final Open openObj) {
+               final List<BgpParameters> prefs = openObj.getBgpParameters();
+               if (prefs != null && !prefs.isEmpty()) {
+                       for (final BgpParameters param : openObj.getBgpParameters()) {
+                               final CParameters cap = param.getCParameters();
+                               if (cap instanceof CMultiprotocol
+                                               && ((CMultiprotocol) cap).getMultiprotocolCapability().getAfi() == LinkstateAddressFamily.class
+                                               && ((CMultiprotocol) cap).getMultiprotocolCapability().getSafi() == LinkstateSubsequentAddressFamily.class) {
+                                       this.remotePref = openObj;
+                                       this.channel.writeAndFlush(new KeepaliveBuilder().build());
+                                       this.session = new BGPSessionImpl(this.timer, this.listener, this.channel, this.remotePref);
+                                       this.state = State.OpenConfirm;
+                                       logger.debug("Channel {} moved to OpenConfirm state with remote proposal {}", this.channel, this.remotePref);
+                                       return;
+                               }
+                       }
+               }
+               final Notify ntf = new NotifyBuilder().setErrorCode(BGPError.UNSPECIFIC_OPEN_ERROR.getCode()).setErrorSubcode(
+                               BGPError.UNSPECIFIC_OPEN_ERROR.getSubcode()).build();
+               this.channel.writeAndFlush(ntf);
+               negotiationFailed(new BGPDocumentedException("Linkstate capability is not configured on router. Check the configuration of BGP speaker.", BGPError.forValue(
+                               ntf.getErrorCode(), ntf.getErrorSubcode())));
+               this.state = State.Finished;
+       }
+
        public synchronized State getState() {
                return this.state;
        }
index ca1a8ff513c3c864d48d3b2b5efdde06b1c6954f..1b9fbd4677b85b6b15e6f7e825ea29dd8f3a4aba 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParametersBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.CAs4BytesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.c.as4.bytes.As4BytesCapabilityBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocolBuilder;
@@ -44,16 +45,15 @@ public final class BGPSessionProposalImpl implements BGPSessionProposal {
                this.bgpId = bgpId;
 
                final List<BgpParameters> tlvs = Lists.newArrayList();
-               tlvs.add((BgpParameters) new CMultiprotocolBuilder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(
-                               Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build()));
-               tlvs.add((BgpParameters) new CMultiprotocolBuilder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(
-                               LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class).build()));
-               // final Map<BGPTableType, Boolean> tableTypes = Maps.newHashMap();
-               // tableTypes.put(ipv4, true);
-               // tableTypes.put(linkstate,true);
-               // tlvs.add(new GracefulCapability(true, 0, tableTypes));
-               tlvs.add((BgpParameters) new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(
-                               new AsNumber((long) as)).build()));
+               tlvs.add(new BgpParametersBuilder().setCParameters(
+                               new CMultiprotocolBuilder().setMultiprotocolCapability(
+                                               new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build()).build()).build());
+               tlvs.add(new BgpParametersBuilder().setCParameters(
+                               new CMultiprotocolBuilder().setMultiprotocolCapability(
+                                               new MultiprotocolCapabilityBuilder().setAfi(LinkstateAddressFamily.class).setSafi(
+                                                               LinkstateSubsequentAddressFamily.class).build()).build()).build());
+               tlvs.add(new BgpParametersBuilder().setCParameters(
+                               new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber((long) as)).build()).build()).build());
                this.prefs = new BGPSessionPreferences(as, holdTimer, bgpId, tlvs);
        }
 
index 65d6676db60d372bfdba5e588b365c58148de6e1..b372c2f85ce4e035443b4a053f659e9d07d234a0 100644 (file)
@@ -16,7 +16,6 @@ import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.UpdateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2;
@@ -61,17 +60,17 @@ public class BGPSynchronization {
                }
        }
 
-       private final Map<BgpTableType, SyncVariables> syncStorage = Maps.newHashMap();
+       private final Map<TablesKey, SyncVariables> syncStorage = Maps.newHashMap();
 
        private final BGPSessionListener listener;
 
        private final BGPSession session;
 
-       public BGPSynchronization(final BGPSession bgpSession, final BGPSessionListener listener, final Set<BgpTableType> types) {
+       public BGPSynchronization(final BGPSession bgpSession, final BGPSessionListener listener, final Set<TablesKey> types) {
                this.listener = Preconditions.checkNotNull(listener);
                this.session = Preconditions.checkNotNull(bgpSession);
 
-               for (final BgpTableType type : types) {
+               for (final TablesKey type : types) {
                        this.syncStorage.put(type, new SyncVariables());
                }
        }
@@ -89,12 +88,12 @@ public class BGPSynchronization {
                if (msg.getNlri() != null || msg.getWithdrawnRoutes() != null) {
                        type = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
                } else if (msg.getPathAttributes().getAugmentation(PathAttributes1.class) != null) {
-                       PathAttributes1 pa = msg.getPathAttributes().getAugmentation(PathAttributes1.class);
+                       final PathAttributes1 pa = msg.getPathAttributes().getAugmentation(PathAttributes1.class);
                        if (pa.getMpReachNlri() != null) {
                                type = new TablesKey(pa.getMpReachNlri().getAfi(), pa.getMpReachNlri().getSafi());
                        }
                } else if (msg.getPathAttributes().getAugmentation(PathAttributes2.class) != null) {
-                       PathAttributes2 pa = msg.getPathAttributes().getAugmentation(PathAttributes2.class);
+                       final PathAttributes2 pa = msg.getPathAttributes().getAugmentation(PathAttributes2.class);
                        if (pa.getMpUnreachNlri() != null) {
                                type = new TablesKey(pa.getMpUnreachNlri().getAfi(), pa.getMpUnreachNlri().getSafi());
                        }
@@ -113,7 +112,7 @@ public class BGPSynchronization {
         * session.
         */
        public void kaReceived() {
-               for (final Entry<BgpTableType, SyncVariables> entry : this.syncStorage.entrySet()) {
+               for (final Entry<TablesKey, SyncVariables> entry : this.syncStorage.entrySet()) {
                        final SyncVariables s = entry.getValue();
                        if (!s.getEor()) {
                                if (!s.getUpd()) {
@@ -127,10 +126,14 @@ public class BGPSynchronization {
                }
        }
 
-       private Update generateEOR(final BgpTableType type) {
+       private Update generateEOR(final TablesKey type) {
                if (type.getAfi().equals(Ipv4AddressFamily.class) && type.getSafi().equals(UnicastSubsequentAddressFamily.class)) {
                        return new UpdateBuilder().build();
                }
-               return new UpdateBuilder().setPathAttributes(new PathAttributesBuilder().addAugmentation(PathAttributes1.class, new PathAttributes1Builder().setMpReachNlri(new MpReachNlriBuilder().setAfi(type.getAfi()).setSafi(type.getSafi()).build()).build()).build()).build();
+               return new UpdateBuilder().setPathAttributes(
+                               new PathAttributesBuilder().addAugmentation(
+                                               PathAttributes1.class,
+                                               new PathAttributes1Builder().setMpReachNlri(
+                                                               new MpReachNlriBuilder().setAfi(type.getAfi()).setSafi(type.getSafi()).build()).build()).build()).build();
        }
 }
index b06b2a0045f1ae8f80e1f0006c417399845fbebf..b3e754d9ad1458de73b40d67998fcf96389d33fe 100644 (file)
@@ -11,8 +11,6 @@ import java.util.concurrent.Future;
 
 import javax.annotation.concurrent.ThreadSafe;
 
-
-
 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
@@ -44,19 +42,19 @@ final class RIBImpl {
        }
 
        synchronized void updateTables(final BGPPeer peer, final Update message) {
-               final DataModificationTransaction trans = dps.beginTransaction();
+               final DataModificationTransaction trans = this.dps.beginTransaction();
 
                // FIXME: detect and handle end-of-RIB markers
 
-               //remove(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
-               //              trans, peer, message.getWithdrawnRoutes().getWithdrawnRoutes().iterator());
+               // remove(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
+               // trans, peer, message.getWithdrawnRoutes().getWithdrawnRoutes().iterator());
 
                final PathAttributes attrs = message.getPathAttributes();
                final PathAttributes2 mpu = attrs.getAugmentation(PathAttributes2.class);
                if (mpu != null) {
                        final MpUnreachNlri nlri = mpu.getMpUnreachNlri();
 
-                       AdjRIBsIn ari = tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
+                       final AdjRIBsIn ari = this.tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
                        if (ari != null) {
                                ari.removeRoutes(trans, peer, nlri);
                        } else {
@@ -64,14 +62,14 @@ final class RIBImpl {
                        }
                }
 
-               //add(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
-               //              trans, peer, message.getNlri().getNlri().iterator(), attrs);
+               // add(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
+               // trans, peer, message.getNlri().getNlri().iterator(), attrs);
 
                final PathAttributes1 mpr = message.getPathAttributes().getAugmentation(PathAttributes1.class);
                if (mpr != null) {
                        final MpReachNlri nlri = mpr.getMpReachNlri();
 
-                       final AdjRIBsIn ari = tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
+                       final AdjRIBsIn ari = this.tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
                        if (ari != null) {
                                ari.addRoutes(trans, peer, nlri, attrs);
                        } else {
@@ -80,22 +78,22 @@ final class RIBImpl {
                }
 
                // FIXME: we need to attach to this future for failures
-               Future<RpcResult<TransactionStatus>> f = trans.commit();
+               final Future<RpcResult<TransactionStatus>> f = trans.commit();
        }
 
        synchronized void clearTable(final BGPPeer peer, final TablesKey key) {
-               final AdjRIBsIn ari = tables.get(key);
+               final AdjRIBsIn ari = this.tables.get(key);
                if (ari != null) {
-                       final DataModificationTransaction trans = dps.beginTransaction();
+                       final DataModificationTransaction trans = this.dps.beginTransaction();
                        ari.clear(trans, peer);
 
                        // FIXME: we need to attach to this future for failures
-                       Future<RpcResult<TransactionStatus>> f = trans.commit();
+                       final Future<RpcResult<TransactionStatus>> f = trans.commit();
                }
        }
 
        @Override
-       public final String toString() {
+       public String toString() {
                return addToStringAttributes(Objects.toStringHelper(this)).toString();
        }
 
index 99a6fb68e03b947a4f3051b14d99a3e716744a5d..17e6b3fde757510c244d013bba66b7c6f92f0d5b 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.bgp.rib.impl.spi;
 
 import io.netty.util.concurrent.Future;
 
-import java.io.IOException;
 import java.net.InetSocketAddress;
 
 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
@@ -27,7 +26,7 @@ public interface BGPDispatcher {
         * @param connection attributes required for connection
         * @param parser BGP message parser
         * @return client session
-        * @throws IOException
         */
-       Future<BGPSessionImpl> createClient(InetSocketAddress address, BGPSessionPreferences preferences, BGPSessionListener listener, final ReconnectStrategy strategy);
+       Future<BGPSessionImpl> createClient(InetSocketAddress address, BGPSessionPreferences preferences, BGPSessionListener listener,
+                       final ReconnectStrategy strategy);
 }
index aff25f329b9244730c7b591fb11947c94f48c0a8..3a0331866d1214afcb15d349b83979d0995e6b77 100644 (file)
@@ -8,24 +8,33 @@
 package org.opendaylight.protocol.bgp.rib.impl;
 
 import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
 
-import java.util.Collections;
 import java.util.Set;
 
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BGPSession;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.UpdateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.NlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpUnreachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 
+import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 
 public class SynchronizationTest {
@@ -43,15 +52,29 @@ public class SynchronizationTest {
        @Before
        public void setUp() {
                this.listener = new SimpleSessionListener();
-//             final BGPIPv4RouteImpl i4 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("1.1.1.1/32"), new BaseBGPObjectState(null, null), null);
-//             this.ipv4m = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(i4), Collections.EMPTY_SET);
-//             final BGPIPv6RouteImpl i6 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("::1/32"), new BaseBGPObjectState(null, null), null);
-//             this.ipv6m = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(i6), Collections.EMPTY_SET);
-//             this.lsm = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(mock(BGPLink.class)), Collections.EMPTY_SET);
+               this.ipv4m = new UpdateBuilder().setNlri(new NlriBuilder().setNlri(Lists.newArrayList(new Ipv4Prefix("1.1.1.1/32"))).build()).build();
 
-               final Set<BgpTableType> types = Sets.newHashSet();
-               types.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
-               types.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
+               final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+               mpBuilder.setAfi(Ipv6AddressFamily.class);
+               mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
+
+               PathAttributesBuilder paBuilder = new PathAttributesBuilder().addAugmentation(PathAttributes1.class,
+                               new PathAttributes1Builder().setMpReachNlri(mpBuilder.build()).build());
+
+               this.ipv6m = new UpdateBuilder().setPathAttributes(paBuilder.build()).build();
+
+               final MpUnreachNlriBuilder mpUBuilder = new MpUnreachNlriBuilder();
+               mpUBuilder.setAfi(LinkstateAddressFamily.class);
+               mpUBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
+
+               paBuilder = new PathAttributesBuilder().addAugmentation(PathAttributes2.class,
+                               new PathAttributes2Builder().setMpUnreachNlri(mpUBuilder.build()).build());
+
+               this.lsm = new UpdateBuilder().setPathAttributes(paBuilder.build()).build();
+
+               final Set<TablesKey> types = Sets.newHashSet();
+               types.add(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
+               types.add(new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
 
                this.bs = new BGPSynchronization(new BGPSession() {
 
@@ -61,27 +84,28 @@ public class SynchronizationTest {
 
                        @Override
                        public Set<BgpTableType> getAdvertisedTableTypes() {
+                               final Set<BgpTableType> types = Sets.newHashSet();
+                               types.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
+                               types.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
                                return types;
                        }
                }, this.listener, types);
        }
 
        @Test
-       @Ignore
-       //FIXME: to be fixed in testing phase
        public void testSynchronize() {
                // simulate sync
-//             this.bs.updReceived(this.ipv6m);
-//
-//             this.bs.updReceived(this.ipv4m);
-//             this.bs.updReceived(this.lsm);
-//             this.bs.kaReceived(); // nothing yet
-//             this.bs.updReceived(this.ipv4m);
+               this.bs.updReceived(this.ipv6m);
+               this.bs.updReceived(this.ipv4m);
+               this.bs.updReceived(this.lsm);
+               this.bs.kaReceived(); // nothing yet
+               this.bs.updReceived(this.ipv4m);
                this.bs.kaReceived(); // linkstate
                assertEquals(1, this.listener.getListMsg().size());
+               assertEquals(
+                               LinkstateAddressFamily.class,
+                               ((Update) this.listener.getListMsg().get(0)).getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi());
                this.bs.kaReceived(); // ipv4 sync
                assertEquals(2, this.listener.getListMsg().size());
-               assertEquals(Ipv4AddressFamily.class,
-                               ((Update) this.listener.getListMsg().get(1)).getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi());
        }
 }
index 4889114acc69b6a86594a4bbb8a326fdecdc9437..1b77f841d11c733444d83b3c6547792866c7134c 100644 (file)
@@ -28,6 +28,8 @@ import org.opendaylight.protocol.framework.ReconnectStrategy;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.NotifyBuilder;
 import org.opendaylight.yangtools.yang.binding.Notification;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Lists;
 import com.google.common.eventbus.EventBus;
@@ -39,7 +41,10 @@ import com.google.common.eventbus.EventBus;
  */
 @ThreadSafe
 public final class BGPMock implements BGP, Closeable {
-       static final Notification connectionLostMagicMessage = new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).build();
+
+       private static final Logger logger = LoggerFactory.getLogger(BGPMock.class);
+
+       static final Notification CONNECTION_LOST_MAGIC_MSG = new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).build();
 
        @GuardedBy("this")
        private final List<byte[]> allPreviousByteMessages;
@@ -66,9 +71,9 @@ public final class BGPMock implements BGP, Closeable {
                                messages.add(parser.parse(body));
                        }
                } catch (final DeserializerException e) {
-                       e.printStackTrace();
+                       logger.warn(e.getMessage(), e);
                } catch (final DocumentedException e) {
-                       e.printStackTrace();
+                       logger.warn(e.getMessage(), e);
                }
                return messages;
        }
@@ -84,7 +89,7 @@ public final class BGPMock implements BGP, Closeable {
        }
 
        public synchronized void insertConnectionLostEvent() {
-               this.insertMessage(connectionLostMagicMessage);
+               this.insertMessage(CONNECTION_LOST_MAGIC_MSG);
        }
 
        public synchronized void insertMessages(final List<Notification> messages) {
index 62aefcecd54449fbf9399849546da9a2a7f74273..be015d95c2c860a8fb5005972d331cc1a0fb3b50 100644 (file)
@@ -30,7 +30,7 @@ import com.google.common.eventbus.Subscribe;
  * This class has @Subscribe annotated methods which receive events from {@link EventBus} . Events are produced by
  * {@link BGPMock}, and each instance notifies exactly one {@link BGPSessionListener}.
  */
-class EventBusRegistration extends ListenerRegistration<BGPSessionListener> {
+final class EventBusRegistration extends ListenerRegistration<BGPSessionListener> {
        private final EventBus eventBus;
 
        public static EventBusRegistration createAndRegister(final EventBus eventBus, final BGPSessionListener listener,
@@ -59,7 +59,7 @@ class EventBusRegistration extends ListenerRegistration<BGPSessionListener> {
        }
 
        private static void sendMessage(final BGPSessionListener listener, final Notification message) {
-               if (BGPMock.connectionLostMagicMessage.equals(message)) {
+               if (BGPMock.CONNECTION_LOST_MAGIC_MSG.equals(message)) {
                        listener.onSessionTerminated(null, null);
                } else if (message instanceof Open) {
                        final Set<BgpTableType> tts = Sets.newHashSet();
@@ -84,9 +84,7 @@ class EventBusRegistration extends ListenerRegistration<BGPSessionListener> {
                                        return tts;
                                }
                        });
-               } else if (message instanceof Keepalive) {
-                       // do nothing
-               } else {
+               } else if (!(message instanceof Keepalive)) {
                        listener.onMessage(null, message);
                }
        }
index 626185a8e4ee955bd2e0bb19b86f7e5e92ba5d52..e7bdaeb9907b27c83ff521347e59fe8fad553ca0 100644 (file)
@@ -28,19 +28,23 @@ import com.google.common.base.Preconditions;
 @ThreadSafe
 public abstract class AbstractAdjRIBsIn<ID, DATA extends DataObject> implements AdjRIBsIn {
        protected abstract class RIBEntryData {
-               final PathAttributes attributes;
+               private final PathAttributes attributes;
 
                protected RIBEntryData(final PathAttributes attributes) {
                        this.attributes = Preconditions.checkNotNull(attributes);
                }
 
+               public PathAttributes getPathAttributes() {
+                       return this.attributes;
+               }
+
                protected abstract DATA getDataObject(ID key);
        }
 
        /**
-        * A single RIB table entry, which holds multiple versions of the entry's state and elects the authoritative based on
-        * ordering specified by the supplied comparator.
-        *
+        * A single RIB table entry, which holds multiple versions of the entry's state and elects the authoritative based
+        * on ordering specified by the supplied comparator.
+        * 
         */
        private final class RIBEntry {
                /*
@@ -61,16 +65,16 @@ public abstract class AbstractAdjRIBsIn<ID, DATA extends DataObject> implements
                }
 
                private InstanceIdentifier<?> getName() {
-                       if (name == null) {
-                               name = identifierForKey(basePath, key);
+                       if (this.name == null) {
+                               this.name = identifierForKey(AbstractAdjRIBsIn.this.basePath, this.key);
                        }
-                       return name;
+                       return this.name;
                }
 
                private RIBEntryData findCandidate(final RIBEntryData initial) {
                        RIBEntryData newState = initial;
                        for (final RIBEntryData s : this.candidates.values()) {
-                               if (newState == null || comparator.compare(newState.attributes, s.attributes) > 0) {
+                               if (newState == null || AbstractAdjRIBsIn.this.comparator.compare(newState.attributes, s.attributes) > 0) {
                                        newState = s;
                                }
                        }
@@ -80,7 +84,7 @@ public abstract class AbstractAdjRIBsIn<ID, DATA extends DataObject> implements
 
                private void electCandidate(final DataModificationTransaction transaction, final RIBEntryData candidate) {
                        if (this.currentState == null || !this.currentState.equals(candidate)) {
-                               transaction.putRuntimeData(getName(), candidate.getDataObject(key));
+                               transaction.putRuntimeData(getName(), candidate.getDataObject(this.key));
                                this.currentState = candidate;
                        }
                }
@@ -93,12 +97,12 @@ public abstract class AbstractAdjRIBsIn<ID, DATA extends DataObject> implements
                                electCandidate(transaction, candidate);
                                return true;
                        } else {
-                               transaction.removeRuntimeData(name);
+                               transaction.removeRuntimeData(this.name);
                                return false;
                        }
                }
 
-               synchronized void setState(final DataModificationTransaction  transaction, final Peer peer, final RIBEntryData state) {
+               synchronized void setState(final DataModificationTransaction transaction, final Peer peer, final RIBEntryData state) {
                        this.candidates.put(peer, state);
                        electCandidate(transaction, findCandidate(state));
                }
@@ -111,7 +115,7 @@ public abstract class AbstractAdjRIBsIn<ID, DATA extends DataObject> implements
 
        protected AbstractAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
                this.comparator = Preconditions.checkNotNull(comparator);
-               basePath = InstanceIdentifier.builder().node(LocRib.class).node(Tables.class, key).toInstance();
+               this.basePath = InstanceIdentifier.builder().node(LocRib.class).node(Tables.class, key).toInstance();
        }
 
        @Override
@@ -128,7 +132,7 @@ public abstract class AbstractAdjRIBsIn<ID, DATA extends DataObject> implements
 
        protected abstract InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath, final ID id);
 
-       protected synchronized void add(final DataModificationTransaction  trans, final Peer peer, final ID id, final RIBEntryData data) {
+       protected synchronized void add(final DataModificationTransaction trans, final Peer peer, final ID id, final RIBEntryData data) {
                RIBEntry e = this.entries.get(id);
                if (e == null) {
                        e = new RIBEntry(id);
@@ -138,7 +142,7 @@ public abstract class AbstractAdjRIBsIn<ID, DATA extends DataObject> implements
                e.setState(trans, peer, data);
        }
 
-       protected synchronized void remove(final DataModificationTransaction  trans, final Peer peer, final ID id) {
+       protected synchronized void remove(final DataModificationTransaction trans, final Peer peer, final ID id) {
                final RIBEntry e = this.entries.get(id);
                if (e != null && e.removeState(trans, peer)) {
                        this.entries.remove(id);
index bdd196e98e87ec032ea2bc6a85d343ce8ae04811..348ae034c63e82d44b57eae12f172afed9be558c 100644 (file)
@@ -9,13 +9,12 @@ package org.opendaylight.protocol.bgp.testtool;
 
 import io.netty.util.concurrent.GlobalEventExecutor;
 
-import java.io.IOException;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 
 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
 import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.BGPExtensionConsumerContextImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl;
 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionProposalImpl;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
@@ -30,10 +29,11 @@ import org.slf4j.LoggerFactory;
  */
 public class Main {
 
-       private final static Logger logger = LoggerFactory.getLogger(Main.class);
+       private static final Logger logger = LoggerFactory.getLogger(Main.class);
 
-       public static String usage = "DESCRIPTION:\n" + "\tCreates a server with given parameters. As long as it runs, it accepts connections "
-                       + "from PCCs.\n" + "USAGE:\n" + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
+       private static String usage = "DESCRIPTION:\n"
+                       + "\tCreates a server with given parameters. As long as it runs, it accepts connections " + "from PCCs.\n" + "USAGE:\n"
+                       + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
                        + "\t\tFormat: x.x.x.x:y where y is port number.\n\n"
                        + "\t\tThis IP address will appear in BGP Open message as BGP Identifier of the server.\n" +
 
@@ -47,20 +47,24 @@ public class Main {
 
                        "With no parameters, this help is printed.";
 
-       BGPDispatcherImpl dispatcher;
+       private final BGPDispatcherImpl dispatcher;
 
-       public Main() throws IOException {
-               this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl(BGPExtensionConsumerContextImpl.getSingletonInstance().getMessageRegistry()));
+       private static final int INITIAL_HOLD_TIME = 90;
+
+       private static final int RECONNECT_MILLIS = 5000;
+
+       Main() throws Exception {
+               this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry()));
        }
 
-       public static void main(final String[] args) throws NumberFormatException, IOException {
+       public static void main(final String[] args) throws Exception {
                if (args.length == 0 || args.length == 1 && args[0].equalsIgnoreCase("--help")) {
                        System.out.println(Main.usage);
                        return;
                }
 
                InetSocketAddress address = null;
-               short holdTimerValue = 90;
+               short holdTimerValue = INITIAL_HOLD_TIME;
                AsNumber as = null;
 
                int i = 0;
@@ -76,7 +80,7 @@ public class Main {
                                as = new AsNumber(Long.valueOf(args[i + 1]));
                                i++;
                        } else {
-                               System.out.println("WARNING: Unrecognized argument: " + args[i]);
+                               logger.error("WARNING: Unrecognized argument: " + args[i]);
                        }
                        i++;
                }
@@ -92,6 +96,7 @@ public class Main {
                logger.debug("{} {} {}", address, sessionListener, proposal);
 
                final InetSocketAddress addr = address;
-               m.dispatcher.createClient(addr, proposal, sessionListener, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000));
+               m.dispatcher.createClient(addr, proposal, sessionListener,
+                               new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, RECONNECT_MILLIS));
        }
 }
index 8f85c906bc0d487e6e008f863cfc284c7eccd600..24db1cae01269a4ec9e96d6eb24729b9e8387dac 100644 (file)
@@ -13,12 +13,11 @@ import io.netty.util.concurrent.DefaultPromise;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import io.netty.util.concurrent.Promise;
 
-import java.io.IOException;
 import java.net.InetSocketAddress;
 
 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
 import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.BGPExtensionConsumerContextImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.impl.BGPHandlerFactory;
 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionNegotiatorFactory;
@@ -59,7 +58,7 @@ public class BGPSpeakerMock<M, S extends ProtocolSession<M>, L extends SessionLi
                });
        }
 
-       public static void main(final String[] args) throws IOException {
+       public static void main(final String[] args) throws Exception {
 
                final SessionListenerFactory<BGPSessionListener> f = new SessionListenerFactory<BGPSessionListener>() {
                        @Override
@@ -73,7 +72,7 @@ public class BGPSpeakerMock<M, S extends ProtocolSession<M>, L extends SessionLi
                final SessionNegotiatorFactory<Notification, BGPSessionImpl, BGPSessionListener> snf = new BGPSessionNegotiatorFactory(new HashedWheelTimer(), prefs);
 
                final BGPSpeakerMock<Notification, BGPSessionImpl, BGPSessionListener> mock = new BGPSpeakerMock<>(snf,
-                               new BGPHandlerFactory(new BGPMessageFactoryImpl(BGPExtensionConsumerContextImpl.getSingletonInstance().getMessageRegistry())),
+                               new BGPHandlerFactory(new BGPMessageFactoryImpl(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry())),
                                new DefaultPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE));
 
                mock.createServer(new InetSocketAddress("127.0.0.2", 12345), f);
index 9e31fcbed6a8ceb8fd4a65931c08cecd16e5e8ef..8f0ee1d93acd3bfadfac71ee5e8935a84bd5cefe 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.protocol.bgp.util;
 
-import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
 
@@ -28,16 +27,20 @@ import com.google.common.primitives.UnsignedBytes;
 @Immutable
 public final class BinaryBGPDumpFileParser {
 
-       private static final byte ff = (byte) 255;
-       private static final Logger LOG = LoggerFactory.getLogger(BinaryBGPDumpFileParser.class);
+       private static final Logger logger = LoggerFactory.getLogger(BinaryBGPDumpFileParser.class);
        private static final int MINIMAL_LENGTH = 19;
 
+       private static final int MARKER_LENGTH = 16;
+
+       private BinaryBGPDumpFileParser() {
+
+       }
+
        /**
         * Extract BGP messages from binary file in MRT format.
         * 
         * @param file file with BGP messages in binary form.
         * @return list with byte arrays representing extracted messages.
-        * @throws IOException
         */
        public static List<byte[]> parseMessages(final byte[] byteArray) {
 
@@ -47,15 +50,15 @@ public final class BinaryBGPDumpFileParser {
                        final byte b = byteArray[i];
 
                        // Marker start
-                       if (b == ff) {
+                       if (b == UnsignedBytes.MAX_VALUE) {
                                final int start = i;
                                int ffCount = 0;
                                for (int j = i; j < i + (17); j++) {
                                        // Check marker
-                                       if (byteArray[j] == ff) {
+                                       if (byteArray[j] == UnsignedBytes.MAX_VALUE) {
                                                ffCount++;
-                                       } else if (ffCount == 16) {
-                                               if (j == (i + 16)) {
+                                       } else if (ffCount == MARKER_LENGTH) {
+                                               if (j == (i + MARKER_LENGTH)) {
                                                        // Parse length
                                                        final int length = UnsignedBytes.toInt(byteArray[j]) * 256 + UnsignedBytes.toInt(byteArray[j + 1]);
 
@@ -64,7 +67,7 @@ public final class BinaryBGPDumpFileParser {
 
                                                        final byte[] message = Arrays.copyOfRange(byteArray, start, start + length);
                                                        messages.add(message);
-                                                       j += length - 16;
+                                                       j += length - MARKER_LENGTH;
                                                }
                                                i = j;
                                                break;
@@ -75,7 +78,7 @@ public final class BinaryBGPDumpFileParser {
                        }
 
                }
-               LOG.info("Succesfully extracted " + messages.size() + " messages");
+               logger.info("Succesfully extracted {} messages", messages.size());
                return messages;
        }
 }
index 0a2d44d2a956492187a4a125f38c9b14cc224972..9ea256ba6b79ccb8c7e78e24369826356e68e805 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.bgp.util;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -30,16 +29,21 @@ import com.google.common.collect.Lists;
 import com.google.common.io.CharStreams;
 
 /**
- * Read text file, parse BGP messages. File can contain comments or other data. BGP messages are detected using 16 ff marker.
- * New lines and spaces are ignored. Use {@link ByteArray#bytesToHexString(byte[])} for serializing bytes to this format.
+ * Read text file, parse BGP messages. File can contain comments or other data. BGP messages are detected using 16 ff
+ * marker. New lines and spaces are ignored. Use {@link ByteArray#bytesToHexString(byte[])} for serializing bytes to
+ * this format.
  */
 @Immutable
-public class HexDumpBGPFileParser {
+public final class HexDumpBGPFileParser {
        private static final int MINIMAL_LENGTH = 19;
-       private static final Logger LOG = LoggerFactory.getLogger(HexDumpBGPFileParser.class);
-       private static final String ff_16 = Strings.repeat("FF", 16);
+       private static final Logger logger = LoggerFactory.getLogger(HexDumpBGPFileParser.class);
+       private static final String FF_16 = Strings.repeat("FF", 16);
 
-       public static List<byte[]> parseMessages(final File file) throws FileNotFoundException, IOException {
+       private HexDumpBGPFileParser() {
+
+       }
+
+       public static List<byte[]> parseMessages(final File file) throws IOException {
                Preconditions.checkArgument(file != null, "Filename cannot be null");
                return parseMessages(new FileInputStream(file));
        }
@@ -53,48 +57,47 @@ public class HexDumpBGPFileParser {
                }
        }
 
-       public static List<byte[]> parseMessages(String content) {
-               content = clearWhiteSpace_toUpper(content);
+       public static List<byte[]> parseMessages(final String c) {
+               final String content = clearWhiteSpaceToUpper(c);
                // search for 16 FFs
 
-               List<byte[]> messages = Lists.newLinkedList();
+               final List<byte[]> messages = Lists.newLinkedList();
                int idx = 0;
-               while ((idx = content.indexOf(ff_16, idx)) > -1) {
+               while ((idx = content.indexOf(FF_16, idx)) > -1) {
                        // next 2 bytes are length
-                       int lengthIdx = idx + 16 * 2;
-                       int messageIdx = lengthIdx + 4;
-                       String hexLength = content.substring(lengthIdx, messageIdx);
+                       final int lengthIdx = idx + 16 * 2;
+                       final int messageIdx = lengthIdx + 4;
+                       final String hexLength = content.substring(lengthIdx, messageIdx);
                        byte[] byteLength = null;
                        try {
                                byteLength = Hex.decodeHex(hexLength.toCharArray());
-                       } catch (DecoderException e) {
+                       } catch (final DecoderException e) {
                                throw new RuntimeException(e);
                        }
-                       int length = ByteArray.bytesToInt(byteLength);
-                       int messageEndIdx = idx + length * 2;
+                       final int length = ByteArray.bytesToInt(byteLength);
+                       final int messageEndIdx = idx + length * 2;
 
                        // Assert that message is longer than minimum 19(header.length == 19)
                        // If length in BGP message would be 0, loop would never end
-                       Preconditions.checkArgument(length >=  MINIMAL_LENGTH,
-                                       "Invalid message at index " + idx
-                                       + ", length atribute is lower than " + MINIMAL_LENGTH);
+                       Preconditions.checkArgument(length >= MINIMAL_LENGTH, "Invalid message at index " + idx + ", length atribute is lower than "
+                                       + MINIMAL_LENGTH);
 
-                       String hexMessage = content.substring(idx, messageEndIdx);
+                       final String hexMessage = content.substring(idx, messageEndIdx);
                        byte[] message = null;
                        try {
                                message = Hex.decodeHex(hexMessage.toCharArray());
-                       } catch (DecoderException e) {
+                       } catch (final DecoderException e) {
                                new RuntimeException(e);
                        }
                        messages.add(message);
                        idx = messageEndIdx;
                }
-               LOG.info("Succesfully extracted " + messages.size() + " messages");
+               logger.info("Succesfully extracted {} messages", messages.size());
                return messages;
        }
 
        @VisibleForTesting
-       static String clearWhiteSpace_toUpper(final String line){
+       static String clearWhiteSpaceToUpper(final String line) {
                return line.replaceAll("\\s", "").toUpperCase();
        }
 
index f66e7595678ba2c81effcf27d52f6d10494ddca7..e1a9283b14e5d78f8bc92e0db62a8a7cda0c4754 100644 (file)
@@ -27,7 +27,7 @@ public class BGPHexFileParserTest {
        @Test
        public void testCleanWhiteSpace() {
                final String input = "abc def\r\nghi\nj";
-               assertEquals("ABCDEFGHIJ", HexDumpBGPFileParser.clearWhiteSpace_toUpper(input));
+               assertEquals("ABCDEFGHIJ", HexDumpBGPFileParser.clearWhiteSpaceToUpper(input));
        }
 
        @Test
index 7f420089237550095efd878bb61e15b31b0f6b85..d0165c68f5e32f258987343fb9cbafd8553948f4 100644 (file)
@@ -7,52 +7,23 @@
  */
 package org.opendaylight.protocol.concepts;
 
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
 import javax.annotation.concurrent.ThreadSafe;
 
-import com.google.common.base.Preconditions;
-
 @ThreadSafe
 public class HandlerRegistry<CLASS, PARSER, SERIALIZER> {
-       private final Map<Class<? extends CLASS>, SERIALIZER> serializers = new ConcurrentHashMap<>();
-       private final Map<Integer, PARSER> parsers = new ConcurrentHashMap<>();
+       private final MultiRegistry<Class<? extends CLASS>, SERIALIZER> serializers = new MultiRegistry<>();
+       private final MultiRegistry<Integer, PARSER> parsers = new MultiRegistry<>();
 
-       public AutoCloseable registerParser(final int type, final PARSER parser) {
-               synchronized (parsers) {
-                       Preconditions.checkArgument(!parsers.containsKey(type), "Type %s already registered", type);
-                       parsers.put(type, parser);
-
-                       return new AbstractRegistration() {
-                               @Override
-                               protected void removeRegistration() {
-                                       synchronized (parsers) {
-                                               parsers.remove(type);
-                                       }
-                               }
-                       };
-               }
+       public AbstractRegistration registerParser(final int type, final PARSER parser) {
+               return parsers.register(type, parser);
        }
 
        public PARSER getParser(final int type) {
                return parsers.get(type);
        }
 
-       public AutoCloseable registerSerializer(final Class<? extends CLASS> clazz, final SERIALIZER serializer) {
-               synchronized (serializers) {
-                       Preconditions.checkArgument(!serializers.containsKey(clazz), "Message class %s already registered", clazz);
-                       serializers.put(clazz, serializer);
-
-                       return new AbstractRegistration() {
-                               @Override
-                               protected void removeRegistration() {
-                                       synchronized (serializers) {
-                                               serializers.remove(clazz);
-                                       }
-                               }
-                       };
-               }
+       public AbstractRegistration registerSerializer(final Class<? extends CLASS> clazz, final SERIALIZER serializer) {
+               return serializers.register(clazz, serializer);
        }
 
        public SERIALIZER getSerializer(final Class<? extends CLASS> clazz) {
index 60560dc2f5b00a1bc8a3a4a78f91a09dad9e4589..8f9c021ed5d332b5b5c792cc6ecbdba4d9289b82 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.protocol.concepts;
 import java.net.Inet4Address;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
@@ -20,6 +21,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
+import com.google.common.net.InetAddresses;
+import com.google.common.primitives.Bytes;
 import com.google.common.primitives.UnsignedBytes;
 
 /**
@@ -27,9 +30,11 @@ import com.google.common.primitives.UnsignedBytes;
  */
 public final class Ipv4Util {
 
+       public static final int IP4_LENGTH = 4;
+
        public static Ipv4Address addressForBytes(final byte[] bytes) {
                try {
-                       return new Ipv4Address(Inet4Address.getByAddress(bytes).getHostAddress());
+                       return new Ipv4Address(InetAddresses.toAddrString(Inet4Address.getByAddress(bytes)));
                } catch (final UnknownHostException e) {
                        throw new IllegalArgumentException(e.getMessage());
                }
@@ -45,14 +50,33 @@ public final class Ipv4Util {
                return a.getAddress();
        }
 
+       public static byte[] bytesForPrefix(final Ipv4Prefix prefix) {
+               final String p = prefix.getValue();
+               final int sep = p.indexOf("/");
+               try {
+                       final byte[] bytes = Inet4Address.getByName(p.substring(0, sep)).getAddress();
+                       return Bytes.concat(bytes, new byte[] { Byte.valueOf(p.substring(sep + 1, p.length() - 1)) });
+               } catch (final UnknownHostException e) {
+                       throw new IllegalArgumentException(e.getMessage());
+               }
+       }
+
        public static Ipv4Prefix prefixForBytes(final byte[] bytes, final int length) {
                Preconditions.checkArgument(length <= bytes.length * 8);
-               return new Ipv4Prefix(addressForBytes(bytes).toString() + "/" + length);
+               final byte[] tmp = Arrays.copyOfRange(bytes, 0, 4);
+               InetAddress a = null;
+               try {
+                       a = InetAddress.getByAddress(tmp);
+               } catch (final UnknownHostException e) {
+                       throw new IllegalArgumentException(e.getMessage());
+               }
+               return new Ipv4Prefix(InetAddresses.toAddrString(a) + "/" + length);
        }
 
        public static List<Ipv4Prefix> prefixListForBytes(final byte[] bytes) {
-               if (bytes.length == 0)
+               if (bytes.length == 0) {
                        return Collections.emptyList();
+               }
 
                final List<Ipv4Prefix> list = Lists.newArrayList();
                int byteOffset = 0;
@@ -74,6 +98,6 @@ public final class Ipv4Util {
                        p = prefix.getIpv6Prefix().getValue();
                }
                final int sep = p.indexOf("/");
-               return Integer.valueOf(p.substring(sep, p.length() - 1));
+               return Integer.valueOf(p.substring(sep + 1, p.length()));
        }
 }
index 6eb959d8de32b944340df9631346cfe713000ff6..fc372bb1f3f74dee1b4183cb41e23d8c24a0f0d0 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.protocol.concepts;
 import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
@@ -19,6 +20,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
+import com.google.common.net.InetAddresses;
+import com.google.common.primitives.Bytes;
 import com.google.common.primitives.UnsignedBytes;
 
 /**
@@ -26,9 +29,11 @@ import com.google.common.primitives.UnsignedBytes;
  */
 public class Ipv6Util {
 
+       public static final int IPV6_LENGTH = 16;
+
        public static Ipv6Address addressForBytes(final byte[] bytes) {
                try {
-                       return new Ipv6Address(Inet6Address.getByAddress(bytes).toString());
+                       return new Ipv6Address(InetAddresses.toAddrString(Inet6Address.getByAddress(bytes)));
                } catch (final UnknownHostException e) {
                        throw new IllegalArgumentException(e.getMessage());
                }
@@ -44,14 +49,33 @@ public class Ipv6Util {
                return a.getAddress();
        }
 
+       public static byte[] bytesForPrefix(final Ipv6Prefix prefix) {
+               final String p = prefix.getValue();
+               final int sep = p.indexOf("/");
+               try {
+                       final byte[] bytes = Inet6Address.getByName(p.substring(0, sep)).getAddress();
+                       return Bytes.concat(bytes, new byte[] { Byte.valueOf(p.substring(sep + 1, p.length() - 1)) });
+               } catch (final UnknownHostException e) {
+                       throw new IllegalArgumentException(e.getMessage());
+               }
+       }
+
        public static Ipv6Prefix prefixForBytes(final byte[] bytes, final int length) {
                Preconditions.checkArgument(length <= bytes.length * 8);
-               return new Ipv6Prefix(addressForBytes(bytes).toString() + "/" + length);
+               final byte[] tmp = Arrays.copyOfRange(bytes, 0, 16);
+               InetAddress a = null;
+               try {
+                       a = InetAddress.getByAddress(tmp);
+               } catch (final UnknownHostException e) {
+                       throw new IllegalArgumentException(e.getMessage());
+               }
+               return new Ipv6Prefix(InetAddresses.toAddrString(a) + "/" + length);
        }
 
        public static List<Ipv6Prefix> prefixListForBytes(final byte[] bytes) {
-               if (bytes.length == 0)
+               if (bytes.length == 0) {
                        return Collections.emptyList();
+               }
 
                final List<Ipv6Prefix> list = Lists.newArrayList();
                int byteOffset = 0;
diff --git a/concepts/src/main/java/org/opendaylight/protocol/concepts/MultiRegistry.java b/concepts/src/main/java/org/opendaylight/protocol/concepts/MultiRegistry.java
new file mode 100644 (file)
index 0000000..462aecd
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.concepts;
+
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.annotation.concurrent.GuardedBy;
+import javax.annotation.concurrent.ThreadSafe;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ListMultimap;
+
+@ThreadSafe
+public final class MultiRegistry<K, V> {
+       private final ConcurrentMap<K, V> current = new ConcurrentHashMap<>();
+
+       @GuardedBy("this")
+       private final ListMultimap<K, V> candidates = ArrayListMultimap.create();
+
+       public synchronized AbstractRegistration register(final K key, final V value) {
+               // Put this value into candidates, then put it into the the current
+               // map, if it does not have a key -- this is to prevent unnecessary
+               // churn by replacing an already-present mapping.
+               candidates.put(key, value);
+               current.putIfAbsent(key, value);
+
+               final Object lock = this;
+               return new AbstractRegistration() {
+                       @Override
+                       protected void removeRegistration() {
+                               synchronized (lock) {
+                                       // The delete sequencing is a bit more complex, as we want
+                                       // to prevent churn and we do not want the user to see
+                                       // the current map without a mapping as long as a candidate
+                                       // exists. To achieve this, we remove the entry from
+                                       // candidates and then check if the list of candidates for
+                                       // this key has become empty. If it has, we just remove
+                                       // the mapping. If there are candidates, then attempt to
+                                       // replace it -- but only if it has pointed to the removed
+                                       // value in the first place.
+                                       candidates.remove(key, value);
+
+                                       final List<V> values = candidates.get(key);
+                                       if (values.isEmpty()) {
+                                               current.remove(key);
+                                       } else {
+                                               current.replace(key, value, values.get(0));
+                                       }
+                               }
+                       }
+               };
+       }
+
+       public V get(final K key) {
+               return current.get(key);
+       }
+}
index a298d61f99fbaf1ba440323e2d9b7740e293bcf5..73bacbd5e5d674a95ce0a640b89db8e545ef71ff 100644 (file)
@@ -4,7 +4,6 @@ module nps-concepts {
        prefix "nps-c";
 
        import ieee754 { prefix ieee754; revision-date 2013-08-19; }
-       import ietf-inet-types { prefix inet; revision-date 2010-09-24; }
 
        organization "Cisco Systems, Inc.";
        contact "Dana Kutenicsova <dkutenic@cisco.com>";
index 341fe3cb74a5d658a4e144ab559fd7c9af27915c..cc5262c412e807479e5c60400c12da980c71d14c 100644 (file)
@@ -7,9 +7,12 @@
  */
 package org.opendaylight.protocol.concepts;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.net.UnknownHostException;
+import java.util.List;
 
 import org.junit.Test;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
@@ -18,6 +21,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.inet.types.rev100924.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
 
+import com.google.common.collect.Lists;
+
 public class IPAddressesAndPrefixesTest {
 
        @Test
@@ -37,4 +42,52 @@ public class IPAddressesAndPrefixesTest {
                assertTrue("123.123.123.123/24".equals(new Ipv4Prefix("123.123.123.123/24").getValue()));
                assertTrue("2001::1/120".equals(new Ipv6Prefix("2001::1/120").getValue()));
        }
+
+       @Test
+       public void testPrefix4ForBytes() {
+               final byte[] bytes = new byte[] { 123, 122, 4, 5 };
+               assertEquals(new Ipv4Prefix("123.122.4.5/32"), Ipv4Util.prefixForBytes(bytes, 32));
+       }
+
+       @Test
+       public void testAddress4ForBytes() {
+               final byte[] bytes = new byte[] { (byte) 123, (byte) 122, (byte) 4, (byte) 5 };
+               assertEquals(new Ipv4Address("123.122.4.5"), Ipv4Util.addressForBytes(bytes));
+               try {
+                       Ipv4Util.addressForBytes(new byte[] { 22, 44, 66, 18, 88, 33 });
+                       fail();
+               } catch (final IllegalArgumentException e) {
+                       assertEquals("addr is of illegal length", e.getMessage());
+               }
+       }
+
+       @Test
+       public void testPrefixList4ForBytes() {
+               final byte[] bytes = new byte[] { 22, (byte) 172, (byte) 168, 3, 8, 12, 32, (byte) 192, (byte) 168, 35, 100 };
+               final List<Ipv4Prefix> prefs = Ipv4Util.prefixListForBytes(bytes);
+               assertEquals(
+                               Lists.newArrayList(new Ipv4Prefix("172.168.3.0/22"), new Ipv4Prefix("12.0.0.0/8"), new Ipv4Prefix("192.168.35.100/32")),
+                               prefs);
+       }
+
+       @Test
+       public void testPrefix6ForBytes() {
+               final byte[] bytes = new byte[] { 0x20, 0x01, 0x0d, (byte) 0xb8, 0x00, 0x01, 0x00, 0x02 };
+               assertEquals(new Ipv6Prefix("2001:db8:1:2::/64"), Ipv6Util.prefixForBytes(bytes, 64));
+       }
+
+       @Test
+       public void testPrefixList6ForBytes() {
+               final List<Ipv6Prefix> prefs = Lists.newArrayList();
+               prefs.add(new Ipv6Prefix("2001:db8:1:2::/64"));
+               prefs.add(new Ipv6Prefix("2001:db8:1:1::/64"));
+               prefs.add(new Ipv6Prefix("2001:db8:1::/64"));
+
+       }
+
+       @Test
+       public void testPrefixLength() {
+               assertEquals(22, Ipv4Util.getPrefixLength(new IpPrefix(new Ipv4Prefix("172.168.3.0/22"))));
+               assertEquals(64, Ipv4Util.getPrefixLength(new IpPrefix(new Ipv6Prefix("2001:db8:1:2::/64"))));
+       }
 }
index 0da09394d18f40bc45a464a04547ba7279e658ad..3345a435694570d29ca8b2a9ce714ed5e06942e5 100644 (file)
             <scope>test</scope>
         </dependency>
 
+        <dependency>
+                       <groupId>${project.groupId}</groupId>
+            <artifactId>programming-api</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+                       <groupId>${project.groupId}</groupId>
+            <artifactId>programming-tunnel-api</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+                       <groupId>${project.groupId}</groupId>
+            <artifactId>topology-api</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+                       <groupId>${project.groupId}</groupId>
+            <artifactId>topology-segment-routing</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+                       <groupId>${project.groupId}</groupId>
+            <artifactId>topology-tunnel-api</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+                       <groupId>${project.groupId}</groupId>
+            <artifactId>topology-tunnel-pcep</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+
         <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>sal-binding-broker-impl</artifactId>
index 97d46e3e7b3df3dfe84d8d55c52bae37dda35591..7f00a96e44db4d8b3ad2078130f017b2e06748e3 100644 (file)
@@ -14,7 +14,7 @@ import com.google.common.collect.Lists;
 public final class BgpLinkstateBundleTest extends AbstractBundleTest {
        @Override
        protected Collection<String> prerequisiteBundles() {
-               return Lists.newArrayList("bgp-concepts", "bgp-parser-api", "bgp-parser-spi", "concepts", "framework", "rsvp-api", "util");
+               return Lists.newArrayList("bgp-concepts", "bgp-parser-api", "bgp-parser-spi", "bgp-rib-api", "concepts", "framework", "rsvp-api", "util");
        }
 
        @Override
index 74c1107529d9018d0bb76b93015bcd9727160bc8..9ff465432e341319643da828174c21223ed034df 100644 (file)
@@ -7,8 +7,12 @@
  */
 package org.opendaylight.protocol.pcep;
 
+import java.net.InetAddress;
+import java.util.concurrent.Future;
+
 import org.opendaylight.protocol.framework.ProtocolSession;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Tlvs;
 
 /**
  * PCEP Session represents the finite state machine in PCEP, including timers and its purpose is to create a PCEP
@@ -22,10 +26,15 @@ public interface PCEPSession extends ProtocolSession<Message> {
         * Sends message from user to PCE/PCC. If the user sends an Open Message, the session returns an error (open message
         * is only allowed, when a PCEP handshake is in progress). Close message will close the session and free all the
         * resources.
-        * 
+        *
         * @param message message to be sent
+        * @return Future promise which will be succeed when the message is enqueued in the socket.
         */
-       public void sendMessage(Message message);
+       Future<Void> sendMessage(Message message);
 
        public void close(TerminationReason reason);
+
+       public Tlvs getRemoteTlvs();
+
+       public InetAddress getRemoteAddress();
 }
index 7734c0364e24545eef7b1fc2bb8941c851660ff1..ed8b20ba0b21cccc8a36ea8a64a16363f19f0e40 100644 (file)
@@ -75,6 +75,30 @@ module pcep-types {
                }
        }
 
+       typedef symbolic-path-name {
+               type binary;
+       }
+
+       typedef operational-status {
+               type enumeration {
+                       enum down {
+                               value 0;
+                       }
+                       enum up {
+                               value 1;
+                       }
+                       enum active {
+                               value 2;
+                       }
+                       enum going-down {
+                               value 3;
+                       }
+                       enum going-up {
+                               value 4;
+                       }
+               }
+       }
+
        // TLVs
        grouping tlv {
                description "Marker grouping for TLV groupings.";
@@ -138,7 +162,7 @@ module pcep-types {
                }
        }
        
-    grouping p2mp-capable-tlv {
+       grouping p2mp-capable-tlv {
                description "P2MP CAPABLE TLV";
                reference "https://tools.ietf.org/html/rfc6006#section-3.1.2";
 
@@ -229,6 +253,7 @@ module pcep-types {
                                }
                        }
                }
+               // FIXME: add tunnel endpoint (from stateful-07) 
        }
 
        grouping symbolic-path-name-tlv {
@@ -237,7 +262,7 @@ module pcep-types {
 
                uses tlv;
                leaf path-name {
-                       type binary;
+                       type symbolic-path-name;
                        mandatory true;
                }
        }
@@ -579,14 +604,13 @@ module pcep-types {
                        }
 
                        uses rsvp:explicit-route-subobjects {
-// FIXME: yangtools bug
-//                             augment "subobject-type" {
-//                                     case path-key {
-//                                             container path-key {
-//                                                     uses path-key-subobject;
-//                                             }
-//                                     }
-//                             }
+                               augment "subobject-type" {
+                                       case path-key {
+                                               container path-key {
+                                                       uses path-key-subobject;
+                                               }
+                                       }
+                               }
                        }
                }
        }
@@ -611,7 +635,15 @@ module pcep-types {
                uses object;
 
                list subobjects {
-                       uses rsvp:record-route-subobjects;
+                       uses rsvp:record-route-subobjects {
+                               augment "subobject-type" {
+                                       case path-key {
+                                               container path-key {
+                                                       uses path-key-subobject;
+                                               }
+                                       }
+                               }
+                       }
                }
        }
 
@@ -670,7 +702,6 @@ module pcep-types {
                description "NOTIFICATION Object";
                reference "https://tools.ietf.org/html/rfc5440#section-7.14";
 
-               // No possibility of TLVs
                uses object;
                container "tlvs" {
                        container overload-duration {
@@ -695,7 +726,6 @@ module pcep-types {
                description "PCEP-ERROR Object";
                reference "https://tools.ietf.org/html/rfc5440#section-7.15";
 
-               // No possibility of TLVs
                uses object;
                container "tlvs" {
                        container req-missing {
@@ -802,7 +832,7 @@ module pcep-types {
        }
 
        grouping lsp-object {
-               description "SRP Object";
+               description "LSP Object";
                reference "https://tools.ietf.org/html/draft-ietf-pce-stateful-pce-05#section-7.3";
 
                uses object;
@@ -819,7 +849,7 @@ module pcep-types {
                                uses rsvp-error-spec-tlv;
                        }
 
-                       container symblic-path-name {
+                       container symbolic-path-name {
                                uses symbolic-path-name-tlv;
                        }
                }
@@ -850,23 +880,7 @@ module pcep-types {
                }
 
                leaf operational {
-                       type enumeration {
-                               enum down {
-                                       value 0;
-                               }
-                               enum up {
-                                       value 1;
-                               }
-                               enum active {
-                                       value 2;
-                               }
-                               enum going-down {
-                                       value 3;
-                               }
-                               enum going-up {
-                                       value 4;
-                               }
-                       }
+                       type operational-status;
                        mandatory true;
                }
 
index 743a97b97bffbd6fce73cc7e49bb8ae51e23ad10..f11f7ac25f5799572cf5a23acde4994208aa94fa 100644 (file)
             <groupId>org.opendaylight.yangtools.model</groupId>
             <artifactId>ietf-inet-types</artifactId>
             <version>2010.09.24-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>${osgi.version}</version>
+            <scope>provided</scope>
         </dependency>
                <dependency>
                        <groupId>org.mockito</groupId>
                                <configuration>
                                        <instructions>
                                                <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
-                                               <Export-Package>
+                                               <Private-Package>
                                                        org.opendaylight.protocol.pcep.impl.*,
-                                               </Export-Package>
+                                               </Private-Package>
+                        <Activator>org.opendaylight.protocol.pcep.parser.impl.BundleActivator</Activator>
                                        </instructions>
                                </configuration>
                        </plugin>
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/Activator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/Activator.java
new file mode 100644 (file)
index 0000000..946f80f
--- /dev/null
@@ -0,0 +1,329 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.protocol.pcep.impl.message.PCCreateMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPCloseMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPErrorMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPKeepAliveMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPNotificationMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPOpenMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPReplyMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPReportMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPRequestMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPUpdateRequestMessageParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPBandwidthObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPClassTypeObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPCloseObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPExcludeRouteObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPExplicitRouteObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPGlobalConstraintsObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPIncludeRouteObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPLspObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPLspaObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPMetricObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPNoPathObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPNotificationObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPObjectiveFunctionObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPPathKeyObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPReportedRouteObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPSrpObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROAsNumberSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROIpPrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROLabelSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROPathKeySubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROUnnumberedInterfaceSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.GeneralizedLabelParser;
+import org.opendaylight.protocol.pcep.impl.subobject.RROIpPrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.RROLabelSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.RROPathKeySubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.RROUnnumberedInterfaceSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.Type1LabelParser;
+import org.opendaylight.protocol.pcep.impl.subobject.WavebandSwitchingLabelParser;
+import org.opendaylight.protocol.pcep.impl.subobject.XROAsNumberSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.XROIpPrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.XROPathKeySubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.XROSRLGSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.XROUnnumberedInterfaceSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LSPIdentifierTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LspDbVersionTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LspSymbolicNameTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LspUpdateErrorTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.NoPathVectorTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.OFListTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.OrderTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.OverloadedDurationTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.PCEStatefulCapabilityTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.PredundancyGroupTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.RSVPErrorSpecTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.ReqMissingTlvParser;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.BandwidthObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClasstypeObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.EndpointsObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExcludeRouteObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExplicitRouteObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.GcObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.IncludeRouteObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.KeepaliveMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LoadBalancingObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspDbVersionTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspErrorCodeTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspaObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.MetricObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NotificationObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfListTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OrderTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OverloadDurationTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeyObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeySubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcepErrorObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcerrMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcinitiateMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcntfMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcrepMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcreqMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcrptMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcupdMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PredundancyGroupIdTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ReportedRouteObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ReqMissingTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RpObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RsvpErrorSpecTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.StatefulCapabilityTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SvecObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SymbolicPathNameTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AsNumberSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.IpPrefixSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LabelSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.SrlgSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.UnnumberedSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.Type1Label;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.WavebandSwitchingLabel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+public final class Activator implements PCEPExtensionProviderActivator {
+       private static final Logger logger = LoggerFactory.getLogger(Activator.class);
+       private List<AutoCloseable> registrations;
+
+       @Override
+       public void start(final PCEPExtensionProviderContext context) {
+               Preconditions.checkState(this.registrations == null);
+               final List<AutoCloseable> regs = new ArrayList<>();
+
+               final LabelHandlerRegistry labelReg = context.getLabelHandlerRegistry();
+               context.registerLabelParser(Type1LabelParser.CTYPE, new Type1LabelParser());
+               context.registerLabelParser(GeneralizedLabelParser.CTYPE, new GeneralizedLabelParser());
+               context.registerLabelParser(WavebandSwitchingLabelParser.CTYPE, new WavebandSwitchingLabelParser());
+
+               context.registerLabelSerializer(Type1Label.class, new Type1LabelParser());
+               context.registerLabelSerializer(GeneralizedLabel.class, new GeneralizedLabelParser());
+               context.registerLabelSerializer(WavebandSwitchingLabel.class, new WavebandSwitchingLabelParser());
+
+               final EROSubobjectHandlerRegistry eroSubReg = context.getEROSubobjectHandlerRegistry();
+               context.registerEROSubobjectParser(EROIpPrefixSubobjectParser.TYPE, new EROIpPrefixSubobjectParser());
+               context.registerEROSubobjectParser(EROIpPrefixSubobjectParser.TYPE6, new EROIpPrefixSubobjectParser());
+               context.registerEROSubobjectParser(EROAsNumberSubobjectParser.TYPE, new EROAsNumberSubobjectParser());
+               context.registerEROSubobjectParser(EROLabelSubobjectParser.TYPE, new EROLabelSubobjectParser(labelReg));
+               context.registerEROSubobjectParser(EROUnnumberedInterfaceSubobjectParser.TYPE, new EROUnnumberedInterfaceSubobjectParser());
+               context.registerEROSubobjectParser(EROPathKeySubobjectParser.TYPE, new EROPathKeySubobjectParser());
+               context.registerEROSubobjectParser(EROPathKeySubobjectParser.TYPE128, new EROPathKeySubobjectParser());
+
+               context.registerEROSubobjectSerializer(IpPrefixSubobject.class, new EROIpPrefixSubobjectParser());
+               context.registerEROSubobjectSerializer(AsNumberSubobject.class, new EROAsNumberSubobjectParser());
+               context.registerEROSubobjectSerializer(LabelSubobject.class, new EROLabelSubobjectParser(labelReg));
+               context.registerEROSubobjectSerializer(UnnumberedSubobject.class, new EROUnnumberedInterfaceSubobjectParser());
+               context.registerEROSubobjectSerializer(PathKeySubobject.class, new EROPathKeySubobjectParser());
+
+               final RROSubobjectHandlerRegistry rroSubReg = context.getRROSubobjectHandlerRegistry();
+               context.registerRROSubobjectParser(RROIpPrefixSubobjectParser.TYPE, new RROIpPrefixSubobjectParser());
+               context.registerRROSubobjectParser(RROIpPrefixSubobjectParser.TYPE6, new RROIpPrefixSubobjectParser());
+               context.registerRROSubobjectParser(RROLabelSubobjectParser.TYPE, new RROLabelSubobjectParser(labelReg));
+               context.registerRROSubobjectParser(RROUnnumberedInterfaceSubobjectParser.TYPE, new RROUnnumberedInterfaceSubobjectParser());
+               context.registerRROSubobjectParser(RROPathKeySubobjectParser.TYPE, new RROPathKeySubobjectParser());
+               context.registerRROSubobjectParser(RROPathKeySubobjectParser.TYPE128, new RROPathKeySubobjectParser());
+
+               context.registerRROSubobjectSerializer(IpPrefixSubobject.class, new RROIpPrefixSubobjectParser());
+               context.registerRROSubobjectSerializer(LabelSubobject.class, new RROLabelSubobjectParser(labelReg));
+               context.registerRROSubobjectSerializer(UnnumberedSubobject.class, new RROUnnumberedInterfaceSubobjectParser());
+               context.registerRROSubobjectSerializer(PathKeySubobject.class, new RROPathKeySubobjectParser());
+
+               final XROSubobjectHandlerRegistry xroSubReg = context.getXROSubobjectHandlerRegistry();
+               context.registerXROSubobjectParser(XROIpPrefixSubobjectParser.TYPE, new XROIpPrefixSubobjectParser());
+               context.registerXROSubobjectParser(XROIpPrefixSubobjectParser.TYPE6, new XROIpPrefixSubobjectParser());
+               context.registerXROSubobjectParser(XROAsNumberSubobjectParser.TYPE, new XROAsNumberSubobjectParser());
+               context.registerXROSubobjectParser(XROSRLGSubobjectParser.TYPE, new XROSRLGSubobjectParser());
+               context.registerXROSubobjectParser(XROUnnumberedInterfaceSubobjectParser.TYPE, new XROUnnumberedInterfaceSubobjectParser());
+               context.registerXROSubobjectParser(XROPathKeySubobjectParser.TYPE, new XROPathKeySubobjectParser());
+               context.registerXROSubobjectParser(XROPathKeySubobjectParser.TYPE128, new XROPathKeySubobjectParser());
+
+               context.registerXROSubobjectSerializer(IpPrefixSubobject.class, new XROIpPrefixSubobjectParser());
+               context.registerXROSubobjectSerializer(AsNumberSubobject.class, new XROAsNumberSubobjectParser());
+               context.registerXROSubobjectSerializer(SrlgSubobject.class, new XROSRLGSubobjectParser());
+               context.registerXROSubobjectSerializer(UnnumberedSubobject.class, new XROUnnumberedInterfaceSubobjectParser());
+               context.registerXROSubobjectSerializer(PathKeySubobject.class, new XROPathKeySubobjectParser());
+
+               final TlvHandlerRegistry tlvReg = context.getTlvHandlerRegistry();
+               context.registerTlvParser(NoPathVectorTlvParser.TYPE, new NoPathVectorTlvParser());
+               context.registerTlvParser(OverloadedDurationTlvParser.TYPE, new OverloadedDurationTlvParser());
+               context.registerTlvParser(ReqMissingTlvParser.TYPE, new ReqMissingTlvParser());
+               context.registerTlvParser(OFListTlvParser.TYPE, new OFListTlvParser());
+               context.registerTlvParser(OrderTlvParser.TYPE, new OrderTlvParser());
+               context.registerTlvParser(PCEStatefulCapabilityTlvParser.TYPE, new PCEStatefulCapabilityTlvParser());
+               context.registerTlvParser(LspSymbolicNameTlvParser.TYPE, new LspSymbolicNameTlvParser());
+               context.registerTlvParser(LSPIdentifierTlvParser.TYPE, new LSPIdentifierTlvParser());
+               context.registerTlvParser(LSPIdentifierTlvParser.TYPE_6, new LSPIdentifierTlvParser());
+               context.registerTlvParser(LspUpdateErrorTlvParser.TYPE, new LspUpdateErrorTlvParser());
+               context.registerTlvParser(RSVPErrorSpecTlvParser.TYPE, new RSVPErrorSpecTlvParser());
+               context.registerTlvParser(LspDbVersionTlvParser.TYPE, new LspDbVersionTlvParser());
+               context.registerTlvParser(PredundancyGroupTlvParser.TYPE, new PredundancyGroupTlvParser());
+
+               context.registerTlvSerializer(NoPathVectorTlv.class, new NoPathVectorTlvParser());
+               context.registerTlvSerializer(OverloadDurationTlv.class, new OverloadedDurationTlvParser());
+               context.registerTlvSerializer(ReqMissingTlv.class, new ReqMissingTlvParser());
+               context.registerTlvSerializer(OfListTlv.class, new OFListTlvParser());
+               context.registerTlvSerializer(OrderTlv.class, new OrderTlvParser());
+               context.registerTlvSerializer(StatefulCapabilityTlv.class, new PCEStatefulCapabilityTlvParser());
+               context.registerTlvSerializer(SymbolicPathNameTlv.class, new LspSymbolicNameTlvParser());
+               context.registerTlvSerializer(LspIdentifiersTlv.class, new LSPIdentifierTlvParser());
+               context.registerTlvSerializer(LspErrorCodeTlv.class, new LspUpdateErrorTlvParser());
+               context.registerTlvSerializer(RsvpErrorSpecTlv.class, new RSVPErrorSpecTlvParser());
+               context.registerTlvSerializer(LspDbVersionTlv.class, new LspDbVersionTlvParser());
+               context.registerTlvSerializer(PredundancyGroupIdTlv.class, new PredundancyGroupTlvParser());
+
+               final ObjectHandlerRegistry objReg = context.getObjectHandlerRegistry();
+               context.registerObjectParser(PCEPOpenObjectParser.CLASS, PCEPOpenObjectParser.TYPE, new PCEPOpenObjectParser(tlvReg));
+               context.registerObjectParser(PCEPRequestParameterObjectParser.CLASS, PCEPRequestParameterObjectParser.TYPE,
+                               new PCEPRequestParameterObjectParser(tlvReg));
+               context.registerObjectParser(PCEPNoPathObjectParser.CLASS, PCEPNoPathObjectParser.TYPE, new PCEPNoPathObjectParser(tlvReg));
+               context.registerObjectParser(PCEPEndPointsObjectParser.CLASS, PCEPEndPointsObjectParser.TYPE, new PCEPEndPointsObjectParser(tlvReg));
+               context.registerObjectParser(PCEPEndPointsObjectParser.CLASS_6, PCEPEndPointsObjectParser.TYPE_6,
+                               new PCEPEndPointsObjectParser(tlvReg));
+               context.registerObjectParser(PCEPBandwidthObjectParser.CLASS, PCEPBandwidthObjectParser.TYPE, new PCEPBandwidthObjectParser(tlvReg));
+               context.registerObjectParser(PCEPBandwidthObjectParser.E_CLASS, PCEPBandwidthObjectParser.E_TYPE,
+                               new PCEPBandwidthObjectParser(tlvReg));
+               context.registerObjectParser(PCEPMetricObjectParser.CLASS, PCEPMetricObjectParser.TYPE, new PCEPMetricObjectParser(tlvReg));
+
+               context.registerObjectParser(PCEPExplicitRouteObjectParser.CLASS, PCEPExplicitRouteObjectParser.TYPE,
+                               new PCEPExplicitRouteObjectParser(eroSubReg));
+               context.registerObjectParser(PCEPReportedRouteObjectParser.CLASS, PCEPReportedRouteObjectParser.TYPE,
+                               new PCEPReportedRouteObjectParser(rroSubReg));
+               context.registerObjectParser(PCEPLspaObjectParser.CLASS, PCEPLspaObjectParser.TYPE, new PCEPLspaObjectParser(tlvReg));
+               context.registerObjectParser(PCEPIncludeRouteObjectParser.CLASS, PCEPIncludeRouteObjectParser.TYPE,
+                               new PCEPIncludeRouteObjectParser(eroSubReg));
+               context.registerObjectParser(PCEPSvecObjectParser.CLASS, PCEPSvecObjectParser.TYPE, new PCEPSvecObjectParser(tlvReg));
+               context.registerObjectParser(PCEPNotificationObjectParser.CLASS, PCEPNotificationObjectParser.TYPE,
+                               new PCEPNotificationObjectParser(tlvReg));
+               context.registerObjectParser(PCEPErrorObjectParser.CLASS, PCEPErrorObjectParser.TYPE, new PCEPErrorObjectParser(tlvReg));
+               context.registerObjectParser(PCEPLoadBalancingObjectParser.CLASS, PCEPLoadBalancingObjectParser.TYPE,
+                               new PCEPLoadBalancingObjectParser(tlvReg));
+               context.registerObjectParser(PCEPCloseObjectParser.CLASS, PCEPCloseObjectParser.TYPE, new PCEPCloseObjectParser(tlvReg));
+               context.registerObjectParser(PCEPPathKeyObjectParser.CLASS, PCEPPathKeyObjectParser.TYPE, new PCEPPathKeyObjectParser(tlvReg));
+               context.registerObjectParser(PCEPObjectiveFunctionObjectParser.CLASS, PCEPObjectiveFunctionObjectParser.TYPE,
+                               new PCEPObjectiveFunctionObjectParser(tlvReg));
+               context.registerObjectParser(PCEPClassTypeObjectParser.CLASS, PCEPClassTypeObjectParser.TYPE, new PCEPClassTypeObjectParser(tlvReg));
+
+               context.registerObjectParser(PCEPGlobalConstraintsObjectParser.CLASS, PCEPGlobalConstraintsObjectParser.TYPE,
+                               new PCEPGlobalConstraintsObjectParser(tlvReg));
+               context.registerObjectParser(PCEPLspObjectParser.CLASS, PCEPLspObjectParser.TYPE, new PCEPLspObjectParser(tlvReg));
+               context.registerObjectParser(PCEPSrpObjectParser.CLASS, PCEPSrpObjectParser.TYPE, new PCEPSrpObjectParser(tlvReg));
+               context.registerObjectParser(PCEPExcludeRouteObjectParser.CLASS, PCEPExcludeRouteObjectParser.TYPE,
+                               new PCEPExcludeRouteObjectParser(xroSubReg));
+
+               context.registerObjectSerializer(OpenObject.class, new PCEPOpenObjectParser(tlvReg));
+               context.registerObjectSerializer(RpObject.class, new PCEPRequestParameterObjectParser(tlvReg));
+               context.registerObjectSerializer(NoPathObject.class, new PCEPNoPathObjectParser(tlvReg));
+               context.registerObjectSerializer(EndpointsObject.class, new PCEPEndPointsObjectParser(tlvReg));
+               context.registerObjectSerializer(BandwidthObject.class, new PCEPBandwidthObjectParser(tlvReg));
+               context.registerObjectSerializer(MetricObject.class, new PCEPMetricObjectParser(tlvReg));
+               context.registerObjectSerializer(ExplicitRouteObject.class, new PCEPExplicitRouteObjectParser(eroSubReg));
+               context.registerObjectSerializer(ReportedRouteObject.class, new PCEPReportedRouteObjectParser(rroSubReg));
+               context.registerObjectSerializer(LspaObject.class, new PCEPLspaObjectParser(tlvReg));
+               context.registerObjectSerializer(IncludeRouteObject.class, new PCEPIncludeRouteObjectParser(eroSubReg));
+               context.registerObjectSerializer(SvecObject.class, new PCEPSvecObjectParser(tlvReg));
+               context.registerObjectSerializer(NotificationObject.class, new PCEPNotificationObjectParser(tlvReg));
+               context.registerObjectSerializer(PcepErrorObject.class, new PCEPErrorObjectParser(tlvReg));
+               context.registerObjectSerializer(LoadBalancingObject.class, new PCEPLoadBalancingObjectParser(tlvReg));
+               context.registerObjectSerializer(CloseObject.class, new PCEPCloseObjectParser(tlvReg));
+               context.registerObjectSerializer(PathKeyObject.class, new PCEPPathKeyObjectParser(tlvReg));
+               context.registerObjectSerializer(OfObject.class, new PCEPObjectiveFunctionObjectParser(tlvReg));
+               context.registerObjectSerializer(ClasstypeObject.class, new PCEPClassTypeObjectParser(tlvReg));
+               context.registerObjectSerializer(GcObject.class, new PCEPGlobalConstraintsObjectParser(tlvReg));
+               context.registerObjectSerializer(LspObject.class, new PCEPLspObjectParser(tlvReg));
+               context.registerObjectSerializer(SrpObject.class, new PCEPSrpObjectParser(tlvReg));
+               context.registerObjectSerializer(ExcludeRouteObject.class, new PCEPExcludeRouteObjectParser(xroSubReg));
+
+               context.registerMessageParser(PCEPOpenMessageParser.TYPE, new PCEPOpenMessageParser(objReg));
+               context.registerMessageParser(PCEPKeepAliveMessageParser.TYPE, new PCEPKeepAliveMessageParser(objReg));
+               context.registerMessageParser(PCEPReplyMessageParser.TYPE, new PCEPReplyMessageParser(objReg));
+               context.registerMessageParser(PCEPRequestMessageParser.TYPE, new PCEPRequestMessageParser(objReg));
+               context.registerMessageParser(PCEPErrorMessageParser.TYPE, new PCEPErrorMessageParser(objReg));
+               context.registerMessageParser(PCEPCloseMessageParser.TYPE, new PCEPCloseMessageParser(objReg));
+               context.registerMessageParser(PCEPUpdateRequestMessageParser.TYPE, new PCEPUpdateRequestMessageParser(objReg));
+               context.registerMessageParser(PCEPReportMessageParser.TYPE, new PCEPReportMessageParser(objReg));
+               context.registerMessageParser(PCCreateMessageParser.TYPE, new PCCreateMessageParser(objReg));
+
+               context.registerMessageSerializer(OpenMessage.class, new PCEPOpenMessageParser(objReg));
+               context.registerMessageSerializer(PcntfMessage.class, new PCEPNotificationMessageParser(objReg));
+               context.registerMessageSerializer(KeepaliveMessage.class, new PCEPKeepAliveMessageParser(objReg));
+               context.registerMessageSerializer(PcrepMessage.class, new PCEPReplyMessageParser(objReg));
+               context.registerMessageSerializer(PcreqMessage.class, new PCEPRequestMessageParser(objReg));
+               context.registerMessageSerializer(PcerrMessage.class, new PCEPErrorMessageParser(objReg));
+               context.registerMessageSerializer(CloseMessage.class, new PCEPCloseMessageParser(objReg));
+               context.registerMessageSerializer(PcupdMessage.class, new PCEPUpdateRequestMessageParser(objReg));
+               context.registerMessageSerializer(PcrptMessage.class, new PCEPReportMessageParser(objReg));
+               context.registerMessageSerializer(PcinitiateMessage.class, new PCCreateMessageParser(objReg));
+
+               this.registrations = regs;
+       }
+
+       @Override
+       public void stop() {
+               Preconditions.checkState(this.registrations != null);
+
+               for (final AutoCloseable r : this.registrations) {
+                       try {
+                               r.close();
+                       } catch (final Exception e) {
+                               logger.warn("Failed to close registration", e);
+                       }
+               }
+
+               this.registrations = null;
+       }
+}
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/BundleActivator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/BundleActivator.java
new file mode 100644 (file)
index 0000000..7318b7f
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.impl;
+
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
+import org.opendaylight.protocol.pcep.spi.osgi.AbstractOSGiPCEPExtensionProviderActivator;
+
+public final class BundleActivator extends AbstractOSGiPCEPExtensionProviderActivator {
+       private final PCEPExtensionProviderActivator activator = new Activator();
+
+       @Override
+       public void start(final PCEPExtensionProviderContext context) throws Exception {
+               activator.start(context);
+       }
+
+       @Override
+       public void stop() throws Exception {
+               activator.stop();
+       }
+}
index 8e39d4f84412ca905c8b26a83086da5ab25413ff..0e3351fd8b1a0bb2358e1c8157d32abdf455fa9b 100644 (file)
@@ -19,6 +19,7 @@ import org.opendaylight.protocol.framework.SessionListenerFactory;
 import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
 import org.opendaylight.protocol.pcep.PCEPDispatcher;
 import org.opendaylight.protocol.pcep.PCEPSessionListener;
+import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
 
 import com.google.common.base.Preconditions;
@@ -29,17 +30,17 @@ import com.google.common.base.Preconditions;
 public class PCEPDispatcherImpl extends AbstractDispatcher<PCEPSessionImpl, PCEPSessionListener> implements PCEPDispatcher {
 
        private final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> snf;
-
-       private final PCEPHandlerFactory hf = new PCEPHandlerFactory(SingletonPCEPProviderContext.getInstance().getMessageHandlerRegistry());
+       private final PCEPHandlerFactory hf;
 
        /**
         * Creates an instance of PCEPDispatcherImpl, gets the default selector and opens it.
         * 
         * @throws IOException if some error occurred during opening the selector
         */
-       public PCEPDispatcherImpl(final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory) {
+       public PCEPDispatcherImpl(final MessageHandlerRegistry registry, final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory) {
                super();
                this.snf = Preconditions.checkNotNull(negotiatorFactory);
+               this.hf = new PCEPHandlerFactory(registry);
        }
 
        @Override
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPImplActivator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPImplActivator.java
deleted file mode 100644 (file)
index 6772c4a..0000000
+++ /dev/null
@@ -1,339 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.pcep.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.opendaylight.protocol.pcep.impl.message.PCCreateMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPCloseMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPErrorMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPKeepAliveMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPNotificationMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPOpenMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPReplyMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPReportMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPRequestMessageParser;
-import org.opendaylight.protocol.pcep.impl.message.PCEPUpdateRequestMessageParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPBandwidthObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPClassTypeObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPCloseObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPExcludeRouteObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPExplicitRouteObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPGlobalConstraintsObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPIncludeRouteObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPLspObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPLspaObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPMetricObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPNoPathObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPNotificationObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPObjectiveFunctionObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPPathKeyObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPReportedRouteObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPSrpObjectParser;
-import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.EROAsNumberSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.EROIpPrefixSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.EROLabelSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.EROPathKeySubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.EROUnnumberedInterfaceSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.GeneralizedLabelChannelSetParser;
-import org.opendaylight.protocol.pcep.impl.subobject.GeneralizedLabelParser;
-import org.opendaylight.protocol.pcep.impl.subobject.RROAsNumberSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.RROIpPrefixSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.RROLabelSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.RROPathKeySubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.RROUnnumberedInterfaceSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.Type1LabelParser;
-import org.opendaylight.protocol.pcep.impl.subobject.WavebandSwitchingLabelParser;
-import org.opendaylight.protocol.pcep.impl.subobject.XROAsNumberSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.XROIpPrefixSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.XROPathKeySubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.XROSRLGSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.XROUnnumberedInterfaceSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.tlv.LSPIdentifierIPv4TlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.LSPIdentifierIPv6TlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.LspDbVersionTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.LspSymbolicNameTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.LspUpdateErrorTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.NoPathVectorTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.OFListTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.OrderTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.OverloadedDurationTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.PCEStatefulCapabilityTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.PredundancyGroupTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.RSVPErrorSpecTlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.ReqMissingTlvParser;
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.PCEPProviderActivator;
-import org.opendaylight.protocol.pcep.spi.PCEPProviderContext;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.BandwidthObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClasstypeObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.EndpointsObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExcludeRouteObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExplicitRouteObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.GcObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.IncludeRouteObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.KeepaliveMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LoadBalancingObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspDbVersionTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspErrorCodeTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspaObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.MetricObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NotificationObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfListTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OrderTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OverloadDurationTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeyObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeySubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcepErrorObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcerrMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcinitiateMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcntfMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcrepMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcreqMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcrptMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcupdMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PredundancyGroupIdTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ReportedRouteObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ReqMissingTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RpObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RsvpErrorSpecTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.StatefulCapabilityTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SvecObject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SymbolicPathNameTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AsNumberSubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.GeneralizedChannelSetLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.GeneralizedLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.IpPrefixSubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LabelSubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.SrlgSubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Type1Label;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.UnnumberedSubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.WavebandSwitchingLabel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Preconditions;
-
-public final class PCEPImplActivator implements PCEPProviderActivator {
-       private static final Logger logger = LoggerFactory.getLogger(PCEPImplActivator.class);
-       private List<AutoCloseable> registrations;
-
-       @Override
-       public void start(final PCEPProviderContext context) {
-               Preconditions.checkState(this.registrations == null);
-               final List<AutoCloseable> regs = new ArrayList<>();
-
-               final LabelHandlerRegistry labelReg = context.getLabelHandlerRegistry();
-               labelReg.registerLabelParser(Type1LabelParser.CTYPE, new Type1LabelParser());
-               labelReg.registerLabelParser(GeneralizedLabelParser.CTYPE, new GeneralizedLabelParser());
-               labelReg.registerLabelParser(WavebandSwitchingLabelParser.CTYPE, new WavebandSwitchingLabelParser());
-               labelReg.registerLabelParser(GeneralizedLabelChannelSetParser.CTYPE, new GeneralizedLabelChannelSetParser());
-
-               labelReg.registerLabelSerializer(Type1Label.class, new Type1LabelParser());
-               labelReg.registerLabelSerializer(GeneralizedLabel.class, new GeneralizedLabelParser());
-               labelReg.registerLabelSerializer(WavebandSwitchingLabel.class, new WavebandSwitchingLabelParser());
-               labelReg.registerLabelSerializer(GeneralizedChannelSetLabel.class, new GeneralizedLabelChannelSetParser());
-
-               final EROSubobjectHandlerRegistry eroSubReg = context.getEROSubobjectHandlerRegistry();
-               eroSubReg.registerSubobjectParser(EROIpPrefixSubobjectParser.TYPE, new EROIpPrefixSubobjectParser());
-               eroSubReg.registerSubobjectParser(EROIpPrefixSubobjectParser.TYPE6, new EROIpPrefixSubobjectParser());
-               eroSubReg.registerSubobjectParser(EROAsNumberSubobjectParser.TYPE, new EROAsNumberSubobjectParser());
-               eroSubReg.registerSubobjectParser(EROLabelSubobjectParser.TYPE, new EROLabelSubobjectParser(labelReg));
-               eroSubReg.registerSubobjectParser(EROUnnumberedInterfaceSubobjectParser.TYPE, new EROUnnumberedInterfaceSubobjectParser());
-               eroSubReg.registerSubobjectParser(EROPathKeySubobjectParser.TYPE, new EROPathKeySubobjectParser());
-               eroSubReg.registerSubobjectParser(EROPathKeySubobjectParser.TYPE128, new EROPathKeySubobjectParser());
-
-               eroSubReg.registerSubobjectSerializer(IpPrefixSubobject.class, new EROIpPrefixSubobjectParser());
-               eroSubReg.registerSubobjectSerializer(AsNumberSubobject.class, new EROAsNumberSubobjectParser());
-               eroSubReg.registerSubobjectSerializer(LabelSubobject.class, new EROLabelSubobjectParser(labelReg));
-               eroSubReg.registerSubobjectSerializer(UnnumberedSubobject.class, new EROUnnumberedInterfaceSubobjectParser());
-               eroSubReg.registerSubobjectSerializer(PathKeySubobject.class, new EROPathKeySubobjectParser());
-
-               final RROSubobjectHandlerRegistry rroSubReg = context.getRROSubobjectHandlerRegistry();
-               rroSubReg.registerSubobjectParser(RROIpPrefixSubobjectParser.TYPE, new RROIpPrefixSubobjectParser());
-               rroSubReg.registerSubobjectParser(RROIpPrefixSubobjectParser.TYPE6, new RROIpPrefixSubobjectParser());
-               rroSubReg.registerSubobjectParser(RROLabelSubobjectParser.TYPE, new RROLabelSubobjectParser(labelReg));
-               rroSubReg.registerSubobjectParser(RROAsNumberSubobjectParser.TYPE, new RROAsNumberSubobjectParser());
-               rroSubReg.registerSubobjectParser(RROUnnumberedInterfaceSubobjectParser.TYPE, new RROUnnumberedInterfaceSubobjectParser());
-               rroSubReg.registerSubobjectParser(RROPathKeySubobjectParser.TYPE, new RROPathKeySubobjectParser());
-               rroSubReg.registerSubobjectParser(RROPathKeySubobjectParser.TYPE128, new RROPathKeySubobjectParser());
-
-               rroSubReg.registerSubobjectSerializer(IpPrefixSubobject.class, new RROIpPrefixSubobjectParser());
-               rroSubReg.registerSubobjectSerializer(LabelSubobject.class, new RROLabelSubobjectParser(labelReg));
-               rroSubReg.registerSubobjectSerializer(AsNumberSubobject.class, new RROAsNumberSubobjectParser());
-               rroSubReg.registerSubobjectSerializer(UnnumberedSubobject.class, new RROUnnumberedInterfaceSubobjectParser());
-               rroSubReg.registerSubobjectSerializer(PathKeySubobject.class, new RROPathKeySubobjectParser());
-
-               final XROSubobjectHandlerRegistry xroSubReg = context.getXROSubobjectHandlerRegistry();
-               xroSubReg.registerSubobjectParser(XROIpPrefixSubobjectParser.TYPE, new XROIpPrefixSubobjectParser());
-               xroSubReg.registerSubobjectParser(XROIpPrefixSubobjectParser.TYPE6, new XROIpPrefixSubobjectParser());
-               xroSubReg.registerSubobjectParser(XROAsNumberSubobjectParser.TYPE, new XROAsNumberSubobjectParser());
-               xroSubReg.registerSubobjectParser(XROSRLGSubobjectParser.TYPE, new XROSRLGSubobjectParser());
-               xroSubReg.registerSubobjectParser(XROUnnumberedInterfaceSubobjectParser.TYPE, new XROUnnumberedInterfaceSubobjectParser());
-               xroSubReg.registerSubobjectParser(XROPathKeySubobjectParser.TYPE, new XROPathKeySubobjectParser());
-               xroSubReg.registerSubobjectParser(XROPathKeySubobjectParser.TYPE128, new XROPathKeySubobjectParser());
-
-               xroSubReg.registerSubobjectSerializer(IpPrefixSubobject.class, new XROIpPrefixSubobjectParser());
-               xroSubReg.registerSubobjectSerializer(AsNumberSubobject.class, new XROAsNumberSubobjectParser());
-               xroSubReg.registerSubobjectSerializer(SrlgSubobject.class, new XROSRLGSubobjectParser());
-               xroSubReg.registerSubobjectSerializer(UnnumberedSubobject.class, new XROUnnumberedInterfaceSubobjectParser());
-               xroSubReg.registerSubobjectSerializer(PathKeySubobject.class, new XROPathKeySubobjectParser());
-
-               final TlvHandlerRegistry tlvReg = context.getTlvHandlerRegistry();
-               tlvReg.registerTlvParser(NoPathVectorTlvParser.TYPE, new NoPathVectorTlvParser());
-               tlvReg.registerTlvParser(OverloadedDurationTlvParser.TYPE, new OverloadedDurationTlvParser());
-               tlvReg.registerTlvParser(ReqMissingTlvParser.TYPE, new ReqMissingTlvParser());
-               tlvReg.registerTlvParser(OFListTlvParser.TYPE, new OFListTlvParser());
-               tlvReg.registerTlvParser(OrderTlvParser.TYPE, new OrderTlvParser());
-               tlvReg.registerTlvParser(PCEStatefulCapabilityTlvParser.TYPE, new PCEStatefulCapabilityTlvParser());
-               tlvReg.registerTlvParser(LspSymbolicNameTlvParser.TYPE, new LspSymbolicNameTlvParser());
-               tlvReg.registerTlvParser(LSPIdentifierIPv4TlvParser.TYPE, new LSPIdentifierIPv4TlvParser());
-               tlvReg.registerTlvParser(LSPIdentifierIPv6TlvParser.TYPE, new LSPIdentifierIPv6TlvParser());
-               tlvReg.registerTlvParser(LspUpdateErrorTlvParser.TYPE, new LspUpdateErrorTlvParser());
-               tlvReg.registerTlvParser(RSVPErrorSpecTlvParser.TYPE, new RSVPErrorSpecTlvParser());
-               tlvReg.registerTlvParser(LspDbVersionTlvParser.TYPE, new LspDbVersionTlvParser());
-               tlvReg.registerTlvParser(PredundancyGroupTlvParser.TYPE, new PredundancyGroupTlvParser());
-
-               tlvReg.registerTlvSerializer(NoPathVectorTlv.class, new NoPathVectorTlvParser());
-               tlvReg.registerTlvSerializer(OverloadDurationTlv.class, new OverloadedDurationTlvParser());
-               tlvReg.registerTlvSerializer(ReqMissingTlv.class, new ReqMissingTlvParser());
-               tlvReg.registerTlvSerializer(OfListTlv.class, new OFListTlvParser());
-               tlvReg.registerTlvSerializer(OrderTlv.class, new OrderTlvParser());
-               tlvReg.registerTlvSerializer(StatefulCapabilityTlv.class, new PCEStatefulCapabilityTlvParser());
-               tlvReg.registerTlvSerializer(SymbolicPathNameTlv.class, new LspSymbolicNameTlvParser());
-               tlvReg.registerTlvSerializer(LspIdentifiersTlv.class, new LSPIdentifierIPv4TlvParser());
-               tlvReg.registerTlvSerializer(LspErrorCodeTlv.class, new LspUpdateErrorTlvParser());
-               tlvReg.registerTlvSerializer(RsvpErrorSpecTlv.class, new RSVPErrorSpecTlvParser());
-               tlvReg.registerTlvSerializer(LspDbVersionTlv.class, new LspDbVersionTlvParser());
-               tlvReg.registerTlvSerializer(PredundancyGroupIdTlv.class, new PredundancyGroupTlvParser());
-
-               final ObjectHandlerRegistry objReg = context.getObjectHandlerRegistry();
-               objReg.registerObjectParser(PCEPOpenObjectParser.CLASS, PCEPOpenObjectParser.TYPE, new PCEPOpenObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPRequestParameterObjectParser.CLASS, PCEPRequestParameterObjectParser.TYPE,
-                               new PCEPRequestParameterObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPNoPathObjectParser.CLASS, PCEPNoPathObjectParser.TYPE, new PCEPNoPathObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPEndPointsObjectParser.CLASS, PCEPEndPointsObjectParser.TYPE, new PCEPEndPointsObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPEndPointsObjectParser.CLASS_6, PCEPEndPointsObjectParser.TYPE_6,
-                               new PCEPEndPointsObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPBandwidthObjectParser.CLASS, PCEPBandwidthObjectParser.TYPE, new PCEPBandwidthObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPBandwidthObjectParser.E_CLASS, PCEPBandwidthObjectParser.E_TYPE,
-                               new PCEPBandwidthObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPMetricObjectParser.CLASS, PCEPMetricObjectParser.TYPE, new PCEPMetricObjectParser(tlvReg));
-
-               objReg.registerObjectParser(PCEPExplicitRouteObjectParser.CLASS, PCEPExplicitRouteObjectParser.TYPE,
-                               new PCEPExplicitRouteObjectParser(eroSubReg));
-               objReg.registerObjectParser(PCEPReportedRouteObjectParser.CLASS, PCEPReportedRouteObjectParser.TYPE,
-                               new PCEPReportedRouteObjectParser(rroSubReg));
-               objReg.registerObjectParser(PCEPLspaObjectParser.CLASS, PCEPLspaObjectParser.TYPE, new PCEPLspaObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPIncludeRouteObjectParser.CLASS, PCEPIncludeRouteObjectParser.TYPE,
-                               new PCEPIncludeRouteObjectParser(eroSubReg));
-               objReg.registerObjectParser(PCEPSvecObjectParser.CLASS, PCEPSvecObjectParser.TYPE, new PCEPSvecObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPNotificationObjectParser.CLASS, PCEPNotificationObjectParser.TYPE,
-                               new PCEPNotificationObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPErrorObjectParser.CLASS, PCEPErrorObjectParser.TYPE, new PCEPErrorObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPLoadBalancingObjectParser.CLASS, PCEPLoadBalancingObjectParser.TYPE,
-                               new PCEPLoadBalancingObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPCloseObjectParser.CLASS, PCEPCloseObjectParser.TYPE, new PCEPCloseObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPPathKeyObjectParser.CLASS, PCEPPathKeyObjectParser.TYPE, new PCEPPathKeyObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPObjectiveFunctionObjectParser.CLASS, PCEPObjectiveFunctionObjectParser.TYPE,
-                               new PCEPObjectiveFunctionObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPClassTypeObjectParser.CLASS, PCEPClassTypeObjectParser.TYPE, new PCEPClassTypeObjectParser(tlvReg));
-
-               objReg.registerObjectParser(PCEPGlobalConstraintsObjectParser.CLASS, PCEPGlobalConstraintsObjectParser.TYPE,
-                               new PCEPGlobalConstraintsObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPLspObjectParser.CLASS, PCEPLspObjectParser.TYPE, new PCEPLspObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPSrpObjectParser.CLASS, PCEPSrpObjectParser.TYPE, new PCEPSrpObjectParser(tlvReg));
-               objReg.registerObjectParser(PCEPExcludeRouteObjectParser.CLASS, PCEPExcludeRouteObjectParser.TYPE,
-                               new PCEPExcludeRouteObjectParser(xroSubReg));
-
-               objReg.registerObjectSerializer(OpenObject.class, new PCEPOpenObjectParser(tlvReg));
-               objReg.registerObjectSerializer(RpObject.class, new PCEPRequestParameterObjectParser(tlvReg));
-               objReg.registerObjectSerializer(NoPathObject.class, new PCEPNoPathObjectParser(tlvReg));
-               objReg.registerObjectSerializer(EndpointsObject.class, new PCEPEndPointsObjectParser(tlvReg));
-               objReg.registerObjectSerializer(BandwidthObject.class, new PCEPBandwidthObjectParser(tlvReg));
-               objReg.registerObjectSerializer(MetricObject.class, new PCEPMetricObjectParser(tlvReg));
-               objReg.registerObjectSerializer(ExplicitRouteObject.class, new PCEPExplicitRouteObjectParser(eroSubReg));
-               objReg.registerObjectSerializer(ReportedRouteObject.class, new PCEPReportedRouteObjectParser(rroSubReg));
-               objReg.registerObjectSerializer(LspaObject.class, new PCEPLspaObjectParser(tlvReg));
-               objReg.registerObjectSerializer(IncludeRouteObject.class, new PCEPIncludeRouteObjectParser(eroSubReg));
-               objReg.registerObjectSerializer(SvecObject.class, new PCEPSvecObjectParser(tlvReg));
-               objReg.registerObjectSerializer(NotificationObject.class, new PCEPNotificationObjectParser(tlvReg));
-               objReg.registerObjectSerializer(PcepErrorObject.class, new PCEPErrorObjectParser(tlvReg));
-               objReg.registerObjectSerializer(LoadBalancingObject.class, new PCEPLoadBalancingObjectParser(tlvReg));
-               objReg.registerObjectSerializer(CloseObject.class, new PCEPCloseObjectParser(tlvReg));
-               objReg.registerObjectSerializer(PathKeyObject.class, new PCEPPathKeyObjectParser(tlvReg));
-               objReg.registerObjectSerializer(OfObject.class, new PCEPObjectiveFunctionObjectParser(tlvReg));
-               objReg.registerObjectSerializer(ClasstypeObject.class, new PCEPClassTypeObjectParser(tlvReg));
-               objReg.registerObjectSerializer(GcObject.class, new PCEPGlobalConstraintsObjectParser(tlvReg));
-               objReg.registerObjectSerializer(LspObject.class, new PCEPLspObjectParser(tlvReg));
-               objReg.registerObjectSerializer(SrpObject.class, new PCEPSrpObjectParser(tlvReg));
-               objReg.registerObjectSerializer(ExcludeRouteObject.class, new PCEPExcludeRouteObjectParser(xroSubReg));
-
-               final MessageHandlerRegistry msgReg = context.getMessageHandlerRegistry();
-               msgReg.registerMessageParser(PCEPOpenMessageParser.TYPE, new PCEPOpenMessageParser(objReg));
-               msgReg.registerMessageParser(PCEPKeepAliveMessageParser.TYPE, new PCEPKeepAliveMessageParser(objReg));
-               msgReg.registerMessageParser(PCEPReplyMessageParser.TYPE, new PCEPReplyMessageParser(objReg));
-               msgReg.registerMessageParser(PCEPRequestMessageParser.TYPE, new PCEPRequestMessageParser(objReg));
-               msgReg.registerMessageParser(PCEPErrorMessageParser.TYPE, new PCEPErrorMessageParser(objReg));
-               msgReg.registerMessageParser(PCEPCloseMessageParser.TYPE, new PCEPCloseMessageParser(objReg));
-               msgReg.registerMessageParser(PCEPUpdateRequestMessageParser.TYPE, new PCEPUpdateRequestMessageParser(objReg));
-               msgReg.registerMessageParser(PCEPReportMessageParser.TYPE, new PCEPReportMessageParser(objReg));
-               msgReg.registerMessageParser(PCCreateMessageParser.TYPE, new PCCreateMessageParser(objReg));
-
-               msgReg.registerMessageSerializer(OpenMessage.class, new PCEPOpenMessageParser(objReg));
-               msgReg.registerMessageSerializer(PcntfMessage.class, new PCEPNotificationMessageParser(objReg));
-               msgReg.registerMessageSerializer(KeepaliveMessage.class, new PCEPKeepAliveMessageParser(objReg));
-               msgReg.registerMessageSerializer(PcrepMessage.class, new PCEPReplyMessageParser(objReg));
-               msgReg.registerMessageSerializer(PcreqMessage.class, new PCEPRequestMessageParser(objReg));
-               msgReg.registerMessageSerializer(PcerrMessage.class, new PCEPErrorMessageParser(objReg));
-               msgReg.registerMessageSerializer(CloseMessage.class, new PCEPCloseMessageParser(objReg));
-               msgReg.registerMessageSerializer(PcupdMessage.class, new PCEPUpdateRequestMessageParser(objReg));
-               msgReg.registerMessageSerializer(PcrptMessage.class, new PCEPReportMessageParser(objReg));
-               msgReg.registerMessageSerializer(PcinitiateMessage.class, new PCCreateMessageParser(objReg));
-
-               this.registrations = regs;
-       }
-
-       @Override
-       public void stop() {
-               Preconditions.checkState(this.registrations != null);
-
-               for (final AutoCloseable r : this.registrations) {
-                       try {
-                               r.close();
-                       } catch (final Exception e) {
-                               logger.warn("Failed to close registration", e);
-                       }
-               }
-
-               this.registrations = null;
-       }
-}
index 1bc18098700dd544dcfed15f98e7f9deb9e4cdaf..883e4563b8e4286e39d8a8531df4efbd8830d146 100644 (file)
@@ -121,7 +121,7 @@ public final class PCEPMessageFactory implements ProtocolMessageFactory<Message>
                final byte[] retBytes = new byte[headerBytes.length + msgBody.length];
 
                ByteArray.copyWhole(headerBytes, retBytes, 0);
-               ByteArray.copyWhole(msgBody, retBytes, PCEPMessageHeader.COMMON_HEADER_LENGTH);
+               ByteArray.copyWhole(msgBody, retBytes, COMMON_HEADER_LENGTH);
 
                return retBytes;
        }
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageHeader.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageHeader.java
deleted file mode 100644 (file)
index 5589ea9..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.pcep.impl;
-
-import java.util.Arrays;
-
-import org.opendaylight.protocol.util.ByteArray;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.primitives.UnsignedBytes;
-
-/**
- * Header parser for {@link org.opendaylight.protocol.pcep.PCEPMessage PCEPMessage}
- */
-public final class PCEPMessageHeader {
-
-       public static final Logger logger = LoggerFactory.getLogger(PCEPMessageHeader.class);
-
-       /*
-        * lengths of fields in bytes
-        */
-       private static final int VER_FLAGS_MF_LENGTH = 1;
-       private static final int TYPE_F_LENGTH = 1;
-       private static final int LENGTH_F_LENGTH = 2;
-
-       /*
-        * lengths of subfields inside multi-field in bits
-        */
-       private static final int VERSION_SF_LENGTH = 3;
-
-       /*
-        * offsets of field in bytes
-        */
-       private static final int VER_FLAGS_MF_OFFSET = 0;
-       private static final int TYPE_F_OFFSET = VER_FLAGS_MF_LENGTH + VER_FLAGS_MF_OFFSET;
-       private static final int LENGTH_F_OFFSET = TYPE_F_LENGTH + TYPE_F_OFFSET;
-
-       /*
-        * offsets of subfields inside multi-filed in bits
-        */
-
-       private static final int VERSION_SF_OFFSET = 0;
-
-       /*
-        * COMMON HEADER LENGTH
-        */
-       public static final int COMMON_HEADER_LENGTH = VER_FLAGS_MF_LENGTH + TYPE_F_LENGTH + LENGTH_F_LENGTH;
-
-       private final int type;
-       private final int length;
-       private final int version;
-
-       public PCEPMessageHeader(final int type, final int length, final int version) {
-               this.type = type;
-               this.length = length;
-               this.version = version;
-       }
-
-       public static PCEPMessageHeader fromBytes(final byte[] bytes) {
-               if (bytes == null) {
-                       throw new IllegalArgumentException("Array of bytes is mandatory");
-               }
-
-               logger.trace("Attempt to parse message header: {}", ByteArray.bytesToHexString(bytes));
-
-               if (bytes.length < COMMON_HEADER_LENGTH) {
-                       throw new IllegalArgumentException("Too few bytes in passed array. Passed: " + bytes.length + "; Expected: >= " + COMMON_HEADER_LENGTH + ".");
-               }
-
-               final int type = UnsignedBytes.toInt(bytes[TYPE_F_OFFSET]);
-
-               final int length = ByteArray.bytesToInt(Arrays.copyOfRange(bytes,
-                               LENGTH_F_OFFSET, LENGTH_F_OFFSET + LENGTH_F_LENGTH));
-
-               final int version = ByteArray.copyBitsRange(bytes[VER_FLAGS_MF_OFFSET], VERSION_SF_OFFSET, VERSION_SF_LENGTH);
-
-               final PCEPMessageHeader ret = new PCEPMessageHeader(type, length, version);
-
-               logger.trace("Message header was parsed. {}", ret);
-               return ret;
-       }
-
-       public byte[] toBytes() {
-               final byte[] retBytes = new byte[COMMON_HEADER_LENGTH];
-
-               // msgVer_Flag
-               retBytes[VER_FLAGS_MF_OFFSET] = (byte) (this.version << (Byte.SIZE - VERSION_SF_LENGTH));
-
-               // msgType
-               retBytes[TYPE_F_OFFSET] = (byte) this.type;
-
-               // msgLength
-               System.arraycopy(ByteArray.intToBytes(this.length), Integer.SIZE / Byte.SIZE - LENGTH_F_LENGTH, retBytes, LENGTH_F_OFFSET, LENGTH_F_LENGTH);
-
-               return retBytes;
-       }
-
-       public int getLength() {
-               return this.length;
-       }
-
-       public int getVersion() {
-               return this.version;
-       }
-
-       public int getType() {
-               return this.type;
-       }
-
-       @Override
-       public String toString() {
-               final StringBuilder builder = new StringBuilder();
-               builder.append("PCEPMessageHeader [type=");
-               builder.append(this.type);
-               builder.append(", length=");
-               builder.append(this.length);
-               builder.append(", version=");
-               builder.append(this.version);
-               builder.append("]");
-               return builder.toString();
-       }
-}
index 47cc916f8ba08d6f6915638c7eb3680bc31f7d93..11de5e9f3ea5920227cf8d1719a629b99c40ef60 100644 (file)
@@ -8,15 +8,19 @@
 package org.opendaylight.protocol.pcep.impl;
 
 import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
 import io.netty.util.Timeout;
 import io.netty.util.Timer;
 import io.netty.util.TimerTask;
 
 import java.io.IOException;
+import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.util.Date;
 import java.util.LinkedList;
 import java.util.Queue;
+import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 
 import org.opendaylight.protocol.framework.AbstractProtocolSession;
@@ -34,6 +38,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.CCloseMessageBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CCloseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Tlvs;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -182,21 +187,30 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
 
        /**
         * Sends message to serialization.
-        * 
+        *
         * @param msg to be sent
         */
        @Override
-       public void sendMessage(final Message msg) {
-               try {
-                       this.channel.writeAndFlush(msg);
-                       this.lastMessageSentAt = System.nanoTime();
-                       if (!(msg instanceof KeepaliveMessage)) {
-                               logger.debug("Sent message: " + msg);
-                       }
-                       this.sentMsgCount++;
-               } catch (final Exception e) {
-                       logger.warn("Message {} was not sent.", msg, e);
+       public Future<Void> sendMessage(final Message msg) {
+               final ChannelFuture f = this.channel.writeAndFlush(msg);
+               this.lastMessageSentAt = System.nanoTime();
+               if (!(msg instanceof KeepaliveMessage)) {
+                       logger.debug("Message enqueued: {}", msg);
                }
+               this.sentMsgCount++;
+
+               f.addListener(new ChannelFutureListener() {
+                       @Override
+                       public void operationComplete(final ChannelFuture arg) {
+                               if (arg.isSuccess()) {
+                                       logger.debug("Message sent to socket: {}", msg);
+                               } else {
+                                       logger.debug("Message not sent: {}", msg, arg.cause());
+                               }
+                       }
+               });
+
+               return f;
        }
 
        /**
@@ -222,6 +236,16 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
                this.channel.close();
        }
 
+       @Override
+       public Tlvs getRemoteTlvs() {
+               return remoteOpen.getTlvs();
+       }
+
+       @Override
+       public InetAddress getRemoteAddress() {
+               return ((InetSocketAddress) this.channel.remoteAddress()).getAddress();
+       }
+
        private synchronized void terminate(final TerminationReason reason) {
                this.listener.onSessionTerminated(this, new PCEPCloseTermination(reason));
                this.closed = true;
@@ -244,7 +268,7 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
 
        /**
         * Sends PCEP Error Message with one PCEPError and Open Object.
-        * 
+        *
         * @param value
         * @param open
         */
@@ -257,7 +281,7 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
         * sent (CAPABILITY_NOT_SUPPORTED) and the method checks if the MAX_UNKNOWN_MSG per minute wasn't overstepped.
         * Second, any other error occurred that is specified by rfc. In this case, the an error message is generated and
         * sent.
-        * 
+        *
         * @param error documented error in RFC5440 or draft
         */
        @VisibleForTesting
@@ -278,7 +302,7 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
        /**
         * Handles incoming message. If the session is up, it notifies the user. The user is notified about every message
         * except KeepAlive.
-        * 
+        *
         * @param msg incoming message
         */
        @Override
@@ -362,10 +386,11 @@ public class PCEPSessionImpl extends AbstractProtocolSession<Message> implements
 
        @Override
        public String getNodeIdentifier() {
-               if (this.remoteOpen.getTlvs() == null)
+               if (this.remoteOpen.getTlvs() == null) {
                        if (this.remoteOpen.getTlvs().getPredundancyGroupId() != null) {
                                return new String(this.remoteOpen.getTlvs().getPredundancyGroupId().getIdentifier());
                        }
+               }
                return "";
        }
 
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SingletonPCEPProviderContext.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SingletonPCEPProviderContext.java
deleted file mode 100644 (file)
index 59b3867..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.pcep.impl;
-
-import javax.annotation.concurrent.ThreadSafe;
-
-import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.PCEPProviderContext;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
-
-/**
- *
- */
-@ThreadSafe
-public final class SingletonPCEPProviderContext implements PCEPProviderContext {
-       private static final class Holder {
-               private static final PCEPProviderContext INSTANCE;
-
-               static {
-                       final PCEPProviderContext pc = new SingletonPCEPProviderContext();
-                       new PCEPImplActivator().start(pc);
-                       INSTANCE = pc;
-               }
-       }
-
-       private final LabelHandlerRegistry labelReg = new SimpleLabelHandlerRegistry();
-       private final MessageHandlerRegistry msgReg = new SimpleMessageHandlerRegistry();
-       private final ObjectHandlerRegistry objReg = new SimpleObjectHandlerRegistry();
-       private final EROSubobjectHandlerRegistry eroSubReg = new SimpleEROSubobjectHandlerFactory();
-       private final RROSubobjectHandlerRegistry rroSubReg = new SimpleRROSubobjectHandlerFactory();
-       private final XROSubobjectHandlerRegistry xroSubReg = new SimpleXROSubobjectHandlerFactory();
-       private final TlvHandlerRegistry tlvReg = new SimpleTlvHandlerRegistry();
-
-       private SingletonPCEPProviderContext() {
-
-       }
-
-       public static PCEPProviderContext getInstance() {
-               return Holder.INSTANCE;
-       }
-
-       @Override
-       public LabelHandlerRegistry getLabelHandlerRegistry() {
-               return labelReg;
-       }
-
-       @Override
-       public MessageHandlerRegistry getMessageHandlerRegistry() {
-               return this.msgReg;
-       }
-
-       @Override
-       public ObjectHandlerRegistry getObjectHandlerRegistry() {
-               return this.objReg;
-       }
-
-       @Override
-       public EROSubobjectHandlerRegistry getEROSubobjectHandlerRegistry() {
-               return this.eroSubReg;
-       }
-
-       @Override
-       public RROSubobjectHandlerRegistry getRROSubobjectHandlerRegistry() {
-               return this.rroSubReg;
-       }
-
-       @Override
-       public XROSubobjectHandlerRegistry getXROSubobjectHandlerRegistry() {
-               return this.xroSubReg;
-       }
-
-       @Override
-       public TlvHandlerRegistry getTlvHandlerRegistry() {
-               return this.tlvReg;
-       }
-}
index 25da97caff3a443ccfeb8afd533f6152579f1abe..546006f3063b145ca1c58d61de7f8160c9e6c941 100644 (file)
@@ -63,10 +63,11 @@ public final class Util {
                final List<IpAddress> addresses = Lists.newArrayList();
 
                while (bytes.length > offset) {
-                       if (family instanceof Ipv4)
+                       if (family instanceof Ipv4) {
                                addresses.add(new IpAddress(Ipv4Util.addressForBytes(ByteArray.subByte(bytes, offset, addrLen))));
-                       else
+                       } else {
                                addresses.add(new IpAddress(Ipv6Util.addressForBytes(ByteArray.subByte(bytes, offset, addrLen))));
+                       }
                        offset += addrLen;
                }
 
@@ -75,26 +76,23 @@ public final class Util {
 
        public static void putAddresses(final byte[] destBytes, int offset, final List<IpAddress> addresses, final int addrLen) {
                for (final IpAddress address : addresses) {
-                       if (address.getIpv4Address() != null)
+                       if (address.getIpv4Address() != null) {
                                System.arraycopy(address.getIpv4Address().getValue().getBytes(), 0, destBytes, offset, addrLen);
-                       else
+                       } else {
                                System.arraycopy(address.getIpv6Address().getValue().getBytes(), 0, destBytes, offset, addrLen);
+                       }
                        offset += addrLen;
                }
        }
 
-       public static int getPadding(final int length, final int padding) {
-               return (padding - (length % padding)) % padding;
-       }
-
        public static Message createErrorMessage(final PCEPErrors e, final OpenObject t) {
                final PcerrBuilder errMessageBuilder = new PcerrBuilder();
                final PCEPErrorMapping mapping = PCEPErrorMapping.getInstance();
                final PCEPErrorIdentifier id = mapping.getFromErrorsEnum(e);
                final Errors err = new ErrorsBuilder().setType(id.type).setValue(id.value).build();
-               if (t == null)
+               if (t == null) {
                        return errMessageBuilder.setPcerrMessage(new PcerrMessageBuilder().setErrors(Arrays.asList(err)).build()).build();
-               else {
+               else {
                        final ErrorType type = new SessionBuilder().setOpen((Open) t).build();
                        return errMessageBuilder.setPcerrMessage(new PcerrMessageBuilder().setErrors(Arrays.asList(err)).setErrorType(type).build()).build();
                }
similarity index 96%
rename from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/AbstractObjectWithTlvsParser.java
rename to pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractObjectWithTlvsParser.java
index 625841d33126fc525d0bfaf1c0885c9f3e918646..4bba7b8315078cffe8b2409cb0b6e50e0ee6277d 100644 (file)
@@ -5,7 +5,7 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.protocol.pcep.impl.message;
+package org.opendaylight.protocol.pcep.impl.object;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.ObjectParser;
@@ -88,7 +88,7 @@ public abstract class AbstractObjectWithTlvsParser<BUILDER> implements ObjectPar
 
        public abstract void addTlv(final BUILDER builder, final Tlv tlv);
 
-       private static int getPadding(final int length, final int padding) {
+       protected static int getPadding(final int length, final int padding) {
                return (padding - (length % padding)) % padding;
        }
 }
index 89309c90608ef8554e7aa2b4fab827814adf4044..bc63d3f62067bebcac4beddf5e946ebf53385c12 100644 (file)
@@ -59,7 +59,8 @@ public abstract class AbstractXROWithSubobjectsParser implements ObjectParser, O
 
                        length = ByteArray.bytesToInt(ByteArray.subByte(bytes, offset + LENGTH_F_OFFSET, SUB_LENGTH_F_LENGTH));
 
-                       type = bytes[offset + TYPE_FLAG_F_OFFSET];
+                       final boolean mandatory = ((bytes[offset + TYPE_FLAG_F_OFFSET] & (1 << 7)) != 0) ? true : false;
+                       type = (bytes[offset + TYPE_FLAG_F_OFFSET] & 0xff) & ~(1 << 7);
 
                        if (length > bytes.length - offset) {
                                throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= "
@@ -70,7 +71,7 @@ public abstract class AbstractXROWithSubobjectsParser implements ObjectParser, O
                        System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
 
                        logger.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
-                       final Subobjects sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes, false);
+                       final Subobjects sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes, mandatory);
                        logger.debug("Subobject was parsed. {}", sub);
 
                        subs.add(sub);
@@ -94,7 +95,8 @@ public abstract class AbstractXROWithSubobjectsParser implements ObjectParser, O
 
                        final byte[] bytes = new byte[SUB_HEADER_LENGTH + valueBytes.length];
 
-                       final byte typeBytes = (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - 1)[0]);
+                       final byte typeBytes = (byte) (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - 1)[0] | (subobject.isMandatory() ? 1 << 7
+                                       : 0));
                        final byte lengthBytes = ByteArray.cutBytes(ByteArray.intToBytes(valueBytes.length), (Integer.SIZE / 8) - 1)[0];
 
                        bytes[0] = typeBytes;
index dee802b16391f7a949563707f022a9a926140c27..bce6864b38a802c2e81405d3f6f5ecc12c15dea2 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.BandwidthObject;
@@ -39,7 +38,7 @@ public class PCEPBandwidthObjectParser extends AbstractObjectWithTlvsParser<Band
 
        @Override
        public BandwidthObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
-       PCEPDocumentedException {
+                       PCEPDocumentedException {
                if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
                }
@@ -47,14 +46,10 @@ public class PCEPBandwidthObjectParser extends AbstractObjectWithTlvsParser<Band
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: "
                                        + BANDWIDTH_F_LENGTH + ".");
                }
-
                final BandwidthBuilder builder = new BandwidthBuilder();
-
                builder.setIgnore(header.isIgnore());
                builder.setProcessingRule(header.isProcessingRule());
-
                builder.setBandwidth(new Float32(bytes));
-
                return builder.build();
        }
 
@@ -68,7 +63,6 @@ public class PCEPBandwidthObjectParser extends AbstractObjectWithTlvsParser<Band
                if (!(object instanceof BandwidthObject)) {
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed BandwidthObject.");
                }
-
                return ((BandwidthObject) object).getBandwidth().getValue();
        }
 
index c8f88cbf33224591eff6a7e24bed637d62246088..81526ad9fdfc1b5e26dcab07b0f36d9a16f0c85f 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
 import org.opendaylight.protocol.pcep.PCEPErrors;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClasstypeObject;
@@ -19,8 +18,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.ClassTypeBuilder;
 
+import com.google.common.primitives.UnsignedBytes;
+
 /**
- * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPClassTypeObject PCEPClassTypeObject}
+ * Parser for {@link ClasstypeObject}
  */
 public class PCEPClassTypeObjectParser extends AbstractObjectWithTlvsParser<ClassTypeBuilder> {
 
@@ -31,17 +32,17 @@ public class PCEPClassTypeObjectParser extends AbstractObjectWithTlvsParser<Clas
        /**
         * Length of Class Type field in bits.
         */
-       public static final int CT_F_LENGTH = 3;
+       private static final int CT_F_LENGTH = 3;
 
        /**
         * Reserved field bit length.
         */
-       public static final int RESERVED = 29;
+       private static final int RESERVED = 29;
 
        /**
         * Size of the object in bytes.
         */
-       public static final int SIZE = (RESERVED + CT_F_LENGTH) / 8;
+       private static final int SIZE = (RESERVED + CT_F_LENGTH) / 8;
 
        public PCEPClassTypeObjectParser(final TlvHandlerRegistry tlvReg) {
                super(tlvReg);
@@ -49,7 +50,7 @@ public class PCEPClassTypeObjectParser extends AbstractObjectWithTlvsParser<Clas
 
        @Override
        public ClasstypeObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
-       PCEPDocumentedException {
+                       PCEPDocumentedException {
                if (bytes == null) {
                        throw new IllegalArgumentException("Byte array is mandatory.");
                }
@@ -60,13 +61,12 @@ public class PCEPClassTypeObjectParser extends AbstractObjectWithTlvsParser<Clas
                if (!header.isProcessingRule()) {
                        throw new PCEPDocumentedException("Processed bit not set", PCEPErrors.P_FLAG_NOT_SET);
                }
-
                final ClassTypeBuilder builder = new ClassTypeBuilder();
 
                builder.setIgnore(header.isIgnore());
                builder.setProcessingRule(header.isProcessingRule());
 
-               final short ct = (short) (bytes[SIZE - 1] & 0xFF);
+               final short ct = (short) UnsignedBytes.toInt(bytes[SIZE - 1]);
                builder.setClassType(new ClassType(ct));
 
                if (ct < 0 || ct > 8) {
@@ -85,9 +85,8 @@ public class PCEPClassTypeObjectParser extends AbstractObjectWithTlvsParser<Clas
                if (!(object instanceof ClasstypeObject)) {
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed ClasstypeObject.");
                }
-
                final byte[] retBytes = new byte[SIZE];
-               retBytes[SIZE - 1] = ((ClasstypeObject) object).getClassType().getValue().byteValue();
+               retBytes[SIZE - 1] = UnsignedBytes.checkedCast(((ClasstypeObject) object).getClassType().getValue());
                return retBytes;
        }
 
index f02047d064c4e1c0dac80f43516157da3b423372..d6a608b7887c8255d6eedecab05be26f5428a8cd 100644 (file)
@@ -9,8 +9,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseObject;
@@ -21,6 +19,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CCloseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.Tlvs;
 
+import com.google.common.primitives.UnsignedBytes;
+
 /**
  * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPCloseObject PCEPCloseObject}
  */
@@ -33,19 +33,19 @@ public class PCEPCloseObjectParser extends AbstractObjectWithTlvsParser<CCloseBu
        /*
         * lengths of fields in bytes
         */
-       public static final int FLAGS_F_LENGTH = 1;
-       public static final int REASON_F_LENGTH = 1;
+       private static final int FLAGS_F_LENGTH = 1;
+       private static final int REASON_F_LENGTH = 1;
 
        /*
         * offsets of fields in bytes
         */
-       public static final int FLAGS_F_OFFSET = 2; // added reserved field of size 2 bytes
-       public static final int REASON_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
+       private static final int FLAGS_F_OFFSET = 2;
+       private static final int REASON_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
 
        /*
         * total size of object in bytes
         */
-       public static final int TLVS_OFFSET = REASON_F_OFFSET + REASON_F_LENGTH;
+       private static final int TLVS_OFFSET = REASON_F_OFFSET + REASON_F_LENGTH;
 
        public PCEPCloseObjectParser(final TlvHandlerRegistry tlvReg) {
                super(tlvReg);
@@ -56,16 +56,11 @@ public class PCEPCloseObjectParser extends AbstractObjectWithTlvsParser<CCloseBu
                if (bytes == null) {
                        throw new IllegalArgumentException("Byte array is mandatory.");
                }
-
                final CCloseBuilder builder = new CCloseBuilder();
-
                parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_OFFSET));
-
                builder.setIgnore(header.isIgnore());
                builder.setProcessingRule(header.isProcessingRule());
-
-               builder.setReason((short) (bytes[REASON_F_OFFSET] & 0xFF));
-
+               builder.setReason((short) UnsignedBytes.toInt(bytes[REASON_F_OFFSET]));
                return builder.build();
        }
 
@@ -79,7 +74,6 @@ public class PCEPCloseObjectParser extends AbstractObjectWithTlvsParser<CCloseBu
                if (!(object instanceof CloseObject)) {
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed CloseObject.");
                }
-
                final CloseObject obj = (CloseObject) object;
 
                final byte[] tlvs = serializeTlvs(obj.getTlvs());
@@ -87,16 +81,12 @@ public class PCEPCloseObjectParser extends AbstractObjectWithTlvsParser<CCloseBu
                if (tlvs != null) {
                        tlvsLength = tlvs.length;
                }
-               final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
+               final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
 
                if (tlvs != null) {
                        ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
                }
-
-               final int reason = ((CClose) obj).getReason().intValue();
-
-               retBytes[REASON_F_OFFSET] = (byte) reason;
-
+               retBytes[REASON_F_OFFSET] = UnsignedBytes.checkedCast(((CClose) obj).getReason());
                return retBytes;
        }
 
index 72a957fc7d51e55869bae5d3a14c534a9e9b19a7..d2808e2838c23bbbaf101a648a4d1ccbce775096 100644 (file)
@@ -12,7 +12,6 @@ import org.opendaylight.protocol.concepts.Ipv6Util;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
 import org.opendaylight.protocol.pcep.PCEPErrors;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.EndpointsObject;
@@ -32,27 +31,25 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 public class PCEPEndPointsObjectParser extends AbstractObjectWithTlvsParser<EndpointsBuilder> {
 
        public static final int CLASS = 4;
-
        public static final int TYPE = 1;
 
+       public static final int CLASS_6 = 4;
+       public static final int TYPE_6 = 2;
+
        /*
         * fields lengths and offsets for IPv4 in bytes
         */
-       public static final int SRC4_F_LENGTH = 4;
-       public static final int DEST4_F_LENGTH = 4;
+       private static final int SRC4_F_LENGTH = 4;
+       private static final int DEST4_F_LENGTH = 4;
 
-       public static final int SRC4_F_OFFSET = 0;
-       public static final int DEST4_F_OFFSET = SRC4_F_OFFSET + SRC4_F_LENGTH;
-
-       public static final int CLASS_6 = 4;
-
-       public static final int TYPE_6 = 2;
+       private static final int SRC4_F_OFFSET = 0;
+       private static final int DEST4_F_OFFSET = SRC4_F_OFFSET + SRC4_F_LENGTH;
 
-       public static final int SRC6_F_LENGTH = 16;
-       public static final int DEST6_F_LENGTH = 16;
+       private static final int SRC6_F_LENGTH = 16;
+       private static final int DEST6_F_LENGTH = 16;
 
-       public static final int SRC6_F_OFFSET = 0;
-       public static final int DEST6_F_OFFSET = SRC6_F_OFFSET + SRC6_F_LENGTH;
+       private static final int SRC6_F_OFFSET = 0;
+       private static final int DEST6_F_OFFSET = SRC6_F_OFFSET + SRC6_F_LENGTH;
 
        public PCEPEndPointsObjectParser(final TlvHandlerRegistry tlvReg) {
                super(tlvReg);
@@ -60,7 +57,7 @@ public class PCEPEndPointsObjectParser extends AbstractObjectWithTlvsParser<Endp
 
        @Override
        public EndpointsObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
-       PCEPDocumentedException {
+                       PCEPDocumentedException {
                if (bytes == null) {
                        throw new IllegalArgumentException("Array of bytes is mandatory");
                }
index a2700cae8a3162b5214e024b3b6b0dc0b6a8955e..46847cad93a64e3df1b52a206c213b7aad0e3200 100644 (file)
@@ -9,8 +9,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
@@ -48,7 +46,7 @@ public class PCEPErrorObjectParser extends AbstractObjectWithTlvsParser<ErrorsBu
 
        @Override
        public PcepErrorObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
-       PCEPDocumentedException {
+                       PCEPDocumentedException {
                if (bytes == null) {
                        throw new IllegalArgumentException("Array of bytes is mandatory.");
                }
@@ -87,7 +85,7 @@ public class PCEPErrorObjectParser extends AbstractObjectWithTlvsParser<ErrorsBu
                if (tlvs != null) {
                        tlvsLength = tlvs.length;
                }
-               final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
+               final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
 
                if (tlvs != null) {
                        ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
index add8e19bfe02739226a28c7e22eb67f7bab781c6..c33e6f07b7312564dc149e0cbac19be59278f74a 100644 (file)
@@ -9,15 +9,15 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
-import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.GcObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.GcBuilder;
 
+import com.google.common.primitives.UnsignedBytes;
+
 /**
  * Parser for {@link GcObject}
  */
@@ -27,17 +27,17 @@ public class PCEPGlobalConstraintsObjectParser extends AbstractObjectWithTlvsPar
 
        public static final int TYPE = 1;
 
-       private final static int MAX_HOP_F_LENGTH = 1;
-       private final static int MAX_UTIL_F_LENGTH = 1;
-       private final static int MIN_UTIL_F_LENGTH = 1;
-       private final static int OVER_BOOKING_FACTOR_F_LENGTH = 1;
+       private static final int MAX_HOP_F_LENGTH = 1;
+       private static final int MAX_UTIL_F_LENGTH = 1;
+       private static final int MIN_UTIL_F_LENGTH = 1;
+       private static final int OVER_BOOKING_FACTOR_F_LENGTH = 1;
 
-       private final static int MAX_HOP_F_OFFSET = 0;
-       private final static int MAX_UTIL_F_OFFSET = MAX_HOP_F_OFFSET + MAX_HOP_F_LENGTH;
-       private final static int MIN_UTIL_F_OFFSET = MAX_UTIL_F_OFFSET + MAX_UTIL_F_LENGTH;
-       private final static int OVER_BOOKING_FACTOR_F_OFFSET = MIN_UTIL_F_OFFSET + MIN_UTIL_F_LENGTH;
+       private static final int MAX_HOP_F_OFFSET = 0;
+       private static final int MAX_UTIL_F_OFFSET = MAX_HOP_F_OFFSET + MAX_HOP_F_LENGTH;
+       private static final int MIN_UTIL_F_OFFSET = MAX_UTIL_F_OFFSET + MAX_UTIL_F_LENGTH;
+       private static final int OVER_BOOKING_FACTOR_F_OFFSET = MIN_UTIL_F_OFFSET + MIN_UTIL_F_LENGTH;
 
-       private final static int TLVS_OFFSET = OVER_BOOKING_FACTOR_F_OFFSET + OVER_BOOKING_FACTOR_F_LENGTH;
+       private static final int TLVS_OFFSET = OVER_BOOKING_FACTOR_F_OFFSET + OVER_BOOKING_FACTOR_F_LENGTH;
 
        public PCEPGlobalConstraintsObjectParser(final TlvHandlerRegistry tlvReg) {
                super(tlvReg);
@@ -48,19 +48,15 @@ public class PCEPGlobalConstraintsObjectParser extends AbstractObjectWithTlvsPar
                if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
                }
-
                final GcBuilder builder = new GcBuilder();
 
-               parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_OFFSET));
-
                builder.setIgnore(header.isIgnore());
                builder.setProcessingRule(header.isProcessingRule());
 
-               builder.setMaxHop((short) (bytes[MAX_HOP_F_OFFSET] & 0xFF));
-               builder.setMinUtilization((short) (bytes[MIN_UTIL_F_OFFSET] & 0xFF));
-               builder.setMaxUtilization((short) (bytes[MAX_UTIL_F_OFFSET] & 0xFF));
-               builder.setOverBookingFactor((short) (bytes[OVER_BOOKING_FACTOR_F_OFFSET] & 0xFF));
-
+               builder.setMaxHop((short) UnsignedBytes.toInt(bytes[MAX_HOP_F_OFFSET]));
+               builder.setMinUtilization((short) UnsignedBytes.toInt(bytes[MIN_UTIL_F_OFFSET]));
+               builder.setMaxUtilization((short) UnsignedBytes.toInt(bytes[MAX_UTIL_F_OFFSET]));
+               builder.setOverBookingFactor((short) UnsignedBytes.toInt(bytes[OVER_BOOKING_FACTOR_F_OFFSET]));
                return builder.build();
        }
 
@@ -74,19 +70,12 @@ public class PCEPGlobalConstraintsObjectParser extends AbstractObjectWithTlvsPar
                if (!(object instanceof GcObject)) {
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed GcObject.");
                }
-
                final GcObject specObj = (GcObject) object;
-
-               // final byte[] tlvs = PCEPTlvParser.put(specObj.getTlvs());
                final byte[] retBytes = new byte[TLVS_OFFSET + 0];
-
-               retBytes[MAX_HOP_F_OFFSET] = specObj.getMaxHop().byteValue();
-               retBytes[MAX_UTIL_F_OFFSET] = specObj.getMaxUtilization().byteValue();
-               retBytes[MIN_UTIL_F_OFFSET] = specObj.getMinUtilization().byteValue();
-               retBytes[OVER_BOOKING_FACTOR_F_OFFSET] = specObj.getOverBookingFactor().byteValue();
-
-               // ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
-
+               retBytes[MAX_HOP_F_OFFSET] = UnsignedBytes.checkedCast(specObj.getMaxHop());
+               retBytes[MAX_UTIL_F_OFFSET] = UnsignedBytes.checkedCast(specObj.getMaxUtilization());
+               retBytes[MIN_UTIL_F_OFFSET] = UnsignedBytes.checkedCast(specObj.getMinUtilization());
+               retBytes[OVER_BOOKING_FACTOR_F_OFFSET] = UnsignedBytes.checkedCast(specObj.getOverBookingFactor());
                return retBytes;
        }
 
index 8eb1d4035b3b7b38a3d68b9fd5c634d887f2d014..fd649e826fb3af50bc78481038df4c0759ab27c9 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
@@ -19,8 +18,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.LoadBalancingBuilder;
 
+import com.google.common.primitives.UnsignedBytes;
+
 /**
- * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPLoadBalancingObject PCEPLoadBalancingObject}
+ * Parser for {@link LoadBalancingObject}
  */
 public class PCEPLoadBalancingObjectParser extends AbstractObjectWithTlvsParser<LoadBalancingBuilder> {
 
@@ -28,15 +29,15 @@ public class PCEPLoadBalancingObjectParser extends AbstractObjectWithTlvsParser<
 
        public static final int TYPE = 1;
 
-       public static final int FLAGS_F_LENGTH = 1;
-       public static final int MAX_LSP_F_LENGTH = 1;
-       public static final int MIN_BAND_F_LENGTH = 4;
+       private static final int FLAGS_F_LENGTH = 1;
+       private static final int MAX_LSP_F_LENGTH = 1;
+       private static final int MIN_BAND_F_LENGTH = 4;
 
-       public static final int FLAGS_F_OFFSET = 2;
-       public static final int MAX_LSP_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
-       public static final int MIN_BAND_F_OFFSET = MAX_LSP_F_OFFSET + MAX_LSP_F_LENGTH;
+       private static final int FLAGS_F_OFFSET = 2;
+       private static final int MAX_LSP_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
+       private static final int MIN_BAND_F_OFFSET = MAX_LSP_F_OFFSET + MAX_LSP_F_LENGTH;
 
-       public static final int SIZE = MIN_BAND_F_OFFSET + MIN_BAND_F_LENGTH;
+       private static final int SIZE = MIN_BAND_F_OFFSET + MIN_BAND_F_LENGTH;
 
        public PCEPLoadBalancingObjectParser(final TlvHandlerRegistry tlvReg) {
                super(tlvReg);
@@ -44,23 +45,18 @@ public class PCEPLoadBalancingObjectParser extends AbstractObjectWithTlvsParser<
 
        @Override
        public LoadBalancingObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
-       PCEPDocumentedException {
+                       PCEPDocumentedException {
                if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
                }
-
                if (bytes.length != SIZE) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: " + SIZE + ".");
                }
-
                final LoadBalancingBuilder builder = new LoadBalancingBuilder();
-
                builder.setIgnore(header.isIgnore());
                builder.setProcessingRule(header.isProcessingRule());
-
-               builder.setMaxLsp((short) (bytes[MAX_LSP_F_OFFSET] & 0xFF));
+               builder.setMaxLsp((short) UnsignedBytes.toInt(bytes[MAX_LSP_F_OFFSET]));
                builder.setMinBandwidth(new Float32(ByteArray.subByte(bytes, MIN_BAND_F_OFFSET, MIN_BAND_F_LENGTH)));
-
                return builder.build();
        }
 
@@ -75,14 +71,10 @@ public class PCEPLoadBalancingObjectParser extends AbstractObjectWithTlvsParser<
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
                                        + ". Needed LoadBalancingObject.");
                }
-
                final LoadBalancingObject specObj = (LoadBalancingObject) object;
-
                final byte[] retBytes = new byte[SIZE];
-
-               retBytes[MAX_LSP_F_OFFSET] = ByteArray.shortToBytes(specObj.getMaxLsp())[1];
+               retBytes[MAX_LSP_F_OFFSET] = UnsignedBytes.checkedCast(specObj.getMaxLsp());
                ByteArray.copyWhole(specObj.getMinBandwidth().getValue(), retBytes, MIN_BAND_F_OFFSET);
-
                return retBytes;
        }
 
index 9b8461010700b77e3f5abfeac1590f11e7372f65..c29d5a6fa3bc5f7acf0f7a833f2f4c24fb77b855 100644 (file)
@@ -11,7 +11,6 @@ import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspObject;
index 6745c01f29a8162c212d9d0430f4e0a3864b3c2d..f2e96c03c413e607a012adbe58a6a69ea7962f68 100644 (file)
@@ -11,7 +11,6 @@ import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspaObject;
@@ -21,6 +20,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.LspaBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AttributeFilter;
 
+import com.google.common.primitives.UnsignedBytes;
+
 /**
  * Parser for {@link LspaObject}
  */
@@ -33,29 +34,29 @@ public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<LspaBuild
        /*
         * lengths of fields in bytes
         */
-       public static final int EXC_ANY_F_LENGTH = 4;
-       public static final int INC_ANY_F_LENGTH = 4;
-       public static final int INC_ALL_F_LENGTH = 4;
-       public static final int SET_PRIO_F_LENGTH = 1;
-       public static final int HOLD_PRIO_F_LENGTH = 1;
-       public static final int FLAGS_F_LENGTH = 1;
+       private static final int EXC_ANY_F_LENGTH = 4;
+       private static final int INC_ANY_F_LENGTH = 4;
+       private static final int INC_ALL_F_LENGTH = 4;
+       private static final int SET_PRIO_F_LENGTH = 1;
+       private static final int HOLD_PRIO_F_LENGTH = 1;
+       private static final int FLAGS_F_LENGTH = 1;
 
        /*
         * offsets of flags inside flags field in bits
         */
-       public static final int S_FLAG_OFFSET = 6;
-       public static final int L_FLAG_OFFSET = 7;
+       private static final int S_FLAG_OFFSET = 6;
+       private static final int L_FLAG_OFFSET = 7;
 
        /*
         * offsets of fields in bytes
         */
-       public static final int EXC_ANY_F_OFFSET = 0;
-       public static final int INC_ANY_F_OFFSET = EXC_ANY_F_OFFSET + EXC_ANY_F_LENGTH;
-       public static final int INC_ALL_F_OFFSET = INC_ANY_F_OFFSET + INC_ANY_F_LENGTH;
-       public static final int SET_PRIO_F_OFFSET = INC_ALL_F_OFFSET + INC_ALL_F_LENGTH;
-       public static final int HOLD_PRIO_F_OFFSET = SET_PRIO_F_OFFSET + SET_PRIO_F_LENGTH;
-       public static final int FLAGS_F_OFFSET = HOLD_PRIO_F_OFFSET + HOLD_PRIO_F_LENGTH;
-       public static final int TLVS_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH + 1; // added reserved field of length 1B
+       private static final int EXC_ANY_F_OFFSET = 0;
+       private static final int INC_ANY_F_OFFSET = EXC_ANY_F_OFFSET + EXC_ANY_F_LENGTH;
+       private static final int INC_ALL_F_OFFSET = INC_ANY_F_OFFSET + INC_ANY_F_LENGTH;
+       private static final int SET_PRIO_F_OFFSET = INC_ALL_F_OFFSET + INC_ALL_F_LENGTH;
+       private static final int HOLD_PRIO_F_OFFSET = SET_PRIO_F_OFFSET + SET_PRIO_F_LENGTH;
+       private static final int FLAGS_F_OFFSET = HOLD_PRIO_F_OFFSET + HOLD_PRIO_F_LENGTH;
+       private static final int TLVS_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH + 1; // added reserved field of length 1B
 
        public PCEPLspaObjectParser(final TlvHandlerRegistry tlvReg) {
                super(tlvReg);
@@ -66,23 +67,20 @@ public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<LspaBuild
                if (bytes == null) {
                        throw new IllegalArgumentException("Bytes array is mandatory.");
                }
-
                final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(bytes, FLAGS_F_OFFSET, FLAGS_F_LENGTH));
 
                final LspaBuilder builder = new LspaBuilder();
-
                parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_F_OFFSET));
 
                builder.setIgnore(header.isIgnore());
                builder.setProcessingRule(header.isProcessingRule());
 
-               builder.setHoldPriority((short) (bytes[HOLD_PRIO_F_OFFSET] & 0xFF));
-               builder.setSetupPriority((short) (bytes[SET_PRIO_F_OFFSET] & 0xFF));
+               builder.setHoldPriority((short) UnsignedBytes.toInt(bytes[HOLD_PRIO_F_OFFSET]));
+               builder.setSetupPriority((short) UnsignedBytes.toInt(bytes[SET_PRIO_F_OFFSET]));
                builder.setLocalProtectionDesired(flags.get(L_FLAG_OFFSET));
                builder.setExcludeAny(new AttributeFilter(ByteArray.bytesToLong(ByteArray.subByte(bytes, EXC_ANY_F_OFFSET, EXC_ANY_F_LENGTH))));
                builder.setIncludeAll(new AttributeFilter(ByteArray.bytesToLong(ByteArray.subByte(bytes, INC_ALL_F_OFFSET, INC_ALL_F_LENGTH))));
                builder.setIncludeAny(new AttributeFilter(ByteArray.bytesToLong(ByteArray.subByte(bytes, INC_ANY_F_OFFSET, INC_ANY_F_LENGTH))));
-
                return builder.build();
        }
 
@@ -96,26 +94,19 @@ public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<LspaBuild
                if (!(object instanceof LspaObject)) {
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed LspaObject.");
                }
-
                final LspaObject lspaObj = (LspaObject) object;
 
-               // FIXME, but no Tlvs defined
-               // final byte[] tlvs = PCEPTlvParser.put(lspaObj.getTlvs());
-               // final byte[] retBytes = new byte[TLVS_F_OFFSET + tlvs.length];
-               // ByteArray.copyWhole(tlvs, retBytes, TLVS_F_OFFSET);
-
                final byte[] retBytes = new byte[TLVS_F_OFFSET];
 
                System.arraycopy(ByteArray.longToBytes(lspaObj.getExcludeAny().getValue()), 4, retBytes, EXC_ANY_F_OFFSET, EXC_ANY_F_LENGTH);
                System.arraycopy(ByteArray.longToBytes(lspaObj.getIncludeAny().getValue()), 4, retBytes, INC_ANY_F_OFFSET, INC_ANY_F_LENGTH);
                System.arraycopy(ByteArray.longToBytes(lspaObj.getIncludeAll().getValue()), 4, retBytes, INC_ALL_F_OFFSET, INC_ALL_F_LENGTH);
-               retBytes[SET_PRIO_F_OFFSET] = ByteArray.shortToBytes(lspaObj.getSetupPriority())[Short.SIZE / Byte.SIZE - 1];
-               retBytes[HOLD_PRIO_F_OFFSET] = ByteArray.shortToBytes(lspaObj.getHoldPriority())[Short.SIZE / Byte.SIZE - 1];
+               retBytes[SET_PRIO_F_OFFSET] = UnsignedBytes.checkedCast(lspaObj.getSetupPriority());
+               retBytes[HOLD_PRIO_F_OFFSET] = UnsignedBytes.checkedCast(lspaObj.getHoldPriority());
 
                final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
                flags.set(L_FLAG_OFFSET, lspaObj.isLocalProtectionDesired());
                ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS_F_OFFSET);
-
                return retBytes;
        }
 
index bef8f5710eda1e0090dab906f813629490250e5b..5b5319e09be58ecca08287ae07e7c9a072490b2c 100644 (file)
@@ -11,7 +11,6 @@ import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
@@ -22,8 +21,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.Metric;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.MetricBuilder;
 
+import com.google.common.primitives.UnsignedBytes;
+
 /**
- * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPMetricObject PCEPMetricObject}
+ * Parser for {@link MetricObject}
  */
 public class PCEPMetricObjectParser extends AbstractObjectWithTlvsParser<MetricBuilder> {
 
@@ -41,9 +42,9 @@ public class PCEPMetricObjectParser extends AbstractObjectWithTlvsParser<MetricB
        /*
         * offsets of fields in bytes
         */
-       public static final int FLAGS_F_OFFSET = 2;
-       public static final int TYPE_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
-       public static final int METRIC_VALUE_F_OFFSET = TYPE_F_OFFSET + TYPE_F_LENGTH;
+       private static final int FLAGS_F_OFFSET = 2;
+       private static final int TYPE_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
+       private static final int METRIC_VALUE_F_OFFSET = TYPE_F_OFFSET + TYPE_F_LENGTH;
 
        /*
         * flags offsets inside flags field in bits
@@ -51,7 +52,7 @@ public class PCEPMetricObjectParser extends AbstractObjectWithTlvsParser<MetricB
        private static final int C_FLAG_OFFSET = 6;
        private static final int B_FLAG_OFFSET = 7;
 
-       public static final int SIZE = METRIC_VALUE_F_OFFSET + METRIC_VALUE_F_LENGTH;
+       private static final int SIZE = METRIC_VALUE_F_OFFSET + METRIC_VALUE_F_LENGTH;
 
        public PCEPMetricObjectParser(final TlvHandlerRegistry tlvReg) {
                super(tlvReg);
@@ -59,7 +60,7 @@ public class PCEPMetricObjectParser extends AbstractObjectWithTlvsParser<MetricB
 
        @Override
        public MetricObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
-       PCEPDocumentedException {
+                       PCEPDocumentedException {
                if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
                }
@@ -68,17 +69,13 @@ public class PCEPMetricObjectParser extends AbstractObjectWithTlvsParser<MetricB
                }
                final byte[] flagBytes = { bytes[FLAGS_F_OFFSET] };
                final BitSet flags = ByteArray.bytesToBitSet(flagBytes);
-
                final MetricBuilder builder = new MetricBuilder();
-
                builder.setIgnore(header.isIgnore());
                builder.setProcessingRule(header.isProcessingRule());
-
                builder.setBound(flags.get(B_FLAG_OFFSET));
                builder.setComputed(flags.get(C_FLAG_OFFSET));
-               builder.setMetricType((short) (bytes[TYPE_F_OFFSET] & 0xFF));
+               builder.setMetricType((short) UnsignedBytes.toInt(bytes[TYPE_F_OFFSET]));
                builder.setValue(new Float32(ByteArray.subByte(bytes, METRIC_VALUE_F_OFFSET, METRIC_VALUE_F_LENGTH)));
-
                return builder.build();
        }
 
@@ -92,18 +89,14 @@ public class PCEPMetricObjectParser extends AbstractObjectWithTlvsParser<MetricB
                if (!(object instanceof MetricObject)) {
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed MetricObject.");
                }
-
                final MetricObject mObj = (MetricObject) object;
-
                final byte[] retBytes = new byte[SIZE];
                final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
                flags.set(C_FLAG_OFFSET, ((Metric) mObj).isComputed());
                flags.set(B_FLAG_OFFSET, mObj.isBound());
-
                ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS_F_OFFSET);
-
+               retBytes[TYPE_F_OFFSET] = UnsignedBytes.checkedCast(mObj.getMetricType());
                System.arraycopy(mObj.getValue().getValue(), 0, retBytes, METRIC_VALUE_F_OFFSET, METRIC_VALUE_F_LENGTH);
-
                return retBytes;
        }
 
index 19355b75e57e60ab817210da253792b8266f0e9f..b03de62ff65451dc2000f895850d89b1ee8e5947 100644 (file)
@@ -11,17 +11,15 @@ import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.NoPath;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.no.path.Tlvs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.NoPath;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.NoPathBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.no.path.Tlvs;
 
 /**
  * Parser for {@link NoPathObject}
@@ -60,7 +58,7 @@ public class PCEPNoPathObjectParser extends AbstractObjectWithTlvsParser<NoPathB
 
        @Override
        public NoPathObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
-       PCEPDocumentedException {
+                       PCEPDocumentedException {
                if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
                }
@@ -98,7 +96,7 @@ public class PCEPNoPathObjectParser extends AbstractObjectWithTlvsParser<NoPathB
                if (tlvs != null) {
                        tlvsLength = tlvs.length;
                }
-               final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
+               final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
 
                if (tlvs != null) {
                        ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
index 4168ca0017edeaf91a634d33d4a950affd327b17..9ca0dd32cbb019799c5841119cd6c6a991647cd2 100644 (file)
@@ -9,8 +9,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NotificationObject;
@@ -53,7 +51,7 @@ public class PCEPNotificationObjectParser extends AbstractObjectWithTlvsParser<N
 
        @Override
        public NotificationObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
-       PCEPDocumentedException {
+                       PCEPDocumentedException {
                if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
                }
@@ -92,7 +90,7 @@ public class PCEPNotificationObjectParser extends AbstractObjectWithTlvsParser<N
                if (tlvs != null) {
                        tlvsLength = tlvs.length;
                }
-               final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
+               final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
 
                if (tlvs != null) {
                        ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
index 9654b0691bb5de635b3ffe724eeb40893a0fd4f4..096d2e94e0e2fab237f43e9103b05feadb99a6f4 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
@@ -30,13 +29,13 @@ public class PCEPObjectiveFunctionObjectParser extends AbstractObjectWithTlvsPar
        /*
         * lengths of fields
         */
-       public static final int OF_CODE_F_LENGTH = 2;
+       private static final int OF_CODE_F_LENGTH = 2;
 
        /*
         * offsets of fields
         */
-       public static final int OF_CODE_F_OFFSET = 0;
-       public static final int TLVS_OFFSET = OF_CODE_F_OFFSET + OF_CODE_F_LENGTH + 2; // added reserved field of size 2
+       private static final int OF_CODE_F_OFFSET = 0;
+       private static final int TLVS_OFFSET = OF_CODE_F_OFFSET + OF_CODE_F_LENGTH + 2;
 
        public PCEPObjectiveFunctionObjectParser(final TlvHandlerRegistry tlvReg) {
                super(tlvReg);
@@ -47,15 +46,10 @@ public class PCEPObjectiveFunctionObjectParser extends AbstractObjectWithTlvsPar
                if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
                }
-
                final OfBuilder builder = new OfBuilder();
-
-               parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_OFFSET));
-
                builder.setIgnore(header.isIgnore());
                builder.setProcessingRule(header.isProcessingRule());
-               builder.setCode(new OfId(ByteArray.bytesToInt(ByteArray.subByte(bytes, OF_CODE_F_OFFSET, OF_CODE_F_LENGTH)) & 0xFFFF));
-
+               builder.setCode(new OfId(ByteArray.bytesToInt(ByteArray.subByte(bytes, OF_CODE_F_OFFSET, OF_CODE_F_LENGTH))));
                return builder.build();
        }
 
@@ -70,16 +64,9 @@ public class PCEPObjectiveFunctionObjectParser extends AbstractObjectWithTlvsPar
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
                                        + ". Needed PCEPObjectiveFunction.");
                }
-
                final OfObject specObj = (OfObject) object;
-               // FIXME
-               // final byte[] tlvs = PCEPTlvParser.put(specObj.getTlvs());
                final byte[] retBytes = new byte[TLVS_OFFSET + 0];
-
-               // ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
-
                ByteArray.copyWhole(ByteArray.shortToBytes(specObj.getCode().getValue().shortValue()), retBytes, OF_CODE_F_OFFSET);
-
                return retBytes;
        }
 
index 29444baa4fbad0e1f103a83c579d0477b6c43cd7..bba35a4ffc7833e8e8f824a2b86e1b85d5b37986 100644 (file)
@@ -11,8 +11,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
 import org.opendaylight.protocol.pcep.PCEPErrors;
-import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspDbVersionTlv;
@@ -132,7 +130,7 @@ public class PCEPOpenObjectParser extends AbstractObjectWithTlvsParser<OpenBuild
 
                final byte[] tlvs = serializeTlvs(open.getTlvs());
 
-               final byte[] bytes = new byte[TLVS_OFFSET + tlvs.length + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
+               final byte[] bytes = new byte[TLVS_OFFSET + tlvs.length + getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
 
                bytes[VER_FLAGS_MF_OFFSET] = versionFlagMF;
                bytes[KEEPALIVE_F_OFFSET] = ByteArray.shortToBytes(open.getKeepalive())[1];
index 570f054cfea6ba9c9363660e47924a7630821c85..f535303104b85ce6d51d4b98a658000bf7aad321 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
index 3e174c3caf397b859375f0e4bd7277932e419c87..5bd8fcc17cf7db7b9b4b4a0d5b5d6b02a6bdf22b 100644 (file)
@@ -13,8 +13,6 @@ import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
@@ -174,7 +172,7 @@ public class PCEPRequestParameterObjectParser extends AbstractObjectWithTlvsPars
                if (tlvs != null) {
                        tlvsLength = tlvs.length;
                }
-               final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
+               final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
 
                if (tlvs != null) {
                        ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
index 1daac5fb191273730c96d08658d92835e4dc9da0..b6bc734a418297830748efcd80daa6f63a9bde89 100644 (file)
@@ -7,36 +7,58 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
+import java.util.Arrays;
+
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpIdNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.requests.SrpBuilder;
 
+/**
+ * Parser for {@link SrpObject}
+ */
 public final class PCEPSrpObjectParser extends AbstractObjectWithTlvsParser<SrpBuilder> {
 
        public static final int CLASS = 33;
 
        public static final int TYPE = 1;
 
+       private static final int FLAGS_SIZE = 4;
+
+       private static final int SRP_ID_SIZE = 4;
+
+       private static final int MIN_SIZE = FLAGS_SIZE + SRP_ID_SIZE;
+
        public PCEPSrpObjectParser(final TlvHandlerRegistry tlvReg) {
                super(tlvReg);
        }
 
        @Override
        public SrpObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException {
-
-               // FIXME: finish
-
+               if (bytes == null || bytes.length == 0) {
+                       throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
+               }
+               if (bytes.length < MIN_SIZE) {
+                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: >=" + MIN_SIZE
+                                       + ".");
+               }
+               if (header.isProcessingRule()) {
+                       throw new PCEPDeserializerException("Processed flag is set");
+               }
                final SrpBuilder builder = new SrpBuilder();
-
                builder.setIgnore(header.isIgnore());
                builder.setProcessingRule(header.isProcessingRule());
-
+               final byte[] srpId = ByteArray.subByte(bytes, FLAGS_SIZE, SRP_ID_SIZE);
+               if (Arrays.equals(srpId, new byte[] { 0, 0, 0, 0 }) || Arrays.equals(srpId, new byte[] { 0xFFFFFFFF })) {
+                       throw new PCEPDeserializerException("Min/Max values for SRP ID are reserved.");
+               }
+               builder.setOperationId(new SrpIdNumber(ByteArray.bytesToLong(srpId)));
                return builder.build();
        }
 
@@ -50,11 +72,14 @@ public final class PCEPSrpObjectParser extends AbstractObjectWithTlvsParser<SrpB
                if (!(object instanceof SrpObject)) {
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed SrpObject.");
                }
-
                final SrpObject srp = (SrpObject) object;
-               // FIXME: finish
-
-               return new byte[0];
+               final Long id = srp.getOperationId().getValue();
+               if (id == 0 || id == 0xFFFFFFFFL) {
+                       throw new IllegalArgumentException("Min/Max values for SRP ID are reserved.");
+               }
+               final byte[] retBytes = new byte[MIN_SIZE];
+               System.arraycopy(ByteArray.intToBytes(id.intValue()), 0, retBytes, FLAGS_SIZE, SRP_ID_SIZE);
+               return retBytes;
        }
 
        @Override
index c3f6b142761d30b2856a3af69e274c82ec7bb79b..d7f45f39e03419566c8b6d153fc7e2fa7b417f3f 100644 (file)
@@ -12,7 +12,6 @@ import java.util.List;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
@@ -36,26 +35,26 @@ public class PCEPSvecObjectParser extends AbstractObjectWithTlvsParser<SvecBuild
        /*
         * field lengths in bytes
         */
-       public static final int FLAGS_F_LENGTH = 3;
-       public static final int REQ_LIST_ITEM_LENGTH = 4;
+       private static final int FLAGS_F_LENGTH = 3;
+       private static final int REQ_LIST_ITEM_LENGTH = 4;
 
        /*
         * fields offsets in bytes
         */
-       public static final int FLAGS_F_OFFSET = 1; // aded reserved field of size 1
-       public static final int REQ_ID_LIST_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
+       private static final int FLAGS_F_OFFSET = 1;
+       private static final int REQ_ID_LIST_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
 
        /*
         * flags offsets inside flags field in bits
         */
-       public static final int S_FLAG_OFFSET = 21;
-       public static final int N_FLAG_OFFSET = 22;
-       public static final int L_FLAG_OFFSET = 23;
+       private static final int S_FLAG_OFFSET = 21;
+       private static final int N_FLAG_OFFSET = 22;
+       private static final int L_FLAG_OFFSET = 23;
 
        /*
         * min size in bytes
         */
-       public static final int MIN_SIZE = FLAGS_F_LENGTH + FLAGS_F_OFFSET;
+       private static final int MIN_SIZE = FLAGS_F_LENGTH + FLAGS_F_OFFSET;
 
        public PCEPSvecObjectParser(final TlvHandlerRegistry tlvReg) {
                super(tlvReg);
@@ -66,23 +65,19 @@ public class PCEPSvecObjectParser extends AbstractObjectWithTlvsParser<SvecBuild
                if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
                }
-
                if (bytes.length < MIN_SIZE) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: >=" + MIN_SIZE
                                        + ".");
                }
-
                final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(bytes, FLAGS_F_OFFSET, FLAGS_F_LENGTH));
                final List<RequestId> requestIDs = Lists.newArrayList();
 
                for (int i = REQ_ID_LIST_OFFSET; i < bytes.length; i += REQ_LIST_ITEM_LENGTH) {
                        requestIDs.add(new RequestId(ByteArray.bytesToLong(ByteArray.subByte(bytes, i, REQ_LIST_ITEM_LENGTH))));
                }
-
                if (requestIDs.isEmpty()) {
                        throw new PCEPDeserializerException("Empty Svec Object - no request ids.");
                }
-
                final SvecBuilder builder = new SvecBuilder();
 
                builder.setIgnore(header.isIgnore());
@@ -120,9 +115,7 @@ public class PCEPSvecObjectParser extends AbstractObjectWithTlvsParser<SvecBuild
                        System.arraycopy(ByteArray.longToBytes(requestIDs.get(i).getValue()), 4, retBytes, REQ_LIST_ITEM_LENGTH * i
                                        + REQ_ID_LIST_OFFSET, REQ_LIST_ITEM_LENGTH);
                }
-
                assert !(requestIDs.isEmpty()) : "Empty Svec Object - no request ids.";
-
                return retBytes;
        }
 
index 09a5affb03061df1d81ae8b00c60d95e29745cad..d7b4dfa4adffb8bab1b355290ff0c7a1ce6155bb 100644 (file)
@@ -25,7 +25,7 @@ public class EROAsNumberSubobjectParser implements EROSubobjectParser, EROSubobj
 
        public static final int TYPE = 32;
 
-       public static final int AS_NUMBER_LENGTH = 4;
+       public static final int AS_NUMBER_LENGTH = 2;
 
        public static final int AS_NUMBER_OFFSET = 0;
 
index 3da789766a4d5f2a6d173e25e0b4e259874f9766..406de8620a6fc3d19b7c6b04c0b9dbe0d04255a2 100644 (file)
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
+import java.util.List;
+
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
+import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.Exrs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.ExrsBuilder;
+
+import com.google.common.collect.Lists;
 
 public class EROExplicitExclusionRouteSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
 
        public static final int TYPE = 33;
 
+       private static final int RESERVED = 2;
+
+       private static final int SUB_TYPE_FLAG_F_LENGTH = 1;
+       private static final int SUB_LENGTH_F_LENGTH = 1;
+       private static final int SUB_HEADER_LENGTH = SUB_TYPE_FLAG_F_LENGTH + SUB_LENGTH_F_LENGTH;
+
+       private static final int TYPE_FLAG_F_OFFSET = 0;
+       private static final int LENGTH_F_OFFSET = TYPE_FLAG_F_OFFSET + SUB_TYPE_FLAG_F_LENGTH;
+       private static final int SO_CONTENTS_OFFSET = LENGTH_F_OFFSET + SUB_LENGTH_F_LENGTH;
+
+       private final XROSubobjectHandlerRegistry registry;
+
+       public EROExplicitExclusionRouteSubobjectParser(final XROSubobjectHandlerRegistry registry) {
+               this.registry = registry;
+       }
+
        @Override
        public Subobjects parseSubobject(final byte[] buffer, final boolean loose) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-
-               // return new EROExplicitExclusionRouteSubobject(PCEPXROSubobjectParser.parse(cutBytes));
-               return null;
+               }
+               final SubobjectsBuilder builder = new SubobjectsBuilder();
+               builder.setLoose(loose);
+               final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects> list = parseSubobjects(buffer);
+               final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.Exrs> exrss = Lists.newArrayList();
+               for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects s : list) {
+                       final ExrsBuilder b = new ExrsBuilder();
+                       b.setAttribute(s.getAttribute());
+                       b.setMandatory(s.isMandatory());
+                       b.setSubobjectType(s.getSubobjectType());
+                       exrss.add(b.build());
+               }
+               builder.setSubobjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.ExrsBuilder().setExrs(
+                               exrss).build());
+               return builder.build();
        }
 
        @Override
        public byte[] serializeSubobject(final Subobjects subobject) {
-               // return PCEPXROSubobjectParser.put(subobject.getXroSubobjets());
-               return new byte[0];
+               if (!(subobject.getSubobjectType() instanceof Exrs)) {
+                       throw new IllegalArgumentException("Unknown subobject instance. Passed " + subobject.getSubobjectType().getClass()
+                                       + ". Needed Exrs.");
+               }
+               final Exrs e = (Exrs) subobject.getSubobjectType();
+               final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects> list = Lists.newArrayList();
+               for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.Exrs ex : e.getExrs()) {
+                       final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.SubobjectsBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.SubobjectsBuilder();
+                       b.setAttribute(ex.getAttribute());
+                       b.setMandatory(ex.isMandatory());
+                       b.setSubobjectType(ex.getSubobjectType());
+                       list.add(b.build());
+               }
+               return serializeSubobject(list);
+       }
+
+       private List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects> parseSubobjects(
+                       final byte[] bytes) throws PCEPDeserializerException {
+               if (bytes == null) {
+                       throw new IllegalArgumentException("Byte array is mandatory.");
+               }
+
+               int type;
+
+               byte[] soContentsBytes;
+               int length;
+               int offset = 0;
+
+               final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects> subs = Lists.newArrayList();
+
+               while (offset < bytes.length) {
+
+                       length = ByteArray.bytesToInt(ByteArray.subByte(bytes, offset + LENGTH_F_OFFSET, SUB_LENGTH_F_LENGTH));
+
+                       final boolean mandatory = ((bytes[offset + TYPE_FLAG_F_OFFSET] & (1 << 7)) != 0) ? true : false;
+                       type = (bytes[offset + TYPE_FLAG_F_OFFSET] & 0xff) & ~(1 << 7);
+                       if (length > bytes.length - offset) {
+                               throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= "
+                                               + (bytes.length - offset));
+                       }
+
+                       soContentsBytes = new byte[length - SO_CONTENTS_OFFSET];
+                       System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
+
+                       final XROSubobjectParser parser = this.registry.getSubobjectParser(type);
+
+                       subs.add(parser.parseSubobject(soContentsBytes, mandatory));
+
+                       offset += length;
+               }
+               return subs;
+       }
+
+       private final byte[] serializeSubobject(
+                       final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects> subobjects) {
+
+               final List<byte[]> result = Lists.newArrayList();
+
+               int finalLength = 0;
+
+               for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects subobject : subobjects) {
+
+                       final XROSubobjectSerializer serializer = this.registry.getSubobjectSerializer(subobject);
+
+                       System.out.println(serializer);
+
+                       final byte[] valueBytes = serializer.serializeSubobject(subobject);
+
+                       final byte[] bytes = new byte[SUB_HEADER_LENGTH + valueBytes.length];
+
+                       final byte typeBytes = (byte) (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - 1)[0] | (subobject.isMandatory() ? 1 << 7
+                                       : 0));
+                       final byte lengthBytes = ByteArray.cutBytes(ByteArray.intToBytes(valueBytes.length), (Integer.SIZE / 8) - 1)[0];
+
+                       bytes[0] = typeBytes;
+                       bytes[1] = lengthBytes;
+                       System.arraycopy(valueBytes, 0, bytes, SUB_HEADER_LENGTH, valueBytes.length);
+
+                       finalLength += bytes.length;
+                       result.add(bytes);
+               }
+
+               final byte[] resultBytes = new byte[finalLength];
+               int byteOffset = 0;
+               for (final byte[] b : result) {
+                       System.arraycopy(b, 0, resultBytes, byteOffset, b.length);
+                       byteOffset += b.length;
+               }
+               return resultBytes;
        }
 
        @Override
index 097c8dd315184abd49f59698b853380773a09fe4..2f17ec611cf365d57b49029d6bc2147e7f460fab 100644 (file)
@@ -30,21 +30,20 @@ public class EROIpPrefixSubobjectParser implements EROSubobjectParser, EROSubobj
 
        public static final int TYPE6 = 2;
 
-       public static final int IP4_F_LENGTH = 4;
-       public static final int PREFIX4_F_LENGTH = 1;
+       private static final int IP4_F_LENGTH = 4;
+       private static final int PREFIX4_F_LENGTH = 1;
 
-       public static final int PREFIX4_F_OFFSET = IP4_F_LENGTH;
+       private static final int PREFIX4_F_OFFSET = IP4_F_LENGTH;
 
-       public static final int CONTENT4_LENGTH = PREFIX4_F_OFFSET + PREFIX4_F_LENGTH + 1; // added reserved field of size 1
+       private static final int CONTENT4_LENGTH = PREFIX4_F_OFFSET + PREFIX4_F_LENGTH + 1;
 
-       public static final int IP_F_LENGTH = 16;
-       public static final int PREFIX_F_LENGTH = 1;
+       private static final int IP_F_LENGTH = 16;
+       private static final int PREFIX_F_LENGTH = 1;
 
-       public static final int IP_F_OFFSET = 0;
-       public static final int PREFIX_F_OFFSET = IP_F_OFFSET + IP_F_LENGTH;
+       private static final int IP_F_OFFSET = 0;
+       private static final int PREFIX_F_OFFSET = IP_F_OFFSET + IP_F_LENGTH;
 
-       public static final int CONTENT_LENGTH = PREFIX_F_OFFSET + PREFIX_F_LENGTH + 1; // added reserved field of size 1
-                                                                                                                                                                       // byte
+       private static final int CONTENT_LENGTH = PREFIX_F_OFFSET + PREFIX_F_LENGTH + 1;
 
        @Override
        public Subobjects parseSubobject(final byte[] buffer, final boolean loose) throws PCEPDeserializerException {
@@ -81,13 +80,13 @@ public class EROIpPrefixSubobjectParser implements EROSubobjectParser, EROSubobj
 
                if (prefix.getIpv4Prefix() != null) {
                        final byte[] retBytes = new byte[CONTENT4_LENGTH];
-                       ByteArray.copyWhole(prefix.getIpv4Prefix().getValue().getBytes(), retBytes, 0);
-                       retBytes[PREFIX_F_OFFSET] = ByteArray.intToBytes(Ipv4Util.getPrefixLength(prefix))[Integer.SIZE / Byte.SIZE - 1];
+                       ByteArray.copyWhole(Ipv4Util.bytesForPrefix(prefix.getIpv4Prefix()), retBytes, 0);
+                       retBytes[PREFIX4_F_OFFSET] = UnsignedBytes.checkedCast(Ipv4Util.getPrefixLength(prefix));
                        return retBytes;
                } else if (prefix.getIpv6Prefix() != null) {
                        final byte[] retBytes = new byte[CONTENT_LENGTH];
-                       ByteArray.copyWhole(prefix.getIpv6Prefix().getValue().getBytes(), retBytes, 0);
-                       retBytes[PREFIX_F_OFFSET] = ByteArray.intToBytes(Ipv4Util.getPrefixLength(prefix))[Integer.SIZE / Byte.SIZE - 1];
+                       ByteArray.copyWhole(Ipv6Util.bytesForPrefix(prefix.getIpv6Prefix()), retBytes, 0);
+                       retBytes[PREFIX_F_OFFSET] = UnsignedBytes.checkedCast(Ipv4Util.getPrefixLength(prefix));
                        return retBytes;
                }
                throw new IllegalArgumentException("No valid IpPrefix");
index 89499ab3de5347c2af4580c8fa84a4c132db71ee..8c0975925f4b31416e766e17b5dac900a60b1620 100644 (file)
@@ -19,9 +19,9 @@ import org.opendaylight.protocol.pcep.spi.LabelSerializer;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LabelSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.Label;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.LabelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
 
 import com.google.common.base.Preconditions;
 
@@ -49,12 +49,13 @@ public class EROLabelSubobjectParser implements EROSubobjectParser, EROSubobject
 
        @Override
        public Subobjects parseSubobject(final byte[] buffer, final boolean loose) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               if (buffer.length < HEADER_LENGTH)
+               }
+               if (buffer.length < HEADER_LENGTH) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >"
                                        + HEADER_LENGTH + ".");
-
+               }
                final BitSet reserved = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, RES_F_OFFSET, RES_F_LENGTH));
 
                final short c_type = (short) (buffer[C_TYPE_F_OFFSET] & 0xFF);
@@ -64,7 +65,6 @@ public class EROLabelSubobjectParser implements EROSubobjectParser, EROSubobject
                if (parser == null) {
                        throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + c_type);
                }
-
                final LabelBuilder builder = new LabelBuilder();
                builder.setUniDirectional(reserved.get(U_FLAG_OFFSET));
                builder.setLabelType(parser.parseLabel(ByteArray.cutBytes(buffer, HEADER_LENGTH)));
@@ -75,15 +75,16 @@ public class EROLabelSubobjectParser implements EROSubobjectParser, EROSubobject
        public byte[] serializeSubobject(final Subobjects subobject) {
                Preconditions.checkNotNull(subobject.getSubobjectType(), "Subobject type cannot be empty.");
 
-               final LabelSubobject label = (LabelSubobject) subobject.getSubobjectType();
-
-               final LabelSerializer serializer = this.registry.getLabelSerializer((CLabel) label);
+               final Label label = (Label) subobject.getSubobjectType();
+               final LabelType l = label.getLabelType();
 
-               if (serializer == null)
-                       throw new IllegalArgumentException("Unknown EROLabelSubobject instance. Passed " + label.getClass());
-
-               final byte[] labelbytes = serializer.serializeSubobject((CLabel) label);
+               final LabelSerializer serializer = this.registry.getLabelSerializer(l);
 
+               if (serializer == null) {
+                       throw new IllegalArgumentException("Unknown EROLabelSubobject instance. Passed "
+                                       + label.getLabelType().getImplementedInterface());
+               }
+               final byte[] labelbytes = serializer.serializeLabel(l);
                final byte[] retBytes = new byte[labelbytes.length + HEADER_LENGTH];
 
                System.arraycopy(labelbytes, 0, retBytes, HEADER_LENGTH, labelbytes.length);
@@ -91,9 +92,7 @@ public class EROLabelSubobjectParser implements EROSubobjectParser, EROSubobject
                final BitSet reserved = new BitSet();
                reserved.set(U_FLAG_OFFSET, label.isUniDirectional());
                System.arraycopy(ByteArray.bitSetToBytes(reserved, RES_F_LENGTH), 0, retBytes, RES_F_OFFSET, RES_F_LENGTH);
-
                retBytes[C_TYPE_F_OFFSET] = (byte) serializer.getType();
-
                return retBytes;
        }
 
index 34f6c998575968b60a81cde074b8081893824228..3ae15631180863e711c3dda89cab12f6f2f253cf 100644 (file)
@@ -13,56 +13,65 @@ import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
 import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeySubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKeyBuilder;
 
+/**
+ * Parser for {@link PathKeySubobject}
+ */
 public class EROPathKeySubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
 
        public static final int TYPE = 64;
 
        public static final int TYPE128 = 65;
 
-       public static final int PK_F_LENGTH = 2;
-       public static final int PCE_ID_F_LENGTH = 4;
+       private static final int PK_F_LENGTH = 2;
+       private static final int PCE_ID_F_LENGTH = 4;
 
-       public static final int PCE128_ID_F_LENGTH = 16;
+       private static final int PCE128_ID_F_LENGTH = 16;
 
-       public static final int PK_F_OFFSET = 0;
-       public static final int PCE_ID_F_OFFSET = PK_F_OFFSET + PK_F_LENGTH;
+       private static final int PK_F_OFFSET = 0;
+       private static final int PCE_ID_F_OFFSET = PK_F_OFFSET + PK_F_LENGTH;
 
-       public static final int CONTENT_LENGTH = PCE_ID_F_OFFSET + PCE_ID_F_LENGTH;
+       private static final int CONTENT_LENGTH = PCE_ID_F_OFFSET + PCE_ID_F_LENGTH;
+       private static final int CONTENT128_LENGTH = PCE_ID_F_OFFSET + PCE128_ID_F_LENGTH;
 
        @Override
        public Subobjects parseSubobject(final byte[] buffer, final boolean loose) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               if (buffer.length != CONTENT_LENGTH)
+               }
+               byte[] pceId = null;
+               if (buffer.length == CONTENT_LENGTH) {
+                       pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT_LENGTH);
+               } else if (buffer.length == CONTENT128_LENGTH) {
+                       pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT128_LENGTH);
+               } else {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >"
                                        + CONTENT_LENGTH + ".");
-
-               final int pathKey = ByteArray.bytesToShort(Arrays.copyOfRange(buffer, PK_F_OFFSET, PCE_ID_F_OFFSET)) & 0xFFFF;
-
-               final byte[] pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT_LENGTH);
-
+               }
+               final int pathKey = ByteArray.bytesToShort(Arrays.copyOfRange(buffer, PK_F_OFFSET, PCE_ID_F_OFFSET));
                final SubobjectsBuilder builder = new SubobjectsBuilder();
                builder.setLoose(loose);
-               // builder.setSubobjectType(value);
+               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+               pBuilder.setPceId(new PceId(pceId));
+               pBuilder.setPathKey(new PathKey(pathKey));
+               builder.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
                return builder.build();
        }
 
        @Override
        public byte[] serializeSubobject(final Subobjects subobject) {
-               final byte[] retBytes = new byte[CONTENT_LENGTH];
-
-               // System.arraycopy(ByteArray.shortToBytes((short) objToSerialize.getPathKey()), 0, retBytes, PK_F_OFFSET,
-               // PK_F_LENGTH);
-               //
-               // if (objToSerialize.getPceId().length != PCE_ID_F_LENGTH)
-               // throw new IllegalArgumentException("Wrong length of pce id. Passed: " + objToSerialize.getPceId().length +
-               // ". Expected: ="
-               // + PCE_ID_F_LENGTH);
-               // System.arraycopy(objToSerialize.getPceId(), 0, retBytes, PCE_ID_F_OFFSET, PCE_ID_F_LENGTH);
-
+               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKey pk = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKey) subobject.getSubobjectType();
+               final int pathKey = pk.getPathKey().getPathKey().getValue();
+               final byte[] pceId = pk.getPathKey().getPceId().getBinary();
+               final byte[] retBytes = new byte[PK_F_LENGTH + pceId.length];
+               System.arraycopy(ByteArray.shortToBytes((short) pathKey), 0, retBytes, PK_F_OFFSET, PK_F_LENGTH);
+               System.arraycopy(pceId, 0, retBytes, PCE_ID_F_OFFSET, pceId.length);
                return retBytes;
        }
 
index b597bfb7b4ccdc1124f47c3890799fac26346d3b..a0dd7c653c9a29e168f07bc5e1acfa236d60b7b7 100644 (file)
@@ -35,11 +35,13 @@ public class EROUnnumberedInterfaceSubobjectParser implements EROSubobjectParser
 
        @Override
        public Subobjects parseSubobject(final byte[] buffer, final boolean loose) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               if (buffer.length != CONTENT_LENGTH)
+               }
+               if (buffer.length != CONTENT_LENGTH) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
                                        + CONTENT_LENGTH + ".");
+               }
                final SubobjectsBuilder builder = new SubobjectsBuilder();
                builder.setLoose(loose);
                final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
@@ -52,18 +54,17 @@ public class EROUnnumberedInterfaceSubobjectParser implements EROSubobjectParser
 
        @Override
        public byte[] serializeSubobject(final Subobjects subobject) {
-               if (!(subobject.getSubobjectType() instanceof UnnumberedSubobject))
+               if (!(subobject.getSubobjectType() instanceof UnnumberedSubobject)) {
                        throw new IllegalArgumentException("Unknown ExplicitRouteSubobject instance. Passed " + subobject.getSubobjectType().getClass()
                                        + ". Needed UnnumberedSubobject.");
-
+               }
                byte[] retBytes;
                retBytes = new byte[CONTENT_LENGTH];
                final UnnumberedSubobject specObj = (UnnumberedSubobject) subobject.getSubobjectType();
-
-               ByteArray.copyWhole(ByteArray.longToBytes(specObj.getRouterId()), retBytes, ROUTER_ID_NUMBER_OFFSET);
+               ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(specObj.getRouterId()), 4, ROUTER_ID_NUMBER_LENGTH), retBytes,
+                               ROUTER_ID_NUMBER_OFFSET);
                System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceId()), Long.SIZE / Byte.SIZE - INTERFACE_ID_NUMBER_LENGTH, retBytes,
                                INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH);
-
                return retBytes;
        }
 
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/GeneralizedLabelChannelSetParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/GeneralizedLabelChannelSetParser.java
deleted file mode 100644 (file)
index fcd2633..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.pcep.impl.subobject;
-
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.LabelParser;
-import org.opendaylight.protocol.pcep.spi.LabelSerializer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedChannelSetLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedChannelSetLabelBuilder;
-
-public class GeneralizedLabelChannelSetParser implements LabelParser, LabelSerializer {
-
-       public static final int CTYPE = 4;
-
-       @Override
-       public GeneralizedChannelSetLabel parseLabel(final byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
-                       throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               // FIXME: finish
-               return new GeneralizedChannelSetLabelBuilder().build();
-       }
-
-       @Override
-       public byte[] serializeSubobject(final CLabel subobject) {
-               if (!(subobject instanceof GeneralizedChannelSetLabel))
-                       throw new IllegalArgumentException("Unknown Label Subobject instance. Passed " + subobject.getClass()
-                                       + ". Needed GeneralizedChannelSetLabel.");
-               // FIXME: finish
-               return new byte[0];
-       }
-
-       @Override
-       public int getType() {
-               return CTYPE;
-       }
-}
index f46eccb89f2add46759408ec3cc5808db8fe2eca..2d8091066a6e9eefc0be4b90bffe7c40b3d1d038 100644 (file)
@@ -10,29 +10,33 @@ package org.opendaylight.protocol.pcep.impl.subobject;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.LabelParser;
 import org.opendaylight.protocol.pcep.spi.LabelSerializer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.GeneralizedLabel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelBuilder;
 
+/**
+ * Parser for {@link GeneralizedLabel}
+ */
 public class GeneralizedLabelParser implements LabelParser, LabelSerializer {
 
        public static final int CTYPE = 2;
 
        @Override
        public LabelType parseLabel(final byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
+               }
 
                return new GeneralizedLabelBuilder().setGeneralizedLabel(buffer).build();
        }
 
        @Override
-       public byte[] serializeSubobject(final CLabel subobject) {
-               if (!(subobject instanceof GeneralizedLabel))
+       public byte[] serializeLabel(final LabelType subobject) {
+               if (!(subobject instanceof GeneralizedLabel)) {
                        throw new IllegalArgumentException("Unknown Label Subobject instance. Passed " + subobject.getClass()
                                        + ". Needed GeneralizedLabel.");
-               return ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabel) subobject).getGeneralizedLabel();
+               }
+               return ((GeneralizedLabel) subobject).getGeneralizedLabel();
        }
 
        @Override
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROAsNumberSubobjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROAsNumberSubobjectParser.java
deleted file mode 100644 (file)
index 9bebc3a..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.pcep.impl.subobject;
-
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Subobjects;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.SubobjectsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AsNumberSubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.SubobjectType;
-
-/**
- * Parser for {@link org.opendaylight.protocol.pcep.subobject.RROAsNumberSubobject RROAsNumberSubobject}
- */
-
-public class RROAsNumberSubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
-
-       public static final int TYPE = 32;
-
-       public static final int AS_NUMBER_LENGTH = 2;
-
-       public static final int AS_NUMBER_OFFSET = 0;
-
-       public static final int CONTENT_LENGTH = AS_NUMBER_LENGTH + AS_NUMBER_OFFSET;
-
-       @Override
-       public Subobjects parseSubobject(final byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
-                       throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               if (buffer.length != CONTENT_LENGTH)
-                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
-                                       + CONTENT_LENGTH + ".");
-
-               return new SubobjectsBuilder().setSubobjectType(
-                               (SubobjectType) new AsNumberBuilder().setAsNumber(new AsNumber(ByteArray.bytesToLong(buffer))).build()).build();
-       }
-
-       @Override
-       public byte[] serializeSubobject(final Subobjects subobject) {
-               if (!(subobject.getSubobjectType() instanceof AsNumberSubobject))
-                       throw new IllegalArgumentException("Unknown ReportedRouteSubobject instance. Passed " + subobject.getSubobjectType().getClass()
-                                       + ". Needed AsNumberSubobject.");
-
-               final byte[] retBytes = new byte[CONTENT_LENGTH];
-
-               final AsNumberSubobject obj = (AsNumberSubobject) subobject.getSubobjectType();
-
-               System.arraycopy(ByteArray.longToBytes(obj.getAsNumber().getValue()), Long.SIZE / Byte.SIZE - AS_NUMBER_LENGTH, retBytes,
-                               AS_NUMBER_OFFSET, AS_NUMBER_LENGTH);
-
-               return retBytes;
-       }
-
-       @Override
-       public int getType() {
-               return TYPE;
-       }
-}
index 96bdbaff108cdf8f8de59096f4344906e74992d8..8a70dec5c40d0d55488d2174fa7342368a621bf4 100644 (file)
@@ -11,6 +11,7 @@ import java.util.Arrays;
 import java.util.BitSet;
 
 import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
@@ -32,81 +33,84 @@ public class RROIpPrefixSubobjectParser implements RROSubobjectParser, RROSubobj
 
        public static final int TYPE6 = 2;
 
-       public static final int IP4_F_LENGTH = 4;
-       public static final int PREFIX4_F_LENGTH = 1;
-       public static final int FLAGS4_F_LENGTH = 1;
+       private static final int IP4_F_LENGTH = 4;
+       private static final int IP_F_LENGTH = 16;
 
-       public static final int IP4_F_OFFSET = 0;
-       public static final int PREFIX4_F_OFFSET = IP4_F_OFFSET + IP4_F_LENGTH;
-       public static final int FLAGS4_F_OFFSET = PREFIX4_F_OFFSET + PREFIX4_F_LENGTH;
+       private static final int PREFIX_F_LENGTH = 1;
+       private static final int FLAGS_F_LENGTH = 1;
 
-       public static final int CONTENT4_LENGTH = FLAGS4_F_OFFSET + FLAGS4_F_LENGTH;
+       private static final int IP_F_OFFSET = 0;
 
-       public static final int IP_F_LENGTH = 16;
-       public static final int PREFIX_F_LENGTH = 1;
-       public static final int FLAGS_F_LENGTH = 1;
+       private static final int PREFIX4_F_OFFSET = IP_F_OFFSET + IP4_F_LENGTH;
+       private static final int FLAGS4_F_OFFSET = PREFIX4_F_OFFSET + PREFIX_F_LENGTH;
 
-       public static final int IP_F_OFFSET = 0;
-       public static final int PREFIX_F_OFFSET = IP_F_OFFSET + IP_F_LENGTH;
-       public static final int FLAGS_F_OFFSET = PREFIX_F_OFFSET + PREFIX_F_LENGTH;
+       private static final int CONTENT4_LENGTH = IP4_F_LENGTH + PREFIX_F_LENGTH + FLAGS_F_LENGTH;
 
-       public static final int CONTENT_LENGTH = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
+       private static final int PREFIX_F_OFFSET = IP_F_OFFSET + IP_F_LENGTH;
+       private static final int FLAGS_F_OFFSET = PREFIX_F_OFFSET + PREFIX_F_LENGTH;
 
-       /*
-        * flags offset in bits
-        */
-       public static final int LPA_F_OFFSET = 7;
-       public static final int LPIU_F_OFFSET = 6;
+       private static final int CONTENT_LENGTH = IP_F_LENGTH + PREFIX_F_LENGTH + FLAGS_F_LENGTH;
+
+       private static final int LPA_F_OFFSET = 7;
+       private static final int LPIU_F_OFFSET = 6;
 
        @Override
        public Subobjects parseSubobject(final byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               if (buffer.length != CONTENT4_LENGTH || buffer.length != CONTENT_LENGTH)
-                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + ";");
-
-               final int length = UnsignedBytes.toInt(buffer[PREFIX4_F_OFFSET]);
-
-               final BitSet flags = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, FLAGS4_F_OFFSET, FLAGS4_F_OFFSET + FLAGS4_F_LENGTH));
-
+               }
                final SubobjectsBuilder builder = new SubobjectsBuilder();
-               builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
-               builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
-               builder.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
-                               new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.subByte(buffer, IP4_F_OFFSET, IP4_F_LENGTH), length))).build());
-
+               if (buffer.length == CONTENT4_LENGTH) {
+                       final int length = UnsignedBytes.toInt(buffer[PREFIX4_F_OFFSET]);
+                       final BitSet flags = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, FLAGS4_F_OFFSET, FLAGS4_F_OFFSET + FLAGS_F_LENGTH));
+                       builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
+                       builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
+                       builder.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+                                       new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.subByte(buffer, IP_F_OFFSET, IP4_F_LENGTH), length))).build());
+               } else if (buffer.length == CONTENT_LENGTH) {
+                       final int length = UnsignedBytes.toInt(buffer[PREFIX_F_OFFSET]);
+                       final BitSet flags = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, FLAGS_F_OFFSET, FLAGS_F_OFFSET + FLAGS_F_LENGTH));
+                       builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
+                       builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
+                       builder.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+                                       new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.subByte(buffer, IP_F_OFFSET, IP_F_LENGTH), length))).build());
+               } else {
+                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + ";");
+               }
                return builder.build();
        }
 
        @Override
        public byte[] serializeSubobject(final Subobjects subobject) {
-               if (!(subobject instanceof IpPrefixSubobject))
+               if (!(subobject.getSubobjectType() instanceof IpPrefixSubobject)) {
                        throw new IllegalArgumentException("Unknown ReportedRouteSubobject instance. Passed " + subobject.getClass()
                                        + ". Needed RROIPAddressSubobject.");
+               }
 
-               final IpPrefixSubobject specObj = (IpPrefixSubobject) subobject;
+               final IpPrefixSubobject specObj = (IpPrefixSubobject) subobject.getSubobjectType();
                final IpPrefix prefix = specObj.getIpPrefix();
 
-               if (prefix.getIpv4Prefix() == null && prefix.getIpv6Prefix() == null)
+               if (prefix.getIpv4Prefix() == null && prefix.getIpv6Prefix() == null) {
                        throw new IllegalArgumentException("Unknown AbstractPrefix instance. Passed " + prefix.getClass() + ".");
+               }
 
-               final BitSet flags = new BitSet(FLAGS4_F_LENGTH * Byte.SIZE);
-
+               final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
                flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
                flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
 
-               final byte[] retBytes = new byte[CONTENT4_LENGTH];
-
                if (prefix.getIpv4Prefix() != null) {
-                       ByteArray.copyWhole(prefix.getIpv4Prefix().getValue().getBytes(), retBytes, IP4_F_OFFSET);
-                       retBytes[PREFIX4_F_OFFSET] = ByteArray.intToBytes(Ipv4Util.getPrefixLength(prefix))[Integer.SIZE / Byte.SIZE - 1];
-                       ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS4_F_LENGTH), retBytes, FLAGS4_F_OFFSET);
+                       final byte[] retBytes = new byte[CONTENT4_LENGTH];
+                       ByteArray.copyWhole(Ipv4Util.bytesForPrefix(prefix.getIpv4Prefix()), retBytes, IP_F_OFFSET);
+                       retBytes[PREFIX4_F_OFFSET] = UnsignedBytes.checkedCast(Ipv4Util.getPrefixLength(prefix));
+                       ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS4_F_OFFSET);
+                       return retBytes;
                } else {
-                       ByteArray.copyWhole(prefix.getIpv6Prefix().getValue().getBytes(), retBytes, IP_F_OFFSET);
-                       retBytes[PREFIX_F_OFFSET] = ByteArray.intToBytes(Ipv4Util.getPrefixLength(prefix))[Integer.SIZE / Byte.SIZE - 1];
+                       final byte[] retBytes = new byte[CONTENT_LENGTH];
+                       ByteArray.copyWhole(Ipv6Util.bytesForPrefix(prefix.getIpv6Prefix()), retBytes, IP_F_OFFSET);
+                       retBytes[PREFIX_F_OFFSET] = UnsignedBytes.checkedCast(Ipv4Util.getPrefixLength(prefix));
                        ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS_F_OFFSET);
+                       return retBytes;
                }
-               return retBytes;
        }
 
        @Override
index 4f14c274788fe454f6ecc63c6c179a3558707851..c5e9e40327afd4ded93fb390ab278d59a2e6283b 100644 (file)
@@ -19,8 +19,8 @@ import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Subobjects;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.SubobjectsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LabelSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.Label;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.LabelBuilder;
 
 import com.google.common.base.Preconditions;
@@ -40,6 +40,7 @@ public class RROLabelSubobjectParser implements RROSubobjectParser, RROSubobject
        public static final int HEADER_LENGTH = C_TYPE_F_OFFSET + C_TYPE_F_LENGTH;
 
        public static final int U_FLAG_OFFSET = 0;
+       public static final int G_FLAG_OFFSET = 7;
 
        private final LabelHandlerRegistry registry;
 
@@ -49,12 +50,13 @@ public class RROLabelSubobjectParser implements RROSubobjectParser, RROSubobject
 
        @Override
        public Subobjects parseSubobject(final byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               if (buffer.length < HEADER_LENGTH)
+               }
+               if (buffer.length < HEADER_LENGTH) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >"
                                        + HEADER_LENGTH + ".");
-
+               }
                final BitSet reserved = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, RES_F_OFFSET, RES_F_LENGTH));
 
                final short c_type = (short) (buffer[C_TYPE_F_OFFSET] & 0xFF);
@@ -64,33 +66,30 @@ public class RROLabelSubobjectParser implements RROSubobjectParser, RROSubobject
                if (parser == null) {
                        throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + c_type);
                }
-
                final LabelBuilder builder = new LabelBuilder();
                builder.setUniDirectional(reserved.get(U_FLAG_OFFSET));
+               builder.setGlobal(reserved.get(G_FLAG_OFFSET));
                builder.setLabelType(parser.parseLabel(ByteArray.cutBytes(buffer, HEADER_LENGTH)));
                return new SubobjectsBuilder().setSubobjectType(builder.build()).build();
        }
 
        @Override
        public byte[] serializeSubobject(final Subobjects subobject) {
-               final LabelSubobject label = (LabelSubobject) subobject.getSubobjectType();
-               final LabelSerializer parser = this.registry.getLabelSerializer((CLabel) label);
-
-               if (parser == null)
+               final Label label = (Label) subobject.getSubobjectType();
+               final LabelType l = label.getLabelType();
+               final LabelSerializer parser = this.registry.getLabelSerializer(l);
+               if (parser == null) {
                        throw new IllegalArgumentException("Unknown RROLabelSubobject instance. Passed " + subobject.getSubobjectType().getClass());
-
-               final byte[] labelbytes = parser.serializeSubobject((CLabel) label);
-
+               }
+               final byte[] labelbytes = parser.serializeLabel(l);
                final byte[] retBytes = new byte[labelbytes.length + HEADER_LENGTH];
-
                System.arraycopy(labelbytes, 0, retBytes, HEADER_LENGTH, labelbytes.length);
 
                final BitSet reserved = new BitSet();
                reserved.set(U_FLAG_OFFSET, label.isUniDirectional());
+               reserved.set(G_FLAG_OFFSET, label.isGlobal());
                System.arraycopy(ByteArray.bitSetToBytes(reserved, RES_F_LENGTH), 0, retBytes, RES_F_OFFSET, RES_F_LENGTH);
-
                retBytes[C_TYPE_F_OFFSET] = (byte) parser.getType();
-
                return retBytes;
        }
 
index 61769292c65bbb0938adf325d284f32bea596393..8fbee863b7ceb092289324f72ccff85d97192b34 100644 (file)
@@ -13,8 +13,11 @@ import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
 import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Subobjects;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.PathKeyBuilder;
 
 public class RROPathKeySubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
 
@@ -22,46 +25,48 @@ public class RROPathKeySubobjectParser implements RROSubobjectParser, RROSubobje
 
        public static final int TYPE128 = 65;
 
-       public static final int PK_F_LENGTH = 2;
-       public static final int PCE_ID_F_LENGTH = 4;
+       private static final int PK_F_LENGTH = 2;
+       private static final int PCE_ID_F_LENGTH = 4;
 
-       public static final int PCE128_ID_F_LENGTH = 16;
+       private static final int PCE128_ID_F_LENGTH = 16;
 
-       public static final int PK_F_OFFSET = 0;
-       public static final int PCE_ID_F_OFFSET = PK_F_OFFSET + PK_F_LENGTH;
+       private static final int PK_F_OFFSET = 0;
+       private static final int PCE_ID_F_OFFSET = PK_F_OFFSET + PK_F_LENGTH;
 
-       public static final int CONTENT_LENGTH = PCE_ID_F_OFFSET + PCE_ID_F_LENGTH;
+       private static final int CONTENT_LENGTH = PCE_ID_F_OFFSET + PCE_ID_F_LENGTH;
+       private static final int CONTENT128_LENGTH = PCE_ID_F_OFFSET + PCE128_ID_F_LENGTH;
 
        @Override
        public Subobjects parseSubobject(final byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               if (buffer.length != CONTENT_LENGTH)
+               }
+               byte[] pceId = null;
+               if (buffer.length == CONTENT_LENGTH) {
+                       pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT_LENGTH);
+               } else if (buffer.length == CONTENT128_LENGTH) {
+                       pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT128_LENGTH);
+               } else {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >"
                                        + CONTENT_LENGTH + ".");
-
-               final int pathKey = ByteArray.bytesToShort(Arrays.copyOfRange(buffer, PK_F_OFFSET, PCE_ID_F_OFFSET)) & 0xFFFF;
-
-               final byte[] pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT_LENGTH);
-
+               }
+               final int pathKey = ByteArray.bytesToShort(Arrays.copyOfRange(buffer, PK_F_OFFSET, PCE_ID_F_OFFSET));
                final SubobjectsBuilder builder = new SubobjectsBuilder();
-               // builder.setSubobjectType(value);
+               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+               pBuilder.setPceId(new PceId(pceId));
+               pBuilder.setPathKey(new PathKey(pathKey));
+               builder.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
                return builder.build();
        }
 
        @Override
        public byte[] serializeSubobject(final Subobjects subobject) {
-               final byte[] retBytes = new byte[CONTENT_LENGTH];
-
-               // System.arraycopy(ByteArray.shortToBytes((short) objToSerialize.getPathKey()), 0, retBytes, PK_F_OFFSET,
-               // PK_F_LENGTH);
-               //
-               // if (objToSerialize.getPceId().length != PCE_ID_F_LENGTH)
-               // throw new IllegalArgumentException("Wrong length of pce id. Passed: " + objToSerialize.getPceId().length +
-               // ". Expected: ="
-               // + PCE_ID_F_LENGTH);
-               // System.arraycopy(objToSerialize.getPceId(), 0, retBytes, PCE_ID_F_OFFSET, PCE_ID_F_LENGTH);
-
+               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.PathKey pk = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.PathKey) subobject.getSubobjectType();
+               final int pathKey = pk.getPathKey().getPathKey().getValue();
+               final byte[] pceId = pk.getPathKey().getPceId().getBinary();
+               final byte[] retBytes = new byte[PK_F_LENGTH + pceId.length];
+               System.arraycopy(ByteArray.shortToBytes((short) pathKey), 0, retBytes, PK_F_OFFSET, PK_F_LENGTH);
+               System.arraycopy(pceId, 0, retBytes, PCE_ID_F_OFFSET, pceId.length);
                return retBytes;
        }
 
index d67be93d870b891c7c2be69052f8b4e359b8e19a..524d89306432fd36ba30aebf358e843157183eba 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
+import java.util.Arrays;
+import java.util.BitSet;
+
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
@@ -19,30 +22,38 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import com.google.common.primitives.UnsignedInts;
 
 /**
- * Parser for {@link org.opendaylight.protocol.pcep.subobject.RROUnnumberedInterfaceSubobject
- * RROUnnumberedInterfaceSubobject}
+ * Parser for {@link UnnumberedSubobject}
  */
 public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
 
        public static final int TYPE = 4;
 
-       public static final int ROUTER_ID_NUMBER_LENGTH = 4;
-       public static final int INTERFACE_ID_NUMBER_LENGTH = 4;
+       private static final int FLAGS_F_LENGTH = 1;
+       private static final int ROUTER_ID_NUMBER_LENGTH = 4;
+       private static final int INTERFACE_ID_NUMBER_LENGTH = 4;
+
+       private static final int ROUTER_ID_NUMBER_OFFSET = 2;
+       private static final int INTERFACE_ID_NUMBER_OFFSET = ROUTER_ID_NUMBER_OFFSET + ROUTER_ID_NUMBER_LENGTH;
 
-       public static final int ROUTER_ID_NUMBER_OFFSET = 2; // added reserved field of size 2
-       public static final int INTERFACE_ID_NUMBER_OFFSET = ROUTER_ID_NUMBER_OFFSET + ROUTER_ID_NUMBER_LENGTH;
+       private static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH;
 
-       public static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH;
+       private static final int LPA_F_OFFSET = 7;
+       private static final int LPIU_F_OFFSET = 6;
 
        @Override
        public Subobjects parseSubobject(final byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               if (buffer.length != CONTENT_LENGTH)
+               }
+               if (buffer.length != CONTENT_LENGTH) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
                                        + CONTENT_LENGTH + ".");
+               }
 
                final SubobjectsBuilder builder = new SubobjectsBuilder();
+               final BitSet flags = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, 0, FLAGS_F_LENGTH));
+               builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
+               builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
                final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
                ubuilder.setRouterId(ByteArray.bytesToLong(ByteArray.subByte(buffer, ROUTER_ID_NUMBER_OFFSET, ROUTER_ID_NUMBER_LENGTH)));
                ubuilder.setInterfaceId(UnsignedInts.toLong(ByteArray.bytesToInt(ByteArray.subByte(buffer, INTERFACE_ID_NUMBER_OFFSET,
@@ -53,18 +64,20 @@ public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser
 
        @Override
        public byte[] serializeSubobject(final Subobjects subobject) {
-               if (!(subobject.getSubobjectType() instanceof UnnumberedSubobject))
+               if (!(subobject.getSubobjectType() instanceof UnnumberedSubobject)) {
                        throw new IllegalArgumentException("Unknown ReportedRouteSubobject instance. Passed " + subobject.getSubobjectType().getClass()
                                        + ". Needed UnnumberedSubobject.");
-
-               byte[] retBytes;
-               retBytes = new byte[CONTENT_LENGTH];
+               }
+               final byte[] retBytes = new byte[CONTENT_LENGTH];
                final UnnumberedSubobject specObj = (UnnumberedSubobject) subobject.getSubobjectType();
-
-               ByteArray.copyWhole(ByteArray.longToBytes(specObj.getRouterId()), retBytes, ROUTER_ID_NUMBER_OFFSET);
+               final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
+               flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
+               flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
+               retBytes[0] = ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH)[0];
+               ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(specObj.getRouterId()), 4, ROUTER_ID_NUMBER_LENGTH), retBytes,
+                               ROUTER_ID_NUMBER_OFFSET);
                System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceId()), Long.SIZE / Byte.SIZE - INTERFACE_ID_NUMBER_LENGTH, retBytes,
                                INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH);
-
                return retBytes;
        }
 
index fff52fdb4ed7533ceb089a2051d9997fb06f79b7..4e538b7629c0ef0b983ce73cfe1732210f17a7fa 100644 (file)
@@ -11,9 +11,8 @@ import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.LabelParser;
 import org.opendaylight.protocol.pcep.spi.LabelSerializer;
 import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Type1Label;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.Type1Label;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.Type1LabelBuilder;
 
 import com.google.common.primitives.UnsignedInts;
@@ -26,21 +25,22 @@ public class Type1LabelParser implements LabelParser, LabelSerializer {
 
        @Override
        public LabelType parseLabel(final byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               if (buffer.length != LABEL_LENGTH)
+               }
+               if (buffer.length != LABEL_LENGTH) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: " + LABEL_LENGTH
                                        + ".");
-
+               }
                return new Type1LabelBuilder().setType1Label(UnsignedInts.toLong(ByteArray.bytesToInt(buffer))).build();
        }
 
        @Override
-       public byte[] serializeSubobject(final CLabel subobject) {
-               if (!(subobject instanceof Type1Label))
+       public byte[] serializeLabel(final LabelType subobject) {
+               if (!(subobject instanceof Type1Label)) {
                        throw new IllegalArgumentException("Unknown Label Subobject instance. Passed " + subobject.getClass() + ". Needed Type1Label.");
-
-               return ByteArray.longToBytes(((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.Type1Label) subobject).getType1Label().longValue());
+               }
+               return ByteArray.subByte(ByteArray.longToBytes(((Type1Label) subobject).getType1Label().longValue()), 4, LABEL_LENGTH);
        }
 
        @Override
index 8d612d2024222681470f89f1e114955f79b78e37..07290ce8b3c8251511c31fc2fadaa28ac42610f5 100644 (file)
@@ -11,55 +11,53 @@ import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.LabelParser;
 import org.opendaylight.protocol.pcep.spi.LabelSerializer;
 import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.WavebandSwitchingLabel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.WavebandSwitchingLabel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.WavebandSwitchingLabelBuilder;
 
+/**
+ * Parser for {@link WavebandSwitchingLabel}
+ */
 public class WavebandSwitchingLabelParser implements LabelParser, LabelSerializer {
 
        public static final int CTYPE = 3;
 
-       private static int WAVEB_F_LENGTH = 4;
-       private static int START_F_LENGTH = 4;
-       private static int END_F_LENGTH = 4;
+       private static final int WAVEB_F_LENGTH = 4;
+       private static final int START_F_LENGTH = 4;
+       private static final int END_F_LENGTH = 4;
 
-       private static int CONTENT_LENGTH = WAVEB_F_LENGTH + START_F_LENGTH + END_F_LENGTH;
+       private static final int CONTENT_LENGTH = WAVEB_F_LENGTH + START_F_LENGTH + END_F_LENGTH;
 
        @Override
-       public LabelType parseLabel(final byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+       public WavebandSwitchingLabel parseLabel(final byte[] buffer) throws PCEPDeserializerException {
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-
-               if (buffer.length != CONTENT_LENGTH)
+               }
+               if (buffer.length != CONTENT_LENGTH) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
                                        + CONTENT_LENGTH + ".");
-
+               }
                final WavebandSwitchingLabelBuilder builder = new WavebandSwitchingLabelBuilder();
-
                int byteOffset = 0;
                builder.setWavebandId(ByteArray.bytesToLong(ByteArray.subByte(buffer, byteOffset, WAVEB_F_LENGTH)));
                byteOffset += WAVEB_F_LENGTH;
                builder.setStartLabel(ByteArray.bytesToLong(ByteArray.subByte(buffer, byteOffset, START_F_LENGTH)));
                byteOffset += START_F_LENGTH;
                builder.setEndLabel(ByteArray.bytesToLong(ByteArray.subByte(buffer, byteOffset, END_F_LENGTH)));
-
                return builder.build();
        }
 
        @Override
-       public byte[] serializeSubobject(final CLabel subobject) {
-               if (!(subobject instanceof WavebandSwitchingLabel))
+       public byte[] serializeLabel(final LabelType subobject) {
+               if (!(subobject instanceof WavebandSwitchingLabel)) {
                        throw new IllegalArgumentException("Unknown Label Subobject instance. Passed " + subobject.getClass()
                                        + ". Needed WavebandSwitchingLabel.");
+               }
                final byte[] retBytes = new byte[CONTENT_LENGTH];
-
                final WavebandSwitchingLabel obj = (WavebandSwitchingLabel) subobject;
-
                System.arraycopy(ByteArray.intToBytes(obj.getWavebandId().intValue()), 0, retBytes, 0, WAVEB_F_LENGTH);
                System.arraycopy(ByteArray.intToBytes(obj.getStartLabel().intValue()), 0, retBytes, WAVEB_F_LENGTH, START_F_LENGTH);
                System.arraycopy(ByteArray.intToBytes(obj.getEndLabel().intValue()), 0, retBytes, WAVEB_F_LENGTH + START_F_LENGTH, END_F_LENGTH);
-
                return retBytes;
        }
 
index c406f15c60011cdac1768a7472ff893d6c1986b8..79323aa9a543d7806c9aaec4ed489de1ba887c67 100644 (file)
@@ -20,42 +20,39 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 /**
  * Parser for {@link AsNumberSubobject}
  */
-
 public class XROAsNumberSubobjectParser implements XROSubobjectParser, XROSubobjectSerializer {
 
        public static final int TYPE = 32;
 
-       public static final int AS_NUMBER_LENGTH = 2;
+       private static final int AS_NUMBER_LENGTH = 2;
 
-       public static final int AS_NUMBER_OFFSET = 0;
+       private static final int AS_NUMBER_OFFSET = 0;
 
-       public static final int CONTENT_LENGTH = AS_NUMBER_LENGTH + AS_NUMBER_OFFSET;
+       private static final int CONTENT_LENGTH = AS_NUMBER_LENGTH + AS_NUMBER_OFFSET;
 
        @Override
        public Subobjects parseSubobject(final byte[] buffer, final boolean mandatory) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               if (buffer.length != CONTENT_LENGTH)
+               }
+               if (buffer.length != CONTENT_LENGTH) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
                                        + CONTENT_LENGTH + ".");
-
+               }
                return new SubobjectsBuilder().setMandatory(mandatory).setSubobjectType(
                                new AsNumberBuilder().setAsNumber(new AsNumber(ByteArray.bytesToLong(buffer))).build()).build();
        }
 
        @Override
        public byte[] serializeSubobject(final Subobjects subobject) {
-               if (!(subobject.getSubobjectType() instanceof AsNumberSubobject))
+               if (!(subobject.getSubobjectType() instanceof AsNumberSubobject)) {
                        throw new IllegalArgumentException("Unknown PCEPXROSubobject instance. Passed " + subobject.getSubobjectType().getClass()
                                        + ". Needed AsNumberSubobject.");
-
+               }
                final byte[] retBytes = new byte[CONTENT_LENGTH];
-
                final AsNumberSubobject obj = (AsNumberSubobject) subobject.getSubobjectType();
-
                System.arraycopy(ByteArray.longToBytes(obj.getAsNumber().getValue()), Long.SIZE / Byte.SIZE - AS_NUMBER_LENGTH, retBytes,
                                AS_NUMBER_OFFSET, AS_NUMBER_LENGTH);
-
                return retBytes;
        }
 
index d4983b98cecd17527baeb5659bfd0e6beb806619..689e062b88c288a9011004ff7a696a9d5b250eb8 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.protocol.pcep.impl.subobject;
 
 import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
@@ -30,60 +31,70 @@ public class XROIpPrefixSubobjectParser implements XROSubobjectParser, XROSubobj
 
        public static final int TYPE6 = 2;
 
-       public static final int IP4_F_LENGTH = 4;
-       public static final int PREFIX_F_LENGTH = 1;
-       public static final int ATTRIBUTE_LENGTH = 1;
+       private static final int IP4_F_LENGTH = 4;
+       private static final int PREFIX_F_LENGTH = 1;
+       private static final int ATTRIBUTE_LENGTH = 1;
 
-       public static final int IP_F_OFFSET = 0;
-       public static final int PREFIX4_F_OFFSET = IP_F_OFFSET + IP4_F_LENGTH;
-       public static final int ATTRIBUTE4_OFFSET = PREFIX4_F_OFFSET + PREFIX_F_LENGTH;
+       private static final int IP_F_OFFSET = 0;
+       private static final int PREFIX4_F_OFFSET = IP_F_OFFSET + IP4_F_LENGTH;
+       private static final int ATTRIBUTE4_OFFSET = PREFIX4_F_OFFSET + PREFIX_F_LENGTH;
 
-       public static final int CONTENT4_LENGTH = ATTRIBUTE4_OFFSET + ATTRIBUTE_LENGTH;
+       private static final int CONTENT4_LENGTH = ATTRIBUTE4_OFFSET + ATTRIBUTE_LENGTH;
 
-       public static final int IP6_F_LENGTH = 16;
-       public static final int PREFIX6_F_OFFSET = IP_F_OFFSET + IP6_F_LENGTH;
-       public static final int ATTRIBUTE6_OFFSET = PREFIX6_F_OFFSET + PREFIX_F_LENGTH;
+       private static final int IP6_F_LENGTH = 16;
+       private static final int PREFIX6_F_OFFSET = IP_F_OFFSET + IP6_F_LENGTH;
+       private static final int ATTRIBUTE6_OFFSET = PREFIX6_F_OFFSET + PREFIX_F_LENGTH;
 
-       public static final int CONTENT6_LENGTH = ATTRIBUTE6_OFFSET + ATTRIBUTE_LENGTH;
+       private static final int CONTENT6_LENGTH = ATTRIBUTE6_OFFSET + ATTRIBUTE_LENGTH;
 
        @Override
        public Subobjects parseSubobject(final byte[] buffer, final boolean mandatory) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               if (buffer.length != CONTENT4_LENGTH && buffer.length != CONTENT6_LENGTH)
-                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + ";");
-
-               final int length = UnsignedBytes.toInt(buffer[PREFIX4_F_OFFSET]);
-
+               }
                final SubobjectsBuilder builder = new SubobjectsBuilder();
                builder.setMandatory(mandatory);
-               builder.setAttribute(Attribute.forValue(buffer[ATTRIBUTE4_OFFSET] & 0xFF));
-               builder.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
-                               new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.subByte(buffer, IP_F_OFFSET, IP4_F_LENGTH), length))).build());
+               if (buffer.length == CONTENT4_LENGTH) {
+                       final int length = UnsignedBytes.toInt(buffer[PREFIX4_F_OFFSET]);
+                       builder.setAttribute(Attribute.forValue(UnsignedBytes.toInt(buffer[ATTRIBUTE4_OFFSET])));
+                       builder.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+                                       new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.subByte(buffer, IP_F_OFFSET, IP4_F_LENGTH), length))).build());
+               } else if (buffer.length == CONTENT6_LENGTH) {
+                       final int length = UnsignedBytes.toInt(buffer[PREFIX6_F_OFFSET]);
+                       builder.setAttribute(Attribute.forValue(UnsignedBytes.toInt(buffer[ATTRIBUTE6_OFFSET])));
+                       builder.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+                                       new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.subByte(buffer, IP_F_OFFSET, IP6_F_LENGTH), length))).build());
+               } else {
+                       throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + ";");
+               }
                return builder.build();
        }
 
        @Override
        public byte[] serializeSubobject(final Subobjects subobject) {
-               if (!(subobject.getSubobjectType() instanceof IpPrefixSubobject))
+               if (!(subobject.getSubobjectType() instanceof IpPrefixSubobject)) {
                        throw new IllegalArgumentException("Unknown PCEPXROSubobject instance. Passed " + subobject.getSubobjectType().getClass()
                                        + ". Needed IpPrefixSubobject.");
+               }
 
                final IpPrefixSubobject specObj = (IpPrefixSubobject) subobject.getSubobjectType();
                final IpPrefix prefix = specObj.getIpPrefix();
 
-               if (prefix.getIpv4Prefix() == null && prefix.getIpv6Prefix() == null)
+               if (prefix.getIpv4Prefix() == null && prefix.getIpv6Prefix() == null) {
                        throw new IllegalArgumentException("Unknown AbstractPrefix instance. Passed " + prefix.getClass() + ".");
+               }
 
                if (prefix.getIpv4Prefix() != null) {
                        final byte[] retBytes = new byte[CONTENT4_LENGTH];
-                       ByteArray.copyWhole(prefix.getIpv4Prefix().getValue().getBytes(), retBytes, IP_F_OFFSET);
+                       ByteArray.copyWhole(Ipv4Util.bytesForPrefix(prefix.getIpv4Prefix()), retBytes, IP_F_OFFSET);
                        retBytes[PREFIX4_F_OFFSET] = ByteArray.intToBytes(Ipv4Util.getPrefixLength(prefix))[Integer.SIZE / Byte.SIZE - 1];
+                       retBytes[ATTRIBUTE4_OFFSET] = UnsignedBytes.checkedCast(subobject.getAttribute().getIntValue());
                        return retBytes;
                } else {
                        final byte[] retBytes = new byte[CONTENT6_LENGTH];
-                       ByteArray.copyWhole(prefix.getIpv6Prefix().getValue().getBytes(), retBytes, IP_F_OFFSET);
+                       ByteArray.copyWhole(Ipv6Util.bytesForPrefix(prefix.getIpv6Prefix()), retBytes, IP_F_OFFSET);
                        retBytes[PREFIX6_F_OFFSET] = ByteArray.intToBytes(Ipv4Util.getPrefixLength(prefix))[Integer.SIZE / Byte.SIZE - 1];
+                       retBytes[ATTRIBUTE6_OFFSET] = UnsignedBytes.checkedCast(subobject.getAttribute().getIntValue());
                        return retBytes;
                }
        }
index 809871c2b3c42255eb40d25948f7f13b47154a85..1cd0b94cc8e1d30715cf9ca9ec96e74530c012c1 100644 (file)
@@ -13,55 +13,65 @@ import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
 import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeySubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKeyBuilder;
 
+/**
+ * Parser for {@link PathKeySubobject}
+ */
 public class XROPathKeySubobjectParser implements XROSubobjectParser, XROSubobjectSerializer {
 
        public static final int TYPE = 64;
 
        public static final int TYPE128 = 65;
 
-       public static final int PK_F_LENGTH = 2;
-       public static final int PCE_ID_F_LENGTH = 4;
+       private static final int PK_F_LENGTH = 2;
+       private static final int PCE_ID_F_LENGTH = 4;
 
-       public static final int PCE128_ID_F_LENGTH = 16;
+       private static final int PCE128_ID_F_LENGTH = 16;
 
-       public static final int PK_F_OFFSET = 0;
-       public static final int PCE_ID_F_OFFSET = PK_F_OFFSET + PK_F_LENGTH;
+       private static final int PK_F_OFFSET = 0;
+       private static final int PCE_ID_F_OFFSET = PK_F_OFFSET + PK_F_LENGTH;
 
-       public static final int CONTENT_LENGTH = PCE_ID_F_OFFSET + PCE_ID_F_LENGTH;
+       private static final int CONTENT_LENGTH = PCE_ID_F_OFFSET + PCE_ID_F_LENGTH;
+       private static final int CONTENT128_LENGTH = PCE_ID_F_OFFSET + PCE128_ID_F_LENGTH;
 
        @Override
        public Subobjects parseSubobject(final byte[] buffer, final boolean mandatory) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               if (buffer.length != CONTENT_LENGTH)
+               }
+               byte[] pceId = null;
+               if (buffer.length == CONTENT_LENGTH) {
+                       pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT_LENGTH);
+               } else if (buffer.length == CONTENT128_LENGTH) {
+                       pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT128_LENGTH);
+               } else {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >"
                                        + CONTENT_LENGTH + ".");
-
-               final int pathKey = ByteArray.bytesToShort(Arrays.copyOfRange(buffer, PK_F_OFFSET, PCE_ID_F_OFFSET)) & 0xFFFF;
-
-               final byte[] pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT_LENGTH);
-
+               }
+               final int pathKey = ByteArray.bytesToShort(Arrays.copyOfRange(buffer, PK_F_OFFSET, PCE_ID_F_OFFSET));
                final SubobjectsBuilder builder = new SubobjectsBuilder();
-               // builder.setSubobjectType(value);
+               builder.setMandatory(mandatory);
+               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+               pBuilder.setPceId(new PceId(pceId));
+               pBuilder.setPathKey(new PathKey(pathKey));
+               builder.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
                return builder.build();
        }
 
        @Override
        public byte[] serializeSubobject(final Subobjects subobject) {
-               final byte[] retBytes = new byte[CONTENT_LENGTH];
-
-               // System.arraycopy(ByteArray.shortToBytes((short) objToSerialize.getPathKey()), 0, retBytes, PK_F_OFFSET,
-               // PK_F_LENGTH);
-               //
-               // if (objToSerialize.getPceId().length != PCE_ID_F_LENGTH)
-               // throw new IllegalArgumentException("Wrong length of pce id. Passed: " + objToSerialize.getPceId().length +
-               // ". Expected: ="
-               // + PCE_ID_F_LENGTH);
-               // System.arraycopy(objToSerialize.getPceId(), 0, retBytes, PCE_ID_F_OFFSET, PCE_ID_F_LENGTH);
-
+               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKey pk = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKey) subobject.getSubobjectType();
+               final int pathKey = pk.getPathKey().getPathKey().getValue();
+               final byte[] pceId = pk.getPathKey().getPceId().getBinary();
+               final byte[] retBytes = new byte[PK_F_LENGTH + pceId.length];
+               System.arraycopy(ByteArray.shortToBytes((short) pathKey), 0, retBytes, PK_F_OFFSET, PK_F_LENGTH);
+               System.arraycopy(pceId, 0, retBytes, PCE_ID_F_OFFSET, pceId.length);
                return retBytes;
        }
 
index 306ff013684295b0a82b694949b1ea7766252848..87a7fa918e9b9ef30930d5d428116216247ca0b2 100644 (file)
@@ -18,6 +18,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.SrlgSubobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.SrlgBuilder;
 
+import com.google.common.primitives.UnsignedBytes;
+
 /**
  * Parser for {@link SrlgSubobject}
  */
@@ -25,22 +27,23 @@ public class XROSRLGSubobjectParser implements XROSubobjectParser, XROSubobjectS
 
        public static final int TYPE = 34;
 
-       public static final int SRLG_ID_NUMBER_LENGTH = 4;
-       public static final int ATTRIBUTE_LENGTH = 1;
+       private static final int SRLG_ID_NUMBER_LENGTH = 4;
+       private static final int ATTRIBUTE_LENGTH = 1;
 
-       public static final int SRLG_ID_NUMBER_OFFSET = 0;
-       public static final int ATTRIBUTE_OFFSET = SRLG_ID_NUMBER_OFFSET + SRLG_ID_NUMBER_LENGTH + 1; // added reserved
-                                                                                                                                                                                                       // field of size 1
+       private static final int SRLG_ID_NUMBER_OFFSET = 0;
+       private static final int ATTRIBUTE_OFFSET = SRLG_ID_NUMBER_OFFSET + SRLG_ID_NUMBER_LENGTH;
 
-       public static final int CONTENT_LENGTH = ATTRIBUTE_OFFSET + ATTRIBUTE_LENGTH;
+       private static final int CONTENT_LENGTH = SRLG_ID_NUMBER_LENGTH + ATTRIBUTE_LENGTH;
 
        @Override
        public Subobjects parseSubobject(final byte[] buffer, final boolean mandatory) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               if (buffer.length != CONTENT_LENGTH)
+               }
+               if (buffer.length != CONTENT_LENGTH) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
                                        + CONTENT_LENGTH + ".");
+               }
 
                final SubobjectsBuilder builder = new SubobjectsBuilder();
                builder.setMandatory(mandatory);
@@ -52,16 +55,18 @@ public class XROSRLGSubobjectParser implements XROSubobjectParser, XROSubobjectS
 
        @Override
        public byte[] serializeSubobject(final Subobjects subobject) {
-               if (!(subobject.getSubobjectType() instanceof SrlgSubobject))
+               if (!(subobject.getSubobjectType() instanceof SrlgSubobject)) {
                        throw new IllegalArgumentException("Unknown PCEPXROSubobject instance. Passed " + subobject.getSubobjectType().getClass()
                                        + ". Needed SrlgSubobject.");
+               }
 
                byte[] retBytes;
                retBytes = new byte[CONTENT_LENGTH];
                final SrlgSubobject specObj = (SrlgSubobject) subobject.getSubobjectType();
 
-               ByteArray.copyWhole(ByteArray.longToBytes(specObj.getSrlgId().getValue()), retBytes, SRLG_ID_NUMBER_OFFSET);
-               retBytes[ATTRIBUTE_OFFSET] = (byte) subobject.getAttribute().getIntValue();
+               ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(specObj.getSrlgId().getValue()), 4, SRLG_ID_NUMBER_LENGTH), retBytes,
+                               SRLG_ID_NUMBER_OFFSET);
+               retBytes[ATTRIBUTE_OFFSET] = UnsignedBytes.checkedCast(subobject.getAttribute().getIntValue());
 
                return retBytes;
        }
index ada6e0dee599872b37f4ca46780c0a16f122a962..c0547217e1d7274c711b5f1faa1ea65cb877f599 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.UnnumberedSubobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.UnnumberedBuilder;
 
+import com.google.common.primitives.UnsignedBytes;
 import com.google.common.primitives.UnsignedInts;
 
 /**
@@ -26,23 +27,25 @@ public class XROUnnumberedInterfaceSubobjectParser implements XROSubobjectParser
 
        public static final int TYPE = 4;
 
-       public static final int ATTRIBUTE_LENGTH = 1;
-       public static final int ROUTER_ID_NUMBER_LENGTH = 4;
-       public static final int INTERFACE_ID_NUMBER_LENGTH = 4;
+       private static final int ATTRIBUTE_LENGTH = 1;
+       private static final int ROUTER_ID_NUMBER_LENGTH = 4;
+       private static final int INTERFACE_ID_NUMBER_LENGTH = 4;
 
-       public static final int ATTRIBUTE_OFFSET = 1;// added reserved field of size 1
-       public static final int ROUTER_ID_NUMBER_OFFSET = ATTRIBUTE_OFFSET + ATTRIBUTE_LENGTH;
-       public static final int INTERFACE_ID_NUMBER_OFFSET = ROUTER_ID_NUMBER_OFFSET + ROUTER_ID_NUMBER_LENGTH;
+       private static final int ATTRIBUTE_OFFSET = 1;
+       private static final int ROUTER_ID_NUMBER_OFFSET = ATTRIBUTE_OFFSET + ATTRIBUTE_LENGTH;
+       private static final int INTERFACE_ID_NUMBER_OFFSET = ROUTER_ID_NUMBER_OFFSET + ROUTER_ID_NUMBER_LENGTH;
 
-       public static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH;
+       private static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH;
 
        @Override
        public Subobjects parseSubobject(final byte[] buffer, final boolean mandatory) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-               if (buffer.length != CONTENT_LENGTH)
+               }
+               if (buffer.length != CONTENT_LENGTH) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
                                        + CONTENT_LENGTH + ".");
+               }
 
                final SubobjectsBuilder builder = new SubobjectsBuilder();
                final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
@@ -51,22 +54,23 @@ public class XROUnnumberedInterfaceSubobjectParser implements XROSubobjectParser
                                INTERFACE_ID_NUMBER_LENGTH))));
                builder.setSubobjectType(ubuilder.build());
                builder.setMandatory(mandatory);
-               builder.setAttribute(Attribute.forValue(buffer[ATTRIBUTE_OFFSET] & 0xFF));
+               builder.setAttribute(Attribute.forValue(UnsignedBytes.toInt(buffer[ATTRIBUTE_OFFSET])));
                return builder.build();
        }
 
        @Override
        public byte[] serializeSubobject(final Subobjects subobject) {
-               if (!(subobject.getSubobjectType() instanceof UnnumberedSubobject))
+               if (!(subobject.getSubobjectType() instanceof UnnumberedSubobject)) {
                        throw new IllegalArgumentException("Unknown PCEPXROSubobject instance. Passed " + subobject.getSubobjectType().getClass()
                                        + ". Needed UnnumberedSubobject.");
+               }
 
-               byte[] retBytes;
-               retBytes = new byte[CONTENT_LENGTH];
+               final byte[] retBytes = new byte[CONTENT_LENGTH];
                final UnnumberedSubobject specObj = (UnnumberedSubobject) subobject.getSubobjectType();
 
-               retBytes[ATTRIBUTE_OFFSET] = (byte) subobject.getAttribute().getIntValue();
-               ByteArray.copyWhole(ByteArray.longToBytes(specObj.getRouterId()), retBytes, ROUTER_ID_NUMBER_OFFSET);
+               retBytes[ATTRIBUTE_OFFSET] = UnsignedBytes.checkedCast(subobject.getAttribute().getIntValue());
+               ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(specObj.getRouterId()), 4, ROUTER_ID_NUMBER_LENGTH), retBytes,
+                               ROUTER_ID_NUMBER_OFFSET);
                System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceId()), Long.SIZE / Byte.SIZE - INTERFACE_ID_NUMBER_LENGTH, retBytes,
                                INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH);
                return retBytes;
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierIPv4TlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierIPv4TlvParser.java
deleted file mode 100644 (file)
index 7f93243..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.pcep.impl.tlv;
-
-import org.opendaylight.protocol.concepts.Ipv4Util;
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvParser;
-import org.opendaylight.protocol.pcep.spi.TlvSerializer;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv4;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv4Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv6;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.LspIdentifiersBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv4ExtendedTunnelId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.TunnelId;
-
-/**
- * Parser for {@link LspIdentifiersTlv}
- */
-public class LSPIdentifierIPv4TlvParser implements TlvParser, TlvSerializer {
-
-       public static final int TYPE = 18;
-
-       private static final int IP_F_LENGTH = 4;
-       private static final int LSP_ID_F_LENGTH = 2;
-       private static final int TUNNEL_ID_F_LENGTH = 2;
-       private static final int EX_TUNNEL_ID_F_LENGTH = 4;
-
-       @Override
-       public LspIdentifiersTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               int position = 0;
-               if (valueBytes == null || valueBytes.length == 0)
-                       throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
-
-               final AddressFamily afi = new Ipv4Builder().setIpv4TunnelSenderAddress(
-                               Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP_F_LENGTH))).setIpv4ExtendedTunnelId(
-                               new Ipv4ExtendedTunnelId(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position += IP_F_LENGTH,
-                                               EX_TUNNEL_ID_F_LENGTH)))).build();
-
-               return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(
-                               new LspId(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, position += EX_TUNNEL_ID_F_LENGTH, LSP_ID_F_LENGTH)))).setTunnelId(
-                               new TunnelId(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, position += LSP_ID_F_LENGTH, TUNNEL_ID_F_LENGTH)))).build();
-       }
-
-       @Override
-       public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
-                       throw new IllegalArgumentException("LspIdentifiersTlv is mandatory.");
-               final LspIdentifiersTlv lsp = (LspIdentifiersTlv) tlv;
-               final AddressFamily afi = lsp.getAddressFamily();
-               if (afi.getClass().equals(Ipv4.class)) {
-                       final Ipv4 ipv4 = (Ipv4) afi;
-                       // buffer.writeBytes(ipv4.getIpv4TunnelSenderAddress().getValue().getBytes());
-                       // buffer.writeBytes(ByteArray.subByte(ByteArray.longToBytes(lsp.getLspId().getValue()), 6,
-                       // LSP_ID_F_LENGTH));
-                       // buffer.writeBytes(ByteArray.subByte(ByteArray.intToBytes(lsp.getTunnelId().getValue()), 2,
-                       // TUNNEL_ID_F_LENGTH));
-                       // buffer.writeBytes(ipv4.getIpv4TunnelSenderAddress().getValue().getBytes());
-               } else {
-                       final Ipv6 ipv6 = (Ipv6) afi;
-                       // buffer.writeBytes(ipv6.getIpv6TunnelSenderAddress().getValue().getBytes());
-                       // buffer.writeBytes(ByteArray.subByte(ByteArray.longToBytes(lsp.getLspId().getValue()), 6,
-                       // LSP_ID_F_LENGTH));
-                       // buffer.writeBytes(ByteArray.subByte(ByteArray.intToBytes(lsp.getTunnelId().getValue()), 2,
-                       // TUNNEL_ID_F_LENGTH));
-                       // buffer.writeBytes(ipv6.getIpv6TunnelSenderAddress().getValue().getBytes());
-               }
-               // FIXME finish
-               return null;
-       }
-
-       @Override
-       public int getType() {
-               return TYPE;
-       }
-}
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierIPv6TlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierIPv6TlvParser.java
deleted file mode 100644 (file)
index 11206a5..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.pcep.impl.tlv;
-
-import org.opendaylight.protocol.concepts.Ipv6Util;
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvParser;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv6Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.LspIdentifiersBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv6ExtendedTunnelId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.TunnelId;
-
-/**
- * Parser for {@link LspIdentifiersTlv}
- */
-public class LSPIdentifierIPv6TlvParser implements TlvParser {
-
-       public static final int TYPE = 19;
-
-       private static final int IP_F_LENGTH = 16;
-       private static final int LSP_ID_F_LENGTH = 2;
-       private static final int TUNNEL_ID_F_LENGTH = 2;
-       private static final int EX_TUNNEL_ID_F_LENGTH = 16;
-
-       @Override
-       public LspIdentifiersTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               int position = 0;
-               if (valueBytes == null || valueBytes.length == 0)
-                       throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
-
-               final AddressFamily afi = new Ipv6Builder().setIpv6TunnelSenderAddress(
-                               Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP_F_LENGTH))).setIpv6ExtendedTunnelId(
-                               new Ipv6ExtendedTunnelId(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position += IP_F_LENGTH,
-                                               EX_TUNNEL_ID_F_LENGTH)))).build();
-
-               return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(
-                               new LspId(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, position += EX_TUNNEL_ID_F_LENGTH, LSP_ID_F_LENGTH)))).setTunnelId(
-                               new TunnelId(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, position += LSP_ID_F_LENGTH, TUNNEL_ID_F_LENGTH)))).build();
-       }
-
-       public int getType() {
-               return TYPE;
-       }
-}
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierTlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierTlvParser.java
new file mode 100644 (file)
index 0000000..1da47a5
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.impl.tlv;
+
+import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.TlvParser;
+import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.LspIdentifiersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv4ExtendedTunnelId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv6ExtendedTunnelId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.TunnelId;
+
+/**
+ * Parser for {@link LspIdentifiersTlv}
+ */
+public class LSPIdentifierTlvParser implements TlvParser, TlvSerializer {
+
+       public static final int TYPE = 18;
+
+       public static final int TYPE_6 = 19;
+
+       private static final int IP6_F_LENGTH = 16;
+       private static final int EX_TUNNEL_ID6_F_LENGTH = 16;
+       private static final int IP4_F_LENGTH = 4;
+       private static final int EX_TUNNEL_ID4_F_LENGTH = 4;
+
+       private static final int LSP_ID_F_LENGTH = 2;
+       private static final int TUNNEL_ID_F_LENGTH = 2;
+
+       private static final int V4_LENGTH = 12;
+       private static final int V6_LENGTH = 36;
+
+       @Override
+       public LspIdentifiersTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
+               int position = 0;
+               if (valueBytes == null || valueBytes.length == 0) {
+                       throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
+               }
+               AddressFamily afi = null;
+               LspId lspId = null;
+               TunnelId tunnelId = null;
+               if (valueBytes.length == V4_LENGTH) {
+                       final Ipv4Builder builder = new Ipv4Builder();
+                       builder.setIpv4TunnelSenderAddress(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP4_F_LENGTH)));
+                       position += IP4_F_LENGTH;
+                       lspId = new LspId(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, position, LSP_ID_F_LENGTH)));
+                       position += LSP_ID_F_LENGTH;
+                       tunnelId = new TunnelId(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, position, TUNNEL_ID_F_LENGTH)));
+                       position += TUNNEL_ID_F_LENGTH;
+                       builder.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position,
+                                       EX_TUNNEL_ID4_F_LENGTH))));
+                       afi = builder.build();
+                       position += EX_TUNNEL_ID4_F_LENGTH;
+               } else if (valueBytes.length == V6_LENGTH) {
+                       final Ipv6Builder builder = new Ipv6Builder();
+                       builder.setIpv6TunnelSenderAddress(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP6_F_LENGTH)));
+                       position += IP6_F_LENGTH;
+                       lspId = new LspId(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, position, LSP_ID_F_LENGTH)));
+                       position += LSP_ID_F_LENGTH;
+                       tunnelId = new TunnelId(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, position, TUNNEL_ID_F_LENGTH)));
+                       position += TUNNEL_ID_F_LENGTH;
+                       builder.setIpv6ExtendedTunnelId(new Ipv6ExtendedTunnelId(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position,
+                                       EX_TUNNEL_ID6_F_LENGTH))));
+                       afi = builder.build();
+                       position += EX_TUNNEL_ID6_F_LENGTH;
+               } else {
+                       throw new IllegalArgumentException("Length " + valueBytes.length + " does not match LSP Identifiers tlv lengths.");
+               }
+
+               return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(lspId).setTunnelId(tunnelId).build();
+       }
+
+       @Override
+       public byte[] serializeTlv(final Tlv tlv) {
+               if (tlv == null) {
+                       throw new IllegalArgumentException("LspIdentifiersTlv is mandatory.");
+               }
+               final LspIdentifiersTlv lsp = (LspIdentifiersTlv) tlv;
+               final AddressFamily afi = lsp.getAddressFamily();
+               int offset = 0;
+               if (afi.getImplementedInterface().equals(Ipv4.class)) {
+                       final byte[] bytes = new byte[V4_LENGTH];
+                       final Ipv4 ipv4 = (Ipv4) afi;
+                       ByteArray.copyWhole(Ipv4Util.bytesForAddress(ipv4.getIpv4TunnelSenderAddress()), bytes, offset);
+                       offset += IP4_F_LENGTH;
+                       ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(lsp.getLspId().getValue()), 6, LSP_ID_F_LENGTH), bytes, offset);
+                       offset += LSP_ID_F_LENGTH;
+                       ByteArray.copyWhole(ByteArray.subByte(ByteArray.intToBytes(lsp.getTunnelId().getValue()), 2, TUNNEL_ID_F_LENGTH), bytes, offset);
+                       offset += TUNNEL_ID_F_LENGTH;
+                       ByteArray.copyWhole(Ipv4Util.bytesForAddress(ipv4.getIpv4ExtendedTunnelId()), bytes, offset);
+                       return bytes;
+               } else {
+                       final byte[] bytes = new byte[V6_LENGTH];
+                       final Ipv6 ipv6 = (Ipv6) afi;
+                       ByteArray.copyWhole(Ipv6Util.bytesForAddress(ipv6.getIpv6TunnelSenderAddress()), bytes, offset);
+                       offset += IP6_F_LENGTH;
+                       ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(lsp.getLspId().getValue()), 6, LSP_ID_F_LENGTH), bytes, offset);
+                       offset += LSP_ID_F_LENGTH;
+                       ByteArray.copyWhole(ByteArray.subByte(ByteArray.intToBytes(lsp.getTunnelId().getValue()), 2, TUNNEL_ID_F_LENGTH), bytes, offset);
+                       offset += TUNNEL_ID_F_LENGTH;
+                       ByteArray.copyWhole(Ipv6Util.bytesForAddress(ipv6.getIpv6ExtendedTunnelId()), bytes, offset);
+                       return bytes;
+               }
+       }
+
+       @Override
+       public int getType() {
+               return TYPE;
+       }
+
+       public int getType6() {
+               return TYPE_6;
+       }
+}
index 904cf1b52cd3ebec0b70ebaa1598f26bf4179263..2930bcac890b2091a50df5ac483297c5a07c773c 100644 (file)
@@ -33,8 +33,9 @@ public class LspDbVersionTlvParser implements TlvParser, TlvSerializer {
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("LspDbVersionTlv is mandatory.");
+               }
                final LspDbVersionTlv lsp = (LspDbVersionTlv) tlv;
                return ByteArray.subByte(lsp.getVersion().toByteArray(), 0, DBV_F_LENGTH);
        }
index 1b1ccbcfb619255f5ffee6b2ed67b39a7ae4c18a..4a9ccae2f66bcf254f2110b37bcc1357e7a7d3a9 100644 (file)
@@ -10,9 +10,10 @@ package org.opendaylight.protocol.pcep.impl.tlv;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SymbolicPathName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SymbolicPathNameTlv;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.SymblicPathNameBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.SymbolicPathNameBuilder;
 
 /**
  * Parser for {@link SymbolicPathNameTlv}
@@ -23,15 +24,16 @@ public class LspSymbolicNameTlvParser implements TlvParser, TlvSerializer {
 
        @Override
        public SymbolicPathNameTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException {
-               return new SymblicPathNameBuilder().setPathName(buffer).build();
+               return new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(buffer)).build();
        }
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("SymbolicPathNameTlv is mandatory.");
+               }
                final SymbolicPathNameTlv spn = (SymbolicPathNameTlv) tlv;
-               return spn.getPathName();
+               return spn.getPathName().getValue();
        }
 
        @Override
index ad2f67616af17a1b7b425a7f0d4bb5b1bf43e199..6322b42d5590300d2c02524c95946856d577e37b 100644 (file)
@@ -31,10 +31,11 @@ public class LspUpdateErrorTlvParser implements TlvParser, TlvSerializer {
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("LspErrorCodeTlv is mandatory.");
+               }
                final LspErrorCodeTlv lsp = (LspErrorCodeTlv) tlv;
-               return ByteArray.subByte(ByteArray.longToBytes(lsp.getErrorCode()), 0, UPDATE_ERR_CODE_LENGTH);
+               return ByteArray.subByte(ByteArray.longToBytes(lsp.getErrorCode()), UPDATE_ERR_CODE_LENGTH, UPDATE_ERR_CODE_LENGTH);
        }
 
        @Override
index 510d678043c70593d7d2253af57b69aec91d5b3a..2eba141a7fa374da6580f30252526e75d9f650b1 100644 (file)
@@ -25,56 +25,47 @@ public class NoPathVectorTlvParser implements TlvParser, TlvSerializer {
 
        public static final int TYPE = 1;
 
-       public static final int FLAGS_F_LENGTH = 4;
+       private static final int FLAGS_F_LENGTH = 4;
 
-       /*
-        * flags offsets inside flags field in bits
-        */
-       public static final int PCE_UNAVAILABLE = 31;
-       public static final int UNKNOWN_DEST = 30;
-       public static final int UNKNOWN_SRC = 29;
-
-       /*
-        * flags offsets of flags added by GCO extension
-        */
-       public static final int NO_GCO_SOLUTION = 25;
-       public static final int NO_GCO_MIGRATION_PATH = 26;
-
-       /*
-        * flags offsets of flags added by RFC 6006
-        */
-       public static final int REACHABLITY_PROBLEM = 24;
+       private static final int REACHABLITY_PROBLEM = 24;
+       private static final int NO_GCO_SOLUTION = 25;
+       private static final int NO_GCO_MIGRATION_PATH = 26;
+       private static final int PATH_KEY = 27;
+       private static final int CHAIN_UNAVAILABLE = 28;
+       private static final int UNKNOWN_SRC = 29;
+       private static final int UNKNOWN_DEST = 30;
+       private static final int PCE_UNAVAILABLE = 31;
 
        @Override
        public NoPathVectorTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               if (valueBytes == null || valueBytes.length == 0)
+               if (valueBytes == null || valueBytes.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-
-               if (valueBytes.length != FLAGS_F_LENGTH)
+               }
+               if (valueBytes.length != FLAGS_F_LENGTH) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + "; Expected: >="
                                        + FLAGS_F_LENGTH + ".");
-
+               }
                final BitSet flags = ByteArray.bytesToBitSet(valueBytes);
-
                return new NoPathVectorBuilder().setFlags(
-                               new Flags(false, flags.get(NO_GCO_MIGRATION_PATH), flags.get(NO_GCO_SOLUTION), flags.get(REACHABLITY_PROBLEM), false, flags.get(PCE_UNAVAILABLE), flags.get(UNKNOWN_DEST), flags.get(UNKNOWN_SRC))).build();
+                               new Flags(flags.get(CHAIN_UNAVAILABLE), flags.get(NO_GCO_MIGRATION_PATH), flags.get(NO_GCO_SOLUTION), flags.get(REACHABLITY_PROBLEM), flags.get(PATH_KEY), flags.get(PCE_UNAVAILABLE), flags.get(UNKNOWN_DEST), flags.get(UNKNOWN_SRC))).build();
        }
 
        @Override
        public byte[] serializeTlv(final Tlv tlvs) {
-               if (tlvs == null)
+               if (tlvs == null) {
                        throw new IllegalArgumentException("NoPathVectorTlv is mandatory.");
+               }
                final NoPathVectorTlv tlv = (NoPathVectorTlv) tlvs;
 
                final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
-
-               flags.set(PCE_UNAVAILABLE, tlv.getFlags().isPceUnavailable());
-               flags.set(UNKNOWN_DEST, tlv.getFlags().isUnknownDestination());
-               flags.set(UNKNOWN_SRC, tlv.getFlags().isUnknownSource());
+               flags.set(REACHABLITY_PROBLEM, tlv.getFlags().isP2mpUnreachable());
                flags.set(NO_GCO_SOLUTION, tlv.getFlags().isNoGcoSolution());
                flags.set(NO_GCO_MIGRATION_PATH, tlv.getFlags().isNoGcoMigration());
-               flags.set(REACHABLITY_PROBLEM, tlv.getFlags().isP2mpUnreachable());
-
+               flags.set(PATH_KEY, tlv.getFlags().isPathKey());
+               flags.set(CHAIN_UNAVAILABLE, tlv.getFlags().isChainUnavailable());
+               flags.set(UNKNOWN_SRC, tlv.getFlags().isUnknownSource());
+               flags.set(UNKNOWN_DEST, tlv.getFlags().isUnknownDestination());
+               flags.set(PCE_UNAVAILABLE, tlv.getFlags().isPceUnavailable());
                return ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH);
        }
 
index 6be36248c74c282610c9911dba599e252e7aae5e..f0cb131590aa2aaee0813f87dbf109014d3dfcc9 100644 (file)
@@ -33,11 +33,12 @@ public class OFListTlvParser implements TlvParser, TlvSerializer {
 
        @Override
        public OfListTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               if (valueBytes == null || valueBytes.length == 0)
+               if (valueBytes == null || valueBytes.length == 0) {
                        throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
-               if (valueBytes.length % OF_CODE_ELEMENT_LENGTH != 0)
+               }
+               if (valueBytes.length % OF_CODE_ELEMENT_LENGTH != 0) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + ".");
-
+               }
                final List<OfId> ofCodes = Lists.newArrayList();
                for (int i = 0; i < valueBytes.length; i += OF_CODE_ELEMENT_LENGTH) {
                        try {
@@ -51,8 +52,9 @@ public class OFListTlvParser implements TlvParser, TlvSerializer {
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("OFListTlv is mandatory.");
+               }
                final OfListTlv oft = (OfListTlv) tlv;
 
                final List<OfId> ofCodes = oft.getCodes();
index 13b441dce906e4cbf6513447686fa6eb3cee9c10..3eb2cfe9f746fdb543407aa2d6cee3e955a16d62 100644 (file)
@@ -34,19 +34,16 @@ public class OrderTlvParser implements TlvParser, TlvSerializer {
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("OrderTlv is mandatory.");
+               }
                final OrderTlv otlv = (OrderTlv) tlv;
-
-               // final byte[] bytes = new byte[];
-               // FIXME: finish
-
-               final byte[] delete = ByteArray.subByte(ByteArray.longToBytes(otlv.getDelete()), 4, ORDR_DEL_LENGTH);
-               // buffer.writeBytes(delete);
-               final byte[] setup = ByteArray.subByte(ByteArray.longToBytes(otlv.getSetup()), 4, ORDR_SETUP_LENGTH);
-               // buffer.writeBytes(setup);
-
-               return new byte[5];
+               final byte[] bytes = new byte[ORDR_DEL_LENGTH + ORDR_SETUP_LENGTH];
+               int offset = 0;
+               ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(otlv.getDelete()), 4, ORDR_DEL_LENGTH), bytes, offset);
+               offset += ORDR_DEL_LENGTH;
+               ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(otlv.getSetup()), 4, ORDR_SETUP_LENGTH), bytes, offset);
+               return bytes;
        }
 
        @Override
index b75a748dd8e8b971c0d418333ccef54d4af29634..b1879299895cb72bc87b0ab9e01c6ea11261f7c9 100644 (file)
@@ -1,5 +1,9 @@
-/**
- * 
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.protocol.pcep.impl.tlv;
 
@@ -28,10 +32,11 @@ public class OverloadedDurationTlvParser implements TlvParser, TlvSerializer {
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("OverloadedTlv is mandatory.");
+               }
                final OverloadDurationTlv odt = (OverloadDurationTlv) tlv;
-               return ByteArray.subByte(ByteArray.longToBytes(odt.getDuration()), 4, OVERLOADED_DURATION_LENGTH);
+               return ByteArray.subByte(ByteArray.longToBytes(odt.getDuration()), OVERLOADED_DURATION_LENGTH, OVERLOADED_DURATION_LENGTH);
        }
 
        @Override
index a20a9b1cb87263ce4e948b2045ac85d63a456e6b..aa8f7978a351e90132f41c9f5da1d6952d08f4ea 100644 (file)
@@ -24,25 +24,22 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 public final class PCEStatefulCapabilityTlvParser implements TlvParser, TlvSerializer {
 
        public static final int TYPE = 16;
-       /*
-        * Flags field length in Bytes
-        */
-       public static final int FLAGS_F_LENGTH = 4;
 
-       /*
-        * Offsets inside flags field in bits;
-        */
-       public static final int I_FLAG_OFFSET = 29;
-       public static final int S_FLAG_OFFSET = 30;
-       public static final int U_FLAG_OFFSET = 31;
+       private static final int FLAGS_F_LENGTH = 4;
+
+       private static final int I_FLAG_OFFSET = 29;
+       private static final int S_FLAG_OFFSET = 30;
+       private static final int U_FLAG_OFFSET = 31;
 
        @Override
        public StatefulCapabilityTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
-               if (buffer.length < FLAGS_F_LENGTH)
+               }
+               if (buffer.length < FLAGS_F_LENGTH) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >= "
                                        + FLAGS_F_LENGTH + ".");
+               }
 
                final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(buffer, 0, FLAGS_F_LENGTH));
                return new StatefulBuilder().setFlags(new Flags(flags.get(S_FLAG_OFFSET), flags.get(I_FLAG_OFFSET), flags.get(U_FLAG_OFFSET))).build();
@@ -50,8 +47,9 @@ public final class PCEStatefulCapabilityTlvParser implements TlvParser, TlvSeria
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("StatefulCapabilityTlv is mandatory.");
+               }
                final StatefulCapabilityTlv sct = (StatefulCapabilityTlv) tlv;
 
                final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
index c7513a232f82864131e13f65a469866f3e66221d..2fcdadbb39d1b56da811a95fc084724104cbf62b 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
 import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RsvpErrorSpecTlv;
@@ -23,9 +24,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.ErrorType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.Rsvp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.RsvpBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.User;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.UserBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.rsvp.RsvpError;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.rsvp.RsvpErrorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.user.UserError;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.user.UserErrorBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ErrorSpec.Flags;
 
@@ -34,7 +37,9 @@ import com.google.common.primitives.UnsignedBytes;
 /**
  * Parser for {@link RsvpErrorSpecTlv}
  */
-public class RSVPErrorSpecTlvParser implements TlvParser, TlvSerializer {
+public final class RSVPErrorSpecTlvParser implements TlvParser, TlvSerializer {
+
+       public static final int TYPE = 21;
 
        private static final int IP4_F_LENGTH = 4;
        private static final int IP6_F_LENGTH = 16;
@@ -54,88 +59,139 @@ public class RSVPErrorSpecTlvParser implements TlvParser, TlvSerializer {
        private static final int USER_ERROR_CLASS_NUM = 194;
        private static final int USER_ERROR_CLASS_TYPE = 1;
 
-       public static final int TYPE = 21;
-
-       /*
-        * flags offsets inside flags field in bits
-        */
        private static final int IN_PLACE_FLAG_OFFSET = 7;
        private static final int NOT_GUILTY_FLAGS_OFFSET = 6;
 
+       private static final int V4_RSVP_LENGTH = 10;
+       private static final int V6_RSVP_LENGTH = 22;
+
        @Override
        public RsvpErrorSpecTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               if (valueBytes == null || valueBytes.length == 0)
+               if (valueBytes == null || valueBytes.length == 0) {
                        throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
+               }
 
-               final int classNum = ByteArray.bytesToInt(ByteArray.subByte(valueBytes, 2, 1));
-               final int classType = ByteArray.bytesToInt(ByteArray.subByte(valueBytes, 3, 1));
+               final int classNum = ByteArray.bytesToInt(ByteArray.subByte(valueBytes, 0, 1));
+               final int classType = ByteArray.bytesToInt(ByteArray.subByte(valueBytes, 1, 1));
 
                ErrorType errorType = null;
-               int byteOffset = 0;
+               final int byteOffset = 2;
 
                if (classNum == RSVP_ERROR_CLASS_NUM) {
-                       final RsvpErrorBuilder builder = new RsvpErrorBuilder();
-                       if (classType == RSVP_IPV4_ERROR_CLASS_TYPE) {
-                               builder.setNode(new IpAddress(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, byteOffset, IP4_F_LENGTH))));
-                               byteOffset += IP4_F_LENGTH;
-                       } else if (classType == RSVP_IPV6_ERROR_CLASS_TYPE) {
-                               builder.setNode(new IpAddress(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, byteOffset, IP6_F_LENGTH))));
-                               byteOffset += IP6_F_LENGTH;
-                       }
-                       final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(valueBytes, byteOffset, FLAGS_F_LENGTH));
-                       byteOffset += FLAGS_F_LENGTH;
-
-                       final short errorCode = (short) (valueBytes[byteOffset] & 0xFF);
-                       byteOffset += ERROR_CODE_F_LENGTH;
-                       final int errorValue = (ByteArray.bytesToShort(ByteArray.subByte(valueBytes, byteOffset, ERROR_VALUE_F_LENGTH)) & 0xFFFF);
-
-                       errorType = new RsvpBuilder().setRsvpError(
-                                       builder.setFlags(new Flags(flags.get(IN_PLACE_FLAG_OFFSET), flags.get(NOT_GUILTY_FLAGS_OFFSET))).setCode(errorCode).setValue(
-                                                       errorValue).build()).build();
+                       errorType = parseRsvp(classType, ByteArray.cutBytes(valueBytes, byteOffset));
                } else if (classNum == USER_ERROR_CLASS_NUM && classType == USER_ERROR_CLASS_TYPE) {
-                       final UserErrorBuilder error = new UserErrorBuilder();
-                       error.setEnterprise(new EnterpriseNumber(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, byteOffset, ENTERPRISE_F_LENGTH))));
-                       byteOffset += ENTERPRISE_F_LENGTH;
-                       error.setSubOrg(ByteArray.bytesToShort(ByteArray.subByte(valueBytes, byteOffset, SUB_ORG_F_LENGTH)));
-                       byteOffset += SUB_ORG_F_LENGTH;
-                       final int errDescrLength = UnsignedBytes.toInt(valueBytes[byteOffset]);
-                       byteOffset += ERR_DESCR_LENGTH_F_LENGTH;
-                       error.setValue(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, byteOffset, USER_VALUE_F_LENGTH)));
-                       byteOffset += USER_VALUE_F_LENGTH;
-                       error.setDescription(ByteArray.bytesToHRString(ByteArray.subByte(valueBytes, byteOffset, errDescrLength)));
-                       byteOffset += errDescrLength;
-                       if (byteOffset < valueBytes.length) {
-                               // TODO: if we have any subobjects
-                               // error.setSubobjects(new SubobjectsBuilder().build());
-                       }
-                       errorType = new UserBuilder().setUserError(error.build()).build();
+                       errorType = parseUserError(ByteArray.cutBytes(valueBytes, byteOffset));
                }
-
                return new RsvpErrorSpecBuilder().setErrorType(errorType).build();
        }
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("RSVPErrorSpecTlv is mandatory.");
+               }
                final RsvpErrorSpecTlv rsvp = (RsvpErrorSpecTlv) tlv;
 
-               if (rsvp.getErrorType().getClass().equals(Rsvp.class)) {
+               if (rsvp.getErrorType().getImplementedInterface().equals(Rsvp.class)) {
                        final Rsvp r = (Rsvp) rsvp.getErrorType();
-                       final RsvpError e = r.getRsvpError();
-                       final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
-                       flags.set(IN_PLACE_FLAG_OFFSET, e.getFlags().isInPlace());
-                       flags.set(NOT_GUILTY_FLAGS_OFFSET, e.getFlags().isNotGuilty());
-                       final IpAddress node = e.getNode();
-                       if (node.getIpv4Address() != null) {
+                       return serializeRsvp(r.getRsvpError());
+               } else {
+                       final User u = (User) rsvp.getErrorType();
+                       return serializerUserError(u.getUserError());
+               }
+       }
 
-                       }
+       private User parseUserError(final byte[] valueBytes) {
+               final UserErrorBuilder error = new UserErrorBuilder();
+               int byteOffset = 0;
+               error.setEnterprise(new EnterpriseNumber(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, byteOffset, ENTERPRISE_F_LENGTH))));
+               byteOffset += ENTERPRISE_F_LENGTH;
+               error.setSubOrg((short) UnsignedBytes.toInt(valueBytes[byteOffset]));
+               byteOffset += SUB_ORG_F_LENGTH;
+               final int errDescrLength = UnsignedBytes.toInt(valueBytes[byteOffset]);
+               byteOffset += ERR_DESCR_LENGTH_F_LENGTH;
+               error.setValue(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, byteOffset, USER_VALUE_F_LENGTH)));
+               byteOffset += USER_VALUE_F_LENGTH;
+               error.setDescription(ByteArray.bytesToHRString(ByteArray.subByte(valueBytes, byteOffset, errDescrLength)));
+               byteOffset += errDescrLength;
+               // TODO: if we have any subobjects
+               return new UserBuilder().setUserError(error.build()).build();
+       }
 
-               } else {
+       private byte[] serializerUserError(final UserError ue) {
+               final byte[] enterprise = ByteArray.subByte(ByteArray.longToBytes(ue.getEnterprise().getValue()), 4, ENTERPRISE_F_LENGTH);
+               final byte suborg = UnsignedBytes.checkedCast(ue.getSubOrg());
+               final byte[] value = ByteArray.subByte(ByteArray.intToBytes(ue.getValue()), 2, USER_VALUE_F_LENGTH);
+               final byte[] desc = (ue.getDescription() == null) ? new byte[0] : ue.getDescription().getBytes();
+               final byte descLen = UnsignedBytes.checkedCast(desc.length);
+               // TODO: if we have any subobjects
+               final byte[] bytes = new byte[2 + ENTERPRISE_F_LENGTH + SUB_ORG_F_LENGTH + USER_VALUE_F_LENGTH + ERR_DESCR_LENGTH_F_LENGTH
+                               + desc.length];
+               bytes[0] = UnsignedBytes.checkedCast(USER_ERROR_CLASS_NUM);
+               bytes[1] = UnsignedBytes.checkedCast(USER_ERROR_CLASS_TYPE);
+               int offset = 2;
+               ByteArray.copyWhole(enterprise, bytes, offset);
+               offset += ENTERPRISE_F_LENGTH;
+               bytes[offset] = suborg;
+               offset += SUB_ORG_F_LENGTH;
+               bytes[offset] = descLen;
+               offset += ERR_DESCR_LENGTH_F_LENGTH;
+               ByteArray.copyWhole(value, bytes, offset);
+               offset += USER_VALUE_F_LENGTH;
+               ByteArray.copyWhole(desc, bytes, offset);
+               return bytes;
+       }
 
+       private Rsvp parseRsvp(final int classType, final byte[] valueBytes) {
+               int byteOffset = 0;
+               final RsvpErrorBuilder builder = new RsvpErrorBuilder();
+               if (classType == RSVP_IPV4_ERROR_CLASS_TYPE) {
+                       builder.setNode(new IpAddress(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, byteOffset, IP4_F_LENGTH))));
+                       byteOffset += IP4_F_LENGTH;
+               } else if (classType == RSVP_IPV6_ERROR_CLASS_TYPE) {
+                       builder.setNode(new IpAddress(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, byteOffset, IP6_F_LENGTH))));
+                       byteOffset += IP6_F_LENGTH;
+               }
+               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(valueBytes, byteOffset, FLAGS_F_LENGTH));
+               byteOffset += FLAGS_F_LENGTH;
+               builder.setFlags(new Flags(flags.get(IN_PLACE_FLAG_OFFSET), flags.get(NOT_GUILTY_FLAGS_OFFSET)));
+               final short errorCode = (short) (valueBytes[byteOffset] & Util.BYTE_MAX_VALUE_BYTES);
+               byteOffset += ERROR_CODE_F_LENGTH;
+               builder.setCode(errorCode);
+               final int errorValue = (ByteArray.bytesToShort(ByteArray.subByte(valueBytes, byteOffset, ERROR_VALUE_F_LENGTH)) & 0xFFFF);
+               builder.setValue(errorValue);
+               return new RsvpBuilder().setRsvpError(builder.build()).build();
+       }
+
+       private byte[] serializeRsvp(final RsvpError rsvp) {
+               final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
+               flags.set(IN_PLACE_FLAG_OFFSET, rsvp.getFlags().isInPlace());
+               flags.set(NOT_GUILTY_FLAGS_OFFSET, rsvp.getFlags().isNotGuilty());
+               int offset = 0;
+               final IpAddress node = rsvp.getNode();
+               byte[] bytes;
+               if (node.getIpv4Address() != null) {
+                       bytes = new byte[V4_RSVP_LENGTH];
+                       bytes[0] = RSVP_ERROR_CLASS_NUM;
+                       bytes[1] = RSVP_IPV4_ERROR_CLASS_TYPE;
+                       offset += 2;
+                       ByteArray.copyWhole(Ipv4Util.bytesForAddress(node.getIpv4Address()), bytes, offset);
+                       offset += IP4_F_LENGTH;
+               } else {
+                       bytes = new byte[V6_RSVP_LENGTH];
+                       bytes[0] = RSVP_ERROR_CLASS_NUM;
+                       bytes[1] = RSVP_IPV6_ERROR_CLASS_TYPE;
+                       offset += 2;
+                       ByteArray.copyWhole(Ipv6Util.bytesForAddress(node.getIpv6Address()), bytes, offset);
+                       offset += IP6_F_LENGTH;
                }
-               // TODO: finish
-               return null;
+               bytes[offset] = ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH)[0];
+               offset += FLAGS_F_LENGTH;
+               bytes[offset] = UnsignedBytes.checkedCast(rsvp.getCode());
+               offset += ERROR_CODE_F_LENGTH;
+               final byte[] value = ByteArray.subByte(ByteArray.intToBytes(rsvp.getValue().intValue()), 2, ERROR_VALUE_F_LENGTH);
+               ByteArray.copyWhole(value, bytes, offset);
+               return bytes;
        }
 
        @Override
index ee967b435288ed9fb14e68409c175d638adec246..9ef75ce1f639f763afafbc34e5dbfa948eb99da9 100644 (file)
@@ -21,10 +21,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
  */
 public class ReqMissingTlvParser implements TlvParser, TlvSerializer {
 
-       private static final int REQ_ID_LENGTH = 4;
-
        public static final int TYPE = 3;
 
+       private static final int REQ_ID_LENGTH = 4;
+
        @Override
        public ReqMissingTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException {
                return new ReqMissingBuilder().setRequestId(new RequestId(ByteArray.bytesToLong(ByteArray.subByte(buffer, 0, REQ_ID_LENGTH)))).build();
@@ -32,10 +32,11 @@ public class ReqMissingTlvParser implements TlvParser, TlvSerializer {
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("ReqMissingTlv is mandatory.");
+               }
                final ReqMissingTlv req = (ReqMissingTlv) tlv;
-               return ByteArray.subByte(ByteArray.longToBytes(req.getRequestId().getValue()), 4, REQ_ID_LENGTH);
+               return ByteArray.subByte(ByteArray.longToBytes(req.getRequestId().getValue()), REQ_ID_LENGTH, REQ_ID_LENGTH);
        }
 
        @Override
diff --git a/pcep/impl/src/main/resources/META-INF/services/org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator b/pcep/impl/src/main/resources/META-INF/services/org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator
new file mode 100644 (file)
index 0000000..ca22928
--- /dev/null
@@ -0,0 +1 @@
+org.opendaylight.protocol.pcep.impl.Activator
diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/LabelSubobjectParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/LabelSubobjectParserTest.java
new file mode 100644 (file)
index 0000000..4a9b7a2
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.impl;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.impl.subobject.GeneralizedLabelParser;
+import org.opendaylight.protocol.pcep.impl.subobject.Type1LabelParser;
+import org.opendaylight.protocol.pcep.impl.subobject.WavebandSwitchingLabelParser;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.Type1LabelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.WavebandSwitchingLabelBuilder;
+
+public class LabelSubobjectParserTest {
+
+       private static final byte[] generalizedLabelBytes = { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF };
+
+       private static final byte[] wavebandLabelBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x12, (byte) 0x34, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x99, (byte) 0x99, (byte) 0x00, (byte) 0x00, (byte) 0x11, (byte) 0x11 };
+
+       @Test
+       public void testGeneralizedLabel() throws PCEPDeserializerException {
+               final GeneralizedLabelParser parser = new GeneralizedLabelParser();
+               final GeneralizedLabelBuilder builder = new GeneralizedLabelBuilder();
+               builder.setGeneralizedLabel(generalizedLabelBytes);
+               assertEquals(builder.build(), parser.parseLabel(generalizedLabelBytes));
+               assertArrayEquals(generalizedLabelBytes, parser.serializeLabel(builder.build()));
+       }
+
+       @Test
+       public void testWavebandLabel() throws PCEPDeserializerException {
+               final WavebandSwitchingLabelParser parser = new WavebandSwitchingLabelParser();
+               final WavebandSwitchingLabelBuilder builder = new WavebandSwitchingLabelBuilder();
+               builder.setWavebandId(0x1234L);
+               builder.setStartLabel(0x9999L);
+               builder.setEndLabel(0x1111L);
+               assertEquals(builder.build(), parser.parseLabel(wavebandLabelBytes));
+               assertArrayEquals(wavebandLabelBytes, parser.serializeLabel(builder.build()));
+       }
+
+       @Test
+       public void testTypeOneLabel() throws PCEPDeserializerException {
+               final Type1LabelParser parser = new Type1LabelParser();
+               final Type1LabelBuilder builder = new Type1LabelBuilder();
+               builder.setType1Label(0x120025ffL);
+               assertEquals(builder.build(), parser.parseLabel(generalizedLabelBytes));
+               assertArrayEquals(generalizedLabelBytes, parser.serializeLabel(builder.build()));
+       }
+}
diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java
new file mode 100644 (file)
index 0000000..66f4a35
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.impl;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.impl.subobject.EROAsNumberSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROExplicitExclusionRouteSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROIpPrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROLabelSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROPathKeySubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROUnnumberedInterfaceSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKeyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.LabelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.UnnumberedBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.ExrsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelBuilder;
+
+import com.google.common.collect.Lists;
+
+public class PCEPEROSubobjectParserTest {
+       private static final byte[] ip4PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x00 };
+       private static final byte[] ip6PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                       (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                       (byte) 0xFF, (byte) 0x16, (byte) 0x00 };
+       private static final byte[] asNumberBytes = { (byte) 0x00, (byte) 0x64 };
+       private static final byte[] unnumberedBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00,
+                       (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+       private static final byte[] pathKey32Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 };
+       private static final byte[] pathKey128Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+                       (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x00 };
+       private static final byte[] labelBytes = { (byte) 0x80, (byte) 0x02, (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF };
+       private static final byte[] exrsBytes = { (byte) 0xa0, (byte) 0x04, (byte) 0x00, (byte) 0x64 };
+
+       @Test
+       public void testEROIp4PrefixSubobject() throws PCEPDeserializerException {
+               final EROIpPrefixSubobjectParser parser = new EROIpPrefixSubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setLoose(true);
+               subs.setSubobjectType(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build());
+               assertEquals(subs.build(), parser.parseSubobject(ip4PrefixBytes, true));
+               assertArrayEquals(ip4PrefixBytes, parser.serializeSubobject(subs.build()));
+       }
+
+       @Test
+       public void testEROIp6PrefixSubobject() throws PCEPDeserializerException {
+               final EROIpPrefixSubobjectParser parser = new EROIpPrefixSubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+                               new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                                               (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                                               (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22))).build());
+               subs.setLoose(false);
+               assertEquals(subs.build(), parser.parseSubobject(ip6PrefixBytes, false));
+               assertArrayEquals(ip6PrefixBytes, parser.serializeSubobject(subs.build()));
+       }
+
+       @Test
+       public void testEROAsNumberSubobject() throws PCEPDeserializerException {
+               final EROAsNumberSubobjectParser parser = new EROAsNumberSubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setLoose(true);
+               subs.setSubobjectType(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build());
+               assertEquals(subs.build(), parser.parseSubobject(asNumberBytes, true));
+               assertArrayEquals(asNumberBytes, parser.serializeSubobject(subs.build()));
+       }
+
+       @Test
+       public void testEROUnnumberedSubobject() throws PCEPDeserializerException {
+               final EROUnnumberedInterfaceSubobjectParser parser = new EROUnnumberedInterfaceSubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setLoose(true);
+               subs.setSubobjectType(new UnnumberedBuilder().setRouterId(0x12345000L).setInterfaceId(0xffffffffL).build());
+               assertEquals(subs.build(), parser.parseSubobject(unnumberedBytes, true));
+               assertArrayEquals(unnumberedBytes, parser.serializeSubobject(subs.build()));
+       }
+
+       @Test
+       public void testEROPathKey32Subobject() throws PCEPDeserializerException {
+               final EROPathKeySubobjectParser parser = new EROPathKeySubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setLoose(true);
+               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+               pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 }));
+               pBuilder.setPathKey(new PathKey(4660));
+               subs.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
+               assertEquals(subs.build(), parser.parseSubobject(pathKey32Bytes, true));
+               assertArrayEquals(pathKey32Bytes, parser.serializeSubobject(subs.build()));
+       }
+
+       @Test
+       public void testEROPathKey128Subobject() throws PCEPDeserializerException {
+               final EROPathKeySubobjectParser parser = new EROPathKeySubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setLoose(true);
+               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+               pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE,
+                               (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
+               pBuilder.setPathKey(new PathKey(4660));
+               subs.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
+               assertEquals(subs.build(), parser.parseSubobject(pathKey128Bytes, true));
+               assertArrayEquals(pathKey128Bytes, parser.serializeSubobject(subs.build()));
+       }
+
+       @Test
+       public void testEROLabelSubobject() throws Exception {
+               final EROLabelSubobjectParser parser = new EROLabelSubobjectParser(PCEPExtensionProviderContextImpl.create().getLabelHandlerRegistry());
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setLoose(true);
+               subs.setSubobjectType(new LabelBuilder().setUniDirectional(true).setLabelType(
+                               new GeneralizedLabelBuilder().setGeneralizedLabel(new byte[] { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF }).build()).build());
+               assertEquals(subs.build(), parser.parseSubobject(labelBytes, true));
+               assertArrayEquals(labelBytes, parser.serializeSubobject(subs.build()));
+       }
+
+       @Test
+       public void testEROEXRSSubobject() throws Exception {
+               final EROExplicitExclusionRouteSubobjectParser parser = new EROExplicitExclusionRouteSubobjectParser(PCEPExtensionProviderContextImpl.create().getXROSubobjectHandlerRegistry());
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setLoose(true);
+               final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.Exrs> list = Lists.newArrayList();
+               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.ExrsBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.ExrsBuilder();
+               builder.setMandatory(true);
+               builder.setSubobjectType(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build());
+               list.add(builder.build());
+               subs.setSubobjectType(new ExrsBuilder().setExrs(list).build());
+               assertEquals(subs.build(), parser.parseSubobject(exrsBytes, true));
+               // assertArrayEquals(exrsBytes, parser.serializeSubobject(subs.build()));
+       }
+}
index d36eb106557b44ebf891a8b23b58c72bc85c5791..1145f1be2380f207d32b945e89485d08ba8077ac 100644 (file)
  */
 package org.opendaylight.protocol.pcep.impl;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.PCEPDocumentedException;
+import org.opendaylight.protocol.pcep.impl.object.PCEPBandwidthObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPClassTypeObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPCloseObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPGlobalConstraintsObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPLspaObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPMetricObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPObjectiveFunctionObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPSrpObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
+import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpIdNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CCloseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.address.family.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.address.family.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.ClassTypeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.LspaBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.OfBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.requests.EndpointsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.requests.SrpBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.SvecBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.LoadBalancingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.reported.route.BandwidthBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.GcBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.MetricBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AttributeFilter;
+
+import com.google.common.collect.Lists;
+import com.google.common.primitives.UnsignedBytes;
 
-/**
- * Used resources<br/>
- * <br/>
- * PCEPOpenObject3.bin<br/>
- * objClass: 1<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * keepAlive: 30<br/>
- * deadTimer: 120<br/>
- * sessionId: 1<br/>
- * tlvs:NO<br/>
- * <br/>
- * PCEPBandwidthObject1LowerBounds.bin<br/>
- * objClass: 5 <br/>
- * objType: 1<br/>
- * objLength: 16<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * Bandwidth: 0<br/>
- * <br/>
- * PCEPBandwidthObject2UpperBounds.bin<br/>
- * objClass: 5 <br/>
- * objType: 1<br/>
- * objLength: 16<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * Bandwidth: 0xFFFFFFFF<br/>
- * <br/>
- * PCEPEndPointsObject1IPv4.bin<br/>
- * objClass: 4 <br/>
- * objType: 1<br/>
- * objLength: 12<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * src IP: 0xA2F5110E <br/>
- * dest IP: 0xFFFFFFFF <br/>
- * <br/>
- * PCEPEndPointsObject2IPv6.bin<br/>
- * objClass: 4 <br/>
- * objType: 2<br/>
- * objLength: 36<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * src IP: 0xFFFFFFFFF FFFFFFFFF FFFFFFFFF FFFFFFFFF<br/>
- * dest IP: 0x00025DD2 FFECA1B6 581E9F50 00000000 <br/>
- * <br/>
- * PCEPErrorObject1.bin<br/>
- * objClass: 13 (RP)<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * Error-type: 1<br/>
- * Error-value: 1<br/>
- * Tlvs: NO<br/>
- * <br/>
- * PCEPErrorObject2Invalid.bin<br/>
- * objClass: 13 (RP)<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * Error-type: 3<br/>
- * Error-value: 0<br/>
- * Tlvs: NO<br/>
- * <br/>
- * PCEPErrorObject3.bin<br/>
- * objClass: 13 (RP)<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * Error-type: 2<br/>
- * Error-value: 0<br/>
- * Tlvs: NO<br/>
- * <br/>
- * PCEPLspaObject1LowerBounds.bin<br/>
- * objClass: 9<br/>
- * objType: 1<br/>
- * objLength: 20<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * Exclude-any: 0x00000000L<br/>
- * Include-any: 0x00000000L<br/>
- * Include-all: 0x00000000L<br/>
- * Setup Prio: 0x00<br/>
- * Holding Prio: 0x00<br/>
- * Flags: - L : false<br/>
- * <br/>
- * PCEPLspaObject2UpperBounds.bin<br/>
- * objClass: 9<br/>
- * objType: 1<br/>
- * objLength: 20<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * Exclude-any: 0xFFFFFFFFL<br/>
- * Include-any: 0xFFFFFFFFL<br/>
- * Include-all: 0xFFFFFFFFL<br/>
- * Setup Prio: 0xFF<br/>
- * Holding Prio: 0xFF<br/>
- * Flags: - L : true<br/>
- * <br/>
- * PCEPLspaObject3RandVals.bin<br/>
- * objClass: 9<br/>
- * objType: 1<br/>
- * objLength: 20<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: true<br/>
- * <br/>
- * Exclude-any: 0x20A1FEE3L<br/>
- * Include-any: 0x1A025CC7L<br/>
- * Include-all: 0x2BB66532L<br/>
- * Setup Prio: 0x03<br/>
- * Holding Prio: 0x02<br/>
- * Flags: - L : true<br/>
- * <br/>
- * NoPathObject1WithTLV.bin<br/>
- * objClass: 3 (RP)<br/>
- * objType: 1<br/>
- * objLength: 16<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * Nature of Issue: 2<br/>
- * No-Path flags:<br/>
- * - C: true<br/>
- * <br/>
- * tlvs:<br/>
- * -- NO-PATH-VECTOR<br/>
- * - flags (0x4000):<br/>
- * - PCE currently unavailable: false<br/>
- * - unknown destination: true<br/>
- * - unknown source: false<br/>
- * 
- * <br/>
- * NoPathObject2WithoutTLV.bin<br/>
- * objClass: 3 (RP)<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: true<br/>
- * <br/>
- * Nature of Issue: 16<br/>
- * No-Path flags:<br/>
- * - C: false<br/>
- * <br/>
- * tlvs:NO<br/>
- * <br/>
- * PCEPNotificationObject1WithTlv.bin <br/>
- * objClass: 12<br/>
- * objType: 1<br/>
- * objLength: 16<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * NT: 1<br/>
- * NV: 1<br/>
- * Tlvs:<br/>
- * - OverloaderDuration(0xFF0000A2L)<br/>
- * <br/>
- * PCEPNotificationObject2WithoutTlv.bin <br/>
- * objClass: 12<br/>
- * objType: 1<br/>
- * objLength: 8<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * NT: 0xFF<br/>
- * NV: 0xFF<br/>
- * Tlvs: NO<br/>
- * <br/>
- * PCEPOpenObject1.bin<br/>
- * objClass: 1<br/>
- * objType: 1<br/>
- * objLength: 28<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * keepAlive: 30<br/>
- * deadTimer: 120<br/>
- * sessionId: 1<br/>
- * tlvs:<br/>
- * - PCEPStatefulCapability<br/>
- * - LSPStateDBVersionTlv<br/>
- * - NodeIdentifierTlv<br/>
- * <br/>
- * PCEPOpenObject2UpperBoundsNoTlv.bin<br/>
- * objClass: 1<br/>
- * objType: 1<br/>
- * objLength: 34<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * keepAlive: 0xFF<br/>
- * deadTimer: 0xFF<br/>
- * sessionId: 0xFF<br/>
- * tlvs: NO<br/>
- * <br/>
- * PCEPRPObject1.bin<br/>
- * objClass: 2 (RP)<br/>
- * objType: 1<br/>
- * objLength: 12<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * RP flags:<br/>
- * - loose/strict: true<br/>
- * - Bi-directional: false<br/>
- * - Reoptimization: false<br/>
- * - Priority: 5<br/>
- * Request ID: 0xDEADBEEF<br/>
- * tlvs: NO<br/>
- * <br/>
- * PCEPSvecObject1_10ReqIDs.bin <br/>
- * objClass: 11<br/>
- * objType: 1<br/>
- * objLength: 48<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: true<br/>
- * - ignored: false<br/>
- * <br/>
- * Flags:<br/>
- * - Link diverse: true<br/>
- * - Node diverse: false<br/>
- * - SRLG diverse: true<br/>
- * Reques-ID-numbers:<br/>
- * #1 - 0xFFFFFFFFL<br/>
- * #2 - 0x00000000L<br/>
- * #3 - 0x01234567L<br/>
- * #4 - 0x89ABCDEFL<br/>
- * #5 - 0xFEDCBA98L<br/>
- * #6 - 0x76543210L<br/>
- * #7 - 0x15825266L<br/>
- * #8 - 0x48120BBEL<br/>
- * #9 - 0x25FB7E52L<br/>
- * #10 - 0xB2F2546BL<br/>
- * <br/>
- * PCEPSvecObject2.bin <br/>
- * objClass: 11<br/>
- * objType: 1<br/>
- * objLength: 08<br/>
- * version: 1<br/>
- * Flags:<br/>
- * - processing: false<br/>
- * - ignored: false<br/>
- * <br/>
- * Flags:<br/>
- * - Link diverse: false<br/>
- * - Node diverse: false<br/>
- * - SRLG diverse: false<br/>
- * Reques-ID-numbers:<br/>
- * #1 - 0x000000FFL<br/>
- * PCEPExcludeRouteObject.1.bin <br/>
- * objClass: 17 <br/>
- * objType: 1 <br/>
- * objLength: 20 <br/>
- * version: 1 <br/>
- * Flags: <br/>
- * - fail: true <br/>
- * Subobjects: <br/>
- * - XROIPv4PreffixSubobject(192.168.0.0/16, exclude, node) <br/>
- * - XROASnumber(0x1234) <br/>
- */
 public class PCEPObjectParserTest {
 
-       // @Mock
-       // private HandlerRegistry registry;
-       //
-       // IPv4Address ipv4addr = new IPv4Address(new byte[] { (byte) 192, (byte) 168, 1, 8 });
-       //
-       // IPv6Address ipv6addr = new IPv6Address(new byte[] { (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1,
-       // (byte) 192, (byte) 168,
-       // 2, 1, (byte) 192, (byte) 168, 2, 1 });
-       //
-       // @SuppressWarnings("unchecked")
-       // private static <T extends PCEPObject> void serDeserTest(final String srcFile, final T specObject) throws
-       // IOException,
-       // PCEPDeserializerException, PCEPDocumentedException {
-       // final byte[] bytesFromFile = ByteArray.fileToBytes(srcFile);
-       // final T deserSpecObj = (T) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
-       // final byte[] serSpecObj = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObject));
-       //
-       // assertEquals(specObject, deserSpecObj);
-       // assertArrayEquals(bytesFromFile, serSpecObj);
-       // }
-       //
-       // /**
-       // * Standard serialization test<br/>
-       // * Used resources:<br/>
-       // * - PCEPOpenObject1.bin<br/>
-       // *
-       // * @throws PCEPDeserializerException
-       // * @throws IOException
-       // * @throws PCEPDocumentedException
-       // */
+       private TlvHandlerRegistry tlvRegistry;
+
+       @Before
+       public void setUp() throws Exception {
+               this.tlvRegistry = PCEPExtensionProviderContextImpl.create().getTlvHandlerRegistry();
+       }
+
        // @Test
        // @Ignore
        // // FIXME: temporary
@@ -379,20 +93,36 @@ public class PCEPObjectParserTest {
        // // assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
        // // }
        // //
-       // // @Test
-       // // public void testCloseObjSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
-       // // serDeserTest("src/test/resources/PCEPCloseObject1.bin", new PCEPCloseObject(Reason.TOO_MANY_UNKNOWN_MSG));
-       // // }
-       //
-       // @Test
-       // @Ignore
-       // // FIXME BUG-89
-       // public void testLoadBalancingObjSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException
-       // {
-       // serDeserTest("src/test/resources/PCEPLoadBalancingObject1.bin", new PCEPLoadBalancingObject(0xF1, new
-       // Bandwidth(new byte[] {
-       // (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }), true));
-       // }
+
+       @Test
+       public void testCloseObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final PCEPCloseObjectParser parser = new PCEPCloseObjectParser(this.tlvRegistry);
+               final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPCloseObject1.bin");
+
+               final CCloseBuilder builder = new CCloseBuilder();
+               builder.setProcessingRule(false);
+               builder.setIgnore(false);
+               builder.setReason((short) 5);
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
+       @Test
+       public void testLoadBalancingObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final PCEPLoadBalancingObjectParser parser = new PCEPLoadBalancingObjectParser(this.tlvRegistry);
+               final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPLoadBalancingObject1.bin");
+
+               final LoadBalancingBuilder builder = new LoadBalancingBuilder();
+               builder.setProcessingRule(true);
+               builder.setIgnore(false);
+               builder.setMaxLsp((short) UnsignedBytes.toInt((byte) 0xf1));
+               builder.setMinBandwidth(new Float32(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
        //
        // @Test
        // public void testLspObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
@@ -467,65 +197,66 @@ public class PCEPObjectParserTest {
        // assertArrayEquals(bytesFromFile, bytesActual);
        // }
        //
-       // /**
-       // * Test for upper/lower bounds (Serialization/Deserialization)<br/>
-       // * Used resources:<br/>
-       // * - PCEPBandwidthObject2UpperBounds.bin<br/>
-       // * - PCEPBandwidthObject1LowerBounds.bin<br/>
-       // *
-       // * @throws IOException
-       // * @throws PCEPDeserializerException
-       // * @throws PCEPDocumentedException
-       // */
-       // @Test
-       // @Ignore
-       // // FIXME BUG-89
-       // public void testBandwidthObjectBounds() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
-       // serDeserTest("src/test/resources/PCEPBandwidthObject1LowerBounds.bin",
-       // new PCEPRequestedPathBandwidthObject(new Bandwidth(new byte[] { 0, 0, 0, 0 }), true, true));
-       // }
-       //
-       // /**
-       // * Test for upper/lower bounds of IPv4 EndPoints (Serialization/Deserialization)<br/>
-       // * Used resources:<br/>
-       // * - PCEPEndPointsObject1IPv4.bin<br/>
-       // *
-       // * @throws IOException
-       // * @throws PCEPDeserializerException
-       // * @throws PCEPDocumentedException
-       // */
-       // @Test
-       // public void testEndPointsObjectSerDeserIPv4() throws IOException, PCEPDeserializerException,
-       // PCEPDocumentedException {
-       // final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
-       // final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
-       // serDeserTest("src/test/resources/PCEPEndPointsObject1IPv4.bin",
-       // new PCEPEndPointsObject<IPv4Address>(new IPv4Address(srcIPBytes), new IPv4Address(destIPBytes)));
-       // }
-       //
-       // /**
-       // * Test for upper/lower bounds of IPv6 EndPoints (Serialization/Deserialization)<br/>
-       // * Used resources:<br/>
-       // * - PCEPEndPointsObject2IPv6.bin<br/>
-       // *
-       // * @throws IOException
-       // * @throws PCEPDeserializerException
-       // * @throws PCEPDocumentedException
-       // */
-       // @Test
-       // public void testEndPointsObjectSerDeserIPv6() throws IOException, PCEPDeserializerException,
-       // PCEPDocumentedException {
-       // final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte)
-       // 0xA1,
-       // (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte)
-       // 0x00, };
-       // final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte)
-       // 0xFF, (byte) 0xFF,
-       // (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
-       //
-       // serDeserTest("src/test/resources/PCEPEndPointsObject2IPv6.bin",
-       // new PCEPEndPointsObject<IPv6Address>(new IPv6Address(srcIPBytes), new IPv6Address(destIPBytes)));
-       // }
+
+       @Test
+       public void testBandwidthObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final PCEPBandwidthObjectParser parser = new PCEPBandwidthObjectParser(this.tlvRegistry);
+               byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject1LowerBounds.bin");
+
+               final BandwidthBuilder builder = new BandwidthBuilder();
+               builder.setProcessingRule(true);
+               builder.setIgnore(true);
+               builder.setBandwidth(new Float32(result));
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+
+               result = ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin");
+
+               builder.setBandwidth(new Float32(result));
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
+       @Test
+       public void testEndPointsObjectIPv4() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
+               final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+
+               final PCEPEndPointsObjectParser parser = new PCEPEndPointsObjectParser(this.tlvRegistry);
+               final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin");
+
+               final EndpointsBuilder builder = new EndpointsBuilder();
+               builder.setProcessingRule(true);
+               builder.setIgnore(false);
+               builder.setAddressFamily(new Ipv4Builder().setSourceIpv4Address(Ipv4Util.addressForBytes(srcIPBytes)).setDestinationIpv4Address(
+                               Ipv4Util.addressForBytes(destIPBytes)).build());
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
+       @Test
+       public void testEndPointsObjectIPv6() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte) 0xA1,
+                               (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, };
+               final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                               (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+
+               final PCEPEndPointsObjectParser parser = new PCEPEndPointsObjectParser(this.tlvRegistry);
+               final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin");
+
+               final EndpointsBuilder builder = new EndpointsBuilder();
+               builder.setProcessingRule(true);
+               builder.setIgnore(false);
+               builder.setAddressFamily(new Ipv6Builder().setSourceIpv6Address(Ipv6Util.addressForBytes(srcIPBytes)).setDestinationIpv6Address(
+                               Ipv6Util.addressForBytes(destIPBytes)).build());
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
        //
        // /**
        // * Test of Serialization/Deserialization of PCEPErrorObjectParser.<br/>
@@ -561,81 +292,84 @@ public class PCEPObjectParserTest {
        // PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject2Invalid.bin")).get(0);
        // }
        //
-       // /**
-       // * Test for upper/lower bounds of PCEPLspaObject (Serialization/Deserialization)<br/>
-       // * Used resources:<br/>
-       // * - PCEPLspaObject1LowerBounds.bin<br/>
-       // * - PCEPLspaObject2UpperBounds.bin<br/>
-       // * - PCEPLspaObject3RandVals.bin<br/>
-       // *
-       // * @throws IOException
-       // * @throws PCEPDeserializerException
-       // * @throws PCEPDocumentedException
-       // */
-       // @Test
-       // public void testLspaObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
-       // serDeserTest("src/test/resources/PCEPLspaObject2UpperBounds.bin",
-       // new PCEPLspaObject(0xFFFFFFFFL, 0xFFFFFFFFL, 0xFFFFFFFFL, (short) 0xFF, (short) 0xFF, false, true, true, true));
-       // serDeserTest("src/test/resources/PCEPLspaObject1LowerBounds.bin",
-       // new PCEPLspaObject(0x00000000L, 0x00000000L, 0x00000000L, (short) 0x00, (short) 0x00, false, false, true, true));
-       // serDeserTest("src/test/resources/PCEPLspaObject3RandVals.bin",
-       // new PCEPLspaObject(0x20A1FEE3L, 0x1A025CC7L, 0x2BB66532L, (short) 0x03, (short) 0x02, false, true, true, true));
-       // }
-       //
-       // @Test
-       // public void testMetricObjectSerDeserBounds() throws IOException, PCEPDeserializerException,
-       // PCEPDocumentedException {
-       // final byte[] bytesFromFileUB = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin");
-       // final byte[] bytesFromFileLB = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin");
-       //
-       // final PCEPMetricObject metricObjectLB = (PCEPMetricObject)
-       // PCEPObjectFactory.parseObjects(bytesFromFileLB).get(0);
-       // final PCEPMetricObject metricObjectUB = (PCEPMetricObject)
-       // PCEPObjectFactory.parseObjects(bytesFromFileUB).get(0);
-       //
-       // assertEquals(new PCEPMetricObject(false, false, new IGPMetric(0), true, true), metricObjectLB);
-       // assertEquals(new PCEPMetricObject(false, true, new TEMetric(4026531840L), true, true), metricObjectUB);
-       //
-       // final byte[] bytesActualLB = PCEPObjectFactory.put(Arrays.asList((PCEPObject) metricObjectLB));
-       // final byte[] bytesActualUB = PCEPObjectFactory.put(Arrays.asList((PCEPObject) metricObjectUB));
-       // assertArrayEquals(bytesFromFileLB, bytesActualLB);
-       // assertArrayEquals(bytesFromFileUB, bytesActualUB);
-       // }
-       //
-       // /**
-       // * Standard deserialization test + specific test without tlv<br/>
-       // * Used resources:<br/>
-       // * - NoPathObject1WithTLV.bin<br/>
-       // * - NoPathObject2WithoutTLV.bin<br/>
-       // *
-       // * @throws PCEPDeserializerException
-       // * @throws IOException
-       // * @throws PCEPDocumentedException
-       // */
+
+       @Test
+       public void testLspaObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final PCEPLspaObjectParser parser = new PCEPLspaObjectParser(this.tlvRegistry);
+               byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPLspaObject1LowerBounds.bin");
+
+               final LspaBuilder builder = new LspaBuilder();
+               builder.setProcessingRule(true);
+               builder.setIgnore(true);
+               builder.setExcludeAny(new AttributeFilter(0L));
+               builder.setIncludeAny(new AttributeFilter(0L));
+               builder.setIncludeAll(new AttributeFilter(0L));
+               builder.setHoldPriority((short) 0);
+               builder.setSetupPriority((short) 0);
+               builder.setLocalProtectionDesired(false);
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+
+               result = ByteArray.fileToBytes("src/test/resources/PCEPLspaObject2UpperBounds.bin");
+
+               builder.setExcludeAny(new AttributeFilter(0xFFFFFFFFL));
+               builder.setIncludeAny(new AttributeFilter(0xFFFFFFFFL));
+               builder.setIncludeAll(new AttributeFilter(0xFFFFFFFFL));
+               builder.setHoldPriority((short) 0xFF);
+               builder.setSetupPriority((short) 0xFF);
+               builder.setLocalProtectionDesired(true);
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+
+               result = ByteArray.fileToBytes("src/test/resources/PCEPLspaObject3RandVals.bin");
+
+               builder.setExcludeAny(new AttributeFilter(0x20A1FEE3L));
+               builder.setIncludeAny(new AttributeFilter(0x1A025CC7L));
+               builder.setIncludeAll(new AttributeFilter(0x2BB66532L));
+               builder.setHoldPriority((short) 0x02);
+               builder.setSetupPriority((short) 0x03);
+               builder.setLocalProtectionDesired(true);
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
+       @Test
+       public void testMetricObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final PCEPMetricObjectParser parser = new PCEPMetricObjectParser(this.tlvRegistry);
+               byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin");
+
+               final MetricBuilder builder = new MetricBuilder();
+               builder.setProcessingRule(true);
+               builder.setIgnore(true);
+               builder.setComputed(false);
+               builder.setBound(false);
+               builder.setMetricType((short) 1);
+               builder.setValue(new Float32(new byte[] { 0, 0, 0, 0 }));
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+
+               result = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin");
+
+               builder.setComputed(true);
+               builder.setBound(false);
+               builder.setMetricType((short) 2);
+               builder.setValue(new Float32(new byte[] { (byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00 }));
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
        // @Test
-       // public void testNoPathObjectDeserialization() throws PCEPDeserializerException, IOException,
-       // PCEPDocumentedException {
-       // // final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>(1);
-       // // tlvs.add(new NoPathVectorTlv(false, false, true, false, false, false));
-       // // serDeserTest("src/test/resources/NoPathObject1WithTLV.bin", new PCEPNoPathObject((short) 2, true, tlvs,
-       // false));
+       // public void testNoPathObject() throws PCEPDeserializerException, IOException, PCEPDocumentedException {
+       // final List<PCEPTlv> tlvs = new ArrayList<PCEPTlv>(1);
+       // tlvs.add(new NoPathVectorTlv(false, false, true, false, false, false));
+       // serDeserTest("src/test/resources/NoPathObject1WithTLV.bin", new PCEPNoPathObject((short) 2, true, tlvs, false));
        // serDeserTest("src/test/resources/NoPathObject2WithoutTLV.bin", new PCEPNoPathObject((short) 0x10, false, true));
        //
-       // }
-       //
-       // /**
-       // * Standard serialization test + without tlv<br/>
-       // * Used resources:<br/>
-       // * - NoPathObject1WithTLV.bin<br/>
-       // * - NoPathObject2WithoutTLV.bin<br/>
-       // *
-       // * @throws PCEPDeserializerException
-       // * @throws IOException
-       // * @throws PCEPDocumentedException
-       // */
-       // @Test
-       // public void testNoPathObjectSerialization() throws IOException, PCEPDeserializerException,
-       // PCEPDocumentedException {
        // byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/NoPathObject2WithoutTLV.bin");
        // PCEPNoPathObject noPathObject = (PCEPNoPathObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
        // byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) noPathObject));
@@ -646,6 +380,7 @@ public class PCEPObjectParserTest {
        // bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) noPathObject));
        // assertArrayEquals(bytesFromFile, bytesActual);
        // }
+
        //
        // /**
        // * Specific test with/without tlvs (Ser/Deser)<br/>
@@ -736,58 +471,61 @@ public class PCEPObjectParserTest {
        // // }, false, false));
        // }
        //
-       // /**
-       // * Test for upper/lower bounds of PCEPSvecObject (Serialization/Deserialization)<br/>
-       // * Used resources:<br/>
-       // * - PCEPSvecObject1_10ReqIDs.bin<br/>
-       // *
-       // * @throws IOException
-       // * @throws PCEPDeserializerException
-       // * @throws PCEPDocumentedException
-       // */
-       // @Test
-       // public void testSvecObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
-       // final List<Long> requestIDs = new ArrayList<Long>(10);
-       // requestIDs.add(0xFFFFFFFFL);
-       // requestIDs.add(0x00000000L);
-       // requestIDs.add(0x01234567L);
-       // requestIDs.add(0x89ABCDEFL);
-       // requestIDs.add(0xFEDCBA98L);
-       // requestIDs.add(0x76543210L);
-       // requestIDs.add(0x15825266L);
-       // requestIDs.add(0x48120BBEL);
-       // requestIDs.add(0x25FB7E52L);
-       // requestIDs.add(0xB2F2546BL);
-       //
-       // serDeserTest("src/test/resources/PCEPSvecObject1_10ReqIDs.bin",
-       // new PCEPSvecObject(true, false, true, false, true, requestIDs, true));
-       // }
-       //
-       // /**
-       // * Test for lowest bounds of PCEPSvecObject (Serialization/Deserialization)<br/>
-       // * Used resources:<br/>
-       // * - PCEPSvecObject2.bin<br/>
-       // *
-       // * @throws IOException
-       // * @throws PCEPDeserializerException
-       // * @throws PCEPDocumentedException
-       // */
-       // @Test
-       // public void testSvecObjectSerDeserNoReqIDs() throws IOException, PCEPDeserializerException,
-       // PCEPDocumentedException {
-       // final List<Long> requestIDs = new ArrayList<Long>();
-       // requestIDs.add(0xFFL);
-       // serDeserTest("src/test/resources/PCEPSvecObject2.bin", new PCEPSvecObject(false, false, false, false, false,
-       // requestIDs, false));
-       // }
-       //
-       // @Test
-       // public void testClassTypeObject() throws PCEPDeserializerException, PCEPDocumentedException {
-       // final PCEPClassTypeObject ct = new PCEPClassTypeObject((short) 4);
-       // // final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
-       // // final byte[] bytes = parser.put(ct);
-       // // assertEquals(ct, parser.parse(bytes, true, false));
-       // }
+
+       @Test
+       public void testSvecObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final PCEPSvecObjectParser parser = new PCEPSvecObjectParser(this.tlvRegistry);
+               byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPSvecObject2.bin");
+
+               final SvecBuilder builder = new SvecBuilder();
+               builder.setProcessingRule(false);
+               builder.setIgnore(false);
+               builder.setLinkDiverse(false);
+               builder.setNodeDiverse(false);
+               builder.setSrlgDiverse(false);
+               builder.setRequestsIds(Lists.newArrayList(new RequestId(0xFFL)));
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+
+               result = ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin");
+
+               builder.setProcessingRule(true);
+               builder.setLinkDiverse(true);
+               builder.setSrlgDiverse(true);
+
+               final List<RequestId> requestIDs = Lists.newArrayList();
+               requestIDs.add(new RequestId(0xFFFFFFFFL));
+               requestIDs.add(new RequestId(0x00000000L));
+               requestIDs.add(new RequestId(0x01234567L));
+               requestIDs.add(new RequestId(0x89ABCDEFL));
+               requestIDs.add(new RequestId(0xFEDCBA98L));
+               requestIDs.add(new RequestId(0x76543210L));
+               requestIDs.add(new RequestId(0x15825266L));
+               requestIDs.add(new RequestId(0x48120BBEL));
+               requestIDs.add(new RequestId(0x25FB7E52L));
+               requestIDs.add(new RequestId(0xB2F2546BL));
+
+               builder.setRequestsIds(requestIDs);
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
+       @Test
+       public void testClassTypeObject() throws PCEPDeserializerException, PCEPDocumentedException {
+               final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser(this.tlvRegistry);
+               final byte[] result = new byte[] { 0, 0, 0, (byte) 0x04 };
+
+               final ClassTypeBuilder builder = new ClassTypeBuilder();
+               builder.setProcessingRule(true);
+               builder.setIgnore(false);
+               builder.setClassType(new ClassType((short) 4));
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
        //
        // /**
        // * Test PCEPExcludeRouteObjectObject (Serialization/Deserialization)<br/>
@@ -808,18 +546,52 @@ public class PCEPObjectParserTest {
        //
        // }
        //
-       // @Test
-       // public void tesObjectiveFunctionObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
-       // serDeserTest("src/test/resources/PCEPObjectiveFunctionObject.1.bin", new
-       // PCEPObjectiveFunctionObject(PCEPOFCodes.MBC, true, false));
-       // }
-       //
-       // @Test
-       // public void tesGlobalConstraintsObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
-       // serDeserTest("src/test/resources/PCEPGlobalConstraintsObject.1.bin",
-       // new PCEPGlobalConstraintsObject((short) 1, (short) 0, (short) 100, (short) 0xFF, true, false));
-       // }
-       //
+
+       @Test
+       public void testSrpObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final PCEPSrpObjectParser parser = new PCEPSrpObjectParser(this.tlvRegistry);
+               final byte[] result = new byte[] { 0, 0, 0, 0, 0, 0, 0, (byte) 0x01 };
+
+               final SrpBuilder builder = new SrpBuilder();
+               builder.setProcessingRule(false);
+               builder.setIgnore(false);
+               builder.setOperationId(new SrpIdNumber(1L));
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
+       @Test
+       public void testObjectiveFunctionObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final PCEPObjectiveFunctionObjectParser parser = new PCEPObjectiveFunctionObjectParser(this.tlvRegistry);
+               final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPObjectiveFunctionObject.1.bin");
+
+               final OfBuilder builder = new OfBuilder();
+               builder.setProcessingRule(true);
+               builder.setIgnore(false);
+               builder.setCode(new OfId(4));
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
+       @Test
+       public void testGlobalConstraintsObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final PCEPGlobalConstraintsObjectParser parser = new PCEPGlobalConstraintsObjectParser(this.tlvRegistry);
+               final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPGlobalConstraintsObject.1.bin");
+
+               final GcBuilder builder = new GcBuilder();
+               builder.setProcessingRule(true);
+               builder.setIgnore(false);
+               builder.setMaxHop((short) 1);
+               builder.setMaxUtilization((short) 0);
+               builder.setMinUtilization((short) 100);
+               builder.setOverBookingFactor((short) 0xFF);
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
        // // FIXME: add at least one test with true value
        // @Test
        // public void openObjectWithTlv() throws PCEPDeserializerException, PCEPDocumentedException {
diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPRROSubobjectParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPRROSubobjectParserTest.java
new file mode 100644 (file)
index 0000000..ddb5656
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.impl;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.impl.subobject.RROIpPrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.RROLabelSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.RROPathKeySubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.RROUnnumberedInterfaceSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.PathKeyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.LabelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.UnnumberedBuilder;
+
+public class PCEPRROSubobjectParserTest {
+
+       private static final byte[] ip4PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x01 };
+       private static final byte[] ip6PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                       (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                       (byte) 0xFF, (byte) 0x16, (byte) 0x02 };
+       private static final byte[] unnumberedBytes = { (byte) 0x02, (byte) 0x00, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00,
+                       (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+       private static final byte[] pathKey32Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 };
+       private static final byte[] pathKey128Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+                       (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x00 };
+       private static final byte[] labelBytes = { (byte) 0x81, (byte) 0x02, (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF };
+
+       @Test
+       public void testRROIp4PrefixSubobject() throws PCEPDeserializerException {
+               final RROIpPrefixSubobjectParser parser = new RROIpPrefixSubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setProtectionAvailable(true);
+               subs.setProtectionInUse(false);
+               subs.setSubobjectType(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build());
+               assertEquals(subs.build(), parser.parseSubobject(ip4PrefixBytes));
+               assertArrayEquals(ip4PrefixBytes, parser.serializeSubobject(subs.build()));
+       }
+
+       @Test
+       public void testRROIp6PrefixSubobject() throws PCEPDeserializerException {
+               final RROIpPrefixSubobjectParser parser = new RROIpPrefixSubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setProtectionAvailable(false);
+               subs.setProtectionInUse(true);
+               subs.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+                               new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                                               (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                                               (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22))).build());
+               assertEquals(subs.build(), parser.parseSubobject(ip6PrefixBytes));
+               assertArrayEquals(ip6PrefixBytes, parser.serializeSubobject(subs.build()));
+       }
+
+       @Test
+       public void testRROUnnumberedSubobject() throws PCEPDeserializerException {
+               final RROUnnumberedInterfaceSubobjectParser parser = new RROUnnumberedInterfaceSubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setProtectionAvailable(false);
+               subs.setProtectionInUse(true);
+               subs.setSubobjectType(new UnnumberedBuilder().setRouterId(0x12345000L).setInterfaceId(0xffffffffL).build());
+               assertEquals(subs.build(), parser.parseSubobject(unnumberedBytes));
+               assertArrayEquals(unnumberedBytes, parser.serializeSubobject(subs.build()));
+       }
+
+       @Test
+       public void testRROPathKey32Subobject() throws PCEPDeserializerException {
+               final RROPathKeySubobjectParser parser = new RROPathKeySubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+               pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 }));
+               pBuilder.setPathKey(new PathKey(4660));
+               subs.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
+               assertEquals(subs.build(), parser.parseSubobject(pathKey32Bytes));
+               assertArrayEquals(pathKey32Bytes, parser.serializeSubobject(subs.build()));
+       }
+
+       @Test
+       public void testRROPathKey128Subobject() throws PCEPDeserializerException {
+               final RROPathKeySubobjectParser parser = new RROPathKeySubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+               pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE,
+                               (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
+               pBuilder.setPathKey(new PathKey(4660));
+               subs.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
+               assertEquals(subs.build(), parser.parseSubobject(pathKey128Bytes));
+               assertArrayEquals(pathKey128Bytes, parser.serializeSubobject(subs.build()));
+       }
+
+       @Test
+       public void testRROLabelSubobject() throws Exception {
+               final RROLabelSubobjectParser parser = new RROLabelSubobjectParser(PCEPExtensionProviderContextImpl.create().getLabelHandlerRegistry());
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setSubobjectType(new LabelBuilder().setUniDirectional(true).setGlobal(true).setLabelType(
+                               new GeneralizedLabelBuilder().setGeneralizedLabel(new byte[] { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF }).build()).build());
+               assertEquals(subs.build(), parser.parseSubobject(labelBytes));
+               assertArrayEquals(labelBytes, parser.serializeSubobject(subs.build()));
+       }
+}
diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPSubobjectParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPSubobjectParserTest.java
deleted file mode 100644 (file)
index d4fc894..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.pcep.impl;
-
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-
-import org.junit.Ignore;
-import org.junit.Test;
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.impl.subobject.EROAsNumberSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.EROIpPrefixSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.EROUnnumberedInterfaceSubobjectParser;
-
-/**
- * Tests for subobjects
- */
-public class PCEPSubobjectParserTest {
-       final byte[] ipv6bytes1 = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
-                       (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
-       final byte[] ipv6bytes2 = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12,
-                       (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
-
-       final byte[] ipv4bytes1 = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
-       final byte[] ipv4bytes2 = { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 };
-
-       final byte[] asnumber = { (byte) 0xA0, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64 };
-
-       @Test
-       public void testSerDeser() throws PCEPDeserializerException, IOException {
-               // final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PackOfSubobjects.bin");
-               // final List<ExplicitRouteSubobject> objsToTest = PCEPEROSubobjectParser.parse(bytesFromFile);
-               //
-               // assertEquals(8, objsToTest.size());
-
-               // final EROAsNumberSubobjectParser parser = new EROAsNumberSubobjectParser();
-               // final CSubobject s = parser.parseSubobject(ByteArray.cutBytes(this.asnumber, 2));
-               //
-               // assertEquals(s, new AsNumberBuilder().setAsNumber(new AsNumber((long) 0x64)).build());
-               // assertEquals(objsToTest.get(1), new AsNumberBuilder().setAsNumber(new AsNumber(0x0010L)).build());
-
-               // assertEquals(objsToTest.get(2), new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new
-               // IPv4Address(this.ipv4bytes1), 0x20), true));
-               //
-               // assertEquals(objsToTest.get(3), new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new
-               // IPv4Address(this.ipv4bytes2), 0x15), false));
-               // assertEquals(objsToTest.get(4), new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new
-               // IPv6Address(this.ipv6bytes1), 0x80), true));
-               //
-               // assertEquals(objsToTest.get(5), new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new
-               // IPv6Address(this.ipv6bytes2), 0x16), false));
-               // final byte[] addr1 = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
-               // assertEquals(objsToTest.get(6),
-               // new EROUnnumberedInterfaceSubobject(new IPv4Address(addr1), new UnnumberedInterfaceIdentifier(0xFFFFFFFFL),
-               // true));
-               //
-               // final byte[] addr2 = { (byte) 0x01, (byte) 0x24, (byte) 0x56, (byte) 0x78 };
-               // assertEquals(objsToTest.get(7),
-               // new EROUnnumberedInterfaceSubobject(new IPv4Address(addr2), new UnnumberedInterfaceIdentifier(0x9ABCDEF0L),
-               // false));
-               //
-               // assertArrayEquals(bytesFromFile, PCEPEROSubobjectParser.put(objsToTest));
-
-       }
-
-       @Test
-       @Ignore
-       public void testEROSubojectsSerDeserWithoutBin() throws PCEPDeserializerException {
-               // final List<ExplicitRouteSubobject> objsToTest = new ArrayList<ExplicitRouteSubobject>();
-               // objsToTest.add(new EROType1LabelSubobject(0xFFFF51F2L, true, false));
-               // objsToTest.add(new EROType1LabelSubobject(0x12345648L, false, true));
-               // objsToTest.add(new EROGeneralizedLabelSubobject(new byte[] { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte)
-               // 0xFF }, true, true));
-               // objsToTest.add(new EROWavebandSwitchingLabelSubobject(0x12345678L, 0x87654321L, 0xFFFFFFFFL, false, false));
-               // objsToTest.add(new EROPathKeyWith32PCEIDSubobject(0x1235, new byte[] { (byte) 0x00, (byte) 0x55, (byte) 0xFF,
-               // (byte) 0xF1 }, true));
-               // objsToTest.add(new EROPathKeyWith128PCEIDSubobject(0x5432, new byte[] { (byte) 0x00, (byte) 0x55, (byte)
-               // 0xFF, (byte) 0xF1,
-               // (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1, (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1,
-               // (byte) 0x00,
-               // (byte) 0x55, (byte) 0xFF, (byte) 0xF1 }, true));
-               // objsToTest.add(new EROExplicitExclusionRouteSubobject(Arrays.asList((ExcludeRouteSubobject) new
-               // XROAsNumberSubobject(new AsNumber((long) 2588), true))));
-
-               // assertEquals(objsToTest, PCEPEROSubobjectParser.parse(PCEPEROSubobjectParser.put(objsToTest)));
-       }
-
-       @Test
-       public void testRROSubojectsSerDeserWithoutBin() throws PCEPDeserializerException {
-               // final List<ReportedRouteSubobject> objsToTest = new ArrayList<ReportedRouteSubobject>();
-               // objsToTest.add(new RROIPAddressSubobject(new IpPrefix(Ipv6Util.prefixForBytes(this.ipv6bytes2, 0x16)), true,
-               // false));
-               // objsToTest.add(new RROIPAddressSubobject(new IpPrefix(Ipv4Util.prefixForBytes(this.ipv4bytes1, 0x16)), true,
-               // false));
-               // objsToTest.add(new RROType1LabelSubobject(0xFFFF51F2L, true));
-               // objsToTest.add(new RROType1LabelSubobject(0x12345648L, false));
-               // objsToTest.add(new RROGeneralizedLabelSubobject(new byte[] { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte)
-               // 0xFF }, true));
-               // objsToTest.add(new RROWavebandSwitchingLabelSubobject(0x12345678L, 0x87654321L, 0xFFFFFFFFL, false));
-               // objsToTest.add(new RROPathKeyWith32PCEIDSubobject(0x1235, new byte[] { (byte) 0x00, (byte) 0x55, (byte) 0xFF,
-               // (byte) 0xF1 }));
-               // objsToTest.add(new RROPathKeyWith128PCEIDSubobject(0x5432, new byte[] { (byte) 0x00, (byte) 0x55, (byte)
-               // 0xFF, (byte) 0xF1,
-               // (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1, (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1,
-               // (byte) 0x00,
-               // (byte) 0x55, (byte) 0xFF, (byte) 0xF1 }));
-               // objsToTest.add(new RROAttributesSubobject(new byte[] { (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1,
-               // (byte) 0x00,
-               // (byte) 0x55, (byte) 0xFF, (byte) 0xF1, (byte) 0x00, (byte) 0x55, (byte) 0xFF, (byte) 0xF1, (byte) 0x00,
-               // (byte) 0x55,
-               // (byte) 0xFF, (byte) 0xF1 }));
-
-               // assertEquals(objsToTest, PCEPRROSubobjectParser.parse(PCEPRROSubobjectParser.put(objsToTest)));
-       }
-
-       @Test
-       public void testXROSubojectsSerDeserWithoutBin() throws PCEPDeserializerException {
-               // final List<ExcludeRouteSubobject> objsToTest = new ArrayList<ExcludeRouteSubobject>();
-               // objsToTest.add(new XROIPPrefixSubobject(new IpPrefix(Ipv6Util.prefixForBytes(this.ipv6bytes2, 0x16)), true,
-               // XROSubobjectAttribute.INTERFACE));
-               // objsToTest.add(new XROIPPrefixSubobject(new IpPrefix(Ipv4Util.prefixForBytes(this.ipv4bytes1, 0x16)), false,
-               // XROSubobjectAttribute.INTERFACE));
-               // objsToTest.add(new XROAsNumberSubobject(new AsNumber((long) 0x1234), true));
-               // objsToTest.add(new XROUnnumberedInterfaceSubobject(new IPv4Address(this.ipv4bytes1), new
-               // UnnumberedInterfaceIdentifier(0xFFFFFFFFL), true, XROSubobjectAttribute.SRLG));
-               // objsToTest.add(new XROSRLGSubobject(new SharedRiskLinkGroup(0x12345678L), false));
-
-               // assertEquals(objsToTest, PCEPXROSubobjectParser.parse(PCEPXROSubobjectParser.put(objsToTest)));
-       }
-
-       //
-       // @Test
-       // public void testDifferentLengthExceptions() {
-       // final byte[] bytes = { (byte) 0x00 }; // not empty but not enought data
-       // // for parsing subobjects
-       //
-       // try {
-       // EROAsNumberSubobjectParser.parse(bytes, true);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       //
-       // try {
-       // EROUnnumberedInterfaceSubobjectParser.parse(bytes, true);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       //
-       // try {
-       // EROIpPrefixSubobjectParser.parse(bytes, true);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       // }
-
-       @Test
-       public void testNullExceptions() throws PCEPDeserializerException {
-               final byte[] bytes = null; // not empty but not enought data for parsing
-               // subobjects
-
-               try {
-                       new EROAsNumberSubobjectParser().parseSubobject(bytes, false);
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-
-               try {
-                       new EROUnnumberedInterfaceSubobjectParser().parseSubobject(bytes, false);
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-
-               try {
-                       new EROIpPrefixSubobjectParser().parseSubobject(bytes, false);
-                       fail("");
-               } catch (final IllegalArgumentException e) {
-               }
-       }
-
-       @Test
-       public void testUnknownInstanceExceptions() {
-
-               // final ExplicitRouteSubobject instance = new ExplicitRouteSubobject() {
-               // };
-
-               // try {
-               // new EROAsNumberSubobjectParser().serializeSubobject(instance);
-               // fail("");
-               // } catch (final IllegalArgumentException e) {
-               // }
-               //
-               // try {
-               // EROUnnumberedInterfaceSubobjectParser.put(instance);
-               // fail("");
-               // } catch (final IllegalArgumentException e) {
-               // }
-
-               // try {
-               // EROIpPrefixSubobjectParser.put(instance);
-               // fail("");
-               // } catch (final IllegalArgumentException e) {
-               // }
-
-               // try {
-               // final byte[] ipv6addr = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
-               // (byte) 0x00,
-               // (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
-               // (byte) 0x00 };
-               // EROIpPrefixSubobjectParser.put(new EROIPPrefixSubobject<IPv6Prefix>(new IPv6Prefix(new IPv6Address(ipv6addr),
-               // 1), false));
-               // fail("");
-               // } catch (final IllegalArgumentException e) {
-               // }
-               //
-               // try {
-               // EROIPv6PrefixSubobjectParser.put(instance);
-               // fail("");
-               // } catch (final IllegalArgumentException e) {
-               // }
-               //
-               // try {
-               // final byte[] ipv4addr = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
-               // EROIPv6PrefixSubobjectParser.put(new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new
-               // IPv4Address(ipv4addr), 1), false));
-               // fail("");
-               // } catch (final IllegalArgumentException e) {
-               // }
-
-       }
-}
index 021b8891f83ccae385949a1514ddfa6bd2df9e86..95286efa441135a2db06edee69a92221a91ae93c 100644 (file)
  */
 package org.opendaylight.protocol.pcep.impl;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.math.BigInteger;
+import java.util.List;
+
+import org.junit.Test;
+import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.impl.tlv.LSPIdentifierTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LspDbVersionTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LspSymbolicNameTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LspUpdateErrorTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.NoPathVectorTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.OFListTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.OrderTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.OverloadedDurationTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.PCEStatefulCapabilityTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.PredundancyGroupTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.RSVPErrorSpecTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.ReqMissingTlvParser;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspDbVersionTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspErrorCodeTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfListTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OrderTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OverloadDurationTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PredundancyGroupIdTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ReqMissingTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RsvpErrorSpecTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.StatefulCapabilityTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.StatefulCapabilityTlv.Flags;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SymbolicPathName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SymbolicPathNameTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.LspErrorCodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.LspIdentifiersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.RsvpErrorSpecBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.SymbolicPathNameBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.tlvs.OverloadDurationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.LspDbVersionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.OfListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.PredundancyGroupIdBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.StatefulBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.tlvs.ReqMissingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.no.path.tlvs.NoPathVectorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.tlvs.OrderBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.RsvpBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.UserBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.rsvp.RsvpErrorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.user.UserErrorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv4ExtendedTunnelId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv6ExtendedTunnelId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.TunnelId;
+
+import com.google.common.collect.Lists;
 
-/**
- * Tests of PCEPTlvParser
- */
 public class PCEPTlvParserTest {
 
-       // @Test
-       // public void testDeserialization() throws PCEPDeserializerException, IOException {
-       // final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PackOfTlvs.bin");
-       // final List<PCEPTlv> tlvsToTest = PCEPTlvParser.parseTlv(bytesFromFile);
-       //
-       // assertEquals(17, tlvsToTest.size());
-       // assertEquals(tlvsToTest.get(0), new PCEStatefulCapabilityTlv(false, false, true));
-       // assertEquals(tlvsToTest.get(1), new LSPStateDBVersionTlv(0xFF00FFAAB2F5F2CFL));
-       // assertEquals(tlvsToTest.get(2), new PCEStatefulCapabilityTlv(false, true, true));
-       // assertEquals(tlvsToTest.get(3), new LSPStateDBVersionTlv(0xFFFFFFFFFFFFFFFFL));
-       // assertEquals(tlvsToTest.get(4), new NoPathVectorTlv(true, true, true, false, true, true));
-       // assertEquals(tlvsToTest.get(5), new OverloadedDurationTlv(0x7FFFFFFF));
-       // assertEquals(tlvsToTest.get(6), new LSPSymbolicNameTlv(new LSPSymbolicName(new
-       // String("Med test of symbolic name").getBytes())));
-       // final byte[] errorCode = { (byte) 0x25, (byte) 0x68, (byte) 0x95, (byte) 0x03 };
-       // assertEquals(tlvsToTest.get(7), new LSPUpdateErrorTlv(errorCode));
-       // final byte[] ipv4Address = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
-       // final byte[] tunnelId1 = { (byte) 0x12, (byte) 0x34 };
-       // final byte[] extendedTunnelID1 = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
-       // final byte[] lspId1 = { (byte) 0xFF, (byte) 0xFF };
-       // assertEquals(tlvsToTest.get(8), new IPv4LSPIdentifiersTlv(new IPv4Address(ipv4Address),
-       // new LSPIdentifier(lspId1), new TunnelIdentifier(tunnelId1), new IPv4ExtendedTunnelIdentifier(new
-       // IPv4Address(extendedTunnelID1))));
-       // final byte[] ipv6Address = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte)
-       // 0xDE, (byte) 0xF0, (byte) 0x12,
-       // (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0 };
-       // final byte[] tunnelId2 = { (byte) 0xFF, (byte) 0xFF };
-       // final byte[] extendedTunnelID2 = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x12, (byte) 0x34,
-       // (byte) 0x56, (byte) 0x78, (byte) 0x01,
-       // (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67 };
-       // final byte[] lspId2 = { (byte) 0x12, (byte) 0x34 };
-       // assertEquals(tlvsToTest.get(9), new IPv6LSPIdentifiersTlv(new IPv6Address(ipv6Address),
-       // new LSPIdentifier(lspId2), new TunnelIdentifier(tunnelId2), new IPv6ExtendedTunnelIdentifier(new
-       // IPv6Address(extendedTunnelID2))));
-       // assertEquals(tlvsToTest.get(10), new RSVPErrorSpecTlv<IPv4Address>(new IPv4Address(ipv4Address), false, true,
-       // 0x92, 0x1602));
-       // assertEquals(tlvsToTest.get(11), new RSVPErrorSpecTlv<IPv6Address>(new IPv6Address(ipv6Address), true, false,
-       // 0xD5, 0xC5D9));
-       // assertEquals(tlvsToTest.get(12), new ReqMissingTlv(0xF7823517L));
-       // final byte[] valueBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
-       // assertEquals(tlvsToTest.get(13), new NodeIdentifierTlv(valueBytes));
-       // assertEquals(tlvsToTest.get(14), new OrderTlv(0xFFFFFFFFL, 0x00000001L));
-       // assertEquals(tlvsToTest.get(15), new OFListTlv(new ArrayList<PCEPOFCodes>() {
-       // private static final long serialVersionUID = 1L;
-       //
-       // {
-       // this.add(PCEPOFCodes.MCC);
-       // this.add(PCEPOFCodes.MCP);
-       // this.add(PCEPOFCodes.MLL);
-       // }
-       // }));
-       // assertEquals(tlvsToTest.get(16), new P2MPCapabilityTlv(2));
-       //
-       // assertArrayEquals(bytesFromFile, PCEPTlvParser.put(tlvsToTest));
-       // }
-       //
-       // @Test
-       // public void testDifferentLengthExceptions() {
-       // final byte[] bytes = { (byte) 0x00 }; // not empty but not enought data
-       // // for parsing subobjects
-       //
-       // try {
-       // LSPIdentifierIPv4TlvParser.parse(bytes);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       //
-       // try {
-       // LSPIdentifierIPv6TlvParser.parse(bytes);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       //
-       // try {
-       // PCEStatefulCapabilityTlvParser.deserializeValueField(bytes);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       //
-       // try {
-       // RSVPErrorSpecTlvParser.parse(bytes);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       //
-       // try {
-       // RSVPErrorSpecIPv6TlvParser.parse(bytes);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       //
-       // try {
-       // OFListTlvParser.parse(bytes);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       // }
-       //
-       // @Test
-       // public void testUnknownInstanceExceptions() {
-       // try {
-       // LSPIdentifierIPv4TlvParser.put(null);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // LSPIdentifierIPv6TlvParser.put(null);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // PCEStatefulCapabilityTlvParser.serializeValueField(null);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // RSVPErrorSpecTlvParser.put(null);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // RSVPErrorSpecIPv6TlvParser.put(null);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // OFListTlvParser.put(null);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // }
-       //
-       // @Test
-       // public void testEmptyExceptions() throws PCEPDeserializerException {
-       // final byte[] bytes = {}; // empty
-       //
-       // try {
-       // LSPIdentifierIPv4TlvParser.parse(bytes);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // LSPIdentifierIPv6TlvParser.parse(bytes);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // PCEStatefulCapabilityTlvParser.deserializeValueField(bytes);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // RSVPErrorSpecTlvParser.parse(bytes);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // RSVPErrorSpecIPv6TlvParser.parse(bytes);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // OFListTlvParser.parse(bytes);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       // }
+       private static final byte[] statefulBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02 };
+       private static final byte[] DbVersionBytes = { (byte) 0xff, (byte) 0x00, (byte) 0xff, (byte) 0xaa, (byte) 0xb2, (byte) 0xf5,
+               (byte) 0xf2, (byte) 0xcf };
+       private static final byte[] noPathVectorBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xa7 };
+       private static final byte[] overloadedBytes = { (byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff };
+       private static final byte[] symbolicNameBytes = { (byte) 0x4d, (byte) 0x65, (byte) 0x64, (byte) 0x20, (byte) 0x74, (byte) 0x65,
+               (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x6f, (byte) 0x66, (byte) 0x20, (byte) 0x73, (byte) 0x79, (byte) 0x6d,
+               (byte) 0x62, (byte) 0x6f, (byte) 0x6c, (byte) 0x69, (byte) 0x63, (byte) 0x20, (byte) 0x6e, (byte) 0x61, (byte) 0x6d,
+               (byte) 0x65 };
+       private static final byte[] lspUpdateErrorBytes = { (byte) 0x25, (byte) 0x68, (byte) 0x95, (byte) 0x03 };
+       private static final byte[] lspIdentifiers4Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0xFF, (byte) 0xFF,
+               (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
+       private static final byte[] lspIdentifiers6Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC,
+               (byte) 0xDE, (byte) 0xF0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE,
+               (byte) 0xF0, (byte) 0x12, (byte) 0x34, (byte) 0xFF, (byte) 0xFF, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+               (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x01,
+               (byte) 0x23, (byte) 0x45, (byte) 0x67 };
+       private static final byte[] rsvpErrorBytes = { (byte) 0x06, (byte) 0x01, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+               (byte) 0x02, (byte) 0x92, (byte) 0x16, (byte) 0x02 };
+       private static final byte[] rsvpError6Bytes = { (byte) 0x06, (byte) 0x02, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+               (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a,
+               (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x02, (byte) 0xd5, (byte) 0xc5, (byte) 0xd9 };
+       private static final byte[] userErrorBytes = { (byte) 0xc2, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x30, (byte) 0x39,
+               (byte) 0x05, (byte) 0x09, (byte) 0x00, (byte) 0x26, (byte) 0x75, (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x20,
+               (byte) 0x64, (byte) 0x65, (byte) 0x73, (byte) 0x63 };
+       private static final byte[] reqMissingBytes = { (byte) 0xF7, (byte) 0x82, (byte) 0x35, (byte) 0x17 };
+       private static final byte[] orderBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+               (byte) 0x01 };
+       private static final byte[] ofListBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
+       private static final byte[] predundancyBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
+
+       @Test
+       public void testStatefulTlv() throws PCEPDeserializerException {
+               final PCEStatefulCapabilityTlvParser parser = new PCEStatefulCapabilityTlvParser();
+               final StatefulCapabilityTlv tlv = new StatefulBuilder().setFlags(new Flags(true, false, false)).build();
+               assertEquals(tlv, parser.parseTlv(statefulBytes));
+               assertArrayEquals(statefulBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testStateDbVersionTlv() throws PCEPDeserializerException {
+               final LspDbVersionTlvParser parser = new LspDbVersionTlvParser();
+               final LspDbVersionTlv tlv = new LspDbVersionBuilder().setVersion(BigInteger.valueOf(0xFF00FFAAB2F5F2CFL)).build();
+               assertEquals(tlv, parser.parseTlv(DbVersionBytes));
+               assertArrayEquals(DbVersionBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testNoPathVectorTlv() throws PCEPDeserializerException {
+               final NoPathVectorTlvParser parser = new NoPathVectorTlvParser();
+               final NoPathVectorTlv tlv = new NoPathVectorBuilder().setFlags(
+                               new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv.Flags(false, true, false, true, false, true, true, true)).build();
+               assertEquals(tlv, parser.parseTlv(noPathVectorBytes));
+               assertArrayEquals(noPathVectorBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testOverloadedDurationTlv() throws PCEPDeserializerException {
+               final OverloadedDurationTlvParser parser = new OverloadedDurationTlvParser();
+               final OverloadDurationTlv tlv = new OverloadDurationBuilder().setDuration(0x7FFFFFFFL).build();
+               assertEquals(tlv, parser.parseTlv(overloadedBytes));
+               assertArrayEquals(overloadedBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testSymbolicNameTlv() throws PCEPDeserializerException {
+               final LspSymbolicNameTlvParser parser = new LspSymbolicNameTlvParser();
+               final SymbolicPathNameTlv tlv = new SymbolicPathNameBuilder().setPathName(new SymbolicPathName("Med test of symbolic name".getBytes())).build();
+               assertEquals(tlv, parser.parseTlv(symbolicNameBytes));
+               assertArrayEquals(symbolicNameBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testLspErrorCodeTlv() throws PCEPDeserializerException {
+               final LspUpdateErrorTlvParser parser = new LspUpdateErrorTlvParser();
+               final LspErrorCodeTlv tlv = new LspErrorCodeBuilder().setErrorCode(627610883L).build();
+               assertEquals(tlv, parser.parseTlv(lspUpdateErrorBytes));
+               assertArrayEquals(lspUpdateErrorBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testLspIdentifiers4Tlv() throws PCEPDeserializerException {
+               final LSPIdentifierTlvParser parser = new LSPIdentifierTlvParser();
+               final Ipv4Builder afi = new Ipv4Builder();
+               afi.setIpv4TunnelSenderAddress(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }));
+               afi.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56,
+                               (byte) 0x78 })));
+               final LspIdentifiersTlv tlv = new LspIdentifiersBuilder().setAddressFamily(afi.build()).setLspId(new LspId(65535L)).setTunnelId(
+                               new TunnelId(4660)).build();
+               assertEquals(tlv, parser.parseTlv(lspIdentifiers4Bytes));
+               assertArrayEquals(lspIdentifiers4Bytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testLspIdentifiers6Tlv() throws PCEPDeserializerException {
+               final LSPIdentifierTlvParser parser = new LSPIdentifierTlvParser();
+               final Ipv6Builder afi = new Ipv6Builder();
+               afi.setIpv6TunnelSenderAddress(Ipv6Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+                               (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A,
+                               (byte) 0xBC, (byte) 0xDE, (byte) 0xF0 }));
+               afi.setIpv6ExtendedTunnelId(new Ipv6ExtendedTunnelId(Ipv6Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56,
+                               (byte) 0x78, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67,
+                               (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67 })));
+               final LspIdentifiersTlv tlv = new LspIdentifiersBuilder().setAddressFamily(afi.build()).setLspId(new LspId(4660L)).setTunnelId(
+                               new TunnelId(65535)).build();
+               assertEquals(tlv, parser.parseTlv(lspIdentifiers6Bytes));
+               assertArrayEquals(lspIdentifiers6Bytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testRSVPError4SpecTlv() throws PCEPDeserializerException {
+               final RSVPErrorSpecTlvParser parser = new RSVPErrorSpecTlvParser();
+               final RsvpErrorBuilder builder = new RsvpErrorBuilder();
+               builder.setNode(new IpAddress(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })));
+               builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ErrorSpec.Flags(false, true));
+               builder.setCode((short) 146);
+               builder.setValue(5634);
+               final RsvpErrorSpecTlv tlv = new RsvpErrorSpecBuilder().setErrorType(new RsvpBuilder().setRsvpError(builder.build()).build()).build();
+               assertEquals(tlv, parser.parseTlv(rsvpErrorBytes));
+               assertArrayEquals(rsvpErrorBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testRSVPError6SpecTlv() throws PCEPDeserializerException {
+               final RSVPErrorSpecTlvParser parser = new RSVPErrorSpecTlvParser();
+               final RsvpErrorBuilder builder = new RsvpErrorBuilder();
+               builder.setNode(new IpAddress(Ipv6Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+                               (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a,
+                               (byte) 0xbc, (byte) 0xde, (byte) 0xf0 })));
+               builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ErrorSpec.Flags(false, true));
+               builder.setCode((short) 213);
+               builder.setValue(50649);
+               final RsvpErrorSpecTlv tlv = new RsvpErrorSpecBuilder().setErrorType(new RsvpBuilder().setRsvpError(builder.build()).build()).build();
+               assertEquals(tlv, parser.parseTlv(rsvpError6Bytes));
+               assertArrayEquals(rsvpError6Bytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testUserErrorSpecTlv() throws PCEPDeserializerException {
+               final RSVPErrorSpecTlvParser parser = new RSVPErrorSpecTlvParser();
+               final UserErrorBuilder builder = new UserErrorBuilder();
+               builder.setEnterprise(new EnterpriseNumber(12345L));
+               builder.setSubOrg((short) 5);
+               builder.setValue(38);
+               builder.setDescription("user desc");
+               final RsvpErrorSpecTlv tlv = new RsvpErrorSpecBuilder().setErrorType(new UserBuilder().setUserError(builder.build()).build()).build();
+               assertEquals(tlv, parser.parseTlv(userErrorBytes));
+               assertArrayEquals(userErrorBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testReqMissingTlv() throws PCEPDeserializerException {
+               final ReqMissingTlvParser parser = new ReqMissingTlvParser();
+               final ReqMissingTlv tlv = new ReqMissingBuilder().setRequestId(new RequestId(0xF7823517L)).build();
+               assertEquals(tlv, parser.parseTlv(reqMissingBytes));
+               assertArrayEquals(reqMissingBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testOrderTlv() throws PCEPDeserializerException {
+               final OrderTlvParser parser = new OrderTlvParser();
+               final OrderTlv tlv = new OrderBuilder().setDelete(0xFFFFFFFFL).setSetup(0x00000001L).build();
+               assertEquals(tlv, parser.parseTlv(orderBytes));
+               assertArrayEquals(orderBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testOFListTlv() throws PCEPDeserializerException {
+               final OFListTlvParser parser = new OFListTlvParser();
+               final List<OfId> ids = Lists.newArrayList();
+               ids.add(new OfId(0x1234));
+               ids.add(new OfId(0x5678));
+               final OfListTlv tlv = new OfListBuilder().setCodes(ids).build();
+               assertEquals(tlv, parser.parseTlv(ofListBytes));
+               assertArrayEquals(ofListBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testPredundancyTlv() throws PCEPDeserializerException {
+               final PredundancyGroupTlvParser parser = new PredundancyGroupTlvParser();
+               final PredundancyGroupIdTlv tlv = new PredundancyGroupIdBuilder().setIdentifier(predundancyBytes).build();
+               assertEquals(tlv, parser.parseTlv(predundancyBytes));
+               assertArrayEquals(predundancyBytes, parser.serializeTlv(tlv));
+       }
 }
index 7c8350c469aaf5d4ee752ac58f9ef02166682541..d72e86607ee37d9401910b9b0a9bcdd0b6700883 100644 (file)
  */
 package org.opendaylight.protocol.pcep.impl;
 
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
 
 import org.junit.Test;
+import org.opendaylight.protocol.concepts.Ipv6Util;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.impl.subobject.XROAsNumberSubobjectParser;
 import org.opendaylight.protocol.pcep.impl.subobject.XROIpPrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.XROPathKeySubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.XROSRLGSubobjectParser;
 import org.opendaylight.protocol.pcep.impl.subobject.XROUnnumberedInterfaceSubobjectParser;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKeyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ExcludeRouteSubobjects.Attribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.SrlgId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.SrlgBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.UnnumberedBuilder;
 
 public class PCEPXROSubobjectParserTest {
 
-       @Test
-       public void testSerDeser() throws PCEPDeserializerException, IOException {
-               final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PackOfXROSubobjects.bin");
-               // final List<ExcludeRouteSubobject> objsToTest = PCEPXROSubobjectParser.parse(bytesFromFile);
+       private static final byte[] ip4PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x00 };
+       private static final byte[] ip6PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                       (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                       (byte) 0xFF, (byte) 0x16, (byte) 0x01 };
+       private static final byte[] srlgBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x02 };
+       private static final byte[] unnumberedBytes = { (byte) 0x00, (byte) 0x01, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00,
+                       (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+       private static final byte[] asNumberBytes = { (byte) 0x00, (byte) 0x64 };
+       private static final byte[] pathKey32Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 };
+       private static final byte[] pathKey128Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+                       (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x00 };
 
-               // assertEquals(5, objsToTest.size());
-               //
-               // assertEquals(
-               // objsToTest.get(0),
-               // new XROIPPrefixSubobject(new IpPrefix(Ipv4Util.prefixForBytes(new byte[] { (byte) 192, (byte) 168, (byte) 0,
-               // (byte) 0 }, 16)), true, XROSubobjectAttribute.NODE));
-               // assertEquals(
-               // objsToTest.get(1),
-               // new XROIPPrefixSubobject(new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte)
-               // 0x56,
-               // (byte) 0x78, (byte) 0x90, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x90, (byte) 0x12,
-               // (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0, (byte) 0 }, 112)), true, XROSubobjectAttribute.INTERFACE));
-               // assertEquals(objsToTest.get(2), new XROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { (byte) 0,
-               // (byte) 0, (byte) 0,
-               // (byte) 0x20 }), new UnnumberedInterfaceIdentifier(0x1234L), false, XROSubobjectAttribute.SRLG));
-               // assertEquals(objsToTest.get(3), new XROAsNumberSubobject(new AsNumber((long) 0x1234), false));
-               // assertEquals(objsToTest.get(4), new XROSRLGSubobject(new SharedRiskLinkGroup(0x12345678L), false));
+       @Test
+       public void testXROIp4PrefixSubobject() throws PCEPDeserializerException {
+               final XROIpPrefixSubobjectParser parser = new XROIpPrefixSubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setMandatory(false);
+               subs.setAttribute(Attribute.Interface);
+               subs.setSubobjectType(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build());
+               assertEquals(subs.build(), parser.parseSubobject(ip4PrefixBytes, false));
+               assertArrayEquals(ip4PrefixBytes, parser.serializeSubobject(subs.build()));
+       }
 
-               // assertArrayEquals(bytesFromFile, PCEPXROSubobjectParser.put(objsToTest));
+       @Test
+       public void testXROIp6PrefixSubobject() throws PCEPDeserializerException {
+               final XROIpPrefixSubobjectParser parser = new XROIpPrefixSubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setMandatory(true);
+               subs.setAttribute(Attribute.Node);
+               subs.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+                               new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                                               (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                                               (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22))).build());
+               assertEquals(subs.build(), parser.parseSubobject(ip6PrefixBytes, true));
+               assertArrayEquals(ip6PrefixBytes, parser.serializeSubobject(subs.build()));
+       }
 
+       @Test
+       public void testXROSrlgSubobject() throws PCEPDeserializerException {
+               final XROSRLGSubobjectParser parser = new XROSRLGSubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setMandatory(true);
+               subs.setAttribute(Attribute.Srlg);
+               subs.setSubobjectType(new SrlgBuilder().setSrlgId(new SrlgId(0x12345678L)).build());
+               assertEquals(subs.build(), parser.parseSubobject(srlgBytes, true));
+               assertArrayEquals(srlgBytes, parser.serializeSubobject(subs.build()));
        }
 
        @Test
-       public void testDifferentLengthExceptions() {
-               final byte[] bytes = { (byte) 0x00 }; // not empty but not enought data for parsing subobjects
+       public void testXROUnnumberedSubobject() throws PCEPDeserializerException {
+               final XROUnnumberedInterfaceSubobjectParser parser = new XROUnnumberedInterfaceSubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setMandatory(true);
+               subs.setAttribute(Attribute.Node);
+               subs.setSubobjectType(new UnnumberedBuilder().setRouterId(0x12345000L).setInterfaceId(0xffffffffL).build());
+               assertEquals(subs.build(), parser.parseSubobject(unnumberedBytes, true));
+               assertArrayEquals(unnumberedBytes, parser.serializeSubobject(subs.build()));
+       }
 
-               try {
-                       new XROAsNumberSubobjectParser().parseSubobject(bytes, true);
-                       fail("");
-               } catch (final PCEPDeserializerException e) {
-               }
+       @Test
+       public void testXROAsNumberSubobject() throws PCEPDeserializerException {
+               final XROAsNumberSubobjectParser parser = new XROAsNumberSubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setMandatory(true);
+               subs.setSubobjectType(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build());
+               assertEquals(subs.build(), parser.parseSubobject(asNumberBytes, true));
+               assertArrayEquals(asNumberBytes, parser.serializeSubobject(subs.build()));
+       }
 
-               try {
-                       new XROUnnumberedInterfaceSubobjectParser().parseSubobject(bytes, true);
-                       fail("");
-               } catch (final PCEPDeserializerException e) {
-               }
+       @Test
+       public void testXROPathKey32Subobject() throws PCEPDeserializerException {
+               final XROPathKeySubobjectParser parser = new XROPathKeySubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setMandatory(true);
+               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+               pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 }));
+               pBuilder.setPathKey(new PathKey(4660));
+               subs.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
+               assertEquals(subs.build(), parser.parseSubobject(pathKey32Bytes, true));
+               assertArrayEquals(pathKey32Bytes, parser.serializeSubobject(subs.build()));
+       }
 
-               try {
-                       new XROIpPrefixSubobjectParser().parseSubobject(bytes, true);
-                       fail("");
-               } catch (final PCEPDeserializerException e) {
-               }
+       @Test
+       public void testXROPathKey128Subobject() throws PCEPDeserializerException {
+               final XROPathKeySubobjectParser parser = new XROPathKeySubobjectParser();
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setMandatory(true);
+               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+               pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE,
+                               (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
+               pBuilder.setPathKey(new PathKey(4660));
+               subs.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
+               assertEquals(subs.build(), parser.parseSubobject(pathKey128Bytes, true));
+               assertArrayEquals(pathKey128Bytes, parser.serializeSubobject(subs.build()));
        }
 }
index 15ed6582d4dfa586f50bde86ee1dd6572d486326..e796e077bfe7218b5c99cd729097ae277e728c02 100644 (file)
@@ -11,12 +11,16 @@ import static org.mockito.Mockito.mock;
 import io.netty.channel.Channel;
 import io.netty.util.HashedWheelTimer;
 
+import java.util.concurrent.Future;
+
 import org.opendaylight.protocol.pcep.PCEPCloseTermination;
 import org.opendaylight.protocol.pcep.PCEPSessionListener;
 import org.opendaylight.protocol.pcep.TerminationReason;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.open.message.OpenBuilder;
 
+import com.google.common.util.concurrent.Futures;
+
 public class ServerSessionMock extends PCEPSessionImpl {
 
        private final MockPCE client;
@@ -28,9 +32,10 @@ public class ServerSessionMock extends PCEPSessionImpl {
        }
 
        @Override
-       public void sendMessage(final Message msg) {
+       public Future<Void> sendMessage(final Message msg) {
                this.lastMessageSentAt = System.nanoTime();
                this.client.onMessage(this, msg);
+               return Futures.immediateFuture(null);
        }
 
        @Override
diff --git a/pcep/impl/src/test/resources/LSPStateDBVersionTlv1.bin b/pcep/impl/src/test/resources/LSPStateDBVersionTlv1.bin
deleted file mode 100644 (file)
index 636c636..0000000
Binary files a/pcep/impl/src/test/resources/LSPStateDBVersionTlv1.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/LSPStateDBVersionTlv2.bin b/pcep/impl/src/test/resources/LSPStateDBVersionTlv2.bin
deleted file mode 100644 (file)
index cbd64c6..0000000
Binary files a/pcep/impl/src/test/resources/LSPStateDBVersionTlv2.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/LSPStateDBVersionTlvInvalid1.bin b/pcep/impl/src/test/resources/LSPStateDBVersionTlvInvalid1.bin
deleted file mode 100644 (file)
index 43c2cfe..0000000
Binary files a/pcep/impl/src/test/resources/LSPStateDBVersionTlvInvalid1.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/NoPathObject1WithTLV.bin b/pcep/impl/src/test/resources/NoPathObject1WithTLV.bin
deleted file mode 100644 (file)
index 58ca456..0000000
Binary files a/pcep/impl/src/test/resources/NoPathObject1WithTLV.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/NoPathObject2WithoutTLV.bin b/pcep/impl/src/test/resources/NoPathObject2WithoutTLV.bin
deleted file mode 100644 (file)
index 6f89865..0000000
Binary files a/pcep/impl/src/test/resources/NoPathObject2WithoutTLV.bin and /dev/null differ
index e6a25a7df6bac76d14f0b8eb04ec42e92a0689bc..593f4708db84ac8fd0f5cc47c634f38c013fe9e4 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPBandwidthObject1LowerBounds.bin and b/pcep/impl/src/test/resources/PCEPBandwidthObject1LowerBounds.bin differ
index 3ebf1ec6dd0ecd622669ff6825ca356465d6cbaf..7bde8641b93c7c55f7365596085b0ce811d0b6c8 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPBandwidthObject2UpperBounds.bin and b/pcep/impl/src/test/resources/PCEPBandwidthObject2UpperBounds.bin differ
index 29dab1a54dd6109d95c9753026bfdf9e6dfb027d..3b6fc84f4eecaa6f1b4fc34beba7e3a80f68e98d 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPCloseObject1.bin and b/pcep/impl/src/test/resources/PCEPCloseObject1.bin differ
index addad73ab0ada5b949e04c33512845212d41af94..7a693eab89653098d1d7d5ede44d510c9ccdb67f 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPEndPointsObject1IPv4.bin and b/pcep/impl/src/test/resources/PCEPEndPointsObject1IPv4.bin differ
index 9470b7cfa7080a0ef8d36b928c1bde3fc4837ab5..4f41aa403a819924ab2307ba8b567a07dcbace51 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPEndPointsObject2IPv6.bin and b/pcep/impl/src/test/resources/PCEPEndPointsObject2IPv6.bin differ
index 831aac4581eb0439dee00724ec549060ce269d16..22dd98779ba497f78b65cadecfcfbffddae7314b 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPGlobalConstraintsObject.1.bin and b/pcep/impl/src/test/resources/PCEPGlobalConstraintsObject.1.bin differ
diff --git a/pcep/impl/src/test/resources/PCEPKeepAliveMessage1.bin b/pcep/impl/src/test/resources/PCEPKeepAliveMessage1.bin
deleted file mode 100644 (file)
index dd6707b..0000000
Binary files a/pcep/impl/src/test/resources/PCEPKeepAliveMessage1.bin and /dev/null differ
index 7070f4b587282755f86e0cfa9b4326f5a3defe51..357cfbf279ac888dfda8e381a525330484ba456b 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPLoadBalancingObject1.bin and b/pcep/impl/src/test/resources/PCEPLoadBalancingObject1.bin differ
index 38c3d837b1027f84bd3af66b0444a2a4f77d54e7..01d633b27e8ea9b17084fc911d0c8cc43a4170a9 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPLspaObject1LowerBounds.bin and b/pcep/impl/src/test/resources/PCEPLspaObject1LowerBounds.bin differ
index de8441e5d1e66174926c93b45b87b9757e7d59eb..d3ee142bdbfc6fff6dfbba0b8b56dbab4909a7d4 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPLspaObject2UpperBounds.bin and b/pcep/impl/src/test/resources/PCEPLspaObject2UpperBounds.bin differ
index 4d1562902065f0b40bdf69966fb5a7569c63ec74..2834c257a40e76eca8841735486c56afb1217f24 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPLspaObject3RandVals.bin and b/pcep/impl/src/test/resources/PCEPLspaObject3RandVals.bin differ
index bb6c3a766f7e85a0c2a7b90548825752586f6839..46426b1617fe258a6500bfba3eb6daea70933b74 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPMetricObject1LowerBounds.bin and b/pcep/impl/src/test/resources/PCEPMetricObject1LowerBounds.bin differ
index 4b80f385591b40a8b1a8270c0c79262869a2f54b..49eee514f7f37d55224e45fac18a78c7ebe5fdea 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPMetricObject2UpperBounds.bin and b/pcep/impl/src/test/resources/PCEPMetricObject2UpperBounds.bin differ
index 45094a11dc6785f34a173486118688180223bc5e..0357d47a88433c9240547f8ff3f5a52f3f9528c3 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPObjectiveFunctionObject.1.bin and b/pcep/impl/src/test/resources/PCEPObjectiveFunctionObject.1.bin differ
index 7e75b794f27475379597092dfe77804da20d8c1c..012710f6ac768414697d32b6b7ccbba175f7675c 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPSvecObject1_10ReqIDs.bin and b/pcep/impl/src/test/resources/PCEPSvecObject1_10ReqIDs.bin differ
index 7f21270f24cb5f2395893b3e75949053f6dac87c..b59255eabed35cfb91819f1a7e31ef2cfbbe519a 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPSvecObject2.bin and b/pcep/impl/src/test/resources/PCEPSvecObject2.bin differ
diff --git a/pcep/impl/src/test/resources/PCEStatefulCapabilityTlv1.bin b/pcep/impl/src/test/resources/PCEStatefulCapabilityTlv1.bin
deleted file mode 100644 (file)
index 34bcb8e..0000000
Binary files a/pcep/impl/src/test/resources/PCEStatefulCapabilityTlv1.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/PCEStatefulCapabilityTlv2.bin b/pcep/impl/src/test/resources/PCEStatefulCapabilityTlv2.bin
deleted file mode 100644 (file)
index c23ed7a..0000000
Binary files a/pcep/impl/src/test/resources/PCEStatefulCapabilityTlv2.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/PCEStatefulCapabilityTlvInvalid1.bin b/pcep/impl/src/test/resources/PCEStatefulCapabilityTlvInvalid1.bin
deleted file mode 100644 (file)
index ba8e160..0000000
Binary files a/pcep/impl/src/test/resources/PCEStatefulCapabilityTlvInvalid1.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/PackOfSubobjects.bin b/pcep/impl/src/test/resources/PackOfSubobjects.bin
deleted file mode 100644 (file)
index 22e5562..0000000
Binary files a/pcep/impl/src/test/resources/PackOfSubobjects.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/PackOfTlvs.bin b/pcep/impl/src/test/resources/PackOfTlvs.bin
deleted file mode 100644 (file)
index 98e8383..0000000
Binary files a/pcep/impl/src/test/resources/PackOfTlvs.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/PackOfXROSubobjects.bin b/pcep/impl/src/test/resources/PackOfXROSubobjects.bin
deleted file mode 100644 (file)
index 8e555d0..0000000
Binary files a/pcep/impl/src/test/resources/PackOfXROSubobjects.bin and /dev/null differ
index 6adf2e98ec8dc4bb947b6d4b926c115cd1f7e436..9492692d90c801b0e42ba0a9d7cd79fe1b9eaf81 100644 (file)
             <version>${project.version}</version>
                        <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>${osgi.version}</version>
+            <scope>provided</scope>
+        </dependency>
        </dependencies>
 
        <build>
                        <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
                        <Export-Package>
                            org.opendaylight.protocol.pcep.spi,
+                           org.opendaylight.protocol.pcep.spi.osgi,
                        </Export-Package>
+                       <Private-Package>
+                           org.opendaylight.protocol.pcep.spi.pojo,
+                       </Private-Package>
                    </instructions>
                </configuration>
            </plugin>
index f50b8baced77dd99d9209100afe3bfb23f720334..83d7e24eb008e8ed12144a0ceac2ac4cf0fcb3b9 100644 (file)
@@ -8,14 +8,8 @@
 package org.opendaylight.protocol.pcep.spi;
 
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
 
 public interface EROSubobjectHandlerRegistry {
-       public AutoCloseable registerSubobjectParser(int subobjectType, EROSubobjectParser parser);
-
        public EROSubobjectParser getSubobjectParser(int subobjectType);
-
-       public AutoCloseable registerSubobjectSerializer(Class<? extends CSubobject> subobjectClass, EROSubobjectSerializer serializer);
-
        public EROSubobjectSerializer getSubobjectSerializer(Subobjects subobject);
 }
index 3f0d4c6b582de75c4de3d1eb5cb319a0200c935e..967352abea2e728fd9227be51d3865efdd57a856 100644 (file)
@@ -7,12 +7,10 @@
  */
 package org.opendaylight.protocol.pcep.spi;
 
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
 
 public interface LabelHandlerRegistry {
-       public AutoCloseable registerLabelParser(int cType, LabelParser parser);
        public LabelParser getLabelParser(int cType);
 
-       public AutoCloseable registerLabelSerializer(Class<? extends CLabel> labelClass, LabelSerializer serializer);
-       public LabelSerializer getLabelSerializer(CLabel label);
+       public LabelSerializer getLabelSerializer(LabelType label);
 }
index d17dce13b1c9e9171cbc1e7bdf33caaab0925b7a..11024bf25890abd8bc8f4760ddd6792d831cf361 100644 (file)
@@ -7,12 +7,12 @@
  */
 package org.opendaylight.protocol.pcep.spi;
 
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
 
 public interface LabelSerializer {
 
        @Deprecated
        public int getType();
 
-       public byte[] serializeSubobject(CLabel subobject);
+       public byte[] serializeLabel(LabelType subobject);
 }
index bd3c136dc61ffdd00d1bbc39c4bdd91c08476638..e9a513009239c093c8fa2e2f9131a4a6e09a0427 100644 (file)
@@ -10,9 +10,6 @@ package org.opendaylight.protocol.pcep.spi;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
 
 public interface MessageHandlerRegistry {
-       public AutoCloseable registerMessageParser(int messageType, MessageParser parser);
-       public AutoCloseable registerMessageSerializer(Class<? extends Message> msgClass, MessageSerializer serializer);
-
        public MessageParser getMessageParser(int messageType);
        public MessageSerializer getMessageSerializer(Message message);
 }
index a003177891accfd0993bdb56680b80f1e00d1b34..0d5ca0c838f8ff6f2c402fc7ba5a5a9befe494c2 100644 (file)
@@ -10,9 +10,6 @@ package org.opendaylight.protocol.pcep.spi;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 
 public interface ObjectHandlerRegistry {
-       public AutoCloseable registerObjectParser(int objectClass, int objectType, ObjectParser parser);
-       public AutoCloseable registerObjectSerializer(Class<? extends Object> objClass, ObjectSerializer serializer);
-
        public ObjectParser getObjectParser(int objectClass, int objectType);
        public ObjectSerializer getObjectSerializer(Object object);
 }
similarity index 77%
rename from pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPProviderActivator.java
rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPExtensionConsumerActivator.java
index 4facaeaa2e3179bfb47b74cfb2b65bc643d6d5b0..8759908a8d89206dbe6bb01fbb81b2b305ff8f9f 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.protocol.pcep.spi;
 
-public interface PCEPProviderActivator {
-       public void start(PCEPProviderContext context);
+public interface PCEPExtensionConsumerActivator {
+       public void start(PCEPExtensionConsumerContext context);
        public void stop();
 }
\ No newline at end of file
similarity index 94%
rename from pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPProviderContext.java
rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPExtensionConsumerContext.java
index 45b8f44d9cff71ecf36b3bbc1600fb94e877a674..f4db40b8e08713114fc27f0f85545352c8da4b38 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.protocol.pcep.spi;
 
-public interface PCEPProviderContext {
+public interface PCEPExtensionConsumerContext {
 
        public LabelHandlerRegistry getLabelHandlerRegistry();
        
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPExtensionProviderActivator.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPExtensionProviderActivator.java
new file mode 100644 (file)
index 0000000..d2e4e65
--- /dev/null
@@ -0,0 +1,13 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.spi;
+
+public interface PCEPExtensionProviderActivator {
+       public void start(PCEPExtensionProviderContext context) throws Exception;
+       public void stop() throws Exception;
+}
\ No newline at end of file
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPExtensionProviderContext.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/PCEPExtensionProviderContext.java
new file mode 100644 (file)
index 0000000..f2b5388
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.spi;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
+
+public interface PCEPExtensionProviderContext extends PCEPExtensionConsumerContext {
+       public AutoCloseable registerLabelSerializer(Class<? extends LabelType> labelClass, LabelSerializer serializer);
+
+       public AutoCloseable registerLabelParser(int cType, LabelParser parser);
+
+       public AutoCloseable registerEROSubobjectParser(int subobjectType, EROSubobjectParser parser);
+
+       public AutoCloseable registerEROSubobjectSerializer(Class<? extends CSubobject> subobjectClass, EROSubobjectSerializer serializer);
+
+       public AutoCloseable registerMessageParser(int messageType, MessageParser parser);
+
+       public AutoCloseable registerMessageSerializer(Class<? extends Message> msgClass, MessageSerializer serializer);
+
+       public AutoCloseable registerObjectParser(int objectClass, int objectType, ObjectParser parser);
+
+       public AutoCloseable registerObjectSerializer(Class<? extends Object> objClass, ObjectSerializer serializer);
+
+       public AutoCloseable registerRROSubobjectParser(int subobjectType, RROSubobjectParser parser);
+
+       public AutoCloseable registerRROSubobjectSerializer(Class<? extends CSubobject> subobjectClass, RROSubobjectSerializer serializer);
+
+       public AutoCloseable registerTlvSerializer(Class<? extends Tlv> tlvClass, TlvSerializer serializer);
+
+       public AutoCloseable registerTlvParser(int tlvType, TlvParser parser);
+
+       public AutoCloseable registerXROSubobjectSerializer(Class<? extends CSubobject> subobjectClass, XROSubobjectSerializer serializer);
+
+       public AutoCloseable registerXROSubobjectParser(int subobjectType, XROSubobjectParser parser);
+}
index 34194f15b92c60e31a64cb95a2ccc9a9271e77c4..53602058d6fff2a7518207fcae55e7e3fece5784 100644 (file)
@@ -8,14 +8,8 @@
 package org.opendaylight.protocol.pcep.spi;
 
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Subobjects;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
 
 public interface RROSubobjectHandlerRegistry {
-       public AutoCloseable registerSubobjectParser(int subobjectType, RROSubobjectParser parser);
-
        public RROSubobjectParser getSubobjectParser(int subobjectType);
-
-       public AutoCloseable registerSubobjectSerializer(Class<? extends CSubobject> subobjectClass, RROSubobjectSerializer serializer);
-
        public RROSubobjectSerializer getSubobjectSerializer(Subobjects subobject);
 }
index 5ad71a0b7c724da837facca95a4f15bab09fe81c..6274f08111a13ccabfc15b2f3e163b40a03dfd65 100644 (file)
@@ -10,9 +10,6 @@ package org.opendaylight.protocol.pcep.spi;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
 
 public interface TlvHandlerRegistry {
-       public AutoCloseable registerTlvParser(int tlvType, TlvParser parser);
        public TlvParser getTlvParser(int tlvType);
-
-       public AutoCloseable registerTlvSerializer(Class<? extends Tlv> tlvClass, TlvSerializer serializer);
        public TlvSerializer getTlvSerializer(Tlv tlv);
 }
index cca8615d9436383cb27144fce555aac1a60d4067..2e4637077476c95bf7c7ae6707dbab702a6818cd 100644 (file)
@@ -8,15 +8,8 @@
 package org.opendaylight.protocol.pcep.spi;
 
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
 
 public interface XROSubobjectHandlerRegistry {
-
-       public AutoCloseable registerSubobjectParser(int subobjectType, XROSubobjectParser parser);
-
        public XROSubobjectParser getSubobjectParser(int subobjectType);
-
-       public AutoCloseable registerSubobjectSerializer(Class<? extends CSubobject> subobjectClass, XROSubobjectSerializer serializer);
-
        public XROSubobjectSerializer getSubobjectSerializer(Subobjects subobject);
 }
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/osgi/AbstractOSGiPCEPExtensionConsumerActivator.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/osgi/AbstractOSGiPCEPExtensionConsumerActivator.java
new file mode 100644 (file)
index 0000000..b1230c7
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.spi.osgi;
+
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionConsumerActivator;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionConsumerContext;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+import com.google.common.base.Preconditions;
+
+public abstract class AbstractOSGiPCEPExtensionConsumerActivator implements BundleActivator, PCEPExtensionConsumerActivator {
+       private PCEPExtensionConsumerContext consumerContext;
+
+       @Override
+       public final void start(final BundleContext context) throws Exception {
+               Preconditions.checkState(consumerContext == null);
+               final PCEPExtensionConsumerContext consumerContext = new OSGiPCEPExtensionConsumerContext(context);
+               start(consumerContext);
+               this.consumerContext = consumerContext;
+       }
+
+       @Override
+       public final void stop(final BundleContext context) throws Exception {
+               Preconditions.checkState(consumerContext != null);
+               try {
+                       stop();
+               } finally {
+                       consumerContext = null;
+               }
+       }
+}
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/osgi/AbstractOSGiPCEPExtensionProviderActivator.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/osgi/AbstractOSGiPCEPExtensionProviderActivator.java
new file mode 100644 (file)
index 0000000..f59071a
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.spi.osgi;
+
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+import com.google.common.base.Preconditions;
+
+public abstract class AbstractOSGiPCEPExtensionProviderActivator implements BundleActivator, PCEPExtensionProviderActivator {
+       private PCEPExtensionProviderContext providerContext;
+
+       @Override
+       public final void start(final BundleContext context) throws Exception {
+               Preconditions.checkState(providerContext == null);
+               final PCEPExtensionProviderContext providerContext = new OSGiPCEPExtensionProviderContext(context);
+               start(providerContext);
+               this.providerContext = providerContext;
+       }
+
+       @Override
+       public final void stop(final BundleContext context) throws Exception {
+               Preconditions.checkState(providerContext != null);
+               try {
+                       stop();
+               } finally {
+                       providerContext = null;
+               }
+       }
+}
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/osgi/OSGiPCEPExtensionConsumerContext.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/osgi/OSGiPCEPExtensionConsumerContext.java
new file mode 100644 (file)
index 0000000..80b2891
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.spi.osgi;
+
+import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionConsumerContext;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.osgi.framework.BundleContext;
+
+import com.google.common.base.Preconditions;
+
+class OSGiPCEPExtensionConsumerContext implements PCEPExtensionConsumerContext {
+       protected final BundleContext bundleContext;
+
+       public OSGiPCEPExtensionConsumerContext(final BundleContext context) {
+               this.bundleContext = Preconditions.checkNotNull(context);
+       }
+
+       @Override
+       public LabelHandlerRegistry getLabelHandlerRegistry() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public MessageHandlerRegistry getMessageHandlerRegistry() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public ObjectHandlerRegistry getObjectHandlerRegistry() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public EROSubobjectHandlerRegistry getEROSubobjectHandlerRegistry() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public RROSubobjectHandlerRegistry getRROSubobjectHandlerRegistry() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public XROSubobjectHandlerRegistry getXROSubobjectHandlerRegistry() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public TlvHandlerRegistry getTlvHandlerRegistry() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+}
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/osgi/OSGiPCEPExtensionProviderContext.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/osgi/OSGiPCEPExtensionProviderContext.java
new file mode 100644 (file)
index 0000000..682c711
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.spi.osgi;
+
+import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.LabelParser;
+import org.opendaylight.protocol.pcep.spi.LabelSerializer;
+import org.opendaylight.protocol.pcep.spi.MessageParser;
+import org.opendaylight.protocol.pcep.spi.MessageSerializer;
+import org.opendaylight.protocol.pcep.spi.ObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.TlvParser;
+import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
+import org.osgi.framework.BundleContext;
+
+class OSGiPCEPExtensionProviderContext extends OSGiPCEPExtensionConsumerContext implements PCEPExtensionProviderContext {
+       OSGiPCEPExtensionProviderContext(final BundleContext context) {
+               super(context);
+       }
+
+       @Override
+       public AutoCloseable registerLabelSerializer(final Class<? extends LabelType> labelClass, final LabelSerializer serializer) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public AutoCloseable registerLabelParser(final int cType, final LabelParser parser) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public AutoCloseable registerEROSubobjectParser(final int subobjectType, final EROSubobjectParser parser) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public AutoCloseable registerEROSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+                       final EROSubobjectSerializer serializer) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public AutoCloseable registerMessageParser(final int messageType, final MessageParser parser) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public AutoCloseable registerMessageSerializer(final Class<? extends Message> msgClass, final MessageSerializer serializer) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public AutoCloseable registerObjectParser(final int objectClass, final int objectType, final ObjectParser parser) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public AutoCloseable registerObjectSerializer(final Class<? extends Object> objClass, final ObjectSerializer serializer) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public AutoCloseable registerRROSubobjectParser(final int subobjectType, final RROSubobjectParser parser) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public AutoCloseable registerRROSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+                       final RROSubobjectSerializer serializer) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public AutoCloseable registerTlvSerializer(final Class<? extends Tlv> tlvClass, final TlvSerializer serializer) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public AutoCloseable registerTlvParser(final int tlvType, final TlvParser parser) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public AutoCloseable registerXROSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+                       final XROSubobjectSerializer serializer) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public AutoCloseable registerXROSubobjectParser(final int subobjectType, final XROSubobjectParser parser) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+}
diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/PCEPExtensionProviderContextImpl.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/PCEPExtensionProviderContextImpl.java
new file mode 100644 (file)
index 0000000..ab2910d
--- /dev/null
@@ -0,0 +1,195 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.spi.pojo;
+
+import java.util.ServiceLoader;
+
+import javax.annotation.concurrent.ThreadSafe;
+
+import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.LabelParser;
+import org.opendaylight.protocol.pcep.spi.LabelSerializer;
+import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.MessageParser;
+import org.opendaylight.protocol.pcep.spi.MessageSerializer;
+import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator;
+import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvParser;
+import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
+
+/**
+ *
+ */
+@ThreadSafe
+public final class PCEPExtensionProviderContextImpl implements PCEPExtensionProviderContext {
+       private static final class Holder {
+               private static final PCEPExtensionProviderContext INSTANCE;
+
+               static {
+                       try {
+                               INSTANCE = PCEPExtensionProviderContextImpl.create();
+                       } catch (final Exception e) {
+                               throw new ExceptionInInitializerError(e);
+                       }
+               }
+       }
+
+       private final SimpleLabelHandlerRegistry labelReg = new SimpleLabelHandlerRegistry();
+       private final SimpleMessageHandlerRegistry msgReg = new SimpleMessageHandlerRegistry();
+       private final SimpleObjectHandlerRegistry objReg = new SimpleObjectHandlerRegistry();
+       private final SimpleEROSubobjectHandlerRegistry eroSubReg = new SimpleEROSubobjectHandlerRegistry();
+       private final SimpleRROSubobjectHandlerRegistry rroSubReg = new SimpleRROSubobjectHandlerRegistry();
+       private final SimpleXROSubobjectHandlerRegistry xroSubReg = new SimpleXROSubobjectHandlerRegistry();
+       private final SimpleTlvHandlerRegistry tlvReg = new SimpleTlvHandlerRegistry();
+
+       protected PCEPExtensionProviderContextImpl() {
+
+       }
+
+       public static PCEPExtensionProviderContext create() throws Exception {
+               final PCEPExtensionProviderContext ctx = new PCEPExtensionProviderContextImpl();
+
+               final ServiceLoader<PCEPExtensionProviderActivator> loader = ServiceLoader.load(PCEPExtensionProviderActivator.class);
+               for (final PCEPExtensionProviderActivator a : loader) {
+                       a.start(ctx);
+               }
+
+               return ctx;
+
+       }
+
+       public static PCEPExtensionProviderContext getSingletonInstance() {
+               return Holder.INSTANCE;
+       }
+
+       @Override
+       public LabelHandlerRegistry getLabelHandlerRegistry() {
+               return this.labelReg;
+       }
+
+       @Override
+       public MessageHandlerRegistry getMessageHandlerRegistry() {
+               return this.msgReg;
+       }
+
+       @Override
+       public ObjectHandlerRegistry getObjectHandlerRegistry() {
+               return this.objReg;
+       }
+
+       @Override
+       public EROSubobjectHandlerRegistry getEROSubobjectHandlerRegistry() {
+               return this.eroSubReg;
+       }
+
+       @Override
+       public RROSubobjectHandlerRegistry getRROSubobjectHandlerRegistry() {
+               return this.rroSubReg;
+       }
+
+       @Override
+       public XROSubobjectHandlerRegistry getXROSubobjectHandlerRegistry() {
+               return this.xroSubReg;
+       }
+
+       @Override
+       public TlvHandlerRegistry getTlvHandlerRegistry() {
+               return this.tlvReg;
+       }
+
+       @Override
+       public AutoCloseable registerLabelSerializer(final Class<? extends LabelType> labelClass, final LabelSerializer serializer) {
+               return this.labelReg.registerLabelSerializer(labelClass, serializer);
+       }
+
+       @Override
+       public AutoCloseable registerLabelParser(final int cType, final LabelParser parser) {
+               return this.labelReg.registerLabelParser(cType, parser);
+       }
+
+       @Override
+       public AutoCloseable registerEROSubobjectParser(final int subobjectType, final EROSubobjectParser parser) {
+               return this.eroSubReg.registerSubobjectParser(subobjectType, parser);
+       }
+
+       @Override
+       public AutoCloseable registerEROSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+                       final EROSubobjectSerializer serializer) {
+               return this.eroSubReg.registerSubobjectSerializer(subobjectClass, serializer);
+       }
+
+       @Override
+       public AutoCloseable registerMessageParser(final int messageType, final MessageParser parser) {
+               return this.msgReg.registerMessageParser(messageType, parser);
+       }
+
+       @Override
+       public AutoCloseable registerMessageSerializer(final Class<? extends Message> msgClass, final MessageSerializer serializer) {
+               return this.msgReg.registerMessageSerializer(msgClass, serializer);
+       }
+
+       @Override
+       public AutoCloseable registerObjectParser(final int objectClass, final int objectType, final ObjectParser parser) {
+               return this.objReg.registerObjectParser(objectClass, objectType, parser);
+       }
+
+       @Override
+       public AutoCloseable registerObjectSerializer(final Class<? extends Object> objClass, final ObjectSerializer serializer) {
+               return this.objReg.registerObjectSerializer(objClass, serializer);
+       }
+
+       @Override
+       public AutoCloseable registerRROSubobjectParser(final int subobjectType, final RROSubobjectParser parser) {
+               return this.rroSubReg.registerSubobjectParser(subobjectType, parser);
+       }
+
+       @Override
+       public AutoCloseable registerRROSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+                       final RROSubobjectSerializer serializer) {
+               return this.rroSubReg.registerSubobjectSerializer(subobjectClass, serializer);
+       }
+
+       @Override
+       public AutoCloseable registerTlvParser(final int tlvType, final TlvParser parser) {
+               return this.tlvReg.registerTlvParser(tlvType, parser);
+       }
+
+       @Override
+       public AutoCloseable registerTlvSerializer(final Class<? extends Tlv> tlvClass, final TlvSerializer serializer) {
+               return this.tlvReg.registerTlvSerializer(tlvClass, serializer);
+       }
+
+       @Override
+       public AutoCloseable registerXROSubobjectParser(final int subobjectType, final XROSubobjectParser parser) {
+               return this.xroSubReg.registerSubobjectParser(subobjectType, parser);
+       }
+
+       @Override
+       public AutoCloseable registerXROSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+                       final XROSubobjectSerializer serializer) {
+               return this.xroSubReg.registerSubobjectSerializer(subobjectClass, serializer);
+       }
+}
similarity index 87%
rename from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleEROSubobjectHandlerFactory.java
rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleEROSubobjectHandlerRegistry.java
index f0aeb62d3b0faa5a89fe05a7351ae8043a65c626..e083d2bebe92438d96169450bc6b15cb665544f6 100644 (file)
@@ -5,39 +5,38 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.protocol.pcep.impl;
+package org.opendaylight.protocol.pcep.spi.pojo;
 
 import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
 import com.google.common.base.Preconditions;
 
-public final class SimpleEROSubobjectHandlerFactory implements EROSubobjectHandlerRegistry {
+public final class SimpleEROSubobjectHandlerRegistry implements EROSubobjectHandlerRegistry {
        private final HandlerRegistry<DataContainer, EROSubobjectParser, EROSubobjectSerializer> handlers = new HandlerRegistry<>();
 
-       @Override
        public AutoCloseable registerSubobjectParser(final int subobjectType, final EROSubobjectParser parser) {
-               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
+               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
                return this.handlers.registerParser(subobjectType, parser);
        }
 
-       @Override
-       public EROSubobjectParser getSubobjectParser(final int subobjectType) {
-               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
-               return this.handlers.getParser(subobjectType);
-       }
-
-       @Override
        public AutoCloseable registerSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
                        final EROSubobjectSerializer serializer) {
                return this.handlers.registerSerializer(subobjectClass, serializer);
        }
 
+       @Override
+       public EROSubobjectParser getSubobjectParser(final int subobjectType) {
+               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
+               return this.handlers.getParser(subobjectType);
+       }
+
        @Override
        public EROSubobjectSerializer getSubobjectSerializer(final Subobjects subobject) {
                return this.handlers.getSerializer(subobject.getImplementedInterface());
similarity index 63%
rename from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleLabelHandlerRegistry.java
rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleLabelHandlerRegistry.java
index 1d34690a9584ba3cce2c9e87248ac6267e7ab637..e374d8118117069e6d5065e7f608e29cdcc6e07e 100644 (file)
@@ -5,13 +5,14 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.protocol.pcep.impl;
+package org.opendaylight.protocol.pcep.spi.pojo;
 
 import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.LabelParser;
 import org.opendaylight.protocol.pcep.spi.LabelSerializer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
+import org.opendaylight.protocol.util.Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
 import com.google.common.base.Preconditions;
@@ -19,25 +20,23 @@ import com.google.common.base.Preconditions;
 public class SimpleLabelHandlerRegistry implements LabelHandlerRegistry {
        private final HandlerRegistry<DataContainer, LabelParser, LabelSerializer> handlers = new HandlerRegistry<>();
 
-       @Override
        public AutoCloseable registerLabelParser(final int cType, final LabelParser parser) {
-               Preconditions.checkArgument(cType >= 0 && cType <= 255);
-               return handlers.registerParser(cType, parser);
+               Preconditions.checkArgument(cType >= 0 && cType <= Util.UNSIGNED_BYTE_MAX_VALUE);
+               return this.handlers.registerParser(cType, parser);
        }
 
-       @Override
-       public LabelParser getLabelParser(final int cType) {
-               Preconditions.checkArgument(cType >= 0 && cType <= 255);
-               return handlers.getParser(cType);
+       public AutoCloseable registerLabelSerializer(final Class<? extends LabelType> labelClass, final LabelSerializer serializer) {
+               return this.handlers.registerSerializer(labelClass, serializer);
        }
 
        @Override
-       public AutoCloseable registerLabelSerializer(final Class<? extends CLabel> labelClass, final LabelSerializer serializer) {
-               return handlers.registerSerializer(labelClass, serializer);
+       public LabelParser getLabelParser(final int cType) {
+               Preconditions.checkArgument(cType >= 0 && cType <= Util.UNSIGNED_BYTE_MAX_VALUE);
+               return this.handlers.getParser(cType);
        }
 
        @Override
-       public LabelSerializer getLabelSerializer(final CLabel label) {
-               return handlers.getSerializer(label.getImplementedInterface());
+       public LabelSerializer getLabelSerializer(final LabelType label) {
+               return this.handlers.getSerializer(label.getImplementedInterface());
        }
 }
similarity index 91%
rename from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleMessageHandlerRegistry.java
rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleMessageHandlerRegistry.java
index e64697d5c28af0674243569398432594a3d480f4..74f6bb348a23b3ca82d7fe62c39e66575d7d8b21 100644 (file)
@@ -5,12 +5,13 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.protocol.pcep.impl;
+package org.opendaylight.protocol.pcep.spi.pojo;
 
 import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.MessageParser;
 import org.opendaylight.protocol.pcep.spi.MessageSerializer;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
@@ -20,20 +21,18 @@ public final class SimpleMessageHandlerRegistry implements MessageHandlerRegistr
 
        private final HandlerRegistry<DataContainer, MessageParser, MessageSerializer> handlers = new HandlerRegistry<>();
 
-       @Override
        public AutoCloseable registerMessageParser(final int messageType, final MessageParser parser) {
-               Preconditions.checkArgument(messageType >= 0 && messageType <= 255);
+               Preconditions.checkArgument(messageType >= 0 && messageType <= Util.UNSIGNED_BYTE_MAX_VALUE);
                return this.handlers.registerParser(messageType, parser);
        }
 
-       @Override
        public AutoCloseable registerMessageSerializer(final Class<? extends Message> msgClass, final MessageSerializer serializer) {
                return this.handlers.registerSerializer(msgClass, serializer);
        }
 
        @Override
        public MessageParser getMessageParser(final int messageType) {
-               Preconditions.checkArgument(messageType >= 0 && messageType <= 255);
+               Preconditions.checkArgument(messageType >= 0 && messageType <= Util.UNSIGNED_BYTE_MAX_VALUE);
                return this.handlers.getParser(messageType);
        }
 
similarity index 76%
rename from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleObjectHandlerRegistry.java
rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleObjectHandlerRegistry.java
index c58df47b13d7d8f25e177e2098b0d244e999b281..7452e375783dc9402778d6222c54a8afd7a9d8e1 100644 (file)
@@ -5,12 +5,13 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.protocol.pcep.impl;
+package org.opendaylight.protocol.pcep.spi.pojo;
 
 import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.ObjectParser;
 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
@@ -22,31 +23,29 @@ import com.google.common.base.Preconditions;
 public final class SimpleObjectHandlerRegistry implements ObjectHandlerRegistry {
        private final HandlerRegistry<DataContainer, ObjectParser, ObjectSerializer> handlers = new HandlerRegistry<>();
 
-       private static final int createKey(final int objectClass, final int objectType) {
-               Preconditions.checkArgument(objectClass >= 0 && objectClass <= 255);
+       private static int createKey(final int objectClass, final int objectType) {
+               Preconditions.checkArgument(objectClass >= 0 && objectClass <= Util.UNSIGNED_BYTE_MAX_VALUE);
                Preconditions.checkArgument(objectType >= 0 && objectType <= 15);
                return (objectClass << 4) | objectType;
        }
 
-       @Override
        public AutoCloseable registerObjectParser(final int objectClass, final int objectType, final ObjectParser parser) {
-               Preconditions.checkArgument(objectClass >= 0 && objectClass <= 255);
+               Preconditions.checkArgument(objectClass >= 0 && objectClass <= Util.UNSIGNED_BYTE_MAX_VALUE);
                Preconditions.checkArgument(objectType >= 0 && objectType <= 15);
-               return handlers.registerParser(createKey(objectClass, objectType), parser);
+               return this.handlers.registerParser(createKey(objectClass, objectType), parser);
        }
 
-       @Override
        public AutoCloseable registerObjectSerializer(final Class<? extends Object> objClass, final ObjectSerializer serializer) {
-               return handlers.registerSerializer(objClass, serializer);
+               return this.handlers.registerSerializer(objClass, serializer);
        }
 
        @Override
        public ObjectParser getObjectParser(final int objectClass, final int objectType) {
-               return handlers.getParser(createKey(objectClass, objectType));
+               return this.handlers.getParser(createKey(objectClass, objectType));
        }
 
        @Override
        public ObjectSerializer getObjectSerializer(final Object object) {
-               return handlers.getSerializer(object.getImplementedInterface());
+               return this.handlers.getSerializer(object.getImplementedInterface());
        }
 }
similarity index 87%
rename from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleRROSubobjectHandlerFactory.java
rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleRROSubobjectHandlerRegistry.java
index 8252929a008ade4223205206a9f7c184b00c3d20..e96788e87de5b69cfdaaeda20f42c32e4b8a9aff 100644 (file)
@@ -5,34 +5,33 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.protocol.pcep.impl;
+package org.opendaylight.protocol.pcep.spi.pojo;
 
 import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Subobjects;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
 import com.google.common.base.Preconditions;
 
-public final class SimpleRROSubobjectHandlerFactory implements RROSubobjectHandlerRegistry {
+public final class SimpleRROSubobjectHandlerRegistry implements RROSubobjectHandlerRegistry {
        private final HandlerRegistry<DataContainer, RROSubobjectParser, RROSubobjectSerializer> handlers = new HandlerRegistry<>();
 
-       @Override
        public AutoCloseable registerSubobjectParser(final int subobjectType, final RROSubobjectParser parser) {
-               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
+               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
                return this.handlers.registerParser(subobjectType, parser);
        }
 
        @Override
        public RROSubobjectParser getSubobjectParser(final int subobjectType) {
-               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
+               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
                return this.handlers.getParser(subobjectType);
        }
 
-       @Override
        public AutoCloseable registerSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
                        final RROSubobjectSerializer serializer) {
                return this.handlers.registerSerializer(subobjectClass, serializer);
similarity index 75%
rename from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleTlvHandlerRegistry.java
rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleTlvHandlerRegistry.java
index 00de0bde21eeac68cc65fa87cf52a397055a1cc2..94f00a97647c4acee1ed1df3a6b0531e15fd7d36 100644 (file)
@@ -5,12 +5,13 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.protocol.pcep.impl;
+package org.opendaylight.protocol.pcep.spi.pojo;
 
 import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
@@ -22,24 +23,22 @@ import com.google.common.base.Preconditions;
 public final class SimpleTlvHandlerRegistry implements TlvHandlerRegistry {
        private final HandlerRegistry<DataContainer, TlvParser, TlvSerializer> handlers = new HandlerRegistry<>();
 
-       @Override
        public AutoCloseable registerTlvParser(final int tlvType, final TlvParser parser) {
-               Preconditions.checkArgument(tlvType >= 0 && tlvType < 65535);
-               return handlers.registerParser(tlvType, parser);
+               Preconditions.checkArgument(tlvType >= 0 && tlvType < Util.UNSIGNED_SHORT_MAX_VALUE);
+               return this.handlers.registerParser(tlvType, parser);
        }
 
-       @Override
-       public TlvParser getTlvParser(final int tlvType) {
-               return handlers.getParser(tlvType);
+       public AutoCloseable registerTlvSerializer(final Class<? extends Tlv> tlvClass, final TlvSerializer serializer) {
+               return this.handlers.registerSerializer(tlvClass, serializer);
        }
 
        @Override
-       public AutoCloseable registerTlvSerializer(final Class<? extends Tlv> tlvClass, final TlvSerializer serializer) {
-               return handlers.registerSerializer(tlvClass, serializer);
+       public TlvParser getTlvParser(final int tlvType) {
+               return this.handlers.getParser(tlvType);
        }
 
        @Override
        public TlvSerializer getTlvSerializer(final Tlv tlv) {
-               return handlers.getSerializer(tlv.getImplementedInterface());
+               return this.handlers.getSerializer(tlv.getImplementedInterface());
        }
 }
similarity index 87%
rename from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/SimpleXROSubobjectHandlerFactory.java
rename to pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleXROSubobjectHandlerRegistry.java
index 9ef5b9dd9f283b379f567fc12880abc98d661855..030adfcb64d1c8607d40060ffcaa3f3b94209af5 100644 (file)
@@ -5,39 +5,38 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.protocol.pcep.impl;
+package org.opendaylight.protocol.pcep.spi.pojo;
 
 import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
 import com.google.common.base.Preconditions;
 
-public final class SimpleXROSubobjectHandlerFactory implements XROSubobjectHandlerRegistry {
+public final class SimpleXROSubobjectHandlerRegistry implements XROSubobjectHandlerRegistry {
        private final HandlerRegistry<DataContainer, XROSubobjectParser, XROSubobjectSerializer> handlers = new HandlerRegistry<>();
 
-       @Override
        public AutoCloseable registerSubobjectParser(final int subobjectType, final XROSubobjectParser parser) {
-               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
+               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
                return this.handlers.registerParser(subobjectType, parser);
        }
 
-       @Override
-       public XROSubobjectParser getSubobjectParser(final int subobjectType) {
-               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
-               return this.handlers.getParser(subobjectType);
-       }
-
-       @Override
        public AutoCloseable registerSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
                        final XROSubobjectSerializer serializer) {
                return this.handlers.registerSerializer(subobjectClass, serializer);
        }
 
+       @Override
+       public XROSubobjectParser getSubobjectParser(final int subobjectType) {
+               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
+               return this.handlers.getParser(subobjectType);
+       }
+
        @Override
        public XROSubobjectSerializer getSubobjectSerializer(final Subobjects subobject) {
                return this.handlers.getSerializer(subobject.getImplementedInterface());
index 006d336288677fa85da92c70aaeb885456ab1daa..dbce743996e38f12206f7e6bf6d79f3bed7e00e4 100644 (file)
@@ -16,10 +16,15 @@ import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
 import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
 import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
 import org.opendaylight.protocol.pcep.impl.PCEPSessionProposalFactoryImpl;
+import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class Main {
 
+       private static final Logger logger = LoggerFactory.getLogger(Main.class);
+
        public static String usage = "DESCRIPTION:\n" + "\tCreates a server with given parameters. As long as it runs, it accepts connections "
                        + "from PCCs.\n" + "USAGE:\n" + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
                        + "\t\tFormat: x.x.x.x:y where y is port number.\n\n" +
@@ -57,6 +62,10 @@ public class Main {
 
                        "With no parameters, this help is printed.";
 
+       private Main() {
+
+       }
+
        public static void main(final String[] args) throws Exception {
                if (args.length == 0 || args.length == 1 && args[0].equalsIgnoreCase("--help")) {
                        System.out.println(Main.usage);
@@ -102,12 +111,12 @@ public class Main {
                                        i++;
                                }
                        } else {
-                               System.out.println("WARNING: Unrecognized argument: " + args[i]);
+                               logger.warn("WARNING: Unrecognized argument: {}", args[i]);
                        }
                        i++;
                }
                if (deadTimerValue != 0 && deadTimerValue != keepAliveValue * 4) {
-                       System.out.println("WARNING: The value of DeadTimer should be 4 times the value of KeepAlive.");
+                       logger.warn("WARNING: The value of DeadTimer should be 4 times the value of KeepAlive.");
                }
                if (deadTimerValue == 0) {
                        deadTimerValue = keepAliveValue * 4;
@@ -117,7 +126,7 @@ public class Main {
 
                final OpenObject prefs = spf.getSessionProposal(address, 0);
 
-               final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5));
+               final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(PCEPExtensionProviderContextImpl.getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5));
 
                dispatcher.createServer(address, new TestingSessionListenerFactory()).get();
        }
index 4e67547eaf4713dab82ecad9ca372b20daf19287..3897ee4d5ea28c53ec00054db5a5fe4385fd0d0e 100644 (file)
@@ -39,17 +39,6 @@ public class SimpleSessionListener implements PCEPSessionListener {
        @Override
        public void onSessionUp(final PCEPSession session) {
                logger.debug("Session up.");
-               // final List<ExplicitRouteSubobject> subs = new ArrayList<ExplicitRouteSubobject>();
-               // subs.add(new EROIPPrefixSubobject<Prefix<?>>(new IPv4Prefix(new IPv4Address(new byte[] { 10, 1, 1, 2 }), 32),
-               // false));
-               // subs.add(new EROIPPrefixSubobject<Prefix<?>>(new IPv4Prefix(new IPv4Address(new byte[] { 2, 2, 2, 2 }), 32),
-               // false));
-               // final CompositeInstantiationObject cpo = new CompositeInstantiationObject(new
-               // PCEPEndPointsObject<IPv4Address>(IPv4.FAMILY.addressForBytes(new byte[] {
-               // 1, 1, 1, 1 }), IPv4.FAMILY.addressForBytes(new byte[] { 2, 2, 2, 2 })), new PCEPLspaObject(0, 0, 0, (short)
-               // 0, (short) 0, false, false, false, false), new PCEPExplicitRouteObject(subs, false), null, null);
-               //
-               // session.sendMessage(new PCCreateMessage(Lists.newArrayList(cpo)));
        }
 
        @Override
index 1e60189650575a281c4d7c1c121a7374764565b1..f08a295dffcb2313bda29a7e665b36c59ba771a3 100644 (file)
@@ -39,14 +39,12 @@ public class TestingSessionListener implements PCEPSessionListener {
        public void onSessionUp(final PCEPSession session) {
                logger.debug("Session up.");
                this.up = true;
-               // this.notifyAll();
        }
 
        @Override
        public void onSessionDown(final PCEPSession session, final Exception e) {
                logger.debug("Session down. Cause : {} or {}", e);
                this.up = false;
-               // this.notifyAll();
        }
 
        @Override
index a5324f860e6325b4ac1e38c8d7650f779d8928f7..6934e98d3171869d9d23422ae2120899e0894e77 100644 (file)
@@ -28,7 +28,7 @@ import org.opendaylight.protocol.pcep.PCEPSessionListener;
 import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
 import org.opendaylight.protocol.pcep.impl.PCEPHandlerFactory;
 import org.opendaylight.protocol.pcep.impl.PCEPSessionImpl;
-import org.opendaylight.protocol.pcep.impl.SingletonPCEPProviderContext;
+import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.open.message.OpenBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.TlvsBuilder;
@@ -67,7 +67,7 @@ public class PCCMock<M, S extends ProtocolSession<M>, L extends SessionListener<
                                (short) 30).setDeadTimer((short) 120).setSessionId((short) 0).setTlvs(builder.build()).build(), 0);
 
                final PCCMock<Message, PCEPSessionImpl, PCEPSessionListener> pcc = new PCCMock<>(snf,
-                               new PCEPHandlerFactory(SingletonPCEPProviderContext.getInstance().getMessageHandlerRegistry()),
+                               new PCEPHandlerFactory(PCEPExtensionProviderContextImpl.getSingletonInstance().getMessageHandlerRegistry()),
                                new DefaultPromise<PCEPSessionImpl>(GlobalEventExecutor.INSTANCE));
 
                pcc.createClient(new InetSocketAddress("127.0.0.3", 12345), new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 2000),
diff --git a/pom.xml b/pom.xml
index 6bef8f9d83cbf5d70b6669ba600d4024996e9519..4c1843d4b30cb4df033ac9f3357af234132ac2cc 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
                <maven.jar.version>2.4</maven.jar.version>
                <maven.shade.version>2.1</maven.shade.version>
                <mockito.version>1.9.5</mockito.version>
-               <netty.version>4.0.9.Final</netty.version>
+               <netty.version>4.0.10.Final</netty.version>
                <nexusproxy>http://nexus.opendaylight.org/content</nexusproxy>
                <slf4j.version>1.7.2</slf4j.version>
                <surefire.version>2.15</surefire.version>
index 02d26651cedf98a3fed998e811930a0bae1cddcb..21fca87d074dda3515f26f35f52d123dfc7c6be9 100644 (file)
@@ -176,6 +176,7 @@ module programming {
                        "The specified instruction is in process of being
                        executed and cannot be cancelled. Wait for the
                        execution process to complete.";
+               base cancel-failure;
        }
 
        rpc cancel-instruction {
@@ -206,11 +207,28 @@ module programming {
                        "Instruction ID clashes with an instruction with an
                        already-queued instruction. Assign a new identifier
                        or wait for the enqueued instruction to complete.";
+               base submit-failure;
        }
 
        identity too-many-instructions {
                description
                        "Instruction queue size exceeded.";
+               base submit-failure;
+       }
+
+       identity unknown-precondition-id {
+               description
+                       "One of the instruction IDs specified in the
+                       precondition list is unknown.";
+               base submit-failure;
+       }
+
+       identity dead-on-arrival {
+               description
+                       "The instruction was submitted after its deadline has
+                       passed, or one of its dependencies resolved as
+                       non-sunccessful.";
+               base submit-failure;
        }
 
        identity instruction-type {
@@ -250,14 +268,46 @@ module programming {
                output {
                        choice result {
                                case failure {
-                                       leaf failure {
-                                               type identityref {
-                                                       base submit-failure;
+                                       container failure {
+                                               leaf type {
+                                                       type identityref {
+                                                               base submit-failure;
+                                                       }
+                                                       mandatory true;
+                                               }
+
+                                               leaf-list failed-preconditions {
+                                                       when "../type = dead-on-arrival";
+                                                       type instruction-id;
                                                }
                                        }
                                }
                        }
                }
        }
+
+       notification instruction-status-changed {
+               leaf id {
+                       description "Instruction identifier.";
+                       type instruction-id;
+                       mandatory true;
+               }
+
+               leaf status {
+                       description "New status of the instruction.";
+                       type instruction-status;
+                       mandatory true;
+               }
+
+               container details {
+                       description
+                               "More details about the instruction state.";
+
+                       leaf-list unmet-dependencies {
+                               when "../../status = cancelled";
+                               type instruction-id;
+                       }
+               }
+       }
 }
 
diff --git a/programming/impl/.project b/programming/impl/.project
new file mode 100644 (file)
index 0000000..6f8b269
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>programming-impl</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.m2e.core.maven2Builder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+               <nature>org.eclipse.m2e.core.maven2Nature</nature>
+       </natures>
+</projectDescription>
diff --git a/programming/impl/pom.xml b/programming/impl/pom.xml
new file mode 100644 (file)
index 0000000..3d2af93
--- /dev/null
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+       <parent>
+               <groupId>org.opendaylight.bgpcep</groupId>
+               <artifactId>programming-parent</artifactId>
+               <version>0.3.0-SNAPSHOT</version>
+       </parent>
+
+       <modelVersion>4.0.0</modelVersion>
+       <artifactId>programming-impl</artifactId>
+       <description>Programming Implementation</description>
+       <packaging>bundle</packaging>
+       <name>${project.artifactId}</name>
+       <prerequisites>
+               <maven>3.0.4</maven>
+       </prerequisites>
+
+       <dependencies>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>programming-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>programming-spi</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-binding-api</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+               <dependency>
+                       <groupId>com.google.code.findbugs</groupId>
+                       <artifactId>jsr305</artifactId>
+                       <version>2.0.1</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-api</artifactId>
+                       <version>${slf4j.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>com.google.guava</groupId>
+                       <artifactId>guava</artifactId>
+                       <version>${guava.version}</version>
+               </dependency>
+        <dependency>
+                       <groupId>io.netty</groupId>
+                       <artifactId>netty-common</artifactId>
+            <version>${netty.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>mockito-configuration</artifactId>
+            <version>${project.version}</version>
+                       <scope>test</scope>
+        </dependency>
+       </dependencies>
+
+       <build>
+        <plugins>
+           <plugin>
+               <groupId>org.apache.felix</groupId>
+               <artifactId>maven-bundle-plugin</artifactId>
+               <version>${maven.bundle.version}</version>
+               <extensions>true</extensions>
+               <configuration>
+                   <instructions>
+                       <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+                       <Private-Package>
+                           org.opendaylight.bgpcep.programming.impl,
+                       </Private-Package>
+                       <Bundle-Activator>org.opendaylight.bgpcep.programming.impl.BundleActivator</Bundle-Activator>
+                   </instructions>
+               </configuration>
+           </plugin>
+               </plugins>
+       </build>
+
+       <distributionManagement>
+               <site>
+                       <id>${project.artifactId}</id>
+                       <name>PROGRAMMING-IMPL Module site</name>
+                       <url>${basedir}/target/site/${project.artifactId}</url>
+               </site>
+       </distributionManagement>
+
+</project>
diff --git a/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/BundleActivator.java b/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/BundleActivator.java
new file mode 100644 (file)
index 0000000..c9c99d6
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.programming.impl;
+
+import io.netty.util.HashedWheelTimer;
+import io.netty.util.Timer;
+
+import java.util.concurrent.Executors;
+
+import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.ProgrammingService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+public final class BundleActivator extends AbstractBindingAwareProvider {
+       private static final Logger LOG = LoggerFactory.getLogger(BundleActivator.class);
+       private RpcRegistration<ProgrammingService> reg;
+       private final Timer timer = new HashedWheelTimer();
+
+       @Override
+       public void onSessionInitiated(final ProviderContext session) {
+               final NotificationProviderService notifs = Preconditions.checkNotNull(session.getSALService(NotificationProviderService.class));
+
+               reg = Preconditions.checkNotNull(session.addRpcImplementation(ProgrammingService.class,
+                               new ProgrammingServiceImpl(notifs, Executors.newSingleThreadExecutor(), timer, null)));
+       }
+}
diff --git a/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/Instruction.java b/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/Instruction.java
new file mode 100644 (file)
index 0000000..c72bd0a
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.programming.impl;
+
+import io.netty.util.Timeout;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.SubmitInstructionInput;
+
+import com.google.common.base.Preconditions;
+
+final class Instruction {
+       private final List<Instruction> dependants = new ArrayList<>();
+       private final List<Instruction> dependencies;
+       private final SubmitInstructionInput input;
+       private volatile InstructionStatus status = InstructionStatus.Queued;
+       private Timeout timeout;
+
+       Instruction(final SubmitInstructionInput input, final List<Instruction> dependencies, final Timeout timeout) {
+               this.input = Preconditions.checkNotNull(input);
+               this.dependencies = Preconditions.checkNotNull(dependencies);
+               this.timeout = Preconditions.checkNotNull(timeout);
+       }
+
+       SubmitInstructionInput getInput() {
+               return input;
+       }
+
+       InstructionStatus getStatus() {
+               return status;
+       }
+
+       void setStatus(final InstructionStatus status) {
+               this.status = status;
+       }
+
+       synchronized void cancel() {
+               if (timeout != null) {
+                       timeout.cancel();
+                       timeout = null;
+               }
+       }
+
+       synchronized void completed() {
+               timeout = null;
+       }
+
+       synchronized void addDependant(final Instruction d) {
+               dependants.add(d);
+       }
+
+       List<Instruction> getDependencies() {
+               return dependencies;
+       }
+
+       List<Instruction> getDependants() {
+               return dependants;
+       }
+}
\ No newline at end of file
diff --git a/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/ProgrammingServiceImpl.java b/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/ProgrammingServiceImpl.java
new file mode 100644 (file)
index 0000000..6d75bfc
--- /dev/null
@@ -0,0 +1,512 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.programming.impl;
+
+import io.netty.util.Timeout;
+import io.netty.util.Timer;
+import io.netty.util.TimerTask;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.FutureListener;
+
+import java.math.BigInteger;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+
+import javax.annotation.concurrent.GuardedBy;
+
+import org.opendaylight.bgpcep.programming.spi.ExecutionResult;
+import org.opendaylight.bgpcep.programming.spi.InstructionExecutor;
+import org.opendaylight.bgpcep.programming.spi.InstructionExecutorRegistry;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.CancelInstructionInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.CancelInstructionOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.CancelInstructionOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.DeadOnArrival;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.DuplicateInstructionId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionStatusChangedBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.ProgrammingService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.SubmitInstructionInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.SubmitInstructionOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.SubmitInstructionOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.UncancellableInstruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.UnknownInstruction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.UnknownPreconditionId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.instruction.status.changed.Details;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.instruction.status.changed.DetailsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.submit.instruction.output.result.failure.Failure;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.submit.instruction.output.result.failure.FailureBuilder;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Multimap;
+
+final class ProgrammingServiceImpl implements InstructionExecutorRegistry, ProgrammingService {
+       private static final Logger LOG = LoggerFactory.getLogger(ProgrammingServiceImpl.class);
+       private static final BigInteger MILLION = BigInteger.valueOf(1000000);
+
+       private final Map<InstructionId, Instruction> insns = new HashMap<>();
+
+       @GuardedBy("this")
+       private final Deque<Instruction> readyQueue = new ArrayDeque<>();
+
+       @GuardedBy("this")
+       private final Deque<Instruction> deferredQueue = new ArrayDeque<>();
+
+       @GuardedBy("this")
+       private final Multimap<Class<? extends InstructionType>, InstructionExecutor> executors = ArrayListMultimap.create();
+
+       private final NotificationProviderService notifs;
+       private final ExecutorService executor;
+       private final Timer timer;
+       private java.util.concurrent.Future<Void> thread;
+       private ExecutorService exec;
+
+       ProgrammingServiceImpl(final NotificationProviderService notifs, final ExecutorService executor,
+                       final Timer timer, final InstructionExecutorRegistry registry) {
+               this.notifs = Preconditions.checkNotNull(notifs);
+               this.executor = Preconditions.checkNotNull(executor);
+               this.timer = Preconditions.checkNotNull(timer);
+       }
+
+       @Override
+       public java.util.concurrent.Future<RpcResult<CancelInstructionOutput>> cancelInstruction(final CancelInstructionInput input) {
+               return executor.submit(new Callable<RpcResult<CancelInstructionOutput>>() {
+                       @Override
+                       public RpcResult<CancelInstructionOutput> call() {
+                               return realCancelInstruction(input);
+                       }
+               });
+       }
+
+       @Override
+       public java.util.concurrent.Future<RpcResult<SubmitInstructionOutput>> submitInstruction(final SubmitInstructionInput input) {
+               return executor.submit(new Callable<RpcResult<SubmitInstructionOutput>>() {
+                       @Override
+                       public RpcResult<SubmitInstructionOutput> call() {
+                               return realSubmitInstruction(input);
+                       }
+               });
+       }
+
+       @Override
+       public synchronized Registration<InstructionExecutor> registerInstructionExecutor(final Class<? extends InstructionType> type, final InstructionExecutor executor) {
+               Preconditions.checkNotNull(type);
+               Preconditions.checkNotNull(executor);
+
+               executors.put(type, executor);
+
+               /*
+                * Walk the deferred instructions back to front, check if they have
+                * the same type as the executor we have just registered. If they do,
+                * we move them to the head of readyQueue. This approach should retain
+                * submission order of the instructions.
+                */
+               final Iterator<Instruction> it = deferredQueue.descendingIterator();
+               while (it.hasNext()) {
+                       final Instruction i = it.next();
+                       if (type.equals(i.getInput().getType())) {
+                               it.remove();
+                               readyQueue.addFirst(i);
+                       }
+               }
+
+               notify();
+
+               final Object lock = this;
+               return new Registration<InstructionExecutor>() {
+                       @Override
+                       public void close() throws Exception {
+                               synchronized (lock) {
+                                       executors.remove(type, executor);
+                               }
+                       }
+
+                       @Override
+                       public InstructionExecutor getInstance() {
+                               return executor;
+                       }
+               };
+       }
+
+       private static final RpcResult<SubmitInstructionOutput> failedSubmit(final Failure f) {
+               return SuccessfulRpcResult.create(
+                               new SubmitInstructionOutputBuilder().setResult(
+                                               new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.submit.instruction.output.result.FailureBuilder()
+                                               .setFailure(f).build()).build());
+       }
+
+       private synchronized RpcResult<CancelInstructionOutput> realCancelInstruction(final CancelInstructionInput input)  {
+               final Instruction i = insns.get(input.getId());
+               if (i == null) {
+                       LOG.debug("Instruction {} not present in the graph", input.getId());
+
+                       final CancelInstructionOutput out = new CancelInstructionOutputBuilder().setFailure(UnknownInstruction.class).build();
+                       return SuccessfulRpcResult.create(out);
+               }
+
+               switch (i.getStatus()) {
+               case Cancelled:
+               case Executing:
+               case Failed:
+               case Successful:
+               case Unknown:
+                       LOG.debug("Instruction {} can no longer be cancelled due to status {}", input.getId());
+                       return SuccessfulRpcResult.create(
+                                       new CancelInstructionOutputBuilder().setFailure(UncancellableInstruction.class).build());
+               case Queued:
+               case Scheduled:
+                       break;
+               }
+
+               cancelInstruction(i, null);
+               return SuccessfulRpcResult.create(new CancelInstructionOutputBuilder().build());
+       }
+
+       private synchronized RpcResult<SubmitInstructionOutput> realSubmitInstruction(final SubmitInstructionInput input) {
+               final InstructionId id = input.getId();
+               if (insns.get(id) != null) {
+                       LOG.info("Instruction ID {} already present", id);
+                       return failedSubmit(new FailureBuilder().setType(DuplicateInstructionId.class).build());
+               }
+
+               // First things first: check the deadline
+               final BigInteger now = BigInteger.valueOf(System.currentTimeMillis()).multiply(MILLION);
+               final BigInteger left = input.getDeadline().getValue().subtract(now);
+
+               if (left.compareTo(BigInteger.ZERO) <= 0) {
+                       LOG.debug("Instruction {} deadline has already passed by {}ns", id, left);
+                       return failedSubmit(new FailureBuilder().setType(DeadOnArrival.class).build());
+               }
+
+               // Resolve dependencies
+               final List<Instruction> dependencies = new ArrayList<>();
+               for (final InstructionId pid : input.getPreconditions()) {
+                       final Instruction i = insns.get(pid);
+                       if (i == null) {
+                               LOG.info("Instruction {} depends on {}, which is not a known instruction", id, pid);
+                               return failedSubmit(new FailureBuilder().setType(UnknownPreconditionId.class).build());
+                       }
+
+                       dependencies.add(i);
+               }
+
+               // Check if all dependencies are non-failed
+               final List<InstructionId> unmet = new ArrayList<>();
+               for (final Instruction d : dependencies) {
+                       switch (d.getStatus()) {
+                       case Cancelled:
+                       case Failed:
+                       case Unknown:
+                               unmet.add(d.getInput().getId());
+                               break;
+                       case Executing:
+                       case Queued:
+                       case Scheduled:
+                       case Successful:
+                               break;
+                       }
+               }
+
+               /*
+                *  Some dependencies have failed, declare the request dead-on-arrival
+                *  and fail the operation.
+                */
+               if (!unmet.isEmpty()) {
+                       return failedSubmit(new FailureBuilder().setType(DeadOnArrival.class).setFailedPreconditions(unmet).build());
+               }
+
+               /*
+                * All pre-flight checks done are at this point, the following
+                * steps can only fail in catastrophic scenarios (OOM and the
+                * like).
+                */
+
+               // Schedule a timeout for the instruction
+               final Timeout t = timer.newTimeout(new TimerTask() {
+                       @Override
+                       public void run(final Timeout timeout) throws Exception {
+                               timeoutInstruction(input.getId());
+                       }
+               }, left.longValue(), TimeUnit.NANOSECONDS);
+
+               // Put it into the instruction list
+               final Instruction i = new Instruction(input, dependencies, t);
+               insns.put(id, i);
+
+               // Attach it into its dependencies
+               for (final Instruction d : dependencies) {
+                       d.addDependant(i);
+               }
+
+               /*
+                * All done. The next part is checking whether the instruction can
+                * run, which we can figure out after sending out the acknowledgement.
+                * This task should be ingress-weighed, so we reinsert it into the
+                * same execution service.
+                */
+               executor.submit(new Runnable() {
+                       @Override
+                       public void run() {
+                               tryScheduleInstruction(i);
+                       }
+               });
+
+               return SuccessfulRpcResult.create(new SubmitInstructionOutputBuilder().build());
+       }
+
+       @GuardedBy("this")
+       private void transitionInstruction(final Instruction v, final InstructionStatus status, final Details details) {
+               // Set the status
+               v.setStatus(status);
+
+               LOG.debug("Instruction {} transitioned to status {}", v.getInput().getId(), status);
+
+               // Send out a notification
+               notifs.publish(new InstructionStatusChangedBuilder().
+                               setId(v.getInput().getId()).setStatus(status).setDetails(details).build());
+       }
+
+       @GuardedBy("this")
+       private void cancelSingle(final Instruction i, final Details details) {
+               // Stop the timeout
+               i.cancel();
+
+               // Set the new status and send out notification
+               transitionInstruction(i, InstructionStatus.Cancelled, details);
+       }
+
+       @GuardedBy("this")
+       private void cancelDependants(final Instruction v) {
+               final Details details = new DetailsBuilder().setUnmetDependencies(ImmutableList.of(v.getInput().getId())).build();
+               for (final Instruction d : v.getDependants()) {
+                       switch (d.getStatus()) {
+                       case Cancelled:
+                       case Executing:
+                       case Failed:
+                       case Successful:
+                       case Unknown:
+                               break;
+                       case Queued:
+                       case Scheduled:
+                               cancelSingle(d, details);
+                               cancelDependants(d);
+                               break;
+                       }
+               }
+       }
+
+       private synchronized void cancelInstruction(final Instruction i, final Details details) {
+               deferredQueue.remove(i);
+               readyQueue.remove(i);
+               cancelSingle(i, details);
+               cancelDependants(i);
+       }
+
+       private synchronized void timeoutInstruction(final InstructionId id) {
+               final Instruction i = insns.get(id);
+               if (i == null) {
+                       LOG.warn("Instruction {} timed out, but not found in the queue", id);
+                       return;
+               }
+
+               switch (i.getStatus()) {
+               case Cancelled:
+               case Failed:
+               case Successful:
+                       LOG.debug("Instruction {} has status {}, timeout is a no-op", id, i.getStatus());
+                       break;
+               case Unknown:
+                       LOG.warn("Instruction {} has status {} before timeout completed", id, i.getStatus());
+                       break;
+               case Executing:
+                       LOG.info("Instruction {} timed out while executing, transitioning into Unknown", id);
+                       transitionInstruction(i, InstructionStatus.Unknown, null);
+                       cancelDependants(i);
+                       break;
+               case Queued:
+                       LOG.debug("Instruction {} timed out while Queued, cancelling it", id);
+
+                       final List<InstructionId> ids = new ArrayList<>();
+                       for (final Instruction d : i.getDependencies()) {
+                               if (d.getStatus() != InstructionStatus.Successful) {
+                                       ids.add(d.getInput().getId());
+                               }
+                       }
+
+                       cancelInstruction(i, new DetailsBuilder().setUnmetDependencies(ids).build());
+                       break;
+               case Scheduled:
+                       LOG.debug("Instruction {} timed out while Scheduled, cancelling it", i.getInput().getId());
+                       // FIXME: we should provide details why it timed out while scheduled
+                       cancelInstruction(i, null);
+                       break;
+               }
+       }
+
+       @GuardedBy("this")
+       private synchronized void tryScheduleInstruction(final Instruction i) {
+               Preconditions.checkState(i.getStatus().equals(InstructionStatus.Queued));
+
+               /*
+                * Check all vertices we depend on. We start off as ready for
+                * scheduling. If we encounter a cancelled/failed/unknown
+                * dependency, we cancel this instruction (and cascade). If we
+                * encounter an executing/queued/scheduled dependency, we hold
+                * of scheduling this one.
+                */
+               boolean ready = true;
+
+               final List<InstructionId> unmet = new ArrayList<>();
+               for (final Instruction d : i.getDependencies()) {
+                       switch (d.getStatus()) {
+                       case Cancelled:
+                       case Failed:
+                       case Unknown:
+                               unmet.add(d.getInput().getId());
+                               break;
+                       case Executing:
+                       case Queued:
+                       case Scheduled:
+                               ready = false;
+                               break;
+                       case Successful:
+                               // No-op
+                               break;
+                       }
+               }
+
+               if (!unmet.isEmpty()) {
+                       LOG.debug("Instruction {} was Queued, while some dependencies were resolved unsuccessfully, cancelling it", i.getInput().getId());
+                       cancelSingle(i, new DetailsBuilder().setUnmetDependencies(unmet).build());
+                       cancelDependants(i);
+                       return;
+               }
+
+               if (ready) {
+                       LOG.debug("Instruction {} is ready for execution", i.getInput().getId());
+                       transitionInstruction(i, InstructionStatus.Scheduled, null);
+
+                       readyQueue.add(i);
+                       notify();
+               }
+       }
+
+       private synchronized void executionFailed(final Instruction i, final Throwable cause) {
+               LOG.error("Instruction {} failed to execute", i.getInput().getId(), cause);
+               transitionInstruction(i, InstructionStatus.Failed, null);
+               cancelDependants(i);
+       }
+
+       private synchronized void executionSuccessful(final Instruction i, final ExecutionResult<?> res) {
+               i.cancel();
+
+               transitionInstruction(i, res.getStatus(), res.getDetails());
+
+               // Walk all dependants and try to schedule them
+               for (final Instruction d : i.getDependants()) {
+                       tryScheduleInstruction(d);
+               }
+       }
+
+       private synchronized void processQueues() throws InterruptedException {
+               /*
+                * This method is only ever interrupted by InterruptedException
+                */
+               while (true) {
+                       while (!readyQueue.isEmpty()) {
+                               final Instruction i = readyQueue.poll();
+
+                               Preconditions.checkState(i.getStatus().equals(InstructionStatus.Scheduled));
+                               final SubmitInstructionInput input = i.getInput();
+
+                               /*
+                                *  Walk all the registered executors for a particular type and
+                                *  offer them the chance to execute the instruction. The first
+                                *  one to accept it wins.
+                                */
+                               Future<ExecutionResult<?>> f = null;
+                               final Collection<InstructionExecutor> el = executors.get(input.getType());
+
+                               for (final InstructionExecutor e : el) {
+                                       f = e.offerInstruction(input.getArguments());
+                                       if (f != null) {
+                                               break;
+                                       }
+                               }
+
+                               // We did not find an executor -- defer the instruction
+                               if (f == null) {
+                                       deferredQueue.add(i);
+                                       continue;
+                               }
+
+                               transitionInstruction(i, InstructionStatus.Executing, null);
+                               f.addListener(new FutureListener<ExecutionResult<?>>() {
+                                       @Override
+                                       public void operationComplete(final Future<ExecutionResult<?>> future) {
+                                               if (future.isSuccess()) {
+                                                       executionSuccessful(i, future.getNow());
+                                               } else {
+                                                       executionFailed(i, future.cause());
+                                               }
+                                       }
+                               });
+                       }
+
+                       wait();
+               }
+       }
+
+       synchronized void start(final ThreadFactory threadFactory) {
+               Preconditions.checkState(exec == null, "Programming service dispatch thread already started");
+
+               exec = Executors.newSingleThreadExecutor(threadFactory);
+               thread = exec.submit(new Callable<Void>() {
+                       @Override
+                       public Void call() throws Exception {
+                               try {
+                                       processQueues();
+                               } catch (Exception ex) {
+                                       if (!(ex instanceof InterruptedException)) {
+                                               LOG.error("Programming service dispatch thread died", ex);
+                                       }
+                                       throw ex;
+                               }
+                               return null;
+                       }
+               });
+               exec.shutdown();
+       }
+
+       synchronized void stop(final long timeout, final TimeUnit unit) throws InterruptedException {
+               Preconditions.checkState(exec != null, "Programming service dispatch thread already stopped");
+
+               thread.cancel(true);
+               exec.awaitTermination(timeout, unit);
+               exec = null;
+       }
+}
diff --git a/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/SuccessfulRpcResult.java b/programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/SuccessfulRpcResult.java
new file mode 100644 (file)
index 0000000..d0d1f15
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.programming.impl;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
+final class SuccessfulRpcResult<T> implements RpcResult<T> {
+       private final T value;
+
+       private SuccessfulRpcResult(final T value) {
+               this.value = value;
+       }
+
+       static <T> SuccessfulRpcResult<T> create(final T value) {
+               return new SuccessfulRpcResult<T>(value);
+       }
+
+       @Override
+       public boolean isSuccessful() {
+               return true;
+       }
+
+       @Override
+       public T getResult() {
+               return value;
+       }
+
+       @Override
+       public Collection<RpcError> getErrors() {
+               return Collections.emptyList();
+       }
+}
\ No newline at end of file
index 76289fbb1c89d6e2a76eabdf7ac0e20f5dc11d35..2358267230925cc017bef36c308f62f7feb40191 100644 (file)
@@ -17,7 +17,9 @@
        <name>${project.artifactId}</name>
        
        <modules>
-               <module>api</module>
+        <module>api</module>
+        <module>impl</module>
+        <module>spi</module>
                <module>tunnel-api</module>
     </modules>
 </project>
diff --git a/programming/spi/.project b/programming/spi/.project
new file mode 100644 (file)
index 0000000..9c4845c
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>programming-spi</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.m2e.core.maven2Builder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+               <nature>org.eclipse.m2e.core.maven2Nature</nature>
+       </natures>
+</projectDescription>
diff --git a/programming/spi/pom.xml b/programming/spi/pom.xml
new file mode 100644 (file)
index 0000000..b923909
--- /dev/null
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+       <parent>
+               <groupId>org.opendaylight.bgpcep</groupId>
+               <artifactId>programming-parent</artifactId>
+               <version>0.3.0-SNAPSHOT</version>
+       </parent>
+
+       <modelVersion>4.0.0</modelVersion>
+       <artifactId>programming-spi</artifactId>
+       <description>Programming Service Provider Interface</description>
+       <packaging>bundle</packaging>
+       <name>${project.artifactId}</name>
+       <prerequisites>
+               <maven>3.0.4</maven>
+       </prerequisites>
+
+       <dependencies>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>programming-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+                       <groupId>io.netty</groupId>
+                       <artifactId>netty-common</artifactId>
+            <version>${netty.version}</version>
+               </dependency>
+
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-binding-api</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+               <dependency>
+                       <groupId>com.google.code.findbugs</groupId>
+                       <artifactId>jsr305</artifactId>
+                       <version>2.0.1</version>
+               </dependency>
+               <dependency>
+                       <groupId>com.google.guava</groupId>
+                       <artifactId>guava</artifactId>
+                       <version>${guava.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-api</artifactId>
+                       <version>${slf4j.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>com.google.guava</groupId>
+                       <artifactId>guava</artifactId>
+                       <version>${guava.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>mockito-configuration</artifactId>
+            <version>${project.version}</version>
+                       <scope>test</scope>
+        </dependency>
+       </dependencies>
+
+       <build>
+        <plugins>
+           <plugin>
+               <groupId>org.apache.felix</groupId>
+               <artifactId>maven-bundle-plugin</artifactId>
+               <version>${maven.bundle.version}</version>
+               <extensions>true</extensions>
+               <configuration>
+                   <instructions>
+                       <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+                       <Export-Package>
+                           org.opendaylight.bgpcep.programming.spi,
+                       </Export-Package>
+                   </instructions>
+               </configuration>
+           </plugin>
+               </plugins>
+       </build>
+
+       <distributionManagement>
+               <site>
+                       <id>${project.artifactId}</id>
+                       <name>PROGRAMMING-SPI Module site</name>
+                       <url>${basedir}/target/site/${project.artifactId}</url>
+               </site>
+       </distributionManagement>
+
+</project>
diff --git a/programming/spi/src/main/java/org/opendaylight/bgpcep/programming/spi/ExecutionResult.java b/programming/spi/src/main/java/org/opendaylight/bgpcep/programming/spi/ExecutionResult.java
new file mode 100644 (file)
index 0000000..63489f6
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.programming.spi;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.instruction.status.changed.Details;
+
+import com.google.common.base.Preconditions;
+
+public final class ExecutionResult<T extends Details> {
+       private final InstructionStatus status;
+       private final T details;
+
+       public ExecutionResult(final InstructionStatus status, final T details) {
+               Preconditions.checkArgument(
+                               status == InstructionStatus.Cancelled ||
+                               status == InstructionStatus.Failed ||
+                               status == InstructionStatus.Successful, "Illegal instruction status " + status);
+               Preconditions.checkArgument(status != InstructionStatus.Failed || details != null, "Failed status requires details");
+
+               this.status = status;
+               this.details = details;
+       }
+
+       public InstructionStatus getStatus() {
+               return status;
+       }
+
+       public T getDetails() {
+               return details;
+       }
+
+       @Override
+       public String toString() {
+               return "ExecutionResult [status=" + status + ", details=" + details
+                               + "]";
+       }
+}
diff --git a/programming/spi/src/main/java/org/opendaylight/bgpcep/programming/spi/InstructionExecutor.java b/programming/spi/src/main/java/org/opendaylight/bgpcep/programming/spi/InstructionExecutor.java
new file mode 100644 (file)
index 0000000..bf86cac
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.programming.spi;
+
+import io.netty.util.concurrent.Future;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.submit.instruction.input.Arguments;
+
+public interface InstructionExecutor {
+       Future<ExecutionResult<?>> offerInstruction(Arguments arguments);
+}
diff --git a/programming/spi/src/main/java/org/opendaylight/bgpcep/programming/spi/InstructionExecutorRegistry.java b/programming/spi/src/main/java/org/opendaylight/bgpcep/programming/spi/InstructionExecutorRegistry.java
new file mode 100644 (file)
index 0000000..0eea0cb
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.programming.spi;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.InstructionType;
+import org.opendaylight.yangtools.concepts.Registration;
+
+public interface InstructionExecutorRegistry {
+       Registration<InstructionExecutor> registerInstructionExecutor(Class<? extends InstructionType> type, InstructionExecutor executor);
+}
index c12a5d25cd0d7f19d6dab353af59e1956779c392..8c9361b765ee07f69a31f41d1d9a8349b09d0b8c 100644 (file)
@@ -3,7 +3,7 @@ module topology-tunnel-programming {
        namespace "urn:opendaylight:params:xml:ns:yang:topology:tunnel:programming";
        prefix "ttp";
 
-       import network-topology { prefix nt; revision-date 2013-07-12; }
+       import network-topology { prefix nt; revision-date 2013-10-21; }
        import topology-tunnel { prefix tt; revision-date 2013-08-19; }
        import programming { prefix pgm; revision-date 2013-09-30; }
 
index 3aa4a53d93f8faaf0c795d3c096bea9c4ad1b561..556ac16e47b33873212676639f67f3ce4671339d 100644 (file)
@@ -203,16 +203,6 @@ module rsvp {
                }
        }
 
-       grouping generalized-channel-set-label {
-               reference "https://tools.ietf.org/html/rfc6002#section-3.2";
-
-               uses c-label;
-
-               list subobjects {
-                       uses label-set;
-               }
-       }
-
        //marker
        grouping c-subobject {
        
@@ -254,9 +244,6 @@ module rsvp {
                        case waveband-switching-label {
                                uses waveband-switching-label;
                        }
-                       case generalized-channel-set-label {
-                               uses generalized-channel-set-label;
-                       }
                }
        }
 
@@ -366,13 +353,13 @@ module rsvp {
                description "Subobject of an Explicit Route Object";
                reference "https://tools.ietf.org/html/rfc4874#section-4.1";
                uses basic-explicit-route-subobjects {
-//                     augment "subobject-type" {
-//                             case exrs {
-//                                     container exrs {
-//                                             uses exclude-route-subobjects;
-//                                     }
-//                             }
-//                     }
+                       augment "subobject-type" {
+                               case exrs {
+                                       list exrs {
+                                               uses exclude-route-subobjects;
+                                       }
+                               }
+                       }
                }
        }
 }
index 9158ce69e751ca4b1f21aac52a22c17426e991d7..2e704bc50a8617e59f4a93bf23d0dd79346b95bd 100644 (file)
@@ -14,17 +14,16 @@ module isis-topology {
     }
 
     organization "TBD";
-
     contact "TBD";
     description "ISIS Topology model";
 
-    revision "2013-07-12" {
+    revision "2013-10-21" {
         description "Initial version";
     }
     typedef iso-system-id {
         description "ISO System ID. RFC 1237";
         type string {
-            pattern '[0-9a-fA-F]{4}(.[0-9a-fA-F]{4}){2}';
+            pattern '[0-9a-fA-F]{4}(\.[0-9a-fA-F]{4}){2}';
         }
     }
 
@@ -37,7 +36,7 @@ module isis-topology {
     typedef iso-net-id {
         description "ISO NET ID. RFC 1237";
         type string {
-            pattern '[0-9a-fA-F]{2}((.[0-9a-fA-F]{4}){6}*)';
+            pattern '[0-9a-fA-F]{2}((\.[0-9a-fA-F]{4}){6})';
         }
     }
 
@@ -52,8 +51,8 @@ module isis-topology {
     }
 
     augment "/nt:network-topology/nt:topology/igp:igp-topology-attributes" {
-        when "../../topology-types/isis";
-        container isis-topogloy-attributes {
+        when "../nt:topology-types/l3t:l3-unicast-igp-topology/isis";
+        container isis-topology-attributes {
             leaf net {
                 type iso-net-id;
             }
@@ -61,13 +60,13 @@ module isis-topology {
     }
 
     augment "/nt:network-topology/nt:topology/nt:node/igp:igp-node-attributes" {
-        when "../../../topology-types/isis";
+        when "../../nt:topology-types/l3t:l3-unicast-igp-topology/isis";
         uses isis-node-attributes;
-
     }
 
     augment "/nt:network-topology/nt:topology/nt:link/igp:igp-link-attributes" {
-        when "../../../../topology-types/isis";
+
+        when "../../nt:topology-types/l3t:l3-unicast-igp-topology/isis";
         uses isis-link-attributes;
     }
 
@@ -112,7 +111,6 @@ module isis-topology {
             }
             container ted {
                 uses ted:ted-node-attributes;
-
             }
         }
     }
index 6a9383ad5986b61bdaaeaa2d3ff772f3e97322d7..f01d43b0c7488a2913206573c96c10d465da7a0f 100644 (file)
@@ -14,7 +14,7 @@ module l3-unicast-igp-topology {
     organization "TBD";
     contact "TBD";
 
-    revision "2013-07-12" {
+    revision "2013-10-21" {
         description "Initial revision";
         reference "TBD";
     }
@@ -44,8 +44,8 @@ module l3-unicast-igp-topology {
         base "flag-identity";
     }
 
-
     typedef flag-type {
+
         type identityref {
             base "flag-identity";
         }
@@ -93,8 +93,8 @@ module l3-unicast-igp-topology {
                 type flag-type;
             }
             leaf-list router-id {
-
                 description "Router-id for the node";
+
                 type inet:ip-address;
             }
             list prefix {
@@ -142,8 +142,8 @@ module l3-unicast-igp-topology {
                 case unnumbered {
                     leaf unnumbered-id {
                     description "Unnumbered interface identifier";
-
                     type uint32;
+
                     }
                 }
             }
@@ -156,20 +156,20 @@ module l3-unicast-igp-topology {
     }
 
     augment "/nt:network-topology/nt:topology" {
-        when "topology-types/l3-unicast-igp-topology";
+        when "nt:topology-types/l3-unicast-igp-topology";
         uses igp-topology-attributes;
     }
 
     augment "/nt:network-topology/nt:topology/nt:node" {
-        when "../../topology-types/l3-unicast-igp-topology";
+        when "../nt:topology-types/l3-unicast-igp-topology";
         uses igp-node-attributes;
     }
     augment "/nt:network-topology/nt:topology/nt:link" {
-        when "../../topology-types/l3-unicast-igp-topology";
+        when "../nt:topology-types/l3-unicast-igp-topology";
         uses igp-link-attributes;
     }
     augment "/nt:network-topology/nt:topology/nt:node/nt:termination-point" {
-        when "../../topology-types/l3-unicast-igp-topology";
+        when "../../nt:topology-types/l3-unicast-igp-topology";
         uses igp-termination-point-attributes;
     }
 
@@ -191,8 +191,8 @@ module l3-unicast-igp-topology {
         }
         leaf topology-ref {
             type nt:topology-ref;
-
         }
+
         uses l3-unicast-igp-topology-type;
         uses nt:link-attributes;
         uses igp-link-attributes;
index 4f1855baef86f62a9e49d791c7ea2a2cf88db5aa..3c5ae5e7e385cd245fbf1a906cf809bb1c687e92 100644 (file)
@@ -21,7 +21,7 @@ module network-topology  {
         through a hierarchy of nodes, then connecting nodes at
         upper layers of the hierarchy.";
 
-    revision 2013-07-12 {
+    revision 2013-10-21 {
         description
             "Initial revision.";
     }
@@ -45,6 +45,7 @@ module network-topology  {
             and/or the type of topology that the node is a part of.";
     }
 
+
     typedef link-id {
         type inet:uri;
         description
@@ -80,7 +81,6 @@ module network-topology  {
             (This type should not be used for relative references.
             In such a case, a relative path should be used instead.)";
     }
-
     typedef topology-ref {
         type leafref {
             path "/network-topology/topology/topology-id";
@@ -94,6 +94,7 @@ module network-topology  {
             path "/network-topology/topology/node/node-id";
         }
         description
+
             "A type for an absolute reference to a node instance.
             (This type should not be used for relative references.
             In such a case, a relative path should be used instead.)";
@@ -129,7 +130,6 @@ module network-topology  {
                 in a supporting node.
                 This dependency information can be inferred from
                 the dependencies between links.  For this reason,
-
                 this item is not separately configurable.  Hence no
                 corresponding constraint needs to be articulated.
                 The corresponding information is simply provided by the
@@ -143,6 +143,7 @@ module network-topology  {
             The objects are provided in a grouping so that in addition to
             the datastore, the data can also be included in notifications
             as needed.";
+
         leaf node-id {
             type node-id;
             description
@@ -178,7 +179,6 @@ module network-topology  {
             type link-id;
             description
                 "The identifier of a link in the topology.
-
                 A link is specific to a topology to which it belongs.";
         }
         container source {
@@ -192,6 +192,7 @@ module network-topology  {
                 type tp-ref;
                 description
                     "Termination point within source node that terminates the link.";
+
             }
         }
         container destination {
@@ -220,14 +221,13 @@ module network-topology  {
         list topology {
             description "
                 This is the model of an abstract topology.
-                A topology contins nodes and links.
+                A topology contains nodes and links.
                 Each topology MUST be identified by
                 unique topology-id for reason that a network could contain many
                 topologies.
             ";
             key "topology-id";
             leaf topology-id {
-
                 type topology-id;
                 description "
                     It is presumed that a datastore will contain many topologies. To
@@ -235,6 +235,19 @@ module network-topology  {
                     topology identifiers.
                 ";
             }
+            leaf server-provided {
+                type boolean;
+                config false;
+                description "
+                    Indicates whether the topology is configurable by clients,
+                    or whether it is provided by the server.  This leaf is
+
+                    populated by the server implementing the model.
+                    It is set to false for topologies that are created by a client;
+                    it is set to true otherwise.  If it is set to true, any
+                    attempt to edit the topology MUST be rejected.
+                ";
+            }
             container topology-types {
                 description
                     "This container is used to identify the type, or types
@@ -276,8 +289,8 @@ module network-topology  {
                     // This constraint is meant to ensure that a referenced node is in fact
                     // a node in an underlay topology.
                 list termination-point {
-
                     description
+
                         "A termination point can terminate a link.
                         Depending on the type of topology, a termination point could,
                         for example, refer to a port or an interface.";
index eaacf6416ea510086340d3ff1cab81b2633c23f3..576cd8262b9c44f2b40831ce191536e6331a78b3 100644 (file)
@@ -1,8 +1,8 @@
 module ospf-topology {
     yang-version 1;
-    namespace "urn:ietf:params:xml:ns:yang:ospf-topology";
-
+    namespace "urn:TBD:params:xml:ns:yang:ospf-topology";
     // replace with IANA namespace when assigned
+
     prefix "ospf";
 
     import network-topology {
@@ -10,7 +10,7 @@ module ospf-topology {
     }
 
     import l3-unicast-igp-topology {
-        prefix "igp";
+        prefix "l3t";
     }
     import ietf-inet-types {
         prefix "inet";
@@ -23,7 +23,7 @@ module ospf-topology {
     contact "TBD";
     description "OSPF Topology model";
 
-    revision "2013-07-12" {
+    revision "2013-10-21" {
         description "Initial revision";
         reference "TBD";
     }
@@ -39,32 +39,31 @@ module ospf-topology {
         }
     }
 
-    augment "/nt:network-topology/nt:topology/nt:topology-types/igp:l3-unicast-igp-topology" {
+    augment "/nt:network-topology/nt:topology/nt:topology-types/l3t:l3-unicast-igp-topology" {
         uses ospf-topology-type;
     }
 
-    augment "/nt:network-topology/nt:topology/igp:igp-topology-attributes" {
-        when "../topology-types/ospf";
+    augment "/nt:network-topology/nt:topology/l3t:igp-topology-attributes" {
+        when "../nt:topology-types/l3t:l3-unicast-igp-topology/ospf";
         container ospf-topology-attributes {
             leaf area-id {
                 type area-id;
             }
         }
-
     }
 
-    augment "/nt:network-topology/nt:topology/nt:node/igp:igp-node-attributes" {
-        when "../../../topology-types/ospf";
+    augment "/nt:network-topology/nt:topology/nt:node/l3t:igp-node-attributes" {
+        when "../../nt:topology-types/l3t:l3-unicast-igp-topology/ospf";
         uses ospf-node-attributes;
     }
 
-    augment "/nt:network-topology/nt:topology/nt:link/igp:igp-link-attributes" {
-        when "../../../topology-types/ospf";
+    augment "/nt:network-topology/nt:topology/nt:link/l3t:igp-link-attributes" {
+        when "../../nt:topology-types/l3t:l3-unicast-igp-topology/ospf";
         uses ospf-link-attributes;
     }
 
-    augment "/nt:network-topology/nt:topology/nt:node/igp:igp-node-attributes/igp:prefix" {
-        when "../../../../topology-types/ospf";
+    augment "/nt:network-topology/nt:topology/nt:node/l3t:igp-node-attributes/l3t:prefix" {
+        when "../../../nt:topology-types/l3t:l3-unicast-igp-topology/ospf";
         uses ospf-prefix-attributes;
     }
 
@@ -99,9 +98,9 @@ module ospf-topology {
                 type uint32;
             }
             leaf-list multi-topology-id {
-
                 description "List of Multi-Topology Identifier up-to 128 (0-127). RFC 4915";
                 max-elements "128";
+
                 type uint8 {
                     range "0..127";
                 }
@@ -148,27 +147,27 @@ module ospf-topology {
         }
     } // ospf-link-attributes
 
-
     grouping ospf-prefix-attributes {
         container ospf-prefix-attributes {
+
             leaf forwarding-address {
-                when "../../igp:l3-unicast-igp-topology/igp:ospf/igp:router-type/igp:asbr";
+                when "../../l3t:l3-unicast-igp-topology/l3t:ospf/l3t:router-type/l3t:asbr";
                 type inet:ipv4-address;
             }
         }
     }
 
-    augment "/igp:igp-node-event" {
+    augment "/l3t:igp-node-event" {
         uses ospf-topology-type;
         uses ospf:ospf-node-attributes;
     }
 
-    augment "/igp:igp-link-event" {
+    augment "/l3t:igp-link-event" {
         uses ospf-topology-type;
         uses ospf:ospf-link-attributes;
     }
 
-    augment "/igp:igp-prefix-event" {
+    augment "/l3t:igp-prefix-event" {
         uses ospf-topology-type;
         uses ospf:ospf-prefix-attributes;
     }
index c3e54c6b227153a9e7800fb02fc3b096e27e6342..fc91e9eae99514a8d5599972c6fb779ce53f89fe 100644 (file)
@@ -11,11 +11,11 @@ module ted {
   organization "TBD";
   contact
     "TBD";
-
   description
     "Helper module to hold TED attributes for OSPF/ISIS";
 
-  revision 2013-07-12 {
+  revision 2013-10-21 {
+
     description
       "Initial revision";
   }
@@ -60,11 +60,11 @@ module ted {
       enum "LSC" {
         description
           "Lambda-Switch Capable (LSC)";
-
         value 150;
       }
       enum "FSC" {
         description
+
           "Fiber-Switch Capable (FSC)";
         value 200;
       }
@@ -109,11 +109,11 @@ module ted {
   }
 
   grouping ted-node-attributes {
-
     description
       "Identifier to uniquely identify a node in TED";
     reference "RFC 5305, RFC 6119: IPv6 Traffic Engineering in IS-IS/OSPF";
     leaf te-router-id-ipv4 {
+
       description
         "Globally unique IPv4 Traffic Engineering Router ID.";
       type inet:ipv4-address;
@@ -158,11 +158,11 @@ module ted {
     }
   }
 
-
   grouping ted-link-attributes {
     description
       "TED Attributes associated with the link.";
     reference "RFC 3630, RFC 3784: IS-IS / OSPF Traffic Engineering (TE)";
+
     leaf color {
       description
         "Administrative group or color of the link";
@@ -207,7 +207,6 @@ module ted {
     }
     container srlg {
       description
-
         "Shared Risk Link Group Attributes";
       uses srlg-attributes;
     }
@@ -256,12 +255,12 @@ module ted {
         description
           "Interface has packet-switching capabilities";
         leaf minimum-lsp-bandwidth {
-
           description
             "Minimum LSP Bandwidth. Units in bytes per second";
           type decimal64 {
             fraction-digits 2;
           }
+
         }
         leaf interface-mtu {
           description
diff --git a/topology/pcep-api/.project b/topology/pcep-api/.project
new file mode 100644 (file)
index 0000000..bfc89df
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>topology-pcep-api</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.m2e.core.maven2Builder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+               <nature>org.eclipse.m2e.core.maven2Nature</nature>
+       </natures>
+</projectDescription>
diff --git a/topology/pcep-api/pom.xml b/topology/pcep-api/pom.xml
new file mode 100644 (file)
index 0000000..9eceb85
--- /dev/null
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+       <parent>
+               <groupId>org.opendaylight.bgpcep</groupId>
+               <artifactId>topology-parent</artifactId>
+               <version>0.3.0-SNAPSHOT</version>
+       </parent>
+
+       <modelVersion>4.0.0</modelVersion>
+       <artifactId>topology-pcep-api</artifactId>
+       <description>Topology PCEP API</description>
+       <packaging>bundle</packaging>
+       <name>${project.artifactId}</name>
+       <prerequisites>
+               <maven>3.0.4</maven>
+       </prerequisites>
+
+       <dependencies>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>pcep-api</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>topology-api</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-binding</artifactId>
+            <version>${yang.binding.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-common</artifactId>
+            <version>${yangtools.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.opendaylight.controller.model</groupId>
+            <artifactId>model-inventory</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+       </dependencies>
+
+       <build>
+        <plugins>
+           <plugin>
+               <groupId>org.opendaylight.yangtools</groupId>
+               <artifactId>yang-maven-plugin</artifactId>
+               <version>${yangtools.version}</version>
+               <executions>
+                   <execution>
+                       <goals>
+                           <goal>generate-sources</goal>
+                       </goals>
+                       <configuration>
+                           <yangFilesRootDir>src/main/yang</yangFilesRootDir>
+                           <codeGenerators>
+                               <generator>
+                                   <codeGeneratorClass>
+                                       org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl
+                                   </codeGeneratorClass>
+                                   <outputBaseDir>
+                                       target/generated-sources/sal
+                                   </outputBaseDir>
+                               </generator>
+                           </codeGenerators>
+                           <inspectDependencies>true</inspectDependencies>
+                       </configuration>
+                   </execution>
+               </executions>
+               <dependencies>
+                   <dependency>
+                       <groupId>org.opendaylight.yangtools</groupId>
+                       <artifactId>maven-sal-api-gen-plugin</artifactId>
+                       <version>${yang.binding.version}</version>
+                       <type>jar</type>
+                   </dependency>
+               </dependencies>
+           </plugin>
+           <plugin>
+               <groupId>org.apache.felix</groupId>
+               <artifactId>maven-bundle-plugin</artifactId>
+               <version>${maven.bundle.version}</version>
+               <extensions>true</extensions>
+               <configuration>
+                   <instructions>
+                       <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+                       <Export-Package>
+                           org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.pcep.rev131024,
+                           org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024,
+                       </Export-Package>
+                   </instructions>
+               </configuration>
+           </plugin>
+               </plugins>
+       </build>
+
+       <distributionManagement>
+               <site>
+                       <id>${project.artifactId}</id>
+                       <name>TOPOLOGY-PCEP-API Module site</name>
+                       <url>${basedir}/target/site/${project.artifactId}</url>
+               </site>
+       </distributionManagement>
+
+</project>
diff --git a/topology/pcep-api/src/main/yang/inventory-pcep.yang b/topology/pcep-api/src/main/yang/inventory-pcep.yang
new file mode 100644 (file)
index 0000000..36150e6
--- /dev/null
@@ -0,0 +1,61 @@
+module inventory-pcep {
+       // vi: set et smarttab sw=4 tabstop=4:
+       yang-version 1;
+       namespace "urn:opendaylight:inventory:pcep";
+       prefix "inv-pcep";
+
+       import network-topology { prefix nt; revision-date 2013-10-21; }
+       import opendaylight-inventory { prefix inv; revision-date 2013-08-19; }
+       import pcep-types { prefix pcep; revision-date 2013-10-05; }
+
+       organization "Cisco Systems, Inc.";
+       contact "Robert Varga <rovarga@cisco.com>";
+
+       description
+               "This module contains the PCEP extensions to base inventory
+               model.
+
+               Copyright (c)2013 Cisco Systems, Inc. All rights reserved.";
+
+       revision "2013-10-24" {
+               description
+                       "Initial revision.";
+               reference "";
+       }
+
+       typedef pcc-sync-state {
+               type enumeration {
+                       enum initial-resync {
+                               description
+                                       "Initial state resynchronization is being performed.";
+                       }
+                       enum synchronized {
+                               description
+                                       "State synchronization has been achieved.";
+                       }
+               }
+       }
+
+       augment "/inv:nodes/inv:node" {
+               container path-computation-client {
+                       description
+                "PCC-related run-time information. This container is only
+                present when the node is connected through PCEP in a PCC
+                role.";
+
+                       container stateful-tlv {
+                               uses pcep:stateful-capability-tlv;
+                       }
+
+                       leaf state-sync {
+                               when "../stateful-tlv";
+                               type pcc-sync-state;
+                       }
+
+            leaf topology-node {
+                type nt:node-ref;
+            }
+               }
+       }
+}
+
diff --git a/topology/pcep-api/src/main/yang/network-topology-pcep.yang b/topology/pcep-api/src/main/yang/network-topology-pcep.yang
new file mode 100644 (file)
index 0000000..f870c72
--- /dev/null
@@ -0,0 +1,47 @@
+module network-topology-pcep {
+       // vi: set et smarttab sw=4 tabstop=4:
+       yang-version 1;
+       namespace "urn:opendaylight:params:xml:ns:yang:topology:pcep";
+       prefix "pn";
+
+       import network-topology { prefix nt; revision-date 2013-10-21; }
+       import pcep-types { prefix pcep; revision-date 2013-10-05; }
+
+       organization "Cisco Systems, Inc.";
+       contact "Robert Varga <rovarga@cisco.com>";
+
+       description
+               "This module contains the PCEP extensions to base topology model. It
+        exposes the LSPs for which a particular node is the head end.
+
+               Copyright (c)2013 Cisco Systems, Inc. All rights reserved.";
+
+       revision "2013-10-24" {
+               description
+                       "Initial revision.";
+               reference "";
+       }
+
+       grouping pcep-client-attributes {
+        description "Data present in a node which is a PCEP client (PCC).";
+
+        container pcc {
+            config false;
+
+            list lsps {
+                leaf name {
+                    type pcep:symbolic-path-name;
+                }
+                key name;
+
+                // FIXME: hide protocol-specific?
+                uses pcep:lsp-object;
+            }
+        }
+       }
+
+       augment "/nt:network-topology/nt:topology/nt:node" {
+               uses pcep-client-attributes;
+       }
+}
+
index c651e72c99dcbdb5b68bc0d34dcf7145f21d92aa..5cf79ba43f5d4704b0f53c1218e0d0064803ea8c 100644 (file)
        <name>${project.artifactId}</name>
        
        <modules>
-               <module>api</module>
+        <module>api</module>
+        <module>pcep-api</module>
+        <module>provider-bgp</module>
+        <module>provider-pcep</module>
                <module>tunnel-api</module>
-        <module>tunnel-pcep</module>
+        <module>tunnel-pcep-api</module>
+        <module>tunnel-provider-pcep</module>
         <module>segment-routing</module>
     </modules>
 </project>
diff --git a/topology/provider-bgp/.project b/topology/provider-bgp/.project
new file mode 100644 (file)
index 0000000..58f8f71
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>topology-provider-bgp</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.m2e.core.maven2Builder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+               <nature>org.eclipse.m2e.core.maven2Nature</nature>
+       </natures>
+</projectDescription>
diff --git a/topology/provider-bgp/pom.xml b/topology/provider-bgp/pom.xml
new file mode 100644 (file)
index 0000000..f56d630
--- /dev/null
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+       <parent>
+               <groupId>org.opendaylight.bgpcep</groupId>
+               <artifactId>topology-parent</artifactId>
+               <version>0.3.0-SNAPSHOT</version>
+       </parent>
+
+       <modelVersion>4.0.0</modelVersion>
+       <artifactId>topology-provider-bgp</artifactId>
+       <description>BGP Topology Provider</description>
+       <packaging>bundle</packaging>
+       <name>${project.artifactId}</name>
+       <prerequisites>
+               <maven>3.0.4</maven>
+       </prerequisites>
+
+       <dependencies>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>bgp-rib-api</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>bgp-linkstate</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>topology-api</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-binding-api</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-api</artifactId>
+                       <version>${slf4j.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>mockito-configuration</artifactId>
+            <version>${project.version}</version>
+                       <scope>test</scope>
+        </dependency>
+       </dependencies>
+
+       <build>
+        <plugins>
+           <plugin>
+               <groupId>org.apache.felix</groupId>
+               <artifactId>maven-bundle-plugin</artifactId>
+               <version>${maven.bundle.version}</version>
+               <extensions>true</extensions>
+               <configuration>
+                   <instructions>
+                       <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+                       <Export-Package>
+                           org.opendaylight.bgpcep.topology.provider.bgp
+                       </Export-Package>
+                       <Private-Package>
+                           org.opendaylight.bgpcep.topology.provider.bgp.impl
+                       </Private-Package>
+                       <Bundle-Activator>org.opendaylight.bgpcep.topology.provider.bgp.impl.Activator</Bundle-Activator>
+                   </instructions>
+               </configuration>
+           </plugin>
+               </plugins>
+       </build>
+
+       <distributionManagement>
+               <site>
+                       <id>${project.artifactId}</id>
+                       <name>TOPOLOGY-PROVIDER-BGP Module site</name>
+                       <url>${basedir}/target/site/${project.artifactId}</url>
+               </site>
+       </distributionManagement>
+
+</project>
diff --git a/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/LocRIBListener.java b/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/LocRIBListener.java
new file mode 100644 (file)
index 0000000..b5bc457
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.topology.provider.bgp;
+
+import java.util.EventListener;
+
+import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.DataModification;
+
+public interface LocRIBListener extends EventListener {
+       /**
+        * @param trans Modification transaction. The implementation must explicitly commit
+        *              it if it wishes to have its modifications propagated. The transaction
+        *              is not shared with any other entity and will be cleaned up by the
+        *              caller if it is not committed before this method returns.
+        * @param event Data change event
+        * @throws Exception throw it if you must. If you can handle it, please do so.
+        */
+       public void onLocRIBChange(DataModification<?, ?> trans, DataChangeEvent<?, ?> event) throws Exception;
+}
diff --git a/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/LocRIBListeners.java b/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/LocRIBListeners.java
new file mode 100644 (file)
index 0000000..cf8340b
--- /dev/null
@@ -0,0 +1,39 @@
+package org.opendaylight.bgpcep.topology.provider.bgp;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public final class LocRIBListeners {
+       public interface Subscribtion {
+               public Class<? extends AddressFamily> getAfi();
+               public Class<? extends SubsequentAddressFamily> getSafi();
+               public LocRIBListener getLocRIBListener();
+       }
+
+       private LocRIBListeners() {
+
+       }
+
+       public static ServiceRegistration<Subscribtion> subscribe(final BundleContext context,
+                       final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi, final LocRIBListener listener) {
+               return context.registerService(Subscribtion.class,
+                               new Subscribtion() {
+                       @Override
+                       public Class<? extends AddressFamily> getAfi() {
+                               return afi;
+                       }
+
+                       @Override
+                       public Class<? extends SubsequentAddressFamily> getSafi() {
+                               return safi;
+                       }
+
+                       @Override
+                       public LocRIBListener getLocRIBListener() {
+                               return listener;
+                       }
+               }, null);
+       }
+}
diff --git a/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/impl/Activator.java b/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/impl/Activator.java
new file mode 100644 (file)
index 0000000..77fe328
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.topology.provider.bgp.impl;
+
+import org.opendaylight.bgpcep.topology.provider.bgp.LocRIBListeners;
+import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+import com.google.common.base.Preconditions;
+
+public class Activator extends AbstractBindingAwareProvider {
+//     private ServiceRegistration<LocRIBListeners.Subscribtion> ipv4, ipv6, linkstate;
+       private BundleContext context;
+
+       @Override
+       public void onSessionInitiated(final ProviderContext session) {
+               final LocRIBListenerSubscriptionTracker reg = new LocRIBListenerSubscriptionTracker(context, session.getSALService(DataProviderService.class));
+               reg.open();
+
+//             ipv4 = LocRIBListeners.subscribe(context, Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv4ReachabilityTopologyBuilder());
+//             ipv6 = LocRIBListeners.subscribe(context, Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv6ReachabilityTopologyBuilder());
+//             linkstate = LocRIBListeners.subscribe(context, LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class, new LinkstateTopologyBuilder());
+       }
+
+       @Override
+       protected void startImpl(final BundleContext context) {
+               this.context = Preconditions.checkNotNull(context);
+       }
+}
diff --git a/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/impl/LocRIBListenerSubscriptionTracker.java b/topology/provider-bgp/src/main/java/org/opendaylight/bgpcep/topology/provider/bgp/impl/LocRIBListenerSubscriptionTracker.java
new file mode 100644 (file)
index 0000000..0deee45
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.topology.provider.bgp.impl;
+
+import org.opendaylight.bgpcep.topology.provider.bgp.LocRIBListener;
+import org.opendaylight.bgpcep.topology.provider.bgp.LocRIBListeners;
+import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.DataModification;
+import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.LocRib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+final class LocRIBListenerSubscriptionTracker extends ServiceTracker<LocRIBListeners.Subscribtion, ListenerRegistration<LocRIBListener>> {
+       private static final InstanceIdentifier<LocRib> locRIBPath = InstanceIdentifier.builder().node(LocRib.class).toInstance();
+       private static final Logger LOG = LoggerFactory.getLogger(LocRIBListenerSubscriptionTracker.class);
+       private final DataProviderService dps;
+
+       LocRIBListenerSubscriptionTracker(final BundleContext context, final DataProviderService dps) {
+               super(context, LocRIBListeners.Subscribtion.class, null);
+               this.dps = Preconditions.checkNotNull(dps);
+       }
+
+       @Override
+       public ListenerRegistration<LocRIBListener> addingService(final ServiceReference<LocRIBListeners.Subscribtion> reference) {
+               final LocRIBListeners.Subscribtion service = context.getService(reference);
+               if (service == null) {
+                       LOG.trace("Service for reference {} disappeared", reference);
+                       return null;
+               }
+
+               final InstanceIdentifier<Tables> path = InstanceIdentifier.builder(locRIBPath).
+                               node(Tables.class, new TablesKey(service.getAfi(), service.getSafi())).toInstance();
+               final LocRIBListener listener = service.getLocRIBListener();
+
+               final DataChangeListener dcl = new DataChangeListener() {
+
+                       @Override
+                       public void onDataChanged(final DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+                               final DataModification<?, ?> trans = dps.beginTransaction();
+
+                               try {
+                                       listener.onLocRIBChange(trans, change);
+                               } catch (Exception e) {
+                                       LOG.info("Data change {} was not completely propagated to listener {}", change, listener, e);
+                               }
+
+                               // FIXME: abort the transaction if it's not committing
+                       }
+               };
+
+               final ListenerRegistration<DataChangeListener> reg = dps.registerDataChangeListener(path, dcl);
+
+               return new ListenerRegistration<LocRIBListener>() {
+                       @Override
+                       public void close() throws Exception {
+                               reg.close();
+                       }
+
+                       @Override
+                       public LocRIBListener getInstance() {
+                               return listener;
+                       }
+               };
+       }
+
+       @Override
+       public void removedService(final ServiceReference<LocRIBListeners.Subscribtion> reference, final ListenerRegistration<LocRIBListener> service) {
+               try {
+                       service.close();
+               } catch (Exception e) {
+                       LOG.error("Failed to unregister service {}", e);
+               }
+               context.ungetService(reference);
+       }
+}
diff --git a/topology/provider-pcep/.project b/topology/provider-pcep/.project
new file mode 100644 (file)
index 0000000..3670b5e
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>topology-provider-pcep</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.m2e.core.maven2Builder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+               <nature>org.eclipse.m2e.core.maven2Nature</nature>
+       </natures>
+</projectDescription>
diff --git a/topology/provider-pcep/pom.xml b/topology/provider-pcep/pom.xml
new file mode 100644 (file)
index 0000000..4c414c6
--- /dev/null
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+       <parent>
+               <groupId>org.opendaylight.bgpcep</groupId>
+               <artifactId>topology-parent</artifactId>
+               <version>0.3.0-SNAPSHOT</version>
+       </parent>
+
+       <modelVersion>4.0.0</modelVersion>
+       <artifactId>topology-provider-pcep</artifactId>
+       <description>PCEP Topology Provider</description>
+       <packaging>bundle</packaging>
+       <name>${project.artifactId}</name>
+       <prerequisites>
+               <maven>3.0.4</maven>
+       </prerequisites>
+
+       <dependencies>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>pcep-api</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>topology-api</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>topology-pcep-api</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-binding-api</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-api</artifactId>
+                       <version>${slf4j.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>mockito-configuration</artifactId>
+            <version>${project.version}</version>
+                       <scope>test</scope>
+        </dependency>
+
+        <!-- FIXME: integrate with config to get rid of this -->
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>pcep-impl</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>pcep-spi</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+       </dependencies>
+
+       <build>
+        <plugins>
+           <plugin>
+               <groupId>org.apache.felix</groupId>
+               <artifactId>maven-bundle-plugin</artifactId>
+               <version>${maven.bundle.version}</version>
+               <extensions>true</extensions>
+               <configuration>
+                   <instructions>
+                       <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+                       <Private-Package>
+                           org.opendaylight.bgpcep.topology.provider.pcep
+                       </Private-Package>
+                       <Bundle-Activator>org.opendaylight.bgpcep.topology.provider.pcep.BundleActivator</Bundle-Activator>
+                   </instructions>
+               </configuration>
+           </plugin>
+               </plugins>
+       </build>
+
+       <distributionManagement>
+               <site>
+                       <id>${project.artifactId}</id>
+                       <name>TOPOLOGY-PROVIDER-PCEP Module site</name>
+                       <url>${basedir}/target/site/${project.artifactId}</url>
+               </site>
+       </distributionManagement>
+
+</project>
diff --git a/topology/provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/provider/pcep/BundleActivator.java b/topology/provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/provider/pcep/BundleActivator.java
new file mode 100644 (file)
index 0000000..93e1e95
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.topology.provider.pcep;
+
+import io.netty.channel.ChannelFuture;
+import io.netty.util.HashedWheelTimer;
+
+import java.net.InetSocketAddress;
+import java.util.concurrent.ExecutionException;
+
+import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.protocol.pcep.PCEPDispatcher;
+import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
+import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
+import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
+import org.opendaylight.protocol.pcep.impl.PCEPSessionProposalFactoryImpl;
+import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+public final class BundleActivator extends AbstractBindingAwareProvider {
+       private static final Logger LOG = LoggerFactory.getLogger(BundleActivator.class);
+
+       @Override
+       public void onSessionInitiated(final ProviderContext session) {
+               final DataProviderService dps = Preconditions.checkNotNull(session.getSALService(DataProviderService.class));
+
+               // FIXME: integration with config subsystem should allow this to be injected as a service
+               final InetSocketAddress address = new InetSocketAddress("0.0.0.0", 4189);
+               final PCEPSessionProposalFactory spf = new PCEPSessionProposalFactoryImpl(30, 10, true, true, true, true, 0);
+               final OpenObject prefs = spf.getSessionProposal(address, 0);
+               final PCEPDispatcher dispatcher = new PCEPDispatcherImpl(PCEPExtensionProviderContextImpl.getSingletonInstance().getMessageHandlerRegistry(),
+                               new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5));
+               final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder().node(Topology.class).toInstance();
+
+               final TopologyExporter exp = new TopologyExporter(dispatcher, dps, topology);
+               final ChannelFuture s = exp.startServer(address);
+               try {
+                       s.get();
+               } catch (InterruptedException | ExecutionException e) {
+                       LOG.error("Failed to instantiate server", e);
+               }
+       }
+}
diff --git a/topology/provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/provider/pcep/ServerSessionManager.java b/topology/provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/provider/pcep/ServerSessionManager.java
new file mode 100644 (file)
index 0000000..66b567a
--- /dev/null
@@ -0,0 +1,332 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.topology.provider.pcep;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
+import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.protocol.framework.SessionListenerFactory;
+import org.opendaylight.protocol.pcep.PCEPSession;
+import org.opendaylight.protocol.pcep.PCEPSessionListener;
+import org.opendaylight.protocol.pcep.PCEPTerminationReason;
+import org.opendaylight.protocol.pcep.TerminationReason;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.pcep.rev131024.PccSyncState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.pcep.rev131024.nodes.node.PathComputationClientBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.pcep.rev131024.nodes.node.path.computation.client.StatefulTlvBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcerr;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcrptMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PlspId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.SymbolicPathName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Tlvs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.Stateful;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.pcrpt.message.Reports;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.pcrpt.message.reports.Lsp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PccBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.pcc.Lsps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.pcc.LspsKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ *
+ */
+final class ServerSessionManager implements SessionListenerFactory<PCEPSessionListener> {
+       private static String createNodeId(final InetAddress addr) {
+               return "pcc://" + addr.getHostAddress();
+       }
+
+       private final class SessionListener implements PCEPSessionListener {
+               private org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node inventoryNode(final DataModificationTransaction trans, final InetAddress address) {
+                       final String pccId = createNodeId(address);
+
+                       // FIXME: after 0.6 yangtools, this cast should not be needed
+                       final Nodes nodes = (Nodes)trans.readOperationalData(inventory);
+
+                       for (final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node n : nodes.getNode()) {
+                               LOG.debug("Matching inventory node {} to peer {}", n, address);
+                               if (n.getId().getValue().equals(pccId)) {
+                                       return n;
+                               }
+
+                               // FIXME: locate the node by its management IP address
+                       }
+
+                       /*
+                        * We failed to find a matching node. Let's create a dynamic one
+                        * to have a backer. Note that this node will be created in the
+                        * Runtime data space.
+                        */
+                       LOG.debug("Failed to find inventory node for peer {}, creating a new one at {}", address, pccId);
+
+                       final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId id =
+                                       new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId(pccId);
+                       final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey nk =
+                                       new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey(id);
+                       final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> nii =
+                                       InstanceIdentifier.builder(inventory).node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, nk).toInstance();
+                       final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node ret =
+                                       new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder().setId(id).setKey(nk).build();
+
+                       trans.putRuntimeData(nii, ret);
+                       ownsInventory = true;
+                       inventoryNodeId = nii;
+                       return ret;
+               }
+
+               final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node topologyNode(
+                               final DataModificationTransaction trans,
+                               final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node invNode) {
+                       // FIXME: after 0.6 yangtools, this cast should not be needed
+                       final Topology topo = (Topology)trans.readOperationalData(topology);
+
+                       for (final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node n : topo.getNode()) {
+                               LOG.debug("Matching topology node {} to inventory node {}", n, invNode);
+                               if (n.getNodeId().getValue().equals(invNode.getId().getValue())) {
+                                       return n;
+                               }
+                       }
+
+                       /*
+                        * We failed to find a matching node. Let's create a dynamic one
+                        * and note that we are the owner (so we clean it up afterwards).
+                        */
+                       final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId id =
+                                       new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId(invNode.getId().getValue());
+                       final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey nk =
+                                       new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey(id);
+                       final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> nti =
+                                       InstanceIdentifier.builder(topology).node(
+                                                       org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class, nk).toInstance();
+
+                       final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node ret =
+                                       new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder().
+                                       setKey(nk).setNodeId(id).build();
+
+                       trans.putRuntimeData(nti, ret);
+                       ownsTopology = true;
+                       topologyNodeId = nti;
+                       return ret;
+               }
+
+               @Override
+               public void onSessionUp(final PCEPSession session) {
+                       /*
+                        * The session went up. Look up the router in Inventory model,
+                        * create it if it is not there (marking that fact for later
+                        * deletion), and mark it as synchronizing. Also create it in
+                        * the topology model, with empty LSP list.
+                        */
+                       final InetAddress peerAddress = session.getRemoteAddress();
+                       final DataModificationTransaction trans = dataProvider.beginTransaction();
+
+                       final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node invNode = inventoryNode(trans, peerAddress);
+                       LOG.debug("Peer {} resolved to inventory node {}", peerAddress, invNode);
+
+                       final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node topoNode = topologyNode(trans, invNode);
+                       LOG.debug("Peer {} resolved to topology node {}", peerAddress, topoNode);
+
+                       // Our augmentation in the topology node
+                       final PccBuilder pb = new PccBuilder();
+
+                       final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1 topoAugment =
+                                       new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1Builder().setPcc(pb.build()).build();
+                       topologyAugmentId = InstanceIdentifier.builder(topologyNodeId).node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1.class).toInstance();
+                       trans.putRuntimeData(topologyAugmentId, topoAugment);
+
+                       // Our augmentation in the inventory node
+                       pccBuilder = new PathComputationClientBuilder();
+
+                       final Tlvs tlvs = session.getRemoteTlvs();
+                       final Stateful stateful = tlvs.getStateful();
+                       if (stateful != null) {
+                               // FIXME: rework once groupings can be used in builders
+                               pccBuilder.setStatefulTlv(new StatefulTlvBuilder().setFlags(tlvs.getStateful().getFlags()).build());
+                               pccBuilder.setStateSync(PccSyncState.InitialResync);
+                       }
+
+                       pccBuilder.setTopologyNode(topoNode.getNodeId());
+
+                       inventoryAugmentBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.pcep.rev131024.Node1Builder()
+                       .setPathComputationClient(pccBuilder.build());
+                       inventoryAugmentId = InstanceIdentifier.builder(inventoryNodeId).node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.pcep.rev131024.Node1.class).toInstance();
+                       trans.putRuntimeData(inventoryAugmentId, inventoryAugmentBuilder.build());
+
+                       // All set, commit the modifications
+                       final Future<RpcResult<TransactionStatus>> s = trans.commit();
+
+                       /*
+                        * FIXME: once this Future is listenable, attach to it so we can
+                        *        do cleanup if the commit fails. For now we force a commit.
+                        */
+                       try {
+                               s.get();
+                       } catch (InterruptedException | ExecutionException e) {
+                               LOG.error("Failed to update internal state for session {}, terminating it", session, e);
+                               session.close(TerminationReason.Unknown);
+                       }
+
+                       LOG.info("Session with {} attached to inventory node {} and topology node {}", session.getRemoteAddress(), invNode.getId(), topoNode.getNodeId());
+               }
+
+               private void tearDown(final PCEPSession session) {
+                       final DataModificationTransaction trans = dataProvider.beginTransaction();
+
+                       /*
+                        * The session went down. Undo all the Inventory and Topology
+                        * changes we have done.
+                        */
+                       trans.removeRuntimeData(inventoryAugmentId);
+                       if (ownsInventory) {
+                               trans.removeRuntimeData(inventoryNodeId);
+                       }
+                       trans.removeRuntimeData(topologyAugmentId);
+                       if (ownsTopology) {
+                               trans.removeRuntimeData(topologyNodeId);
+                       }
+
+                       /*
+                        * FIXME: once this Future is listenable, attach to it so we can
+                        *        do cleanup if the commit fails. For now we force a commit.
+                        */
+                       final Future<RpcResult<TransactionStatus>> s = trans.commit();
+                       try {
+                               s.get();
+                       } catch (InterruptedException | ExecutionException e) {
+                               LOG.error("Failed to cleanup internal state for session {}", session, e);
+                       }
+               }
+
+               @Override
+               public void onSessionDown(final PCEPSession session, final Exception e) {
+                       LOG.warn("Session {} went down unexpectedly", e);
+                       tearDown(session);
+               }
+
+               @Override
+               public void onSessionTerminated(final PCEPSession session, final PCEPTerminationReason reason) {
+                       LOG.info("Session {} terminated by peer with reason {}", session, reason);
+                       tearDown(session);
+               }
+
+               private InstanceIdentifier<Lsps> lspIdentifier(final SymbolicPathName name) {
+                       return InstanceIdentifier.builder(topologyAugmentId).
+                                       node(Lsps.class, new LspsKey(name.getPathName())).toInstance();
+               }
+
+               @Override
+               public void onMessage(final PCEPSession session, final Message message) {
+                       if (!(message instanceof PcrptMessage)) {
+                               LOG.info("Unhandled message {} on session {}", message, session);
+                               session.sendMessage(unhandledMessageError);
+                       }
+
+                       final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrpt.message.PcrptMessage rpt =
+                                       ((PcrptMessage)message).getPcrptMessage();
+
+                       final DataModificationTransaction trans = dataProvider.beginTransaction();
+
+                       for (final Reports r : rpt.getReports()) {
+                               final Lsp lsp = r.getLsp();
+
+                               if (lsp.isSync() && !synced) {
+                                       // Update synchronization flag
+                                       synced = true;
+                                       inventoryAugmentBuilder.setPathComputationClient(pccBuilder.setStateSync(PccSyncState.Synchronized).build());
+                                       trans.putRuntimeData(inventoryAugmentId, inventoryAugmentBuilder.build());
+                                       LOG.debug("Session {} achieved synchronized state", session);
+                               }
+
+                               final PlspId id = lsp.getPlspId();
+                               if (lsp.isRemove()) {
+                                       final SymbolicPathName name = lsps.remove(id);
+                                       if (name != null) {
+                                               trans.removeRuntimeData(lspIdentifier(name));
+                                       }
+
+                                       LOG.debug("LSP {} removed", lsp);
+                               } else {
+                                       if (!lsps.containsKey(id)) {
+                                               LOG.debug("PLSPID {} not known yet, looking for a symbolic name", id);
+
+                                               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.Tlvs tlvs =
+                                                               r.getLsp().getTlvs();
+                                               final SymbolicPathName name = tlvs.getSymbolicPathName();
+                                               if (name == null) {
+                                                       LOG.error("PLSPID {} seen for the first time, not reporting the LSP");
+                                                       // TODO: what should we do here?
+                                                       continue;
+                                               }
+                                       }
+
+                                       final SymbolicPathName name = lsps.get(id);
+                                       trans.putRuntimeData(lspIdentifier(name), lsp);
+
+                                       LOG.debug("LSP {} updated");
+                               }
+                       }
+
+                       /*
+                        * FIXME: once this Future is listenable, attach to it so we can
+                        *        do cleanup if the commit fails. For now we force a commit.
+                        */
+                       final Future<RpcResult<TransactionStatus>> s = trans.commit();
+                       try {
+                               s.get();
+                       } catch (InterruptedException | ExecutionException e) {
+                               LOG.error("Failed to update internal state for session {}, closing it", session, e);
+                               session.close(TerminationReason.Unknown);
+                       }
+               }
+       }
+
+       private static final Logger LOG = LoggerFactory.getLogger(ServerSessionManager.class);
+       private static final Pcerr unhandledMessageError = new PcerrBuilder().setPcerrMessage(
+                       new PcerrMessageBuilder().setErrorType(null).build()).build();
+       private final Map<PlspId, SymbolicPathName> lsps = new HashMap<>();
+       private final InstanceIdentifier<Nodes> inventory;
+       private final InstanceIdentifier<Topology> topology;
+       private final DataProviderService dataProvider;
+
+       private boolean ownsInventory = false;
+       private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> inventoryNodeId;
+       private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.pcep.rev131024.Node1> inventoryAugmentId;
+       private org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.pcep.rev131024.Node1Builder inventoryAugmentBuilder;
+       private PathComputationClientBuilder pccBuilder;
+       private boolean synced = false;
+
+       private boolean ownsTopology = false;
+       private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> topologyNodeId;
+       private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1> topologyAugmentId;
+
+       public ServerSessionManager(final DataProviderService dataProvider,
+                       final InstanceIdentifier<Nodes> inventory, final InstanceIdentifier<Topology> topology) {
+               this.dataProvider = Preconditions.checkNotNull(dataProvider);
+               this.inventory = Preconditions.checkNotNull(inventory);
+               this.topology = Preconditions.checkNotNull(topology);
+       }
+
+       @Override
+       public PCEPSessionListener getSessionListener() {
+               return new SessionListener();
+       }
+}
diff --git a/topology/provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/provider/pcep/TopologyExporter.java b/topology/provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/provider/pcep/TopologyExporter.java
new file mode 100644 (file)
index 0000000..d03c126
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.topology.provider.pcep;
+
+import io.netty.channel.ChannelFuture;
+
+import java.net.InetSocketAddress;
+
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.protocol.pcep.PCEPDispatcher;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import com.google.common.base.Preconditions;
+
+public final class TopologyExporter {
+       private static final InstanceIdentifier<Nodes> inventory = new InstanceIdentifier<Nodes>(Nodes.class);
+       private final PCEPDispatcher dispatcher;
+       private final DataProviderService dataProvider;
+       private final InstanceIdentifier<Topology> topology;
+
+       public TopologyExporter(final PCEPDispatcher dispatcher,
+                       final DataProviderService dataService,
+                       final InstanceIdentifier<Topology> topology) {
+               this.dispatcher = Preconditions.checkNotNull(dispatcher);
+               this.dataProvider = Preconditions.checkNotNull(dataService);
+               this.topology = Preconditions.checkNotNull(topology);
+       }
+
+       public ChannelFuture startServer(final InetSocketAddress address) {
+               return dispatcher.createServer(address, new ServerSessionManager(dataProvider, inventory, topology));
+       }
+}
index 347ede30876c4465d744093e8838d3acbcf07155..14dded54903cd7857bf0ab37d2c27167ace4f68d 100644 (file)
@@ -3,7 +3,7 @@ module network-topology-sr {
        namespace "urn:opendaylight:params:xml:ns:yang:topology:sr";
        prefix "sr";
 
-       import network-topology { prefix nt; revision-date 2013-07-12; }
+       import network-topology { prefix nt; revision-date 2013-10-21; }
 
        organization "Cisco Systems, Inc.";
        contact "Robert Varga <rovarga@cisco.com>";
index eb128cb8c3208a75d63db24ce8841b62e9615198..c9e8764a82a2d4c64b313959b6e7a89a7e28432c 100644 (file)
@@ -4,7 +4,7 @@ module topology-tunnel-sr {
        prefix "tun-sr";
 
        import network-topology-sr { prefix sr; revision-date 2013-08-19; }
-       import network-topology { prefix nt; revision-date 2013-07-12; }
+       import network-topology { prefix nt; revision-date 2013-10-21; }
        import topology-tunnel { prefix tt; revision-date 2013-08-19; }
        import topology-tunnel-p2p { prefix p2p; revision-date 2013-08-19; }
 
index 0206eaa79b79abfacd097b88b914813541437342..d35cf7e5499b55f8167b49adf7b90622ffde15dc 100644 (file)
@@ -3,7 +3,7 @@ module topology-tunnel-p2p {
        namespace "urn:opendaylight:params:xml:ns:yang:topology:tunnel:p2p";
        prefix "p2p";
 
-       import network-topology { prefix nt; revision-date 2013-07-12; }
+       import network-topology { prefix nt; revision-date 2013-10-21; }
        import topology-tunnel { prefix tt; revision-date 2013-08-19; }
 
        organization "Cisco Systems, Inc.";
index e8917f912d6874db1ac851925aed5b85d5f518fe..063afcd0ad75b514ee43e6f8cb3e8e7f9944fbf3 100644 (file)
@@ -4,7 +4,7 @@ module topology-tunnel {
        prefix "tt";
 
        import ietf-inet-types { prefix inet; revision-date 2010-09-24; }
-       import network-topology { prefix nt; revision-date 2013-07-12; }
+       import network-topology { prefix nt; revision-date 2013-10-21; }
 
        organization "Cisco Systems, Inc.";
        contact "Robert Varga <rovarga@cisco.com>";
similarity index 97%
rename from topology/tunnel-pcep/pom.xml
rename to topology/tunnel-pcep-api/pom.xml
index e9928580d56d1bba6da91aef2a1acf456b45ccfe..1ea57a525329f39b08d88febba4d2308ef78c953 100644 (file)
@@ -10,7 +10,7 @@
        </parent>
 
        <modelVersion>4.0.0</modelVersion>
-       <artifactId>topology-tunnel-pcep</artifactId>
+       <artifactId>topology-tunnel-pcep-api</artifactId>
        <description>Topology Tunnel PCEP binding</description>
        <packaging>bundle</packaging>
        <name>${project.artifactId}</name>
@@ -86,7 +86,7 @@
                    <instructions>
                        <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
                        <Export-Package>
-                           org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.rev130820,
+                           org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.rev130820.*,
                        </Export-Package>
                    </instructions>
                </configuration>
similarity index 82%
rename from topology/tunnel-pcep/src/main/yang/topology-tunnel-pcep.yang
rename to topology/tunnel-pcep-api/src/main/yang/topology-tunnel-pcep.yang
index 1df0b394f5108249d26dd7c0b6b46d003a2fb172..e17563e6e78979dd3ce0848b67b4419f74ff22a9 100644 (file)
@@ -1,10 +1,11 @@
 module topology-tunnel-pcep {
+       // vi: set et smarttab sw=4 tabstop=4:
        yang-version 1;
        namespace "urn:opendaylight:params:xml:ns:yang:topology:tunnel:pcep";
        prefix "pceptun";
 
        import ieee754 { prefix ieee754; revision-date 2013-08-19; }
-       import network-topology { prefix nt; revision-date 2013-07-12; }
+       import network-topology { prefix nt; revision-date 2013-10-21; }
        import pcep-types { prefix pcep; revision-date 2013-10-05; }
        import rsvp { prefix rsvp; revision-date 2013-08-20; }
        import topology-tunnel { prefix tt; revision-date 2013-08-19; }
@@ -14,8 +15,8 @@ module topology-tunnel-pcep {
        contact "Robert Varga <rovarga@cisco.com>";
 
        description
-               "This module contains the Segment Routing extensions to
-               base tunnel topology model.
+               "This module contains the PCEP extensions to base tunnel
+               topology model.
 
                Copyright (c)2013 Cisco Systems, Inc. All rights reserved.";
 
@@ -33,17 +34,6 @@ module topology-tunnel-pcep {
                reference "https://tools.ietf.org/html/draft-ietf-pce-stateful-pce-05#section-7.3";
        }
 
-       typedef operational-status {
-               type enumeration {
-                       enum down;
-                       enum up;
-                       enum active;
-                       enum going-down;
-                       enum going-up;
-               }
-               reference "https://tools.ietf.org/html/draft-ietf-pce-stateful-pce-05#section-7.3";
-       }
-
        grouping tunnel-pcep-type {
                container pcep-tunnel {
                        presence "indicates a link is a PCEP tunnel";
@@ -60,7 +50,7 @@ module topology-tunnel-pcep {
                }
 
                leaf operational-status {
-                       type operational-status;
+                       type pcep:operational-status;
                        config false;
                }
 
@@ -79,7 +69,7 @@ module topology-tunnel-pcep {
                }
 
                leaf operational-status {
-                       type operational-status;
+                       type pcep:operational-status;
                        config false;
                }
        }
diff --git a/topology/tunnel-provider-pcep/.project b/topology/tunnel-provider-pcep/.project
new file mode 100644 (file)
index 0000000..af7f519
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>topology-tunnel-provider-pcep</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.m2e.core.maven2Builder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+               <nature>org.eclipse.m2e.core.maven2Nature</nature>
+       </natures>
+</projectDescription>
diff --git a/topology/tunnel-provider-pcep/pom.xml b/topology/tunnel-provider-pcep/pom.xml
new file mode 100644 (file)
index 0000000..93b0696
--- /dev/null
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+       <parent>
+               <groupId>org.opendaylight.bgpcep</groupId>
+               <artifactId>topology-parent</artifactId>
+               <version>0.3.0-SNAPSHOT</version>
+       </parent>
+
+       <modelVersion>4.0.0</modelVersion>
+       <artifactId>topology-tunnel-provider-pcep</artifactId>
+       <description>PCEP Topology Provider</description>
+       <packaging>bundle</packaging>
+       <name>${project.artifactId}</name>
+       <prerequisites>
+               <maven>3.0.4</maven>
+       </prerequisites>
+
+       <dependencies>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>topology-api</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>topology-pcep-api</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>topology-tunnel-api</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>topology-tunnel-pcep-api</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-binding-api</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-api</artifactId>
+                       <version>${slf4j.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>mockito-configuration</artifactId>
+            <version>${project.version}</version>
+                       <scope>test</scope>
+        </dependency>
+       </dependencies>
+
+       <build>
+        <plugins>
+           <plugin>
+               <groupId>org.apache.felix</groupId>
+               <artifactId>maven-bundle-plugin</artifactId>
+               <version>${maven.bundle.version}</version>
+               <extensions>true</extensions>
+               <configuration>
+                   <instructions>
+                       <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+                       <Private-Package>
+                           org.opendaylight.bgpcep.topology.tunnel.provider.pcep
+                       </Private-Package>
+                       <Bundle-Activator>org.opendaylight.bgpcep.topology.tunnel.provider.pcep.BundleActivator</Bundle-Activator>
+                   </instructions>
+               </configuration>
+           </plugin>
+               </plugins>
+       </build>
+
+       <distributionManagement>
+               <site>
+                       <id>${project.artifactId}</id>
+                       <name>TOPOLOGY-PROVIDER-PCEP Module site</name>
+                       <url>${basedir}/target/site/${project.artifactId}</url>
+               </site>
+       </distributionManagement>
+
+</project>
diff --git a/topology/tunnel-provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/tunnel/provider/pcep/BundleActivator.java b/topology/tunnel-provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/tunnel/provider/pcep/BundleActivator.java
new file mode 100644 (file)
index 0000000..2a4a6fd
--- /dev/null
@@ -0,0 +1,22 @@
+package org.opendaylight.bgpcep.topology.tunnel.provider.pcep;
+
+import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+public final class BundleActivator extends AbstractBindingAwareProvider {
+       private static final Logger LOG = LoggerFactory.getLogger(BundleActivator.class);
+
+       @Override
+       public void onSessionInitiated(final ProviderContext session) {
+               final DataProviderService dps = Preconditions.checkNotNull(session.getSALService(DataProviderService.class));
+
+               // FIXME: migrate to config subsystem
+               final TunnelTopologyExporter tte = new TunnelTopologyExporter(dps, null);
+               tte.addTargetTopology(null);
+       }
+}
diff --git a/topology/tunnel-provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/tunnel/provider/pcep/NodeChangedListener.java b/topology/tunnel-provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/tunnel/provider/pcep/NodeChangedListener.java
new file mode 100644 (file)
index 0000000..3b2d409
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.topology.tunnel.provider.pcep;
+
+import java.util.Map.Entry;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
+import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
+import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
+import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.pcc.Lsps;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+final class NodeChangedListener implements DataChangeListener {
+       private static final Logger LOG = LoggerFactory.getLogger(NodeChangedListener.class);
+       private final InstanceIdentifier<Topology> target;
+       private final DataProviderService dataProvider;
+
+       NodeChangedListener(final DataProviderService dataProvider, final InstanceIdentifier<Topology> target) {
+               this.dataProvider = Preconditions.checkNotNull(dataProvider);
+               this.target = Preconditions.checkNotNull(target);
+       }
+
+       private void remove(final DataModificationTransaction trans, final InstanceIdentifier<?> id) {
+               if (Node.class.equals(id.getTargetType())) {
+                       // FIXME: implement this
+               } else if (Lsps.class.equals(id.getTargetType())) {
+                       // FIXME: implement this
+               } else {
+                       LOG.debug("Ignoring changed instance {}", id);
+               }
+       }
+
+       private void create(final DataModificationTransaction trans, final InstanceIdentifier<?> id, final DataObject obj) {
+               // FIXME: implement this
+       }
+
+       @Override
+       public void onDataChanged(final DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+               final DataModificationTransaction trans = dataProvider.beginTransaction();
+
+               for (final InstanceIdentifier<?> i : change.getRemovedOperationalData()) {
+                       remove(trans, i);
+               }
+
+               for (final Entry<InstanceIdentifier<?>, DataObject> e : change.getUpdatedOperationalData().entrySet()) {
+                       remove(trans, e.getKey());
+                       create(trans, e.getKey(), e.getValue());
+               }
+
+               for (final Entry<InstanceIdentifier<?>, DataObject> e : change.getCreatedOperationalData().entrySet()) {
+                       create(trans, e.getKey(), e.getValue());
+               }
+
+               final Future<RpcResult<TransactionStatus>> f = trans.commit();
+
+               // FIXME: change to a subscribtion once that is possible
+               try {
+                       f.get();
+               } catch (InterruptedException | ExecutionException e) {
+                       LOG.error("Failed to propagate a topology change, target topology became inconsistent", e);
+               }
+       }
+}
\ No newline at end of file
diff --git a/topology/tunnel-provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/tunnel/provider/pcep/TunnelTopologyExporter.java b/topology/tunnel-provider-pcep/src/main/java/org/opendaylight/bgpcep/topology/tunnel/provider/pcep/TunnelTopologyExporter.java
new file mode 100644 (file)
index 0000000..237d2a0
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.topology.tunnel.provider.pcep;
+
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import com.google.common.base.Preconditions;
+
+final class TunnelTopologyExporter {
+       private final DataProviderService dataProvider;
+       private final InstanceIdentifier<Node> srcTree;
+
+       TunnelTopologyExporter(final DataProviderService dataProvider, final InstanceIdentifier<Topology> sourceTopology) {
+               this.dataProvider = Preconditions.checkNotNull(dataProvider);
+               srcTree = Preconditions.checkNotNull(InstanceIdentifier.builder(sourceTopology).node(Node.class).toInstance());
+       }
+
+       ListenerRegistration<?> addTargetTopology(final InstanceIdentifier<Topology> tunnelTopology) {
+               return dataProvider.registerDataChangeListener(srcTree, new NodeChangedListener(dataProvider, tunnelTopology));
+       }
+}
diff --git a/util/src/main/java/org/opendaylight/protocol/util/DefaultingTypesafeContainer.java b/util/src/main/java/org/opendaylight/protocol/util/DefaultingTypesafeContainer.java
deleted file mode 100644 (file)
index 8110091..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.util;
-
-import com.google.common.base.Objects.ToStringHelper;
-
-/**
- * Extension of the TypesafeContainer which supports the notion of a default
- * key.
- *
- * @param <S> Supertype of all objects stored in this container
- */
-public class DefaultingTypesafeContainer<S> extends TypesafeContainer<S> {
-       private static final long serialVersionUID = 140170613440644179L;
-       private Class<? extends S> defaultKey = null;
-
-       /**
-        * Returns the default entry.
-        *
-        * @return Default entry, or null if no default was set
-        */
-       public S getDefaultEntry() {
-               if (defaultKey == null) {
-                       return null;
-               }
-               return defaultKey.cast(getEntry(defaultKey));
-       }
-
-       /**
-        * Sets or resets the default entry.
-        *
-        * @param entry Default entry value. Use null to reset the container
-        *        to no default entry.
-        */
-       public void setDefaultEntry(final S entry) {
-               if (defaultKey != null) {
-                       removeEntry(defaultKey);
-                       defaultKey = null;
-               }
-               if (entry != null) {
-                       /*
-                        * This is rather obvious: entry is required to be a subclass
-                        * of T. This implies that its class conforms to
-                        * Class<? extends T>. For some reason, the compiler is not
-                        * smart enough to know this.
-                        */
-                       @SuppressWarnings("unchecked")
-                       final Class<? extends S> c = (Class<? extends S>) entry.getClass();
-                       defaultKey = c;
-
-                       setEntry(defaultKey, entry);
-               }
-       }
-
-       @Override
-       protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
-               toStringHelper.add("defaultKey", this.defaultKey);
-               return super.addToStringAttributes(toStringHelper);
-       }
-
-       @Override
-       public int hashCode() {
-               return super.hashCode() * 7 + (defaultKey != null ? defaultKey.hashCode() : 0);
-       }
-
-       @Override
-       public boolean equals(Object obj) {
-               if (obj instanceof DefaultingTypesafeContainer == false) {
-                       return false;
-               }
-               if (obj == this) {
-                       return true;
-               }
-               if (super.equals(obj)==false) {
-                       return false;
-               }
-               Object thatDefaultKey = ((DefaultingTypesafeContainer<?>)obj).defaultKey;
-               if (defaultKey == thatDefaultKey) {
-            return true;
-        }
-        if ((defaultKey == null) != (thatDefaultKey == null)) {
-            return false;
-        }
-        return thatDefaultKey.equals(thatDefaultKey);
-       }
-
-}
diff --git a/util/src/main/java/org/opendaylight/protocol/util/Util.java b/util/src/main/java/org/opendaylight/protocol/util/Util.java
new file mode 100644 (file)
index 0000000..cd0f816
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.util;
+
+public class Util {
+
+       public static final int UNSIGNED_SHORT_MAX_VALUE = 65535;
+
+       public static final int UNSIGNED_BYTE_MAX_VALUE = 255;
+
+       public static final int BYTE_MAX_VALUE_BYTES = 0xFF;
+}