From e47c73b73d01011798a032632f22006119d5847e Mon Sep 17 00:00:00 2001 From: Dana Kutenicsova Date: Mon, 14 Oct 2013 11:29:23 +0000 Subject: [PATCH] Revert "BUG-47 : unfinished PCEP migration to generated DTOs." This reverts commit ce6991a8596c022555b003e128077a8f5468ec5e. Change-Id: Ia4ac01c0897a1bc4ab723a8d2e6b7dd5f84da56a Signed-off-by: Dana Kutenicsova --- .../protocol/concepts/Ipv6Util.java | 11 - .../protocol/pcep/PCEPCloseTermination.java | 12 +- .../protocol/pcep/PCEPErrorMapping.java | 178 -- .../protocol/pcep/PCEPObject.java | 95 + .../protocol/pcep/PCEPSession.java | 3 +- .../pcep/PCEPSessionProposalFactory.java | 14 +- .../opendaylight/protocol/pcep/PCEPTlv.java} | 16 +- .../protocol/pcep/TerminationReason.java | 45 - .../protocol/pcep/UnknownObject.java | 52 - .../AbstractExtendedTunnelIdentifier.java | 79 + .../AggregateBandwidthConsumptionMetric.java | 32 + .../concepts/CumulativeIGPCostMetric.java | 32 + .../pcep/concepts/CumulativeTECostMetric.java | 32 + .../concepts/ExtendedTunnelIdentifier.java | 29 + .../IPv4ExtendedTunnelIdentifier.java | 30 + .../IPv6ExtendedTunnelIdentifier.java | 30 + .../protocol/pcep/concepts/LSPIdentifier.java | 55 + .../pcep/concepts/LSPSymbolicName.java | 53 + .../concepts/MostLoadedLinkLoadMetric.java | 32 + .../pcep/concepts/P2MPHopCountMetric.java | 32 + .../protocol/pcep/concepts/P2MPIGPMetric.java | 32 + .../protocol/pcep/concepts/P2MPTEMetric.java | 32 + .../pcep/concepts/TunnelIdentifier.java | 46 + .../UnnumberedInterfaceIdentifier.java | 82 + .../pcep/message/PCCreateMessage.java | 112 ++ .../pcep/message/PCEPCloseMessage.java | 107 ++ .../pcep/message/PCEPErrorMessage.java | 229 +++ .../pcep/message/PCEPNotificationMessage.java | 106 ++ .../pcep/message/PCEPOpenMessage.java | 103 ++ .../pcep/message/PCEPReplyMessage.java | 152 ++ .../pcep/message/PCEPReportMessage.java | 106 ++ .../pcep/message/PCEPRequestMessage.java | 153 ++ .../message/PCEPUpdateRequestMessage.java | 106 ++ .../pcep/object/CompositeErrorObject.java | 196 +++ .../object/CompositeInstantiationObject.java | 254 +++ .../pcep/object/CompositeNotifyObject.java | 175 ++ .../pcep/object/CompositePathObject.java | 267 +++ .../pcep/object/CompositeReplySvecObject.java | 200 +++ .../pcep/object/CompositeRequestObject.java | 463 +++++ .../object/CompositeRequestSvecObject.java | 261 +++ .../pcep/object/CompositeResponseObject.java | 365 ++++ .../pcep/object/CompositeRptPathObject.java | 266 +++ .../object/CompositeStateReportObject.java | 163 ++ .../pcep/object/CompositeUpdPathObject.java | 227 +++ .../object/CompositeUpdateRequestObject.java | 163 ++ .../pcep/object/PCEPBandwidthObject.java | 78 + .../pcep/object/PCEPBranchNodeListObject.java | 35 + .../pcep/object/PCEPBranchNodeObject.java | 79 + .../pcep/object/PCEPClassTypeObject.java | 73 + .../protocol/pcep/object/PCEPCloseObject.java | 119 ++ .../protocol/pcep/object/PCEPEndPoints.java | 18 + .../pcep/object/PCEPEndPointsObject.java | 100 ++ .../protocol/pcep/object/PCEPErrorObject.java | 109 ++ .../pcep/object/PCEPExcludeRouteObject.java | 105 ++ .../PCEPExistingPathBandwidthObject.java | 27 + .../pcep/object/PCEPExplicitRouteObject.java | 81 + .../object/PCEPGlobalConstraintsObject.java | 183 ++ .../pcep/object/PCEPIncludeRouteObject.java | 82 + .../pcep/object/PCEPLoadBalancingObject.java | 91 + .../protocol/pcep/object/PCEPLspObject.java | 189 ++ .../protocol/pcep/object/PCEPLspaObject.java | 267 +++ .../pcep/object/PCEPMetricObject.java | 116 ++ .../pcep/object/PCEPNoPathObject.java | 132 ++ .../object/PCEPNonBranchNodeListObject.java | 35 + .../pcep/object/PCEPNotificationObject.java | 128 ++ .../object/PCEPObjectiveFunctionObject.java | 120 ++ .../protocol/pcep/object/PCEPOpenObject.java | 150 ++ .../pcep/object/PCEPP2MPEndPointsObject.java | 96 ++ .../pcep/object/PCEPReportedRouteObject.java | 80 + .../object/PCEPRequestParameterObject.java | 327 ++++ .../PCEPRequestedPathBandwidthObject.java | 27 + .../PCEPSecondaryExplicitRouteObject.java | 83 + .../PCEPSecondaryRecordRouteObject.java | 75 + .../protocol/pcep/object/PCEPSvecObject.java | 154 ++ .../PCEPUnreachedDestinationObject.java | 63 + .../EROUnnumberedInterfaceSubobject.java | 42 +- .../RROUnnumberedInterfaceSubobject.java | 146 +- .../XROUnnumberedInterfaceSubobject.java | 42 +- .../pcep/tlv/AbstractLSPIdentifiersTlv.java | 139 ++ .../protocol/pcep/tlv/ByPassTlv.java | 131 ++ .../pcep/tlv/IPv4LSPIdentifiersTlv.java | 42 + .../pcep/tlv/IPv6LSPIdentifiersTlv.java | 42 + .../protocol/pcep/tlv/LSPCleanupTlv.java | 79 + .../protocol/pcep/tlv/LSPIdentifiersTlv.java | 55 + .../pcep/tlv/LSPStateDBVersionTlv.java | 73 + .../protocol/pcep/tlv/LSPSymbolicNameTlv.java | 78 + .../protocol/pcep/tlv/LSPUpdateErrorTlv.java | 78 + .../protocol/pcep/tlv/NoPathVectorTlv.java | 172 ++ .../protocol/pcep/tlv/NodeIdentifierTlv.java | 84 + .../protocol/pcep/tlv/OFListTlv.java | 80 + .../protocol/pcep/tlv/OrderTlv.java | 96 ++ .../pcep/tlv/OverloadedDurationTlv.java | 73 + .../protocol/pcep/tlv/P2MPCapabilityTlv.java | 80 + .../pcep/tlv/PCEStatefulCapabilityTlv.java | 123 ++ .../protocol/pcep/tlv/RSVPErrorSpecTlv.java | 155 ++ .../protocol/pcep/tlv/ReqMissingTlv.java | 73 + pcep/api/src/main/yang/pcep-types.yang | 83 +- pcep/api/src/main/yang/rsvp.yang | 52 - .../protocol/pcep/api/APITest.java | 41 + .../protocol/pcep/api/ConceptsTest.java | 155 ++ .../protocol/pcep/api/ObjectsTest.java | 713 ++++++++ .../protocol/pcep/api/TlvsTest.java | 312 ++++ .../impl/AbstractPCEPSessionNegotiator.java | 48 +- .../impl/DefaultPCEPSessionNegotiator.java | 27 +- .../DefaultPCEPSessionNegotiatorFactory.java | 13 +- .../pcep/impl/HandlerRegistryImpl.java | 290 +--- .../pcep/impl/PCEPEROSubobjectParser.java | 279 +-- .../pcep/impl/PCEPMessageFactory.java | 17 +- .../pcep/impl/PCEPMessageValidator.java | 66 + .../protocol/pcep/impl/PCEPObjectFactory.java | 330 ++++ .../protocol/pcep/impl/PCEPObjectHeader.java | 174 ++ .../protocol/pcep/impl/PCEPObjectParser.java | 21 + .../protocol/pcep/impl/PCEPSessionImpl.java | 76 +- .../impl/PCEPSessionProposalFactoryImpl.java | 29 +- .../protocol/pcep/impl/PCEPTlvParser.java | 294 ++++ .../pcep/impl/RawPCEPMessageFactory.java | 113 +- .../opendaylight/protocol/pcep/impl/Util.java | 48 +- .../impl/message/PCCreateMessageParser.java | 43 +- .../message/PCCreateMessageValidator.java | 198 ++- .../impl/message/PCEPCloseMessageParser.java | 71 +- .../message/PCEPCloseMessageValidator.java | 47 + .../impl/message/PCEPErrorMessageParser.java | 177 +- .../message/PCEPErrorMessageValidator.java | 142 ++ .../message/PCEPKeepAliveMessageParser.java | 37 +- .../PCEPKeepAliveMessageValidator.java | 38 + .../PCEPNotificationMessageParser.java | 158 +- .../PCEPNotificationMessageValidator.java | 105 ++ .../impl/message/PCEPOpenMessageParser.java | 73 +- .../message/PCEPOpenMessageValidator.java | 46 + .../impl/message/PCEPReplyMessageParser.java | 38 +- .../message/PCEPReplyMessageValidator.java | 599 +++---- .../impl/message/PCEPReportMessageParser.java | 37 +- .../message/PCEPReportMessageValidator.java | 243 +-- .../message/PCEPRequestMessageParser.java | 38 +- .../message/PCEPRequestMessageValidator.java | 515 +++--- .../PCEPUpdateRequestMessageParser.java | 40 +- .../PCEPUpdateRequestMessageValidator.java | 209 +-- .../object/PCEPBandwidthObjectParser.java | 89 - .../PCEPBranchNodeListObjectParser.java | 44 + .../object/PCEPClassTypeObjectParser.java | 70 +- .../impl/object/PCEPCloseObjectParser.java | 130 +- .../object/PCEPEndPointsIPv4ObjectParser.java | 62 + .../object/PCEPEndPointsIPv6ObjectParser.java | 63 + .../object/PCEPEndPointsObjectParser.java | 134 -- .../impl/object/PCEPErrorObjectParser.java | 264 ++- .../object/PCEPExcludeRouteObjectParser.java | 113 +- ...PCEPExistingPathBandwidthObjectParser.java | 42 + .../object/PCEPExplicitRouteObjectParser.java | 101 +- .../PCEPGlobalConstraintsObjectParser.java | 79 +- .../object/PCEPIncludeRouteObjectParser.java | 66 +- .../object/PCEPLoadBalancingObjectParser.java | 64 +- .../pcep/impl/object/PCEPLspObjectParser.java | 80 +- .../impl/object/PCEPLspaObjectParser.java | 94 +- .../impl/object/PCEPMetricObjectParser.java | 207 ++- .../impl/object/PCEPNoPathObjectParser.java | 89 +- .../PCEPNonBranchNodeListObjectParser.java | 44 + .../object/PCEPNotificationObjectParser.java | 91 +- .../PCEPObjectiveFunctionObjectParser.java | 79 +- .../impl/object/PCEPOpenObjectParser.java | 132 +- .../PCEPP2MPEndPointsIPv4ObjectParser.java | 68 + .../PCEPP2MPEndPointsIPv6ObjectParser.java | 68 + .../impl/object/PCEPPathKeyObjectParser.java | 74 - .../object/PCEPReportedRouteObjectParser.java | 65 +- .../PCEPRequestParameterObjectParser.java | 127 +- ...CEPRequestedPathBandwidthObjectParser.java | 43 + ...CEPSecondaryExplicitRouteObjectParser.java | 43 + .../PCEPSecondaryRecordRouteObjectParser.java | 44 + .../pcep/impl/object/PCEPSrpObjectParser.java | 68 - .../impl/object/PCEPSvecObjectParser.java | 91 +- ...PUnreachedIPv4DestinationObjectParser.java | 54 + ...PUnreachedIPv6DestinationObjectParser.java | 54 + .../pcep/impl/object/UnknownObject.java | 27 + .../subobject/EROAsNumberSubobjectParser.java | 41 +- .../EROIPv4PrefixSubobjectParser.java | 61 + .../EROIPv6PrefixSubobjectParser.java | 62 + .../subobject/EROIpPrefixSubobjectParser.java | 84 - ...EROUnnumberedInterfaceSubobjectParser.java | 28 +- ...RROUnnumberedInterfaceSubobjectParser.java | 30 +- ...XROUnnumberedInterfaceSubobjectParser.java | 32 +- .../impl/tlv/LSPIdentifierIPv4TlvParser.java | 91 +- .../impl/tlv/LSPIdentifierIPv6TlvParser.java | 62 +- .../pcep/impl/tlv/LspDbVersionTlvParser.java | 46 - .../impl/tlv/LspSymbolicNameTlvParser.java | 41 - .../impl/tlv/LspUpdateErrorTlvParser.java | 44 - .../pcep/impl/tlv/NoPathVectorTlvParser.java | 47 +- .../pcep/impl/tlv/OFListTlvParser.java | 46 +- .../pcep/impl/tlv/OrderTlvParser.java | 56 - .../impl/tlv/OverloadedDurationTlvParser.java | 41 - .../tlv/PCEStatefulCapabilityTlvParser.java | 93 +- .../impl/tlv/PredundancyGroupTlvParser.java | 41 - .../impl/tlv/RSVPErrorSpecIPv4TlvParser.java | 78 + .../impl/tlv/RSVPErrorSpecIPv6TlvParser.java | 79 + .../pcep/impl/tlv/RSVPErrorSpecTlvParser.java | 145 -- .../pcep/impl/tlv/ReqMissingTlvParser.java | 45 - .../protocol/pcep/impl/CompositeTest.java | 438 +++++ .../pcep/impl/FiniteStateMachineTest.java | 118 +- .../protocol/pcep/impl/MockPCE.java | 11 +- .../pcep/impl/PCEPObjectParserTest.java | 1198 ++++++------- .../pcep/impl/PCEPSubobjectParserTest.java | 230 +-- .../protocol/pcep/impl/PCEPTlvParserTest.java | 390 +++-- .../protocol/pcep/impl/PCEPValidatorTest.java | 1531 ++++++++--------- .../pcep/impl/PCEPXROSubobjectParserTest.java | 10 +- .../protocol/pcep/impl/ServerSessionMock.java | 9 +- .../tlv/LSPStateDBVersionTlvParserTest.java | 68 + .../PCEStatefulCapabilityTlvParserTest.java | 72 + .../pcep/spi/AbstractMessageParser.java | 127 -- .../pcep/spi/AbstractObjectParser.java | 179 -- .../protocol/pcep/spi/HandlerRegistry.java | 7 - .../protocol/pcep/spi/MessageParser.java | 6 +- .../protocol/pcep/spi/ObjectHeaderImpl.java | 116 -- .../protocol/pcep/spi/ObjectParser.java | 8 +- .../protocol/pcep/spi/ObjectSerializer.java | 11 +- .../protocol/pcep/spi/RawMessage.java | 7 +- .../protocol/pcep/spi/SubobjectParser.java | 15 - .../protocol/pcep/spi/TlvParser.java | 5 +- .../protocol/pcep/spi/TlvSerializer.java | 8 +- .../protocol/pcep/testtool/Main.java | 4 +- .../pcep/testtool/SimpleSessionListener.java | 30 +- .../protocol/pcep/testtool/PCCMock.java | 15 +- 219 files changed, 18175 insertions(+), 7062 deletions(-) delete mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPErrorMapping.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPObject.java rename pcep/{spi/src/main/java/org/opendaylight/protocol/pcep/spi/SubobjectSerializer.java => api/src/main/java/org/opendaylight/protocol/pcep/PCEPTlv.java} (53%) delete mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/TerminationReason.java delete mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/UnknownObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/AbstractExtendedTunnelIdentifier.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/AggregateBandwidthConsumptionMetric.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/CumulativeIGPCostMetric.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/CumulativeTECostMetric.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/ExtendedTunnelIdentifier.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/IPv4ExtendedTunnelIdentifier.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/IPv6ExtendedTunnelIdentifier.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/LSPIdentifier.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/LSPSymbolicName.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/MostLoadedLinkLoadMetric.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/P2MPHopCountMetric.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/P2MPIGPMetric.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/P2MPTEMetric.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/TunnelIdentifier.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/UnnumberedInterfaceIdentifier.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCCreateMessage.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPCloseMessage.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPErrorMessage.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPNotificationMessage.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPOpenMessage.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPReplyMessage.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPReportMessage.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPRequestMessage.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPUpdateRequestMessage.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeErrorObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeInstantiationObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeNotifyObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositePathObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeReplySvecObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeRequestObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeRequestSvecObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeResponseObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeRptPathObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeStateReportObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeUpdPathObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeUpdateRequestObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPBandwidthObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPBranchNodeListObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPBranchNodeObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPClassTypeObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPCloseObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPEndPoints.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPEndPointsObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPErrorObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPExcludeRouteObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPExistingPathBandwidthObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPExplicitRouteObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPGlobalConstraintsObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPIncludeRouteObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPLoadBalancingObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPLspObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPLspaObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPMetricObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPNoPathObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPNonBranchNodeListObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPNotificationObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPObjectiveFunctionObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPOpenObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPP2MPEndPointsObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPReportedRouteObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPRequestParameterObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPRequestedPathBandwidthObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPSecondaryExplicitRouteObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPSecondaryRecordRouteObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPSvecObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPUnreachedDestinationObject.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/AbstractLSPIdentifiersTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/ByPassTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/IPv4LSPIdentifiersTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/IPv6LSPIdentifiersTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPCleanupTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPIdentifiersTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPStateDBVersionTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPSymbolicNameTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPUpdateErrorTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/NoPathVectorTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/NodeIdentifierTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/OFListTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/OrderTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/OverloadedDurationTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/P2MPCapabilityTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/PCEStatefulCapabilityTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/RSVPErrorSpecTlv.java create mode 100644 pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/ReqMissingTlv.java create mode 100644 pcep/api/src/test/java/org/opendaylight/protocol/pcep/api/ConceptsTest.java create mode 100644 pcep/api/src/test/java/org/opendaylight/protocol/pcep/api/ObjectsTest.java create mode 100644 pcep/api/src/test/java/org/opendaylight/protocol/pcep/api/TlvsTest.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageValidator.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPObjectFactory.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPObjectHeader.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPCloseMessageValidator.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPErrorMessageValidator.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPKeepAliveMessageValidator.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPNotificationMessageValidator.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPOpenMessageValidator.java delete mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPBandwidthObjectParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPBranchNodeListObjectParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsIPv4ObjectParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsIPv6ObjectParser.java delete mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsObjectParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExistingPathBandwidthObjectParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNonBranchNodeListObjectParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPP2MPEndPointsIPv4ObjectParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPP2MPEndPointsIPv6ObjectParser.java delete mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPPathKeyObjectParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPRequestedPathBandwidthObjectParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSecondaryExplicitRouteObjectParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSecondaryRecordRouteObjectParser.java delete mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSrpObjectParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPUnreachedIPv4DestinationObjectParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPUnreachedIPv6DestinationObjectParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/UnknownObject.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROIPv4PrefixSubobjectParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROIPv6PrefixSubobjectParser.java delete mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROIpPrefixSubobjectParser.java delete mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspDbVersionTlvParser.java delete mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspSymbolicNameTlvParser.java delete mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspUpdateErrorTlvParser.java delete mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OrderTlvParser.java delete mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OverloadedDurationTlvParser.java delete mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/PredundancyGroupTlvParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/RSVPErrorSpecIPv4TlvParser.java create mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/RSVPErrorSpecIPv6TlvParser.java delete mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/RSVPErrorSpecTlvParser.java delete mode 100644 pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/ReqMissingTlvParser.java create mode 100644 pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/CompositeTest.java create mode 100644 pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/tlv/LSPStateDBVersionTlvParserTest.java create mode 100644 pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/tlv/PCEStatefulCapabilityTlvParserTest.java delete mode 100644 pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractMessageParser.java delete mode 100644 pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectParser.java delete mode 100644 pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectHeaderImpl.java delete mode 100644 pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/SubobjectParser.java diff --git a/concepts/src/main/java/org/opendaylight/protocol/concepts/Ipv6Util.java b/concepts/src/main/java/org/opendaylight/protocol/concepts/Ipv6Util.java index 6eb959d8de..985e82bc1d 100644 --- a/concepts/src/main/java/org/opendaylight/protocol/concepts/Ipv6Util.java +++ b/concepts/src/main/java/org/opendaylight/protocol/concepts/Ipv6Util.java @@ -8,7 +8,6 @@ package org.opendaylight.protocol.concepts; import java.net.Inet6Address; -import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Collections; import java.util.List; @@ -34,16 +33,6 @@ public class Ipv6Util { } } - public static byte[] bytesForAddress(final Ipv6Address address) { - Inet6Address a; - try { - a = (Inet6Address) InetAddress.getByName(address.getValue()); - } catch (final UnknownHostException e) { - throw new IllegalArgumentException(e.getMessage()); - } - return a.getAddress(); - } - public static Ipv6Prefix prefixForBytes(final byte[] bytes, final int length) { Preconditions.checkArgument(length <= bytes.length * 8); return new Ipv6Prefix(addressForBytes(bytes).toString() + "/" + length); diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPCloseTermination.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPCloseTermination.java index 6343873b37..60683ce9ed 100644 --- a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPCloseTermination.java +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPCloseTermination.java @@ -7,21 +7,23 @@ */ package org.opendaylight.protocol.pcep; +import org.opendaylight.protocol.pcep.object.PCEPCloseObject.Reason; + import com.google.common.base.Objects.ToStringHelper; /** - * Used as a reason when one of the regular reasons was the cause of the termination of a session. + * Used as a reason when one of the regular reasons was the cause of the + * termination of a session. */ public final class PCEPCloseTermination extends PCEPTerminationReason { - private final TerminationReason reason; + private final Reason reason; /** * Creates new Termination. - * * @param reason reason for termination */ - public PCEPCloseTermination(final TerminationReason reason) { + public PCEPCloseTermination(final Reason reason) { super(); this.reason = reason; } @@ -36,7 +38,7 @@ public final class PCEPCloseTermination extends PCEPTerminationReason { @Override protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { - return toStringHelper.add("reason", this.reason); + return toStringHelper.add("reason", reason); } } diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPErrorMapping.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPErrorMapping.java deleted file mode 100644 index abc39eac13..0000000000 --- a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPErrorMapping.java +++ /dev/null @@ -1,178 +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; - -import java.util.HashMap; -import java.util.Map; -import java.util.NoSuchElementException; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Bidirectional mapping of {@link org.opendaylight.protocol.pcep.PCEPErrors PCEPErrors} and - * {@link org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser.PCEPErrorIdentifier ErrorIdentifier} - */ -public final class PCEPErrorMapping { - - private final static Logger logger = LoggerFactory.getLogger(PCEPErrorMapping.class); - - /** - * Caret for combination of Error-type and Error-value - */ - public static class PCEPErrorIdentifier { - public final short type; - public final short value; - - private PCEPErrorIdentifier(final short type, final short value) { - this.type = type; - this.value = value; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + this.type; - result = prime * result + this.value; - return result; - } - - @Override - public boolean equals(final java.lang.Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (this.getClass() != obj.getClass()) - return false; - final PCEPErrorIdentifier other = (PCEPErrorIdentifier) obj; - if (this.type != other.type) - return false; - if (this.value != other.value) - return false; - return true; - } - - @Override - public String toString() { - return "type " + this.type + " value " + this.value; - } - } - - private static final PCEPErrorMapping instance = new PCEPErrorMapping(); - - private final Map errorsMap = new HashMap(); - private final Map errorIdsMap = new HashMap(); - - private PCEPErrorMapping() { - this.fillIn(); - } - - private void fillIn() { - this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 1), PCEPErrors.NON_OR_INVALID_OPEN_MSG); - this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 2), PCEPErrors.NO_OPEN_BEFORE_EXP_OPENWAIT); - this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 3), PCEPErrors.NON_ACC_NON_NEG_SESSION_CHAR); - this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 4), PCEPErrors.NON_ACC_NEG_SESSION_CHAR); - this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 5), PCEPErrors.SECOND_OPEN_MSG); - this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 6), PCEPErrors.PCERR_NON_ACC_SESSION_CHAR); - this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 7), PCEPErrors.NO_MSG_BEFORE_EXP_KEEPWAIT); - this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 8), PCEPErrors.PCEP_VERSION_NOT_SUPPORTED); - - this.fillIn(new PCEPErrorIdentifier((short) 2, (short) 0), PCEPErrors.CAPABILITY_NOT_SUPPORTED); - - this.fillIn(new PCEPErrorIdentifier((short) 3, (short) 1), PCEPErrors.UNRECOGNIZED_OBJ_CLASS); - this.fillIn(new PCEPErrorIdentifier((short) 3, (short) 2), PCEPErrors.UNRECOGNIZED_OBJ_TYPE); - - this.fillIn(new PCEPErrorIdentifier((short) 4, (short) 1), PCEPErrors.NOT_SUPPORTED_OBJ_CLASS); - this.fillIn(new PCEPErrorIdentifier((short) 4, (short) 2), PCEPErrors.NOT_SUPPORTED_OBJ_TYPE); - - this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 1), PCEPErrors.C_BIT_SET); - this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 2), PCEPErrors.O_BIT_SET); - this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 3), PCEPErrors.OF_NOT_ALLOWED); - this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 4), PCEPErrors.OF_BIT_SET); - this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 5), PCEPErrors.GCO_NOT_ALLOWED); - this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 7), PCEPErrors.P2MP_COMPUTATION_NOT_ALLOWED); - - this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 1), PCEPErrors.RP_MISSING); - this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 2), PCEPErrors.RRO_MISSING); - this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 3), PCEPErrors.END_POINTS_MISSING); - this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 8), PCEPErrors.LSP_MISSING); - this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 9), PCEPErrors.ERO_MISSING); - this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 10), PCEPErrors.BANDWIDTH_MISSING); - this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 11), PCEPErrors.LSPA_MISSING); - this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 12), PCEPErrors.DB_VERSION_TLV_MISSING); - - this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 13), PCEPErrors.LSP_CLEANUP_TLV_MISSING); - this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 14), PCEPErrors.SYMBOLIC_PATH_NAME_MISSING); - - this.fillIn(new PCEPErrorIdentifier((short) 7, (short) 0), PCEPErrors.SYNC_PATH_COMP_REQ_MISSING); - - this.fillIn(new PCEPErrorIdentifier((short) 8, (short) 0), PCEPErrors.UNKNOWN_REQ_REF); - - this.fillIn(new PCEPErrorIdentifier((short) 9, (short) 0), PCEPErrors.ATTEMPT_2ND_SESSION); - - this.fillIn(new PCEPErrorIdentifier((short) 10, (short) 1), PCEPErrors.P_FLAG_NOT_SET); - - this.fillIn(new PCEPErrorIdentifier((short) 12, (short) 1), PCEPErrors.UNSUPPORTED_CT); - this.fillIn(new PCEPErrorIdentifier((short) 12, (short) 2), PCEPErrors.INVALID_CT); - this.fillIn(new PCEPErrorIdentifier((short) 12, (short) 3), PCEPErrors.CT_AND_SETUP_PRIORITY_DO_NOT_FORM_TE_CLASS); - - this.fillIn(new PCEPErrorIdentifier((short) 15, (short) 1), PCEPErrors.INSUFFICIENT_MEMORY); - this.fillIn(new PCEPErrorIdentifier((short) 15, (short) 2), PCEPErrors.GCO_NOT_SUPPORTED); - - this.fillIn(new PCEPErrorIdentifier((short) 16, (short) 1), PCEPErrors.CANNOT_SATISFY_P2MP_REQUEST_DUE_TO_INSUFFISIENT_MEMMORY); - this.fillIn(new PCEPErrorIdentifier((short) 16, (short) 2), PCEPErrors.NOT_CAPPABLE_P2MP_COMPUTATION); - - this.fillIn(new PCEPErrorIdentifier((short) 17, (short) 1), PCEPErrors.P2MP_NOT_CAPPABLE_SATISFY_REQ_DUE_LT2); - this.fillIn(new PCEPErrorIdentifier((short) 17, (short) 2), PCEPErrors.P2MP_NOT_CAPPABLE_SATISFY_REQ_DUE_LT3); - this.fillIn(new PCEPErrorIdentifier((short) 17, (short) 3), PCEPErrors.P2MP_NOT_CAPPABLE_SATISFY_REQ_DUE_LT4); - this.fillIn(new PCEPErrorIdentifier((short) 17, (short) 4), PCEPErrors.P2MP_NOT_CAPPABLE_SATISFY_REQ_DUE_INCONSISTENT_EP); - - this.fillIn(new PCEPErrorIdentifier((short) 18, (short) 1), PCEPErrors.P2MP_FRAGMENTATION_FAILRUE); - - this.fillIn(new PCEPErrorIdentifier((short) 19, (short) 1), PCEPErrors.UPDATE_REQ_FOR_NON_LSP); - this.fillIn(new PCEPErrorIdentifier((short) 19, (short) 2), PCEPErrors.UPDATE_REQ_FOR_NO_STATEFUL); - // TODO: value TBD - this.fillIn(new PCEPErrorIdentifier((short) 19, (short) 3), PCEPErrors.LSP_LIMIT_REACHED); - this.fillIn(new PCEPErrorIdentifier((short) 19, (short) 4), PCEPErrors.DELEGATION_NOT_REVOKED); - - this.fillIn(new PCEPErrorIdentifier((short) 20, (short) 1), PCEPErrors.CANNOT_PROCESS_STATE_REPORT); - this.fillIn(new PCEPErrorIdentifier((short) 20, (short) 2), PCEPErrors.LSP_DB_VERSION_MISMATCH); - this.fillIn(new PCEPErrorIdentifier((short) 20, (short) 3), PCEPErrors.DB_VERSION_TLV_MISSING_WHEN_SYNC_ALLOWED); - - this.fillIn(new PCEPErrorIdentifier((short) 23, (short) 1), PCEPErrors.USED_SYMBOLIC_PATH_NAME); - } - - private void fillIn(final PCEPErrorIdentifier identifier, final PCEPErrors error) { - this.errorsMap.put(error, identifier); - this.errorIdsMap.put(identifier, error); - } - - public PCEPErrorIdentifier getFromErrorsEnum(final PCEPErrors error) { - final PCEPErrorIdentifier ei = this.errorsMap.get(error); - if (ei == null) { - logger.debug("Unknown PCEPErrors type: {}.", error); - throw new NoSuchElementException("Unknown PCEPErrors type: " + error); - } - return ei; - } - - public PCEPErrors getFromErrorIdentifier(final PCEPErrorIdentifier identifier) { - final PCEPErrors e = this.errorIdsMap.get(identifier); - if (e == null) { - logger.debug("Unknown error type/value combination: {}.", identifier); - throw new NoSuchElementException("Unknown error type/value combination: " + identifier); - } - return e; - } - - public static PCEPErrorMapping getInstance() { - return instance; - } -} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPObject.java new file mode 100644 index 0000000000..c847ddddef --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPObject.java @@ -0,0 +1,95 @@ +/* + * 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; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Basic structure for PCEP Objects. + * + * @see Common Object + * Header + */ +public abstract class PCEPObject { + + private final boolean processed; + + private final boolean ignored; + + /** + * Constructor is protected to prevent direct instantiation, but to allow to + * call this constructor via super(). + * + * @param processed + * P flag + * @param ignored + * I flag + */ + protected PCEPObject(boolean processed, boolean ignored) { + this.processed = processed; + this.ignored = ignored; + } + + /** + * @see Common + * Object Header + * + * @return true if P flag is set and false if is not. + */ + public boolean isProcessed() { + return this.processed; + } + + /** + * @see Common + * Object Header + * + * @return true if I flag is set and false if is not. + */ + public boolean isIgnored() { + return this.ignored; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (this.ignored ? 1231 : 1237); + result = prime * result + (this.processed ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPObject other = (PCEPObject) obj; + if (this.ignored != other.ignored) + return false; + if (this.processed != other.processed) + return false; + return true; + } + + @Override + public String toString(){ + return addToStringAttributes(Objects.toStringHelper(this)).toString(); + } + + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("processed", this.processed); + toStringHelper.add("ignored", this.ignored); + return toStringHelper; + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPSession.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPSession.java index 74c1107529..301354e1a8 100644 --- a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPSession.java +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPSession.java @@ -8,6 +8,7 @@ package org.opendaylight.protocol.pcep; import org.opendaylight.protocol.framework.ProtocolSession; +import org.opendaylight.protocol.pcep.object.PCEPCloseObject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; /** @@ -27,5 +28,5 @@ public interface PCEPSession extends ProtocolSession { */ public void sendMessage(Message message); - public void close(TerminationReason reason); + public void close(PCEPCloseObject.Reason reason); } diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPSessionProposalFactory.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPSessionProposalFactory.java index 1dcf570c89..168147f50d 100644 --- a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPSessionProposalFactory.java +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPSessionProposalFactory.java @@ -9,7 +9,7 @@ package org.opendaylight.protocol.pcep; import java.net.InetSocketAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; /** * Factory for generating PCEP Session proposals. Used by a server. @@ -18,11 +18,13 @@ public interface PCEPSessionProposalFactory { /** * Returns one session proposal that is registered to this factory - * - * @param address serves as constraint, so that factory is able to return different proposals for different - * addresses - * @param sessionId is used for creation of PCEPOpenObject + * + * @param address + * serves as constraint, so that factory is able to return + * different proposals for different addresses + * @param sessionId + * is used for creation of PCEPOpenObject * @return specific session proposal */ - public OpenObject getSessionProposal(InetSocketAddress address, int sessionId); + public PCEPOpenObject getSessionProposal(InetSocketAddress address, int sessionId); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/SubobjectSerializer.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPTlv.java similarity index 53% rename from pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/SubobjectSerializer.java rename to pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPTlv.java index ed3dee0c38..d10848976e 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/SubobjectSerializer.java +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/PCEPTlv.java @@ -5,14 +5,16 @@ * 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; +package org.opendaylight.protocol.pcep; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject; +import java.io.Serializable; -public interface SubobjectSerializer { - - @Deprecated - public int getType(); +/** + * Interface grouping all implemented tlvs. + * + * @see PCEP TLV + * Format + */ +public interface PCEPTlv extends Serializable { - public byte[] serializeSubobject(CSubobject subobject); } diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/TerminationReason.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/TerminationReason.java deleted file mode 100644 index 7a4f39a51b..0000000000 --- a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/TerminationReason.java +++ /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.pcep; - -import java.util.Map; - -import com.google.common.collect.Maps; - -public enum TerminationReason { - Unknown((short) 1), ExpDeadtimer((short) 2), MalformedMsg((short) 3), TooManyUnknownReqRep((short) 4), TooManyUnknownMsg((short) 5); - - short value; - static Map valueMap; - - static { - valueMap = Maps.newHashMap(); - for (final TerminationReason enumItem : TerminationReason.values()) { - valueMap.put(enumItem.value, enumItem); - } - } - - private TerminationReason(final short value) { - this.value = value; - } - - /** - * @return integer value - */ - public short getShortValue() { - return this.value; - } - - /** - * @param valueArg - * @return corresponding TerminationReason item - */ - public static TerminationReason forValue(final short valueArg) { - return valueMap.get(valueArg); - } -} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/UnknownObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/UnknownObject.java deleted file mode 100644 index c4877df2af..0000000000 --- a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/UnknownObject.java +++ /dev/null @@ -1,52 +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; - -import java.util.Arrays; -import java.util.List; - -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.pcerr.message.pcerr.message.Errors; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder; -import org.opendaylight.yangtools.yang.binding.DataContainer; - -public class UnknownObject implements Object { - - private final Errors error; - - private final PCEPErrors e; - - public UnknownObject(final PCEPErrors error) { - final PCEPErrorMapping mapping = PCEPErrorMapping.getInstance(); - this.e = error; - this.error = new ErrorsBuilder().setType(mapping.getFromErrorsEnum(error).type).setValue(mapping.getFromErrorsEnum(error).value).build(); - } - - public List getErrors() { - return Arrays.asList(this.error); - } - - public PCEPErrors getError() { - return this.e; - } - - @Override - public Class getImplementedInterface() { - return Object.class; - } - - @Override - public Boolean isIgnore() { - return false; - } - - @Override - public Boolean isProcessingRule() { - return false; - } -} \ No newline at end of file diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/AbstractExtendedTunnelIdentifier.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/AbstractExtendedTunnelIdentifier.java new file mode 100644 index 0000000000..2b031cfd8c --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/AbstractExtendedTunnelIdentifier.java @@ -0,0 +1,79 @@ +/* + * 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.concepts; + +import org.opendaylight.protocol.concepts.NetworkAddress; + +/** + * Basic structure of Extended Tunnel Identifier. + * + * @see LSP + * Identifiers TLVs + * @param + */ +public abstract class AbstractExtendedTunnelIdentifier> implements Comparable>, ExtendedTunnelIdentifier { + + private static final long serialVersionUID = 110737862492677555L; + + private final T identifier; + + protected AbstractExtendedTunnelIdentifier(final T identifier) { + this.identifier = identifier; + } + + @Override + public T getIdentifier() { + return this.identifier; + } + + @Override + public int compareTo(final ExtendedTunnelIdentifier other) { + if (this.identifier == other.getIdentifier()) + return 0; + if (this.identifier == null) + return -1; + if (other.getIdentifier() == null) + return 1; + return this.identifier.compareTo(other.getIdentifier()); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.identifier == null) ? 0 : this.identifier.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final AbstractExtendedTunnelIdentifier other = (AbstractExtendedTunnelIdentifier) obj; + if (this.identifier == null) { + if (other.identifier != null) + return false; + } else if (!this.identifier.equals(other.identifier)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("AbstractExtendedTunnelIdentifier [identifier="); + builder.append(this.identifier); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/AggregateBandwidthConsumptionMetric.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/AggregateBandwidthConsumptionMetric.java new file mode 100644 index 0000000000..f2ba955193 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/AggregateBandwidthConsumptionMetric.java @@ -0,0 +1,32 @@ +/* + * 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.concepts; + +import org.opendaylight.protocol.concepts.AbstractMetric; + +/** + * Aggregate Bandwidth Consumption metric class. + */ +public class AggregateBandwidthConsumptionMetric extends AbstractMetric { + + private static final long serialVersionUID = 3935025327997428991L; + + /** + * Construct a new Aggregate Bandwidth Consumption metric object. + * + * @param value + * Metric value + * @throws IllegalArgumentException + * ex when value is outside of allowed range (0-4294967295) + */ + public AggregateBandwidthConsumptionMetric(final long value) { + super(value); + if (value < 0 || value > 4294967295L) + throw new IllegalArgumentException("Invalid Agregate Bandwidth Consumption metric value"); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/CumulativeIGPCostMetric.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/CumulativeIGPCostMetric.java new file mode 100644 index 0000000000..b8504622af --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/CumulativeIGPCostMetric.java @@ -0,0 +1,32 @@ +/* + * 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.concepts; + +import org.opendaylight.protocol.concepts.AbstractMetric; + +/** + * Cumulative IGP cost metric class + */ +public class CumulativeIGPCostMetric extends AbstractMetric { + + private static final long serialVersionUID = 3935025327997428991L; + + /** + * Construct a new Cumulative IGP cost metric object. + * + * @param value + * Metric value + * @throws IllegalArgumentException + * ex when value is outside of allowed range (0-4294967295) + */ + public CumulativeIGPCostMetric(final long value) { + super(value); + if (value < 0 || value > 4294967295L) + throw new IllegalArgumentException("Invalid cumulative IGP cost metric value"); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/CumulativeTECostMetric.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/CumulativeTECostMetric.java new file mode 100644 index 0000000000..2a3ce3bbb0 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/CumulativeTECostMetric.java @@ -0,0 +1,32 @@ +/* + * 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.concepts; + +import org.opendaylight.protocol.concepts.AbstractMetric; + +/** + * Cumulative TE cost metric class + */ +public class CumulativeTECostMetric extends AbstractMetric { + + private static final long serialVersionUID = 3935025327997428991L; + + /** + * Construct a new Cumulative TE cost metric object. + * + * @param value + * Metric value + * @throws IllegalArgumentException + * ex when value is outside of allowed range (0-4294967295) + */ + public CumulativeTECostMetric(final long value) { + super(value); + if (value < 0 || value > 4294967295L) + throw new IllegalArgumentException("Invalid cumulative TE cost metric value"); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/ExtendedTunnelIdentifier.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/ExtendedTunnelIdentifier.java new file mode 100644 index 0000000000..7eb911000b --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/ExtendedTunnelIdentifier.java @@ -0,0 +1,29 @@ +/* + * 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.concepts; + +import org.opendaylight.protocol.concepts.Identifier; +import org.opendaylight.protocol.concepts.NetworkAddress; + +/** + * Interface grouping Extended Tunnel Identifiers. + * + * @see LSP + * Identifiers TLVs + * @param IPv4 or IPv6 address that is wrapped in this tunnel + */ +public interface ExtendedTunnelIdentifier> extends Identifier { + + /** + * Getter for Identifier of Extended Tunnel. + * + * @return T IPv4 or IPv6 address + */ + public T getIdentifier(); +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/IPv4ExtendedTunnelIdentifier.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/IPv4ExtendedTunnelIdentifier.java new file mode 100644 index 0000000000..65891e3273 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/IPv4ExtendedTunnelIdentifier.java @@ -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.protocol.pcep.concepts; + +import org.opendaylight.protocol.concepts.IPv4Address; + +/** + * Specific structure of IPv4 Extended Tunnel Identifier. + * + * @see LSP + * Identifiers TLVs + */ +public final class IPv4ExtendedTunnelIdentifier extends AbstractExtendedTunnelIdentifier { + + private static final long serialVersionUID = -8872936514548777175L; + + /** + * Creates IPv4ExtendedTunnelIdentifier with given IPv4Address. + * @param routerAddress {@link IPv4Address} + */ + public IPv4ExtendedTunnelIdentifier(final IPv4Address routerAddress) { + super(routerAddress); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/IPv6ExtendedTunnelIdentifier.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/IPv6ExtendedTunnelIdentifier.java new file mode 100644 index 0000000000..036b8856ff --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/IPv6ExtendedTunnelIdentifier.java @@ -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.protocol.pcep.concepts; + +import org.opendaylight.protocol.concepts.IPv6Address; + +/** + * Specific structure of IPv6 Extended Tunnel Identifier. + * + * @see LSP + * Identifiers TLVs + */ +public final class IPv6ExtendedTunnelIdentifier extends AbstractExtendedTunnelIdentifier { + + private static final long serialVersionUID = -4603732260818370518L; + + /** + * Creates IPv6ExtendedTunnelIdentifier with given IPv6Address. + * @param routerAddress {@link IPv6Address} + */ + public IPv6ExtendedTunnelIdentifier(final IPv6Address routerAddress) { + super(routerAddress); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/LSPIdentifier.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/LSPIdentifier.java new file mode 100644 index 0000000000..f5b978f169 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/LSPIdentifier.java @@ -0,0 +1,55 @@ +/* + * 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.concepts; + +import org.opendaylight.protocol.concepts.AbstractIdentifier; +import org.opendaylight.protocol.util.ByteArray; +import com.google.common.base.Objects.ToStringHelper; + +/** + * A 16-bit identifier used in the SENDER_TEMPLATE and the FILTER_SPEC that can + * be changed to allow a sender to share resources with itself. + */ +public final class LSPIdentifier extends AbstractIdentifier { + + private static final long serialVersionUID = 1337756730239265010L; + + private final byte[] lspId; + + /** + * Creates LSPIdentifier using byte array as value. + * + * @param lspId + * value of the LSPIdentifier TLV. Must be exactly 2 bytes long. + */ + public LSPIdentifier(final byte[] lspId) { + if (lspId.length != 2) + throw new IllegalArgumentException("Invalid LSP identifier"); + this.lspId = lspId; + } + + /** + * Gets LSP Id in raw byte array representation. + * + * @return byte array representation of LSP ID. May be null. + */ + public byte[] getLspId() { + return this.lspId; + } + + @Override + protected byte[] getBytes() { + return this.lspId; + } + + @Override + protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { + return toStringHelper.add("lspId", ByteArray.toHexString(lspId, ".")); + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/LSPSymbolicName.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/LSPSymbolicName.java new file mode 100644 index 0000000000..40931fc19e --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/LSPSymbolicName.java @@ -0,0 +1,53 @@ +/* + * 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.concepts; + +import org.opendaylight.protocol.concepts.AbstractIdentifier; +import org.opendaylight.protocol.util.ByteArray; +import com.google.common.base.Objects.ToStringHelper; + +/** + * @see The + * LSP Symbolic Name TLV + */ +public final class LSPSymbolicName extends AbstractIdentifier { + + private static final long serialVersionUID = -5649378295100912021L; + + private final byte[] symbolicName; + + /** + * Creates LSPSymbolicName using byte array as value. + * + * @param symbolicName + * value of the LSPSymbolicName TLV + */ + public LSPSymbolicName(final byte[] symbolicName) { + this.symbolicName = symbolicName; + } + + /** + * Gets Symbolic Name in raw byte array representation. + * + * @return byte array representation of Symbolic Name. May be null. + */ + public byte[] getSymbolicName() { + return this.symbolicName; + } + + @Override + protected byte[] getBytes() { + return this.symbolicName; + } + + @Override + protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { + return toStringHelper.add("symbolicName", ByteArray.toHexString(symbolicName, ".")); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/MostLoadedLinkLoadMetric.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/MostLoadedLinkLoadMetric.java new file mode 100644 index 0000000000..762fdb1336 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/MostLoadedLinkLoadMetric.java @@ -0,0 +1,32 @@ +/* + * 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.concepts; + +import org.opendaylight.protocol.concepts.AbstractMetric; + +/** + * Load of the most loaded link metric class + */ +public class MostLoadedLinkLoadMetric extends AbstractMetric { + + private static final long serialVersionUID = 3935025327997428991L; + + /** + * Construct a new Load of the most loaded link metric object. + * + * @param value + * Metric value + * @throws IllegalArgumentException + * ex when value is outside of allowed range (0-4294967295) + */ + public MostLoadedLinkLoadMetric(final long value) { + super(value); + if (value < 0 || value > 4294967295L) + throw new IllegalArgumentException("Invalid Load of the most loaded link metric value"); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/P2MPHopCountMetric.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/P2MPHopCountMetric.java new file mode 100644 index 0000000000..be2a0f661c --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/P2MPHopCountMetric.java @@ -0,0 +1,32 @@ +/* + * 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.concepts; + +import org.opendaylight.protocol.concepts.AbstractMetric; + +/** + * P2MP hop count metric class + */ +public class P2MPHopCountMetric extends AbstractMetric { + + private static final long serialVersionUID = 3935025327997428991L; + + /** + * Construct a new P2MP hop count metric object. + * + * @param value + * Metric value + * @throws IllegalArgumentException + * ex when value is outside of allowed range (0-4294967295) + */ + public P2MPHopCountMetric(final long value) { + super(value); + if (value < 0 || value > 4294967295L) + throw new IllegalArgumentException("Invalid P2MP hop count metric value"); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/P2MPIGPMetric.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/P2MPIGPMetric.java new file mode 100644 index 0000000000..c8e3f916be --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/P2MPIGPMetric.java @@ -0,0 +1,32 @@ +/* + * 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.concepts; + +import org.opendaylight.protocol.concepts.AbstractMetric; + +/** + * P2MP IGP metric class + */ +public class P2MPIGPMetric extends AbstractMetric { + + private static final long serialVersionUID = 3935025327997428991L; + + /** + * Construct a new P2MP IGP metric metric object. + * + * @param value + * Metric value + * @throws IllegalArgumentException + * ex when value is outside of allowed range (0-4294967295) + */ + public P2MPIGPMetric(final long value) { + super(value); + if (value < 0 || value > 4294967295L) + throw new IllegalArgumentException("Invalid P2MP IGP metric value"); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/P2MPTEMetric.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/P2MPTEMetric.java new file mode 100644 index 0000000000..74cc34ef19 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/P2MPTEMetric.java @@ -0,0 +1,32 @@ +/* + * 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.concepts; + +import org.opendaylight.protocol.concepts.AbstractMetric; + +/** + * P2MP TE metric class + */ +public class P2MPTEMetric extends AbstractMetric { + + private static final long serialVersionUID = 3935025327997428991L; + + /** + * Construct a new P2MP TE metric object. + * + * @param value + * Metric value + * @throws IllegalArgumentException + * ex when value is outside of allowed range (0-4294967295) + */ + public P2MPTEMetric(final long value) { + super(value); + if (value < 0 || value > 4294967295L) + throw new IllegalArgumentException("Invalid P2MP TE metri value"); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/TunnelIdentifier.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/TunnelIdentifier.java new file mode 100644 index 0000000000..c4859b14f0 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/TunnelIdentifier.java @@ -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.pcep.concepts; + +import org.opendaylight.protocol.concepts.AbstractIdentifier; +import org.opendaylight.protocol.util.ByteArray; +import com.google.common.base.Objects.ToStringHelper; + +/** + * A 16-bit identifier used in the SESSION that remains constant over the life + * of the tunnel. + */ +public final class TunnelIdentifier extends AbstractIdentifier { + + private static final long serialVersionUID = 137237703900885441L; + + private final byte[] tunnelId; + + /** + * Creates TunnelIdentifier using byte array as value. + * + * @param tunnelId + * value of the TunnelIdentifier TLV. Must be exactly 2 bytes + * long. + */ + public TunnelIdentifier(final byte[] tunnelId) { + if (tunnelId.length != 2) + throw new IllegalArgumentException("Invalid tunnel ID."); + this.tunnelId = tunnelId; + } + + @Override + public byte[] getBytes() { + return this.tunnelId; + } + + @Override + protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { + return toStringHelper.add("tunnelId", ByteArray.toHexString(tunnelId, ".")); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/UnnumberedInterfaceIdentifier.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/UnnumberedInterfaceIdentifier.java new file mode 100644 index 0000000000..601ebf68ce --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/concepts/UnnumberedInterfaceIdentifier.java @@ -0,0 +1,82 @@ +/* + * 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.concepts; + +import org.opendaylight.protocol.concepts.Identifier; + +/** + * A 32-bit (unsigned) identifying an interface within a router. This identifier + * is explicitly local to the router, e.g. each router has its own namespace. + */ +public final class UnnumberedInterfaceIdentifier implements Comparable, Identifier { + + private static final long serialVersionUID = -8488014237579913120L; + + private final long interfaceId; + + /** + * Creates an instance of UnnumberedInterfaceIdentifier from long number. + * + * @param interfaceId + * long the value of the UnnumberedInterfaceIdentifier + */ + public UnnumberedInterfaceIdentifier(final long interfaceId) { + if (interfaceId < 0 || interfaceId > 4294967295L) + throw new IllegalArgumentException("Invalid link identifier"); + this.interfaceId = interfaceId; + } + + /** + * Getter for Interface Id represented as long. + * + * @return long representation of Interface Id. From 0 to 4294967295. + */ + public long getInterfaceId() { + return this.interfaceId; + } + + @Override + public int compareTo(final UnnumberedInterfaceIdentifier o) { + if (this.interfaceId < o.getInterfaceId()) + return -1; + if (this.interfaceId > o.getInterfaceId()) + return 1; + return 0; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (this.interfaceId ^ (this.interfaceId >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final UnnumberedInterfaceIdentifier other = (UnnumberedInterfaceIdentifier) obj; + if (this.interfaceId != other.interfaceId) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("UnnumberedInterfaceIdentifier [interfaceId="); + builder.append(this.interfaceId); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCCreateMessage.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCCreateMessage.java new file mode 100644 index 0000000000..a942e566c7 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCCreateMessage.java @@ -0,0 +1,112 @@ +/* + * 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.message; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.object.CompositeInstantiationObject; +import org.opendaylight.protocol.pcep.object.CompositeStateReportObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; + +import com.google.common.collect.Lists; + +/** + * @see 5.1. The LSP Create Message + */ +public class PCCreateMessage implements Message { + + private final List lsps; + + private final List objects; + + /** + * Constructs {@link PCCreateMessage}. + * + * @throws IllegalArgumentException if there is not even one {@link CompositeInstantiationObject} in the list. + * + * @param lsps List. Can't be empty or null. + */ + public PCCreateMessage(final List lsps) { + if (lsps == null || lsps.isEmpty()) { + throw new IllegalArgumentException("At least one CompositeStateReportObject is mandatory."); + } + + this.lsps = lsps; + this.objects = Lists.newArrayList(); + for (final CompositeInstantiationObject cio : lsps) { + this.objects.addAll(cio.getCompositeAsList()); + } + } + + /** + * Gets list of {@link CompositeStateReportObject}. + * + * @return List. Can't be null or empty. + */ + public List getLSPs() { + return this.lsps; + } + + public List getAllObjects() { + return this.objects; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.lsps == null) ? 0 : this.lsps.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (!(obj instanceof PCCreateMessage)) { + return false; + } + final PCCreateMessage other = (PCCreateMessage) obj; + if (this.lsps == null) { + if (other.lsps != null) { + return false; + } + } else if (!this.lsps.equals(other.lsps)) { + return false; + } + return true; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("PCCreateMessage [lsps="); + builder.append(this.lsps); + builder.append("]"); + return builder.toString(); + } + + @Override + public Class getImplementedInterface() { + return Message.class; + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPCloseMessage.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPCloseMessage.java new file mode 100644 index 0000000000..498eff03ea --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPCloseMessage.java @@ -0,0 +1,107 @@ +/* + * 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.message; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.object.PCEPCloseObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; + +import com.google.common.collect.Lists; + +/** + * Structure of Close Message. + * + * @see Close Message + */ +public class PCEPCloseMessage implements Message { + + private final PCEPCloseObject closeObj; + + private final List objects; + + /** + * Constructs a new Close Message, which has to include PCEP Close Object. Is used to close an established session + * between PCEP Peers. + * + * @throws IllegalArgumentException if the CloseObject passed, is null. + * + * @see Close Message + * + * @param closeObj Can't be null. + */ + public PCEPCloseMessage(final PCEPCloseObject closeObj) { + if (closeObj == null) { + throw new IllegalArgumentException("PCEPCloseObject is mandatory. Can't be null."); + } + + this.closeObj = closeObj; + this.objects = Lists.newArrayList(); + if (closeObj != null) { + this.objects.add(closeObj); + } + } + + /** + * Gets {@link PCEPCloseObject}, which is mandatory object of PCEP Close Message. + * + * @return {@link PCEPCloseObject} . Can't be null. + */ + public PCEPCloseObject getCloseObject() { + return this.closeObj; + } + + public List getAllObjects() { + return this.objects; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.closeObj == null) ? 0 : this.closeObj.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + final PCEPCloseMessage other = (PCEPCloseMessage) obj; + if (this.closeObj == null) { + if (other.closeObj != null) { + return false; + } + } else if (!this.closeObj.equals(other.closeObj)) { + return false; + } + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("PCEPCloseMessage [closeObj="); + builder.append(this.closeObj); + builder.append("]"); + return builder.toString(); + } + + @Override + public Class getImplementedInterface() { + return Message.class; + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPErrorMessage.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPErrorMessage.java new file mode 100644 index 0000000000..b32f39cc3e --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPErrorMessage.java @@ -0,0 +1,229 @@ +/* + * 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.message; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.object.CompositeErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; + +import com.google.common.collect.Lists; + +/** + * Structure of Error Message. + * + * @see Error Message + */ +public class PCEPErrorMessage implements Message { + + private PCEPOpenObject openObj; + + private final List errorObjects; + + private final List errors; + + private final List objects; + + public PCEPErrorMessage(final PCEPErrorObject errorObject) { + this(new ArrayList() { + private static final long serialVersionUID = 72172137965955228L; + + { + this.add(errorObject); + } + }); + } + + public PCEPErrorMessage(final CompositeErrorObject compositeErrorObject) { + this(new ArrayList() { + private static final long serialVersionUID = 72172137965955228L; + + { + if (compositeErrorObject != null) { + this.add(compositeErrorObject); + } + } + }); + } + + /** + * Constructs Error Message from list of {@link PCEPErrorObject} or {@link CompositeErrorObject}. + * + * @param errorObjects List either objects of type: {@link PCEPErrorObject} or {@link CompositeErrorObject} + * + * @throws IllegalArgumentException if any other type is passed in the list, that cannot be processed + */ + public PCEPErrorMessage(final List errorObjects) { + this.objects = Lists.newArrayList(); + if (errorObjects != null) { + for (int i = 0; i < errorObjects.size(); i++) { + if (errorObjects.get(i) instanceof CompositeErrorObject) { + this.objects.addAll(((CompositeErrorObject) errorObjects.get(i)).getCompositeAsList()); + } else if (errorObjects.get(i) instanceof PCEPErrorObject) { + this.objects.add((PCEPErrorObject) errorObjects.get(i)); + } + } + } + this.errors = new ArrayList(); + this.errorObjects = new ArrayList(); + + if (errorObjects != null) { + for (int i = 0; i < errorObjects.size(); i++) { + if (errorObjects.get(i) instanceof CompositeErrorObject) { + this.errors.add((CompositeErrorObject) errorObjects.get(i)); + } else if (errorObjects.get(i) instanceof PCEPErrorObject) { + this.errorObjects.add((PCEPErrorObject) errorObjects.get(i)); + } else { + throw new IllegalArgumentException("Wrong instance passed in list. Acceptable is only CompositeErrorObject or PCEPErrorObject."); + } + } + } + } + + /** + * Constructs Error Message from list of {@link PCEPErrorObject} and {@link CompositeErrorObject} and + * {@link PCEPOpenObject} that cannot be null. This constructor is used during PCEP handshake to suggest new session + * characteristics for the session that are listen in {@link PCEPOpenObject}. + * + * @param openObj {@link PCEPOpenObject} cannot be null + * @param errorObjects List list of error objects + * @param errors List list of composite error objects + */ + public PCEPErrorMessage(final PCEPOpenObject openObj, final List errorObjects, final List errors) { + this.objects = Lists.newArrayList(); + if (errorObjects != null) { + this.objects.addAll(errorObjects); + } + if (openObj != null) { + this.objects.add(openObj); + } + if (errors != null) { + for (final CompositeErrorObject ceo : errors) { + this.objects.addAll(ceo.getCompositeAsList()); + } + } + + this.openObj = openObj; + + if (errorObjects == null) { + throw new IllegalArgumentException("At least one PCEPErrorObject is mandatory."); + } + this.errorObjects = errorObjects; + + if (errors == null) { + this.errors = Collections.emptyList(); + } else { + this.errors = errors; + } + } + + /** + * Gets {@link PCEPOpenObject} if this is included. If its included, it proposes alternative acceptable session + * characteristic values. + * + * @return PCEPOpenObject. May be null. + */ + public PCEPOpenObject getOpenObject() { + return this.openObj; + } + + /** + * In unsolicited manner can be included List of PCEPErrorObjects PCEPErrorMessage, which + * is not sent in response to a request. + * + * @return List + */ + public List getErrorObjects() { + return this.errorObjects; + } + + /** + * If the PCErr message is sent in response to a request, the PCErr message MUST include set of RP objects related + * to pending path computation requests that triggered the error condition. In this situation it is constructed as + * {@link org.opendaylight.protocol.pcep.object.CompositeErrorObject CompCompositeErrorObject}. That includes list + * of RP objects. + * + * @return CompositeErrorObject. May be null. + */ + public List getErrors() { + return this.errors; + } + + public List getAllObjects() { + return this.objects; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.errorObjects == null) ? 0 : this.errorObjects.hashCode()); + result = prime * result + ((this.errors == null) ? 0 : this.errors.hashCode()); + result = prime * result + ((this.openObj == null) ? 0 : this.openObj.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + final PCEPErrorMessage other = (PCEPErrorMessage) obj; + if (this.errorObjects == null) { + if (other.errorObjects != null) { + return false; + } + } else if (!this.errorObjects.equals(other.errorObjects)) { + return false; + } + if (this.errors == null) { + if (other.errors != null) { + return false; + } + } else if (!this.errors.equals(other.errors)) { + return false; + } + if (this.openObj == null) { + if (other.openObj != null) { + return false; + } + } else if (!this.openObj.equals(other.openObj)) { + return false; + } + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("PCEPErrorMessage [openObj="); + builder.append(this.openObj); + builder.append(", errorObjects="); + builder.append(this.errorObjects); + builder.append(", errors="); + builder.append(this.errors); + builder.append("]"); + return builder.toString(); + } + + @Override + public Class getImplementedInterface() { + return Message.class; + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPNotificationMessage.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPNotificationMessage.java new file mode 100644 index 0000000000..10ebdb44c5 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPNotificationMessage.java @@ -0,0 +1,106 @@ +/* + * 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.message; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.object.CompositeNotifyObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; + +import com.google.common.collect.Lists; + +/** + * Structure of Notification Message. + * + * @see Notification Message + */ +public class PCEPNotificationMessage implements Message { + + private final List notifications; + + private final List objects; + + /** + * Constructs new Notification Message. + * + * @throws IllegalArgumentException if there is not even one {@link CompositeNotifyObject} in the list. + * + * @param notifications List. Can't be empty or null. + */ + public PCEPNotificationMessage(final List notifications) { + this.objects = Lists.newArrayList(); + if (notifications != null) { + for (final CompositeNotifyObject cno : notifications) { + this.objects.addAll(cno.getCompositeAsList()); + } + } + if (notifications == null || notifications.isEmpty()) { + throw new IllegalArgumentException("At least one CompositeNotifyObject is mandatory."); + } + + this.notifications = notifications; + } + + /** + * Gets list of {@link org.opendaylight.protocol.pcep.object.CompositeNotifyObject CompositeNotifyObjects}. + * + * @return List. Can't be null or empty. + */ + public List getNotifications() { + return this.notifications; + } + + public List getAllObjects() { + return this.objects; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.notifications == null) ? 0 : this.notifications.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + final PCEPNotificationMessage other = (PCEPNotificationMessage) obj; + if (this.notifications == null) { + if (other.notifications != null) { + return false; + } + } else if (!this.notifications.equals(other.notifications)) { + return false; + } + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("PCEPNotificationMessage [notifications="); + builder.append(this.notifications); + builder.append("]"); + return builder.toString(); + } + + @Override + public Class getImplementedInterface() { + return Message.class; + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPOpenMessage.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPOpenMessage.java new file mode 100644 index 0000000000..5186e11f64 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPOpenMessage.java @@ -0,0 +1,103 @@ +/* + * 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.message; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; + +import com.google.common.collect.Lists; + +/** + * Structure of Open Message. + * + * @see Open Message + */ +public class PCEPOpenMessage implements Message { + + private final PCEPOpenObject openObj; + + private final List objects; + + /** + * Constructs new Open Message. + * + * @throws IllegalArgumentException if the PCEPOpenObject is null. + * + * @param openObj {@link PCEPOpenObject}. Can't be null. + */ + public PCEPOpenMessage(final PCEPOpenObject openObj) { + this.objects = Lists.newArrayList(); + if (openObj != null) { + this.objects.add(openObj); + } else { + throw new IllegalArgumentException("PCEPOpenObject is mandatory."); + } + + this.openObj = openObj; + } + + /** + * Gets {@link PCEPOpenObject} + * + * @return {@link PCEPOpenObject}. Can't be null. + */ + public PCEPOpenObject getOpenObject() { + return this.openObj; + } + + public List getAllObjects() { + return this.objects; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.openObj == null) ? 0 : this.openObj.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + final PCEPOpenMessage other = (PCEPOpenMessage) obj; + if (this.openObj == null) { + if (other.openObj != null) { + return false; + } + } else if (!this.openObj.equals(other.openObj)) { + return false; + } + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("PCEPOpenMessage [openObj="); + builder.append(this.openObj); + builder.append("]"); + return builder.toString(); + } + + @Override + public Class getImplementedInterface() { + return Message.class; + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPReplyMessage.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPReplyMessage.java new file mode 100644 index 0000000000..46d86ec1d6 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPReplyMessage.java @@ -0,0 +1,152 @@ +/* + * 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.message; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.object.CompositeReplySvecObject; +import org.opendaylight.protocol.pcep.object.CompositeResponseObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; + +import com.google.common.collect.Lists; + +/** + * Structure for Reply Message. + * + * @see Reply Message + */ +public class PCEPReplyMessage implements Message { + + private final List svecList; + + private final List responses; + + private final List objects; + + /** + * Constructs new Reply Message. + * + * @throws IllegalArgumentException if there is not even one {@link CompositeResponseObject} in the list. + * + * @param responses List. Can't be empty or null. + */ + public PCEPReplyMessage(final List responses) { + this(responses, null); + } + + /** + * Constructs {@link PCEPReplyMessage}. + * + * @throws IllegalArgumentException if there is not even one {@link CompositeResponseObject} in the list. + * + * @param svecList List + * @param responses List. Can't be empty or null. + */ + public PCEPReplyMessage(final List responses, final List svecList) { + this.objects = Lists.newArrayList(); + if (svecList != null) { + for (final CompositeReplySvecObject cno : svecList) { + this.objects.addAll(cno.getCompositeAsList()); + } + } + if (responses != null) { + for (final CompositeResponseObject cno : responses) { + this.objects.addAll(cno.getCompositeAsList()); + } + } + + if (responses == null || responses.isEmpty()) { + throw new IllegalArgumentException("At least one CompositeResponseObject is mandatory."); + } + this.responses = responses; + + if (svecList != null) { + this.svecList = svecList; + } else { + this.svecList = Collections.emptyList(); + } + } + + /** + * Gets list of {@link CompositeResponseObject}. + * + * @return List. Can't be null or empty. + */ + public List getResponses() { + return this.responses; + } + + /** + * Gets list of {@link CompositeReplySvecObject}. + * + * @return List. Can't be null but may be empty. + */ + public List getSvecList() { + return this.svecList; + } + + public List getAllObjects() { + return this.objects; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.responses == null) ? 0 : this.responses.hashCode()); + result = prime * result + ((this.svecList == null) ? 0 : this.svecList.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + final PCEPReplyMessage other = (PCEPReplyMessage) obj; + if (this.responses == null) { + if (other.responses != null) { + return false; + } + } else if (!this.responses.equals(other.responses)) { + return false; + } + if (this.svecList == null) { + if (other.svecList != null) { + return false; + } + } else if (!this.svecList.equals(other.svecList)) { + return false; + } + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("PCEPReplyMessage [svecList="); + builder.append(this.svecList); + builder.append(", responses="); + builder.append(this.responses); + builder.append("]"); + return builder.toString(); + } + + @Override + public Class getImplementedInterface() { + return Message.class; + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPReportMessage.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPReportMessage.java new file mode 100644 index 0000000000..8b1d3eaf74 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPReportMessage.java @@ -0,0 +1,106 @@ +/* + * 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.message; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.object.CompositeStateReportObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; + +import com.google.common.collect.Lists; + +/** + * Structure of Report Message + * + * @see State Report Message + */ +public class PCEPReportMessage implements Message { + + private final List reports; + + private final List objects; + + /** + * Constructs {@link PCEPReportMessage}. + * + * @throws IllegalArgumentException if there is not even one {@link CompositeStateReportObject} in the list. + * + * @param reports List. Can't be empty or null. + */ + public PCEPReportMessage(final List reports) { + this.objects = Lists.newArrayList(); + if (reports != null) { + for (final CompositeStateReportObject csro : reports) { + this.objects.addAll(csro.getCompositeAsList()); + } + } + if (reports == null || reports.isEmpty()) { + throw new IllegalArgumentException("At least one CompositeStateReportObject is mandatory."); + } + + this.reports = reports; + } + + /** + * Gets list of {@link CompositeStateReportObject}. + * + * @return List. Can't be null or empty. + */ + public List getStateReports() { + return this.reports; + } + + public List getAllObjects() { + return this.objects; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.reports == null) ? 0 : this.reports.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + final PCEPReportMessage other = (PCEPReportMessage) obj; + if (this.reports == null) { + if (other.reports != null) { + return false; + } + } else if (!this.reports.equals(other.reports)) { + return false; + } + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("PCEPReportMessage [reports="); + builder.append(this.reports); + builder.append("]"); + return builder.toString(); + } + + @Override + public Class getImplementedInterface() { + return Message.class; + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPRequestMessage.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPRequestMessage.java new file mode 100644 index 0000000000..fecd3fedcb --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPRequestMessage.java @@ -0,0 +1,153 @@ +/* + * 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.message; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.object.CompositeRequestObject; +import org.opendaylight.protocol.pcep.object.CompositeRequestSvecObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; + +import com.google.common.collect.Lists; + +/** + * Structure of Request Message. + * + * @see Request Message + */ +public class PCEPRequestMessage implements Message { + + private final List svecList; + + private final List requests; + + private final List objects; + + /** + * Constructs new Request Message. + * + * @throws IllegalArgumentException if there is not even one {@link CompositeRequestObject} in the list. + * + * @param requests List. Can't be empty or null. + */ + public PCEPRequestMessage(final List requests) { + this(null, requests); + } + + /** + * Constructs new Request Message. + * + * @throws IllegalArgumentException if there is not even one {@link CompositeRequestObject} in the list. + * + * @param svecList List + * @param requests List. Can't be null or empty. + */ + public PCEPRequestMessage(final List svecList, final List requests) { + this.objects = Lists.newArrayList(); + if (svecList != null) { + for (final CompositeRequestSvecObject cso : svecList) { + this.objects.addAll(cso.getCompositeAsList()); + } + } + if (requests != null) { + for (final CompositeRequestObject cro : requests) { + this.objects.addAll(cro.getCompositeAsList()); + } + } + + if (svecList != null) { + this.svecList = svecList; + } else { + this.svecList = Collections.emptyList(); + } + + if (requests == null || requests.isEmpty()) { + throw new IllegalArgumentException("At least one CompositeRequestObject is mandatory."); + } + this.requests = requests; + + } + + /** + * Gets list of {@link CompositeRequestSvecObject}. + * + * @return List. Can't be null, but may be empty. + */ + public List getSvecObjects() { + return this.svecList; + } + + /** + * Gets list of {@link CompositeRequestObject}. + * + * @return List. Can't be null or empty. + */ + public List getRequests() { + return this.requests; + } + + public List getAllObjects() { + return this.objects; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.requests == null) ? 0 : this.requests.hashCode()); + result = prime * result + ((this.svecList == null) ? 0 : this.svecList.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + final PCEPRequestMessage other = (PCEPRequestMessage) obj; + if (this.requests == null) { + if (other.requests != null) { + return false; + } + } else if (!this.requests.equals(other.requests)) { + return false; + } + if (this.svecList == null) { + if (other.svecList != null) { + return false; + } + } else if (!this.svecList.equals(other.svecList)) { + return false; + } + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("PCEPRequestMessage [svecObjs="); + builder.append(this.svecList); + builder.append(", requests="); + builder.append(this.requests); + builder.append("]"); + return builder.toString(); + } + + @Override + public Class getImplementedInterface() { + return Message.class; + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPUpdateRequestMessage.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPUpdateRequestMessage.java new file mode 100644 index 0000000000..32fba964fc --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/message/PCEPUpdateRequestMessage.java @@ -0,0 +1,106 @@ +/* + * 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.message; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.object.CompositeUpdateRequestObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; + +import com.google.common.collect.Lists; + +/** + * Structure of Update Request Message. + * + * @see Update Request Message + */ +public class PCEPUpdateRequestMessage implements Message { + + private final List updateRequests; + + private final List objects; + + /** + * Constructs new Update Request Message. + * + * @throws IllegalArgumentException if there is not even one {@link CompositeUpdateRequestObject} in the list. + * + * @param updateRequests List. Can't be empty or null. + */ + public PCEPUpdateRequestMessage(final List updateRequests) { + this.objects = Lists.newArrayList(); + if (updateRequests != null) { + for (final CompositeUpdateRequestObject curo : updateRequests) { + this.objects.addAll(curo.getCompositeAsList()); + } + } + + if (updateRequests == null || updateRequests.isEmpty()) { + throw new IllegalArgumentException("At least one CompositeUpdateRequestObject is mandatory."); + } + this.updateRequests = updateRequests; + } + + /** + * Gets list of {@link CompositeUpdateRequestObject}. + * + * @return List. Can't be null or empty. + */ + public List getUpdateRequests() { + return this.updateRequests; + } + + public List getAllObjects() { + return this.objects; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.updateRequests == null) ? 0 : this.updateRequests.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + final PCEPUpdateRequestMessage other = (PCEPUpdateRequestMessage) obj; + if (this.updateRequests == null) { + if (other.updateRequests != null) { + return false; + } + } else if (!this.updateRequests.equals(other.updateRequests)) { + return false; + } + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("PCEPUpdateRequestMessage [updateRequests="); + builder.append(this.updateRequests); + builder.append("]"); + return builder.toString(); + } + + @Override + public Class getImplementedInterface() { + return Message.class; + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeErrorObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeErrorObject.java new file mode 100644 index 0000000000..e657b7b2fa --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeErrorObject.java @@ -0,0 +1,196 @@ +/* + * 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.object; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; + +/** + * Structure that combines set of related objects. + * + * @see Error (PCErr) + * Message - <error> + */ +public class CompositeErrorObject { + + private List requestParameters; + + private final List errors; + + public CompositeErrorObject(final PCEPRequestParameterObject requestParameter, final PCEPErrorObject error) { + this(new ArrayList() { + private static final long serialVersionUID = -3974192068960284132L; + + { + if (requestParameter != null) + this.add(requestParameter); + } + }, new ArrayList() { + private static final long serialVersionUID = -3976331879683713909L; + + { + if (error != null) + this.add(error); + } + }); + } + + /** + * Constructs basic composite object only with mandatory objects. + * + * @param errors + * List. Can't be null or empty. + */ + public CompositeErrorObject(List errors) { + this(null, errors); + } + + /** + * Constructs composite object with optional objects. + * + * @param requestParameters + * List + * @param errors + * List. Can't be null or empty. + */ + public CompositeErrorObject(List requestParameters, List errors) { + + if (errors == null || errors.isEmpty()) + throw new IllegalArgumentException("Error Object is mandatory."); + this.errors = errors; + if (requestParameters != null) + this.requestParameters = requestParameters; + else + this.requestParameters = Collections.emptyList(); + } + + /** + * Gets list of all objects, which are in appropriate order. + * + * @return List. Can't be null or empty. + */ + public List getCompositeAsList() { + final List list = new ArrayList(); + if (this.requestParameters != null && !this.requestParameters.isEmpty()) + list.addAll(this.requestParameters); + list.addAll(this.errors); + return list; + } + + /** + * Creates this object from a list of PCEPObjects. + * + * @param objects + * List list of PCEPObjects from whose this object + * should be created. + * @return CompositeErrorObject + */ + public static CompositeErrorObject getCompositeFromList(List objects) { + if (objects == null || objects.isEmpty()) + throw new IllegalArgumentException("List cannot be null or empty."); + + final List requestParameters = new ArrayList(); + final List errors = new ArrayList(); + + int state = 1; + while (!objects.isEmpty()) { + final PCEPObject obj = objects.get(0); + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPRequestParameterObject) { + requestParameters.add((PCEPRequestParameterObject) obj); + state = 1; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPErrorObject) { + errors.add((PCEPErrorObject) obj); + state = 2; + break; + } + } + + if (state == 3) { + break; + } + + objects.remove(obj); + } + + if (errors.isEmpty()) + throw new IllegalArgumentException("Atleast one PCEPErrorObject is mandatory."); + + return new CompositeErrorObject(requestParameters, errors); + } + + /** + * Gets list of {@link PCEPRequestParameterObject}. + * + * @return List. Can't be null, but may be + * empty. + */ + public List getRequestParameters() { + return this.requestParameters; + } + + /** + * Gets list of {@link PCEPErrorObject} + * + * @return List. Can't be null or empty. + */ + public List getErrors() { + return this.errors; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.errors == null) ? 0 : this.errors.hashCode()); + result = prime * result + ((this.requestParameters == null) ? 0 : this.requestParameters.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final CompositeErrorObject other = (CompositeErrorObject) obj; + if (this.errors == null) { + if (other.errors != null) + return false; + } else if (!this.errors.equals(other.errors)) + return false; + if (this.requestParameters == null) { + if (other.requestParameters != null) + return false; + } else if (!this.requestParameters.equals(other.requestParameters)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("CompositeErrorObject [requestParameters="); + builder.append(this.requestParameters); + builder.append(", errors="); + builder.append(this.errors); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeInstantiationObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeInstantiationObject.java new file mode 100644 index 0000000000..83c9615ea5 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeInstantiationObject.java @@ -0,0 +1,254 @@ +/* + * 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.object; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; + +import com.google.common.base.Preconditions; + +/** + * Structure that combines set of related objects. + * + * @see PCCreate Message + */ +public class CompositeInstantiationObject { + + private final PCEPEndPointsObject endPoints; + + private final PCEPLspaObject lspa; + + private final PCEPExplicitRouteObject ero; + + private final PCEPRequestedPathBandwidthObject bandwidth; + + private final List metrics; + + /** + * Constructs basic composite object only with mandatory objects. + * + * @param endPoints PCEPEndPointsObject. Can't be null. + * @param lspa PCEPLspaObject. Can't be null. + */ + public CompositeInstantiationObject(final PCEPEndPointsObject endPoints, final PCEPLspaObject lspa) { + this(endPoints, lspa, null, null, null); + } + + /** + * Constructs composite object with optional objects. + * + * @param endPoints PCEPEndPointsObject. Can't be null. + * @param lspa PCEPLspaObject. Can't be null. + * @param ero PCEPExplicitRouteObject + * @param bandwidth PCEPRequestedPathBandwidthObject + * @param metrics List + */ + public CompositeInstantiationObject(final PCEPEndPointsObject endPoints, final PCEPLspaObject lspa, + final PCEPExplicitRouteObject ero, final PCEPRequestedPathBandwidthObject bandwidth, final List metrics) { + this.endPoints = Preconditions.checkNotNull(endPoints); + this.lspa = Preconditions.checkNotNull(lspa); + this.ero = ero; + this.bandwidth = bandwidth; + this.metrics = metrics; + } + + /** + * Gets list of all objects, which are in appropriate order. + * + * @return List. Can't be null or empty. + */ + public List getCompositeAsList() { + final List list = new ArrayList(); + list.add(this.endPoints); + list.add(this.lspa); + if (this.ero != null) + list.add(this.ero); + if (this.bandwidth != null) + list.add(this.bandwidth); + if (this.metrics != null && !this.metrics.isEmpty()) + list.addAll(this.metrics); + return list; + } + + /** + * Creates this object from a list of PCEPObjects. + * + * @param objects List list of PCEPObjects from whose this object should be created. + * @return CompositeInstantiationObject + */ + public static CompositeInstantiationObject getCompositeFromList(final List objects) { + if (objects == null || objects.isEmpty()) { + throw new IllegalArgumentException("List cannot be null or empty."); + } + + PCEPEndPointsObject endPoints = null; + if (objects.get(0) instanceof PCEPEndPointsObject) { + endPoints = (PCEPEndPointsObject) objects.get(0); + objects.remove(endPoints); + } else + throw new IllegalArgumentException("End Points object must be first."); + + PCEPLspaObject lspa = null; + if (objects.get(0) instanceof PCEPLspaObject) { + lspa = (PCEPLspaObject) objects.get(0); + objects.remove(lspa); + } else + throw new IllegalArgumentException("LSPA object must be second."); + + PCEPExplicitRouteObject ero = null; + PCEPRequestedPathBandwidthObject bandwidth = null; + final List metrics = new ArrayList(); + + int state = 1; + while (!objects.isEmpty()) { + final PCEPObject obj = objects.get(0); + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPExplicitRouteObject) { + ero = (PCEPExplicitRouteObject) obj; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPRequestedPathBandwidthObject) { + bandwidth = (PCEPRequestedPathBandwidthObject) obj; + break; + } + case 3: + state = 4; + if (obj instanceof PCEPMetricObject) { + metrics.add((PCEPMetricObject) obj); + state = 3; + + break; + } + } + + if (state == 4) { + break; + } + + objects.remove(obj); + } + + return new CompositeInstantiationObject(endPoints, lspa, ero, bandwidth, metrics); + } + + /** + * @return the endPoints + */ + public final PCEPEndPointsObject getEndPoints() { + return this.endPoints; + } + + /** + * @return the lspa + */ + public final PCEPLspaObject getLspa() { + return this.lspa; + } + + /** + * @return the ero + */ + public final PCEPExplicitRouteObject getEro() { + return this.ero; + } + + /** + * @return the bandwidth + */ + public final PCEPRequestedPathBandwidthObject getBandwidth() { + return this.bandwidth; + } + + /** + * @return the metrics + */ + public final List getMetrics() { + return this.metrics; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.bandwidth == null) ? 0 : this.bandwidth.hashCode()); + result = prime * result + ((this.endPoints == null) ? 0 : this.endPoints.hashCode()); + result = prime * result + ((this.ero == null) ? 0 : this.ero.hashCode()); + result = prime * result + ((this.lspa == null) ? 0 : this.lspa.hashCode()); + result = prime * result + ((this.metrics == null) ? 0 : this.metrics.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof CompositeInstantiationObject)) + return false; + final CompositeInstantiationObject other = (CompositeInstantiationObject) obj; + if (this.bandwidth == null) { + if (other.bandwidth != null) + return false; + } else if (!this.bandwidth.equals(other.bandwidth)) + return false; + if (this.endPoints == null) { + if (other.endPoints != null) + return false; + } else if (!this.endPoints.equals(other.endPoints)) + return false; + if (this.ero == null) { + if (other.ero != null) + return false; + } else if (!this.ero.equals(other.ero)) + return false; + if (this.lspa == null) { + if (other.lspa != null) + return false; + } else if (!this.lspa.equals(other.lspa)) + return false; + if (this.metrics == null) { + if (other.metrics != null) + return false; + } else if (!this.metrics.equals(other.metrics)) + return false; + return true; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("CompositeInstantiationObject [endPoints="); + builder.append(this.endPoints); + builder.append(", lspa="); + builder.append(this.lspa); + builder.append(", ero="); + builder.append(this.ero); + builder.append(", bandwidth="); + builder.append(this.bandwidth); + builder.append(", metrics="); + builder.append(this.metrics); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeNotifyObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeNotifyObject.java new file mode 100644 index 0000000000..6e9ebd55a7 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeNotifyObject.java @@ -0,0 +1,175 @@ +/* + * 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.object; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; + +/** + * Structure that combines set of related objects. + * + * @see Notification + * (PCNtf) Message - <notify> + */ +public class CompositeNotifyObject { + + private List requestParameters; + + private final List notifications; + + /** + * Constructs basic composite object only with mandatory objects. + * + * @param notifications + * List. Can't be null or empty. + */ + public CompositeNotifyObject(List notifications) { + this(null, notifications); + } + + /** + * Constructs composite object with optional objects. + * + * @param requestParameters + * List + * @param notifications + * List. Can't be null or empty. + */ + public CompositeNotifyObject(List requestParameters, List notifications) { + if (notifications == null || notifications.isEmpty()) + throw new IllegalArgumentException("Notification Object is mandatory."); + if (requestParameters != null) + this.requestParameters = requestParameters; + else + this.requestParameters = Collections.emptyList(); + this.notifications = notifications; + } + + /** + * Gets list of all objects, which are in appropriate order. + * + * @return List + */ + public List getCompositeAsList() { + final List list = new ArrayList(); + if (this.requestParameters != null && !this.requestParameters.isEmpty()) + list.addAll(this.requestParameters); + list.addAll(this.notifications); + return list; + } + + /** + * Creates this object from a list of PCEPObjects. + * @param objects List list of PCEPObjects from whose this + * object should be created. + * @return CompositeNotifyObject + */ + public static CompositeNotifyObject getCompositeFromList(List objects) { + if (objects == null || objects.isEmpty()) + throw new IllegalArgumentException("List cannot be null or empty."); + + final List requestParameters = new ArrayList(); + final List notifications = new ArrayList(); + + int state = 1; + while (!objects.isEmpty()) { + final PCEPObject obj = objects.get(0); + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPRequestParameterObject) { + requestParameters.add((PCEPRequestParameterObject) obj); + state = 1; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPNotificationObject) { + notifications.add((PCEPNotificationObject) obj); + state = 2; + break; + } + } + + if (state == 3) { + break; + } + + objects.remove(obj); + } + + if (notifications.isEmpty()) + return null; + + return new CompositeNotifyObject(requestParameters, notifications); + } + + /** + * Gets list of {@link PCEPRequestParameterObject}. + * + * @return List. Can't be null, but may be + * empty. + */ + public List getRequestParameters() { + return this.requestParameters; + } + + /** + * Gets list of {@link PCEPNotificationObject}. + * + * @return List. Can't be null or empty. + */ + public List getNotificationObjects() { + return this.notifications; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.notifications == null) ? 0 : this.notifications.hashCode()); + result = prime * result + ((this.requestParameters == null) ? 0 : this.requestParameters.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final CompositeNotifyObject other = (CompositeNotifyObject) obj; + if (this.notifications == null) { + if (other.notifications != null) + return false; + } else if (!this.notifications.equals(other.notifications)) + return false; + if (this.requestParameters == null) { + if (other.requestParameters != null) + return false; + } else if (!this.requestParameters.equals(other.requestParameters)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("CompositeNotifyObject [requestParameters="); + builder.append(this.requestParameters); + builder.append(", notifications="); + builder.append(this.notifications); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositePathObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositePathObject.java new file mode 100644 index 0000000000..0c00caee6d --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositePathObject.java @@ -0,0 +1,267 @@ +/* + * 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.object; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; + +/** + * Structure that combines set of related objects. + * + * @see Path + * Computation Reply (PCRep) Message - <path>
Same for every + * usage of path object. + */ +public class CompositePathObject { + + private final PCEPExplicitRouteObject explicitRoute; + + private final PCEPLspaObject lspa; + + private final PCEPRequestedPathBandwidthObject bandwidth; + + private List metrics; + + private final PCEPIncludeRouteObject includeRoute; + + /** + * Constructs basic composite object only with mandatory objects. + * + * @param explicitRoute + * PCEPExplicitRouteObject. Can't be null or empty. + */ + public CompositePathObject(PCEPExplicitRouteObject explicitRoute) { + this(explicitRoute, null, null, null, null); + } + + /** + * Constructs composite object with optional objects. + * + * @param explicitRoute + * PCEPExplicitRouteObject. Can't be null or empty. + * @param lspa + * PCEPLspaObject + * @param bandwidth + * PCEPRequestedPathBandwidthObject + * @param metrics + * List + * @param includeRoute + * PCEPIncludeRouteObject + */ + public CompositePathObject(PCEPExplicitRouteObject explicitRoute, PCEPLspaObject lspa, PCEPRequestedPathBandwidthObject bandwidth, + List metrics, PCEPIncludeRouteObject includeRoute) { + if (explicitRoute == null) + throw new IllegalArgumentException("Explicit Route Object is mandatory."); + this.explicitRoute = explicitRoute; + this.lspa = lspa; + this.bandwidth = bandwidth; + if (metrics != null) + this.metrics = metrics; + else + this.metrics = Collections.emptyList(); + this.includeRoute = includeRoute; + } + + /** + * Gets list of all objects, which are in appropriate order. + * + * @return List. Can't be null or empty. + */ + public List getCompositeAsList() { + final List list = new ArrayList(); + list.add(this.explicitRoute); + if (this.lspa != null) + list.add(this.lspa); + if (this.bandwidth != null) + list.add(this.bandwidth); + if (this.metrics != null && !this.metrics.isEmpty()) + list.addAll(this.metrics); + if (this.includeRoute != null) + list.add(this.includeRoute); + return list; + } + + /** + * Creates this object from a list of PCEPObjects. + * @param objects List list of PCEPObjects from whose this + * object should be created. + * @return CompositePathObject + */ + public static CompositePathObject getCompositeFromList(List objects) { + if (objects == null || objects.isEmpty()) { + throw new IllegalArgumentException("List cannot be null or empty."); + } + + PCEPExplicitRouteObject explicitRoute = null; + if (objects.get(0) instanceof PCEPExplicitRouteObject) { + explicitRoute = (PCEPExplicitRouteObject) objects.get(0); + objects.remove(explicitRoute); + } else + return null; + + PCEPLspaObject lspa = null; + PCEPRequestedPathBandwidthObject bandwidth = null; + final List metrics = new ArrayList(); + PCEPIncludeRouteObject iro = null; + + int state = 1; + while (!objects.isEmpty()) { + final PCEPObject obj = objects.get(0); + + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPLspaObject) { + lspa = (PCEPLspaObject) obj; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPRequestedPathBandwidthObject) { + bandwidth = (PCEPRequestedPathBandwidthObject) obj; + break; + } + case 3: + if (obj instanceof PCEPMetricObject) { + metrics.add((PCEPMetricObject) obj); + state = 3; + break; + } else + state = 4; + case 4: + if (obj instanceof PCEPIncludeRouteObject) { + iro = (PCEPIncludeRouteObject) obj; + break; + } + state = 5; + } + + if (state == 5) { + break; + } + + objects.remove(obj); + } + + return new CompositePathObject(explicitRoute, lspa, bandwidth, metrics, iro); + } + + /** + * Gets {@link PCEPExplicitRouteObject}. + * + * @return PCEPExplicitRouteObject. Can't be null. + */ + public PCEPExplicitRouteObject getExcludedRoute() { + return this.explicitRoute; + } + + /** + * Gets {@link PCEPLspaObject}. + * + * @return PCEPLspaObject. May be null. + */ + public PCEPLspaObject getLspa() { + return this.lspa; + } + + /** + * Gets {@link PCEPBandwidthObject}. + * + * @return PCEPBandwidthObject. May be null. + */ + public PCEPBandwidthObject getBandwidth() { + return this.bandwidth; + } + + /** + * Gets list of {@link PCEPMetricObject}. + * + * @return List. Can't be null, but may be empty. + */ + public List getMetrics() { + return this.metrics; + } + + /** + * Gets {@link PCEPIncludeRouteObject}. + * + * @return PCEPIncludeRouteObject. May be null. + */ + public PCEPIncludeRouteObject getIncludeRoute() { + return this.includeRoute; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.bandwidth == null) ? 0 : this.bandwidth.hashCode()); + result = prime * result + ((this.explicitRoute == null) ? 0 : this.explicitRoute.hashCode()); + result = prime * result + ((this.includeRoute == null) ? 0 : this.includeRoute.hashCode()); + result = prime * result + ((this.lspa == null) ? 0 : this.lspa.hashCode()); + result = prime * result + ((this.metrics == null) ? 0 : this.metrics.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final CompositePathObject other = (CompositePathObject) obj; + if (this.bandwidth == null) { + if (other.bandwidth != null) + return false; + } else if (!this.bandwidth.equals(other.bandwidth)) + return false; + if (this.explicitRoute == null) { + if (other.explicitRoute != null) + return false; + } else if (!this.explicitRoute.equals(other.explicitRoute)) + return false; + if (this.includeRoute == null) { + if (other.includeRoute != null) + return false; + } else if (!this.includeRoute.equals(other.includeRoute)) + return false; + if (this.lspa == null) { + if (other.lspa != null) + return false; + } else if (!this.lspa.equals(other.lspa)) + return false; + if (this.metrics == null) { + if (other.metrics != null) + return false; + } else if (!this.metrics.equals(other.metrics)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("CompositePathObject [explicitRoute="); + builder.append(this.explicitRoute); + builder.append(", lspa="); + builder.append(this.lspa); + builder.append(", bandwidth="); + builder.append(this.bandwidth); + builder.append(", metrics="); + builder.append(this.metrics); + builder.append(", includeRoute="); + builder.append(this.includeRoute); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeReplySvecObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeReplySvecObject.java new file mode 100644 index 0000000000..41d4c7fb91 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeReplySvecObject.java @@ -0,0 +1,200 @@ +/* + * 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.object; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.message.PCEPReplyMessage; + +/** + * Composite SvecObject used in {@link PCEPReplyMessage} + */ +public class CompositeReplySvecObject { + + private final PCEPSvecObject svec; + private final PCEPObjectiveFunctionObject objectiveFunction; + private final List metrics; + + /** + * Constructs basic composite object only with mandatory objects. + * + * @param svec + * PCEPSvecObject + */ + public CompositeReplySvecObject(PCEPSvecObject svec) { + this(svec, null, null); + } + + /** + * Constructs composite object also with optional objects. + * + * @param svec + * PCEPSvecObject + * @param objectiveFunction + * PCEPObjectiveFunctionObject + * @param metrics + * list of PCEPMetricObject + */ + public CompositeReplySvecObject(PCEPSvecObject svec, PCEPObjectiveFunctionObject objectiveFunction, List metrics) { + if (svec == null) + throw new IllegalArgumentException("Svec object is mandatory."); + this.svec = svec; + this.objectiveFunction = objectiveFunction; + if (metrics != null) + this.metrics = metrics; + else + this.metrics = Collections.emptyList(); + } + + /** + * Gets list of all objects, which are in appropriate order. + * + * @return List. Can't be null or empty. + */ + public List getCompositeAsList() { + final List list = new ArrayList(); + list.add(this.svec); + if (this.objectiveFunction != null) + list.add(this.objectiveFunction); + if (this.metrics != null && !this.metrics.isEmpty()) + list.addAll(this.metrics); + return list; + } + + /** + * Creates this object from a list of PCEPObjects. + * + * @param objects + * List list of PCEPObjects from whose this object + * should be created. + * @return CompositePathObject + */ + public static CompositeReplySvecObject getCompositeFromList(List objects) { + if (objects == null || objects.isEmpty()) { + throw new IllegalArgumentException("List cannot be null or empty."); + } + + PCEPSvecObject svec = null; + if (objects.get(0) instanceof PCEPSvecObject) { + svec = (PCEPSvecObject) objects.get(0); + objects.remove(svec); + } else + return null; + + PCEPObjectiveFunctionObject of = null; + final List metrics = new ArrayList(); + + int state = 1; + while (!objects.isEmpty()) { + final PCEPObject obj = objects.get(0); + + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPObjectiveFunctionObject) { + of = (PCEPObjectiveFunctionObject) obj; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPMetricObject) { + metrics.add((PCEPMetricObject) obj); + state = 2; + + break; + } + } + + if (state == 3) + break; + + objects.remove(obj); + } + + return new CompositeReplySvecObject(svec, of, metrics); + } + + /** + * Gets {@link PCEPSvecObject} + * + * @return PCEPSvecObject. Can't be null. + */ + public PCEPSvecObject getSvec() { + return this.svec; + } + + /** + * Gets {@link PCEPObjectiveFunctionObject} + * + * @return PCEPObjectiveFunctionObject. May be null. + */ + public PCEPObjectiveFunctionObject getObjectiveFunction() { + return this.objectiveFunction; + } + + /** + * @return the metrics + */ + public List getMetrics() { + return this.metrics; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("CompositeReplySvecObject [svec="); + builder.append(this.svec); + builder.append(", objectiveFunction="); + builder.append(this.objectiveFunction); + builder.append(", metrics="); + builder.append(this.metrics); + builder.append("]"); + return builder.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.metrics == null) ? 0 : this.metrics.hashCode()); + result = prime * result + ((this.objectiveFunction == null) ? 0 : this.objectiveFunction.hashCode()); + result = prime * result + ((this.svec == null) ? 0 : this.svec.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final CompositeReplySvecObject other = (CompositeReplySvecObject) obj; + if (this.metrics == null) { + if (other.metrics != null) + return false; + } else if (!this.metrics.equals(other.metrics)) + return false; + if (this.objectiveFunction == null) { + if (other.objectiveFunction != null) + return false; + } else if (!this.objectiveFunction.equals(other.objectiveFunction)) + return false; + if (this.svec == null) { + if (other.svec != null) + return false; + } else if (!this.svec.equals(other.svec)) + return false; + return true; + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeRequestObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeRequestObject.java new file mode 100644 index 0000000000..392c5a32e9 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeRequestObject.java @@ -0,0 +1,463 @@ +/* + * 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.object; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; + +/** + * Structure that combines set of related objects. + * + * @see Path + * Computation Request (PCReq) Message - <request>
+ * + * @see Path Computation + * Request Message with CLASSTYPE Object + */ +public class CompositeRequestObject { + + private final PCEPRequestParameterObject requestParameter; + + private final PCEPEndPointsObject endPoints; + + private final PCEPClassTypeObject classType; + + private final PCEPLspObject lsp; + + private final PCEPLspaObject lspa; + + private final PCEPRequestedPathBandwidthObject bandwidth; + + private final List metrics; + + private final PCEPReportedRouteObject reportedRoute; + + private final PCEPExistingPathBandwidthObject rroBandwidth; + + private final PCEPIncludeRouteObject includeRoute; + + private final PCEPLoadBalancingObject loadBalancing; + + /** + * Constructs basic composite object only with mandatory objects. + * + * @param requestParameter + * PCEPRequestParameterObject. Can't be null. + * @param endPoints + * PCEPEndPointsObject. Can't be null. + */ + public CompositeRequestObject(PCEPRequestParameterObject requestParameter, PCEPEndPointsObject endPoints) { + this(requestParameter, endPoints, null, null, null, null, null, null, null, null, null); + } + + /** + * Constructs composite object with optional objects. + * + * @param requestParameter + * PCEPRequestParameterObject. Can't be null. + * @param endPoints + * PCEPEndPointsObject. Can't be null. + * @param classType + * PCEPClassTypeObject + * @param lsp + * PCEPLspObject + * @param lspa + * PCEPLspaObject + * @param bandwidth + * PCEPRequestedPathBandwidthObject + * @param metrics + * List + * @param reportedRoute + * PCEPReportedRouteObject + * @param rroBandwidth + * PCEPExistingPathBandwidthObject + * @param includeRoute + * PCEPIncludeRouteObject + * @param loadBalancing + * PCEPLoadBalancingObject + */ + public CompositeRequestObject(PCEPRequestParameterObject requestParameter, PCEPEndPointsObject endPoints, PCEPClassTypeObject classType, + PCEPLspObject lsp, PCEPLspaObject lspa, PCEPRequestedPathBandwidthObject bandwidth, List metrics, + PCEPReportedRouteObject reportedRoute, PCEPExistingPathBandwidthObject rroBandwidth, PCEPIncludeRouteObject includeRoute, + PCEPLoadBalancingObject loadBalancing) { + if (requestParameter == null) + throw new IllegalArgumentException("Request Parameter Object is mandatory."); + if (endPoints == null) + throw new IllegalArgumentException("End-Points Object is mandatory."); + this.requestParameter = requestParameter; + this.endPoints = endPoints; + this.classType = classType; + this.lsp = lsp; + this.lspa = lspa; + this.bandwidth = bandwidth; + if (metrics != null) + this.metrics = metrics; + else + this.metrics = Collections.emptyList(); + this.reportedRoute = reportedRoute; + this.rroBandwidth = rroBandwidth; + this.includeRoute = includeRoute; + this.loadBalancing = loadBalancing; + } + + /** + * Gets list of all objects, which are in appropriate order. + * + * @return List. Can't be null or empty. + */ + public List getCompositeAsList() { + final List list = new ArrayList(); + list.add(this.requestParameter); + list.add(this.endPoints); + if (this.classType != null) + list.add(this.classType); + if (this.lsp != null) + list.add(this.lsp); + if (this.lspa != null) + list.add(this.lspa); + if (this.bandwidth != null) + list.add(this.bandwidth); + if (this.metrics != null && !this.metrics.isEmpty()) + list.addAll(this.metrics); + if (this.reportedRoute != null) { + list.add(this.reportedRoute); + if (this.rroBandwidth != null) + list.add(this.rroBandwidth); + } + if (this.includeRoute != null) + list.add(this.includeRoute); + if (this.loadBalancing != null) + list.add(this.loadBalancing); + return list; + } + + /** + * Creates this object from a list of PCEPObjects. + * + * @param objects + * List list of PCEPObjects from whose this object + * should be created. + * @return CompositeRequestObject + */ + public static CompositeRequestObject getCompositeFromList(List objects) { + if (objects == null || objects.isEmpty()) { + throw new IllegalArgumentException("List cannot be null or empty."); + } + PCEPRequestParameterObject requestParameter = null; + if (objects.get(0) instanceof PCEPRequestParameterObject) { + requestParameter = (PCEPRequestParameterObject) objects.get(0); + objects.remove(requestParameter); + } else + return null; + + PCEPEndPointsObject endPoints = null; + if (objects.get(0) instanceof PCEPEndPointsObject) { + endPoints = (PCEPEndPointsObject) objects.get(0); + objects.remove(endPoints); + } else + throw new IllegalArgumentException("End Points object must be second."); + + PCEPClassTypeObject classType = null; + PCEPLspObject lsp = null; + PCEPLspaObject lspa = null; + PCEPRequestedPathBandwidthObject bandwidth = null; + final List metrics = new ArrayList(); + PCEPReportedRouteObject rro = null; + PCEPExistingPathBandwidthObject rroBandwidth = null; + PCEPIncludeRouteObject iro = null; + PCEPLoadBalancingObject loadBalancing = null; + + int state = 1; + while (!objects.isEmpty()) { + final PCEPObject obj = objects.get(0); + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPClassTypeObject) { + classType = (PCEPClassTypeObject) obj; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPLspObject) { + lsp = (PCEPLspObject) obj; + break; + } + case 3: + state = 4; + if (obj instanceof PCEPLspaObject) { + lspa = (PCEPLspaObject) obj; + break; + } + case 4: + state = 5; + if (obj instanceof PCEPRequestedPathBandwidthObject) { + bandwidth = (PCEPRequestedPathBandwidthObject) obj; + break; + } + case 5: + state = 6; + if (obj instanceof PCEPMetricObject) { + metrics.add((PCEPMetricObject) obj); + state = 5; + + break; + } + case 6: + state = 8; + if (obj instanceof PCEPReportedRouteObject) { + rro = (PCEPReportedRouteObject) obj; + state = 7; + break; + } + case 7: + state = 8; + if (obj instanceof PCEPExistingPathBandwidthObject) { + rroBandwidth = (PCEPExistingPathBandwidthObject) obj; + break; + } + case 8: + state = 9; + if (obj instanceof PCEPIncludeRouteObject) { + iro = (PCEPIncludeRouteObject) obj; + break; + } + case 9: + if (obj instanceof PCEPLoadBalancingObject) { + loadBalancing = (PCEPLoadBalancingObject) obj; + break; + } + state = 10; + } + + if (state == 10) { + break; + } + + objects.remove(obj); + } + + return new CompositeRequestObject(requestParameter, endPoints, classType, lsp, lspa, bandwidth, metrics, rro, rroBandwidth, iro, loadBalancing); + } + + /** + * Gets {@link PCEPRequestParameterObject}. + * + * @return PCEPRequestParameterObject. Can't be null. + */ + public PCEPRequestParameterObject getRequestParameter() { + return this.requestParameter; + } + + /** + * Gets {@link PCEPEndPointsObject}. + * + * @return PCEPEndPointsObject. Can't be null. + */ + public PCEPEndPointsObject getEndPoints() { + return this.endPoints; + } + + /** + * Gets {@link PCEPClassTypeObject}. + * + * @return PCEPClassTypeObject. May be null. + */ + public PCEPClassTypeObject getClassType() { + return this.classType; + } + + /** + * Gets {@link PCEPLspObject}. + * + * @return PCEPLspObject. May be null. + */ + public PCEPLspObject getLsp() { + return this.lsp; + } + + /** + * Gets {@link PCEPLspaObject}. + * + * @return PCEPLspaObject. May be null. + */ + public PCEPLspaObject getLspa() { + return this.lspa; + } + + /** + * Gets {@link PCEPBandwidthObject}. + * + * @return PCEPBandwidthObject. May be null. + */ + public PCEPBandwidthObject getBandwidth() { + return this.bandwidth; + } + + /** + * Gets list of {@link PCEPMetricObject}. + * + * @return List + */ + public List getMetrics() { + return this.metrics; + } + + /** + * Gets {@link PCEPReportedRouteObject}. + * + * @return PCEPReportedRouteObject. May be null. + */ + public PCEPReportedRouteObject getReportedRoute() { + return this.reportedRoute; + } + + /** + * Gets {@link PCEPBandwidthObject}. + * + * @return PCEPBandwidthObject. May be null. + */ + public PCEPBandwidthObject getRroBandwidth() { + return this.rroBandwidth; + } + + /** + * Gets {@link PCEPIncludeRouteObject}. + * + * @return PCEPIncludeRouteObject. May be null. + */ + public PCEPIncludeRouteObject getIncludeRoute() { + return this.includeRoute; + } + + /** + * Gets {@link PCEPLoadBalancingObject}. + * + * @return PCEPLoadBalancingObject. May be null. + */ + public PCEPLoadBalancingObject getLoadBalancing() { + return this.loadBalancing; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.bandwidth == null) ? 0 : this.bandwidth.hashCode()); + result = prime * result + ((this.classType == null) ? 0 : this.classType.hashCode()); + result = prime * result + ((this.endPoints == null) ? 0 : this.endPoints.hashCode()); + result = prime * result + ((this.includeRoute == null) ? 0 : this.includeRoute.hashCode()); + result = prime * result + ((this.loadBalancing == null) ? 0 : this.loadBalancing.hashCode()); + result = prime * result + ((this.lsp == null) ? 0 : this.lsp.hashCode()); + result = prime * result + ((this.lspa == null) ? 0 : this.lspa.hashCode()); + result = prime * result + ((this.metrics == null) ? 0 : this.metrics.hashCode()); + result = prime * result + ((this.reportedRoute == null) ? 0 : this.reportedRoute.hashCode()); + result = prime * result + ((this.requestParameter == null) ? 0 : this.requestParameter.hashCode()); + result = prime * result + ((this.rroBandwidth == null) ? 0 : this.rroBandwidth.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof CompositeRequestObject)) + return false; + final CompositeRequestObject other = (CompositeRequestObject) obj; + if (this.bandwidth == null) { + if (other.bandwidth != null) + return false; + } else if (!this.bandwidth.equals(other.bandwidth)) + return false; + if (this.classType == null) { + if (other.classType != null) + return false; + } else if (!this.classType.equals(other.classType)) + return false; + if (this.endPoints == null) { + if (other.endPoints != null) + return false; + } else if (!this.endPoints.equals(other.endPoints)) + return false; + if (this.includeRoute == null) { + if (other.includeRoute != null) + return false; + } else if (!this.includeRoute.equals(other.includeRoute)) + return false; + if (this.loadBalancing == null) { + if (other.loadBalancing != null) + return false; + } else if (!this.loadBalancing.equals(other.loadBalancing)) + return false; + if (this.lsp == null) { + if (other.lsp != null) + return false; + } else if (!this.lsp.equals(other.lsp)) + return false; + if (this.lspa == null) { + if (other.lspa != null) + return false; + } else if (!this.lspa.equals(other.lspa)) + return false; + if (this.metrics == null) { + if (other.metrics != null) + return false; + } else if (!this.metrics.equals(other.metrics)) + return false; + if (this.reportedRoute == null) { + if (other.reportedRoute != null) + return false; + } else if (!this.reportedRoute.equals(other.reportedRoute)) + return false; + if (this.requestParameter == null) { + if (other.requestParameter != null) + return false; + } else if (!this.requestParameter.equals(other.requestParameter)) + return false; + if (this.rroBandwidth == null) { + if (other.rroBandwidth != null) + return false; + } else if (!this.rroBandwidth.equals(other.rroBandwidth)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("CompositeRequestObject [requestParameter="); + builder.append(this.requestParameter); + builder.append(", endPoints="); + builder.append(this.endPoints); + builder.append(", classType="); + builder.append(this.classType); + builder.append(", lsp="); + builder.append(this.lsp); + builder.append(", lspa="); + builder.append(this.lspa); + builder.append(", bandwidth="); + builder.append(this.bandwidth); + builder.append(", metrics="); + builder.append(this.metrics); + builder.append(", reportedRoute="); + builder.append(this.reportedRoute); + builder.append(", rroBandwidth="); + builder.append(this.rroBandwidth); + builder.append(", includeRoute="); + builder.append(this.includeRoute); + builder.append(", loadBalancing="); + builder.append(this.loadBalancing); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeRequestSvecObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeRequestSvecObject.java new file mode 100644 index 0000000000..fc348173f6 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeRequestSvecObject.java @@ -0,0 +1,261 @@ +/* + * 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.object; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.message.PCEPRequestMessage; + +/** + * Composite SvecObject used in {@link PCEPRequestMessage} + */ +public class CompositeRequestSvecObject { + + private final PCEPSvecObject svec; + private final PCEPObjectiveFunctionObject objectiveFunction; + private final PCEPGlobalConstraintsObject globalConstraints; + private final PCEPExcludeRouteObject excludeRoute; + private final List metrics; + + /** + * Constructs basic composite object only with mandatory objects. + * + * @param svec + * PCEPSvecObject + */ + public CompositeRequestSvecObject(PCEPSvecObject svec) { + this(svec, null, null, null, null); + } + + /** + * Constructs composite object with optional objects. + * + * @param svec + * PCEPSvecObject + * @param objectiveFunction + * PCEPObjectiveFunctionObject + * @param globalConstraints + * PCEPGlobalConstraints + * @param excludeRoute + * PCEPExcludeRouteObject + * @param metrics + * list of PCEPMetricObject + */ + public CompositeRequestSvecObject(PCEPSvecObject svec, PCEPObjectiveFunctionObject objectiveFunction, PCEPGlobalConstraintsObject globalConstraints, + PCEPExcludeRouteObject excludeRoute, List metrics) { + if (svec == null) + throw new IllegalArgumentException("Svec object is mandatory."); + this.svec = svec; + this.objectiveFunction = objectiveFunction; + this.globalConstraints = globalConstraints; + this.excludeRoute = excludeRoute; + if (metrics != null) + this.metrics = metrics; + else + this.metrics = Collections.emptyList(); + } + + /** + * Gets list of all objects, which are in appropriate order. + * + * @return List. Can't be null or empty. + */ + public List getCompositeAsList() { + final List list = new ArrayList(); + list.add(this.svec); + if (this.objectiveFunction != null) + list.add(this.objectiveFunction); + if (this.globalConstraints != null) + list.add(this.globalConstraints); + if (this.excludeRoute != null) + list.add(this.excludeRoute); + if (this.metrics != null && !this.metrics.isEmpty()) + list.addAll(this.metrics); + return list; + } + + /** + * Creates this object from a list of PCEPObjects. + * + * @param objects + * List list of PCEPObjects from whose this object + * should be created. + * @return CompositePathObject + */ + public static CompositeRequestSvecObject getCompositeFromList(List objects) { + if (objects == null || objects.isEmpty()) { + throw new IllegalArgumentException("List cannot be null or empty."); + } + + PCEPSvecObject svec = null; + if (objects.get(0) instanceof PCEPSvecObject) { + svec = (PCEPSvecObject) objects.get(0); + objects.remove(svec); + } else + return null; + + PCEPObjectiveFunctionObject of = null; + PCEPGlobalConstraintsObject gc = null; + PCEPExcludeRouteObject xro = null; + final List metrics = new ArrayList(); + + int state = 1; + while (!objects.isEmpty()) { + final PCEPObject obj = objects.get(0); + + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPObjectiveFunctionObject) { + of = (PCEPObjectiveFunctionObject) obj; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPGlobalConstraintsObject) { + gc = (PCEPGlobalConstraintsObject) obj; + break; + } + case 3: + state = 4; + if (obj instanceof PCEPExcludeRouteObject) { + xro = (PCEPExcludeRouteObject) obj; + break; + } + case 4: + state = 5; + if (obj instanceof PCEPMetricObject) { + metrics.add((PCEPMetricObject) obj); + state = 4; + + break; + } + } + + if (state == 5) + break; + + objects.remove(obj); + } + + return new CompositeRequestSvecObject(svec, of, gc, xro, metrics); + } + + /** + * Gets {@link PCEPSvecObject} + * + * @return PCEPSvecObject. Can't be null. + */ + public PCEPSvecObject getSvec() { + return this.svec; + } + + /** + * Gets {@link PCEPObjectiveFunctionObject} + * + * @return PCEPObjectiveFunctionObject. May be null. + */ + public PCEPObjectiveFunctionObject getObjectiveFunction() { + return this.objectiveFunction; + } + + /** + * Gets {@link PCEPGlobalConstraintsObject} + * + * @return PCEPGlobalConstraints. May be null. + */ + public PCEPGlobalConstraintsObject getGlobalConstraints() { + return this.globalConstraints; + } + + /** + * Gets {@link PCEPExcludeRouteObject} + * + * @return PCEPExcludeRouteObject. May be null. + */ + public PCEPExcludeRouteObject getExcludeRoute() { + return this.excludeRoute; + } + + /** + * @return the metrics + */ + public List getMetrics() { + return this.metrics; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("CompositeSvecObject [svec="); + builder.append(this.svec); + builder.append(", objectiveFunction="); + builder.append(this.objectiveFunction); + builder.append(", globalConstraints="); + builder.append(this.globalConstraints); + builder.append(", excludeRoute="); + builder.append(this.excludeRoute); + builder.append(", metrics="); + builder.append(this.metrics); + builder.append("]"); + return builder.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.excludeRoute == null) ? 0 : this.excludeRoute.hashCode()); + result = prime * result + ((this.globalConstraints == null) ? 0 : this.globalConstraints.hashCode()); + result = prime * result + ((this.metrics == null) ? 0 : this.metrics.hashCode()); + result = prime * result + ((this.objectiveFunction == null) ? 0 : this.objectiveFunction.hashCode()); + result = prime * result + ((this.svec == null) ? 0 : this.svec.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final CompositeRequestSvecObject other = (CompositeRequestSvecObject) obj; + if (this.excludeRoute == null) { + if (other.excludeRoute != null) + return false; + } else if (!this.excludeRoute.equals(other.excludeRoute)) + return false; + if (this.globalConstraints == null) { + if (other.globalConstraints != null) + return false; + } else if (!this.globalConstraints.equals(other.globalConstraints)) + return false; + if (this.metrics == null) { + if (other.metrics != null) + return false; + } else if (!this.metrics.equals(other.metrics)) + return false; + if (this.objectiveFunction == null) { + if (other.objectiveFunction != null) + return false; + } else if (!this.objectiveFunction.equals(other.objectiveFunction)) + return false; + if (this.svec == null) { + if (other.svec != null) + return false; + } else if (!this.svec.equals(other.svec)) + return false; + return true; + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeResponseObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeResponseObject.java new file mode 100644 index 0000000000..a725dccc38 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeResponseObject.java @@ -0,0 +1,365 @@ +/* + * 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.object; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; + +/** + * Structure that combines set of related objects. + * + * @see Path + * Computation Reply (PCRep) Message - <response>
+ */ +public class CompositeResponseObject { + + private final PCEPRequestParameterObject requestParameter; + + private final PCEPNoPathObject noPath; + + private final PCEPLspObject lsp; + + private final PCEPLspaObject lspa; + + private final PCEPRequestedPathBandwidthObject bandwidth; + + private List metrics; + + private final PCEPIncludeRouteObject includeRoute; + + private List paths; + + /** + * Constructs basic composite object only with mandatory objects. + * + * @param requestParameter + * PCEPRequestParameterObject. Can't be null. + */ + public CompositeResponseObject(PCEPRequestParameterObject requestParameter) { + this(requestParameter, null, null, null, null, null, null, null); + } + + /** + * Constructs composite object with optional objects. + * + * @param requestParameter + * PCEPRequestParameterObject. Can't be null. + * @param noPath + * PCEPNoPathObject + * @param lsp + * PCEPLspObject + * @param lspa + * PCEPLspaObject + * @param bandwidth + * PCEPRequestedPathBandwidthObject + * @param metrics + * List + * @param includeRoute + * PCEPIncludeRouteObject + * @param paths + * List + */ + public CompositeResponseObject(PCEPRequestParameterObject requestParameter, PCEPNoPathObject noPath, PCEPLspObject lsp, PCEPLspaObject lspa, + PCEPRequestedPathBandwidthObject bandwidth, List metrics, PCEPIncludeRouteObject includeRoute, List paths) { + if (requestParameter == null) + throw new IllegalArgumentException("Request Parameter Object is mandatory."); + this.requestParameter = requestParameter; + this.noPath = noPath; + this.lsp = lsp; + this.lspa = lspa; + this.bandwidth = bandwidth; + if (metrics != null) + this.metrics = metrics; + else + this.metrics = Collections.emptyList(); + this.includeRoute = includeRoute; + if (paths != null) + this.paths = paths; + else + this.paths = Collections.emptyList(); + } + + /** + * Gets list of all objects, which are in appropriate order. + * + * @return List + */ + public List getCompositeAsList() { + final List list = new ArrayList(); + list.add(this.requestParameter); + if (this.noPath != null) + list.add(this.noPath); + if (this.lsp != null) + list.add(this.lsp); + if (this.lspa != null) + list.add(this.lspa); + if (this.bandwidth != null) + list.add(this.bandwidth); + if (this.metrics != null && !this.metrics.isEmpty()) + list.addAll(this.metrics); + if (this.includeRoute != null) + list.add(this.includeRoute); + if (this.paths != null && !this.paths.isEmpty()) + for (final CompositePathObject cpo : this.paths) + list.addAll(cpo.getCompositeAsList()); + return list; + } + + /** + * Creates this object from a list of PCEPObjects. + * @param objects List list of PCEPObjects from whose this + * object should be created. + * @return CompositeResponseObject + */ + public static CompositeResponseObject getCompositeFromList(List objects) { + if (objects == null || objects.isEmpty()) { + throw new IllegalArgumentException("List cannot be null or empty."); + } + PCEPRequestParameterObject requestParameter = null; + if (objects.get(0) instanceof PCEPRequestParameterObject) { + requestParameter = (PCEPRequestParameterObject) objects.get(0); + objects.remove(requestParameter); + } else + return null; + PCEPNoPathObject noPath = null; + PCEPLspObject lsp = null; + PCEPLspaObject lspa = null; + PCEPRequestedPathBandwidthObject bandwidth = null; + final List metrics = new ArrayList(); + PCEPIncludeRouteObject iro = null; + final List paths = new ArrayList(); + + int state = 1; + while (!objects.isEmpty()) { + final PCEPObject obj = objects.get(0); + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPNoPathObject) { + noPath = (PCEPNoPathObject) obj; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPLspObject) { + lsp = (PCEPLspObject) obj; + break; + } + case 3: + state = 4; + if (obj instanceof PCEPLspaObject) { + lspa = (PCEPLspaObject) obj; + break; + } + case 4: + state = 5; + if (obj instanceof PCEPRequestedPathBandwidthObject) { + bandwidth = (PCEPRequestedPathBandwidthObject) obj; + break; + } + case 5: + if (obj instanceof PCEPMetricObject) { + metrics.add((PCEPMetricObject) obj); + state = 5; + break; + } else + state = 6; + case 6: + state = 8; + if (obj instanceof PCEPIncludeRouteObject) { + iro = (PCEPIncludeRouteObject) obj; + break; + } + state = 7; + } + + if (state == 7) { + break; + } + objects.remove(obj); + if (state == 8) { + break; + } + } + if (!objects.isEmpty()) { + CompositePathObject path = CompositePathObject.getCompositeFromList(objects); + while (path != null) { + paths.add(path); + if (objects.isEmpty()) + break; + path = CompositePathObject.getCompositeFromList(objects); + } + } + return new CompositeResponseObject(requestParameter, noPath, lsp, lspa, bandwidth, metrics, iro, paths); + } + + /** + * Gets {@link PCEPRequestParameterObject}. + * + * @return PCEPRequestParameterObject. Can't be null. + */ + public PCEPRequestParameterObject getRequestParameter() { + return this.requestParameter; + } + + /** + * Gets {@link PCEPNoPathObject}. + * + * @return PCEPNoPathObject. May be null. + */ + public PCEPNoPathObject getNoPath() { + return this.noPath; + } + + /** + * Gets {@link PCEPLspObject} + * + * @return PCEPLspObject. May be null. + */ + public PCEPLspObject getLsp() { + return this.lsp; + } + + /** + * Gets {@link PCEPLspaObject}. + * + * @return PCEPLspaObject. May be null. + */ + public PCEPLspaObject getLspa() { + return this.lspa; + } + + /** + * Gets {@link PCEPBandwidthObject}. + * + * @return PCEPBandwidthObject. May be null. + */ + public PCEPBandwidthObject getBandwidth() { + return this.bandwidth; + } + + /** + * Gets list of {@link PCEPMetricObject}. + * + * @return List. Can't be null, but may be empty. + */ + public List getMetrics() { + return this.metrics; + } + + /** + * Gets list of {@link CompositePathObject}. + * + * @return PCEPIncludeRouteObject. Can't be null, but may be empty. + */ + public PCEPIncludeRouteObject getIncludeRoute() { + return this.includeRoute; + } + + /** + * Gets list of {@link CompositePathObject}. + * + * @return List. Can't be null, but may be empty. + */ + public List getPaths() { + return this.paths; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.bandwidth == null) ? 0 : this.bandwidth.hashCode()); + result = prime * result + ((this.includeRoute == null) ? 0 : this.includeRoute.hashCode()); + result = prime * result + ((this.lsp == null) ? 0 : this.lsp.hashCode()); + result = prime * result + ((this.lspa == null) ? 0 : this.lspa.hashCode()); + result = prime * result + ((this.metrics == null) ? 0 : this.metrics.hashCode()); + result = prime * result + ((this.noPath == null) ? 0 : this.noPath.hashCode()); + result = prime * result + ((this.paths == null) ? 0 : this.paths.hashCode()); + result = prime * result + ((this.requestParameter == null) ? 0 : this.requestParameter.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final CompositeResponseObject other = (CompositeResponseObject) obj; + if (this.bandwidth == null) { + if (other.bandwidth != null) + return false; + } else if (!this.bandwidth.equals(other.bandwidth)) + return false; + if (this.includeRoute == null) { + if (other.includeRoute != null) + return false; + } else if (!this.includeRoute.equals(other.includeRoute)) + return false; + if (this.lsp == null) { + if (other.lsp != null) + return false; + } else if (!this.lsp.equals(other.lsp)) + return false; + if (this.lspa == null) { + if (other.lspa != null) + return false; + } else if (!this.lspa.equals(other.lspa)) + return false; + if (this.metrics == null) { + if (other.metrics != null) + return false; + } else if (!this.metrics.equals(other.metrics)) + return false; + if (this.noPath == null) { + if (other.noPath != null) + return false; + } else if (!this.noPath.equals(other.noPath)) + return false; + if (this.paths == null) { + if (other.paths != null) + return false; + } else if (!this.paths.equals(other.paths)) + return false; + if (this.requestParameter == null) { + if (other.requestParameter != null) + return false; + } else if (!this.requestParameter.equals(other.requestParameter)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("CompositeResponseObject [requestParameter="); + builder.append(this.requestParameter); + builder.append(", noPath="); + builder.append(this.noPath); + builder.append(", lsp="); + builder.append(this.lsp); + builder.append(", lspa="); + builder.append(this.lspa); + builder.append(", bandwidth="); + builder.append(this.bandwidth); + builder.append(", metrics="); + builder.append(this.metrics); + builder.append(", includeRoute="); + builder.append(this.includeRoute); + builder.append(", paths="); + builder.append(this.paths); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeRptPathObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeRptPathObject.java new file mode 100644 index 0000000000..56ed2879f3 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeRptPathObject.java @@ -0,0 +1,266 @@ +/* + * 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.object; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; + +/** + * Structure that combines set of related objects. + * + * @see PCRpt + * Message + */ +public class CompositeRptPathObject { + private final PCEPExplicitRouteObject explicitRoute; + + private final PCEPLspaObject lspa; + + private final PCEPExistingPathBandwidthObject bandwidth; + + private final PCEPReportedRouteObject reportedRoute; + + private List metrics; + + /** + * Constructs basic composite object only with mandatory objects. + * + * @param explicitRoute + * PCEPExplicitRouteObject. Can't be null. + */ + public CompositeRptPathObject(final PCEPExplicitRouteObject explicitRoute) { + this(explicitRoute, null, null, null, null); + } + + /** + * Constructs composite object with optional objects. + * + * @param explicitRoute + * PCEPExplicitRouteObject. Can't be null. + * @param lspa + * PCEPLspaObject + * @param bandwidth + * PCEPRequestedPathBandwidthObject + * @param reportedRoute + * PCEPReportedRouteObject + * @param metrics + * List + */ + public CompositeRptPathObject(final PCEPExplicitRouteObject explicitRoute, final PCEPLspaObject lspa, final PCEPExistingPathBandwidthObject bandwidth, + final PCEPReportedRouteObject reportedRoute, final List metrics) { + if (explicitRoute == null) + throw new IllegalArgumentException("Explicit Route Object is mandatory."); + this.explicitRoute = explicitRoute; + this.lspa = lspa; + this.bandwidth = bandwidth; + if (metrics != null) + this.metrics = metrics; + else + this.metrics = Collections.emptyList(); + this.reportedRoute = reportedRoute; + } + + /** + * Gets list of all objects, which are in appropriate order. + * + * @return List. Can't be null or empty. + */ + public List getCompositeAsList() { + final List list = new ArrayList(); + list.add(this.explicitRoute); + if (this.lspa != null) + list.add(this.lspa); + if (this.bandwidth != null) + list.add(this.bandwidth); + if (this.reportedRoute != null) + list.add(this.reportedRoute); + if (this.metrics != null && !this.metrics.isEmpty()) + list.addAll(this.metrics); + return list; + } + + /** + * Creates this object from a list of PCEPObjects. + * @param objects List list of PCEPObjects from whose this + * object should be created. + * @return CompositeRptPathObject + */ + public static CompositeRptPathObject getCompositeFromList(final List objects) { + if (objects == null || objects.isEmpty()) { + throw new IllegalArgumentException("List cannot be null or empty."); + } + + PCEPExplicitRouteObject explicitRoute = null; + if (objects.get(0) instanceof PCEPExplicitRouteObject) { + explicitRoute = (PCEPExplicitRouteObject) objects.get(0); + objects.remove(explicitRoute); + } else + return null; + + PCEPLspaObject lspa = null; + PCEPExistingPathBandwidthObject bandwidth = null; + final List metrics = new ArrayList(); + PCEPReportedRouteObject rro = null; + + int state = 1; + while (!objects.isEmpty()) { + final PCEPObject obj = objects.get(0); + + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPLspaObject) { + lspa = (PCEPLspaObject) obj; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPExistingPathBandwidthObject) { + bandwidth = (PCEPExistingPathBandwidthObject) obj; + break; + } + case 3: + state = 4; + if (obj instanceof PCEPReportedRouteObject) { + rro = (PCEPReportedRouteObject) obj; + break; + } + case 4: + if (obj instanceof PCEPMetricObject) { + metrics.add((PCEPMetricObject) obj); + state = 4; + break; + } else + state = 5; + } + + if (state == 5) { + break; + } + + objects.remove(obj); + } + + return new CompositeRptPathObject(explicitRoute, lspa, bandwidth, rro, metrics); + } + + /** + * Gets {@link PCEPExplicitRouteObject}. + * + * @return PCEPExplicitRouteObject. Can't be null. + */ + public PCEPExplicitRouteObject getExcludedRoute() { + return this.explicitRoute; + } + + /** + * Gets {@link PCEPLspaObject}. + * + * @return PCEPLspaObject. May be null. + */ + public PCEPLspaObject getLspa() { + return this.lspa; + } + + /** + * Gets {@link PCEPBandwidthObject}. + * + * @return PCEPBandwidthObject. May be null. + */ + public PCEPBandwidthObject getBandwidth() { + return this.bandwidth; + } + + /** + * Gets list of {@link PCEPMetricObject}. + * + * @return List. Can't be null, but may be empty. + */ + public List getMetrics() { + return this.metrics; + } + + /** + * Gets {@link PCEPReportedRouteObject}. + * + * @return PCEPReportedRouteObject. May be null. + */ + public PCEPReportedRouteObject getReportedRoute() { + return this.reportedRoute; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.bandwidth == null) ? 0 : this.bandwidth.hashCode()); + result = prime * result + ((this.explicitRoute == null) ? 0 : this.explicitRoute.hashCode()); + result = prime * result + ((this.lspa == null) ? 0 : this.lspa.hashCode()); + result = prime * result + ((this.metrics == null) ? 0 : this.metrics.hashCode()); + result = prime * result + ((this.reportedRoute == null) ? 0 : this.reportedRoute.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final CompositeRptPathObject other = (CompositeRptPathObject) obj; + if (this.bandwidth == null) { + if (other.bandwidth != null) + return false; + } else if (!this.bandwidth.equals(other.bandwidth)) + return false; + if (this.explicitRoute == null) { + if (other.explicitRoute != null) + return false; + } else if (!this.explicitRoute.equals(other.explicitRoute)) + return false; + if (this.lspa == null) { + if (other.lspa != null) + return false; + } else if (!this.lspa.equals(other.lspa)) + return false; + if (this.metrics == null) { + if (other.metrics != null) + return false; + } else if (!this.metrics.equals(other.metrics)) + return false; + if (this.reportedRoute == null) { + if (other.reportedRoute != null) + return false; + } else if (!this.reportedRoute.equals(other.reportedRoute)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("CompositeRptPathObject [explicitRoute="); + builder.append(this.explicitRoute); + builder.append(", lspa="); + builder.append(this.lspa); + builder.append(", bandwidth="); + builder.append(this.bandwidth); + builder.append(", reportedRoute="); + builder.append(this.reportedRoute); + builder.append(", metrics="); + builder.append(this.metrics); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeStateReportObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeStateReportObject.java new file mode 100644 index 0000000000..51469564a8 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeStateReportObject.java @@ -0,0 +1,163 @@ +/* + * 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.object; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; + +/** + * Structure that combines set of related objects. + * + * @see The + * PCRpt Message - <state-report>
+ */ +public class CompositeStateReportObject { + + private final PCEPLspObject lsp; + + private List paths; + + /** + * Constructs basic composite object only with mandatory objects. + * + * @param lsp + * PCEPLspObject + */ + public CompositeStateReportObject(PCEPLspObject lsp) { + this(lsp, null); + } + + /** + * Constructs composite object with optional objects. + * + * @param lsp + * PCEPLspObject + * @param paths + * List Can't be null. + */ + public CompositeStateReportObject(PCEPLspObject lsp, List paths) { + if (lsp == null) + throw new IllegalArgumentException("LSP Object is mandatory."); + this.lsp = lsp; + if (paths != null) + this.paths = paths; + else + this.paths = Collections.emptyList(); + } + + /** + * Creates this object from a list of PCEPObjects. + * @param objects List list of PCEPObjects from whose this + * object should be created. + * @return CompositeStateReportObject + */ + public static CompositeStateReportObject getCompositeFromList(List objects) { + if (objects == null || objects.isEmpty()) { + throw new IllegalArgumentException("List can not be null or empty."); + } + + PCEPLspObject lsp = null; + if (objects.get(0) instanceof PCEPLspObject) { + lsp = (PCEPLspObject) objects.get(0); + objects.remove(lsp); + } else + return null; + + final List paths = new ArrayList(); + + if (!objects.isEmpty()) { + CompositeRptPathObject path = CompositeRptPathObject.getCompositeFromList(objects); + while (path != null) { + paths.add(path); + if (objects.isEmpty()) + break; + path = CompositeRptPathObject.getCompositeFromList(objects); + } + } + + return new CompositeStateReportObject(lsp, paths); + } + + /** + * Gets list of all objects, which are in appropriate order. + * + * @return List + */ + public List getCompositeAsList() { + final List list = new ArrayList(); + list.add(this.lsp); + if (this.paths != null && !this.paths.isEmpty()) + for (final CompositeRptPathObject cpo : this.paths) + list.addAll(cpo.getCompositeAsList()); + return list; + } + + /** + * Gets {@link PCEPLspObject}. + * + * @return PCEPLspObject. Can't be null. + */ + public PCEPLspObject getLsp() { + return this.lsp; + } + + /** + * Gets list of {@link CompositeRptPathObject}. + * + * @return List. May be null. + */ + public List getPaths() { + return this.paths; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.lsp == null) ? 0 : this.lsp.hashCode()); + result = prime * result + ((this.paths == null) ? 0 : this.paths.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final CompositeStateReportObject other = (CompositeStateReportObject) obj; + if (this.lsp == null) { + if (other.lsp != null) + return false; + } else if (!this.lsp.equals(other.lsp)) + return false; + if (this.paths == null) { + if (other.paths != null) + return false; + } else if (!this.paths.equals(other.paths)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("CompositeStateReportObject [lsp="); + builder.append(this.lsp); + builder.append(", paths="); + builder.append(this.paths); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeUpdPathObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeUpdPathObject.java new file mode 100644 index 0000000000..a6d845a289 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeUpdPathObject.java @@ -0,0 +1,227 @@ +/* + * 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.object; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; + +/** + * Structure that combines set of related objects. + * + * @see draft-ietf-pce-stateful-pce-01 (sec. 6.2) - The PCUpd Message - + * <path>
+ */ +public class CompositeUpdPathObject { + + private final PCEPExplicitRouteObject explicitRoute; + + private final PCEPLspaObject lspa; + + private final PCEPRequestedPathBandwidthObject bandwidth; + + private List metrics; + + /** + * Constructs basic composite object only with mandatory objects. + * @param explicitRoute PCEPExplicitRouteObject + */ + public CompositeUpdPathObject(PCEPExplicitRouteObject explicitRoute) { + this(explicitRoute, null, null, null); + } + + /** + * Constructs composite object with optional objects. + * @param explicitRoute PCEPExplicitRouteObject + * @param lspa PCEPLspaObject + * @param bandwidth PCEPRequestedPathBandwidthObject + * @param metrics List + */ + public CompositeUpdPathObject(PCEPExplicitRouteObject explicitRoute, PCEPLspaObject lspa, PCEPRequestedPathBandwidthObject bandwidth, + List metrics) { + if (explicitRoute == null) + throw new IllegalArgumentException("Explicit Route Object is mandatory."); + this.explicitRoute = explicitRoute; + this.lspa = lspa; + this.bandwidth = bandwidth; + if (metrics != null) + this.metrics = metrics; + else + this.metrics = Collections.emptyList(); + } + + /** + * Gets list of all objects, which are in appropriate order. + * @return List + */ + public List getCompositeAsList() { + final List list = new ArrayList(); + list.add(this.explicitRoute); + if (this.lspa != null) + list.add(this.lspa); + if (this.bandwidth != null) + list.add(this.bandwidth); + if (this.metrics != null && !this.metrics.isEmpty()) + list.addAll(this.metrics); + return list; + } + + /** + * Creates this object from a list of PCEPObjects. + * @param objects List list of PCEPObjects from whose this + * object should be created. + * @return CompositeUpdPathObject constructed from objects + */ + public static CompositeUpdPathObject getCompositeFromList(List objects) { + if (objects == null || objects.isEmpty()) { + throw new IllegalArgumentException("List cannot be null or empty."); + } + + PCEPExplicitRouteObject explicitRoute = null; + if (objects.get(0) instanceof PCEPExplicitRouteObject) { + explicitRoute = (PCEPExplicitRouteObject) objects.get(0); + objects.remove(explicitRoute); + } else + return null; + + PCEPLspaObject lspa = null; + PCEPRequestedPathBandwidthObject bandwidth = null; + final List metrics = new ArrayList(); + + int state = 1; + while (!objects.isEmpty()) { + final PCEPObject obj = objects.get(0); + + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPLspaObject) { + lspa = (PCEPLspaObject) obj; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPRequestedPathBandwidthObject) { + bandwidth = (PCEPRequestedPathBandwidthObject) obj; + break; + } + case 3: + if (obj instanceof PCEPMetricObject) { + metrics.add((PCEPMetricObject) obj); + state = 3; + break; + } else + state = 4; + } + + if (state == 4) { + break; + } + + objects.remove(obj); + } + + return new CompositeUpdPathObject(explicitRoute, lspa, bandwidth, metrics); + } + + /** + * Gets {@link PCEPExplicitRouteObject} + * + * @return PCEPExplicitRouteObject + */ + public PCEPExplicitRouteObject getExcludedRoute() { + return this.explicitRoute; + } + + /** + * Gets {@link PCEPLspaObject} + * + * @return PCEPLspaObject + */ + public PCEPLspaObject getLspa() { + return this.lspa; + } + + /** + * Gets bandwidth. + * + * @return PCEPBandwidthObject + */ + public PCEPBandwidthObject getBandwidth() { + return this.bandwidth; + } + + /** + * Gets list of {@link PCEPMetricObject}. + * + * @return List + */ + public List getMetrics() { + return this.metrics; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.bandwidth == null) ? 0 : this.bandwidth.hashCode()); + result = prime * result + ((this.explicitRoute == null) ? 0 : this.explicitRoute.hashCode()); + result = prime * result + ((this.lspa == null) ? 0 : this.lspa.hashCode()); + result = prime * result + ((this.metrics == null) ? 0 : this.metrics.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final CompositeUpdPathObject other = (CompositeUpdPathObject) obj; + if (this.bandwidth == null) { + if (other.bandwidth != null) + return false; + } else if (!this.bandwidth.equals(other.bandwidth)) + return false; + if (this.explicitRoute == null) { + if (other.explicitRoute != null) + return false; + } else if (!this.explicitRoute.equals(other.explicitRoute)) + return false; + if (this.lspa == null) { + if (other.lspa != null) + return false; + } else if (!this.lspa.equals(other.lspa)) + return false; + if (this.metrics == null) { + if (other.metrics != null) + return false; + } else if (!this.metrics.equals(other.metrics)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("CompositeUpdPathObject [explicitRoute="); + builder.append(this.explicitRoute); + builder.append(", lspa="); + builder.append(this.lspa); + builder.append(", bandwidth="); + builder.append(this.bandwidth); + builder.append(", metrics="); + builder.append(this.metrics); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeUpdateRequestObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeUpdateRequestObject.java new file mode 100644 index 0000000000..7f05f1daa9 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/CompositeUpdateRequestObject.java @@ -0,0 +1,163 @@ +/* + * 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.object; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; + +/** + * Structure that combines set of related objects. + * + * @see The + * PCRpt Message - <update-request>
+ */ +public class CompositeUpdateRequestObject { + + private final PCEPLspObject lsp; + + private List paths; + + /** + * Constructs basic composite object only with mandatory objects. + * + * @param lsp + * PCEPLspObject. Can't be null. + */ + public CompositeUpdateRequestObject(PCEPLspObject lsp) { + this(lsp, null); + } + + /** + * Constructs composite object with optional objects. + * + * @param lsp + * PCEPLspObject. Can't be null. + * @param paths + * List + */ + public CompositeUpdateRequestObject(PCEPLspObject lsp, List paths) { + if (lsp == null) + throw new IllegalArgumentException("LSP Object is mandatory."); + this.lsp = lsp; + if (paths != null) + this.paths = paths; + else + this.paths = Collections.emptyList(); + } + + /** + * Gets list of all objects, which are in appropriate order. + * + * @return List. Can't be null. + */ + public List getCompositeAsList() { + final List list = new ArrayList(); + list.add(this.lsp); + if (this.paths != null && !this.paths.isEmpty()) + for (final CompositeUpdPathObject cpo : this.paths) + list.addAll(cpo.getCompositeAsList()); + return list; + } + + /** + * Creates this object from a list of PCEPObjects. + * @param objects List list of PCEPObjects from whose this + * object should be created. + * @return CompositeUpdateRequestObject + */ + public static CompositeUpdateRequestObject getCompositeFromList(List objects) { + if (objects == null || objects.isEmpty()) { + throw new IllegalArgumentException("List cannot be null or empty."); + } + + PCEPLspObject lsp = null; + if (objects.get(0) instanceof PCEPLspObject) { + lsp = (PCEPLspObject) objects.get(0); + objects.remove(lsp); + } else + return null; + + final List paths = new ArrayList(); + + if (!objects.isEmpty()) { + CompositeUpdPathObject path = CompositeUpdPathObject.getCompositeFromList(objects); + while (path != null) { + paths.add(path); + if (objects.isEmpty()) + break; + path = CompositeUpdPathObject.getCompositeFromList(objects); + } + } + + return new CompositeUpdateRequestObject(lsp, paths); + } + + /** + * Gets {@link PCEPLspObject}. + * + * @return PCEPLspObject. Can't be null. + */ + public PCEPLspObject getLsp() { + return this.lsp; + } + + /** + * Gets list of {@link CompositeUpdPathObject}. + * + * @return List. Can't be null, but may be empty. + */ + public List getPaths() { + return this.paths; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.lsp == null) ? 0 : this.lsp.hashCode()); + result = prime * result + ((this.paths == null) ? 0 : this.paths.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final CompositeUpdateRequestObject other = (CompositeUpdateRequestObject) obj; + if (this.lsp == null) { + if (other.lsp != null) + return false; + } else if (!this.lsp.equals(other.lsp)) + return false; + if (this.paths == null) { + if (other.paths != null) + return false; + } else if (!this.paths.equals(other.paths)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("CompositeUpdateRequestObject [lsp="); + builder.append(this.lsp); + builder.append(", paths="); + builder.append(this.paths); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPBandwidthObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPBandwidthObject.java new file mode 100644 index 0000000000..abc96d4f1f --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPBandwidthObject.java @@ -0,0 +1,78 @@ +/* + * 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.object; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Bandwidth; + +import com.google.common.base.Objects.ToStringHelper; + +/** + * Basic structure of Bandwidth Object. + * + * @see PCEP Bandwidth Object + */ +public abstract class PCEPBandwidthObject extends PCEPObject { + + private final Bandwidth bandwidth; + + /** + * Constructs basic Bandwidth Object. + * + * @param bandwidth Bandwidth + * @param processed boolean + * @param ignored boolean + */ + public PCEPBandwidthObject(final Bandwidth bandwidth, final boolean processed, final boolean ignored) { + super(processed, ignored); + if (bandwidth == null) + this.bandwidth = new Bandwidth(new byte[] { 0 }); + else + this.bandwidth = bandwidth; + } + + /** + * Gets {@link PCEPBandwidthObject}. + * + * @return Bandwidth. Can't be null. + */ + public Bandwidth getBandwidth() { + return this.bandwidth; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.bandwidth == null) ? 0 : this.bandwidth.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPBandwidthObject other = (PCEPBandwidthObject) obj; + if (this.bandwidth == null) { + if (other.bandwidth != null) + return false; + } else if (!this.bandwidth.equals(other.bandwidth)) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { + toStringHelper.add("bandwidth", this.bandwidth); + return super.addToStringAttributes(toStringHelper); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPBranchNodeListObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPBranchNodeListObject.java new file mode 100644 index 0000000000..27b5251125 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPBranchNodeListObject.java @@ -0,0 +1,35 @@ +/* + * 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.object; + +import java.util.List; + +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; + +/** + * Structure of Branch Node list object. + * + * @see Branch Node + * Object [RFC6006] + */ +public class PCEPBranchNodeListObject extends PCEPBranchNodeObject { + + /** + * Constructs Branch Node list object. + * + * @param subobjects + * List + * @param processed + * boolean + * @param ignored + * boolean + */ + public PCEPBranchNodeListObject(List subobjects, boolean processed, boolean ignored) { + super(subobjects, processed, ignored); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPBranchNodeObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPBranchNodeObject.java new file mode 100644 index 0000000000..3c2cd97032 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPBranchNodeObject.java @@ -0,0 +1,79 @@ +/* + * 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.object; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; +import com.google.common.base.Objects.ToStringHelper; + +/** + * + */ +public abstract class PCEPBranchNodeObject extends PCEPObject { + + protected final List subobjects; + + /** + * Constructs Branch Node list object. + * + * @param subobjects + * List + * @param processed + * boolean + * @param ignored + * boolean + */ + public PCEPBranchNodeObject(List subobjects, boolean processed, boolean ignored) { + super(processed, ignored); + if (subobjects == null || subobjects.isEmpty()) + throw new IllegalArgumentException("Subobjects can't be null or empty."); + this.subobjects = subobjects; + } + + /** + * Gets list of {@link ExplicitRouteSubobject} + * + * @return List. Can't be null or empty. + */ + public List getSubobjects() { + return this.subobjects; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.subobjects == null) ? 0 : this.subobjects.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPBranchNodeObject other = (PCEPBranchNodeObject) obj; + if (this.subobjects == null) { + if (other.subobjects != null) + return false; + } else if (!this.subobjects.equals(other.subobjects)) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("subobjects", this.subobjects); + return super.addToStringAttributes(toStringHelper); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPClassTypeObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPClassTypeObject.java new file mode 100644 index 0000000000..70648c6631 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPClassTypeObject.java @@ -0,0 +1,73 @@ +/* + * 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.object; + +import org.opendaylight.protocol.pcep.PCEPObject; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Structure of ClassType Object. + * + * @see Object + * Definition + */ +public class PCEPClassTypeObject extends PCEPObject { + + private final short classType; + + /** + * Constructs ClassType Object with given class type. + * + * @param classType + * short, must be positive and less than 8. + */ + public PCEPClassTypeObject(short classType) { + super(true, false); + if (classType < 0 || classType > 7) { + throw new IllegalArgumentException("ClassType range overstepped."); + } + this.classType = classType; + } + + /** + * Gets class type. + * + * @return class type + */ + public short getClassType() { + return this.classType; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + this.classType; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (!(obj instanceof PCEPClassTypeObject)) + return false; + final PCEPClassTypeObject other = (PCEPClassTypeObject) obj; + if (this.classType != other.classType) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("classType", this.classType); + return super.addToStringAttributes(toStringHelper); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPCloseObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPCloseObject.java new file mode 100644 index 0000000000..bf4217a8a1 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPCloseObject.java @@ -0,0 +1,119 @@ +/* + * 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.object; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.PCEPTlv; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Structure of Close Object. + * + * @see PCEP Close + * Object + */ +public class PCEPCloseObject extends PCEPObject { + + /** + * Constants for reasons of closing session. + */ + public enum Reason { + UNKNOWN, EXP_DEADTIMER, MALFORMED_MSG, TOO_MANY_UNKNOWN_REQ_REP, TOO_MANY_UNKNOWN_MSG + } + + private final Reason reason; + + private List tlvs; + + /** + * Constructs Close Object only with mandatory object. + * + * @param reason + * Reason. Can't be null. + */ + public PCEPCloseObject(Reason reason) { + this(reason, null); + } + + /** + * Constructs Close Object also with optional objects. + * + * @param reason + * Reason. Can't be null. + * @param tlvs + * List + */ + public PCEPCloseObject(Reason reason, List tlvs) { + super(false, false); + if (reason == null) + throw new IllegalArgumentException("Reason is mandatory."); + this.reason = reason; + + if (tlvs != null) + this.tlvs = tlvs; + else + this.tlvs = Collections.emptyList(); + } + + /** + * Gets {@link Reason} + * + * @return Reason. Can't be null. + */ + public Reason getReason() { + return this.reason; + } + + /** + * Gets list of {@link PCEPTlv} + * + * @return List. Can't be null, but may be empty. + */ + public List getTlvs() { + return this.tlvs; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.reason == null) ? 0 : this.reason.hashCode()); + result = prime * result + ((this.tlvs == null) ? 0 : this.tlvs.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPCloseObject other = (PCEPCloseObject) obj; + if (this.reason != other.reason) + return false; + if (this.tlvs == null) { + if (other.tlvs != null) + return false; + } else if (!this.tlvs.equals(other.tlvs)) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("reason", this.reason); + toStringHelper.add("tlvs", this.tlvs); + return super.addToStringAttributes(toStringHelper); + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPEndPoints.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPEndPoints.java new file mode 100644 index 0000000000..c475fc569d --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPEndPoints.java @@ -0,0 +1,18 @@ +/* + * 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.object; + +import org.opendaylight.protocol.pcep.PCEPObject; + +public abstract class PCEPEndPoints extends PCEPObject { + + protected PCEPEndPoints(boolean processed, boolean ignored) { + super(processed, ignored); + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPEndPointsObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPEndPointsObject.java new file mode 100644 index 0000000000..987d969e27 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPEndPointsObject.java @@ -0,0 +1,100 @@ +/* + * 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.object; + +import org.opendaylight.protocol.concepts.NetworkAddress; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Parameterized structure of PCEP End Points Object. + * + * @see PCEP + * EndPointsObject + * @param + * subtype of NetworkAddress + */ +public class PCEPEndPointsObject> extends PCEPEndPoints { + + private final T sourceAddress; + + private final T destinationAddress; + + /** + * Constructs Close Object with mandatory object. + * + * @param sourceAddress + * T. Cant't be null. + * @param destinationAddress + * T. Cant't be null. + */ + public PCEPEndPointsObject(T sourceAddress, T destinationAddress) { + super(true, false); + if (sourceAddress == null) + throw new IllegalArgumentException("Source address is mantadory."); + this.sourceAddress = sourceAddress; + if (destinationAddress == null) + throw new IllegalArgumentException("Destination address is mantadory."); + this.destinationAddress = destinationAddress; + } + + /** + * Gets source address of type T. + * + * @return T. Can't be null. + */ + public T getSourceAddress() { + return this.sourceAddress; + } + + /** + * Gets destination address of type T. + * + * @return T. Can't be null. + */ + public T getDestinationAddress() { + return this.destinationAddress; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("sourceAddress", this.sourceAddress); + toStringHelper.add("destinationAddress", this.destinationAddress); + return super.addToStringAttributes(toStringHelper); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.destinationAddress == null) ? 0 : this.destinationAddress.hashCode()); + result = prime * result + ((this.sourceAddress == null) ? 0 : this.sourceAddress.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (!(obj instanceof PCEPEndPointsObject)) + return false; + final PCEPEndPointsObject other = (PCEPEndPointsObject) obj; + if (this.destinationAddress == null) { + if (other.destinationAddress != null) + return false; + } else if (!this.destinationAddress.equals(other.destinationAddress)) + return false; + if (this.sourceAddress == null) { + if (other.sourceAddress != null) + return false; + } else if (!this.sourceAddress.equals(other.sourceAddress)) + return false; + return true; + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPErrorObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPErrorObject.java new file mode 100644 index 0000000000..3f1ab226f4 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPErrorObject.java @@ -0,0 +1,109 @@ +/* + * 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.object; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.PCEPTlv; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Structure of PCEP Error Object. + * + * @see PCEP Error + * Object + */ +public class PCEPErrorObject extends PCEPObject { + + private final PCEPErrors error; + + private final List tlvs; + + /** + * Constructs Error Object only with mandatory object. + * + * @param type + * PCEPErrors. Can't be null. + */ + public PCEPErrorObject(PCEPErrors type) { + this(type, null); + } + + /** + * Constructs Error Object also with optional objects. + * + * @param type + * PCEPErrors. Can't be null + * @param tlvs + * List + */ + public PCEPErrorObject(PCEPErrors type, List tlvs) { + super(false, false); + this.error = type; + if (tlvs != null) + this.tlvs = tlvs; + else + this.tlvs = Collections.emptyList(); + } + + /** + * Gets {@link PCEPErrors} + * + * @return PCEPErrors. Can't be null. + */ + public PCEPErrors getError() { + return this.error; + } + + /** + * Gets list of {@link PCEPTlv} + * + * @return List. Can't be null, but may be empty. + */ + public List getTlvs() { + return this.tlvs; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.error == null) ? 0 : this.error.hashCode()); + result = prime * result + ((this.tlvs == null) ? 0 : this.tlvs.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPErrorObject other = (PCEPErrorObject) obj; + if (this.error != other.error) + return false; + if (this.tlvs == null) { + if (other.tlvs != null) + return false; + } else if (!this.tlvs.equals(other.tlvs)) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("error", this.error); + toStringHelper.add("tlvs", this.tlvs); + return super.addToStringAttributes(toStringHelper); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPExcludeRouteObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPExcludeRouteObject.java new file mode 100644 index 0000000000..a2fe0a8f9b --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPExcludeRouteObject.java @@ -0,0 +1,105 @@ +/* + * 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.object; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.subobject.ExcludeRouteSubobject; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Provides a list of network resources that the PCE is requested to exclude + * from the path that it computes. Flags associated with each list member + * instruct the PCE as to whether the network resources must be excluded from + * the computed path, or whether the PCE should make best efforts to exclude the + * resources from the computed path. + * + * @see Exclude + * Route Object definition + */ +public class PCEPExcludeRouteObject extends PCEPObject { + + private final boolean fail; + + private final List subobjects; + + /** + * Constructs Exclude Route Object. + * + * @param subobjects + * List. Can't be null or empty. + * @param fail + * boolean + * @param processed + * boolean + * @param ignored + * boolean + */ + public PCEPExcludeRouteObject(List subobjects, boolean fail, boolean processed, boolean ignored) { + super(processed, ignored); + if (subobjects == null || subobjects.isEmpty()) + throw new IllegalArgumentException("Subobjects can't be null or empty."); + + this.fail = fail; + this.subobjects = subobjects; + } + + /** + * Gets list of sub-objects + * + * @return List. Can't be null or empty. + */ + public List getSubobjects() { + return this.subobjects; + } + + /** + * @see Exclude + * Route Object definition + * + * @return if returns true, the requesting PCC requires the computation of a + * new path for an existing TE LSP that has failed + */ + public boolean isFail() { + return this.fail; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("fail", this.fail); + toStringHelper.add("subobjects", this.subobjects); + return super.addToStringAttributes(toStringHelper); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.subobjects == null) ? 0 : this.subobjects.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPExcludeRouteObject other = (PCEPExcludeRouteObject) obj; + if (this.subobjects == null) { + if (other.subobjects != null) + return false; + } else if (!this.subobjects.equals(other.subobjects)) + return false; + return true; + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPExistingPathBandwidthObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPExistingPathBandwidthObject.java new file mode 100644 index 0000000000..73c879563d --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPExistingPathBandwidthObject.java @@ -0,0 +1,27 @@ +/* + * 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.object; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Bandwidth; + +/** + * Structure of specific Bandwidth. Used in Composite Requested Object to refer to bandwidth of existing path. + */ +public class PCEPExistingPathBandwidthObject extends PCEPBandwidthObject { + + /** + * Constructs Existing Path Bandwidth. + * + * @param bandwidth Bandwidth. Can't be null. + * @param processed boolean + * @param ignored boolean + */ + public PCEPExistingPathBandwidthObject(final Bandwidth bandwidth, final boolean processed, final boolean ignored) { + super(bandwidth, processed, ignored); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPExplicitRouteObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPExplicitRouteObject.java new file mode 100644 index 0000000000..2e571c2991 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPExplicitRouteObject.java @@ -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.pcep.object; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Structure of Explicit Route Object. + * + * @see PCEP Explicit + * Route Object + */ +public class PCEPExplicitRouteObject extends PCEPObject { + + private final List subobjects; + + /** + * Constructs Explicit Route Object. + * + * @param subobjects + * List. Can't be null or empty. + * @param ignored + * boolean + */ + public PCEPExplicitRouteObject(List subobjects, boolean ignored) { + super(false, ignored); + if (subobjects == null || subobjects.isEmpty()) + throw new IllegalArgumentException("Subobjects can't be null or empty."); + this.subobjects = subobjects; + } + + /** + * Gets list of {@link ExplicitRouteSubobject} + * + * @return List. Can't be null or empty. + */ + public List getSubobjects() { + return this.subobjects; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("subobjects", this.subobjects); + return super.addToStringAttributes(toStringHelper); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.subobjects == null) ? 0 : this.subobjects.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPExplicitRouteObject other = (PCEPExplicitRouteObject) obj; + if (this.subobjects == null) { + if (other.subobjects != null) + return false; + } else if (!this.subobjects.equals(other.subobjects)) + return false; + return true; + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPGlobalConstraintsObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPGlobalConstraintsObject.java new file mode 100644 index 0000000000..19fe36de7d --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPGlobalConstraintsObject.java @@ -0,0 +1,183 @@ +/* + * 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.object; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.PCEPTlv; +import com.google.common.base.Objects.ToStringHelper; + +/** + * The GLOBAL CONSTRAINTS Object is used in a PCReq message to specify the + * necessary global constraints that should be applied to all individual path + * computations for a global concurrent path optimization request. + * + * @see GLOBAL + * CONSTRAINTS (GC) Object + */ +public class PCEPGlobalConstraintsObject extends PCEPObject { + + private final short maxHop; + private final short maxUtilization; + private final short minUtilization; + private final short overBookingFactor; + + private List tlvs; + + /** + * Constructs Global Constraints Object with all mandatory fields. + * + * @param maxhop + * 8-bit integer + * @param maxUtilization + * 8-bit integer between 0 and 100 + * @param minUtilization + * 8-bit integer between 0 and 100 + * @param overBookingFactor + * 8-bit integer + * @param processed + * boolean + * @param ignored + * boolean + */ + public PCEPGlobalConstraintsObject(short maxhop, short maxUtilization, short minUtilization, short overBookingFactor, boolean processed, boolean ignored) { + this(maxhop, maxUtilization, minUtilization, overBookingFactor, null, processed, ignored); + } + + /** + * Constructs Global Constraints Object with all mandatory fields and + * optional list of tlvs. + * + * @param maxhop + * 8-bit integer + * @param maxUtilization + * 8-bit integer between 0 and 100 + * @param minUtilization + * 8-bit integer between 0 and 100 + * @param overBookingFactor + * 8-bit integer + * @param tlvs + * list of tlvs + * @param processed + * boolean + * @param ignored + * boolean + */ + public PCEPGlobalConstraintsObject(short maxhop, short maxUtilization, short minUtilization, short overBookingFactor, List tlvs, + boolean processed, boolean ignored) { + super(processed, ignored); + this.maxHop = maxhop; + + if (maxUtilization < 0 || maxUtilization > 100) + throw new IllegalArgumentException("Maximu utilization can be only between 0 and 100. Passed: " + maxUtilization); + this.maxUtilization = maxUtilization; + + if (minUtilization < 0 || minUtilization > 100) + throw new IllegalArgumentException("Minimum utilization can be only between 0 and 100. Passed: " + minUtilization); + this.minUtilization = minUtilization; + + this.overBookingFactor = overBookingFactor; + + if (tlvs == null) + this.tlvs = Collections.emptyList(); + else + this.tlvs = tlvs; + } + + /** + * Gets the maximum hop count for all the TE LSPs + * + * @return the maximum hop count + */ + public short getMaxHop() { + return this.maxHop; + } + + /** + * Gets the maximum utilization percentage by which all links should be + * bound + * + * @return the maximum utilization percentage + */ + public short getMaxUtilization() { + return this.maxUtilization; + } + + /** + * Gets the minimum utilization percentage by which all links should be + * bound + * + * @return the maximum utilization percentage + */ + public short getMinUtilization() { + return this.minUtilization; + } + + /** + * Gets the over booking factor percentage that allows the reserved + * bandwidth to be overbooked on each link beyond its physical capacity + * limit + * + * @return the over booking factor percentage + */ + public short getOverBookingFactor() { + return this.overBookingFactor; + } + + /** + * Gets the list of optional tlvs + * + * @return List. Can be empty but not null. + */ + public List getTlvs() { + return this.tlvs; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("maxHop", this.maxHop); + toStringHelper.add("maxUtilization", this.maxUtilization); + toStringHelper.add("minUtilization", this.minUtilization); + toStringHelper.add("overBookingFactor", this.overBookingFactor); + toStringHelper.add("tlvs", this.tlvs); + return super.addToStringAttributes(toStringHelper); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + this.maxHop; + result = prime * result + this.maxUtilization; + result = prime * result + this.minUtilization; + result = prime * result + this.overBookingFactor; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPGlobalConstraintsObject other = (PCEPGlobalConstraintsObject) obj; + if (this.maxHop != other.maxHop) + return false; + if (this.maxUtilization != other.maxUtilization) + return false; + if (this.minUtilization != other.minUtilization) + return false; + if (this.overBookingFactor != other.overBookingFactor) + return false; + return true; + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPIncludeRouteObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPIncludeRouteObject.java new file mode 100644 index 0000000000..783eafec00 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPIncludeRouteObject.java @@ -0,0 +1,82 @@ +/* + * 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.object; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Structure of Explicit Route Object. + * + * @see PCEP Include + * Route Object + */ +public class PCEPIncludeRouteObject extends PCEPObject { + + private final List subobjects; + + /** + * Constructs Include Route Object. + * + * @param subobjects + * List + * @param processed + * boolean + * @param ignored + * boolean + */ + public PCEPIncludeRouteObject(List subobjects, boolean processed, boolean ignored) { + super(processed, ignored); + if (subobjects == null || subobjects.isEmpty()) + throw new IllegalArgumentException("Subobjects can't be null or empty."); + this.subobjects = subobjects; + } + + /** + * Gets list of {@link ExplicitRouteSubobject} + * + * @return List. Can't be null or empty. + */ + public List getSubobjects() { + return this.subobjects; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.subobjects == null) ? 0 : this.subobjects.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPIncludeRouteObject other = (PCEPIncludeRouteObject) obj; + if (this.subobjects == null) { + if (other.subobjects != null) + return false; + } else if (!this.subobjects.equals(other.subobjects)) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("subobjects", this.subobjects); + return super.addToStringAttributes(toStringHelper); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPLoadBalancingObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPLoadBalancingObject.java new file mode 100644 index 0000000000..860fb67ee8 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPLoadBalancingObject.java @@ -0,0 +1,91 @@ +/* + * 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.object; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Bandwidth; + +import com.google.common.base.Objects.ToStringHelper; + +/** + * Structure for PCEP Load Balancing Object. + * + * @see PCEP Load Balancing Object + */ +public class PCEPLoadBalancingObject extends PCEPObject { + + private final int maxLSP; + + private final Bandwidth minBandwidth; + + /** + * Constructs Load Balancing Object. + * + * @param maxLSP int + * @param minBandwidth Bandwidth + * @param processed boolean + */ + public PCEPLoadBalancingObject(final int maxLSP, final Bandwidth minBandwidth, final boolean processed) { + super(processed, false); + this.maxLSP = maxLSP; + this.minBandwidth = minBandwidth; + } + + /** + * Gets Maximum LSP. + * + * @return int + */ + public int getMaxLSP() { + return this.maxLSP; + } + + /** + * Gets Minimal bandwidth. + * + * @return Bandwidth + */ + public Bandwidth getMinBandwidth() { + return this.minBandwidth; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + this.maxLSP; + result = prime * result + ((this.minBandwidth == null) ? 0 : this.minBandwidth.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPLoadBalancingObject other = (PCEPLoadBalancingObject) obj; + if (this.maxLSP != other.maxLSP) + return false; + if (this.minBandwidth == null) { + if (other.minBandwidth != null) + return false; + } else if (!this.minBandwidth.equals(other.minBandwidth)) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { + toStringHelper.add("maxLSP", this.maxLSP); + toStringHelper.add("minBandwidth", this.minBandwidth); + return super.addToStringAttributes(toStringHelper); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPLspObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPLspObject.java new file mode 100644 index 0000000000..e9d26f905f --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPLspObject.java @@ -0,0 +1,189 @@ +/* + * 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.object; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.PCEPTlv; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Structure of PCEP LSP Object. + * + * @see PCEP + * LSP Object + */ +public class PCEPLspObject extends PCEPObject { + + private final int lspID; + + private final boolean delegate; + + private final boolean sync; + + private final boolean operational; + + private final boolean remove; + + private final List tlvs; + + /** + * Constructs PCEP LSP Object only with mandatory values. + * + * @param lspID + * int + * @param delegate + * boolean + * @param sync + * boolean + * @param operational + * boolean + * @param remove + * boolean + */ + public PCEPLspObject(int lspID, boolean delegate, boolean sync, boolean operational, boolean remove) { + this(lspID, delegate, sync, operational, remove, null); + } + + /** + * Constructs PCEP LSP Object also with optional Objects. + * + * @param lspID + * int + * @param delegate + * boolean + * @param sync + * boolean + * @param operational + * boolean + * @param remove + * boolean + * @param tlvs + * List + */ + public PCEPLspObject(int lspID, boolean delegate, boolean sync, boolean operational, boolean remove, List tlvs) { + super(false, false); + this.lspID = lspID; + this.delegate = delegate; + this.sync = sync; + this.operational = operational; + this.remove = remove; + if (tlvs != null) + this.tlvs = tlvs; + else + this.tlvs = Collections.emptyList(); + } + + /** + * Gets integer representation of LSP ID. + * + * @return int + */ + public int getLspID() { + return this.lspID; + } + + /** + * Gets Delegate flag. + * + * @return boolean + */ + public boolean isDelegate() { + return this.delegate; + } + + /** + * Gets Sync flag. + * + * @return boolean + */ + public boolean isSync() { + return this.sync; + } + + /** + * Gets Operational flag. + * + * @return boolean + */ + public boolean isOperational() { + return this.operational; + } + + /** + * Gets Remove flag. + * + * @return boolean + */ + public boolean isRemove() { + return this.remove; + } + + /** + * Gets list of {@link PCEPTlv} + * + * @return List. Can't be null, but may be empty. + */ + public List getTlvs() { + return this.tlvs; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (this.delegate ? 1231 : 1237); + result = prime * result + this.lspID; + result = prime * result + (this.operational ? 1231 : 1237); + result = prime * result + (this.remove ? 1231 : 1237); + result = prime * result + (this.sync ? 1231 : 1237); + result = prime * result + ((this.tlvs == null) ? 0 : this.tlvs.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPLspObject other = (PCEPLspObject) obj; + if (this.delegate != other.delegate) + return false; + if (this.lspID != other.lspID) + return false; + if (this.operational != other.operational) + return false; + if (this.remove != other.remove) + return false; + if (this.sync != other.sync) + return false; + if (this.tlvs == null) { + if (other.tlvs != null) + return false; + } else if (!this.tlvs.equals(other.tlvs)) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("lspID", this.lspID); + toStringHelper.add("delegate", this.delegate); + toStringHelper.add("sync", this.sync); + toStringHelper.add("operational", this.operational); + toStringHelper.add("remove", this.remove); + toStringHelper.add("tlvs", this.tlvs); + return super.addToStringAttributes(toStringHelper); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPLspaObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPLspaObject.java new file mode 100644 index 0000000000..3b76b3f8f6 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPLspaObject.java @@ -0,0 +1,267 @@ +/* + * 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.object; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.PCEPTlv; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Structure for PCEP LSPA Object. + * + * @see PCEP LSPA + * Object + * @see SessionAttribute + * Object + * @see + * The Standby flag in the LSPA object + */ +public class PCEPLspaObject extends PCEPObject { + + private final long excludedAny; + + private final long includeAny; + + private final long includeAll; + + private final short setupPriority; + + private final short holdingPriority; + + private final boolean standByPath; + + private final boolean localProtected; + + private final List tlvs; + + /** + * Constructs object only with mandatory objects. + * + * @param excludedAny + * long + * @param includeAny + * long + * @param includeAll + * long + * @param setupPriority + * short + * @param holdingPriority + * short + * @param standByPath + * boolean + * @param localProtected + * boolean + * @param processed + * boolean + * @param ignored + * boolean + */ + public PCEPLspaObject(long excludedAny, long includeAny, long includeAll, short setupPriority, short holdingPriority, boolean standByPath, + boolean localProtected, boolean processed, boolean ignored) { + this(excludedAny, includeAny, includeAll, setupPriority, holdingPriority, standByPath, localProtected, null, processed, ignored); + } + + /** + * Constructs object also with optional objects. + * + * @param excludedAny + * long + * @param includeAny + * long + * @param includeAll + * long + * @param setupPriority + * short + * @param holdingPriority + * short + * @param localProtected + * boolean + * @param tlvs + * List + * @param processed + * boolean + * @param ignored + * boolean + */ + public PCEPLspaObject(long excludedAny, long includeAny, long includeAll, short setupPriority, short holdingPriority, boolean standByPath, + boolean localProtected, List tlvs, boolean processed, boolean ignored) { + super(processed, ignored); + this.excludedAny = excludedAny; + this.includeAny = includeAny; + this.includeAll = includeAll; + this.setupPriority = setupPriority; + this.holdingPriority = holdingPriority; + this.standByPath = standByPath; + this.localProtected = localProtected; + if (tlvs != null) + this.tlvs = tlvs; + else + this.tlvs = Collections.emptyList(); + } + + /** + * A 32-bit vector representing a set of attribute filters associated with a + * tunnel any of which renders a link unacceptable. + * + * @return long + */ + public long getExcludeAny() { + return this.excludedAny; + } + + /** + * A 32-bit vector representing a set of attribute filters associated with a + * tunnel any of which renders a link acceptable (with respect to this + * test). A null set (all bits set to zero) automatically passes. + * + * @return long + */ + public long getIncludeAny() { + return this.includeAny; + } + + /** + * A 32-bit vector representing a set of attribute filters associated with a + * tunnel all of which must be present for a link to be acceptable (with + * respect to this test). A null set (all bits set to zero) automatically + * passes. + * + * @return long + */ + public long getIncludeAll() { + return this.includeAll; + } + + /** + * The priority of TE LSP with respect to taking resources, in the range of + * 0 to 7 (validation not included). The value 0 is the highest priority. + * The Setup Priority is used in deciding whether this session can preempt + * another session. + * + * @return short + */ + public short getSetupPriority() { + return this.setupPriority; + } + + /** + * The priority of TE LSP with respect to holding resources, in the range of + * 0 to 7 (validation not included). The value 0 is the highest priority. + * Holding Priority is used in deciding whether this session can be + * preempted by another session. + * + * @return short + */ + public short getHoldingPriority() { + return this.holdingPriority; + } + + /** + * Corresponds to the "Local Protection Desired" bit ([RFC3209]) of + * SESSION-ATTRIBUTE Object. When set, this means that the computed path + * must include links protected with Fast REroute as defined in [RFC4090]. + * + * @return boolean + */ + public boolean isLocalProtected() { + return this.localProtected; + } + + /** + * The protection path setup regimen (standby or not) is specified in the + * path using a new per-path flag in the LSPA object, the S (standby) flag + * + * @return boolean + */ + public boolean isStandByPath() { + return this.standByPath; + } + + /** + * Gets list of {@link PCEPTlv} + * + * @return List. Can't be null, but may be empty. + */ + public List getTlvs() { + return this.tlvs; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (int) (this.excludedAny ^ (this.excludedAny >>> 32)); + result = prime * result + this.holdingPriority; + result = prime * result + (int) (this.includeAll ^ (this.includeAll >>> 32)); + result = prime * result + (int) (this.includeAny ^ (this.includeAny >>> 32)); + result = prime * result + (this.localProtected ? 1231 : 1237); + result = prime * result + this.setupPriority; + result = prime * result + (this.standByPath ? 1231 : 1237); + result = prime * result + ((this.tlvs == null) ? 0 : this.tlvs.hashCode()); + return result; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (!(obj instanceof PCEPLspaObject)) + return false; + final PCEPLspaObject other = (PCEPLspaObject) obj; + if (this.excludedAny != other.excludedAny) + return false; + if (this.holdingPriority != other.holdingPriority) + return false; + if (this.includeAll != other.includeAll) + return false; + if (this.includeAny != other.includeAny) + return false; + if (this.localProtected != other.localProtected) + return false; + if (this.setupPriority != other.setupPriority) + return false; + if (this.standByPath != other.standByPath) + return false; + if (this.tlvs == null) { + if (other.tlvs != null) + return false; + } else if (!this.tlvs.equals(other.tlvs)) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("excludedAny", this.excludedAny); + toStringHelper.add("includeAny", this.includeAny); + toStringHelper.add("includeAll", this.includeAll); + toStringHelper.add("setupPriority", this.setupPriority); + toStringHelper.add("holdingPriority", this.holdingPriority); + toStringHelper.add("standByPath", this.standByPath); + toStringHelper.add("localProtected", this.localProtected); + toStringHelper.add("tlvs", this.tlvs); + return super.addToStringAttributes(toStringHelper); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPMetricObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPMetricObject.java new file mode 100644 index 0000000000..ff0d056c43 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPMetricObject.java @@ -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.object; + +import org.opendaylight.protocol.concepts.AbstractMetric; +import org.opendaylight.protocol.pcep.PCEPObject; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Structure of PCEP Metric Object. + * + * @see PCEP Metric + * Object + */ +public class PCEPMetricObject extends PCEPObject { + + private final boolean bound; + + private final boolean computedMetric; + + private final AbstractMetric metric; + + /** + * Constructs PCEP Metric Object. + * + * @param bound + * boolean + * @param computedMetric + * boolean + * @param metric + * cannot be null + * @param processed + * boolean + * @param ignored + * boolean + */ + public PCEPMetricObject(boolean bound, boolean computedMetric, AbstractMetric metric, boolean processed, boolean ignored) { + super(processed, ignored); + this.bound = bound; + this.computedMetric = computedMetric; + if (metric == null) + throw new IllegalArgumentException("Mandatory parameter metric cannot be null."); + this.metric = metric; + } + + /** + * Gets Bound flag. + * + * @return boolean + */ + public boolean isBound() { + return this.bound; + } + + /** + * Gets Computed Metric flag. + * + * @return boolean + */ + public boolean isComputedMetric() { + return this.computedMetric; + } + + /** + * Gets {@link AbstractMetric}. + * + * @return AbstractMetric + */ + public AbstractMetric getMetric() { + return this.metric; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (this.bound ? 1231 : 1237); + result = prime * result + (this.computedMetric ? 1231 : 1237); + result = prime * result + ((this.metric == null) ? 0 : this.metric.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPMetricObject other = (PCEPMetricObject) obj; + if (this.bound != other.bound) + return false; + if (this.computedMetric != other.computedMetric) + return false; + if (this.metric == null) { + if (other.metric != null) + return false; + } else if (!this.metric.equals(other.metric)) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("bound", this.bound); + toStringHelper.add("computedMetric", this.computedMetric); + toStringHelper.add("metric", this.metric); + return super.addToStringAttributes(toStringHelper); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPNoPathObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPNoPathObject.java new file mode 100644 index 0000000000..df0ec7749f --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPNoPathObject.java @@ -0,0 +1,132 @@ +/* + * 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.object; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.PCEPTlv; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Structure of PCEP No Path Object. + * + * @see PCEP No Path + * Object + */ +public class PCEPNoPathObject extends PCEPObject { + + private final short natureOfIssue; + + private final boolean constrained; + + private final List tlvs; + + /** + * Constructs PCEP No Path Object only with mandatory values. + * + * @param natureOfIssue + * short + * @param constrained + * boolean + * @param ignored + * boolean + */ + public PCEPNoPathObject(short natureOfIssue, boolean constrained, boolean ignored) { + this(natureOfIssue, constrained, null, ignored); + } + + /** + * Constructs PCEP No Path Object also with optional Objects. + * + * @param natureOfIssue + * short + * @param constrained + * boolean + * @param tlvs + * List + * @param ignored + * boolean + */ + public PCEPNoPathObject(short natureOfIssue, boolean constrained, List tlvs, boolean ignored) { + super(false, ignored); + this.natureOfIssue = natureOfIssue; + this.constrained = constrained; + if (tlvs != null) + this.tlvs = tlvs; + else + this.tlvs = Collections.emptyList(); + } + + /** + * Returns short representation of Nature of issue. + * + * @return short + */ + public short getNatureOfIssue() { + return this.natureOfIssue; + } + + /** + * Gets Constrained flag. + * + * @return boolean + */ + public boolean isConstrained() { + return this.constrained; + } + + /** + * Gets list of {@link PCEPTlv} + * + * @return List. Can't be null, but may be empty. + */ + public List getTlvs() { + return this.tlvs; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (this.constrained ? 1231 : 1237); + result = prime * result + this.natureOfIssue; + result = prime * result + ((this.tlvs == null) ? 0 : this.tlvs.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPNoPathObject other = (PCEPNoPathObject) obj; + if (this.constrained != other.constrained) + return false; + if (this.natureOfIssue != other.natureOfIssue) + return false; + if (this.tlvs == null) { + if (other.tlvs != null) + return false; + } else if (!this.tlvs.equals(other.tlvs)) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("natureOfIssue", this.natureOfIssue); + toStringHelper.add("constrained", this.constrained); + toStringHelper.add("tlvs", this.tlvs); + return super.addToStringAttributes(toStringHelper); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPNonBranchNodeListObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPNonBranchNodeListObject.java new file mode 100644 index 0000000000..25a2ad3183 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPNonBranchNodeListObject.java @@ -0,0 +1,35 @@ +/* + * 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.object; + +import java.util.List; + +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; + +/** + * Structure of Non-Branch Node list object. + * + * @see Branch Node + * Object [RFC6006] + */ +public class PCEPNonBranchNodeListObject extends PCEPBranchNodeObject { + + /** + * Constructs Non-Branch Node list object. + * + * @param subobjects + * List + * @param processed + * boolean + * @param ignored + * boolean + */ + public PCEPNonBranchNodeListObject(List subobjects, boolean processed, boolean ignored) { + super(subobjects, processed, ignored); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPNotificationObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPNotificationObject.java new file mode 100644 index 0000000000..d0a797ad6f --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPNotificationObject.java @@ -0,0 +1,128 @@ +/* + * 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.object; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.PCEPTlv; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Structure of PCEP Notification Object. + * + * @see PCEP + * Notification Object + */ +public class PCEPNotificationObject extends PCEPObject { + + private final short type; + + private final short value; + + private List tlvs; + + /** + * Constructs PCEP Notification Object only with mandatory values. + * + * @param type + * short + * @param value + * short + */ + public PCEPNotificationObject(short type, short value) { + this(type, value, null); + } + + /** + * Constructs PCEP Notification Object also with optional Objects. + * + * @param type + * short + * @param value + * short + * @param tlvs + * List + */ + public PCEPNotificationObject(short type, short value, List tlvs) { + super(false, false); + this.type = type; + this.value = value; + if (tlvs != null) + this.tlvs = tlvs; + else + this.tlvs = Collections.emptyList(); + } + + /** + * Returns short representation of Type. + * + * @return short + */ + public short getType() { + return this.type; + } + + /** + * Returns short value. + * + * @return short + */ + public short getValue() { + return this.value; + } + + /** + * Gets list of {@link PCEPTlv} + * + * @return List. Can't be null, but may be empty. + */ + public List getTlvs() { + return this.tlvs; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.tlvs == null) ? 0 : this.tlvs.hashCode()); + result = prime * result + this.type; + result = prime * result + this.value; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPNotificationObject other = (PCEPNotificationObject) obj; + if (this.tlvs == null) { + if (other.tlvs != null) + return false; + } else if (!this.tlvs.equals(other.tlvs)) + return false; + if (this.type != other.type) + return false; + if (this.value != other.value) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("type", this.type); + toStringHelper.add("value", this.value); + toStringHelper.add("tlvs", this.tlvs); + return super.addToStringAttributes(toStringHelper); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPObjectiveFunctionObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPObjectiveFunctionObject.java new file mode 100644 index 0000000000..b264d8aaf5 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPObjectiveFunctionObject.java @@ -0,0 +1,120 @@ +/* + * 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.object; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPOFCodes; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.PCEPTlv; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Indicates the desired/required objective function to be applied by the PCE + * during path computation or within a PCRep message so as to indicate the + * objective function that was used by the PCE during path computation. + * + * @see OF Object + */ +public class PCEPObjectiveFunctionObject extends PCEPObject { + + private final PCEPOFCodes code; + + private final List tlvs; + + /** + * Constructs objective function object only with mandatory objects. + * + * @param code + * PCEPOFCodes + * @param processed + * boolean + * @param ignored + * boolean + */ + public PCEPObjectiveFunctionObject(PCEPOFCodes code, boolean processed, boolean ignored) { + this(code, null, processed, ignored); + } + + /** + * Constructs objective function object also with optional objects. + * + * @param code + * PCEPOFCodes + * @param tlvs + * the list of tlvs + * @param processed + * boolean + * @param ignored + * boolean + */ + public PCEPObjectiveFunctionObject(PCEPOFCodes code, List tlvs, boolean processed, boolean ignored) { + super(processed, ignored); + this.code = code; + + if (tlvs == null) + this.tlvs = Collections.emptyList(); + else + this.tlvs = tlvs; + } + + /** + * Gets the objective function code + * + * @return the PCEPOFCodes + */ + public PCEPOFCodes getCode() { + return this.code; + } + + /** + * Gets the list of tlvs + * + * @return the list of tlvs + */ + public List getTlvs() { + return this.tlvs; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("code", this.code); + toStringHelper.add("tlvs", this.tlvs); + return super.addToStringAttributes(toStringHelper); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.code == null) ? 0 : this.code.hashCode()); + result = prime * result + ((this.tlvs == null) ? 0 : this.tlvs.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPObjectiveFunctionObject other = (PCEPObjectiveFunctionObject) obj; + if (this.code != other.code) + return false; + if (this.tlvs == null) { + if (other.tlvs != null) + return false; + } else if (!this.tlvs.equals(other.tlvs)) + return false; + return true; + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPOpenObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPOpenObject.java new file mode 100644 index 0000000000..799190ff9f --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPOpenObject.java @@ -0,0 +1,150 @@ +/* + * 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.object; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.PCEPTlv; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Structure of PCEP Open Object. + * + * @see PCEP Open + * Object + */ +public class PCEPOpenObject extends PCEPObject { + + public static final int PCEP_VERSION = 1; + + private final int keepAliveTimerValue; + + private final int deadTimerValue; + + private final int sessionId; + + private final List tlvs; + + /** + * Constructs PCEP Open Object also with optional Objects. + * + * @param keepAliveTimerValue + * int + * @param deadTimerValue + * int + * @param sessionId + * int + * @param tlvs + * List + */ + public PCEPOpenObject(int keepAliveTimerValue, int deadTimerValue, int sessionId, List tlvs) { + super(false, false); + this.keepAliveTimerValue = keepAliveTimerValue; + this.deadTimerValue = deadTimerValue; + this.sessionId = sessionId; + if (tlvs != null) + this.tlvs = tlvs; + else + this.tlvs = Collections.emptyList(); + } + + /** + * Constructs PCEP Open Object only with mandatory values. + * + * @param keepAliveTimerValue + * int + * @param deadTimerValue + * int + * @param sessionId + * int + */ + public PCEPOpenObject(int keepAliveTimerValue, int deadTimerValue, int sessionId) { + this(keepAliveTimerValue, deadTimerValue, sessionId, Collections. emptyList()); + } + + /** + * Returns integer representation of Keep Alive Timer. + * + * @return int + */ + public int getKeepAliveTimerValue() { + return this.keepAliveTimerValue; + } + + /** + * Returns integer representation of Dead Timer. + * + * @return int + */ + public int getDeadTimerValue() { + return this.deadTimerValue; + } + + /** + * Returns integer representation of Session ID. + * + * @return int + */ + public int getSessionId() { + return this.sessionId; + } + + /** + * Gets list of {@link PCEPTlv}. + * + * @return List + */ + public List getTlvs() { + return this.tlvs; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + this.deadTimerValue; + result = prime * result + this.keepAliveTimerValue; + result = prime * result + this.sessionId; + result = prime * result + ((this.tlvs == null) ? 0 : this.tlvs.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPOpenObject other = (PCEPOpenObject) obj; + if (this.deadTimerValue != other.deadTimerValue) + return false; + if (this.keepAliveTimerValue != other.keepAliveTimerValue) + return false; + if (this.sessionId != other.sessionId) + return false; + if (this.tlvs == null) { + if (other.tlvs != null) + return false; + } else if (!this.tlvs.equals(other.tlvs)) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("keepAliveTimerValue", this.keepAliveTimerValue); + toStringHelper.add("deadTimerValue", this.deadTimerValue); + toStringHelper.add("sessionId", this.sessionId); + toStringHelper.add("tlvs", this.tlvs); + return super.addToStringAttributes(toStringHelper); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPP2MPEndPointsObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPP2MPEndPointsObject.java new file mode 100644 index 0000000000..af20d8cc04 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPP2MPEndPointsObject.java @@ -0,0 +1,96 @@ +/* + * 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.object; + +import java.util.List; + +import org.opendaylight.protocol.concepts.NetworkAddress; +import com.google.common.base.Objects.ToStringHelper; + +public class PCEPP2MPEndPointsObject> extends PCEPEndPoints { + + private final long leafType; + + private final T sourceAddress; + + private final List destinationAddresses; + + public PCEPP2MPEndPointsObject(long leafType, T sourceAddress, List destinationAddresses, boolean processed, boolean ignored) { + super(processed, ignored); + this.leafType = leafType; + this.sourceAddress = sourceAddress; + if (destinationAddresses == null || destinationAddresses.isEmpty()) + throw new IllegalArgumentException("At least one destination have to be specified."); + + this.destinationAddresses = destinationAddresses; + } + + /** + * @return the leafType + */ + public long getLeafType() { + return this.leafType; + } + + /** + * @return the sourceAddress + */ + public T getSourceAddress() { + return this.sourceAddress; + } + + /** + * @return the destinationAddresses + */ + public List getDestinationAddresses() { + return this.destinationAddresses; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.destinationAddresses == null) ? 0 : this.destinationAddresses.hashCode()); + result = prime * result + (int) (this.leafType ^ (this.leafType >>> 32)); + result = prime * result + ((this.sourceAddress == null) ? 0 : this.sourceAddress.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPP2MPEndPointsObject other = (PCEPP2MPEndPointsObject) obj; + if (this.destinationAddresses == null) { + if (other.destinationAddresses != null) + return false; + } else if (!this.destinationAddresses.equals(other.destinationAddresses)) + return false; + if (this.leafType != other.leafType) + return false; + if (this.sourceAddress == null) { + if (other.sourceAddress != null) + return false; + } else if (!this.sourceAddress.equals(other.sourceAddress)) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("leafType", this.leafType); + toStringHelper.add("sourceAddress", this.sourceAddress); + toStringHelper.add("destinationAddresses", this.destinationAddresses); + return super.addToStringAttributes(toStringHelper); + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPReportedRouteObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPReportedRouteObject.java new file mode 100644 index 0000000000..25dbdc1a66 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPReportedRouteObject.java @@ -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.protocol.pcep.object; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.subobject.ReportedRouteSubobject; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Structure of PCEP Reported Route Object. + * + * @see PCEP Reported + * Route Object + */ +public class PCEPReportedRouteObject extends PCEPObject { + + private final List subobjects; + + /** + * Constructs PCEP Reported Route Object. + * + * @param subobjects + * List. Can't be null or empty. + * @param processed + * boolean + */ + public PCEPReportedRouteObject(List subobjects, boolean processed) { + super(processed, false); + if (subobjects == null || subobjects.isEmpty()) + throw new IllegalArgumentException("Subobjects can't be null or empty."); + this.subobjects = subobjects; + } + + /** + * Gets list of {@link ReportedRouteSubobject}. + * + * @return List. Can't be null or empty. + */ + public List getSubobjects() { + return this.subobjects; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("subobjects", this.subobjects); + return super.addToStringAttributes(toStringHelper); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.subobjects == null) ? 0 : this.subobjects.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPReportedRouteObject other = (PCEPReportedRouteObject) obj; + if (this.subobjects == null) { + if (other.subobjects != null) + return false; + } else if (!this.subobjects.equals(other.subobjects)) + return false; + return true; + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPRequestParameterObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPRequestParameterObject.java new file mode 100644 index 0000000000..650dc6834b --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPRequestParameterObject.java @@ -0,0 +1,327 @@ +/* + * 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.object; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.PCEPTlv; +import org.opendaylight.protocol.pcep.tlv.OrderTlv; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Structure of PCEP Requested Parameter Object. + * + * @see PCEP Request + * Parameter Object [RFC5440] + * @see RP Object + * Flag [RFC5541] + * @see The Extension + * of the RP Object [RFC6006] + */ +public class PCEPRequestParameterObject extends PCEPObject { + + private final boolean loose; + + private final boolean bidirectional; + + private final boolean reoptimized; + + private final boolean makeBeforeBreak; + + private final boolean reportRequestOrder; + + private final boolean suplyOFOnResponse; + + /* + * RFC6006 flags + */ + private final boolean fragmentation; + + private final boolean p2mp; + + private final boolean eroCompression; + + // End of flags + + private final short priority; + + private final long requestID; + + private final List tlvs; + + /** + * Constructs PCEP Requested Parameter Object only with mandatory values. + * + * @param loose + * boolean + * @param bidirectional + * boolean + * @param reoptimized + * boolean + * @param makeBeforeBreak + * boolean + * @param suplyOFOnResponse + * boolean + * @param priority + * short + * @param requestID + * long + * @param processed + * boolean + * @param ignored + * boolean; + */ + public PCEPRequestParameterObject(boolean loose, boolean bidirectional, boolean reoptimized, boolean makeBeforeBreak, boolean suplyOFOnResponse, + boolean fragmentation, boolean p2mp, boolean eroCompression, short priority, long requestID, boolean processed, boolean ignored) { + this(loose, bidirectional, reoptimized, makeBeforeBreak, false, suplyOFOnResponse, fragmentation, p2mp, eroCompression, priority, requestID, null, + processed, ignored); + } + + /** + * Constructs PCEP Requested Parameter Object also with optional Objects. + * + * @param loose + * boolean + * @param bidirectional + * boolean + * @param reoptimized + * boolean + * @param makeBeforeBreak + * boolean + * @param reportRequestOrder + * boolean + * @param suplyOFOnResponse + * boolean + * @param priority + * short + * @param requestID + * long + * @param tlvs + * List + * @param processed + * boolean + * @param ignored + * boolean + */ + public PCEPRequestParameterObject(boolean loose, boolean bidirectional, boolean reoptimized, boolean makeBeforeBreak, boolean reportRequestOrder, + boolean suplyOFOnResponse, boolean fragmentation, boolean p2mp, boolean eroCompression, short priority, long requestID, List tlvs, + boolean processed, boolean ignored) { + super(processed, ignored); + this.loose = loose; + this.bidirectional = bidirectional; + this.reoptimized = reoptimized; + this.makeBeforeBreak = makeBeforeBreak; + this.reportRequestOrder = reportRequestOrder; + this.suplyOFOnResponse = suplyOFOnResponse; + this.fragmentation = fragmentation; + this.p2mp = p2mp; + this.eroCompression = eroCompression; + + this.priority = priority; + this.requestID = requestID; + if (tlvs != null) + this.tlvs = tlvs; + else + this.tlvs = Collections.emptyList(); + + if (makeBeforeBreak && !reoptimized) + throw new IllegalArgumentException("M (make-before-break) can be set only if R (reoptimied) flag is set too."); + + if (reportRequestOrder && !this.validateOrderTlv()) + throw new IllegalArgumentException("D (report request order) flag is set, but missing OrderTlv."); + } + + /** + * Gets Loose flag. + * + * @return boolean + */ + public boolean isLoose() { + return this.loose; + } + + /** + * Gets Bidirectional flag. + * + * @return boolean + */ + public boolean isBidirectional() { + return this.bidirectional; + } + + /** + * Gets Reoptimization flag. + * + * @return boolean + */ + public boolean isReoptimized() { + return this.reoptimized; + } + + /** + * Gets make-before-break flag + * + * @return boolean + */ + public boolean isMakeBeforeBreak() { + return this.makeBeforeBreak; + } + + /** + * Gets report requested order flag + * + * @return boolean + */ + public boolean isReportRequestOrder() { + return this.reportRequestOrder; + } + + /** + * Gets report supply objective function on response flag + * + * @return boolean + */ + public boolean isSuplyOFOnResponse() { + return this.suplyOFOnResponse; + } + + /** + * @return the fragmentation + */ + public boolean isFragmentation() { + return this.fragmentation; + } + + /** + * @return the p2mp + */ + public boolean isP2mp() { + return this.p2mp; + } + + /** + * @return the eroCompression + */ + public boolean isEroCompression() { + return this.eroCompression; + } + + /** + * Returns short representation of Priority. + * + * @return short + */ + public short getPriority() { + return this.priority; + } + + /** + * Returns long representation of Requested ID. + * + * @return long + */ + public long getRequestID() { + return this.requestID; + } + + /** + * Gets list of {@link PCEPTlv} + * + * @return List. Can't be null, but may be empty. + */ + public List getTlvs() { + return this.tlvs; + } + + private boolean validateOrderTlv() { + for (final PCEPTlv tlv : this.tlvs) { + if (tlv instanceof OrderTlv) + return true; + } + + return false; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (this.bidirectional ? 1231 : 1237); + result = prime * result + (this.eroCompression ? 1231 : 1237); + result = prime * result + (this.fragmentation ? 1231 : 1237); + result = prime * result + (this.loose ? 1231 : 1237); + result = prime * result + (this.makeBeforeBreak ? 1231 : 1237); + result = prime * result + (this.p2mp ? 1231 : 1237); + result = prime * result + this.priority; + result = prime * result + (this.reoptimized ? 1231 : 1237); + result = prime * result + (this.reportRequestOrder ? 1231 : 1237); + result = prime * result + (int) (this.requestID ^ (this.requestID >>> 32)); + result = prime * result + (this.suplyOFOnResponse ? 1231 : 1237); + result = prime * result + ((this.tlvs == null) ? 0 : this.tlvs.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPRequestParameterObject other = (PCEPRequestParameterObject) obj; + if (this.bidirectional != other.bidirectional) + return false; + if (this.eroCompression != other.eroCompression) + return false; + if (this.fragmentation != other.fragmentation) + return false; + if (this.loose != other.loose) + return false; + if (this.makeBeforeBreak != other.makeBeforeBreak) + return false; + if (this.p2mp != other.p2mp) + return false; + if (this.priority != other.priority) + return false; + if (this.reoptimized != other.reoptimized) + return false; + if (this.reportRequestOrder != other.reportRequestOrder) + return false; + if (this.requestID != other.requestID) + return false; + if (this.suplyOFOnResponse != other.suplyOFOnResponse) + return false; + if (this.tlvs == null) { + if (other.tlvs != null) + return false; + } else if (!this.tlvs.equals(other.tlvs)) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("loose", this.loose); + toStringHelper.add("bidirectional", this.bidirectional); + toStringHelper.add("reoptimized", this.reoptimized); + toStringHelper.add("makeBeforeBreak", this.makeBeforeBreak); + toStringHelper.add("reportRequestOrder", this.reportRequestOrder); + toStringHelper.add("suplyOFOnResponse", this.suplyOFOnResponse); + toStringHelper.add("fragmentation", this.fragmentation); + toStringHelper.add("p2mp", this.p2mp); + toStringHelper.add("eroCompression", this.eroCompression); + toStringHelper.add("priority", this.priority); + toStringHelper.add("requestID", this.requestID); + toStringHelper.add("tlvs", this.tlvs); + return super.addToStringAttributes(toStringHelper); + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPRequestedPathBandwidthObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPRequestedPathBandwidthObject.java new file mode 100644 index 0000000000..136b9b69da --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPRequestedPathBandwidthObject.java @@ -0,0 +1,27 @@ +/* + * 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.object; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Bandwidth; + +/** + * Structure of specific Bandwidth. Used for example in Composite Requested Object to request specific bandwidth. + */ +public class PCEPRequestedPathBandwidthObject extends PCEPBandwidthObject { + + /** + * Constructs Requested Path Bandwidth. + * + * @param bandwidth Bandwidth. Can't be null. + * @param processed boolean + * @param ignored boolean + */ + public PCEPRequestedPathBandwidthObject(final Bandwidth bandwidth, final boolean processed, final boolean ignored) { + super(bandwidth, processed, ignored); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPSecondaryExplicitRouteObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPSecondaryExplicitRouteObject.java new file mode 100644 index 0000000000..f3e8861f5c --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPSecondaryExplicitRouteObject.java @@ -0,0 +1,83 @@ +/* + * 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.object; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; +import com.google.common.base.Objects.ToStringHelper; + +/** + * @author miroslav + * + * May 2012 + * + * Copyright (c) 2012 by Cisco Systems, Inc. All rights reserved. + */ + +public class PCEPSecondaryExplicitRouteObject extends PCEPObject { + + private final List subobjects; + + /** + * Constructs Secondary Explicit Route Object. + * + * @param subobjects + * List. Can't be null or empty. + * @param ignored + * boolean + */ + public PCEPSecondaryExplicitRouteObject(List subobjects, boolean processed, boolean ignored) { + super(processed, ignored); + if (subobjects == null || subobjects.isEmpty()) + throw new IllegalArgumentException("Subobjects can't be null or empty."); + this.subobjects = subobjects; + } + + /** + * Gets list of {@link ExplicitRouteSubobject} + * + * @return List. Can't be null or empty. + */ + public List getSubobjects() { + return this.subobjects; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("subobjects", this.subobjects); + return super.addToStringAttributes(toStringHelper); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.subobjects == null) ? 0 : this.subobjects.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPSecondaryExplicitRouteObject other = (PCEPSecondaryExplicitRouteObject) obj; + if (this.subobjects == null) { + if (other.subobjects != null) + return false; + } else if (!this.subobjects.equals(other.subobjects)) + return false; + return true; + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPSecondaryRecordRouteObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPSecondaryRecordRouteObject.java new file mode 100644 index 0000000000..69d6cd227d --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPSecondaryRecordRouteObject.java @@ -0,0 +1,75 @@ +/* + * 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.object; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.subobject.ReportedRouteSubobject; +import com.google.common.base.Objects.ToStringHelper; + +public class PCEPSecondaryRecordRouteObject extends PCEPObject { + + private final List subobjects; + + /** + * Constructs Secondary Record Route Object. + * + * @param subobjects + * List. Can't be null or empty. + * @param ignored + * boolean + */ + public PCEPSecondaryRecordRouteObject(List subobjects, boolean processed, boolean ignored) { + super(processed, ignored); + if (subobjects == null || subobjects.isEmpty()) + throw new IllegalArgumentException("Subobjects can't be null or empty."); + this.subobjects = subobjects; + } + + /** + * Gets list of {@link ReportedRouteSubobject} + * + * @return List. Can't be null or empty. + */ + public List getSubobjects() { + return this.subobjects; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("subobjects", this.subobjects); + return super.addToStringAttributes(toStringHelper); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.subobjects == null) ? 0 : this.subobjects.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPSecondaryRecordRouteObject other = (PCEPSecondaryRecordRouteObject) obj; + if (this.subobjects == null) { + if (other.subobjects != null) + return false; + } else if (!this.subobjects.equals(other.subobjects)) + return false; + return true; + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPSvecObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPSvecObject.java new file mode 100644 index 0000000000..4a618eb64a --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPSvecObject.java @@ -0,0 +1,154 @@ +/* + * 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.object; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPObject; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Structure of PCEP SVEC Object. + * + * @see PCEP SVEC + * Object + * @see Synchronization + * of P2MP TE Path Computation Requests [RFC6006] + */ +public class PCEPSvecObject extends PCEPObject { + + private final boolean linkDiversed; + + private final boolean nodeDiversed; + + private final boolean srlgDiversed; + + private final boolean paritialPathDiversed; + + private final boolean linkDirectionDiversed; + + private final List requestIDs; + + /** + * Constructs PCEP SVEC Object. + * + * @param linkDiversed + * boolean + * @param nodeDiversed + * boolean + * @param srlgDiversed + * boolean + * @param requestIDs + * List. Can't be null or empty. + * @param processed + * boolean + */ + public PCEPSvecObject(boolean linkDiversed, boolean nodeDiversed, boolean srlgDiversed, boolean partialPathDiversed, boolean linkDirectionDiversed, + List requestIDs, boolean processed) { + super(processed, false); + this.linkDiversed = linkDiversed; + this.nodeDiversed = nodeDiversed; + this.srlgDiversed = srlgDiversed; + this.paritialPathDiversed = partialPathDiversed; + this.linkDirectionDiversed = linkDirectionDiversed; + + if (requestIDs == null || requestIDs.isEmpty()) + throw new IllegalArgumentException("RequestIDs can't be null or empty."); + this.requestIDs = requestIDs; + } + + /** + * Gets Link Diversed flag. + * + * @return boolean + */ + public boolean isLinkDiversed() { + return this.linkDiversed; + } + + /** + * Gets Node Diversed flag. + * + * @return boolean + */ + public boolean isNodeDiversed() { + return this.nodeDiversed; + } + + /** + * Gets Srlg Diversed flag. + * + * @return boolean + */ + public boolean isSrlgDiversed() { + return this.srlgDiversed; + } + + public boolean isParitialPathDiversed() { + return this.paritialPathDiversed; + } + + public boolean isLinkDirectionDiversed() { + return this.linkDirectionDiversed; + } + + /** + * Gets list of Long representations of RequestIDs. + * + * @return List. Can't be null or empty. + */ + public List getRequestIDs() { + return this.requestIDs; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (this.linkDiversed ? 1231 : 1237); + result = prime * result + (this.nodeDiversed ? 1231 : 1237); + result = prime * result + ((this.requestIDs == null) ? 0 : this.requestIDs.hashCode()); + result = prime * result + (this.srlgDiversed ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPSvecObject other = (PCEPSvecObject) obj; + if (this.linkDiversed != other.linkDiversed) + return false; + if (this.nodeDiversed != other.nodeDiversed) + return false; + if (this.requestIDs == null) { + if (other.requestIDs != null) + return false; + } else if (!this.requestIDs.equals(other.requestIDs)) + return false; + if (this.srlgDiversed != other.srlgDiversed) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("linkDiversed", this.linkDiversed); + toStringHelper.add("nodeDiversed", this.nodeDiversed); + toStringHelper.add("srlgDiversed", this.srlgDiversed); + toStringHelper.add("paritialPathDiversed", this.paritialPathDiversed); + toStringHelper.add("linkDirectionDiversed", this.linkDirectionDiversed); + toStringHelper.add("requestIDs", this.requestIDs); + return super.addToStringAttributes(toStringHelper); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPUnreachedDestinationObject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPUnreachedDestinationObject.java new file mode 100644 index 0000000000..37b6d8c2b3 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/object/PCEPUnreachedDestinationObject.java @@ -0,0 +1,63 @@ +/* + * 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.object; + +import java.util.List; + +import org.opendaylight.protocol.concepts.NetworkAddress; +import org.opendaylight.protocol.pcep.PCEPObject; +import com.google.common.base.Objects.ToStringHelper; + +public class PCEPUnreachedDestinationObject> extends PCEPObject { + + private final List unreachedDestinations; + + public PCEPUnreachedDestinationObject(List unreachedDestinations, boolean processed, boolean ignored) { + super(processed, ignored); + if (unreachedDestinations == null || unreachedDestinations.isEmpty()) + throw new IllegalArgumentException("At least one destination have to be specified."); + + this.unreachedDestinations = unreachedDestinations; + } + + public List getUnreachedDestinations() { + return this.unreachedDestinations; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.unreachedDestinations == null) ? 0 : this.unreachedDestinations.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPUnreachedDestinationObject other = (PCEPUnreachedDestinationObject) obj; + if (this.unreachedDestinations == null) { + if (other.unreachedDestinations != null) + return false; + } else if (!this.unreachedDestinations.equals(other.unreachedDestinations)) + return false; + return true; + } + + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { + toStringHelper.add("unreachedDestinations", this.unreachedDestinations); + return super.addToStringAttributes(toStringHelper); + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/subobject/EROUnnumberedInterfaceSubobject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/subobject/EROUnnumberedInterfaceSubobject.java index 8b5bc9675f..516a4c2876 100644 --- a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/subobject/EROUnnumberedInterfaceSubobject.java +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/subobject/EROUnnumberedInterfaceSubobject.java @@ -9,27 +9,30 @@ package org.opendaylight.protocol.pcep.subobject; import org.opendaylight.protocol.concepts.IPv4Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.UnnumberedSubobject; - +import org.opendaylight.protocol.pcep.concepts.UnnumberedInterfaceIdentifier; import com.google.common.base.Objects.ToStringHelper; /** - * Structure of unnumbered Interface Subobject. - * - * @see Section 4: Signalling Unnumbered Links in EROs + * Structure of unnumbered Iterface Subobject. + * + * @see Section 4: Signalling + * Unnumbered Links in EROs */ public class EROUnnumberedInterfaceSubobject extends ExplicitRouteSubobject { - private final UnnumberedSubobject interfaceID; + private final UnnumberedInterfaceIdentifier interfaceID; private final IPv4Address routerID; /** * Constructs new Unnumbered Interface Subobject. - * - * @param routerID IPv4Address - * @param interfaceID UnnumberedInterfaceIdentifier - * @param loose boolean + * + * @param routerID + * IPv4Address + * @param interfaceID + * UnnumberedInterfaceIdentifier + * @param loose + * boolean */ - public EROUnnumberedInterfaceSubobject(final IPv4Address routerID, final UnnumberedSubobject interfaceID, final boolean loose) { + public EROUnnumberedInterfaceSubobject(final IPv4Address routerID, final UnnumberedInterfaceIdentifier interfaceID, boolean loose) { super(loose); this.routerID = routerID; this.interfaceID = interfaceID; @@ -37,7 +40,7 @@ public class EROUnnumberedInterfaceSubobject extends ExplicitRouteSubobject { /** * Gets {@link IPv4Address} representation of router ID. - * + * * @return IPv4Address */ public IPv4Address getRouterID() { @@ -45,11 +48,12 @@ public class EROUnnumberedInterfaceSubobject extends ExplicitRouteSubobject { } /** - * Gets {@link UnnumberedSubobject} representation of Interface ID. - * - * @return UnnumberedSubobject + * Gets {@link UnnumberedInterfaceIdentifier} representation of Interface + * ID. + * + * @return UnnumberedInterfaceIdentifier */ - public UnnumberedSubobject getInterfaceID() { + public UnnumberedInterfaceIdentifier getInterfaceID() { return this.interfaceID; } @@ -63,7 +67,7 @@ public class EROUnnumberedInterfaceSubobject extends ExplicitRouteSubobject { } @Override - public boolean equals(final Object obj) { + public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) @@ -97,8 +101,8 @@ public class EROUnnumberedInterfaceSubobject extends ExplicitRouteSubobject { return builder.toString(); } - @Override - protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { + @Override + protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) { toStringHelper.add("interfaceID", this.interfaceID); toStringHelper.add("routerID", this.routerID); toStringHelper.add("loose", this.loose); diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/subobject/RROUnnumberedInterfaceSubobject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/subobject/RROUnnumberedInterfaceSubobject.java index c07ccd226d..9a96848a7e 100644 --- a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/subobject/RROUnnumberedInterfaceSubobject.java +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/subobject/RROUnnumberedInterfaceSubobject.java @@ -9,87 +9,91 @@ package org.opendaylight.protocol.pcep.subobject; import org.opendaylight.protocol.concepts.IPv4Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.UnnumberedSubobject; +import org.opendaylight.protocol.pcep.concepts.UnnumberedInterfaceIdentifier; /** * Structure of unnumbered Iterface Subobject. - * - * @see Section 4: Signalling Unnumbered Links in EROs + * + * @see Section 4: Signalling + * Unnumbered Links in EROs */ public class RROUnnumberedInterfaceSubobject extends ReportedRouteSubobject { - private final UnnumberedSubobject interfaceID; - private final IPv4Address routerID; + private final UnnumberedInterfaceIdentifier interfaceID; + private final IPv4Address routerID; - /** - * Constructs new Unnumbered Interface Subobject. - * - * @param routerID IPv4Address - * @param interfaceID UnnumberedInterfaceIdentifier - */ - public RROUnnumberedInterfaceSubobject(final IPv4Address routerID, final UnnumberedSubobject interfaceID) { - super(); - this.routerID = routerID; - this.interfaceID = interfaceID; - } + /** + * Constructs new Unnumbered Interface Subobject. + * + * @param routerID + * IPv4Address + * @param interfaceID + * UnnumberedInterfaceIdentifier + */ + public RROUnnumberedInterfaceSubobject(final IPv4Address routerID, final UnnumberedInterfaceIdentifier interfaceID) { + super(); + this.routerID = routerID; + this.interfaceID = interfaceID; + } - /** - * Gets {@link IPv4Address} representation of router ID. - * - * @return IPv4Address - */ - public IPv4Address getRouterID() { - return this.routerID; - } + /** + * Gets {@link IPv4Address} representation of router ID. + * + * @return IPv4Address + */ + public IPv4Address getRouterID() { + return this.routerID; + } - /** - * Gets {@link UnnumberedSubobject} representation of Interface ID. - * - * @return UnnumberedSubobject - */ - public UnnumberedSubobject getInterfaceID() { - return this.interfaceID; - } + /** + * Gets {@link UnnumberedInterfaceIdentifier} representation of Interface + * ID. + * + * @return UnnumberedInterfaceIdentifier + */ + public UnnumberedInterfaceIdentifier getInterfaceID() { + return this.interfaceID; + } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((this.interfaceID == null) ? 0 : this.interfaceID.hashCode()); - result = prime * result + ((this.routerID == null) ? 0 : this.routerID.hashCode()); - return result; - } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.interfaceID == null) ? 0 : this.interfaceID.hashCode()); + result = prime * result + ((this.routerID == null) ? 0 : this.routerID.hashCode()); + return result; + } - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (this.getClass() != obj.getClass()) - return false; - final RROUnnumberedInterfaceSubobject other = (RROUnnumberedInterfaceSubobject) obj; - if (this.interfaceID == null) { - if (other.interfaceID != null) - return false; - } else if (!this.interfaceID.equals(other.interfaceID)) - return false; - if (this.routerID == null) { - if (other.routerID != null) - return false; - } else if (!this.routerID.equals(other.routerID)) - return false; - return true; - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final RROUnnumberedInterfaceSubobject other = (RROUnnumberedInterfaceSubobject) obj; + if (this.interfaceID == null) { + if (other.interfaceID != null) + return false; + } else if (!this.interfaceID.equals(other.interfaceID)) + return false; + if (this.routerID == null) { + if (other.routerID != null) + return false; + } else if (!this.routerID.equals(other.routerID)) + return false; + return true; + } - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("RROUnnumberedInterfaceSubobject [interfaceID="); - builder.append(this.interfaceID); - builder.append(", routerID="); - builder.append(this.routerID); - builder.append("]"); - return builder.toString(); - } + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("RROUnnumberedInterfaceSubobject [interfaceID="); + builder.append(this.interfaceID); + builder.append(", routerID="); + builder.append(this.routerID); + builder.append("]"); + return builder.toString(); + } } diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/subobject/XROUnnumberedInterfaceSubobject.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/subobject/XROUnnumberedInterfaceSubobject.java index d7e128ca22..a05887a035 100644 --- a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/subobject/XROUnnumberedInterfaceSubobject.java +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/subobject/XROUnnumberedInterfaceSubobject.java @@ -8,31 +8,36 @@ package org.opendaylight.protocol.pcep.subobject; import org.opendaylight.protocol.concepts.IPv4Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.UnnumberedSubobject; +import org.opendaylight.protocol.pcep.concepts.UnnumberedInterfaceIdentifier; /** - * Structure of unnumbered Interface Subobject. Defined in RFC5521. - * - * @see Exclude Route Object definition + * Structure of unnumbered Iterface Subobject. Defined in RFC5521. + * + * @see Exclude Route + * Object definition */ public class XROUnnumberedInterfaceSubobject extends ExcludeRouteSubobject { private final XROSubobjectAttribute attribute; - private final UnnumberedSubobject interfaceID; + private final UnnumberedInterfaceIdentifier interfaceID; private final IPv4Address routerID; /** * Constructs new Unnumbered Interface Subobject. - * - * @param routerID IPv4Address - * @param interfaceID UnnumberedInterfaceIdentifier - * @param mandatory boolean - * @param attribute XROSubobjectAttribute + * + * @param routerID + * IPv4Address + * @param interfaceID + * UnnumberedInterfaceIdentifier + * @param mandatory + * boolean + * @param attribute + * XROSubobjectAttribute */ - public XROUnnumberedInterfaceSubobject(final IPv4Address routerID, final UnnumberedSubobject interfaceID, final boolean mandatory, - final XROSubobjectAttribute attribute) { + public XROUnnumberedInterfaceSubobject(final IPv4Address routerID, final UnnumberedInterfaceIdentifier interfaceID, boolean mandatory, + XROSubobjectAttribute attribute) { super(mandatory); this.attribute = attribute; this.routerID = routerID; @@ -41,7 +46,7 @@ public class XROUnnumberedInterfaceSubobject extends ExcludeRouteSubobject { /** * Gets the attribute of the subobject - * + * * @return the attribute */ public XROSubobjectAttribute getAttribute() { @@ -50,7 +55,7 @@ public class XROUnnumberedInterfaceSubobject extends ExcludeRouteSubobject { /** * Gets {@link IPv4Address} representation of router ID. - * + * * @return IPv4Address */ public IPv4Address getRouterID() { @@ -58,11 +63,12 @@ public class XROUnnumberedInterfaceSubobject extends ExcludeRouteSubobject { } /** - * Gets {@link UnnumberedInterfaceIdentifier} representation of Interface ID. - * + * Gets {@link UnnumberedInterfaceIdentifier} representation of Interface + * ID. + * * @return UnnumberedInterfaceIdentifier */ - public UnnumberedSubobject getInterfaceID() { + public UnnumberedInterfaceIdentifier getInterfaceID() { return this.interfaceID; } @@ -77,7 +83,7 @@ public class XROUnnumberedInterfaceSubobject extends ExcludeRouteSubobject { } @Override - public boolean equals(final Object obj) { + public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/AbstractLSPIdentifiersTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/AbstractLSPIdentifiersTlv.java new file mode 100644 index 0000000000..3f1dee3c34 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/AbstractLSPIdentifiersTlv.java @@ -0,0 +1,139 @@ +/* + * 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.tlv; + +import org.opendaylight.protocol.concepts.NetworkAddress; +import org.opendaylight.protocol.pcep.concepts.ExtendedTunnelIdentifier; +import org.opendaylight.protocol.pcep.concepts.LSPIdentifier; +import org.opendaylight.protocol.pcep.concepts.TunnelIdentifier; + +/** + * Basic structure of LSP Identifiers TLV. + * + * @see LSP + * Identifiers TLVs + * @param + */ +public abstract class AbstractLSPIdentifiersTlv> implements LSPIdentifiersTlv { + private static final long serialVersionUID = 2386922658825295806L; + + private final T senderAddress; + + private final LSPIdentifier lspID; + + private final TunnelIdentifier tunnelID; + + private final ExtendedTunnelIdentifier extendedTunnelID; + + /** + * Construct LSP Identifier TLV with mandatory objects. + * + * @param senderAddress + * @param lspID + * @param tunnelID + * @param extendedTunnelID + */ + protected AbstractLSPIdentifiersTlv(T senderAddress, LSPIdentifier lspID, TunnelIdentifier tunnelID, ExtendedTunnelIdentifier extendedTunnelID) { + if (senderAddress == null) + throw new IllegalArgumentException("SenderAdress is mandatory."); + this.senderAddress = senderAddress; + + if (lspID == null) + throw new IllegalArgumentException("LspID is mandatory."); + this.lspID = lspID; + + if (tunnelID == null) + throw new IllegalArgumentException("TunnelID is mandatory."); + this.tunnelID = tunnelID; + + if (extendedTunnelID == null) + throw new IllegalArgumentException("ExtendedTunnelID is mandatory."); + this.extendedTunnelID = extendedTunnelID; + } + + @Override + public T getSenderAddress() { + return this.senderAddress; + } + + @Override + public LSPIdentifier getLspID() { + return this.lspID; + } + + @Override + public TunnelIdentifier getTunnelID() { + return this.tunnelID; + } + + @Override + public ExtendedTunnelIdentifier getExtendedTunnelID() { + return this.extendedTunnelID; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.extendedTunnelID == null) ? 0 : this.extendedTunnelID.hashCode()); + result = prime * result + ((this.lspID == null) ? 0 : this.lspID.hashCode()); + result = prime * result + ((this.senderAddress == null) ? 0 : this.senderAddress.hashCode()); + result = prime * result + ((this.tunnelID == null) ? 0 : this.tunnelID.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final AbstractLSPIdentifiersTlv other = (AbstractLSPIdentifiersTlv) obj; + if (this.extendedTunnelID == null) { + if (other.extendedTunnelID != null) + return false; + } else if (!this.extendedTunnelID.equals(other.extendedTunnelID)) + return false; + if (this.lspID == null) { + if (other.lspID != null) + return false; + } else if (!this.lspID.equals(other.lspID)) + return false; + if (this.senderAddress == null) { + if (other.senderAddress != null) + return false; + } else if (!this.senderAddress.equals(other.senderAddress)) + return false; + if (this.tunnelID == null) { + if (other.tunnelID != null) + return false; + } else if (!this.tunnelID.equals(other.tunnelID)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("AbstractLSPIdentifiersTlv [senderAddress="); + builder.append(this.senderAddress); + builder.append(", lspID="); + builder.append(this.lspID); + builder.append(", tunnelID="); + builder.append(this.tunnelID); + builder.append(", extendedTunnelID="); + builder.append(this.extendedTunnelID); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/ByPassTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/ByPassTlv.java new file mode 100644 index 0000000000..65475d0b69 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/ByPassTlv.java @@ -0,0 +1,131 @@ +/* + * 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.tlv; + +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.pcep.PCEPTlv; + +/** + * Structure of No Path Vector TLV. + * + * @see + */ +public class ByPassTlv implements PCEPTlv { + + private static final long serialVersionUID = 5879892226322401651L; + + private final boolean nodeProtection; + + private final boolean localProtectionInUse; + + private final IPv4Address bypassAddress; + + /** + * Constructs ByPass Tlv. + * + * @param nodeProtection + * boolean + * @param localProtectionInUse + * boolean + * @param bypassAddress + * IPv4Address + */ + public ByPassTlv(final boolean nodeProtection, final boolean localProtectionInUse, + final IPv4Address bypassAddress) { + this.nodeProtection = nodeProtection; + this.localProtectionInUse = localProtectionInUse; + this.bypassAddress = bypassAddress; + } + + /** + * The N Flag indicates whether the Bypass is used for node-protection. + * If the N flag is set to 1, the Bypass is used for node-protection. + * If the N flag is 0, the Bypass is used for link-protection. + * + * @return the nodeProtection + */ + public final boolean isNodeProtection() { + return this.nodeProtection; + } + + /** + * The I Flag indicates that local repair mechanism is in use. + * + * @return the localProtectionInUse + */ + public final boolean isLocalProtectionInUse() { + return this.localProtectionInUse; + } + + /** + * For link protection, the Bypass IPv4 Address is + * the nexthop address of the protected link in the paths of the + * protected LSPs. For node protection, the Bypass IPv4 Address is + * the node addresses of the protected node. + * + * @return the bypassAddress + */ + public final IPv4Address getBypassAddress() { + return this.bypassAddress; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("ByPassTlv [nodeProtection="); + builder.append(this.nodeProtection); + builder.append(", localProtectionInUse="); + builder.append(this.localProtectionInUse); + builder.append(", bypassAddress="); + builder.append(this.bypassAddress); + builder.append("]"); + return builder.toString(); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((this.bypassAddress == null) ? 0 : this.bypassAddress.hashCode()); + result = prime * result + (this.localProtectionInUse ? 1231 : 1237); + result = prime * result + (this.nodeProtection ? 1231 : 1237); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof ByPassTlv)) + return false; + final ByPassTlv other = (ByPassTlv) obj; + if (this.bypassAddress == null) { + if (other.bypassAddress != null) + return false; + } else if (!this.bypassAddress.equals(other.bypassAddress)) + return false; + if (this.localProtectionInUse != other.localProtectionInUse) + return false; + if (this.nodeProtection != other.nodeProtection) + return false; + return true; + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/IPv4LSPIdentifiersTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/IPv4LSPIdentifiersTlv.java new file mode 100644 index 0000000000..8867473583 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/IPv4LSPIdentifiersTlv.java @@ -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.protocol.pcep.tlv; + +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.pcep.concepts.ExtendedTunnelIdentifier; +import org.opendaylight.protocol.pcep.concepts.LSPIdentifier; +import org.opendaylight.protocol.pcep.concepts.TunnelIdentifier; + +/** + * Specific structure for IPv4 LSP Identifier TLV. + * + * @see LSP + * Identifiers TLVs + */ +public final class IPv4LSPIdentifiersTlv extends AbstractLSPIdentifiersTlv { + private static final long serialVersionUID = -8249620306610957898L; + + /** + * Constructs new IPv4 LSP Identifiers TLV. + * + * @param senderAddress + * {@link IPv4Address} + * @param lspID + * {@link LSPIdentifier} + * @param tunnelID + * {@link TunnelIdentifier} + * @param extendedTunnelID + * {@link ExtendedTunnelIdentifier} + */ + public IPv4LSPIdentifiersTlv(IPv4Address senderAddress, LSPIdentifier lspID, TunnelIdentifier tunnelID, + ExtendedTunnelIdentifier extendedTunnelID) { + super(senderAddress, lspID, tunnelID, extendedTunnelID); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/IPv6LSPIdentifiersTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/IPv6LSPIdentifiersTlv.java new file mode 100644 index 0000000000..6fa94b6276 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/IPv6LSPIdentifiersTlv.java @@ -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.protocol.pcep.tlv; + +import org.opendaylight.protocol.concepts.IPv6Address; +import org.opendaylight.protocol.pcep.concepts.ExtendedTunnelIdentifier; +import org.opendaylight.protocol.pcep.concepts.LSPIdentifier; +import org.opendaylight.protocol.pcep.concepts.TunnelIdentifier; + +/** + * Specific structure of IPv6 LSP Identifier TLV. + * + * @see LSP + * Identifiers TLVs + */ +public final class IPv6LSPIdentifiersTlv extends AbstractLSPIdentifiersTlv { + private static final long serialVersionUID = 4188840025844510894L; + + /** + * Constructs new IPv6 LSP Identifiers TLV. + * + * @param senderAddress + * {@link IPv6Address} + * @param lspID + * {@link LSPIdentifier} + * @param tunnelID + * {@link TunnelIdentifier} + * @param extendedTunnelID + * {@link ExtendedTunnelIdentifier} + */ + public IPv6LSPIdentifiersTlv(IPv6Address senderAddress, LSPIdentifier lspID, TunnelIdentifier tunnelID, + ExtendedTunnelIdentifier extendedTunnelID) { + super(senderAddress, lspID, tunnelID, extendedTunnelID); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPCleanupTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPCleanupTlv.java new file mode 100644 index 0000000000..c529949845 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPCleanupTlv.java @@ -0,0 +1,79 @@ +/* + * 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.tlv; + +import org.opendaylight.protocol.pcep.PCEPTlv; + +/** + * Structure of LSP Cleanup Tlv + * + * @see LSP-CLEANUP TLV + */ +public class LSPCleanupTlv implements PCEPTlv { + + private static final long serialVersionUID = -2540695596612553355L; + + private final int timeout; + + /** + * Creates new LSP Cleanup Tlv. + * + */ + public LSPCleanupTlv(int timeout) { + if (timeout < 0 || timeout > Integer.MAX_VALUE) + throw new IllegalArgumentException("Timeout (" + timeout + ") cannot be negative or bigger than 2^31 -1."); + this.timeout = timeout; + } + + /** + * @return the timeout + */ + public final int getTimeout() { + return this.timeout; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + this.timeout; + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof LSPCleanupTlv)) + return false; + final LSPCleanupTlv other = (LSPCleanupTlv) obj; + if (this.timeout != other.timeout) + return false; + return true; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("LSPCleanupTlv [timeout="); + builder.append(this.timeout); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPIdentifiersTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPIdentifiersTlv.java new file mode 100644 index 0000000000..5247000ed9 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPIdentifiersTlv.java @@ -0,0 +1,55 @@ +/* + * 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.tlv; + +import org.opendaylight.protocol.concepts.NetworkAddress; +import org.opendaylight.protocol.pcep.PCEPTlv; +import org.opendaylight.protocol.pcep.concepts.ExtendedTunnelIdentifier; +import org.opendaylight.protocol.pcep.concepts.LSPIdentifier; +import org.opendaylight.protocol.pcep.concepts.TunnelIdentifier; + +/** + * Interface defining basic LSPIdentifiersTLV. + * + * @see LSP + * Identifiers TLVs + * @param + */ +public interface LSPIdentifiersTlv> extends PCEPTlv { + + /** + * Gets specific senders {@link NetworkAddress}. + * + * @return T sender network address + */ + public T getSenderAddress(); + + /** + * Gets {@link LSPIdentifier}. + * + * @return LSPIdentifier + */ + public LSPIdentifier getLspID(); + + /** + * Gets {@link TunnelIdentifier}. + * + * @return TunnelIdentifier + */ + public TunnelIdentifier getTunnelID(); + + /** + * Gets specific {@link ExtendedTunnelIdentifier}. + * + * + * @return ExtendedTunnelIdentifier + */ + public ExtendedTunnelIdentifier getExtendedTunnelID(); +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPStateDBVersionTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPStateDBVersionTlv.java new file mode 100644 index 0000000000..c8a074250f --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPStateDBVersionTlv.java @@ -0,0 +1,73 @@ +/* + * 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.tlv; + +import org.opendaylight.protocol.pcep.PCEPTlv; + +/** + * Structure of LSP State DB Version TLV. + * + * @see LSP + * State Database Version TLV + */ +public class LSPStateDBVersionTlv implements PCEPTlv { + private static final long serialVersionUID = 3165807743418210453L; + private final long dbVersion; + + /** + * Construct new LSP State DB Version TLV. + * + * @param dbVersion + * long + */ + public LSPStateDBVersionTlv(long dbVersion) { + this.dbVersion = dbVersion; + } + + /** + * Gets long representation of DB Version. + * + * @return long + */ + public long getDbVersion() { + return this.dbVersion; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (this.dbVersion ^ (this.dbVersion >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final LSPStateDBVersionTlv other = (LSPStateDBVersionTlv) obj; + if (this.dbVersion != other.dbVersion) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("LSPStateDBVersionTlv [dbVersion="); + builder.append(this.dbVersion); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPSymbolicNameTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPSymbolicNameTlv.java new file mode 100644 index 0000000000..87fb4904f3 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPSymbolicNameTlv.java @@ -0,0 +1,78 @@ +/* + * 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.tlv; + +import org.opendaylight.protocol.pcep.PCEPTlv; +import org.opendaylight.protocol.pcep.concepts.LSPSymbolicName; + +/** + * Structure of LSP Symbolic Name Tlv. + * + * @see The + * LSP Symbolic Name TLV + */ +public class LSPSymbolicNameTlv implements PCEPTlv { + private static final long serialVersionUID = 2525226814028262452L; + private final LSPSymbolicName symbolicName; + + /** + * Constructs new LSP Symbolic Name TLV. + * + * @param symbolicName + * LSPSymbolicName + */ + public LSPSymbolicNameTlv(LSPSymbolicName symbolicName) { + this.symbolicName = symbolicName; + } + + /** + * Gets {@link LSPSymbolicName}. + * + * @return LSPSymbolicName + */ + public LSPSymbolicName getSymbolicName() { + return this.symbolicName; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.symbolicName == null) ? 0 : this.symbolicName.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final LSPSymbolicNameTlv other = (LSPSymbolicNameTlv) obj; + if (this.symbolicName == null) { + if (other.symbolicName != null) + return false; + } else if (!this.symbolicName.equals(other.symbolicName)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("LSPSymbolicNameTlv [symbolicName="); + builder.append(this.symbolicName); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPUpdateErrorTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPUpdateErrorTlv.java new file mode 100644 index 0000000000..64a4ed7910 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/LSPUpdateErrorTlv.java @@ -0,0 +1,78 @@ +/* + * 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.tlv; + +import java.util.Arrays; + +import org.opendaylight.protocol.pcep.PCEPTlv; + +/** + * Structure of LSP Update Error TLV. + * + * @see LSP + * Update Error Code TLV + */ +public class LSPUpdateErrorTlv implements PCEPTlv { + private static final long serialVersionUID = -6919035417806059716L; + private final byte[] errorCode; + + /** + * Constructs new LSP Update Error Tlv. + * + * @param errorCode + * byte[]. Size has to be 4 bytes. + */ + public LSPUpdateErrorTlv(byte[] errorCode) { + if (errorCode.length != 4) + throw new IllegalArgumentException("Update error code has wrong size."); + this.errorCode = errorCode; + } + + /** + * TBD + * + * @return error code as byte[] + */ + public byte[] getErrorCode() { + return this.errorCode; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Arrays.hashCode(this.errorCode); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final LSPUpdateErrorTlv other = (LSPUpdateErrorTlv) obj; + if (!Arrays.equals(this.errorCode, other.errorCode)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("LSPUpdateErrorTlv [errorCode="); + builder.append(Arrays.toString(this.errorCode)); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/NoPathVectorTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/NoPathVectorTlv.java new file mode 100644 index 0000000000..b9276e141f --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/NoPathVectorTlv.java @@ -0,0 +1,172 @@ +/* + * 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.tlv; + +import org.opendaylight.protocol.pcep.PCEPTlv; + +/** + * Structure of No Path Vector TLV. Extended to conform RFC5557. + * + * @see NO-PATH Object + * [RFC5440] - defined in text + * @see NO-PATH + * Indicator [RFC5557] + */ +public class NoPathVectorTlv implements PCEPTlv { + + private static final long serialVersionUID = -4993945476359800826L; + + private final boolean pceUnavailable; + + private final boolean unknownDest; + + private final boolean unknownSrc; + + private final boolean noGCOSolution; + + private final boolean noGCOMigrationPath; + + private final boolean reachablityProblem; + + /** + * Constructs new No Path Vector Tlv. + * + * @param pceUnavailable + * boolean + * @param unknownDest + * boolean + * @param unknownSrc + * boolean + * @param noGCOSolution + * boolean + * @param noGCOMigrationPath + * boolean + */ + public NoPathVectorTlv(boolean pceUnavailable, boolean unknownDest, boolean unknownSrc, boolean noGCOSolution, boolean noGCOMigrationPath, + boolean reachabilityProblem) { + super(); + this.pceUnavailable = pceUnavailable; + this.unknownDest = unknownDest; + this.unknownSrc = unknownSrc; + this.noGCOSolution = noGCOSolution; + this.noGCOMigrationPath = noGCOMigrationPath; + this.reachablityProblem = reachabilityProblem; + } + + /** + * Returns true if PCE currently unavailable + * + * @return boolean + */ + public boolean isPceUnavailable() { + return this.pceUnavailable; + } + + /** + * Returns true if unknown destination + * + * @return boolean + */ + public boolean isUnknownDest() { + return this.unknownDest; + } + + /** + * Returns true if unknown source + * + * @return boolean + */ + public boolean isUnknownSrc() { + return this.unknownSrc; + } + + /** + * If returns true the PCE indicates that no migration path was found. + * + * @return boolean + */ + public boolean isNoGCOSolution() { + return this.noGCOSolution; + } + + /** + * If returns true the PCE indicates no feasible solution was found that + * meets all the constraints associated with global concurrent path + * optimization in the PCRep message + * + * @return boolean + */ + public boolean isNoGCOMigrationPath() { + return this.noGCOMigrationPath; + } + + /** + * @return the reachablityProblem + */ + public boolean isReachablityProblem() { + return this.reachablityProblem; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (this.noGCOMigrationPath ? 1231 : 1237); + result = prime * result + (this.noGCOSolution ? 1231 : 1237); + result = prime * result + (this.pceUnavailable ? 1231 : 1237); + result = prime * result + (this.reachablityProblem ? 1231 : 1237); + result = prime * result + (this.unknownDest ? 1231 : 1237); + result = prime * result + (this.unknownSrc ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final NoPathVectorTlv other = (NoPathVectorTlv) obj; + if (this.noGCOMigrationPath != other.noGCOMigrationPath) + return false; + if (this.noGCOSolution != other.noGCOSolution) + return false; + if (this.pceUnavailable != other.pceUnavailable) + return false; + if (this.reachablityProblem != other.reachablityProblem) + return false; + if (this.unknownDest != other.unknownDest) + return false; + if (this.unknownSrc != other.unknownSrc) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("NoPathVectorTlv [pceUnavailable="); + builder.append(this.pceUnavailable); + builder.append(", unknownDest="); + builder.append(this.unknownDest); + builder.append(", unknownSrc="); + builder.append(this.unknownSrc); + builder.append(", noGCOSolution="); + builder.append(this.noGCOSolution); + builder.append(", noGCOMigrationPath="); + builder.append(this.noGCOMigrationPath); + builder.append(", reachablityProblem="); + builder.append(this.reachablityProblem); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/NodeIdentifierTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/NodeIdentifierTlv.java new file mode 100644 index 0000000000..0f7849e040 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/NodeIdentifierTlv.java @@ -0,0 +1,84 @@ +/* + * 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.tlv; + +import java.nio.ByteBuffer; +import java.nio.charset.CharacterCodingException; +import java.nio.charset.Charset; +import java.util.Arrays; + +import org.opendaylight.protocol.pcep.PCEPTlv; + +/** + * Structure of Node Identifier TLV. + * + * @see draft-ietf-pce-stateful-pce-01 (sec. 7.1.3) - NODE_IDENTIFIER_TLV + */ +public class NodeIdentifierTlv implements PCEPTlv { + private static final long serialVersionUID = -7959631526276210055L; + private final byte[] value; + + /** + * Constructs new Node Identifier TLV. + * + * @param value + * byte[] + */ + public NodeIdentifierTlv(byte[] value) { + if (value == null) + throw new IllegalArgumentException("Value is mandatory."); + if (value.length == 0) + throw new IllegalArgumentException("Value has to be long at least 1 byte."); + + this.value = value; + } + + /** + * Gets value of Node Identifier TLV as Bytes Array. + * + * @return byte[] + */ + public byte[] getValue() { + return this.value; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Arrays.hashCode(this.value); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final NodeIdentifierTlv other = (NodeIdentifierTlv) obj; + if (!Arrays.equals(this.value, other.value)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("NodeIdentifierTlv [value="); + try { + builder.append(Charset.forName("UTF-8").newDecoder().decode(ByteBuffer.wrap(this.value)).toString()); + } catch (final CharacterCodingException e) { + builder.append(Arrays.toString(this.value)); + } + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/OFListTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/OFListTlv.java new file mode 100644 index 0000000000..bedbe3cb37 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/OFListTlv.java @@ -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.protocol.pcep.tlv; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPOFCodes; +import org.opendaylight.protocol.pcep.PCEPTlv; + +/** + * It MAY be carried within an OPEN object sent by a PCE in an Open message to a + * PCEP peer so as to indicate the list of supported objective functions. + * + * @see OF-List TLV + */ +public class OFListTlv implements PCEPTlv { + private static final long serialVersionUID = 3409582385994162451L; + + private final List ofCodes; + + /** + * Constructs new objective functions list tlv + * + * @param ofCodes + * lit of objective functions + */ + public OFListTlv(List ofCodes) { + super(); + this.ofCodes = ofCodes; + } + + /** + * Gets list of objective functions + * + * @return list of objective functions + */ + public List getOfCodes() { + return this.ofCodes; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.ofCodes == null) ? 0 : this.ofCodes.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final OFListTlv other = (OFListTlv) obj; + if (this.ofCodes == null) { + if (other.ofCodes != null) + return false; + } else if (!this.ofCodes.equals(other.ofCodes)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("OFListTlv [ofCodes="); + builder.append(this.ofCodes); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/OrderTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/OrderTlv.java new file mode 100644 index 0000000000..8d04b2dae4 --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/OrderTlv.java @@ -0,0 +1,96 @@ +/* + * 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.tlv; + +import org.opendaylight.protocol.pcep.PCEPTlv; + +/** + * The Order TLV is an optional TLV in the RP object, that indicates the order + * in which the old TE LSP must be removed and the new TE LSP must be setup + * during a reoptimization. It is carried in the PCRep message in response to a + * reoptimization request. + * + * @see The Order + * Response [RFC5557] + */ +public class OrderTlv implements PCEPTlv { + + private static final long serialVersionUID = 4275350142878198146L; + + private final long deleteOrder; + private final long setupOrder; + + /** + * Constructs new Order tlv with all mandatory objects. + * + * @param deleteOrder + * 32-bit integer + * @param setupOrder + * 32-bit integer + */ + public OrderTlv(long deleteOrder, long setupOrder) { + super(); + this.deleteOrder = deleteOrder; + this.setupOrder = setupOrder; + } + + /** + * Gets the delete order + * + * @return the delete order + */ + public long getDeleteOrder() { + return this.deleteOrder; + } + + /** + * Gets the setup order + * + * @return the setup order + */ + public long getSetupOrder() { + return this.setupOrder; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("OrderTlv [deleteOrder="); + builder.append(this.deleteOrder); + builder.append(", setupOrder="); + builder.append(this.setupOrder); + builder.append("]"); + return builder.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (this.deleteOrder ^ (this.deleteOrder >>> 32)); + result = prime * result + (int) (this.setupOrder ^ (this.setupOrder >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final OrderTlv other = (OrderTlv) obj; + if (this.deleteOrder != other.deleteOrder) + return false; + if (this.setupOrder != other.setupOrder) + return false; + return true; + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/OverloadedDurationTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/OverloadedDurationTlv.java new file mode 100644 index 0000000000..e1af086e3c --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/OverloadedDurationTlv.java @@ -0,0 +1,73 @@ +/* + * 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.tlv; + +import org.opendaylight.protocol.pcep.PCEPTlv; + +/** + * Structure of Overloaded Duratioon Tlv. + * + * @see NOTIFICATION + * Object - defined in text + */ +public class OverloadedDurationTlv implements PCEPTlv { + private static final long serialVersionUID = -5829314427598008054L; + private final int value; + + /** + * Construct new Overloaded Duration Tlv. + * + * @param value + * int + */ + public OverloadedDurationTlv(int value) { + this.value = value; + } + + /** + * Gets Integer representation of Overloade Duration Value. + * + * @return int + */ + public int getValue() { + return this.value; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + this.value; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final OverloadedDurationTlv other = (OverloadedDurationTlv) obj; + if (this.value != other.value) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("OverloadedDurationTlv [value="); + builder.append(this.value); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/P2MPCapabilityTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/P2MPCapabilityTlv.java new file mode 100644 index 0000000000..88af019d6e --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/P2MPCapabilityTlv.java @@ -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.protocol.pcep.tlv; + +import org.opendaylight.protocol.pcep.PCEPTlv; + +/** + * Structure of P2MP Capability Tlv. + * + * @see 3.1.2. Open + * Message Extension [RFC6006] + */ +public class P2MPCapabilityTlv implements PCEPTlv { + private static final long serialVersionUID = -7959631526276210055L; + + private final int value; + + /** + * Constructs new P2MP Capability Tlv. + */ + public P2MPCapabilityTlv(int value) { + if (value < 0 || value > 65535) + throw new IllegalArgumentException("Value (" + value + ") cannot be negative or bigger than 2^16 -1."); + + this.value = value; + } + + /** + * Constructs new P2MP Capability Tlv, with value defaultly set to zero as + * mentioned in RFC6006. + */ + public P2MPCapabilityTlv() { + this.value = 0; + } + + /** + * Gets integer value of P2MP Capability Tlv. + * + * @return int + */ + public int getValue() { + return this.value; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + this.value; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final P2MPCapabilityTlv other = (P2MPCapabilityTlv) obj; + if (this.value != other.value) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("P2MPCapablityTlv [value="); + builder.append(this.value); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/PCEStatefulCapabilityTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/PCEStatefulCapabilityTlv.java new file mode 100644 index 0000000000..b5ef16af1e --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/PCEStatefulCapabilityTlv.java @@ -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.tlv; + +import org.opendaylight.protocol.pcep.PCEPTlv; + +/** + * Structure of PCE Stateful Capability Tlv. + * + * @see STATEFUL-PCE-CAPABILITY + * TLV + * @see Stateful PCE Capability + * TLV + * + */ +public class PCEStatefulCapabilityTlv implements PCEPTlv { + + private static final long serialVersionUID = 5567589958323130325L; + + private final boolean update; + + private final boolean versioned; + + private final boolean instantiated; + + /** + * Constructs PCE Stateful Capability Tlv + * + * @param update + * boolean + * @param versioned + * boolean + */ + public PCEStatefulCapabilityTlv(boolean instantiated, boolean update, boolean versioned) { + this.instantiated = instantiated; + this.update = update; + this.versioned = versioned; + } + + /** + * Setting of Instantiated flag. + * + * @return boolean + */ + public boolean isInstantiated() { + return this.instantiated; + } + + /** + * Setting of Update flag. + * + * @return boolean + */ + public boolean isUpdate() { + return this.update; + } + + /** + * Setting of Versioned flag. + * + * @return boolean + */ + public boolean isVersioned() { + return this.versioned; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (this.instantiated ? 1231 : 1237); + result = prime * result + (this.update ? 1231 : 1237); + result = prime * result + (this.versioned ? 1231 : 1237); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof PCEStatefulCapabilityTlv)) + return false; + final PCEStatefulCapabilityTlv other = (PCEStatefulCapabilityTlv) obj; + if (this.instantiated != other.instantiated) + return false; + if (this.update != other.update) + return false; + if (this.versioned != other.versioned) + return false; + return true; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("PCEStatefulCapabilityTlv [update="); + builder.append(this.update); + builder.append(", versioned="); + builder.append(this.versioned); + builder.append(", instantiated="); + builder.append(this.instantiated); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/RSVPErrorSpecTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/RSVPErrorSpecTlv.java new file mode 100644 index 0000000000..9da45a510b --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/RSVPErrorSpecTlv.java @@ -0,0 +1,155 @@ +/* + * 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.tlv; + +import org.opendaylight.protocol.concepts.NetworkAddress; +import org.opendaylight.protocol.pcep.PCEPTlv; + +/** + * Structure of RSVP Error Spec Tlv. + * + * @see Apendix A.5: ERROR_SPEC + * Class + * @param + */ +public class RSVPErrorSpecTlv> implements PCEPTlv { + private static final long serialVersionUID = 3948879942549682846L; + + private final T errorNodeAddress; + + private final boolean inPlace; + + private final boolean guilty; + + private final int errorCode; + + private final int errorValue; + + /** + * + * Constructs new RSVP Error Spec Tlv. + * + * @param errorNodeAddress + * T + * @param inPlace + * boolean + * @param guilty + * boolean + * @param errorCode + * int + * @param errorValue + * int + */ + public RSVPErrorSpecTlv(T errorNodeAddress, boolean inPlace, boolean guilty, int errorCode, int errorValue) { + this.errorNodeAddress = errorNodeAddress; + this.inPlace = inPlace; + this.guilty = guilty; + this.errorCode = errorCode; + this.errorValue = errorValue; + } + + /** + * Gets {@link NetworkAddress} of Error Node. + * + * @return T + */ + public T getErrorNodeAddress() { + return this.errorNodeAddress; + } + + /** + * Setting of InPlace flag. + * + * @return boolean + */ + public boolean isInPlace() { + return this.inPlace; + } + + /** + * Setting of Guilty flag. + * + * @return boolean + */ + public boolean isGuilty() { + return this.guilty; + } + + /** + * Gets int representation of Error Code. + * + * @return int + */ + public int getErrorCode() { + return this.errorCode; + } + + /** + * Gets int representation of Error Value. + * + * @return int + */ + public int getErrorValue() { + return this.errorValue; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + this.errorCode; + result = prime * result + ((this.errorNodeAddress == null) ? 0 : this.errorNodeAddress.hashCode()); + result = prime * result + this.errorValue; + result = prime * result + (this.guilty ? 1231 : 1237); + result = prime * result + (this.inPlace ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final RSVPErrorSpecTlv other = (RSVPErrorSpecTlv) obj; + if (this.errorCode != other.errorCode) + return false; + if (this.errorNodeAddress == null) { + if (other.errorNodeAddress != null) + return false; + } else if (!this.errorNodeAddress.equals(other.errorNodeAddress)) + return false; + if (this.errorValue != other.errorValue) + return false; + if (this.guilty != other.guilty) + return false; + if (this.inPlace != other.inPlace) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("RSVPErrorSpecTlv [errorNodeAddress="); + builder.append(this.errorNodeAddress); + builder.append(", inPlace="); + builder.append(this.inPlace); + builder.append(", guilty="); + builder.append(this.guilty); + builder.append(", errorCode="); + builder.append(this.errorCode); + builder.append(", errorValue="); + builder.append(this.errorValue); + builder.append("]"); + return builder.toString(); + } +} diff --git a/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/ReqMissingTlv.java b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/ReqMissingTlv.java new file mode 100644 index 0000000000..b8357faa2c --- /dev/null +++ b/pcep/api/src/main/java/org/opendaylight/protocol/pcep/tlv/ReqMissingTlv.java @@ -0,0 +1,73 @@ +/* + * 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.tlv; + +import org.opendaylight.protocol.pcep.PCEPTlv; + +/** + * Structure of Request Missing Tlv. + * + * @see PCEP-ERROR + * Object - defined in text (Error-type=7) + */ +public class ReqMissingTlv implements PCEPTlv { + private static final long serialVersionUID = -3910927830017195746L; + private final long requestID; + + /** + * Constructs new Request Missing Tlv. + * + * @param requestID + * long + */ + public ReqMissingTlv(long requestID) { + this.requestID = requestID; + } + + /** + * gets long representation of Requested ID. + * + * @return long + */ + public long getRequestID() { + return this.requestID; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (this.requestID ^ (this.requestID >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final ReqMissingTlv other = (ReqMissingTlv) obj; + if (this.requestID != other.requestID) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("ReqMissingTlv [requestID="); + builder.append(this.requestID); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/pcep/api/src/main/yang/pcep-types.yang b/pcep/api/src/main/yang/pcep-types.yang index 56ac4c63aa..8c0bff6c60 100644 --- a/pcep/api/src/main/yang/pcep-types.yang +++ b/pcep/api/src/main/yang/pcep-types.yang @@ -80,7 +80,6 @@ module pcep-types { description "NO-PATH-VECTOR TLV"; reference "https://tools.ietf.org/html/rfc5440#section-7.5"; - uses tlv; leaf flags { type bits { bit p2mp-unreachable { @@ -117,7 +116,6 @@ module pcep-types { description "OVERLOAD-DURATION TLV"; reference "https://tools.ietf.org/html/rfc5440#section-7.14"; - uses tlv; leaf duration { type uint32; units seconds; @@ -128,13 +126,12 @@ module pcep-types { description "REQ-MISSING TLV"; reference "https://tools.ietf.org/html/rfc5440#section-7.5"; - uses tlv; leaf request-id { type request-id; } } - - grouping p2mp-capable-tlv { + + grouping p2mp-capable-tlv { description "P2MP CAPABLE TLV"; reference "https://tools.ietf.org/html/rfc6006#section-3.1.2"; @@ -143,13 +140,11 @@ module pcep-types { mandatory true; } } - grouping stateful-capability-tlv { description "Stateful PCE Capability TLV"; reference "https://tools.ietf.org/html/draft-ietf-pce-stateful-pce-05#section-7.1.1"; - uses tlv; leaf flags { type bits { bit lsp-update-capability { @@ -170,7 +165,6 @@ module pcep-types { description "LSP State Database Version TLV"; reference "https://tools.ietf.org/html/draft-ietf-pce-stateful-pce-05#section-7.1.2"; - uses tlv; leaf version { type uint64; mandatory true; @@ -181,7 +175,6 @@ module pcep-types { description "PCE Redundancy Group Identifier TLV"; reference "https://tools.ietf.org/html/draft-ietf-pce-stateful-pce-05#section-7.1.3"; - uses tlv; leaf identifier { type binary; mandatory true; @@ -192,7 +185,6 @@ module pcep-types { description "LSP Identifiers TLV"; reference "https://tools.ietf.org/html/draft-ietf-pce-stateful-pce-05#section-7.3.1"; - uses tlv; leaf lsp-id { type rsvp:lsp-id; mandatory true; @@ -231,7 +223,6 @@ module pcep-types { description "Symbolic Path Name TLV"; reference "https://tools.ietf.org/html/draft-ietf-pce-stateful-pce-05#section-7.3.2"; - uses tlv; leaf path-name { type binary; mandatory true; @@ -242,7 +233,6 @@ module pcep-types { description "LSP Error Code TLV"; reference "https://tools.ietf.org/html/draft-ietf-pce-stateful-pce-05#section-7.3.3"; - uses tlv; leaf error-code { type uint32; mandatory true; @@ -253,7 +243,6 @@ module pcep-types { description "RSVP Error Spec TLV"; reference "https://tools.ietf.org/html/draft-ietf-pce-stateful-pce-05#section-7.3.4"; - uses tlv; choice error-type { case rsvp { container rsvp-error { @@ -272,7 +261,6 @@ module pcep-types { description "OF-List TLV"; reference "https://tools.ietf.org/html/rfc5541#section-2.1"; - uses tlv; leaf-list codes { type of-id; } @@ -282,7 +270,6 @@ module pcep-types { description "Order TLV"; reference "https://tools.ietf.org/html/rfc5557#section-5.4"; - uses tlv; leaf delete { type uint32; mandatory true; @@ -506,10 +493,10 @@ module pcep-types { grouping bandwidth-object { description "BANDWIDTH Object"; reference "https://tools.ietf.org/html/rfc5440#section-7.7"; - - uses object; // No possibility to carry TLVs + uses object-header; + leaf bandwidth { type ieee754:float32; } @@ -541,32 +528,12 @@ module pcep-types { } } - grouping exclude-route-object { - description "Exclude Route Object"; - reference "https://tools.ietf.org/html/rfc5521#section-2.1.1"; - - uses object; - - leaf flags { - type bits { - bit fail { - position 31; - } - } - mandatory true; - } - - list subobjects { - uses rsvp:exclude-route-subobjects; - } - } - grouping explicit-route-object { description "Explicit Route Object"; reference "https://tools.ietf.org/html/rfc5440#section-7.9"; // No possibility of TLVs - uses object; + uses object-header; list subobjects { leaf loose { @@ -583,16 +550,10 @@ module pcep-types { reference "https://tools.ietf.org/html/rfc5440#section-7.12"; // No possibility of TLVs - uses object; + uses object-header; list subobjects { - uses rsvp:route-subobjects { - augment subobject-type { - case explicit-exclusion-route { - uses rsvp:exclude-route-subobjects; - } - } - } + uses rsvp:route-subobjects; } } @@ -601,7 +562,7 @@ module pcep-types { reference "https://tools.ietf.org/html/rfc5440#section-7.10"; // No possibility of TLVs - uses object; + uses object-header; list subobjects { uses rsvp:record-route-subobjects; @@ -637,7 +598,7 @@ module pcep-types { reference "https://tools.ietf.org/html/rfc5440#section-7.13"; // No possibility of TLVs - uses object; + uses object-header; leaf link-diverse { type boolean; @@ -713,7 +674,7 @@ module pcep-types { reference "https://tools.ietf.org/html/rfc5440#section-7.16"; // No possibility of TLVs - uses object; + uses object-header; leaf max-lsp { type uint8; @@ -729,22 +690,20 @@ module pcep-types { description "CLOSE Object"; reference "https://tools.ietf.org/html/rfc5440#section-7.17"; + // No possibility of TLVs uses object; leaf reason { type uint8; mandatory true; } - - container tlvs { - } } grouping path-key-object { description "PATH-KEY Object"; reference "https://tools.ietf.org/html/rfc5520#section-3.2.2"; - uses object; + uses object-header; list path-keys { min-elements 1; @@ -878,7 +837,7 @@ module pcep-types { description "CLASSTYPE Object"; reference "https://tools.ietf.org/html/rfc5455#section-3"; - uses object; + uses object-header; leaf class-type { type class-type; @@ -1039,6 +998,18 @@ module pcep-types { uses lsp-object; } } + + container p2mp { + when "../rp/p2mp = true"; + + list trees { + container endpoints { + uses endpoints-object; + } + + // FIXME: finish this + } + } } } @@ -1170,13 +1141,13 @@ module pcep-types { grouping close-message { uses message; - container c-close-message { + container close-message { description "Close Message"; reference "https://tools.ietf.org/html/rfc5440#section-6.8"; uses message-header; - container c-close { + container close { uses close-object; } } diff --git a/pcep/api/src/main/yang/rsvp.yang b/pcep/api/src/main/yang/rsvp.yang index 91edabca0f..5a4846fddb 100644 --- a/pcep/api/src/main/yang/rsvp.yang +++ b/pcep/api/src/main/yang/rsvp.yang @@ -67,10 +67,6 @@ module rsvp { reference "https://tools.ietf.org/html/rfc3209#section-4.6.1.2"; } - typedef srlg-id { - type uint32; - } - grouping error-spec { reference "https://tools.ietf.org/html/rfc2205#page-81"; @@ -128,14 +124,8 @@ module rsvp { // Filled by enterprise-specific augmentations } } - - //marker - grouping c-subobject { - - } grouping ip-prefix-subobject { - uses c-subobject; leaf ip-prefix { reference "http://tools.ietf.org/html/rfc3209#section-4.3.3.1"; type inet:ip-prefix; @@ -144,7 +134,6 @@ module rsvp { } grouping as-number-subobject { - uses c-subobject; leaf as-number { reference "http://tools.ietf.org/html/rfc3209#section-4.3.3.4"; type inet:as-number; @@ -153,7 +142,6 @@ module rsvp { } grouping label-subobject { - uses c-subobject; leaf c-type { type uint8; mandatory true; @@ -170,7 +158,6 @@ module rsvp { } grouping unnumbered-subobject { - uses c-subobject; leaf router-id { type uint32; mandatory true; @@ -182,14 +169,6 @@ module rsvp { } } - grouping srlg-subobject { - uses c-subobject; - leaf srlg-id { - type srlg-id; - mandatory true; - } - } - grouping record-route-subobjects { leaf protection-available { type boolean; @@ -235,36 +214,5 @@ module rsvp { } } } - - grouping exclude-route-subobjects { - description "Subobject of an Exclude Route Object"; - reference "https://tools.ietf.org/html/rfc4874#section-3.1"; - - leaf mandatory { - type boolean; - default false; - } - - leaf attribute { - type uint8; - mandatory true; - } - - choice subobject-type { - case as-number { - uses as-number-subobject; - } - case ip-prefix { - uses ip-prefix-subobject; - } - case srlg { - uses srlg-subobject; - } - case unnumbered { - uses unnumbered-subobject; - } - } - } - } diff --git a/pcep/api/src/test/java/org/opendaylight/protocol/pcep/api/APITest.java b/pcep/api/src/test/java/org/opendaylight/protocol/pcep/api/APITest.java index 0e0c1267d6..46d35f1820 100644 --- a/pcep/api/src/test/java/org/opendaylight/protocol/pcep/api/APITest.java +++ b/pcep/api/src/test/java/org/opendaylight/protocol/pcep/api/APITest.java @@ -8,13 +8,22 @@ package org.opendaylight.protocol.pcep.api; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; import org.junit.Test; import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.PCEPDocumentedException; import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.subobject.EROAsNumberSubobject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber; +/** + * + */ public class APITest { @Test @@ -32,4 +41,36 @@ public class APITest { final PCEPDocumentedException de = new PCEPDocumentedException("", PCEPErrors.C_BIT_SET); assertEquals(PCEPErrors.C_BIT_SET, de.getError()); } + + @Test + public void testPCEPObject() { + final PCEPObject obj1 = new PCEPObject(true, false) { + }; + final PCEPObject obj2 = new PCEPErrorObject(PCEPErrors.CANNOT_PROCESS_STATE_REPORT); + final PCEPObject obj4 = new PCEPObject(true, false) { + }; + + assertNotSame(obj1, obj2); + assertNotSame(obj1, obj4); + assertEquals(obj1.hashCode(), obj4.hashCode()); + assertEquals(obj1.toString(), obj4.toString()); + + } + + @Test + public void testSubobject() { + final ExplicitRouteSubobject sub1 = new EROAsNumberSubobject(new AsNumber((long) 100), true); + final ExplicitRouteSubobject sub2 = new ExplicitRouteSubobject(false) { + }; + final ExplicitRouteSubobject sub3 = new ExplicitRouteSubobject(false) { + }; + final ExplicitRouteSubobject sub4 = new EROAsNumberSubobject(new AsNumber((long) 100), true); + + assertNotSame(sub1, sub2); + assertNotSame(sub2, sub3); + assertEquals(sub1, sub4); + assertNotSame(sub2, sub3); + assertEquals(sub1.hashCode(), sub4.hashCode()); + assertEquals(sub2.toString(), sub3.toString()); + } } diff --git a/pcep/api/src/test/java/org/opendaylight/protocol/pcep/api/ConceptsTest.java b/pcep/api/src/test/java/org/opendaylight/protocol/pcep/api/ConceptsTest.java new file mode 100644 index 0000000000..e599a9e3a2 --- /dev/null +++ b/pcep/api/src/test/java/org/opendaylight/protocol/pcep/api/ConceptsTest.java @@ -0,0 +1,155 @@ +/* + * 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.api; + +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 java.net.InetAddress; +import java.net.UnknownHostException; + +import org.junit.Test; + +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.concepts.IPv6Address; +import org.opendaylight.protocol.pcep.concepts.AbstractExtendedTunnelIdentifier; +import org.opendaylight.protocol.pcep.concepts.AggregateBandwidthConsumptionMetric; +import org.opendaylight.protocol.pcep.concepts.CumulativeIGPCostMetric; +import org.opendaylight.protocol.pcep.concepts.CumulativeTECostMetric; +import org.opendaylight.protocol.pcep.concepts.IPv4ExtendedTunnelIdentifier; +import org.opendaylight.protocol.pcep.concepts.IPv6ExtendedTunnelIdentifier; +import org.opendaylight.protocol.pcep.concepts.LSPIdentifier; +import org.opendaylight.protocol.pcep.concepts.LSPSymbolicName; +import org.opendaylight.protocol.pcep.concepts.MostLoadedLinkLoadMetric; +import org.opendaylight.protocol.pcep.concepts.TunnelIdentifier; +import org.opendaylight.protocol.pcep.concepts.UnnumberedInterfaceIdentifier; + +public class ConceptsTest { + + @Test + public void testConcepts() throws UnknownHostException { + final AbstractExtendedTunnelIdentifier t1 = new AbstractExtendedTunnelIdentifier(new IPv4Address( + InetAddress.getByName("127.0.0.1"))) { + private static final long serialVersionUID = 445350555352830607L; + }; + + final AbstractExtendedTunnelIdentifier t2 = new AbstractExtendedTunnelIdentifier(new IPv4Address( + InetAddress.getByName("127.0.0.2"))) { + private static final long serialVersionUID = 572633522583009640L; + }; + + final AbstractExtendedTunnelIdentifier t3 = new AbstractExtendedTunnelIdentifier(new IPv4Address( + InetAddress.getByName("127.0.0.1"))) { + private static final long serialVersionUID = 445350555352830607L; + }; + + assertNotSame(t1, t2); + assertEquals(-1, t1.compareTo(t2)); + assertEquals(t1.hashCode(), t3.hashCode()); + assertEquals(t1.toString(), t3.toString()); + + final IPv4ExtendedTunnelIdentifier v4 = new IPv4ExtendedTunnelIdentifier(new IPv4Address(InetAddress.getByName("127.0.0.1"))); + final IPv6ExtendedTunnelIdentifier v6 = new IPv6ExtendedTunnelIdentifier(new IPv6Address(InetAddress.getByName("2001:db8:85a3::8a2e:370:7333"))); + assertTrue(v4 instanceof AbstractExtendedTunnelIdentifier); + assertTrue(v6 instanceof AbstractExtendedTunnelIdentifier); + + final LSPIdentifier id1 = new LSPIdentifier(new byte[] { 1, 2 }); + final LSPIdentifier id2 = new LSPIdentifier(new byte[] { 1, 3 }); + final LSPIdentifier id3 = new LSPIdentifier(new byte[] { 1, 3 }); + + assertNotSame(id1, id2); + assertNotSame(id1.getLspId(), id2.getLspId()); + assertEquals(id3.toString(), id2.toString()); + + final LSPSymbolicName n1 = new LSPSymbolicName(new byte[] { 5 }); + final LSPSymbolicName n2 = new LSPSymbolicName(new byte[] { 6, 3 }); + final LSPSymbolicName n3 = new LSPSymbolicName(new byte[] { 5 }); + assertNotSame(n1.getSymbolicName(), n2.getSymbolicName()); + assertEquals(n1, n3); + assertEquals(n1.toString(), n3.toString()); + + final TunnelIdentifier ti1 = new TunnelIdentifier(new byte[] { 2, 4 }); + final TunnelIdentifier ti2 = new TunnelIdentifier(new byte[] { 2, 4 }); + assertArrayEquals(ti1.getBytes(), ti2.getBytes()); + assertEquals(ti1, ti2); + assertEquals(ti1.toString(), ti2.toString()); + + final UnnumberedInterfaceIdentifier u1 = new UnnumberedInterfaceIdentifier(3000); + final UnnumberedInterfaceIdentifier u2 = new UnnumberedInterfaceIdentifier(4000); + final UnnumberedInterfaceIdentifier u3 = new UnnumberedInterfaceIdentifier(3000); + + assertEquals(-1, u1.compareTo(u2)); + assertEquals(u1, u3); + assertEquals(u1.hashCode(), u3.hashCode()); + assertEquals(u1.getInterfaceId(), u3.getInterfaceId()); + assertEquals(u1.toString(), u3.toString()); + + final CumulativeIGPCostMetric cigp1 = new CumulativeIGPCostMetric(3000); + final CumulativeIGPCostMetric cigp2 = new CumulativeIGPCostMetric(4000); + final CumulativeIGPCostMetric cigp3 = new CumulativeIGPCostMetric(3000); + try { + new CumulativeIGPCostMetric(-1); + fail("Expected exception but no thrown."); + } catch (final IllegalArgumentException e) { + } + + assertEquals(-1, cigp1.compareTo(cigp2)); + assertEquals(cigp1, cigp3); + assertEquals(cigp1.hashCode(), cigp3.hashCode()); + assertEquals(cigp1.getValue(), cigp3.getValue()); + assertEquals(cigp1.toString(), cigp3.toString()); + + final CumulativeTECostMetric cte1 = new CumulativeTECostMetric(3000); + final CumulativeTECostMetric cte2 = new CumulativeTECostMetric(4000); + final CumulativeTECostMetric cte3 = new CumulativeTECostMetric(3000); + + assertEquals(-1, cte1.compareTo(cte2)); + assertEquals(cte1, cte3); + assertEquals(cte1.hashCode(), cte3.hashCode()); + assertEquals(cte1.getValue(), cte3.getValue()); + assertEquals(cte1.toString(), cte3.toString()); + try { + new CumulativeTECostMetric(-1); + fail("Expected exception but no thrown."); + } catch (final IllegalArgumentException e) { + } + + final AggregateBandwidthConsumptionMetric agg1 = new AggregateBandwidthConsumptionMetric(3000); + final AggregateBandwidthConsumptionMetric agg2 = new AggregateBandwidthConsumptionMetric(4000); + final AggregateBandwidthConsumptionMetric agg3 = new AggregateBandwidthConsumptionMetric(3000); + + assertEquals(-1, agg1.compareTo(agg2)); + assertEquals(agg1, agg3); + assertEquals(agg1.hashCode(), agg3.hashCode()); + assertEquals(agg1.getValue(), agg3.getValue()); + assertEquals(agg1.toString(), agg3.toString()); + try { + new AggregateBandwidthConsumptionMetric(-1); + fail("Expected exception but no thrown."); + } catch (final IllegalArgumentException e) { + } + + final MostLoadedLinkLoadMetric mlm1 = new MostLoadedLinkLoadMetric(3000); + final MostLoadedLinkLoadMetric mlm2 = new MostLoadedLinkLoadMetric(4000); + final MostLoadedLinkLoadMetric mlm3 = new MostLoadedLinkLoadMetric(3000); + + assertEquals(-1, mlm1.compareTo(mlm2)); + assertEquals(mlm1, mlm3); + assertEquals(mlm1.hashCode(), mlm3.hashCode()); + assertEquals(mlm1.getValue(), mlm3.getValue()); + assertEquals(mlm1.toString(), mlm3.toString()); + try { + new MostLoadedLinkLoadMetric(-1); + fail("Expected exception but no thrown."); + } catch (final IllegalArgumentException e) { + } + } +} diff --git a/pcep/api/src/test/java/org/opendaylight/protocol/pcep/api/ObjectsTest.java b/pcep/api/src/test/java/org/opendaylight/protocol/pcep/api/ObjectsTest.java new file mode 100644 index 0000000000..19e867fcd4 --- /dev/null +++ b/pcep/api/src/test/java/org/opendaylight/protocol/pcep/api/ObjectsTest.java @@ -0,0 +1,713 @@ +/* + * 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.api; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.matchers.JUnitMatchers.containsString; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.opendaylight.protocol.concepts.IPv4; +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.concepts.IPv4Prefix; +import org.opendaylight.protocol.concepts.SharedRiskLinkGroup; +import org.opendaylight.protocol.concepts.TEMetric; +import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPOFCodes; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.PCEPTlv; +import org.opendaylight.protocol.pcep.concepts.UnnumberedInterfaceIdentifier; +import org.opendaylight.protocol.pcep.message.PCEPOpenMessage; +import org.opendaylight.protocol.pcep.object.CompositeErrorObject; +import org.opendaylight.protocol.pcep.object.CompositeNotifyObject; +import org.opendaylight.protocol.pcep.object.CompositePathObject; +import org.opendaylight.protocol.pcep.object.CompositeReplySvecObject; +import org.opendaylight.protocol.pcep.object.CompositeRequestObject; +import org.opendaylight.protocol.pcep.object.CompositeRequestSvecObject; +import org.opendaylight.protocol.pcep.object.CompositeResponseObject; +import org.opendaylight.protocol.pcep.object.CompositeRptPathObject; +import org.opendaylight.protocol.pcep.object.CompositeStateReportObject; +import org.opendaylight.protocol.pcep.object.CompositeUpdPathObject; +import org.opendaylight.protocol.pcep.object.CompositeUpdateRequestObject; +import org.opendaylight.protocol.pcep.object.PCEPClassTypeObject; +import org.opendaylight.protocol.pcep.object.PCEPEndPoints; +import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPExcludeRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPExistingPathBandwidthObject; +import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPGlobalConstraintsObject; +import org.opendaylight.protocol.pcep.object.PCEPIncludeRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPLoadBalancingObject; +import org.opendaylight.protocol.pcep.object.PCEPLspObject; +import org.opendaylight.protocol.pcep.object.PCEPLspaObject; +import org.opendaylight.protocol.pcep.object.PCEPMetricObject; +import org.opendaylight.protocol.pcep.object.PCEPNoPathObject; +import org.opendaylight.protocol.pcep.object.PCEPNotificationObject; +import org.opendaylight.protocol.pcep.object.PCEPObjectiveFunctionObject; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; +import org.opendaylight.protocol.pcep.object.PCEPP2MPEndPointsObject; +import org.opendaylight.protocol.pcep.object.PCEPReportedRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject; +import org.opendaylight.protocol.pcep.object.PCEPSvecObject; +import org.opendaylight.protocol.pcep.subobject.EROAsNumberSubobject; +import org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject; +import org.opendaylight.protocol.pcep.subobject.EROUnnumberedInterfaceSubobject; +import org.opendaylight.protocol.pcep.subobject.ExcludeRouteSubobject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; +import org.opendaylight.protocol.pcep.subobject.RROAsNumberSubobject; +import org.opendaylight.protocol.pcep.subobject.RROIPAddressSubobject; +import org.opendaylight.protocol.pcep.subobject.RROUnnumberedInterfaceSubobject; +import org.opendaylight.protocol.pcep.subobject.ReportedRouteSubobject; +import org.opendaylight.protocol.pcep.subobject.XROAsNumberSubobject; +import org.opendaylight.protocol.pcep.subobject.XROIPPrefixSubobject; +import org.opendaylight.protocol.pcep.subobject.XROSRLGSubobject; +import org.opendaylight.protocol.pcep.subobject.XROSubobjectAttribute; +import org.opendaylight.protocol.pcep.subobject.XROUnnumberedInterfaceSubobject; +import org.opendaylight.protocol.pcep.tlv.OrderTlv; +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.nps.concepts.rev130930.Bandwidth; + +import com.google.common.collect.Lists; + +/** + * + */ +public class ObjectsTest { + + private final AsNumber as = new AsNumber((long) 2555); + + @Test + public void compositeErrorObjectTest() { + + final List errorObjects = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPErrorObject(PCEPErrors.ATTEMPT_2ND_SESSION)); + } + }; + + final List errorParams = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPRequestParameterObject(true, true, true, true, true, false, false, false, (short) 1, 1, true, true)); + } + }; + final CompositeErrorObject m = new CompositeErrorObject(errorParams, errorObjects); + final CompositeErrorObject m2 = new CompositeErrorObject(errorParams, errorObjects); + final CompositeErrorObject m3 = new CompositeErrorObject(errorObjects); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertEquals(m.getCompositeAsList(), m2.getCompositeAsList()); + assertEquals(m.getErrors(), m2.getErrors()); + assertEquals(m.getRequestParameters(), m2.getRequestParameters()); + assertEquals(m, CompositeErrorObject.getCompositeFromList(m.getCompositeAsList())); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void compositeNotifyObjectTest() { + + final List notifications = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPNotificationObject((short) 2, (short) 3)); + } + }; + + final List reqParams = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPRequestParameterObject(true, true, true, true, true, false, false, false, (short) 1, 1, true, true)); + } + }; + final CompositeNotifyObject m = new CompositeNotifyObject(reqParams, notifications); + final CompositeNotifyObject m2 = new CompositeNotifyObject(reqParams, notifications); + final CompositeNotifyObject m3 = new CompositeNotifyObject(notifications); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertEquals(m.getCompositeAsList(), m2.getCompositeAsList()); + assertEquals(m.getNotificationObjects(), m2.getNotificationObjects()); + assertEquals(m.getRequestParameters(), m2.getRequestParameters()); + assertEquals(m, CompositeNotifyObject.getCompositeFromList(m.getCompositeAsList())); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void compositePathObjectTest() { + + final List subobjects = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false)); + } + }; + + final CompositePathObject m = new CompositePathObject(new PCEPExplicitRouteObject(subobjects, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false)); + } + }, new PCEPIncludeRouteObject(subobjects, true, true)); + final CompositePathObject m2 = new CompositePathObject(new PCEPExplicitRouteObject(subobjects, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false)); + } + }, new PCEPIncludeRouteObject(subobjects, true, true)); + final CompositePathObject m3 = new CompositePathObject(new PCEPExplicitRouteObject(subobjects, false)); + + // FIXME BUG-89 + assertEquals(m.toString(), m2.toString()); + // assertEquals(m.hashCode(), m2.hashCode()); + // assertEquals(m.getCompositeAsList(), m2.getCompositeAsList()); + // assertEquals(m.getBandwidth(), m2.getBandwidth()); + assertEquals(m.getExcludedRoute(), m2.getExcludedRoute()); + assertEquals(m.getIncludeRoute(), m2.getIncludeRoute()); + assertEquals(m.getLspa(), m2.getLspa()); + assertEquals(m.getMetrics(), m2.getMetrics()); + assertEquals(m, CompositePathObject.getCompositeFromList(m.getCompositeAsList())); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void compositeRptPathObjectTest() { + + final List eroSubobjects = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new EROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), new UnnumberedInterfaceIdentifier(2), true)); + this.add(new EROIPPrefixSubobject(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 12, (byte) 122, + (byte) 125, (byte) 2 }), 22), false)); + } + }; + + final List rroSubobjects = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new RROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), new UnnumberedInterfaceIdentifier(2))); + this.add(new RROIPAddressSubobject(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 12, (byte) 122, + (byte) 125, (byte) 2 }), 22), true, false)); + } + }; + + final CompositeRptPathObject m = new CompositeRptPathObject(new PCEPExplicitRouteObject(eroSubobjects, false), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new PCEPReportedRouteObject(rroSubobjects, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false)); + } + }); + final CompositeRptPathObject m2 = new CompositeRptPathObject(new PCEPExplicitRouteObject(eroSubobjects, false), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new PCEPReportedRouteObject(rroSubobjects, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false)); + } + }); + final CompositePathObject m3 = new CompositePathObject(new PCEPExplicitRouteObject(eroSubobjects, false)); + // FIXME BUG-89 + // assertEquals(m, m2); + // assertEquals(m.toString(), m2.toString()); + // assertEquals(m.hashCode(), m2.hashCode()); + // assertEquals(m.getCompositeAsList(), m2.getCompositeAsList()); + // assertEquals(m.getBandwidth(), m2.getBandwidth()); + assertEquals(m.getExcludedRoute(), m2.getExcludedRoute()); + assertEquals(m.getLspa(), m2.getLspa()); + assertEquals(m.getMetrics(), m2.getMetrics()); + assertEquals(m, CompositeRptPathObject.getCompositeFromList(m.getCompositeAsList())); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void compositeUpdPathObjectTest() { + + final List subobjects = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false)); + } + }; + + final CompositeUpdPathObject m = new CompositeUpdPathObject(new PCEPExplicitRouteObject(subobjects, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false)); + } + }); + final CompositeUpdPathObject m2 = new CompositeUpdPathObject(new PCEPExplicitRouteObject(subobjects, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false)); + } + }); + final CompositeUpdPathObject m3 = new CompositeUpdPathObject(new PCEPExplicitRouteObject(subobjects, false)); + + // FIXME BUG-89 + // assertEquals(m, m2); + // assertEquals(m.toString(), m2.toString()); + // assertEquals(m.hashCode(), m2.hashCode()); + // assertEquals(m.getCompositeAsList(), m2.getCompositeAsList()); + // assertEquals(m.getBandwidth(), m2.getBandwidth()); + assertEquals(m.getExcludedRoute(), m2.getExcludedRoute()); + assertEquals(m.getLspa(), m2.getLspa()); + assertEquals(m.getMetrics(), m2.getMetrics()); + assertEquals(m, CompositeUpdPathObject.getCompositeFromList(m.getCompositeAsList())); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void compositeRequestedObjectTest() { + + final List eroSubobjects = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false)); + } + }; + + final List rroSubobjects = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new RROAsNumberSubobject(ObjectsTest.this.as)); + } + }; + + final CompositeRequestObject m = new CompositeRequestObject(new PCEPRequestParameterObject(true, true, true, true, true, true, false, false, false, (short) 1, 1, new ArrayList() { + private static final long serialVersionUID = 1L; + { + this.add(new OrderTlv(1L, 2L)); + } + }, true, true), new PCEPEndPointsObject(new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), new IPv4Address(new byte[] { + (byte) 127, (byte) 0, (byte) 0, (byte) 1 })), new PCEPClassTypeObject((short) 2), new PCEPLspObject((short) 1, true, true, true, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false)); + } + }, new PCEPReportedRouteObject(rroSubobjects, true), new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new PCEPIncludeRouteObject(eroSubobjects, true, true), new PCEPLoadBalancingObject(2, new Bandwidth(ByteArray.floatToBytes((float) 0.2)), true)); + final CompositeRequestObject m2 = new CompositeRequestObject(new PCEPRequestParameterObject(true, true, true, true, true, true, false, false, false, (short) 1, 1, new ArrayList() { + private static final long serialVersionUID = 1L; + { + this.add(new OrderTlv(1L, 2L)); + } + }, true, true), new PCEPEndPointsObject(new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), new IPv4Address(new byte[] { + (byte) 127, (byte) 0, (byte) 0, (byte) 1 })), new PCEPClassTypeObject((short) 2), new PCEPLspObject((short) 1, true, true, true, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false)); + } + }, new PCEPReportedRouteObject(rroSubobjects, true), new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new PCEPIncludeRouteObject(eroSubobjects, true, true), new PCEPLoadBalancingObject(2, new Bandwidth(ByteArray.floatToBytes((float) 0.2)), true)); + final CompositeRequestObject m3 = new CompositeRequestObject(new PCEPRequestParameterObject(true, true, true, true, true, true, false, false, false, (short) 1, 1, new ArrayList() { + private static final long serialVersionUID = 1L; + { + this.add(new OrderTlv(1L, 2L)); + } + }, true, true), new PCEPEndPointsObject(new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), new IPv4Address(new byte[] { + (byte) 127, (byte) 0, (byte) 0, (byte) 1 }))); + + // FIXME BUG-89 + // assertEquals(m, m2); + // assertEquals(m.toString(), m2.toString()); + // assertEquals(m.hashCode(), m2.hashCode()); + // assertEquals(m.getCompositeAsList(), m2.getCompositeAsList()); + // assertEquals(m.getBandwidth(), m2.getBandwidth()); + assertEquals(m.getLspa(), m2.getLspa()); + assertEquals(m.getMetrics(), m2.getMetrics()); + assertEquals(m.getClassType(), m2.getClassType()); + assertEquals(m.getEndPoints(), m2.getEndPoints()); + assertEquals(m.getIncludeRoute(), m2.getIncludeRoute()); + assertEquals(m.getLsp(), m2.getLsp()); + // assertEquals(m.getRroBandwidth(), m2.getRroBandwidth()); + assertEquals(m, CompositeRequestObject.getCompositeFromList(m.getCompositeAsList())); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void compositeResponseObjectTest() { + + final List subobjects = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false)); + } + }; + + final List paths = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new CompositePathObject(new PCEPExplicitRouteObject(subobjects, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false)); + } + }, new PCEPIncludeRouteObject(subobjects, true, true))); + } + }; + + final CompositeResponseObject m = new CompositeResponseObject(new PCEPRequestParameterObject(true, true, true, true, true, false, false, false, (short) 1, 1, true, true), new PCEPNoPathObject((short) 2, true, false), new PCEPLspObject((short) 1, true, true, true, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false)); + } + }, new PCEPIncludeRouteObject(subobjects, true, true), paths); + final CompositeResponseObject m2 = new CompositeResponseObject(new PCEPRequestParameterObject(true, true, true, true, true, false, false, false, (short) 1, 1, true, true), new PCEPNoPathObject((short) 2, true, false), new PCEPLspObject((short) 1, true, true, true, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false)); + } + }, new PCEPIncludeRouteObject(subobjects, true, true), paths); + final CompositeResponseObject m3 = new CompositeResponseObject(new PCEPRequestParameterObject(true, true, true, true, true, false, false, false, (short) 1, 1, true, true)); + + // FIXME BUG-89 + // assertEquals(m, m2); + // assertEquals(m.toString(), m2.toString()); + // assertEquals(m.hashCode(), m2.hashCode()); + // assertEquals(m.getCompositeAsList(), m2.getCompositeAsList()); + // assertEquals(m.getBandwidth(), m2.getBandwidth()); + assertEquals(m.getLspa(), m2.getLspa()); + assertEquals(m.getMetrics(), m2.getMetrics()); + assertEquals(m.getIncludeRoute(), m2.getIncludeRoute()); + assertEquals(m.getLsp(), m2.getLsp()); + assertEquals(m.getPaths(), m2.getPaths()); + assertEquals(m.getRequestParameter(), m2.getRequestParameter()); + assertEquals(m, CompositeResponseObject.getCompositeFromList(m.getCompositeAsList())); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void compositeStateReportObjectTest() { + + final List eroSubobjects = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false)); + } + }; + + final List rroSubobjects = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new RROAsNumberSubobject(ObjectsTest.this.as)); + } + }; + + final List paths = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new CompositeRptPathObject(new PCEPExplicitRouteObject(eroSubobjects, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new PCEPReportedRouteObject(rroSubobjects, true), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false)); + } + })); + } + }; + + final CompositeStateReportObject m = new CompositeStateReportObject(new PCEPLspObject((short) 1, true, true, true, true), paths); + final CompositeStateReportObject m2 = new CompositeStateReportObject(new PCEPLspObject((short) 1, true, true, true, true), paths); + final CompositeStateReportObject m3 = new CompositeStateReportObject(new PCEPLspObject((short) 1, true, true, true, true)); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertEquals(m.getCompositeAsList(), m2.getCompositeAsList()); + assertEquals(m.getLsp(), m2.getLsp()); + assertEquals(m.getPaths(), m2.getPaths()); + assertEquals(m, CompositeStateReportObject.getCompositeFromList(m.getCompositeAsList())); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void compositeUpdateRequestObjectTest() { + + final List subobjects = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false)); + } + }; + + final List paths = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new CompositeUpdPathObject(new PCEPExplicitRouteObject(subobjects, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false)); + } + })); + } + }; + + final CompositeUpdateRequestObject m = new CompositeUpdateRequestObject(new PCEPLspObject((short) 1, true, true, true, true), paths); + final CompositeUpdateRequestObject m2 = new CompositeUpdateRequestObject(new PCEPLspObject((short) 1, true, true, true, true), paths); + final CompositeUpdateRequestObject m3 = new CompositeUpdateRequestObject(new PCEPLspObject((short) 1, true, true, true, true)); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertEquals(m.getCompositeAsList(), m2.getCompositeAsList()); + assertEquals(m.getLsp(), m2.getLsp()); + assertEquals(m.getPaths(), m2.getPaths()); + assertEquals(m, CompositeUpdateRequestObject.getCompositeFromList(m.getCompositeAsList())); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void compositeRequestSVECObjectTest() { + + final List subobjects = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new XROAsNumberSubobject(ObjectsTest.this.as, false)); + } + }; + + final List requestIds = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(0x12345678L); + } + }; + + final CompositeRequestSvecObject m = new CompositeRequestSvecObject(new PCEPSvecObject(true, true, true, false, false, requestIds, true), new PCEPObjectiveFunctionObject(PCEPOFCodes.MBC, true, false), new PCEPGlobalConstraintsObject((short) 2, (short) 2, (short) 2, (short) 2, true, false), new PCEPExcludeRouteObject(subobjects, true, true, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(0x123456), true, false)); + } + }); + final CompositeRequestSvecObject m2 = new CompositeRequestSvecObject(new PCEPSvecObject(true, true, true, false, false, requestIds, true), new PCEPObjectiveFunctionObject(PCEPOFCodes.MBC, true, false), new PCEPGlobalConstraintsObject((short) 2, (short) 2, (short) 2, (short) 2, true, false), new PCEPExcludeRouteObject(subobjects, true, true, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(0x123456), true, false)); + } + }); + final CompositeRequestSvecObject m3 = new CompositeRequestSvecObject(new PCEPSvecObject(true, true, true, false, false, requestIds, true)); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertEquals(m.getCompositeAsList(), m2.getCompositeAsList()); + assertEquals(m.getExcludeRoute(), m2.getExcludeRoute()); + assertEquals(m.getGlobalConstraints(), m2.getGlobalConstraints()); + assertEquals(m.getObjectiveFunction(), m2.getObjectiveFunction()); + assertEquals(m.getSvec(), m2.getSvec()); + assertEquals(m, CompositeRequestSvecObject.getCompositeFromList(m.getCompositeAsList())); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void compositeRplySVECObjectTest() { + + final List requestIds = new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(0x12345678L); + } + }; + + final CompositeReplySvecObject m = new CompositeReplySvecObject(new PCEPSvecObject(true, true, true, false, false, requestIds, true), new PCEPObjectiveFunctionObject(PCEPOFCodes.MBC, true, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(0x123456), true, false)); + } + }); + final CompositeReplySvecObject m2 = new CompositeReplySvecObject(new PCEPSvecObject(true, true, true, false, false, requestIds, true), new PCEPObjectiveFunctionObject(PCEPOFCodes.MBC, true, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(0x123456), true, false)); + } + }); + final CompositeReplySvecObject m3 = new CompositeReplySvecObject(new PCEPSvecObject(true, true, true, false, false, requestIds, true)); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertEquals(m.getCompositeAsList(), m2.getCompositeAsList()); + assertEquals(m.getObjectiveFunction(), m2.getObjectiveFunction()); + assertEquals(m.getSvec(), m2.getSvec()); + assertEquals(m, CompositeReplySvecObject.getCompositeFromList(m.getCompositeAsList())); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void subobjectsTest() { + final EROAsNumberSubobject xas = new EROAsNumberSubobject(this.as, false); + final EROUnnumberedInterfaceSubobject uis = new EROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { (byte) 127, (byte) 0, + (byte) 0, (byte) 2 }), new UnnumberedInterfaceIdentifier(2), true); + final EROIPPrefixSubobject ips = new EROIPPrefixSubobject(new IPv4Prefix(new IPv4Address(new byte[] { + (byte) 12, (byte) 122, (byte) 125, (byte) 2 }), 22), false); + + assertEquals(xas.getASNumber().getValue().longValue(), 2555); + assertEquals(xas.isLoose(), false); + assertFalse(xas.equals(null)); + assertFalse(xas.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(xas.equals(xas)); + + assertEquals(uis.getInterfaceID().getInterfaceId(), 2); + assertEquals(uis.getRouterID(), new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 })); + assertEquals(uis.isLoose(), true); + assertFalse(uis.equals(null)); + assertFalse(uis.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(uis.equals(uis)); + + assertEquals(ips.getPrefix(), new IPv4Prefix(new IPv4Address(new byte[] { (byte) 12, (byte) 122, (byte) 125, (byte) 2 }), 22)); + assertEquals(ips.isLoose(), false); + assertFalse(ips.equals(null)); + assertFalse(ips.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(ips.equals(ips)); + } + + @Test + public void xroSubobjectsTest() { + final XROAsNumberSubobject xas = new XROAsNumberSubobject(this.as, false); + final XROUnnumberedInterfaceSubobject uis = new XROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { (byte) 127, (byte) 0, + (byte) 0, (byte) 2 }), new UnnumberedInterfaceIdentifier(2), true, XROSubobjectAttribute.SRLG); + final XROIPPrefixSubobject ips = new XROIPPrefixSubobject(new IPv4Prefix(new IPv4Address(new byte[] { + (byte) 12, (byte) 122, (byte) 125, (byte) 2 }), 22), false, XROSubobjectAttribute.SRLG); + final XROSRLGSubobject srlg = new XROSRLGSubobject(new SharedRiskLinkGroup(0x1234L), true); + + assertEquals(xas.getASNumber().getValue().longValue(), 2555); + assertEquals(xas.isMandatory(), false); + assertFalse(xas.equals(null)); + assertFalse(xas.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(xas.equals(xas)); + + // FIXME BUG-89 + // assertEquals(xas.toString(), "XROAsNumberSubobject [asnumber=AsNumber [_value=2555], mandatory=false]"); + + assertEquals(uis.getInterfaceID().getInterfaceId(), 2); + assertEquals(uis.getRouterID(), new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 })); + assertEquals(uis.isMandatory(), true); + assertFalse(uis.equals(null)); + assertFalse(uis.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(uis.equals(uis)); + assertEquals(uis.getAttribute(), XROSubobjectAttribute.SRLG); + assertEquals( + uis.toString(), + "XROUnnumberedInterfaceSubobject [attribute=SRLG, interfaceID=UnnumberedInterfaceIdentifier [interfaceId=2], routerID=127.0.0.2, mandatory=true]"); + + assertEquals(ips.getPrefix(), new IPv4Prefix(new IPv4Address(new byte[] { (byte) 12, (byte) 122, (byte) 125, (byte) 2 }), 22)); + assertEquals(ips.isMandatory(), false); + assertFalse(ips.equals(null)); + assertFalse(ips.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(ips.equals(ips)); + assertEquals(ips.getAttribute(), XROSubobjectAttribute.SRLG); + assertEquals(ips.toString(), "XROIPPrefixSubobject [attribute=SRLG, prefix=12.122.124.0/22, mandatory=false]"); + + assertEquals(srlg.getSrlgId().getValue(), 0x1234L); + assertEquals(srlg.getAttribute(), XROSubobjectAttribute.SRLG); + assertFalse(srlg.equals(null)); + assertFalse(srlg.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(srlg.equals(srlg)); + assertEquals(srlg.toString(), "XROSRLGSubobject [attribute=SRLG, srlgId=4660, mandatory=true]"); + } + + @Test + public void testToString() { + final List objects = Lists.newArrayList(); + objects.add(new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(22)), true, false)); + objects.add(new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(22)), true, false)); + objects.add(new PCEPEndPointsObject(IPv4.FAMILY.addressForBytes(new byte[] { 1, 1, 1, 1 }), IPv4.FAMILY.addressForBytes(new byte[] { + 1, 1, 1, 2 }))); + objects.add(new PCEPP2MPEndPointsObject(0, IPv4.FAMILY.addressForBytes(new byte[] { 1, 1, 1, 1 }), Lists.newArrayList(IPv4.FAMILY.addressForBytes(new byte[] { + 1, 1, 1, 1 })), true, false)); + + for (final PCEPObject o : objects) { + assertThat(o.toString(), containsString("processed=true")); + assertThat(o.toString(), containsString("ignored=false")); + // FIXME BUG-89 + // if (o instanceof PCEPBandwidthObject) + // assertThat(o.toString(), containsString("bandwidth=Bandwidth [_value=22.0]")); + if (o instanceof PCEPEndPoints) + assertThat(o.toString(), containsString("sourceAddress=1.1.1.1")); + if (o instanceof PCEPP2MPEndPointsObject) + assertThat(o.toString(), containsString("destinationAddresses=[1.1.1.1]")); + } + } + +} diff --git a/pcep/api/src/test/java/org/opendaylight/protocol/pcep/api/TlvsTest.java b/pcep/api/src/test/java/org/opendaylight/protocol/pcep/api/TlvsTest.java new file mode 100644 index 0000000000..a3c435695a --- /dev/null +++ b/pcep/api/src/test/java/org/opendaylight/protocol/pcep/api/TlvsTest.java @@ -0,0 +1,312 @@ +/* + * 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.api; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; + +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.concepts.IPv6Address; +import org.opendaylight.protocol.pcep.PCEPOFCodes; +import org.opendaylight.protocol.pcep.concepts.IPv4ExtendedTunnelIdentifier; +import org.opendaylight.protocol.pcep.concepts.IPv6ExtendedTunnelIdentifier; +import org.opendaylight.protocol.pcep.concepts.LSPIdentifier; +import org.opendaylight.protocol.pcep.concepts.LSPSymbolicName; +import org.opendaylight.protocol.pcep.concepts.TunnelIdentifier; +import org.opendaylight.protocol.pcep.message.PCEPOpenMessage; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; +import org.opendaylight.protocol.pcep.tlv.IPv4LSPIdentifiersTlv; +import org.opendaylight.protocol.pcep.tlv.IPv6LSPIdentifiersTlv; +import org.opendaylight.protocol.pcep.tlv.LSPCleanupTlv; +import org.opendaylight.protocol.pcep.tlv.LSPStateDBVersionTlv; +import org.opendaylight.protocol.pcep.tlv.LSPSymbolicNameTlv; +import org.opendaylight.protocol.pcep.tlv.LSPUpdateErrorTlv; +import org.opendaylight.protocol.pcep.tlv.NoPathVectorTlv; +import org.opendaylight.protocol.pcep.tlv.NodeIdentifierTlv; +import org.opendaylight.protocol.pcep.tlv.OFListTlv; +import org.opendaylight.protocol.pcep.tlv.OverloadedDurationTlv; +import org.opendaylight.protocol.pcep.tlv.PCEStatefulCapabilityTlv; +import org.opendaylight.protocol.pcep.tlv.RSVPErrorSpecTlv; +import org.opendaylight.protocol.pcep.tlv.ReqMissingTlv; + +/** + * + */ +public class TlvsTest { + @Test + public void IPv4LSPIdentifiersTlvTest() { + final IPv4LSPIdentifiersTlv m = new IPv4LSPIdentifiersTlv(new IPv4Address( + new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), new LSPIdentifier(new byte[] { (byte) 127, (byte) 0 }), new TunnelIdentifier( + new byte[] { (byte) 127, (byte) 0 }), new IPv4ExtendedTunnelIdentifier(new IPv4Address( + new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }))); + final IPv4LSPIdentifiersTlv m2 = new IPv4LSPIdentifiersTlv(new IPv4Address( + new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), new LSPIdentifier(new byte[] { (byte) 127, (byte) 0 }), new TunnelIdentifier( + new byte[] { (byte) 127, (byte) 0 }), new IPv4ExtendedTunnelIdentifier(new IPv4Address( + new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }))); + final IPv4LSPIdentifiersTlv m3 = new IPv4LSPIdentifiersTlv(new IPv4Address( + new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), new LSPIdentifier(new byte[] { (byte) 127, (byte) 0 }), new TunnelIdentifier( + new byte[] { (byte) 127, (byte) 0 }), new IPv4ExtendedTunnelIdentifier(new IPv4Address( + new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 3 }))); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertEquals(m.getExtendedTunnelID(), m2.getExtendedTunnelID()); + assertEquals(m.getLspID(), m2.getLspID()); + assertEquals(m.getSenderAddress(), m2.getSenderAddress()); + assertEquals(m.getTunnelID(), m2.getTunnelID()); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void IPv6LSPIdentifiersTlvTest() { + final IPv6LSPIdentifiersTlv m = new IPv6LSPIdentifiersTlv(new IPv6Address( + new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2, (byte) 127, (byte) 0, (byte) 0, (byte) 2, (byte) 127, (byte) 0, (byte) 0, (byte) 2, + (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), new LSPIdentifier(new byte[] { (byte) 127, (byte) 0 }), new TunnelIdentifier(new byte[] { + (byte) 127, (byte) 0 }), new IPv6ExtendedTunnelIdentifier(new IPv6Address( + new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2, (byte) 127, (byte) 0, (byte) 0, (byte) 2, (byte) 127, (byte) 0, (byte) 0, (byte) 2, + (byte) 127, (byte) 0, (byte) 0, (byte) 2 }))); + final IPv6LSPIdentifiersTlv m2 = new IPv6LSPIdentifiersTlv(new IPv6Address( + new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2, (byte) 127, (byte) 0, (byte) 0, (byte) 2, (byte) 127, (byte) 0, (byte) 0, (byte) 2, + (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), new LSPIdentifier(new byte[] { (byte) 127, (byte) 0 }), new TunnelIdentifier(new byte[] { + (byte) 127, (byte) 0 }), new IPv6ExtendedTunnelIdentifier(new IPv6Address( + new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2, (byte) 127, (byte) 0, (byte) 0, (byte) 2, (byte) 127, (byte) 0, (byte) 0, (byte) 2, + (byte) 127, (byte) 0, (byte) 0, (byte) 2 }))); + final IPv6LSPIdentifiersTlv m3 = new IPv6LSPIdentifiersTlv(new IPv6Address( + new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2, (byte) 127, (byte) 0, (byte) 0, (byte) 2, (byte) 127, (byte) 0, (byte) 0, (byte) 2, + (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), new LSPIdentifier(new byte[] { (byte) 127, (byte) 0 }), new TunnelIdentifier(new byte[] { + (byte) 127, (byte) 0 }), new IPv6ExtendedTunnelIdentifier(new IPv6Address( + new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2, (byte) 127, (byte) 0, (byte) 0, (byte) 2, (byte) 127, (byte) 0, (byte) 0, (byte) 2, + (byte) 127, (byte) 0, (byte) 0, (byte) 3 }))); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertEquals(m.getExtendedTunnelID(), m2.getExtendedTunnelID()); + assertEquals(m.getLspID(), m2.getLspID()); + assertEquals(m.getSenderAddress(), m2.getSenderAddress()); + assertEquals(m.getTunnelID(), m2.getTunnelID()); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void LSPStateDBVersionTlvTest() { + final LSPStateDBVersionTlv m = new LSPStateDBVersionTlv(25); + final LSPStateDBVersionTlv m2 = new LSPStateDBVersionTlv(25); + final LSPStateDBVersionTlv m3 = new LSPStateDBVersionTlv(26); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertEquals(m.getDbVersion(), m2.getDbVersion()); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void LSPSymbolicNameTlvTest() { + final LSPSymbolicNameTlv m = new LSPSymbolicNameTlv(new LSPSymbolicName(new byte[] { (byte) 2 })); + final LSPSymbolicNameTlv m2 = new LSPSymbolicNameTlv(new LSPSymbolicName(new byte[] { (byte) 2 })); + final LSPSymbolicNameTlv m3 = new LSPSymbolicNameTlv(new LSPSymbolicName(new byte[] { (byte) 3 })); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertEquals(m.getSymbolicName(), m2.getSymbolicName()); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void LSPUpdateErrorTlvTest() { + final LSPUpdateErrorTlv m = new LSPUpdateErrorTlv(new byte[] { (byte) 2, (byte) 2, (byte) 2, (byte) 2 }); + final LSPUpdateErrorTlv m2 = new LSPUpdateErrorTlv(new byte[] { (byte) 2, (byte) 2, (byte) 2, (byte) 2 }); + final LSPUpdateErrorTlv m3 = new LSPUpdateErrorTlv(new byte[] { (byte) 2, (byte) 2, (byte) 2, (byte) 3 }); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertArrayEquals(m.getErrorCode(), m2.getErrorCode()); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void NoPathVectorTlvTest() { + final NoPathVectorTlv m = new NoPathVectorTlv(false, true, false, false, false, false); + final NoPathVectorTlv m2 = new NoPathVectorTlv(false, true, false, false, false, false); + final NoPathVectorTlv m3 = new NoPathVectorTlv(false, true, true, false, false, false); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertFalse(m.isPceUnavailable()); + assertTrue(m.isUnknownDest()); + assertFalse(m.isUnknownSrc()); + assertFalse(m.isNoGCOSolution()); + assertFalse(m.isNoGCOMigrationPath()); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void NodeIdentifierTlvTest() throws UnsupportedEncodingException { + final NodeIdentifierTlv m = new NodeIdentifierTlv(new byte[] { (byte) 2 }); + final NodeIdentifierTlv m2 = new NodeIdentifierTlv(new byte[] { (byte) 2 }); + final NodeIdentifierTlv m3 = new NodeIdentifierTlv(new byte[] { (byte) 79, (byte) 102, (byte) 45, (byte) 57, (byte) 107, (byte) 45, (byte) 48, + (byte) 50 }); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertArrayEquals(m.getValue(), m2.getValue()); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + assertEquals(m3.toString(), "NodeIdentifierTlv [value=Of-9k-02]"); + + //non-ascii string + final String str = "þščťžéíá"; + + //test utf-8 validity + assertEquals("NodeIdentifierTlv [value=" + str + "]", new NodeIdentifierTlv(str.getBytes("UTF-8")).toString()); + + //test enother encoding, should be represented as raw binary + assertEquals("NodeIdentifierTlv [value=" + Arrays.toString(str.getBytes("ISO8859_1")) + "]", + new NodeIdentifierTlv(str.getBytes("ISO8859_1")).toString()); + } + + @Test + public void OverloadedDurationTlvTest() { + final OverloadedDurationTlv m = new OverloadedDurationTlv(2); + final OverloadedDurationTlv m2 = new OverloadedDurationTlv(2); + final OverloadedDurationTlv m3 = new OverloadedDurationTlv(3); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertEquals(m.getValue(), m2.getValue()); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void PCEStatefulCapabilityTlvTest() { + final PCEStatefulCapabilityTlv m = new PCEStatefulCapabilityTlv(false, true, false); + final PCEStatefulCapabilityTlv m2 = new PCEStatefulCapabilityTlv(false, true, false); + final PCEStatefulCapabilityTlv m3 = new PCEStatefulCapabilityTlv(true, true, true); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void RSVPErrorSpecTlvTest() { + final RSVPErrorSpecTlv m = new RSVPErrorSpecTlv(new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), true, true, 2, 2); + final RSVPErrorSpecTlv m2 = new RSVPErrorSpecTlv(new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), true, true, 2, 2); + final RSVPErrorSpecTlv m3 = new RSVPErrorSpecTlv(new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), false, true, 2, 2); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertEquals(m.getErrorCode(), m2.getErrorCode()); + assertEquals(m.getErrorNodeAddress(), m2.getErrorNodeAddress()); + assertEquals(m.getErrorValue(), m2.getErrorValue()); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void ReqMissingTlvTest() { + final ReqMissingTlv m = new ReqMissingTlv(2); + final ReqMissingTlv m2 = new ReqMissingTlv(2); + final ReqMissingTlv m3 = new ReqMissingTlv(3); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertEquals(m.getRequestID(), m2.getRequestID()); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void OFListTlvTest() { + final List ofcodes = new ArrayList(); + + final OFListTlv m = new OFListTlv(ofcodes); + final OFListTlv m2 = new OFListTlv(ofcodes); + final OFListTlv m3 = new OFListTlv(null); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertEquals(m.getOfCodes(), m2.getOfCodes()); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + } + + @Test + public void LSPCleanupTlvTest() { + final LSPCleanupTlv m = new LSPCleanupTlv(Integer.MAX_VALUE); + final LSPCleanupTlv m2 = new LSPCleanupTlv(Integer.MAX_VALUE); + final LSPCleanupTlv m3 = new LSPCleanupTlv(0); + + assertEquals(m, m2); + assertEquals(m.toString(), m2.toString()); + assertEquals(m.hashCode(), m2.hashCode()); + assertEquals(m.getTimeout(), m2.getTimeout()); + assertFalse(m.equals(null)); + assertFalse(m.equals(m3)); + assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1)))); + assertTrue(m.equals(m)); + + try { + new LSPCleanupTlv(Integer.MIN_VALUE); + } catch (final IllegalArgumentException e) { + assertEquals("Timeout (" + Integer.MIN_VALUE + ") cannot be negative or bigger than 2^31 -1.", e.getMessage()); + } + } +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiator.java index 58cfdf5fe4..ca80fc3e47 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiator.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiator.java @@ -20,18 +20,18 @@ import javax.annotation.concurrent.GuardedBy; import org.opendaylight.protocol.framework.AbstractSessionNegotiator; import org.opendaylight.protocol.pcep.PCEPErrors; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.pcerr.pcerr.message.error.type.Session; +import org.opendaylight.protocol.pcep.message.PCEPErrorMessage; +import org.opendaylight.protocol.pcep.message.PCEPOpenMessage; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; 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.Message; -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.PcerrMessage; 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.message.OpenMessageBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; /** * Abstract PCEP session negotiator. Takes care of basic handshake without implementing a specific policy. Policies need @@ -70,7 +70,6 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot } private static final Logger logger = LoggerFactory.getLogger(AbstractPCEPSessionNegotiator.class); - private final Timer timer; @GuardedBy("this") @@ -80,10 +79,10 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot private Timeout failTimer; @GuardedBy("this") - private OpenObject localPrefs; + private PCEPOpenObject localPrefs; @GuardedBy("this") - private OpenObject remotePrefs; + private PCEPOpenObject remotePrefs; private volatile boolean localOK, openRetry, remoteOK; @@ -97,7 +96,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot * * @return Session parameters proposal. */ - protected abstract OpenObject getInitialProposal(); + protected abstract PCEPOpenObject getInitialProposal(); /** * Get the revised session parameters proposal based on the feedback the peer has provided to us. @@ -105,7 +104,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot * @param suggestion Peer-provided suggested session parameters * @return Session parameters proposal. */ - protected abstract OpenObject getRevisedProposal(OpenObject suggestion); + protected abstract PCEPOpenObject getRevisedProposal(PCEPOpenObject suggestion); /** * Check whether a peer-provided session parameters proposal is acceptable. @@ -113,7 +112,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot * @param proposal peer-proposed session parameters * @return true if the proposal is acceptable, false otherwise */ - protected abstract boolean isProposalAcceptable(OpenObject proposal); + protected abstract boolean isProposalAcceptable(PCEPOpenObject proposal); /** * Given a peer-provided session parameters proposal which we found unacceptable, provide a counter-proposal. The @@ -122,7 +121,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot * @param proposal unacceptable peer proposal * @return our counter-proposal, or null if there is no way to negotiate an acceptable proposal */ - protected abstract OpenObject getCounterProposal(OpenObject proposal); + protected abstract PCEPOpenObject getCounterProposal(PCEPOpenObject proposal); /** * Create the protocol session. @@ -134,7 +133,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot * @param remotePrefs Session preferences proposed by the peer and accepted by us. * @return New protocol session. */ - protected abstract PCEPSessionImpl createSession(Timer timer, Channel channel, OpenObject localPrefs, OpenObject remotePrefs); + protected abstract PCEPSessionImpl createSession(Timer timer, Channel channel, PCEPOpenObject localPrefs, PCEPOpenObject remotePrefs); /** * Sends PCEP Error Message with one PCEPError. @@ -142,8 +141,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot * @param value */ private void sendErrorMessage(final PCEPErrors value) { - - this.channel.writeAndFlush(Util.createErrorMessage(value, null)); + this.channel.writeAndFlush(new PCEPErrorMessage(ImmutableList.of(new PCEPErrorObject(value)))); } private void scheduleFailTimer() { @@ -181,10 +179,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot final synchronized protected void startNegotiation() { Preconditions.checkState(this.state == State.Idle); this.localPrefs = getInitialProposal(); - final OpenMessage m = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder().setOpenMessage( - new OpenMessageBuilder().setOpen( - (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.open.message.Open) this.localPrefs).build()).build(); - this.channel.writeAndFlush(m); + this.channel.writeAndFlush(new PCEPOpenMessage(this.localPrefs)); this.state = State.OpenWait; scheduleFailTimer(); @@ -214,9 +209,9 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot } return; - } else if (msg instanceof PcerrMessage) { - final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessage err = ((PcerrMessage) msg).getPcerrMessage(); - this.localPrefs = getRevisedProposal((OpenObject) ((Session) err.getErrorType()).getOpen()); + } else if (msg instanceof PCEPErrorMessage) { + final PCEPErrorMessage err = (PCEPErrorMessage) msg; + this.localPrefs = getRevisedProposal(err.getOpenObject()); if (this.localPrefs == null) { sendErrorMessage(PCEPErrors.PCERR_NON_ACC_SESSION_CHAR); negotiationFailed(new RuntimeException("Peer suggested unacceptable retry proposal")); @@ -233,9 +228,8 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot break; case OpenWait: - if (msg instanceof OpenMessage) { - final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage o = ((OpenMessage) msg).getOpenMessage(); - final OpenObject open = o.getOpen(); + if (msg instanceof PCEPOpenMessage) { + final PCEPOpenObject open = ((PCEPOpenMessage) msg).getOpenObject(); if (isProposalAcceptable(open)) { this.channel.writeAndFlush(new KeepaliveMessageBuilder().build()); this.remotePrefs = open; @@ -258,7 +252,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot return; } - final OpenObject newPrefs = getCounterProposal(open); + final PCEPOpenObject newPrefs = getCounterProposal(open); if (newPrefs == null) { sendErrorMessage(PCEPErrors.NON_ACC_NON_NEG_SESSION_CHAR); negotiationFailed(new RuntimeException("Peer sent unacceptable session parameters")); @@ -266,7 +260,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot return; } - this.channel.writeAndFlush(Util.createErrorMessage(PCEPErrors.NON_ACC_NEG_SESSION_CHAR, newPrefs)); + this.channel.writeAndFlush(new PCEPErrorMessage(newPrefs, ImmutableList.of(new PCEPErrorObject(PCEPErrors.NON_ACC_NEG_SESSION_CHAR)), null)); this.openRetry = true; this.state = this.localOK ? State.OpenWait : State.KeepWait; diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiator.java index 13ca7cdd4e..22570439b4 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiator.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiator.java @@ -12,8 +12,7 @@ import io.netty.util.Timer; import io.netty.util.concurrent.Promise; import org.opendaylight.protocol.pcep.PCEPSessionListener; -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.open.message.open.message.OpenBuilder; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; import com.google.common.base.Preconditions; @@ -22,39 +21,37 @@ public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegot private final int maxUnknownMessages; public DefaultPCEPSessionNegotiator(final Timer timer, final Promise promise, final Channel channel, - final PCEPSessionListener listener, final short sessionId, final int maxUnknownMessages, final OpenObject localPrefs) { + final PCEPSessionListener listener, final short sessionId, final int maxUnknownMessages, final PCEPOpenObject localPrefs) { super(timer, promise, channel); this.maxUnknownMessages = maxUnknownMessages; - this.myLocalPrefs = new OpenBuilder().setKeepalive(localPrefs.getKeepalive()).setDeadTimer(localPrefs.getDeadTimer()).setSessionId( - sessionId).setTlvs(localPrefs.getTlvs()).build(); + this.myLocalPrefs = new PCEPOpenObject(localPrefs.getKeepAliveTimerValue(), localPrefs.getDeadTimerValue(), sessionId, localPrefs.getTlvs()); this.listener = Preconditions.checkNotNull(listener); } - private final OpenObject myLocalPrefs; + private final PCEPOpenObject myLocalPrefs; @Override - protected OpenObject getInitialProposal() { - return this.myLocalPrefs; + protected PCEPOpenObject getInitialProposal() { + return myLocalPrefs; } @Override - protected PCEPSessionImpl createSession(final Timer timer, final Channel channel, final OpenObject localPrefs, - final OpenObject remotePrefs) { - return new PCEPSessionImpl(timer, this.listener, this.maxUnknownMessages, channel, localPrefs, remotePrefs); + protected PCEPSessionImpl createSession(final Timer timer, final Channel channel, final PCEPOpenObject localPrefs, final PCEPOpenObject remotePrefs) { + return new PCEPSessionImpl(timer, listener, maxUnknownMessages, channel, localPrefs, remotePrefs); } @Override - protected boolean isProposalAcceptable(final OpenObject open) { + protected boolean isProposalAcceptable(final PCEPOpenObject open) { return true; } @Override - protected OpenObject getCounterProposal(final OpenObject open) { + protected PCEPOpenObject getCounterProposal(final PCEPOpenObject open) { return null; } @Override - protected OpenObject getRevisedProposal(final OpenObject suggestion) { - return this.myLocalPrefs; + protected PCEPOpenObject getRevisedProposal(final PCEPOpenObject suggestion) { + return myLocalPrefs; } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiatorFactory.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiatorFactory.java index 982ecfbfcf..1fdcfa00cf 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiatorFactory.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiatorFactory.java @@ -12,24 +12,25 @@ import io.netty.util.Timer; import io.netty.util.concurrent.Promise; import org.opendaylight.protocol.pcep.PCEPSessionListener; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; import com.google.common.base.Preconditions; public final class DefaultPCEPSessionNegotiatorFactory extends AbstractPCEPSessionNegotiatorFactory { - private final OpenObject localPrefs; + private final PCEPOpenObject localPrefs; private final int maxUnknownMessages; private final Timer timer; - public DefaultPCEPSessionNegotiatorFactory(final Timer timer, final OpenObject localPrefs, final int maxUnknownMessages) { + public DefaultPCEPSessionNegotiatorFactory(final Timer timer, final PCEPOpenObject localPrefs, + final int maxUnknownMessages) { this.timer = Preconditions.checkNotNull(timer); this.localPrefs = Preconditions.checkNotNull(localPrefs); this.maxUnknownMessages = maxUnknownMessages; } @Override - protected AbstractPCEPSessionNegotiator createNegotiator(final Promise promise, final PCEPSessionListener listener, - final Channel channel, final short sessionId) { - return new DefaultPCEPSessionNegotiator(this.timer, promise, channel, listener, sessionId, this.maxUnknownMessages, this.localPrefs); + protected AbstractPCEPSessionNegotiator createNegotiator(final Promise promise, + final PCEPSessionListener listener , final Channel channel, final short sessionId) { + return new DefaultPCEPSessionNegotiator(timer, promise, channel, listener, sessionId, maxUnknownMessages, localPrefs); } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/HandlerRegistryImpl.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/HandlerRegistryImpl.java index 6bb3acd595..3517040c41 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/HandlerRegistryImpl.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/HandlerRegistryImpl.java @@ -11,88 +11,16 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.opendaylight.protocol.concepts.AbstractRegistration; -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.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.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.HandlerRegistry; 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.SubobjectParser; -import org.opendaylight.protocol.pcep.spi.SubobjectSerializer; 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.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.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.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.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.Message; -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.Object; -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.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.PcepErrorObject; -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.pcep.types.rev131005.Tlv; -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.CSubobject; import com.google.common.base.Preconditions; @@ -104,104 +32,16 @@ public class HandlerRegistryImpl implements HandlerRegistry { // FIXME: fill this in - // reg.registerMessageHandler(PCEPOpenMessage.class, 1, new PCEPOpenMessageParser()); - // reg.registerMessageHandler(PCEPNotificationMessage.class, 5, new PCEPNotificationMessageParser()); - // reg.registerMessageHandler(PCEPKeepAliveMessage.class, 2, new PCEPKeepAliveMessageParser()); - // reg.registerMessageHandler(PCEPReplyMessage.class, 4, new PCEPReplyMessageParser()); - // reg.registerMessageHandler(PCEPRequestMessage.class, 3, new PCEPRequestMessageParser()); - // reg.registerMessageHandler(PCEPErrorMessage.class, 6, new PCEPErrorMessageParser()); - // reg.registerMessageHandler(PCEPCloseMessage.class, 7, new PCEPCloseMessageParser()); - // reg.registerMessageHandler(PCEPUpdateRequestMessage.class, 11, new PCEPUpdateRequestMessageParser()); - // reg.registerMessageHandler(PCEPReportMessage.class, 10, new PCEPReportMessageParser()); - // reg.registerMessageHandler(PCCreateMessage.class, 12, new PCCreateMessageParser()); - - reg.registerTlvParser(NoPathVectorTlvParser.TYPE, new NoPathVectorTlvParser()); - reg.registerTlvParser(OverloadedDurationTlvParser.TYPE, new OverloadedDurationTlvParser()); - reg.registerTlvParser(ReqMissingTlvParser.TYPE, new ReqMissingTlvParser()); - reg.registerTlvParser(OFListTlvParser.TYPE, new OFListTlvParser()); - reg.registerTlvParser(OrderTlvParser.TYPE, new OrderTlvParser()); - reg.registerTlvParser(PCEStatefulCapabilityTlvParser.TYPE, new PCEStatefulCapabilityTlvParser()); - reg.registerTlvParser(LspSymbolicNameTlvParser.TYPE, new LspSymbolicNameTlvParser()); - reg.registerTlvParser(LSPIdentifierIPv4TlvParser.TYPE, new LSPIdentifierIPv4TlvParser()); - reg.registerTlvParser(LSPIdentifierIPv6TlvParser.TYPE, new LSPIdentifierIPv6TlvParser()); - reg.registerTlvParser(LspUpdateErrorTlvParser.TYPE, new LspUpdateErrorTlvParser()); - reg.registerTlvParser(RSVPErrorSpecTlvParser.TYPE, new RSVPErrorSpecTlvParser()); - reg.registerTlvParser(LspDbVersionTlvParser.TYPE, new LspDbVersionTlvParser()); - reg.registerTlvParser(PredundancyGroupTlvParser.TYPE, new PredundancyGroupTlvParser()); - - reg.registerTlvSerializer(NoPathVectorTlv.class, new NoPathVectorTlvParser()); - reg.registerTlvSerializer(OverloadDurationTlv.class, new OverloadedDurationTlvParser()); - reg.registerTlvSerializer(ReqMissingTlv.class, new ReqMissingTlvParser()); - reg.registerTlvSerializer(OfListTlv.class, new OFListTlvParser()); - reg.registerTlvSerializer(OrderTlv.class, new OrderTlvParser()); - reg.registerTlvSerializer(StatefulCapabilityTlv.class, new PCEStatefulCapabilityTlvParser()); - reg.registerTlvSerializer(SymbolicPathNameTlv.class, new LspSymbolicNameTlvParser()); - reg.registerTlvSerializer(LspIdentifiersTlv.class, new LSPIdentifierIPv4TlvParser()); - reg.registerTlvSerializer(LspErrorCodeTlv.class, new LspUpdateErrorTlvParser()); - reg.registerTlvSerializer(RsvpErrorSpecTlv.class, new RSVPErrorSpecTlvParser()); - reg.registerTlvSerializer(LspDbVersionTlv.class, new LspDbVersionTlvParser()); - reg.registerTlvSerializer(PredundancyGroupIdTlv.class, new PredundancyGroupTlvParser()); - - reg.registerObjectParser(PCEPOpenObjectParser.CLASS, PCEPOpenObjectParser.TYPE, new PCEPOpenObjectParser(reg)); - reg.registerObjectParser(PCEPRequestParameterObjectParser.CLASS, PCEPRequestParameterObjectParser.TYPE, - new PCEPRequestParameterObjectParser(reg)); - reg.registerObjectParser(PCEPNoPathObjectParser.CLASS, PCEPNoPathObjectParser.TYPE, new PCEPNoPathObjectParser(reg)); - reg.registerObjectParser(PCEPEndPointsObjectParser.CLASS, PCEPEndPointsObjectParser.TYPE, new PCEPEndPointsObjectParser(reg)); - reg.registerObjectParser(PCEPEndPointsObjectParser.CLASS_6, PCEPEndPointsObjectParser.TYPE_6, new PCEPEndPointsObjectParser(reg)); - reg.registerObjectParser(PCEPBandwidthObjectParser.CLASS, PCEPBandwidthObjectParser.TYPE, new PCEPBandwidthObjectParser(reg)); - reg.registerObjectParser(PCEPBandwidthObjectParser.E_CLASS, PCEPBandwidthObjectParser.E_TYPE, new PCEPBandwidthObjectParser(reg)); - reg.registerObjectParser(PCEPMetricObjectParser.CLASS, PCEPMetricObjectParser.TYPE, new PCEPMetricObjectParser(reg)); - reg.registerObjectParser(PCEPExplicitRouteObjectParser.CLASS, PCEPExplicitRouteObjectParser.TYPE, - new PCEPExplicitRouteObjectParser(reg)); - reg.registerObjectParser(PCEPReportedRouteObjectParser.CLASS, PCEPReportedRouteObjectParser.TYPE, - new PCEPReportedRouteObjectParser(reg)); - reg.registerObjectParser(PCEPLspaObjectParser.CLASS, PCEPLspaObjectParser.TYPE, new PCEPLspaObjectParser(reg)); - reg.registerObjectParser(PCEPIncludeRouteObjectParser.CLASS, PCEPIncludeRouteObjectParser.TYPE, - new PCEPIncludeRouteObjectParser(reg)); - reg.registerObjectParser(PCEPSvecObjectParser.CLASS, PCEPSvecObjectParser.TYPE, new PCEPSvecObjectParser(reg)); - reg.registerObjectParser(PCEPNotificationObjectParser.CLASS, PCEPNotificationObjectParser.TYPE, - new PCEPNotificationObjectParser(reg)); - reg.registerObjectParser(PCEPErrorObjectParser.CLASS, PCEPErrorObjectParser.TYPE, new PCEPErrorObjectParser(reg)); - reg.registerObjectParser(PCEPLoadBalancingObjectParser.CLASS, PCEPLoadBalancingObjectParser.TYPE, - new PCEPLoadBalancingObjectParser(reg)); - reg.registerObjectParser(PCEPCloseObjectParser.CLASS, PCEPCloseObjectParser.TYPE, new PCEPCloseObjectParser(reg)); - reg.registerObjectParser(PCEPPathKeyObjectParser.CLASS, PCEPPathKeyObjectParser.TYPE, new PCEPPathKeyObjectParser(reg)); - reg.registerObjectParser(PCEPObjectiveFunctionObjectParser.CLASS, PCEPObjectiveFunctionObjectParser.TYPE, - new PCEPObjectiveFunctionObjectParser(reg)); - reg.registerObjectParser(PCEPClassTypeObjectParser.CLASS, PCEPClassTypeObjectParser.TYPE, new PCEPClassTypeObjectParser(reg)); - reg.registerObjectParser(PCEPGlobalConstraintsObjectParser.CLASS, PCEPGlobalConstraintsObjectParser.TYPE, - new PCEPGlobalConstraintsObjectParser(reg)); - reg.registerObjectParser(PCEPLspObjectParser.CLASS, PCEPLspObjectParser.TYPE, new PCEPLspObjectParser(reg)); - reg.registerObjectParser(PCEPSrpObjectParser.CLASS, PCEPSrpObjectParser.TYPE, new PCEPSrpObjectParser(reg)); - // reg.registerObjectParser(PCEPExcludeRouteObjectParser.CLASS, PCEPExcludeRouteObjectParser.TYPE, new - // PCEPExcludeRouteObjectParser(reg)); - - reg.registerObjectSerializer(OpenObject.class, new PCEPOpenObjectParser(reg)); - reg.registerObjectSerializer(RpObject.class, new PCEPRequestParameterObjectParser(reg)); - reg.registerObjectSerializer(NoPathObject.class, new PCEPNoPathObjectParser(reg)); - reg.registerObjectSerializer(EndpointsObject.class, new PCEPEndPointsObjectParser(reg)); - reg.registerObjectSerializer(BandwidthObject.class, new PCEPBandwidthObjectParser(reg)); - reg.registerObjectSerializer(MetricObject.class, new PCEPMetricObjectParser(reg)); - reg.registerObjectSerializer(ExplicitRouteObject.class, new PCEPExplicitRouteObjectParser(reg)); - reg.registerObjectSerializer(ReportedRouteObject.class, new PCEPReportedRouteObjectParser(reg)); - reg.registerObjectSerializer(LspaObject.class, new PCEPLspaObjectParser(reg)); - reg.registerObjectSerializer(IncludeRouteObject.class, new PCEPIncludeRouteObjectParser(reg)); - reg.registerObjectSerializer(SvecObject.class, new PCEPSvecObjectParser(reg)); - reg.registerObjectSerializer(NotificationObject.class, new PCEPNotificationObjectParser(reg)); - reg.registerObjectSerializer(PcepErrorObject.class, new PCEPErrorObjectParser(reg)); - reg.registerObjectSerializer(LoadBalancingObject.class, new PCEPLoadBalancingObjectParser(reg)); - reg.registerObjectSerializer(CloseObject.class, new PCEPCloseObjectParser(reg)); - reg.registerObjectSerializer(PathKeyObject.class, new PCEPPathKeyObjectParser(reg)); - reg.registerObjectSerializer(OfObject.class, new PCEPObjectiveFunctionObjectParser(reg)); - reg.registerObjectSerializer(ClasstypeObject.class, new PCEPClassTypeObjectParser(reg)); - reg.registerObjectSerializer(GcObject.class, new PCEPGlobalConstraintsObjectParser(reg)); - reg.registerObjectSerializer(LspObject.class, new PCEPLspObjectParser(reg)); - reg.registerObjectSerializer(SrpObject.class, new PCEPSrpObjectParser(reg)); - // reg.registerObjectSerializer(ExcludeRouteObject.class, new PCEPExcludeRouteObjectParser(reg)); - - reg.registerSubobjectParser(EROAsNumberSubobjectParser.TYPE, new EROAsNumberSubobjectParser()); - - reg.registerSubobjectSerializer(AsNumberSubobject.class, new EROAsNumberSubobjectParser()); + // reg.registerMessageHandler(PCEPOpenMessage.class, 1, new PCEPOpenMessageParser()); + // reg.registerMessageHandler(PCEPNotificationMessage.class, 5, new PCEPNotificationMessageParser()); + // reg.registerMessageHandler(PCEPKeepAliveMessage.class, 2, new PCEPKeepAliveMessageParser()); + // reg.registerMessageHandler(PCEPReplyMessage.class, 4, new PCEPReplyMessageParser()); + // reg.registerMessageHandler(PCEPRequestMessage.class, 3, new PCEPRequestMessageParser()); + // reg.registerMessageHandler(PCEPErrorMessage.class, 6, new PCEPErrorMessageParser()); + // reg.registerMessageHandler(PCEPCloseMessage.class, 7, new PCEPCloseMessageParser()); + // reg.registerMessageHandler(PCEPUpdateRequestMessage.class, 11, new PCEPUpdateRequestMessageParser()); + // reg.registerMessageHandler(PCEPReportMessage.class, 10, new PCEPReportMessageParser()); + // reg.registerMessageHandler(PCCreateMessage.class, 12, new PCCreateMessageParser()); INSTANCE = reg; } @@ -215,9 +55,6 @@ public class HandlerRegistryImpl implements HandlerRegistry { private final Map tlvParsers = new ConcurrentHashMap<>(); private final Map, TlvSerializer> tlvSerializers = new ConcurrentHashMap<>(); - private final Map subobjectParsers = new ConcurrentHashMap<>(); - private final Map, SubobjectSerializer> subobjectSerializers = new ConcurrentHashMap<>(); - private HandlerRegistryImpl() { } @@ -225,13 +62,13 @@ public class HandlerRegistryImpl implements HandlerRegistry { @Override public MessageParser getMessageParser(final int messageType) { Preconditions.checkArgument(messageType >= 0 && messageType <= 255); - return this.msgParsers.get(messageType); + return msgParsers.get(messageType); } @Override public MessageSerializer getMessageSerializer(final Message message) { final Class c = message.getClass(); - for (final Map.Entry, MessageSerializer> s : this.msgSerializers.entrySet()) { + for (Map.Entry, MessageSerializer> s : msgSerializers.entrySet()) { if (s.getKey().isAssignableFrom(c)) { return s.getValue(); } @@ -245,13 +82,13 @@ public class HandlerRegistryImpl implements HandlerRegistry { Preconditions.checkArgument(objectClass >= 0 && objectClass <= 255); Preconditions.checkArgument(objectType >= 0 && objectType <= 15); - return this.objParsers.get((objectClass << 4) + objectType); + return objParsers.get((objectClass << 4) + objectType); } @Override public ObjectSerializer getObjectSerializer(final Object object) { final Class c = object.getClass(); - for (final Map.Entry, ObjectSerializer> s : this.objSerializers.entrySet()) { + for (Map.Entry, ObjectSerializer> s : objSerializers.entrySet()) { if (s.getKey().isAssignableFrom(c)) { return s.getValue(); } @@ -263,13 +100,13 @@ public class HandlerRegistryImpl implements HandlerRegistry { @Override public TlvParser getTlvParser(final int tlvType) { Preconditions.checkArgument(tlvType >= 0 && tlvType <= 65535); - return this.tlvParsers.get(tlvType); + return tlvParsers.get(tlvType); } @Override public TlvSerializer getTlvSerializer(final Tlv tlv) { final Class c = tlv.getClass(); - for (final Map.Entry, TlvSerializer> s : this.tlvSerializers.entrySet()) { + for (Map.Entry, TlvSerializer> s : tlvSerializers.entrySet()) { if (s.getKey().isAssignableFrom(c)) { return s.getValue(); } @@ -278,32 +115,15 @@ public class HandlerRegistryImpl implements HandlerRegistry { return null; } - @Override - public SubobjectSerializer getSubobjectSerializer(final CSubobject subobject) { - final Class c = subobject.getClass(); - for (final Map.Entry, SubobjectSerializer> s : this.subobjectSerializers.entrySet()) { - if (s.getKey().isAssignableFrom(c)) { - return s.getValue(); - } - } - return null; - } - - @Override - public SubobjectParser getSubobjectParser(final int subobjectType) { - Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535); - return this.subobjectParsers.get(subobjectType); - } - private synchronized void unregisterMessageParser(final Integer msgType) { - this.msgParsers.remove(msgType); + msgParsers.remove(msgType); } @Override public synchronized AutoCloseable registerMessageParser(final int msgType, final MessageParser parser) { Preconditions.checkArgument(msgType >= 0 && msgType <= 255); - Preconditions.checkArgument(!this.msgParsers.containsKey(msgType), "Message type %s already registered", msgType); - this.msgParsers.put(msgType, parser); + Preconditions.checkArgument(!msgParsers.containsKey(msgType), "Message type %s already registered", msgType); + msgParsers.put(msgType, parser); return new AbstractRegistration() { @Override @@ -314,13 +134,13 @@ public class HandlerRegistryImpl implements HandlerRegistry { } private synchronized void unregisterMessageSerializer(final Class msgClass) { - this.msgSerializers.remove(msgClass); + msgSerializers.remove(msgClass); } @Override public synchronized AutoCloseable registerMessageSerializer(final Class msgClass, final MessageSerializer serializer) { - Preconditions.checkArgument(!this.msgSerializers.containsKey(msgClass), "Message class %s already registered", msgClass); - this.msgSerializers.put(msgClass, serializer); + Preconditions.checkArgument(!msgSerializers.containsKey(msgClass), "Message class %s already registered", msgClass); + msgSerializers.put(msgClass, serializer); return new AbstractRegistration() { @Override @@ -331,18 +151,18 @@ public class HandlerRegistryImpl implements HandlerRegistry { } private synchronized void unregisterObjectParser(final Integer key) { - this.objParsers.remove(key); + objParsers.remove(key); } @Override - public synchronized AutoCloseable registerObjectParser(final int objectClass, final int objectType, final ObjectParser parser) { + public synchronized AutoCloseable registerObjectParser(final int objectClass, final int objectType, + final ObjectParser parser) { Preconditions.checkArgument(objectClass >= 0 && objectClass <= 255); Preconditions.checkArgument(objectType >= 0 && objectType <= 15); final Integer key = (objectClass << 4) + objectType; - Preconditions.checkArgument(!this.objParsers.containsKey(key), "Object class %s type %s already registered", objectClass, - objectType); - this.objParsers.put(key, parser); + Preconditions.checkArgument(!objParsers.containsKey(key), "Object class %s type %s already registered", objectClass, objectType); + objParsers.put(key, parser); return new AbstractRegistration() { @Override @@ -353,13 +173,13 @@ public class HandlerRegistryImpl implements HandlerRegistry { } private synchronized void unregisterObjectSerializer(final Class objClass) { - this.objSerializers.remove(objClass); + objSerializers.remove(objClass); } @Override public synchronized AutoCloseable registerObjectSerializer(final Class objClass, final ObjectSerializer serializer) { - Preconditions.checkArgument(!this.objSerializers.containsKey(objClass), "Object class %s already registered", objClass); - this.objSerializers.put(objClass, serializer); + Preconditions.checkArgument(!objSerializers.containsKey(objClass), "Object class %s already registered", objClass); + objSerializers.put(objClass, serializer); return new AbstractRegistration() { @Override @@ -370,15 +190,15 @@ public class HandlerRegistryImpl implements HandlerRegistry { } private synchronized void unregisterTlvParser(final int tlvType) { - this.tlvParsers.remove(tlvType); + tlvParsers.remove(tlvType); } @Override public synchronized AutoCloseable registerTlvParser(final int tlvType, final TlvParser parser) { Preconditions.checkArgument(tlvType >= 0 && tlvType <= 65535); - Preconditions.checkArgument(!this.tlvParsers.containsKey(tlvType), "TLV type %s already registered", tlvType); + Preconditions.checkArgument(!tlvParsers.containsKey(tlvType), "TLV type %s already registered", tlvType); - this.tlvParsers.put(tlvType, parser); + tlvParsers.put(tlvType, parser); return new AbstractRegistration() { @Override @@ -389,13 +209,13 @@ public class HandlerRegistryImpl implements HandlerRegistry { } private synchronized void unregisterTlvSerializer(final Class tlvClass) { - this.tlvSerializers.remove(tlvClass); + tlvSerializers.remove(tlvClass); } @Override public synchronized AutoCloseable registerTlvSerializer(final Class tlvClass, final TlvSerializer serializer) { - Preconditions.checkArgument(!this.tlvSerializers.containsKey(tlvClass), "TLV class %s already registered", tlvClass); - this.tlvSerializers.put(tlvClass, serializer); + Preconditions.checkArgument(!tlvSerializers.containsKey(tlvClass), "TLV class %s already registered", tlvClass); + tlvSerializers.put(tlvClass, serializer); return new AbstractRegistration() { @Override @@ -404,42 +224,4 @@ public class HandlerRegistryImpl implements HandlerRegistry { } }; } - - @Override - public AutoCloseable registerSubobjectSerializer(final Class subobjectClass, final SubobjectSerializer serializer) { - Preconditions.checkArgument(!this.tlvSerializers.containsKey(subobjectClass), "Subobject class %s already registered", - subobjectClass); - this.subobjectSerializers.put(subobjectClass, serializer); - - return new AbstractRegistration() { - @Override - protected void removeRegistration() { - unregisterSubobjectSerializer(subobjectClass); - } - }; - } - - private synchronized void unregisterSubobjectSerializer(final Class subobjectClass) { - this.subobjectSerializers.remove(subobjectClass); - } - - @Override - public AutoCloseable registerSubobjectParser(final int subobjectType, final SubobjectParser parser) { - Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535); - Preconditions.checkArgument(!this.subobjectParsers.containsKey(subobjectType), "Subobject type %s already registered", - subobjectType); - - this.subobjectParsers.put(subobjectType, parser); - - return new AbstractRegistration() { - @Override - protected void removeRegistration() { - unregisterSubobjectParser(subobjectType); - } - }; - } - - private synchronized void unregisterSubobjectParser(final int subobjectType) { - this.subobjectParsers.remove(subobjectType); - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParser.java index 721cd98628..350600c2ea 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParser.java @@ -10,10 +10,17 @@ package org.opendaylight.protocol.pcep.impl; import java.util.ArrayList; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.protocol.concepts.IPv4Prefix; import org.opendaylight.protocol.concepts.IPv6Prefix; 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.EROIPv4PrefixSubobjectParser; +import org.opendaylight.protocol.pcep.impl.subobject.EROIPv6PrefixSubobjectParser; import org.opendaylight.protocol.pcep.impl.subobject.EROLabelSubobjectParser; import org.opendaylight.protocol.pcep.impl.subobject.EROPathKeyWith128PCEIDSubobjectParser; import org.opendaylight.protocol.pcep.impl.subobject.EROPathKeyWith32PCEIDSubobjectParser; @@ -28,26 +35,25 @@ import org.opendaylight.protocol.pcep.subobject.EROPathKeyWith32PCEIDSubobject; import org.opendaylight.protocol.pcep.subobject.EROProtectionSubobject; import org.opendaylight.protocol.pcep.subobject.EROUnnumberedInterfaceSubobject; import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; -import org.opendaylight.protocol.util.ByteArray; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Parser for {@link org.opendaylight.protocol.pcep.PCEPSubobject PCEPSubobject} */ public class PCEPEROSubobjectParser { - private static final Logger logger = LoggerFactory.getLogger(PCEPEROSubobjectParser.class); + private static final Logger logger = LoggerFactory.getLogger(PCEPEROSubobjectParser.class); - /** - * Type identifier for {@link org.opendaylight.protocol.pcep.PCEPSubobject PCEPSubobject} - */ - public enum PCEPSubobjectType { - IPv4_PREFIX(1), IPv6_PREFIX(2), LABEL(3), UNNUMBERED_INTERFACE_ID(4), AS_NUMBER(32), EXRS(33), PROTECTION(37), PK_32(64), PK_128(65); + /** + * Type identifier for {@link org.opendaylight.protocol.pcep.PCEPSubobject + * PCEPSubobject} + */ + public enum PCEPSubobjectType { + IPv4_PREFIX(1), IPv6_PREFIX(2), LABEL(3), UNNUMBERED_INTERFACE_ID(4), AS_NUMBER(32), EXRS(33), PROTECTION(37), PK_32( + 64), PK_128(65); private final int indicator; - PCEPSubobjectType(final int indicator) { + PCEPSubobjectType(int indicator) { this.indicator = indicator; } @@ -55,161 +61,158 @@ public class PCEPEROSubobjectParser { return this.indicator; } - public static PCEPSubobjectType getFromInt(final int type) throws PCEPDeserializerException { + public static PCEPSubobjectType getFromInt(int type) throws PCEPDeserializerException { for (final PCEPSubobjectType type_e : PCEPSubobjectType.values()) { if (type_e.getIndicator() == type) return type_e; } - throw new PCEPDeserializerException("Unknown Subobject type. Passed: " + type + "; Known: " + PCEPSubobjectType.values() + "."); + throw new PCEPDeserializerException("Unknown Subobject type. Passed: " + type + "; Known: " + + PCEPSubobjectType.values() + "."); } } - /* - * Fields lengths in Bytes - */ - public static final int TYPE_FLAG_F_LENGTH = 1; - public static final int LENGTH_F_LENGTH = 1; + /* + * Fields lengths in Bytes + */ + public static final int TYPE_FLAG_F_LENGTH = 1; + public static final int LENGTH_F_LENGTH = 1; - /* - * Fields offsets in Bytes - */ - public static final int TYPE_FLAG_F_OFFSET = 0; - public static final int LENGTH_F_OFFSET = TYPE_FLAG_F_OFFSET + TYPE_FLAG_F_LENGTH; - public static final int SO_CONTENTS_OFFSET = LENGTH_F_OFFSET + LENGTH_F_LENGTH; + /* + * Fields offsets in Bytes + */ + public static final int TYPE_FLAG_F_OFFSET = 0; + public static final int LENGTH_F_OFFSET = TYPE_FLAG_F_OFFSET + TYPE_FLAG_F_LENGTH; + public static final int SO_CONTENTS_OFFSET = LENGTH_F_OFFSET + LENGTH_F_LENGTH; - public static List parse(final byte[] bytes) throws PCEPDeserializerException { - if (bytes == null) - throw new IllegalArgumentException("Byte array is mandatory."); + public static List parse(byte[] bytes) throws PCEPDeserializerException { + if (bytes == null) + throw new IllegalArgumentException("Byte array is mandatory."); - final List subobjsList = new ArrayList(); - boolean loose_flag; - PCEPSubobjectType type; - byte[] soContentsBytes; - int length; - int offset = 0; + final List subobjsList = new ArrayList(); + boolean loose_flag; + PCEPSubobjectType type; + byte[] soContentsBytes; + int length; + int offset = 0; - while (offset < bytes.length) { + while (offset < bytes.length) { - loose_flag = ((bytes[offset + TYPE_FLAG_F_OFFSET] & (1 << 7)) != 0) ? true : false; - length = ByteArray.bytesToInt(ByteArray.subByte(bytes, offset + LENGTH_F_OFFSET, LENGTH_F_LENGTH)); + loose_flag = ((bytes[offset + TYPE_FLAG_F_OFFSET] & (1 << 7)) != 0) ? true : false; + length = ByteArray.bytesToInt(ByteArray.subByte(bytes, offset + LENGTH_F_OFFSET, LENGTH_F_LENGTH)); - type = PCEPSubobjectType.getFromInt((bytes[offset + TYPE_FLAG_F_OFFSET] & 0xff) & ~(1 << 7)); + type = PCEPSubobjectType.getFromInt((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)); + 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); + soContentsBytes = new byte[length - SO_CONTENTS_OFFSET]; + 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 ExplicitRouteSubobject subObj = parseSpecificSubobject(type, soContentsBytes, loose_flag); - logger.debug("Subobject was parsed. {}", subObj); + logger.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes)); + final ExplicitRouteSubobject subObj = parseSpecificSubobject(type, soContentsBytes, loose_flag); + logger.debug("Subobject was parsed. {}", subObj); - subobjsList.add(subObj); + subobjsList.add(subObj); - offset += length; - } - - return subobjsList; + offset += length; } - public static byte[] put(final List objsToSerialize) { - final List bytesList = new ArrayList(objsToSerialize.size()); - - int length = 0; - for (final ExplicitRouteSubobject obj : objsToSerialize) { - final byte[] bytes = put(obj); - length += bytes.length; - bytesList.add(bytes); - } + return subobjsList; + } - final byte[] retBytes = new byte[length]; + public static byte[] put(List objsToSerialize) { + final List bytesList = new ArrayList(objsToSerialize.size()); - int offset = 0; - for (final byte[] bytes : bytesList) { - System.arraycopy(bytes, 0, retBytes, offset, bytes.length); - offset += bytes.length; - } - - return retBytes; + int length = 0; + for (final ExplicitRouteSubobject obj : objsToSerialize) { + final byte[] bytes = put(obj); + length += bytes.length; + bytesList.add(bytes); } - public static byte[] put(final ExplicitRouteSubobject objToSerialize) { - int typeIndicator = 0; - - byte[] soContentsBytes = null; - - if (objToSerialize instanceof EROIPPrefixSubobject - && ((EROIPPrefixSubobject) objToSerialize).getPrefix() instanceof IPv4Prefix) { - typeIndicator = PCEPSubobjectType.IPv4_PREFIX.getIndicator(); - // soContentsBytes = EROIpPrefixSubobjectParser.put(objToSerialize); - } else if (objToSerialize instanceof EROIPPrefixSubobject - && ((EROIPPrefixSubobject) objToSerialize).getPrefix() instanceof IPv6Prefix) { - typeIndicator = PCEPSubobjectType.IPv6_PREFIX.getIndicator(); - // soContentsBytes = EROIPv6PrefixSubobjectParser.put(objToSerialize); - } else if (objToSerialize instanceof EROAsNumberSubobject) { - typeIndicator = PCEPSubobjectType.AS_NUMBER.getIndicator(); - // soContentsBytes = EROAsNumberSubobjectParser.put(objToSerialize); - } else if (objToSerialize instanceof EROUnnumberedInterfaceSubobject) { - typeIndicator = PCEPSubobjectType.UNNUMBERED_INTERFACE_ID.getIndicator(); - soContentsBytes = EROUnnumberedInterfaceSubobjectParser.put(objToSerialize); - } else if (objToSerialize instanceof EROLabelSubobject) { - typeIndicator = PCEPSubobjectType.LABEL.getIndicator(); - soContentsBytes = EROLabelSubobjectParser.put((EROLabelSubobject) objToSerialize); - } else if (objToSerialize instanceof EROExplicitExclusionRouteSubobject) { - typeIndicator = PCEPSubobjectType.EXRS.getIndicator(); - soContentsBytes = EROExplicitExclusionRouteSubobjectParser.put((EROExplicitExclusionRouteSubobject) objToSerialize); - } else if (objToSerialize instanceof EROPathKeyWith32PCEIDSubobject) { - typeIndicator = PCEPSubobjectType.PK_32.getIndicator(); - soContentsBytes = EROPathKeyWith32PCEIDSubobjectParser.put((EROPathKeyWith32PCEIDSubobject) objToSerialize); - } else if (objToSerialize instanceof EROPathKeyWith128PCEIDSubobject) { - typeIndicator = PCEPSubobjectType.PK_128.getIndicator(); - soContentsBytes = EROPathKeyWith128PCEIDSubobjectParser.put((EROPathKeyWith128PCEIDSubobject) objToSerialize); - } else if (objToSerialize instanceof EROProtectionSubobject) { - typeIndicator = PCEPSubobjectType.PROTECTION.getIndicator(); - soContentsBytes = EROProtectionSubobjectParser.put((EROProtectionSubobject) objToSerialize); - } else - throw new IllegalArgumentException("Unknown instance of PCEPSubobject. Passed: " + objToSerialize.getClass() + "."); - - final byte[] bytes = new byte[SO_CONTENTS_OFFSET + soContentsBytes.length]; - - bytes[TYPE_FLAG_F_OFFSET] = (byte) (ByteArray.cutBytes(ByteArray.intToBytes(typeIndicator), (Integer.SIZE / 8) - TYPE_FLAG_F_LENGTH)[0] | (objToSerialize.isLoose() ? 1 << 7 - : 0)); - bytes[LENGTH_F_OFFSET] = ByteArray.cutBytes(ByteArray.intToBytes(soContentsBytes.length + SO_CONTENTS_OFFSET), (Integer.SIZE / 8) - - LENGTH_F_LENGTH)[0]; - - System.arraycopy(soContentsBytes, 0, bytes, SO_CONTENTS_OFFSET, soContentsBytes.length); - - return bytes; + final byte[] retBytes = new byte[length]; + + int offset = 0; + for (final byte[] bytes : bytesList) { + System.arraycopy(bytes, 0, retBytes, offset, bytes.length); + offset += bytes.length; } - private static ExplicitRouteSubobject parseSpecificSubobject(final PCEPSubobjectType type, final byte[] soContentsBytes, - final boolean loose_flag) throws PCEPDeserializerException { - - switch (type) { - case IPv4_PREFIX: - // return EROIpPrefixSubobjectParser.parse(soContentsBytes, loose_flag); - case IPv6_PREFIX: - // return EROIPv6PrefixSubobjectParser.parse(soContentsBytes, loose_flag); - case UNNUMBERED_INTERFACE_ID: - return EROUnnumberedInterfaceSubobjectParser.parse(soContentsBytes, loose_flag); - case AS_NUMBER: - // return EROAsNumberSubobjectParser.parse(soContentsBytes, loose_flag); - case LABEL: - return EROLabelSubobjectParser.parse(soContentsBytes, loose_flag); - case EXRS: - return EROExplicitExclusionRouteSubobjectParser.parse(soContentsBytes, loose_flag); - case PK_32: - return EROPathKeyWith32PCEIDSubobjectParser.parse(soContentsBytes, loose_flag); - case PK_128: - return EROPathKeyWith128PCEIDSubobjectParser.parse(soContentsBytes, loose_flag); - case PROTECTION: - return EROProtectionSubobjectParser.parse(soContentsBytes, loose_flag); - default: - throw new PCEPDeserializerException("Unknown Subobject type. Passed: " + type + "."); - } + return retBytes; + } + + public static byte[] put(ExplicitRouteSubobject objToSerialize) { + int typeIndicator = 0; + + final byte[] soContentsBytes; + + if (objToSerialize instanceof EROIPPrefixSubobject && ((EROIPPrefixSubobject) objToSerialize).getPrefix() instanceof IPv4Prefix) { + typeIndicator = PCEPSubobjectType.IPv4_PREFIX.getIndicator(); + soContentsBytes = EROIPv4PrefixSubobjectParser.put(objToSerialize); + } else if (objToSerialize instanceof EROIPPrefixSubobject && ((EROIPPrefixSubobject) objToSerialize).getPrefix() instanceof IPv6Prefix) { + typeIndicator = PCEPSubobjectType.IPv6_PREFIX.getIndicator(); + soContentsBytes = EROIPv6PrefixSubobjectParser.put(objToSerialize); + } else if (objToSerialize instanceof EROAsNumberSubobject) { + typeIndicator = PCEPSubobjectType.AS_NUMBER.getIndicator(); + soContentsBytes = EROAsNumberSubobjectParser.put(objToSerialize); + } else if (objToSerialize instanceof EROUnnumberedInterfaceSubobject) { + typeIndicator = PCEPSubobjectType.UNNUMBERED_INTERFACE_ID.getIndicator(); + soContentsBytes = EROUnnumberedInterfaceSubobjectParser.put(objToSerialize); + } else if (objToSerialize instanceof EROLabelSubobject) { + typeIndicator = PCEPSubobjectType.LABEL.getIndicator(); + soContentsBytes = EROLabelSubobjectParser.put((EROLabelSubobject) objToSerialize); + } else if (objToSerialize instanceof EROExplicitExclusionRouteSubobject) { + typeIndicator = PCEPSubobjectType.EXRS.getIndicator(); + soContentsBytes = EROExplicitExclusionRouteSubobjectParser.put((EROExplicitExclusionRouteSubobject) objToSerialize); + } else if (objToSerialize instanceof EROPathKeyWith32PCEIDSubobject) { + typeIndicator = PCEPSubobjectType.PK_32.getIndicator(); + soContentsBytes = EROPathKeyWith32PCEIDSubobjectParser.put((EROPathKeyWith32PCEIDSubobject) objToSerialize); + } else if (objToSerialize instanceof EROPathKeyWith128PCEIDSubobject) { + typeIndicator = PCEPSubobjectType.PK_128.getIndicator(); + soContentsBytes = EROPathKeyWith128PCEIDSubobjectParser.put((EROPathKeyWith128PCEIDSubobject) objToSerialize); + } else if (objToSerialize instanceof EROProtectionSubobject) { + typeIndicator = PCEPSubobjectType.PROTECTION.getIndicator(); + soContentsBytes = EROProtectionSubobjectParser.put((EROProtectionSubobject) objToSerialize); + } else + throw new IllegalArgumentException("Unknown instance of PCEPSubobject. Passed: " + objToSerialize.getClass() + "."); + + final byte[] bytes = new byte[SO_CONTENTS_OFFSET + soContentsBytes.length]; + + bytes[TYPE_FLAG_F_OFFSET] = (byte) (ByteArray.cutBytes(ByteArray.intToBytes(typeIndicator), (Integer.SIZE / 8) - TYPE_FLAG_F_LENGTH)[0] | (objToSerialize + .isLoose() ? 1 << 7 : 0)); + bytes[LENGTH_F_OFFSET] = ByteArray.cutBytes(ByteArray.intToBytes(soContentsBytes.length + SO_CONTENTS_OFFSET), (Integer.SIZE / 8) - LENGTH_F_LENGTH)[0]; + + System.arraycopy(soContentsBytes, 0, bytes, SO_CONTENTS_OFFSET, soContentsBytes.length); + + return bytes; + } + + private static ExplicitRouteSubobject parseSpecificSubobject(PCEPSubobjectType type, byte[] soContentsBytes, boolean loose_flag) + throws PCEPDeserializerException { + + switch (type) { + case IPv4_PREFIX: + return EROIPv4PrefixSubobjectParser.parse(soContentsBytes, loose_flag); + case IPv6_PREFIX: + return EROIPv6PrefixSubobjectParser.parse(soContentsBytes, loose_flag); + case UNNUMBERED_INTERFACE_ID: + return EROUnnumberedInterfaceSubobjectParser.parse(soContentsBytes, loose_flag); + case AS_NUMBER: + return EROAsNumberSubobjectParser.parse(soContentsBytes, loose_flag); + case LABEL: + return EROLabelSubobjectParser.parse(soContentsBytes, loose_flag); + case EXRS: + return EROExplicitExclusionRouteSubobjectParser.parse(soContentsBytes, loose_flag); + case PK_32: + return EROPathKeyWith32PCEIDSubobjectParser.parse(soContentsBytes, loose_flag); + case PK_128: + return EROPathKeyWith128PCEIDSubobjectParser.parse(soContentsBytes, loose_flag); + case PROTECTION: + return EROProtectionSubobjectParser.parse(soContentsBytes, loose_flag); + default: + throw new PCEPDeserializerException("Unknown Subobject type. Passed: " + type + "."); } + } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageFactory.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageFactory.java index 2191484abe..99ee068964 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageFactory.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageFactory.java @@ -13,6 +13,7 @@ import java.util.List; import org.opendaylight.protocol.framework.DeserializerException; import org.opendaylight.protocol.framework.DocumentedException; import org.opendaylight.protocol.framework.ProtocolMessageFactory; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.RawMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; @@ -33,14 +34,14 @@ public final class PCEPMessageFactory implements ProtocolMessageFactory Preconditions.checkState(msg instanceof RawMessage); final RawMessage raw = (RawMessage) msg; - // try { - // validated.addAll(PCEPMessageValidator.getValidator(raw.getMsgType()).validate(raw.getAllObjects())); - // } catch (final PCEPDeserializerException e) { - // // FIXME: at validation time we may want to terminate with: - // // logger.error("Malformed message, terminating. ", e); - // // this.terminate(Reason.MALFORMED_MSG); - // throw e; - // } + try { + validated.addAll(PCEPMessageValidator.getValidator(raw.getMsgType()).validate(raw.getAllObjects())); + } catch (final PCEPDeserializerException e) { + // FIXME: at validation time we may want to terminate with: + // logger.error("Malformed message, terminating. ", e); + // this.terminate(Reason.MALFORMED_MSG); + throw e; + } } return validated; diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageValidator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageValidator.java new file mode 100644 index 0000000000..eb3b6bb280 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageValidator.java @@ -0,0 +1,66 @@ +/* + * 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.HashMap; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.message.PCCreateMessageValidator; +import org.opendaylight.protocol.pcep.impl.message.PCEPCloseMessageValidator; +import org.opendaylight.protocol.pcep.impl.message.PCEPErrorMessageValidator; +import org.opendaylight.protocol.pcep.impl.message.PCEPKeepAliveMessageValidator; +import org.opendaylight.protocol.pcep.impl.message.PCEPNotificationMessageValidator; +import org.opendaylight.protocol.pcep.impl.message.PCEPOpenMessageValidator; +import org.opendaylight.protocol.pcep.impl.message.PCEPReplyMessageValidator; +import org.opendaylight.protocol.pcep.impl.message.PCEPReportMessageValidator; +import org.opendaylight.protocol.pcep.impl.message.PCEPRequestMessageValidator; +import org.opendaylight.protocol.pcep.impl.message.PCEPUpdateRequestMessageValidator; +import org.opendaylight.protocol.pcep.spi.PCEPMessageType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; + +/** + * Base class for message validators + */ +public abstract class PCEPMessageValidator { + + private static class MapOfValidators extends HashMap { + + private static final long serialVersionUID = -5715193806554448822L; + + private final static MapOfValidators instance = new MapOfValidators(); + + private MapOfValidators() { + this.fillInMap(); + } + + private void fillInMap() { + this.put(PCEPMessageType.OPEN, new PCEPOpenMessageValidator()); + this.put(PCEPMessageType.KEEPALIVE, new PCEPKeepAliveMessageValidator()); + this.put(PCEPMessageType.NOTIFICATION, new PCEPNotificationMessageValidator()); + this.put(PCEPMessageType.ERROR, new PCEPErrorMessageValidator()); + this.put(PCEPMessageType.RESPONSE, new PCEPReplyMessageValidator()); + this.put(PCEPMessageType.REQUEST, new PCEPRequestMessageValidator()); + this.put(PCEPMessageType.UPDATE_REQUEST, new PCEPUpdateRequestMessageValidator()); + this.put(PCEPMessageType.STATUS_REPORT, new PCEPReportMessageValidator()); + this.put(PCEPMessageType.CLOSE, new PCEPCloseMessageValidator()); + this.put(PCEPMessageType.PCCREATE, new PCCreateMessageValidator()); + } + + public static MapOfValidators getInstance() { + return instance; + } + } + + public abstract List validate(List objects) throws PCEPDeserializerException; + + public static PCEPMessageValidator getValidator(final PCEPMessageType msgType) { + return MapOfValidators.getInstance().get(msgType); + } +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPObjectFactory.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPObjectFactory.java new file mode 100644 index 0000000000..6ceecbdc33 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPObjectFactory.java @@ -0,0 +1,330 @@ +/* + * 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.Arrays; +import java.util.HashMap; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.concepts.IPv6Address; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectIdentifier.ObjectClass; +import org.opendaylight.protocol.pcep.impl.object.PCEPBranchNodeListObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPCloseObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsIPv4ObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsIPv6ObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPExcludeRouteObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPExistingPathBandwidthObjectParser; +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.PCEPNonBranchNodeListObjectParser; +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.PCEPP2MPEndPointsIPv4ObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPP2MPEndPointsIPv6ObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPReportedRouteObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPRequestedPathBandwidthObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPSecondaryExplicitRouteObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPSecondaryRecordRouteObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPUnreachedIPv4DestinationObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPUnreachedIPv6DestinationObjectParser; +import org.opendaylight.protocol.pcep.impl.object.UnknownObject; +import org.opendaylight.protocol.pcep.object.PCEPBranchNodeListObject; +import org.opendaylight.protocol.pcep.object.PCEPBranchNodeObject; +import org.opendaylight.protocol.pcep.object.PCEPCloseObject; +import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPExcludeRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPExistingPathBandwidthObject; +import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPGlobalConstraintsObject; +import org.opendaylight.protocol.pcep.object.PCEPIncludeRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPLoadBalancingObject; +import org.opendaylight.protocol.pcep.object.PCEPLspObject; +import org.opendaylight.protocol.pcep.object.PCEPLspaObject; +import org.opendaylight.protocol.pcep.object.PCEPMetricObject; +import org.opendaylight.protocol.pcep.object.PCEPNoPathObject; +import org.opendaylight.protocol.pcep.object.PCEPNonBranchNodeListObject; +import org.opendaylight.protocol.pcep.object.PCEPNotificationObject; +import org.opendaylight.protocol.pcep.object.PCEPObjectiveFunctionObject; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; +import org.opendaylight.protocol.pcep.object.PCEPP2MPEndPointsObject; +import org.opendaylight.protocol.pcep.object.PCEPReportedRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject; +import org.opendaylight.protocol.pcep.object.PCEPSecondaryExplicitRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPSecondaryRecordRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPSvecObject; +import org.opendaylight.protocol.pcep.object.PCEPUnreachedDestinationObject; + +/** + * Factory for subclasses of {@link org.opendaylight.protocol.pcep.PCEPObject PCEPObject} + */ +public class PCEPObjectFactory { + + private static final Logger logger = LoggerFactory.getLogger(PCEPObjectFactory.class); + + /** + * Map of parsers for subobjects of {@link org.opendaylight.protocol.pcep.PCEPObject + * PCEPObject} + */ + private static class MapOfParsers extends HashMap { + private static final long serialVersionUID = 1L; + + private final static MapOfParsers instance = new MapOfParsers(); + + private MapOfParsers() { + this.fillInMap(); + } + + private void fillInMap() { + this.put(new PCEPObjectIdentifier(ObjectClass.OPEN, 1), new PCEPOpenObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.RP, 1), new PCEPRequestParameterObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.NO_PATH, 1), new PCEPNoPathObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.BANDWIDTH, 1), new PCEPRequestedPathBandwidthObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.BANDWIDTH, 2), new PCEPExistingPathBandwidthObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.METRIC, 1), new PCEPMetricObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.END_POINTS, 1), new PCEPEndPointsIPv4ObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.END_POINTS, 2), new PCEPEndPointsIPv6ObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.LSPA, 1), new PCEPLspaObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.SVEC, 1), new PCEPSvecObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.NOTIFICATION, 1), new PCEPNotificationObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.ERROR, 1), new PCEPErrorObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.CLOSE, 1), new PCEPCloseObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.LOAD_BALANCING, 1), new PCEPLoadBalancingObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.LSP, 1), new PCEPLspObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.ERO, 1), new PCEPExplicitRouteObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.RRO, 1), new PCEPReportedRouteObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.IRO, 1), new PCEPIncludeRouteObjectParser()); + + /* GCO extension */ + this.put(new PCEPObjectIdentifier(ObjectClass.XRO, 1), new PCEPExcludeRouteObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.OBJCETIVE_FUNCTION, 1), new PCEPObjectiveFunctionObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.GLOBAL_CONSTRAINTS, 1), new PCEPGlobalConstraintsObjectParser()); + + /* RFC6006 */ + this.put(new PCEPObjectIdentifier(ObjectClass.END_POINTS, 3), new PCEPP2MPEndPointsIPv4ObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.END_POINTS, 4), new PCEPP2MPEndPointsIPv6ObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.UNREACHED_DESTINATION, 1), new PCEPUnreachedIPv4DestinationObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.UNREACHED_DESTINATION, 2), new PCEPUnreachedIPv6DestinationObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.SERO, 1), new PCEPSecondaryExplicitRouteObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.SRRO, 1), new PCEPSecondaryRecordRouteObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.BRANCH_NODE, 1), new PCEPBranchNodeListObjectParser()); + this.put(new PCEPObjectIdentifier(ObjectClass.BRANCH_NODE, 2), new PCEPNonBranchNodeListObjectParser()); + } + + public static MapOfParsers getInstance() { + return instance; + } + } + + private static PCEPObject parse(final byte[] bytes, final PCEPObjectHeader header) throws PCEPDocumentedException, PCEPDeserializerException { + if (bytes == null) + throw new IllegalArgumentException("Array of bytes is mandatory."); + if (header == null) + throw new IllegalArgumentException("PCEPObjectHeader is mandatory."); + + logger.trace("Attempt to parse object from bytes: {}", ByteArray.bytesToHexString(bytes)); + + /* + * if PCEPObjectIdentifier.getObjectClassFromInt() don't throws + * exception and if Map.get() returns null, we know that we can't + * recognize OBJ TYPE. + */ + final PCEPObjectParser objParserClass = MapOfParsers.getInstance().get( + new PCEPObjectIdentifier(PCEPObjectIdentifier.ObjectClass.getFromInt(header.objClass), header.objType)); + if (objParserClass == null) { + logger.debug("Object could not be parsed. Header: {}. Body bytes: {}", header, Arrays.toString(bytes)); + throw new PCEPDocumentedException("Unrecognized object type: " + header.objType + " for object class: " + header.objClass, + PCEPErrors.UNRECOGNIZED_OBJ_TYPE); + } + final PCEPObject obj = objParserClass.parse(bytes, header.processed, header.ignored); + logger.trace("Object was parsed. {}", obj); + return obj; + } + + public static List parseObjects(final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException { + int offset = 0; + final List objs = new ArrayList(); + + while (bytes.length - offset > 0) { + if (bytes.length - offset < PCEPObjectHeader.COMMON_OBJECT_HEADER_LENGTH) + throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + (bytes.length - offset) + " Expected: >= " + + PCEPObjectHeader.COMMON_OBJECT_HEADER_LENGTH + "."); + + final PCEPObjectHeader header = PCEPObjectHeader.parseHeader(Arrays.copyOfRange(bytes, offset, offset + + PCEPObjectHeader.COMMON_OBJECT_HEADER_LENGTH)); + + if (bytes.length - offset < header.objLength) + throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + (bytes.length - offset) + " Expected: >= " + header.objLength + + "."); + + // copy bytes for deeper parsing + final byte[] bytesToPass = ByteArray.subByte(bytes, offset + PCEPObjectHeader.COMMON_OBJECT_HEADER_LENGTH, header.objLength + - PCEPObjectHeader.COMMON_OBJECT_HEADER_LENGTH); + + offset += header.objLength; + + // if obj is not-supported or unrecognized and p flag si set + // adds UnknownObject to list for validation purposes + try { + objs.add(PCEPObjectFactory.parse(bytesToPass, header)); + } catch (final PCEPDocumentedException e) { + if (e.getError() == PCEPErrors.UNRECOGNIZED_OBJ_CLASS | e.getError() == PCEPErrors.UNRECOGNIZED_OBJ_TYPE + | e.getError() == PCEPErrors.NOT_SUPPORTED_OBJ_CLASS | e.getError() == PCEPErrors.NOT_SUPPORTED_OBJ_TYPE) { + objs.add(new UnknownObject(header.processed, header.ignored, e.getError())); + } else { + throw e; + } + } + } + + return objs; + } + + public static byte[] put(final List objects) { + if (objects == null || objects.isEmpty()) + throw new IllegalArgumentException("List is mandatory and can't be empty."); + + final List listBytes = new ArrayList(); + + byte[] bytes; + int size = 0; + for (final PCEPObject obj : objects) { + bytes = put(obj); + size += bytes.length; + listBytes.add(bytes); + } + + final byte[] retBytes = new byte[size]; + + int offset = 0; + for (final byte[] bs : listBytes) { + ByteArray.copyWhole(bs, retBytes, offset); + offset += bs.length; + } + + return retBytes; + } + + private static byte[] put(final PCEPObject obj) { + + byte[] objBody; + ObjectClass objClass; + int objType = 1; + + if (obj instanceof PCEPOpenObject) { + objClass = PCEPObjectIdentifier.ObjectClass.OPEN; + } else if (obj instanceof PCEPRequestParameterObject) { + objClass = PCEPObjectIdentifier.ObjectClass.RP; + } else if (obj instanceof PCEPNoPathObject) { + objClass = PCEPObjectIdentifier.ObjectClass.NO_PATH; + } else if (obj instanceof PCEPRequestedPathBandwidthObject) { + objClass = PCEPObjectIdentifier.ObjectClass.BANDWIDTH; + } else if (obj instanceof PCEPExistingPathBandwidthObject) { + objClass = PCEPObjectIdentifier.ObjectClass.BANDWIDTH; + objType = 2; + } else if (obj instanceof PCEPMetricObject) { + objClass = PCEPObjectIdentifier.ObjectClass.METRIC; + } else if (obj instanceof PCEPEndPointsObject) { + objClass = PCEPObjectIdentifier.ObjectClass.END_POINTS; + if (((PCEPEndPointsObject) obj).getSourceAddress() instanceof IPv6Address) { + objType = 2; + } else if (!(((PCEPEndPointsObject) obj).getSourceAddress() instanceof IPv4Address)) + throw new IllegalArgumentException("Unknown instance of Source Address."); + + } else if (obj instanceof PCEPP2MPEndPointsObject) { + objClass = PCEPObjectIdentifier.ObjectClass.END_POINTS; + objType = 3; + if (((PCEPP2MPEndPointsObject) obj).getSourceAddress() instanceof IPv6Address) { + objType = 4; + } else if (!(((PCEPP2MPEndPointsObject) obj).getSourceAddress() instanceof IPv4Address)) + throw new IllegalArgumentException("Unknown instance of Source Address."); + + } else if (obj instanceof PCEPUnreachedDestinationObject) { + objClass = PCEPObjectIdentifier.ObjectClass.UNREACHED_DESTINATION; + if (((PCEPUnreachedDestinationObject) obj).getUnreachedDestinations().get(0) instanceof IPv6Address) { + objType = 2; + } else if (!(((PCEPUnreachedDestinationObject) obj).getUnreachedDestinations().get(0) instanceof IPv4Address)) + throw new IllegalArgumentException("Unknown instance of Source Address."); + + } else if (obj instanceof PCEPLspaObject) { + objClass = PCEPObjectIdentifier.ObjectClass.LSPA; + } else if (obj instanceof PCEPSvecObject) { + objClass = PCEPObjectIdentifier.ObjectClass.SVEC; + objType = 1; + } else if (obj instanceof PCEPNotificationObject) { + objClass = PCEPObjectIdentifier.ObjectClass.NOTIFICATION; + } else if (obj instanceof PCEPErrorObject) { + objClass = PCEPObjectIdentifier.ObjectClass.ERROR; + } else if (obj instanceof PCEPCloseObject) { + objClass = PCEPObjectIdentifier.ObjectClass.CLOSE; + } else if (obj instanceof PCEPLoadBalancingObject) { + objClass = PCEPObjectIdentifier.ObjectClass.LOAD_BALANCING; + } else if (obj instanceof PCEPLspObject) { + objClass = PCEPObjectIdentifier.ObjectClass.LSP; + } else if (obj instanceof PCEPExplicitRouteObject) { + objClass = PCEPObjectIdentifier.ObjectClass.ERO; + } else if (obj instanceof PCEPReportedRouteObject) { + objClass = PCEPObjectIdentifier.ObjectClass.RRO; + } else if (obj instanceof PCEPIncludeRouteObject) { + objClass = PCEPObjectIdentifier.ObjectClass.IRO; + } else if (obj instanceof PCEPExcludeRouteObject) { + objClass = PCEPObjectIdentifier.ObjectClass.XRO; + } else if (obj instanceof PCEPObjectiveFunctionObject) { + objClass = PCEPObjectIdentifier.ObjectClass.OBJCETIVE_FUNCTION; + } else if (obj instanceof PCEPGlobalConstraintsObject) { + objClass = PCEPObjectIdentifier.ObjectClass.GLOBAL_CONSTRAINTS; + } else if (obj instanceof PCEPBranchNodeObject) { + objClass = PCEPObjectIdentifier.ObjectClass.BRANCH_NODE; + if (obj instanceof PCEPNonBranchNodeListObject) { + objType = 2; + } else if (!(obj instanceof PCEPBranchNodeListObject)) + throw new IllegalArgumentException("Unknown instance of PCEPBranchNodeObject."); + } else if (obj instanceof PCEPSecondaryExplicitRouteObject) { + objClass = PCEPObjectIdentifier.ObjectClass.SERO; + } else if (obj instanceof PCEPSecondaryRecordRouteObject) { + objClass = PCEPObjectIdentifier.ObjectClass.SRRO; + } else + throw new IllegalArgumentException("Unknown instance of PCEPObject."); + + final PCEPObjectParser objParserClass = MapOfParsers.getInstance().get(new PCEPObjectIdentifier(objClass, objType)); + objBody = objParserClass.put(obj); + + final byte[] objHeader = PCEPObjectHeader.putHeader(new PCEPObjectHeader(objClass.getIdentifier(), objType, objBody.length + + PCEPObjectHeader.COMMON_OBJECT_HEADER_LENGTH, obj.isProcessed(), obj.isIgnored())); + + assert objBody.length % 4 == 0 : "Wrong length of PCEPObjectBody. Passed object has length: " + objBody.length + " that is not multiple of 4."; + + final byte[] retBytes = new byte[objHeader.length + objBody.length]; + ByteArray.copyWhole(objHeader, retBytes, 0); + ByteArray.copyWhole(objBody, retBytes, PCEPObjectHeader.OBJ_BODY_OFFSET); + + return retBytes; + } +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPObjectHeader.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPObjectHeader.java new file mode 100644 index 0000000000..718436a42b --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPObjectHeader.java @@ -0,0 +1,174 @@ +/* + * 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 java.util.BitSet; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.opendaylight.protocol.util.ByteArray; +import com.google.common.primitives.UnsignedBytes; + +/** + * Header parser for {@link org.opendaylight.protocol.pcep.PCEPObject PCEPObject} + */ +public class PCEPObjectHeader { + + private static final Logger logger = LoggerFactory.getLogger(PCEPObjectHeader.class); + + /* + * Common object header fields lengths in bytes + */ + public final static int OC_F_LENGTH = 1; + public final static int OT_FLAGS_MF_LENGTH = 1; // multi-field + public final static int OBJ_LENGTH_F_LENGTH = 2; + + /* + * size of fields inside of multi-filed in bits + */ + public final static int OT_SF_LENGTH = 4; + public final static int FLAGS_SF_LENGTH = 4; + + /* + * offsets of fields inside of multi-field in bits + */ + public final static int OT_SF_OFFSET = 0; + public final static int FLAGS_SF_OFFSET = OT_SF_OFFSET + OT_SF_LENGTH; + + /* + * flags offsets inside multi-filed + */ + public final static int P_FLAG_OFFSET = 6; + public final static int I_FLAG_OFFSET = 7; + + /* + * Common object header fields offsets in bytes; + */ + public final static int OC_F_OFFSET = 0; + public final static int OT_FLAGS_MF_OFFSET = OC_F_OFFSET + OC_F_LENGTH; + public final static int OBJ_LENGTH_F_OFFSET = OT_FLAGS_MF_OFFSET + OT_FLAGS_MF_LENGTH; + public final static int OBJ_BODY_OFFSET = OBJ_LENGTH_F_OFFSET + OBJ_LENGTH_F_LENGTH; + + /* + * Common object header length in bytes + */ + public final static int COMMON_OBJECT_HEADER_LENGTH = (OC_F_LENGTH + OT_FLAGS_MF_LENGTH + OBJ_LENGTH_F_LENGTH); + + public final int objClass; + public final int objType; + public final int objLength; + public final boolean processed; + public final boolean ignored; + + public PCEPObjectHeader(final int objClass, final int objType, final int objLength, final boolean processed, final boolean ignore) { + this.objClass = objClass; + this.objType = objType; + this.objLength = objLength; + this.processed = processed; + this.ignored = ignore; + + } + + public static PCEPObjectHeader parseHeader(final byte[] bytes) { + if (bytes == null) + throw new IllegalArgumentException("Array of bytes is mandatory."); + + logger.trace("Attempt to parse object header from bytes: {}", ByteArray.bytesToHexString(bytes)); + + final int objClass = ByteArray.bytesToInt(Arrays.copyOfRange(bytes, OC_F_OFFSET, OC_F_OFFSET + OC_F_LENGTH)); + + final int objType = UnsignedBytes.toInt(ByteArray.copyBitsRange(bytes[OT_FLAGS_MF_OFFSET], OT_SF_OFFSET, OT_SF_LENGTH)); + + final int objLength = ByteArray.bytesToInt(Arrays.copyOfRange(bytes, OBJ_LENGTH_F_OFFSET, OBJ_LENGTH_F_OFFSET + OBJ_LENGTH_F_LENGTH)); + + final byte[] flagsBytes = { ByteArray.copyBitsRange(bytes[OT_FLAGS_MF_OFFSET], FLAGS_SF_OFFSET, FLAGS_SF_LENGTH) }; + + final BitSet flags = ByteArray.bytesToBitSet(flagsBytes); + + final PCEPObjectHeader objHeader = new PCEPObjectHeader(objClass, objType, objLength, flags.get(P_FLAG_OFFSET), flags.get(I_FLAG_OFFSET)); + logger.trace("Object header was parsed. {}", objHeader); + return objHeader; + } + + public static byte[] putHeader(final PCEPObjectHeader header) { + if (header == null) + throw new IllegalArgumentException("PCEPObjectHeader is mandatory."); + + final byte[] retBytes = new byte[COMMON_OBJECT_HEADER_LENGTH]; + + // objClass + retBytes[OC_F_OFFSET] = (byte) header.objClass; + + // objType_flags multi-field + retBytes[OT_FLAGS_MF_OFFSET] = (byte) (header.objType << (Byte.SIZE - OT_SF_LENGTH)); + if (header.processed) + retBytes[OT_FLAGS_MF_OFFSET] |= 1 << Byte.SIZE - (P_FLAG_OFFSET) - 1; + if (header.ignored) + retBytes[OT_FLAGS_MF_OFFSET] |= 1 << Byte.SIZE - (I_FLAG_OFFSET) - 1; + + // objLength + System.arraycopy(ByteArray.intToBytes(header.objLength), Integer.SIZE / Byte.SIZE - OBJ_LENGTH_F_LENGTH, retBytes, OBJ_LENGTH_F_OFFSET, + OBJ_LENGTH_F_LENGTH); + + return retBytes; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("PCEPObjectHeader [objClass="); + builder.append(this.objClass); + builder.append(", objType="); + builder.append(this.objType); + builder.append(", objLength="); + builder.append(this.objLength); + builder.append(", processed="); + builder.append(this.processed); + builder.append(", ignored="); + builder.append(this.ignored); + builder.append("]"); + return builder.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (this.ignored ? 1231 : 1237); + result = prime * result + this.objClass; + result = prime * result + this.objLength; + result = prime * result + this.objType; + result = prime * result + (this.processed ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPObjectHeader other = (PCEPObjectHeader) obj; + if (this.ignored != other.ignored) + return false; + if (this.objClass != other.objClass) + return false; + if (this.objLength != other.objLength) + return false; + if (this.objType != other.objType) + return false; + if (this.processed != other.processed) + return false; + return true; + } + +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParser.java new file mode 100644 index 0000000000..4e92586e92 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParser.java @@ -0,0 +1,21 @@ +/* + * 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.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPObject; + +/** + * Interface for {@link org.opendaylight.protocol.pcep.PCEPObject PCEPObject} subobjects + */ +public interface PCEPObjectParser { + public abstract PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException, PCEPDocumentedException; + + public abstract byte[] put(PCEPObject obj); +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java index 47cc916f8b..2480d62f64 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionImpl.java @@ -14,8 +14,10 @@ import io.netty.util.TimerTask; import java.io.IOException; import java.net.InetSocketAddress; +import java.util.ArrayList; import java.util.Date; import java.util.LinkedList; +import java.util.List; import java.util.Queue; import java.util.concurrent.TimeUnit; @@ -24,15 +26,17 @@ import org.opendaylight.protocol.pcep.PCEPCloseTermination; import org.opendaylight.protocol.pcep.PCEPErrors; import org.opendaylight.protocol.pcep.PCEPSession; 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.message.rev131007.CloseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseMessage; +import org.opendaylight.protocol.pcep.PCEPTlv; +import org.opendaylight.protocol.pcep.message.PCEPCloseMessage; +import org.opendaylight.protocol.pcep.message.PCEPErrorMessage; +import org.opendaylight.protocol.pcep.message.PCEPOpenMessage; +import org.opendaylight.protocol.pcep.object.PCEPCloseObject; +import org.opendaylight.protocol.pcep.object.PCEPCloseObject.Reason; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; +import org.opendaylight.protocol.pcep.tlv.NodeIdentifierTlv; 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.Message; -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.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.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,12 +73,12 @@ public class PCEPSessionImpl extends AbstractProtocolSession implements /** * Open Object with session characteristics that were accepted by another PCE (sent from this session). */ - private final OpenObject localOpen; + private final PCEPOpenObject localOpen; /** * Open Object with session characteristics for this session (sent from another PCE). */ - private final OpenObject remoteOpen; + private final PCEPOpenObject remoteOpen; private static final Logger logger = LoggerFactory.getLogger(PCEPSessionImpl.class); @@ -95,7 +99,7 @@ public class PCEPSessionImpl extends AbstractProtocolSession implements private final KeepaliveMessage kaMessage = (KeepaliveMessage) new KeepaliveMessageBuilder().build(); PCEPSessionImpl(final Timer timer, final PCEPSessionListener listener, final int maxUnknownMessages, final Channel channel, - final OpenObject localOpen, final OpenObject remoteOpen) { + final PCEPOpenObject localOpen, final PCEPOpenObject remoteOpen) { this.listener = Preconditions.checkNotNull(listener); this.stateTimer = Preconditions.checkNotNull(timer); this.channel = Preconditions.checkNotNull(channel); @@ -142,7 +146,7 @@ public class PCEPSessionImpl extends AbstractProtocolSession implements if (this.channel.isActive()) { if (ct >= nextDead) { logger.debug("DeadTimer expired. " + new Date()); - this.terminate(TerminationReason.ExpDeadtimer); + this.terminate(Reason.EXP_DEADTIMER); } else { this.stateTimer.newTimeout(new TimerTask() { @Override @@ -214,19 +218,19 @@ public class PCEPSessionImpl extends AbstractProtocolSession implements * inside the session or from the listener, therefore the parent of this session should be informed. */ @Override - public synchronized void close(final TerminationReason reason) { + public synchronized void close(final PCEPCloseObject.Reason reason) { logger.debug("Closing session: {}", this); this.closed = true; - this.sendMessage(new CloseBuilder().setCCloseMessage( - new CCloseMessageBuilder().setCClose(new CCloseBuilder().setReason(reason.getShortValue()).build()).build()).build()); + // FIXME: just to get rid of compilation errors + this.sendMessage((Message) new PCEPCloseMessage(new PCEPCloseObject(reason))); this.channel.close(); } - private synchronized void terminate(final TerminationReason reason) { + private synchronized void terminate(final PCEPCloseObject.Reason reason) { this.listener.onSessionTerminated(this, new PCEPCloseTermination(reason)); this.closed = true; - this.sendMessage(new CloseBuilder().setCCloseMessage( - new CCloseMessageBuilder().setCClose(new CCloseBuilder().setReason(reason.getShortValue()).build()).build()).build()); + // FIXME: just to get rid of compilation errors + this.sendMessage((Message) new PCEPCloseMessage(new PCEPCloseObject(reason))); this.close(); } @@ -248,8 +252,12 @@ public class PCEPSessionImpl extends AbstractProtocolSession implements * @param value * @param open */ - private void sendErrorMessage(final PCEPErrors value, final OpenObject open) { - this.sendMessage(Util.createErrorMessage(value, open)); + private void sendErrorMessage(final PCEPErrors value, final PCEPOpenObject open) { + final PCEPErrorObject error = new PCEPErrorObject(value); + final List errors = new ArrayList(); + errors.add(error); + // FIXME: just to get rid of compilation errors + this.sendMessage((Message) new PCEPErrorMessage(open, errors, null)); } /** @@ -270,7 +278,7 @@ public class PCEPSessionImpl extends AbstractProtocolSession implements this.unknownMessagesTimes.poll(); } if (this.unknownMessagesTimes.size() > this.maxUnknownMessages) { - this.terminate(TerminationReason.TooManyUnknownMsg); + this.terminate(Reason.TOO_MANY_UNKNOWN_MSG); } } } @@ -290,9 +298,9 @@ public class PCEPSessionImpl extends AbstractProtocolSession implements // Internal message handling. The user does not see these messages if (msg instanceof KeepaliveMessage) { // Do nothing, the timer has been already reset - } else if (msg instanceof OpenMessage) { + } else if (msg instanceof PCEPOpenMessage) { this.sendErrorMessage(PCEPErrors.ATTEMPT_2ND_SESSION); - } else if (msg instanceof CloseMessage) { + } else if (msg instanceof PCEPCloseMessage) { /* * Session is up, we are reporting all messages to user. One notable * exception is CLOSE message, which needs to be converted into a @@ -325,12 +333,12 @@ public class PCEPSessionImpl extends AbstractProtocolSession implements @Override public Integer getDeadTimerValue() { - return new Integer(this.remoteOpen.getDeadTimer()); + return this.remoteOpen.getDeadTimerValue(); } @Override public Integer getKeepAliveTimerValue() { - return new Integer(this.localOpen.getKeepalive()); + return this.localOpen.getKeepAliveTimerValue(); } @Override @@ -344,6 +352,16 @@ public class PCEPSessionImpl extends AbstractProtocolSession implements this.close(); } + @Override + public String getNodeIdentifier() { + for (final PCEPTlv tlv : this.remoteOpen.getTlvs()) { + if (tlv instanceof NodeIdentifierTlv) { + return tlv.toString(); + } + } + return ""; + } + @Override public final String toString() { return addToStringAttributes(Objects.toStringHelper(this)).toString(); @@ -359,14 +377,4 @@ public class PCEPSessionImpl extends AbstractProtocolSession implements protected void sessionUp() { this.listener.onSessionUp(this); } - - @Override - public String getNodeIdentifier() { - 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/PCEPSessionProposalFactoryImpl.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionProposalFactoryImpl.java index 79b623f59e..d996e23be1 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionProposalFactoryImpl.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPSessionProposalFactoryImpl.java @@ -8,14 +8,14 @@ package org.opendaylight.protocol.pcep.impl; import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.List; import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory; -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.StatefulCapabilityTlv.Flags; -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.Tlvs; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.TlvsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.StatefulBuilder; +import org.opendaylight.protocol.pcep.PCEPTlv; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; +import org.opendaylight.protocol.pcep.tlv.LSPCleanupTlv; +import org.opendaylight.protocol.pcep.tlv.PCEStatefulCapabilityTlv; public class PCEPSessionProposalFactoryImpl implements PCEPSessionProposalFactory { @@ -23,8 +23,7 @@ public class PCEPSessionProposalFactoryImpl implements PCEPSessionProposalFactor private final boolean stateful, active, versioned, instant; - public PCEPSessionProposalFactoryImpl(final int deadTimer, final int keepAlive, final boolean stateful, final boolean active, - final boolean versioned, final boolean instant, final int timeout) { + public PCEPSessionProposalFactoryImpl(final int deadTimer, final int keepAlive, final boolean stateful, final boolean active, final boolean versioned, final boolean instant, final int timeout) { this.deadTimer = deadTimer; this.keepAlive = keepAlive; this.stateful = stateful; @@ -35,14 +34,16 @@ public class PCEPSessionProposalFactoryImpl implements PCEPSessionProposalFactor } @Override - public OpenObject getSessionProposal(final InetSocketAddress address, final int sessionId) { - final Tlvs tlvs = null; - final TlvsBuilder builder = new TlvsBuilder(); + public PCEPOpenObject getSessionProposal(final InetSocketAddress address, final int sessionId) { + List tlvs = null; if (PCEPSessionProposalFactoryImpl.this.stateful) { - builder.setStateful((new StatefulBuilder().setFlags(new Flags(PCEPSessionProposalFactoryImpl.this.versioned, PCEPSessionProposalFactoryImpl.this.instant, PCEPSessionProposalFactoryImpl.this.active)).build())); + tlvs = new ArrayList(); + tlvs.add(new PCEStatefulCapabilityTlv(PCEPSessionProposalFactoryImpl.this.instant, PCEPSessionProposalFactoryImpl.this.active, PCEPSessionProposalFactoryImpl.this.versioned)); + if (PCEPSessionProposalFactoryImpl.this.instant) { + tlvs.add(new LSPCleanupTlv(PCEPSessionProposalFactoryImpl.this.timeout)); + } } - return new OpenBuilder().setKeepalive((short) PCEPSessionProposalFactoryImpl.this.keepAlive).setDeadTimer( - (short) PCEPSessionProposalFactoryImpl.this.deadTimer).setSessionId((short) sessionId).setTlvs(tlvs).build(); + return new PCEPOpenObject(PCEPSessionProposalFactoryImpl.this.keepAlive, PCEPSessionProposalFactoryImpl.this.deadTimer, sessionId, tlvs); } public int getKeepAlive() { diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParser.java new file mode 100644 index 0000000000..99a77405f4 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParser.java @@ -0,0 +1,294 @@ +/* + * 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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.concepts.IPv6Address; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPTlv; +import org.opendaylight.protocol.pcep.concepts.LSPSymbolicName; +import org.opendaylight.protocol.pcep.impl.tlv.LSPIdentifierIPv4TlvParser; +import org.opendaylight.protocol.pcep.impl.tlv.LSPIdentifierIPv6TlvParser; +import org.opendaylight.protocol.pcep.impl.tlv.NoPathVectorTlvParser; +import org.opendaylight.protocol.pcep.impl.tlv.OFListTlvParser; +import org.opendaylight.protocol.pcep.impl.tlv.PCEStatefulCapabilityTlvParser; +import org.opendaylight.protocol.pcep.impl.tlv.RSVPErrorSpecIPv4TlvParser; +import org.opendaylight.protocol.pcep.impl.tlv.RSVPErrorSpecIPv6TlvParser; +import org.opendaylight.protocol.pcep.tlv.IPv4LSPIdentifiersTlv; +import org.opendaylight.protocol.pcep.tlv.IPv6LSPIdentifiersTlv; +import org.opendaylight.protocol.pcep.tlv.LSPCleanupTlv; +import org.opendaylight.protocol.pcep.tlv.LSPStateDBVersionTlv; +import org.opendaylight.protocol.pcep.tlv.LSPSymbolicNameTlv; +import org.opendaylight.protocol.pcep.tlv.LSPUpdateErrorTlv; +import org.opendaylight.protocol.pcep.tlv.NoPathVectorTlv; +import org.opendaylight.protocol.pcep.tlv.NodeIdentifierTlv; +import org.opendaylight.protocol.pcep.tlv.OFListTlv; +import org.opendaylight.protocol.pcep.tlv.OrderTlv; +import org.opendaylight.protocol.pcep.tlv.OverloadedDurationTlv; +import org.opendaylight.protocol.pcep.tlv.P2MPCapabilityTlv; +import org.opendaylight.protocol.pcep.tlv.PCEStatefulCapabilityTlv; +import org.opendaylight.protocol.pcep.tlv.RSVPErrorSpecTlv; +import org.opendaylight.protocol.pcep.tlv.ReqMissingTlv; + +/** + * Parser for {@link org.opendaylight.protocol.pcep.PCEPTlv PCEPTlv} and its subclasses + */ +public final class PCEPTlvParser { + + private static final Logger logger = LoggerFactory.getLogger(PCEPTlvParser.class); + + /** + * Type indicator for {@link org.opendaylight.protocol.pcep.PCEPTlv PCEPTlv} + */ + private enum PCEPTlvType { + NO_PATH_VECTOR(1), + OVERLOADED_DURATION(2), + REQ_MISSING(3), + OF_LIST_TLV(4), + ORDER_TLV(5), + P2MP_CAPABILITY(6), + PCE_STATEFUL_CAPABILITY(16), + LSP_SYMBOLIC_NAME(17), + LSP_IDENTIFIER_IPV4(18), + LSP_IDENTIFIER_IPV6(19), + LSP_UPDATE_ERROR(20), + RSVP_ERROR_SPEC_IPV4(21), + RSVP_ERROR_SPEC_IPV6(22), + LSP_STATE_DB_VERSION(23), + // TODO: use IANA defined number - for now has been used first unused + // number + NODE_IDENTIFIER(24), + LSP_CLEANUP_TLV(26); + + private final int indicator; + + PCEPTlvType(final int indicator) { + this.indicator = indicator; + } + + public int getIndicator() { + return this.indicator; + } + + public static PCEPTlvType getFromInt(final int type) throws PCEPDeserializerException { + + for (final PCEPTlvType type_e : PCEPTlvType.values()) { + if (type_e.getIndicator() == type) + return type_e; + } + + throw new PCEPDeserializerException("Unknown TLV type: " + type); + } + } + + /* + * Fields lengths in Bytes + */ + public static final int TYPE_F_LENGTH = 2; + public static final int LENGTH_F_LENGTH = 2; + public static final int HEADER_LENGTH = LENGTH_F_LENGTH + TYPE_F_LENGTH; + + /* + * Fields offsets in Bytes + */ + public static final int TYPE_F_OFFSET = 0; + public static final int LENGTH_F_OFFSET = TYPE_F_OFFSET + TYPE_F_LENGTH; + public static final int VALUE_F_OFFSET = LENGTH_F_OFFSET + LENGTH_F_LENGTH; + + /* + * padding of value field in bytes + */ + public static final int PADDED_TO = 4; + + /* + * constants for specific one-value tlvs + */ + private static final int DBV_F_LENGTH = 8; + private static final int OVERLOADED_DURATION_LENGTH = 4; + private static final int UPDATE_ERR_CODE_LENGTH = 4; + private static final int REQ_ID_LENGTH = 4; + private static final int ORDR_DEL_LENGTH = 4; + private static final int ORDR_SETUP_LENGTH = 4; + private static final int P2MP_CAPABLITY_LENGTH = 2; + + public static List parse(final byte[] bytes) throws PCEPDeserializerException { + if (bytes == null) + throw new IllegalArgumentException("Byte array is mandatory."); + + final List tlvList = new ArrayList(); + PCEPTlvType type; + int length; + int offset = 0; + + while (offset + HEADER_LENGTH < bytes.length) { + + length = ByteArray.bytesToInt(ByteArray.subByte(bytes, offset + LENGTH_F_OFFSET, LENGTH_F_LENGTH)); + + type = PCEPTlvType.getFromInt(ByteArray.bytesToInt(ByteArray.subByte(bytes, offset + TYPE_F_OFFSET, TYPE_F_LENGTH))); + + if (HEADER_LENGTH + length > bytes.length - offset) + throw new PCEPDeserializerException("Wrong length specified. Passed: " + (HEADER_LENGTH + length) + "; Expected: <= " + (bytes.length - offset) + + "."); + + final byte[] tlvBytes = ByteArray.subByte(bytes, offset + VALUE_F_OFFSET, length); + + logger.trace("Attempt to parse tlv from bytes: {}", ByteArray.bytesToHexString(tlvBytes)); + final PCEPTlv tlv = parseSpecificTLV(type, tlvBytes); + logger.trace("Tlv was parsed. {}", tlv); + + tlvList.add(tlv); + + offset += HEADER_LENGTH + length + Util.getPadding(HEADER_LENGTH + length, PADDED_TO); + } + + return tlvList; + } + + public static byte[] put(final List objsToSerialize) { + final List bytesList = new ArrayList(objsToSerialize.size()); + + int length = 0; + for (final PCEPTlv obj : objsToSerialize) { + final byte[] bytes = put(obj); + length += bytes.length; + bytesList.add(bytes); + } + + final byte[] retBytes = new byte[length]; + + int offset = 0; + for (final byte[] bytes : bytesList) { + System.arraycopy(bytes, 0, retBytes, offset, bytes.length); + offset += bytes.length; + } + + return retBytes; + } + + public static byte[] put(final PCEPTlv objToSerialize) { + int typeIndicator = 0; + + byte[] valueBytes; + + if (objToSerialize instanceof PCEStatefulCapabilityTlv) { + typeIndicator = PCEPTlvType.PCE_STATEFUL_CAPABILITY.getIndicator(); + valueBytes = PCEStatefulCapabilityTlvParser.serializeValueField((PCEStatefulCapabilityTlv) objToSerialize); + } else if (objToSerialize instanceof LSPStateDBVersionTlv) { + typeIndicator = PCEPTlvType.LSP_STATE_DB_VERSION.getIndicator(); + valueBytes = ByteArray.longToBytes(((LSPStateDBVersionTlv) objToSerialize).getDbVersion()); + } else if (objToSerialize instanceof NoPathVectorTlv) { + typeIndicator = PCEPTlvType.NO_PATH_VECTOR.getIndicator(); + valueBytes = NoPathVectorTlvParser.put((NoPathVectorTlv) objToSerialize); + } else if (objToSerialize instanceof OverloadedDurationTlv) { + typeIndicator = PCEPTlvType.OVERLOADED_DURATION.getIndicator(); + valueBytes = ByteArray.intToBytes(((OverloadedDurationTlv) objToSerialize).getValue()); + } else if (objToSerialize instanceof LSPSymbolicNameTlv) { + typeIndicator = PCEPTlvType.LSP_SYMBOLIC_NAME.getIndicator(); + valueBytes = ((LSPSymbolicNameTlv) objToSerialize).getSymbolicName().getSymbolicName(); + } else if (objToSerialize instanceof LSPUpdateErrorTlv) { + typeIndicator = PCEPTlvType.LSP_UPDATE_ERROR.getIndicator(); + valueBytes = ((LSPUpdateErrorTlv) objToSerialize).getErrorCode(); + + assert valueBytes.length == UPDATE_ERR_CODE_LENGTH : "Update error code si too large."; + + } else if (objToSerialize instanceof IPv4LSPIdentifiersTlv) { + typeIndicator = PCEPTlvType.LSP_IDENTIFIER_IPV4.getIndicator(); + valueBytes = LSPIdentifierIPv4TlvParser.put((IPv4LSPIdentifiersTlv) objToSerialize); + } else if (objToSerialize instanceof IPv6LSPIdentifiersTlv) { + typeIndicator = PCEPTlvType.LSP_IDENTIFIER_IPV6.getIndicator(); + valueBytes = LSPIdentifierIPv6TlvParser.put((IPv6LSPIdentifiersTlv) objToSerialize); + } else if (objToSerialize instanceof RSVPErrorSpecTlv && ((RSVPErrorSpecTlv) objToSerialize).getErrorNodeAddress() instanceof IPv4Address) { + typeIndicator = PCEPTlvType.RSVP_ERROR_SPEC_IPV4.getIndicator(); + valueBytes = RSVPErrorSpecIPv4TlvParser.put((RSVPErrorSpecTlv) objToSerialize); + } else if (objToSerialize instanceof RSVPErrorSpecTlv && ((RSVPErrorSpecTlv) objToSerialize).getErrorNodeAddress() instanceof IPv6Address) { + typeIndicator = PCEPTlvType.RSVP_ERROR_SPEC_IPV6.getIndicator(); + valueBytes = RSVPErrorSpecIPv6TlvParser.put((RSVPErrorSpecTlv) objToSerialize); + } else if (objToSerialize instanceof ReqMissingTlv) { + typeIndicator = PCEPTlvType.REQ_MISSING.getIndicator(); + valueBytes = new byte[REQ_ID_LENGTH]; + System.arraycopy(ByteArray.longToBytes(((ReqMissingTlv) objToSerialize).getRequestID()), Long.SIZE / Byte.SIZE - REQ_ID_LENGTH, valueBytes, 0, + REQ_ID_LENGTH); + } else if (objToSerialize instanceof NodeIdentifierTlv) { + typeIndicator = PCEPTlvType.NODE_IDENTIFIER.getIndicator(); + valueBytes = ((NodeIdentifierTlv) objToSerialize).getValue(); + } else if (objToSerialize instanceof OrderTlv) { + typeIndicator = PCEPTlvType.ORDER_TLV.getIndicator(); + valueBytes = new byte[ORDR_DEL_LENGTH + ORDR_SETUP_LENGTH]; + ByteArray.copyWhole(ByteArray.intToBytes((int) ((OrderTlv) objToSerialize).getDeleteOrder()), valueBytes, 0); + ByteArray.copyWhole(ByteArray.intToBytes((int) ((OrderTlv) objToSerialize).getSetupOrder()), valueBytes, ORDR_DEL_LENGTH); + } else if (objToSerialize instanceof P2MPCapabilityTlv) { + typeIndicator = PCEPTlvType.P2MP_CAPABILITY.getIndicator(); + valueBytes = new byte[P2MP_CAPABLITY_LENGTH]; + ByteArray.copyWhole(ByteArray.shortToBytes((short) ((P2MPCapabilityTlv) objToSerialize).getValue()), valueBytes, 0); + } else if (objToSerialize instanceof OFListTlv) { + typeIndicator = PCEPTlvType.OF_LIST_TLV.getIndicator(); + valueBytes = OFListTlvParser.put((OFListTlv) objToSerialize); + } else if (objToSerialize instanceof LSPCleanupTlv) { + typeIndicator = PCEPTlvType.LSP_CLEANUP_TLV.getIndicator(); + valueBytes = ByteArray.intToBytes(((LSPCleanupTlv) objToSerialize).getTimeout()); + } else + throw new IllegalArgumentException("Unknown instance of PCEPTlv. Passed: " + objToSerialize + "."); + + final byte[] typeBytes = ByteArray.cutBytes(ByteArray.intToBytes(typeIndicator), (Integer.SIZE / 8) - TYPE_F_LENGTH); + final byte[] lengthBytes = ByteArray.cutBytes(ByteArray.intToBytes(valueBytes.length), (Integer.SIZE / 8) - LENGTH_F_LENGTH); + final byte[] bytes = new byte[HEADER_LENGTH + valueBytes.length + Util.getPadding(HEADER_LENGTH + valueBytes.length, PADDED_TO)]; + + System.arraycopy(typeBytes, 0, bytes, TYPE_F_OFFSET, TYPE_F_LENGTH); + System.arraycopy(lengthBytes, 0, bytes, LENGTH_F_OFFSET, LENGTH_F_LENGTH); + System.arraycopy(valueBytes, 0, bytes, VALUE_F_OFFSET, valueBytes.length); + + return bytes; + } + + private static PCEPTlv parseSpecificTLV(final PCEPTlvType type, final byte[] valueBytes) throws PCEPDeserializerException { + switch (type) { + case PCE_STATEFUL_CAPABILITY: + return PCEStatefulCapabilityTlvParser.deserializeValueField(valueBytes); + case LSP_STATE_DB_VERSION: + return new LSPStateDBVersionTlv(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, 0, DBV_F_LENGTH))); + case NO_PATH_VECTOR: + return NoPathVectorTlvParser.parse(valueBytes); + case OVERLOADED_DURATION: + return new OverloadedDurationTlv(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, 0, OVERLOADED_DURATION_LENGTH))); + case LSP_SYMBOLIC_NAME: + return new LSPSymbolicNameTlv(new LSPSymbolicName(valueBytes)); + case LSP_UPDATE_ERROR: + return new LSPUpdateErrorTlv(valueBytes); + case LSP_IDENTIFIER_IPV4: + return LSPIdentifierIPv4TlvParser.parse(valueBytes); + case LSP_IDENTIFIER_IPV6: + return LSPIdentifierIPv6TlvParser.parse(valueBytes); + case RSVP_ERROR_SPEC_IPV4: + return RSVPErrorSpecIPv4TlvParser.parse(valueBytes); + case RSVP_ERROR_SPEC_IPV6: + return RSVPErrorSpecIPv6TlvParser.parse(valueBytes); + case REQ_MISSING: + return new ReqMissingTlv(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, 0, REQ_ID_LENGTH))); + case NODE_IDENTIFIER: + return new NodeIdentifierTlv(valueBytes); + case ORDER_TLV: + return new OrderTlv(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, 0, ORDR_DEL_LENGTH)), ByteArray.bytesToLong(ByteArray.subByte( + valueBytes, ORDR_DEL_LENGTH, ORDR_SETUP_LENGTH))); + case P2MP_CAPABILITY: + return new P2MPCapabilityTlv(ByteArray.bytesToShort(ByteArray.subByte(valueBytes, 0, P2MP_CAPABLITY_LENGTH)) & 0xFFFF); + case OF_LIST_TLV: + return OFListTlvParser.parse(valueBytes); + case LSP_CLEANUP_TLV: + return new LSPCleanupTlv(ByteArray.bytesToInt(valueBytes)); + default: + throw new PCEPDeserializerException("Unknown TLV type. Passed: " + type + ";"); + } + } +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/RawPCEPMessageFactory.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/RawPCEPMessageFactory.java index ee33deaf00..451349d608 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/RawPCEPMessageFactory.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/RawPCEPMessageFactory.java @@ -16,8 +16,29 @@ import org.opendaylight.protocol.framework.ProtocolMessageFactory; 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.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.message.PCCreateMessage; +import org.opendaylight.protocol.pcep.message.PCEPCloseMessage; +import org.opendaylight.protocol.pcep.message.PCEPErrorMessage; +import org.opendaylight.protocol.pcep.message.PCEPNotificationMessage; +import org.opendaylight.protocol.pcep.message.PCEPOpenMessage; +import org.opendaylight.protocol.pcep.message.PCEPReplyMessage; +import org.opendaylight.protocol.pcep.message.PCEPReportMessage; +import org.opendaylight.protocol.pcep.message.PCEPRequestMessage; +import org.opendaylight.protocol.pcep.message.PCEPUpdateRequestMessage; import org.opendaylight.protocol.pcep.spi.PCEPMessageType; +import org.opendaylight.protocol.pcep.spi.RawMessage; import org.opendaylight.protocol.util.ByteArray; +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.Message; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,16 +76,16 @@ class RawPCEPMessageFactory implements ProtocolMessageFactory { } private void fillInMap() { - // this.put(PCEPMessageType.OPEN, new PCEPOpenMessageParser()); - // this.put(PCEPMessageType.KEEPALIVE, new PCEPKeepAliveMessageParser()); - // this.put(PCEPMessageType.NOTIFICATION, new PCEPNotificationMessageParser()); - // this.put(PCEPMessageType.ERROR, new PCEPErrorMessageParser()); - // this.put(PCEPMessageType.RESPONSE, new PCEPReplyMessageParser()); - // this.put(PCEPMessageType.REQUEST, new PCEPRequestMessageParser()); - // this.put(PCEPMessageType.UPDATE_REQUEST, new PCEPUpdateRequestMessageParser()); - // this.put(PCEPMessageType.STATUS_REPORT, new PCEPReportMessageParser()); - // this.put(PCEPMessageType.CLOSE, new PCEPCloseMessageParser()); - // this.put(PCEPMessageType.PCCREATE, new PCCreateMessageParser()); + this.put(PCEPMessageType.OPEN, new PCEPOpenMessageParser()); + this.put(PCEPMessageType.KEEPALIVE, new PCEPKeepAliveMessageParser()); + this.put(PCEPMessageType.NOTIFICATION, new PCEPNotificationMessageParser()); + this.put(PCEPMessageType.ERROR, new PCEPErrorMessageParser()); + this.put(PCEPMessageType.RESPONSE, new PCEPReplyMessageParser()); + this.put(PCEPMessageType.REQUEST, new PCEPRequestMessageParser()); + this.put(PCEPMessageType.UPDATE_REQUEST, new PCEPUpdateRequestMessageParser()); + this.put(PCEPMessageType.STATUS_REPORT, new PCEPReportMessageParser()); + this.put(PCEPMessageType.CLOSE, new PCEPCloseMessageParser()); + this.put(PCEPMessageType.PCCREATE, new PCCreateMessageParser()); } public static MapOfParsers getInstance() { @@ -108,16 +129,16 @@ class RawPCEPMessageFactory implements ProtocolMessageFactory { throw new DocumentedException("Unhandled message type " + type, new PCEPDocumentedException("Unhandled message type " + type, PCEPErrors.CAPABILITY_NOT_SUPPORTED)); } - final Message msg = null; - // try { - // msg = new RawMessage(PCEPObjectFactory.parseObjects(msgBody), msgType); - // } catch (final PCEPDeserializerException e) { - // logger.debug("Unexpected deserializer problem", e); - // throw new DeserializerException(e.getMessage(), e); - // } catch (final PCEPDocumentedException e) { - // logger.debug("Documented deserializer problem", e); - // throw new DocumentedException(e.getMessage(), e); - // } + Message msg; + try { + msg = new RawMessage(PCEPObjectFactory.parseObjects(msgBody), msgType); + } catch (final PCEPDeserializerException e) { + logger.debug("Unexpected deserializer problem", e); + throw new DeserializerException(e.getMessage(), e); + } catch (final PCEPDocumentedException e) { + logger.debug("Documented deserializer problem", e); + throw new DocumentedException(e.getMessage(), e); + } logger.debug("Message was parsed. {}", msg); return Lists.newArrayList(msg); } @@ -128,32 +149,32 @@ class RawPCEPMessageFactory implements ProtocolMessageFactory { throw new IllegalArgumentException("PCEPMessage is mandatory."); } - final PCEPMessageType msgType = null; - - // if (msg instanceof PCEPOpenMessage) { - // msgType = PCEPMessageType.OPEN; - // } else if (msg instanceof KeepaliveMessage) { - // msgType = PCEPMessageType.KEEPALIVE; - // } else if (msg instanceof CloseMessage) { - // msgType = PCEPMessageType.CLOSE; - // } else if (msg instanceof PCEPReplyMessage) { - // msgType = PCEPMessageType.RESPONSE; - // } else if (msg instanceof PCEPRequestMessage) { - // msgType = PCEPMessageType.REQUEST; - // } else if (msg instanceof PCEPNotificationMessage) { - // msgType = PCEPMessageType.NOTIFICATION; - // } else if (msg instanceof PCEPErrorMessage) { - // msgType = PCEPMessageType.ERROR; - // } else if (msg instanceof PCEPReportMessage) { - // msgType = PCEPMessageType.STATUS_REPORT; - // } else if (msg instanceof PCEPUpdateRequestMessage) { - // msgType = PCEPMessageType.UPDATE_REQUEST; - // } else if (msg instanceof PCCreateMessage) { - // msgType = PCEPMessageType.PCCREATE; - // } else { - // logger.error("Unknown instance of PCEPMessage. Message class: {}", msg.getClass()); - // throw new IllegalArgumentException("Unknown instance of PCEPMessage. Passed " + msg.getClass()); - // } + final PCEPMessageType msgType; + + if (msg instanceof PCEPOpenMessage) { + msgType = PCEPMessageType.OPEN; + } else if (msg instanceof KeepaliveMessage) { + msgType = PCEPMessageType.KEEPALIVE; + } else if (msg instanceof PCEPCloseMessage) { + msgType = PCEPMessageType.CLOSE; + } else if (msg instanceof PCEPReplyMessage) { + msgType = PCEPMessageType.RESPONSE; + } else if (msg instanceof PCEPRequestMessage) { + msgType = PCEPMessageType.REQUEST; + } else if (msg instanceof PCEPNotificationMessage) { + msgType = PCEPMessageType.NOTIFICATION; + } else if (msg instanceof PCEPErrorMessage) { + msgType = PCEPMessageType.ERROR; + } else if (msg instanceof PCEPReportMessage) { + msgType = PCEPMessageType.STATUS_REPORT; + } else if (msg instanceof PCEPUpdateRequestMessage) { + msgType = PCEPMessageType.UPDATE_REQUEST; + } else if (msg instanceof PCCreateMessage) { + msgType = PCEPMessageType.PCCREATE; + } else { + logger.error("Unknown instance of PCEPMessage. Message class: {}", msg.getClass()); + throw new IllegalArgumentException("Unknown instance of PCEPMessage. Passed " + msg.getClass()); + } logger.trace("Serializing {}", msgType); diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/Util.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/Util.java index ff5180240b..c4b936ff68 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/Util.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/Util.java @@ -8,25 +8,12 @@ package org.opendaylight.protocol.pcep.impl; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; +import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.protocol.concepts.AddressFamily; import org.opendaylight.protocol.concepts.NetworkAddress; -import org.opendaylight.protocol.pcep.PCEPErrorMapping; -import org.opendaylight.protocol.pcep.PCEPErrorMapping.PCEPErrorIdentifier; -import org.opendaylight.protocol.pcep.PCEPErrors; -import org.opendaylight.protocol.util.ByteArray; -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.OpenObject; -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.pcerr.message.pcerr.message.ErrorType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.Errors; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.SessionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.session.Open; /** * Utilities used in pcep-impl @@ -41,22 +28,25 @@ public final class Util { private final HashMap kvToV = new HashMap(); - public void put(final K key, final KV keyValue, final V value) { + public void put(K key, KV keyValue, V value) { this.kToKv.put(key, keyValue); this.kvToV.put(keyValue, value); } - public KV getKeyValueFromKey(final K key) { + public KV getKeyValueFromKey(K key) { return this.kToKv.get(key); } - public V getValueFromKeyValue(final KV keyValue) { + public V getValueFromKeyValue(KV keyValue) { return this.kvToV.get(keyValue); } } - public static > List parseAddresses(final byte[] bytes, int offset, final AddressFamily family, - final int addrLen) { + public static int getPadding(int length, int padding) { + return (padding - (length % padding)) % padding; + } + + public static > List parseAddresses(byte[] bytes, int offset, AddressFamily family, int addrLen) { final List addresses = new ArrayList(); while (bytes.length > offset) { @@ -67,28 +57,10 @@ public final class Util { return addresses; } - public static > void putAddresses(final byte[] destBytes, int offset, final List addresses, - final int addrLen) { + public static > void putAddresses(byte[] destBytes, int offset, List addresses, int addrLen) { for (final T address : addresses) { System.arraycopy(address.getAddress(), 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) - return errMessageBuilder.setPcerrMessage(new PcerrMessageBuilder().setErrors(Arrays.asList(err)).build()).build(); - else { - final ErrorType type = new SessionBuilder().setOpen((Open) t).build(); - return errMessageBuilder.setPcerrMessage(new PcerrMessageBuilder().setErrors(Arrays.asList(err)).setErrorType(type).build()).build(); - } - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCCreateMessageParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCCreateMessageParser.java index 1a896ee9c9..e47be9076a 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCCreateMessageParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCCreateMessageParser.java @@ -7,39 +7,30 @@ */ package org.opendaylight.protocol.pcep.impl.message; -import io.netty.buffer.ByteBuf; - -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.spi.AbstractMessageParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import org.opendaylight.protocol.pcep.impl.PCEPMessageParser; +import org.opendaylight.protocol.pcep.impl.PCEPObjectFactory; +import org.opendaylight.protocol.pcep.message.PCCreateMessage; 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.PcinitiateMessage; /** * Parser for {@link PCCreateMessage} */ -public class PCCreateMessageParser extends AbstractMessageParser { - - private final int TYPE = 12; - - public PCCreateMessageParser(final HandlerRegistry registry) { - super(registry); - } - +public class PCCreateMessageParser implements PCEPMessageParser { + + /* + * (non-Javadoc) + * + * @see + * org.opendaylight.protocol.pcep.impl.PCEPMessageParser#put(org.opendaylight.protocol.pcep.PCEPMessage + * ) + */ @Override - public void serializeMessage(final Message message, final ByteBuf buffer) { - if (!(message instanceof PcinitiateMessage)) - throw new IllegalArgumentException("Wrong instance of Message. Passed instance of " + message.getClass() - + ". Needed PcinitiateMessage."); - } + public byte[] put(final Message msg) { + if (!(msg instanceof PCCreateMessage)) + throw new IllegalArgumentException("Wrong instance of PCEPMessage. Passed instance of " + msg.getClass() + + ". Needed PCCreateMessage."); - @Override - public PcinitiateMessage parseMessage(final byte[] buffer) throws PCEPDeserializerException { - return null; + return PCEPObjectFactory.put(((PCCreateMessage) msg).getAllObjects()); } - @Override - public int getMessageType() { - return this.TYPE; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCCreateMessageValidator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCCreateMessageValidator.java index 92303b1ba0..42fa0c0756 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCCreateMessageValidator.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCCreateMessageValidator.java @@ -7,99 +7,117 @@ */ package org.opendaylight.protocol.pcep.impl.message; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPMessageValidator; +import org.opendaylight.protocol.pcep.impl.object.UnknownObject; +import org.opendaylight.protocol.pcep.message.PCCreateMessage; +import org.opendaylight.protocol.pcep.message.PCEPErrorMessage; +import org.opendaylight.protocol.pcep.object.CompositeInstantiationObject; +import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPLspaObject; +import org.opendaylight.protocol.pcep.object.PCEPMetricObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; /** * PCCCreateMessage validator. Validates message integrity. */ -// FIXME: merge with parser -class PCCreateMessageValidator { - - // @Override - // public List validate(final List objects) throws PCEPDeserializerException { - // if (objects == null) - // throw new IllegalArgumentException("Passed list can't be null."); - // - // final List insts = new ArrayList(); - // - // CompositeInstantiationObject inst; - // while (!objects.isEmpty()) { - // try { - // if ((inst = this.getValidInstantiationObject(objects)) == null) - // break; - // } catch (final PCEPDocumentedException e) { - // return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(e.getError()))); - // } - // - // insts.add(inst); - // } - // - // if (insts.isEmpty()) - // throw new PCEPDeserializerException("At least one CompositeInstantiationObject is mandatory."); - // - // if (!objects.isEmpty()) - // throw new PCEPDeserializerException("Unprocessed objects: " + objects); - // - // return Arrays.asList((Message) new PCCreateMessage(insts)); - // } - // - // private CompositeInstantiationObject getValidInstantiationObject(final List objects) throws - // PCEPDocumentedException { - // if (objects.get(0) instanceof UnknownObject) - // throw new PCEPDocumentedException("Unknown object", ((UnknownObject) objects.get(0)).getError()); - // if (!(objects.get(0) instanceof EndpointsObject)) - // return null; - // - // final EndpointsObject endPoints = ((EndpointsObject) objects.get(0)); - // objects.remove(0); - // - // if (objects.get(0) instanceof UnknownObject) - // throw new PCEPDocumentedException("Unknown object", ((UnknownObject) objects.get(0)).getError()); - // if (!(objects.get(0) instanceof LspaObject)) - // throw new PCEPDocumentedException("LSPA Object must be second.", PCEPErrors.LSPA_MISSING); - // final LspaObject lspa = (LspaObject) objects.get(0); - // objects.remove(0); - // - // ExplicitRouteObject ero = null; - // BandwidthObject bandwidth = null; - // final List metrics = Lists.newArrayList(); - // - // Object obj; - // int state = 1; - // while (!objects.isEmpty()) { - // obj = objects.get(0); - // if (obj instanceof UnknownObject) { - // throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError()); - // } - // - // switch (state) { - // case 1: - // state = 2; - // if (obj instanceof ExplicitRouteObject) { - // ero = (ExplicitRouteObject) obj; - // break; - // } - // case 2: - // state = 3; - // if (obj instanceof BandwidthObject) { - // bandwidth = (BandwidthObject) obj; - // break; - // } - // case 3: - // state = 4; - // if (obj instanceof MetricObject) { - // metrics.add((MetricObject) obj); - // state = 3; - // break; - // } - // } - // - // if (state == 4) - // break; - // - // objects.remove(0); - // } - // - // return new CompositeInstantiationObject(endPoints, lspa, ero, bandwidth, metrics); - // } +public class PCCreateMessageValidator extends PCEPMessageValidator { + + @Override + public List validate(final List objects) throws PCEPDeserializerException { + if (objects == null) + throw new IllegalArgumentException("Passed list can't be null."); + + final List insts = new ArrayList(); + + CompositeInstantiationObject inst; + while (!objects.isEmpty()) { + try { + if ((inst = this.getValidInstantiationObject(objects)) == null) + break; + } catch (final PCEPDocumentedException e) { + return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(e.getError()))); + } + + insts.add(inst); + } + + if (insts.isEmpty()) + throw new PCEPDeserializerException("At least one CompositeInstantiationObject is mandatory."); + + if (!objects.isEmpty()) + throw new PCEPDeserializerException("Unprocessed objects: " + objects); + + return Arrays.asList((Message) new PCCreateMessage(insts)); + } + + private CompositeInstantiationObject getValidInstantiationObject(final List objects) throws PCEPDocumentedException { + if (objects.get(0) instanceof UnknownObject) + throw new PCEPDocumentedException("Unknown object", ((UnknownObject) objects.get(0)).getError()); + if (!(objects.get(0) instanceof PCEPEndPointsObject)) + return null; + + final PCEPEndPointsObject endPoints = ((PCEPEndPointsObject) objects.get(0)); + objects.remove(0); + + if (objects.get(0) instanceof UnknownObject) + throw new PCEPDocumentedException("Unknown object", ((UnknownObject) objects.get(0)).getError()); + if (!(objects.get(0) instanceof PCEPLspaObject)) + throw new PCEPDocumentedException("LSPA Object must be second.", PCEPErrors.LSPA_MISSING); + final PCEPLspaObject lspa = (PCEPLspaObject) objects.get(0); + objects.remove(0); + + PCEPExplicitRouteObject ero = null; + PCEPRequestedPathBandwidthObject bandwidth = null; + final List metrics = new ArrayList(); + + PCEPObject obj; + int state = 1; + while (!objects.isEmpty()) { + obj = objects.get(0); + if (obj instanceof UnknownObject) { + throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError()); + } + + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPExplicitRouteObject) { + ero = (PCEPExplicitRouteObject) obj; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPRequestedPathBandwidthObject) { + bandwidth = (PCEPRequestedPathBandwidthObject) obj; + break; + } + case 3: + state = 4; + if (obj instanceof PCEPMetricObject) { + metrics.add((PCEPMetricObject) obj); + state = 3; + break; + } + } + + if (state == 4) + break; + + objects.remove(0); + } + + return new CompositeInstantiationObject(endPoints, lspa, ero, bandwidth, metrics); + } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPCloseMessageParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPCloseMessageParser.java index 5a37f08e4a..4280ce9506 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPCloseMessageParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPCloseMessageParser.java @@ -7,76 +7,23 @@ */ package org.opendaylight.protocol.pcep.impl.message; -import io.netty.buffer.ByteBuf; - -import java.util.List; - -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractMessageParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.CloseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseMessage; +import org.opendaylight.protocol.pcep.impl.PCEPMessageParser; +import org.opendaylight.protocol.pcep.impl.PCEPObjectFactory; +import org.opendaylight.protocol.pcep.message.PCEPCloseMessage; 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.close.message.CCloseMessage; -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.CClose; /** * Parser for {@link org.opendaylight.protocol.pcep.message.PCEPCloseMessage PCEPCloseMessage} */ -public class PCEPCloseMessageParser extends AbstractMessageParser { - - private final int TYPE = 7; - - public PCEPCloseMessageParser(final HandlerRegistry registry) { - super(registry); - } - - @Override - public void serializeMessage(final Message message, final ByteBuf buffer) { - if (!(message instanceof CloseMessage)) - throw new IllegalArgumentException("Wrong instance of Message. Passed instance of " + message.getClass() - + ". Nedded CloseMessage."); - final CCloseMessage close = ((CloseMessage) message).getCCloseMessage(); - - if (close.getCClose() == null) { - throw new IllegalArgumentException("Close Object must be present in Close Message."); - } - buffer.writeBytes(serializeObject(close.getCClose())); - } +public class PCEPCloseMessageParser implements PCEPMessageParser { @Override - public CloseMessage parseMessage(final byte[] buffer) throws PCEPDeserializerException, PCEPDocumentedException { - if (buffer == null || buffer.length == 0) { - throw new PCEPDeserializerException("Close message doesn't contain CLOSE object."); - } - final List objs = parseObjects(buffer); + public byte[] put(final Message msg) { + if (!(msg instanceof PCEPCloseMessage)) + throw new IllegalArgumentException("Wrong instance of PCEPMessage. Passed instance of " + msg.getClass() + + ". Nedded PCEPCloseMessage."); - return validate(objs); + return PCEPObjectFactory.put(((PCEPCloseMessage) msg).getAllObjects()); } - private Close validate(final List objects) throws PCEPDeserializerException { - if (objects == null) - throw new IllegalArgumentException("Passed list can't be null."); - - if (objects.isEmpty() || !(objects.get(0) instanceof CClose)) - throw new PCEPDeserializerException("Close message doesn't contain CLOSE object."); - - final Object o = objects.get(0); - final CCloseMessage msg = new CCloseMessageBuilder().setCClose((CClose) o).build(); - objects.remove(0); - - if (!objects.isEmpty()) - throw new PCEPDeserializerException("Unprocessed Objects: " + objects); - - return new CloseBuilder().setCCloseMessage(msg).build(); - } - - @Override - public int getMessageType() { - return this.TYPE; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPCloseMessageValidator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPCloseMessageValidator.java new file mode 100644 index 0000000000..2bf4f7d01f --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPCloseMessageValidator.java @@ -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.pcep.impl.message; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPMessageValidator; +import org.opendaylight.protocol.pcep.message.PCEPCloseMessage; +import org.opendaylight.protocol.pcep.object.PCEPCloseObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; + +/** + * PCEPCloseMessage validator. Validates message integrity. + */ +public class PCEPCloseMessageValidator extends PCEPMessageValidator { + + @Override + public List validate(final List objects) throws PCEPDeserializerException { + if (objects == null) + throw new IllegalArgumentException("Passed list can't be null."); + + if (objects.isEmpty() || !(objects.get(0) instanceof PCEPCloseObject)) + throw new PCEPDeserializerException("Close message doesn't contain CLOSE object."); + + final PCEPCloseMessage msg = new PCEPCloseMessage((PCEPCloseObject) objects.get(0)); + objects.remove(0); + + if (!objects.isEmpty()) + throw new PCEPDeserializerException("Unprocessed Objects: " + objects); + + return new ArrayList() { + private static final long serialVersionUID = 1L; + { + this.add(msg); + } + }; + } + +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPErrorMessageParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPErrorMessageParser.java index f65a99dfee..7b8d8df68e 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPErrorMessageParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPErrorMessageParser.java @@ -7,179 +7,22 @@ */ package org.opendaylight.protocol.pcep.impl.message; -import io.netty.buffer.ByteBuf; - -import java.util.Arrays; -import java.util.List; - -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.PCEPErrorMapping; -import org.opendaylight.protocol.pcep.PCEPErrors; -import org.opendaylight.protocol.pcep.UnknownObject; -import org.opendaylight.protocol.pcep.spi.AbstractMessageParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder; +import org.opendaylight.protocol.pcep.impl.PCEPMessageParser; +import org.opendaylight.protocol.pcep.impl.PCEPObjectFactory; +import org.opendaylight.protocol.pcep.message.PCEPErrorMessage; 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.OpenObject; -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.RpObject; -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.pcerr.message.pcerr.message.Errors; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.Request; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.RequestBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.Session; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.SessionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request.Rps; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.session.Open; - -import com.google.common.collect.Lists; /** - * Parser for {@link PcerrMessage} + * Parser for {@link org.opendaylight.protocol.pcep.message.PCEPErrorMessage PCEPErrorMessage} */ -public class PCEPErrorMessageParser extends AbstractMessageParser { - - public final int TYPE = 6; - - public PCEPErrorMessageParser(final HandlerRegistry registry) { - super(registry); - } +public class PCEPErrorMessageParser implements PCEPMessageParser { @Override - public void serializeMessage(final Message message, final ByteBuf buffer) { - if (!(message instanceof PcerrMessage)) - throw new IllegalArgumentException("Wrong instance of Message. Passed instance " + message.getClass() - + ". Nedded ErrorMessage."); - final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessage err = ((PcerrMessage) message).getPcerrMessage(); - - if (err.getErrors() == null || err.getErrors().isEmpty()) - throw new IllegalArgumentException("Errors should not be empty."); - - if (err.getErrorType() instanceof Request) { - final List rps = ((Request) err.getErrorType()).getRps(); - for (final Rps r : rps) { - buffer.writeBytes(serializeObject(r)); - } - } - - for (final Errors e : err.getErrors()) { - buffer.writeBytes(serializeObject(e)); - } - - if (err.getErrorType() instanceof Session) { - buffer.writeBytes(serializeObject(((Session) err.getErrorType()).getOpen())); - } - } - - @Override - public PcerrMessage parseMessage(final byte[] buffer) throws PCEPDeserializerException, PCEPDocumentedException { - if (buffer == null || buffer.length == 0) { - throw new PCEPDeserializerException("Error message is empty."); - } - final List objs = parseObjects(buffer); - PcerrMessage m = null; - try { - m = validate(objs); - } catch (final PCEPDocumentedException e) { - final PCEPErrorMapping maping = PCEPErrorMapping.getInstance(); - return new PcerrBuilder().setPcerrMessage( - new PcerrMessageBuilder().setErrors( - Arrays.asList(new ErrorsBuilder().setType(maping.getFromErrorsEnum(e.getError()).type).setValue( - maping.getFromErrorsEnum(e.getError()).value).build())).build()).build(); - } - return m; - } - - private PcerrMessage validate(final List objects) throws PCEPDeserializerException, PCEPDocumentedException { - if (objects == null) - throw new IllegalArgumentException("Passed list can't be null."); + public byte[] put(final Message msg) { + if (!(msg instanceof PCEPErrorMessage)) + throw new IllegalArgumentException("Wrong instance of PCEPMessage. Passed instance " + msg.getClass() + + ". Nedded PCEPErrorMessage."); - Open openObj = null; - final List requestParameters = Lists.newArrayList(); - final List errorObjects = Lists.newArrayList(); - final PcerrMessageBuilder b = new PcerrMessageBuilder(); - - Object obj; - int state = 1; - while (!objects.isEmpty()) { - obj = objects.get(0); - - if (obj instanceof UnknownObject) - return new PcerrBuilder().setPcerrMessage(b.setErrors(((UnknownObject) obj).getErrors()).build()).build(); - - switch (state) { - case 1: - if (obj instanceof PcepErrorObject) { - final PcepErrorObject o = (PcepErrorObject) obj; - errorObjects.add((Errors) o); - break; - } - state = 2; - case 2: - state = 3; - if (obj instanceof OpenObject) { - openObj = (Open) obj; - break; - } - case 3: - while (!objects.isEmpty()) { - switch (state) { - case 1: - state = 2; - if (obj instanceof RpObject) { - final RpObject o = ((RpObject) obj); - if (o.isProcessingRule()) - throw new PCEPDocumentedException("Invalid setting of P flag.", PCEPErrors.P_FLAG_NOT_SET); - requestParameters.add((Rps) o); - state = 1; - break; - } - case 2: - if (obj instanceof PcepErrorObject) { - final PcepErrorObject o = (PcepErrorObject) obj; - errorObjects.add((Errors) o); - state = 2; - break; - } - state = 3; - } - - if (state == 3) - break; - - objects.remove(0); - } - - state = 4; - break; - } - - if (state == 4) { - break; - } - - objects.remove(0); - } - - if (errorObjects.isEmpty() && errorObjects.isEmpty()) - throw new PCEPDeserializerException("At least one PCEPErrorObject is mandatory."); - - if (!objects.isEmpty()) - throw new PCEPDeserializerException("Unprocessed Objects: " + objects); - if (requestParameters != null) - b.setErrorType(new RequestBuilder().setRps(requestParameters).build()); - if (openObj != null) - b.setErrorType(new SessionBuilder().setOpen(openObj).build()); - - return new PcerrBuilder().setPcerrMessage(b.setErrors(errorObjects).build()).build(); - } - - @Override - public int getMessageType() { - return this.TYPE; + return PCEPObjectFactory.put(((PCEPErrorMessage) msg).getAllObjects()); } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPErrorMessageValidator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPErrorMessageValidator.java new file mode 100644 index 0000000000..3cdeb3aada --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPErrorMessageValidator.java @@ -0,0 +1,142 @@ +/* + * 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.message; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPMessageValidator; +import org.opendaylight.protocol.pcep.impl.object.UnknownObject; +import org.opendaylight.protocol.pcep.message.PCEPErrorMessage; +import org.opendaylight.protocol.pcep.object.CompositeErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; + +/** + * PCEPErrorMessage validator. Validates message integrity. + */ +public class PCEPErrorMessageValidator extends PCEPMessageValidator { + + @Override + public List validate(final List objects) throws PCEPDeserializerException { + if (objects == null) + throw new IllegalArgumentException("Passed list can't be null."); + + PCEPOpenObject openObj = null; + final List errors = new ArrayList(); + final List errorObjects = new ArrayList(); + + PCEPObject obj; + int state = 1; + while (!objects.isEmpty()) { + obj = objects.get(0); + + if (obj instanceof UnknownObject) + return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(((UnknownObject) obj).getError()))); + + switch (state) { + case 1: + if (obj instanceof PCEPErrorObject) { + errorObjects.add((PCEPErrorObject) obj); + break; + } + state = 2; + case 2: + state = 3; + if (obj instanceof PCEPOpenObject) { + openObj = (PCEPOpenObject) obj; + break; + } + case 3: + while (!objects.isEmpty()) { + CompositeErrorObject comObj; + + try { + comObj = getValidErrorComposite(objects); + } catch (final PCEPDocumentedException e) { + return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(e.getError()))); + } + + if (comObj == null) + break; + + errors.add(comObj); + } + + state = 4; + break; + } + + if (state == 4) { + break; + } + + objects.remove(0); + } + + if (errors.isEmpty() && errorObjects.isEmpty()) + throw new PCEPDeserializerException("At least one PCEPErrorObject is mandatory."); + + if (!objects.isEmpty()) + throw new PCEPDeserializerException("Unprocessed Objects: " + objects); + + return Arrays.asList((Message) new PCEPErrorMessage(openObj, errorObjects, errors)); + } + + private static CompositeErrorObject getValidErrorComposite(final List objects) throws PCEPDocumentedException, + PCEPDeserializerException { + final List requestParameters = new ArrayList(); + final List errors = new ArrayList(); + PCEPObject obj; + int state = 1; + + while (!objects.isEmpty()) { + obj = objects.get(0); + + if (obj instanceof UnknownObject) + throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError()); + + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPRequestParameterObject) { + if (((PCEPRequestParameterObject) obj).isProcessed()) + throw new PCEPDocumentedException("Invalid setting of P flag.", PCEPErrors.P_FLAG_NOT_SET); + requestParameters.add((PCEPRequestParameterObject) obj); + state = 1; + break; + } + case 2: + if (obj instanceof PCEPErrorObject) { + errors.add((PCEPErrorObject) obj); + state = 2; + break; + } + state = 3; + } + + if (state == 3) + break; + + objects.remove(0); + } + + if (errors.isEmpty()) + return null; + + return new CompositeErrorObject(requestParameters, errors); + } + +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPKeepAliveMessageParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPKeepAliveMessageParser.java index 0f4c5e5548..ac5830f0cd 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPKeepAliveMessageParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPKeepAliveMessageParser.java @@ -7,42 +7,21 @@ */ package org.opendaylight.protocol.pcep.impl.message; -import io.netty.buffer.ByteBuf; - -import org.opendaylight.protocol.pcep.spi.AbstractMessageParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder; +import org.opendaylight.protocol.pcep.impl.PCEPMessageParser; 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.Message; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder; /** - * Parser for {@link KeepaliveMessage} + * Parser for {@link org.opendaylight.protocol.pcep.message.PCEPKeepAliveMessage PCEPKeepAliveMessage} */ -public class PCEPKeepAliveMessageParser extends AbstractMessageParser { - - private final int TYPE = 2; - - public PCEPKeepAliveMessageParser(HandlerRegistry registry) { - super(registry); - } +public class PCEPKeepAliveMessageParser implements PCEPMessageParser { @Override - public void serializeMessage(Message message, ByteBuf buffer) { - if (!(message instanceof KeepaliveMessage)) - throw new IllegalArgumentException("Wrong instance of Message. Passed instance of " + message.getClass() - + ". Nedded KeepaliveMessage."); - - buffer.writeBytes(new byte[0]); - } + public byte[] put(final Message msg) { + if (!(msg instanceof KeepaliveMessage)) + throw new IllegalArgumentException("Wrong instance of PCEPMessage. Passed instance of " + msg.getClass() + + ". Nedded PCEPKeepAliveMessage."); - @Override - public KeepaliveMessage parseMessage(byte[] buffer) { - return new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build(); - } - - @Override - public int getMessageType() { - return TYPE; + return new byte[0]; } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPKeepAliveMessageValidator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPKeepAliveMessageValidator.java new file mode 100644 index 0000000000..bc89130c69 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPKeepAliveMessageValidator.java @@ -0,0 +1,38 @@ +/* + * 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.message; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPMessageValidator; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder; +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.keepalive.message.KeepaliveMessageBuilder; + +/** + * PCEPKeepAliveMessage validator. Validates message integrity. + */ +public class PCEPKeepAliveMessageValidator extends PCEPMessageValidator { + + @Override + public List validate(final List objects) throws PCEPDeserializerException { + if (objects != null && !objects.isEmpty()) + throw new PCEPDeserializerException("KeepAlive message has content."); + + return new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build()); + } + }; + } +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPNotificationMessageParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPNotificationMessageParser.java index c39589f079..67c215953d 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPNotificationMessageParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPNotificationMessageParser.java @@ -7,160 +7,22 @@ */ package org.opendaylight.protocol.pcep.impl.message; -import io.netty.buffer.ByteBuf; - -import java.util.Arrays; -import java.util.List; - -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.PCEPErrorMapping; -import org.opendaylight.protocol.pcep.PCEPErrors; -import org.opendaylight.protocol.pcep.UnknownObject; -import org.opendaylight.protocol.pcep.spi.AbstractMessageParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; -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.message.rev131007.PcntfBuilder; +import org.opendaylight.protocol.pcep.impl.PCEPMessageParser; +import org.opendaylight.protocol.pcep.impl.PCEPObjectFactory; +import org.opendaylight.protocol.pcep.message.PCEPNotificationMessage; 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.NotificationObject; -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.PcntfMessage; -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.pcerr.message.PcerrMessageBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.PcntfMessageBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Notifications; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Rps; - -import com.google.common.collect.Lists; /** - * Parser for {@link PcntfMessage} + * Parser for {@link org.opendaylight.protocol.pcep.message.PCEPNotificationMessage PCEPNotificationMessage} */ -public class PCEPNotificationMessageParser extends AbstractMessageParser { - - private final int TYPE = 5; - - public PCEPNotificationMessageParser(final HandlerRegistry registry) { - super(registry); - } - - @Override - public void serializeMessage(final Message message, final ByteBuf buffer) { - if (!(message instanceof PcntfMessage)) - throw new IllegalArgumentException("Wrong instance of Message. Passed instance of " + message.getClass() - + ". Needed PcntfMessage."); - final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.PcntfMessage msg = ((PcntfMessage) message).getPcntfMessage(); - - for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.Notifications n : msg.getNotifications()) { - if (n.getRps() != null && !n.getRps().isEmpty()) { - for (final Rps rps : n.getRps()) { - buffer.writeBytes(serializeObject(rps)); - } - } - if (n.getNotifications() == null || n.getNotifications().isEmpty()) { - throw new IllegalArgumentException("Message must contain at least one notification object"); - } else { - for (final Notifications not : n.getNotifications()) { - buffer.writeBytes(serializeObject(not)); - } - } - } - } +public class PCEPNotificationMessageParser implements PCEPMessageParser { @Override - public Message parseMessage(final byte[] buffer) throws PCEPDeserializerException, PCEPDocumentedException { - if (buffer == null || buffer.length == 0) { - throw new PCEPDeserializerException("Notification message cannot be empty."); - } - final List objs = parseObjects(buffer); - - return validate(objs); - } - - public Message validate(final List objects) throws PCEPDeserializerException { - if (objects == null) - throw new IllegalArgumentException("Passed list can't be null."); - - final PCEPErrorMapping maping = PCEPErrorMapping.getInstance(); - - final List compositeNotifications = Lists.newArrayList(); - - while (!objects.isEmpty()) { - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.Notifications comObj; - try { - comObj = getValidNotificationComposite(objects); - } catch (final PCEPDocumentedException e) { - final PcerrMessageBuilder b = new PcerrMessageBuilder(); - b.setErrors(Arrays.asList(new ErrorsBuilder().setType(maping.getFromErrorsEnum(e.getError()).type).setValue( - maping.getFromErrorsEnum(e.getError()).value).build())); - return new PcerrBuilder().setPcerrMessage(b.build()).build(); - } + public byte[] put(final Message msg) { + if (!(msg instanceof PCEPNotificationMessage)) + throw new IllegalArgumentException("Wrong instance of PCEPMessage. Passed instance of " + msg.getClass() + + ". Needed PCEPNotificationMessage."); - if (comObj == null) - break; - - compositeNotifications.add(comObj); - } - - if (compositeNotifications.isEmpty()) - throw new PCEPDeserializerException("Atleast one CompositeNotifiObject is mandatory."); - - if (!objects.isEmpty()) - throw new PCEPDeserializerException("Unprocessed Objects: " + objects); - - return new PcntfBuilder().setPcntfMessage(new PcntfMessageBuilder().setNotifications(compositeNotifications).build()).build(); - } - - private static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.Notifications getValidNotificationComposite( - final List objects) throws PCEPDocumentedException { - final List requestParameters = Lists.newArrayList(); - final List notifications = Lists.newArrayList(); - Object obj; - - int state = 1; - while (!objects.isEmpty()) { - obj = objects.get(0); - - if (obj instanceof UnknownObject) - throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError()); - - switch (state) { - case 1: - state = 2; - if (obj instanceof RpObject) { - final RpObject rp = (RpObject) obj; - if (rp.isProcessingRule()) - throw new PCEPDocumentedException("Invalid setting of P flag.", PCEPErrors.P_FLAG_NOT_SET); - requestParameters.add((Rps) rp); - state = 1; - break; - } - case 2: - if (obj instanceof NotificationObject) { - final NotificationObject n = (NotificationObject) obj; - notifications.add((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.notifications.Notifications) n); - state = 2; - break; - } - state = 3; - } - - if (state == 3) - break; - - objects.remove(obj); - } - - if (notifications.isEmpty()) - return null; - - return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.NotificationsBuilder().setNotifications( - notifications).setRps(requestParameters).build(); - } - - @Override - public int getMessageType() { - return this.TYPE; + return PCEPObjectFactory.put(((PCEPNotificationMessage) msg).getAllObjects()); } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPNotificationMessageValidator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPNotificationMessageValidator.java new file mode 100644 index 0000000000..21324160a2 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPNotificationMessageValidator.java @@ -0,0 +1,105 @@ +/* + * 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.message; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPMessageValidator; +import org.opendaylight.protocol.pcep.impl.object.UnknownObject; +import org.opendaylight.protocol.pcep.message.PCEPErrorMessage; +import org.opendaylight.protocol.pcep.message.PCEPNotificationMessage; +import org.opendaylight.protocol.pcep.object.CompositeNotifyObject; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPNotificationObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; + +/** + * PCEPNotificationMessage validator. Validates message integrity. + */ +public class PCEPNotificationMessageValidator extends PCEPMessageValidator { + + @Override + public List validate(final List objects) throws PCEPDeserializerException { + if (objects == null) + throw new IllegalArgumentException("Passed list can't be null."); + + final List compositeNotifications = new ArrayList(); + + while (!objects.isEmpty()) { + CompositeNotifyObject comObj; + try { + comObj = getValidNotificationComposite(objects); + } catch (final PCEPDocumentedException e) { + return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(e.getError()))); + } + + if (comObj == null) + break; + + compositeNotifications.add(comObj); + } + + if (compositeNotifications.isEmpty()) + throw new PCEPDeserializerException("Atleast one CompositeNotifiObject is mandatory."); + + if (!objects.isEmpty()) + throw new PCEPDeserializerException("Unprocessed Objects: " + objects); + + return Arrays.asList((Message) new PCEPNotificationMessage(compositeNotifications)); + } + + private static CompositeNotifyObject getValidNotificationComposite(final List objects) throws PCEPDocumentedException { + final List requestParameters = new ArrayList(); + final List notifications = new ArrayList(); + PCEPObject obj; + + int state = 1; + while (!objects.isEmpty()) { + obj = objects.get(0); + + if (obj instanceof UnknownObject) + throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError()); + + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPRequestParameterObject) { + if (((PCEPRequestParameterObject) obj).isProcessed()) + throw new PCEPDocumentedException("Invalid setting of P flag.", PCEPErrors.P_FLAG_NOT_SET); + requestParameters.add((PCEPRequestParameterObject) obj); + state = 1; + break; + } + case 2: + if (obj instanceof PCEPNotificationObject) { + notifications.add((PCEPNotificationObject) obj); + state = 2; + break; + } + state = 3; + } + + if (state == 3) + break; + + objects.remove(obj); + } + + if (notifications.isEmpty()) + return null; + + return new CompositeNotifyObject(requestParameters, notifications); + } +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPOpenMessageParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPOpenMessageParser.java index 4e63577fcd..c262edf083 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPOpenMessageParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPOpenMessageParser.java @@ -7,76 +7,23 @@ */ package org.opendaylight.protocol.pcep.impl.message; -import io.netty.buffer.ByteBuf; - -import java.util.List; - -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractMessageParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import org.opendaylight.protocol.pcep.impl.PCEPMessageParser; +import org.opendaylight.protocol.pcep.impl.PCEPObjectFactory; +import org.opendaylight.protocol.pcep.message.PCEPOpenMessage; 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.OpenMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessageBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.open.message.Open; /** - * Parser for {@link OpenMessage} + * Parser for {@link org.opendaylight.protocol.pcep.message.PCEPOpenMessage PCEPOpenMessage} */ -public class PCEPOpenMessageParser extends AbstractMessageParser { - - private final int TYPE = 1; - - public PCEPOpenMessageParser(final HandlerRegistry registry) { - super(registry); - } - - @Override - public void serializeMessage(final Message message, final ByteBuf buffer) { - if (!(message instanceof OpenMessage)) - throw new IllegalArgumentException("Wrong instance of Message. Passed instance " + message.getClass() + ". Nedded OpenMessage."); - final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage open = ((OpenMessage) message).getOpenMessage(); - - if (open.getOpen() == null) { - throw new IllegalArgumentException("Open Object must be present in Open Message."); - } - - buffer.writeBytes(serializeObject(open.getOpen())); - } +public class PCEPOpenMessageParser implements PCEPMessageParser { @Override - public OpenMessage parseMessage(final byte[] buffer) throws PCEPDeserializerException, PCEPDocumentedException { - if (buffer == null || buffer.length == 0) { - throw new PCEPDeserializerException("Open message doesn't contain OPEN object."); - } - final List objs = parseObjects(buffer); + public byte[] put(final Message msg) { + if (!(msg instanceof PCEPOpenMessage)) + throw new IllegalArgumentException("Wrong instance of PCEPMessage. Passed instance " + msg.getClass() + + ". Nedded PCEPOpenMessage."); - return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder().setOpenMessage( - validate(objs)).build(); + return PCEPObjectFactory.put(((PCEPOpenMessage) msg).getAllObjects()); } - private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage validate( - final List objects) throws PCEPDeserializerException { - if (objects == null) - throw new IllegalArgumentException("Passed list can't be null."); - - if (objects.isEmpty() || !(objects.get(0) instanceof Open)) - throw new PCEPDeserializerException("Open message doesn't contain OPEN object."); - - final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage msg = new OpenMessageBuilder().setOpen( - (Open) objects.get(0)).build(); - - objects.remove(0); - - if (!objects.isEmpty()) - throw new PCEPDeserializerException("Unprocessed Objects: " + objects); - - return msg; - } - - @Override - public int getMessageType() { - return this.TYPE; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPOpenMessageValidator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPOpenMessageValidator.java new file mode 100644 index 0000000000..6ef9841bfd --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPOpenMessageValidator.java @@ -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.pcep.impl.message; + +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPMessageValidator; +import org.opendaylight.protocol.pcep.message.PCEPOpenMessage; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; + +/** + * PCEPOpenMessage validator. Validates message integrity. + */ +public class PCEPOpenMessageValidator extends PCEPMessageValidator { + + @Override + public List validate(final List objects) throws PCEPDeserializerException { + if (objects == null) + throw new IllegalArgumentException("Passed list can't be null."); + + if (objects.isEmpty() || !(objects.get(0) instanceof PCEPOpenObject)) + throw new PCEPDeserializerException("Open message doesn't contain OPEN object."); + + final PCEPOpenMessage msg = new PCEPOpenMessage((PCEPOpenObject) objects.get(0)); + objects.remove(0); + + if (!objects.isEmpty()) + throw new PCEPDeserializerException("Unprocessed Objects: " + objects); + + return new ArrayList() { + private static final long serialVersionUID = 1L; + { + this.add(msg); + } + }; + } +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReplyMessageParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReplyMessageParser.java index ac27bcf878..0245720c26 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReplyMessageParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReplyMessageParser.java @@ -7,41 +7,23 @@ */ package org.opendaylight.protocol.pcep.impl.message; -import io.netty.buffer.ByteBuf; - -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.spi.AbstractMessageParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import org.opendaylight.protocol.pcep.impl.PCEPMessageParser; +import org.opendaylight.protocol.pcep.impl.PCEPObjectFactory; +import org.opendaylight.protocol.pcep.message.PCEPReplyMessage; 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.PcrepMessage; /** - * Parser for {@link PcrepMessage} + * Parser for {@link org.opendaylight.protocol.pcep.message.PCEPReplyMessage PCEPReplyMessage} */ -// FIXME: finish -public class PCEPReplyMessageParser extends AbstractMessageParser { - - private final int TYPE = 4; - - public PCEPReplyMessageParser(HandlerRegistry registry) { - super(registry); - } +public class PCEPReplyMessageParser implements PCEPMessageParser { @Override - public void serializeMessage(Message message, ByteBuf buffer) { - if (!(message instanceof PcrepMessage)) - throw new IllegalArgumentException("Wrong instance of Message. Passed instance of " + message.getClass() - + ". Nedded PcrepMessage."); - - } + public byte[] put(final Message msg) { + if (!(msg instanceof PCEPReplyMessage)) + throw new IllegalArgumentException("Wrong instance of PCEPMessage. Passed instance of " + msg.getClass() + + ". Nedded PCEPReplyMessage."); - @Override - public PcrepMessage parseMessage(byte[] buffer) throws PCEPDeserializerException { - return null; + return PCEPObjectFactory.put(((PCEPReplyMessage) msg).getAllObjects()); } - @Override - public int getMessageType() { - return TYPE; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReplyMessageValidator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReplyMessageValidator.java index b1653e3809..a1c415f5d0 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReplyMessageValidator.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReplyMessageValidator.java @@ -7,297 +7,318 @@ */ package org.opendaylight.protocol.pcep.impl.message; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPMessageValidator; +import org.opendaylight.protocol.pcep.impl.object.UnknownObject; +import org.opendaylight.protocol.pcep.message.PCEPErrorMessage; +import org.opendaylight.protocol.pcep.message.PCEPReplyMessage; +import org.opendaylight.protocol.pcep.object.CompositeErrorObject; +import org.opendaylight.protocol.pcep.object.CompositePathObject; +import org.opendaylight.protocol.pcep.object.CompositeReplySvecObject; +import org.opendaylight.protocol.pcep.object.CompositeResponseObject; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPIncludeRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPLspObject; +import org.opendaylight.protocol.pcep.object.PCEPLspaObject; +import org.opendaylight.protocol.pcep.object.PCEPMetricObject; +import org.opendaylight.protocol.pcep.object.PCEPNoPathObject; +import org.opendaylight.protocol.pcep.object.PCEPObjectiveFunctionObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject; +import org.opendaylight.protocol.pcep.object.PCEPSvecObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; + +import com.google.common.collect.Lists; /** * PCEPReplyMessage validator. Validates message integrity. */ -// FIXME: merge with parser -class PCEPReplyMessageValidator { - - // private static class SubReplyValidator { - // - // private boolean requestRejected = true; - // - // private List msgs = Lists.newArrayList(); - // - // private PCEPRequestParameterObject rpObj; - // - // private PCEPNoPathObject noPath; - // private PCEPLspObject lsp; - // private PCEPLspaObject lspa; - // private PCEPRequestedPathBandwidthObject bandwidth; - // private List metrics; - // private PCEPIncludeRouteObject iro; - // private List paths; - // - // private void init() { - // this.requestRejected = false; - // this.msgs = Lists.newArrayList(); - // - // this.noPath = null; - // this.lsp = null; - // this.lspa = null; - // this.iro = null; - // this.rpObj = null; - // this.metrics = new ArrayList(); - // this.paths = new ArrayList(); - // } - // - // public List validate(final List objects, final List svecList) { - // this.init(); - // - // if (!(objects.get(0) instanceof PCEPRequestParameterObject)) - // return null; - // - // final PCEPRequestParameterObject rpObj = (PCEPRequestParameterObject) objects.get(0); - // objects.remove(0); - // - // Object obj; - // int state = 1; - // while (!objects.isEmpty()) { - // obj = objects.get(0); - // if (obj instanceof UnknownObject) { - // if (((UnknownObject) obj).isProcessingRule()) { - // this.msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new - // PCEPErrorObject(((UnknownObject) obj).getError())))); - // this.requestRejected = true; - // } - // - // objects.remove(0); - // continue; - // } - // - // switch (state) { - // case 1: - // state = 2; - // if (obj instanceof PCEPNoPathObject) { - // this.noPath = (PCEPNoPathObject) obj; - // break; - // } - // case 2: - // state = 3; - // if (obj instanceof PCEPLspObject) { - // this.lsp = (PCEPLspObject) obj; - // break; - // } - // case 3: - // state = 4; - // if (obj instanceof PCEPLspaObject) { - // this.lspa = (PCEPLspaObject) obj; - // break; - // } - // case 4: - // state = 5; - // if (obj instanceof PCEPRequestedPathBandwidthObject) { - // this.bandwidth = (PCEPRequestedPathBandwidthObject) obj; - // break; - // } - // case 5: - // state = 6; - // if (obj instanceof PCEPMetricObject) { - // this.metrics.add((PCEPMetricObject) obj); - // state = 5; - // break; - // } - // case 6: - // state = 7; - // if (obj instanceof PCEPIncludeRouteObject) { - // this.iro = (PCEPIncludeRouteObject) obj; - // state = 8; - // break; - // } - // } - // - // if (state == 7) - // break; - // - // objects.remove(0); - // - // if (state == 8) - // break; - // } - // - // if (!objects.isEmpty()) { - // CompositePathObject path = this.getValidCompositePath(objects); - // while (path != null) { - // this.paths.add(path); - // if (objects.isEmpty()) - // break; - // path = this.getValidCompositePath(objects); - // } - // } - // - // if (!this.requestRejected) { - // this.msgs.add(new PCEPReplyMessage(Collections.unmodifiableList(Arrays.asList(new CompositeResponseObject(rpObj, - // this.noPath, this.lsp, this.lspa, this.bandwidth, this.metrics, this.iro, this.paths))), - // Collections.unmodifiableList(svecList))); - // } - // - // return this.msgs; - // } - // - // private CompositePathObject getValidCompositePath(final List objects) { - // if (!(objects.get(0) instanceof PCEPExplicitRouteObject)) - // return null; - // - // final PCEPExplicitRouteObject explicitRoute = (PCEPExplicitRouteObject) objects.get(0); - // objects.remove(0); - // - // PCEPLspaObject pathLspa = null; - // PCEPRequestedPathBandwidthObject pathBandwidth = null; - // final List pathMetrics = new ArrayList(); - // PCEPIncludeRouteObject pathIro = null; - // - // Object obj; - // int state = 1; - // while (!objects.isEmpty()) { - // obj = objects.get(0); - // if (obj instanceof UnknownObject) { - // if (((UnknownObject) obj).isProcessingRule()) { - // this.msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(this.rpObj, false), new - // PCEPErrorObject(((UnknownObject) obj).getError())))); - // this.requestRejected = true; - // } - // objects.remove(0); - // continue; - // } - // - // switch (state) { - // case 1: - // state = 2; - // if (obj instanceof PCEPLspaObject) { - // pathLspa = (PCEPLspaObject) obj; - // break; - // } - // case 2: - // state = 3; - // if (obj instanceof PCEPRequestedPathBandwidthObject) { - // pathBandwidth = (PCEPRequestedPathBandwidthObject) obj; - // break; - // } - // case 3: - // state = 4; - // if (obj instanceof PCEPMetricObject) { - // pathMetrics.add((PCEPMetricObject) obj); - // state = 3; - // break; - // } - // case 4: - // state = 5; - // if (obj instanceof PCEPIncludeRouteObject) { - // pathIro = (PCEPIncludeRouteObject) obj; - // state = 6; - // break; - // } - // - // } - // - // if (state == 5) - // break; - // - // objects.remove(0); - // - // if (state == 6) - // break; - // } - // - // return new CompositePathObject(explicitRoute, pathLspa, pathBandwidth, pathMetrics, pathIro); - // } - // } - // - // @Override - // public List validate(final List objects) throws PCEPDeserializerException { - // if (objects == null) - // throw new IllegalArgumentException("Passed list can't be null."); - // - // final List msgs = Lists.newArrayList(); - // final List svecList = new ArrayList(); - // - // CompositeReplySvecObject svecComp; - // while (!objects.isEmpty()) { - // try { - // if ((svecComp = this.getValidSvecComposite(objects)) == null) - // break; - // } catch (final PCEPDocumentedException e) { - // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(e.getError()))); - // return msgs; - // } - // - // svecList.add(svecComp); - // } - // - // List subMessages; - // final SubReplyValidator subValidator = new SubReplyValidator(); - // while (!objects.isEmpty()) { - // subMessages = subValidator.validate(objects, svecList); - // if (subMessages == null) - // break; - // msgs.addAll(subMessages); - // } - // - // if (msgs.isEmpty()) { - // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.RP_MISSING))); - // return msgs; - // } - // - // if (!objects.isEmpty()) - // throw new PCEPDeserializerException("Unprocessed Objects: " + objects); - // - // return msgs; - // } - // - // private CompositeReplySvecObject getValidSvecComposite(final List objects) throws PCEPDocumentedException - // { - // if (objects == null) - // throw new IllegalArgumentException("List cannot be null."); - // - // if (!(objects.get(0) instanceof PCEPSvecObject)) - // return null; - // - // final PCEPSvecObject svec = (PCEPSvecObject) objects.get(0); - // objects.remove(0); - // - // PCEPObjectiveFunctionObject of = null; - // final List metrics = new ArrayList(); - // - // Object obj; - // int state = 1; - // while (!objects.isEmpty()) { - // obj = objects.get(0); - // - // if (obj instanceof UnknownObject) - // throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError()); - // - // switch (state) { - // case 1: - // state = 2; - // if (obj instanceof PCEPObjectiveFunctionObject) { - // of = (PCEPObjectiveFunctionObject) obj; - // break; - // } - // case 2: - // state = 3; - // if (obj instanceof PCEPMetricObject) { - // metrics.add((PCEPMetricObject) obj); - // state = 2; - // break; - // } - // } - // - // if (state == 3) - // break; - // - // objects.remove(0); - // } - // - // return new CompositeReplySvecObject(svec, of, metrics); - // } - // - // private static PCEPRequestParameterObject copyRP(final PCEPRequestParameterObject origRp, final boolean - // processed) { - // return new PCEPRequestParameterObject(origRp.isLoose(), origRp.isBidirectional(), origRp.isReoptimized(), - // origRp.isMakeBeforeBreak(), origRp.isReportRequestOrder(), origRp.isSuplyOFOnResponse(), - // origRp.isFragmentation(), origRp.isP2mp(), origRp.isEroCompression(), origRp.getPriority(), - // origRp.getRequestID(), origRp.getTlvs(), processed, origRp.isIgnored()); - // } +public class PCEPReplyMessageValidator extends PCEPMessageValidator { + + private static class SubReplyValidator { + + private boolean requestRejected = true; + + private List msgs = Lists.newArrayList(); + + private PCEPRequestParameterObject rpObj; + + private PCEPNoPathObject noPath; + private PCEPLspObject lsp; + private PCEPLspaObject lspa; + private PCEPRequestedPathBandwidthObject bandwidth; + private List metrics; + private PCEPIncludeRouteObject iro; + private List paths; + + private void init() { + this.requestRejected = false; + this.msgs = Lists.newArrayList(); + + this.noPath = null; + this.lsp = null; + this.lspa = null; + this.iro = null; + this.rpObj = null; + this.metrics = new ArrayList(); + this.paths = new ArrayList(); + } + + public List validate(final List objects, final List svecList) { + this.init(); + + if (!(objects.get(0) instanceof PCEPRequestParameterObject)) + return null; + + final PCEPRequestParameterObject rpObj = (PCEPRequestParameterObject) objects.get(0); + objects.remove(0); + + PCEPObject obj; + int state = 1; + while (!objects.isEmpty()) { + obj = objects.get(0); + if (obj instanceof UnknownObject) { + if (((UnknownObject) obj).isProcessed()) { + this.msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new PCEPErrorObject(((UnknownObject) obj).getError())))); + this.requestRejected = true; + } + + objects.remove(0); + continue; + } + + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPNoPathObject) { + this.noPath = (PCEPNoPathObject) obj; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPLspObject) { + this.lsp = (PCEPLspObject) obj; + break; + } + case 3: + state = 4; + if (obj instanceof PCEPLspaObject) { + this.lspa = (PCEPLspaObject) obj; + break; + } + case 4: + state = 5; + if (obj instanceof PCEPRequestedPathBandwidthObject) { + this.bandwidth = (PCEPRequestedPathBandwidthObject) obj; + break; + } + case 5: + state = 6; + if (obj instanceof PCEPMetricObject) { + this.metrics.add((PCEPMetricObject) obj); + state = 5; + break; + } + case 6: + state = 7; + if (obj instanceof PCEPIncludeRouteObject) { + this.iro = (PCEPIncludeRouteObject) obj; + state = 8; + break; + } + } + + if (state == 7) + break; + + objects.remove(0); + + if (state == 8) + break; + } + + if (!objects.isEmpty()) { + CompositePathObject path = this.getValidCompositePath(objects); + while (path != null) { + this.paths.add(path); + if (objects.isEmpty()) + break; + path = this.getValidCompositePath(objects); + } + } + + if (!this.requestRejected) { + this.msgs.add(new PCEPReplyMessage(Collections.unmodifiableList(Arrays.asList(new CompositeResponseObject(rpObj, this.noPath, this.lsp, this.lspa, this.bandwidth, this.metrics, this.iro, this.paths))), Collections.unmodifiableList(svecList))); + } + + return this.msgs; + } + + private CompositePathObject getValidCompositePath(final List objects) { + if (!(objects.get(0) instanceof PCEPExplicitRouteObject)) + return null; + + final PCEPExplicitRouteObject explicitRoute = (PCEPExplicitRouteObject) objects.get(0); + objects.remove(0); + + PCEPLspaObject pathLspa = null; + PCEPRequestedPathBandwidthObject pathBandwidth = null; + final List pathMetrics = new ArrayList(); + PCEPIncludeRouteObject pathIro = null; + + PCEPObject obj; + int state = 1; + while (!objects.isEmpty()) { + obj = objects.get(0); + if (obj instanceof UnknownObject) { + if (((UnknownObject) obj).isProcessed()) { + this.msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(this.rpObj, false), new PCEPErrorObject(((UnknownObject) obj).getError())))); + this.requestRejected = true; + } + objects.remove(0); + continue; + } + + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPLspaObject) { + pathLspa = (PCEPLspaObject) obj; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPRequestedPathBandwidthObject) { + pathBandwidth = (PCEPRequestedPathBandwidthObject) obj; + break; + } + case 3: + state = 4; + if (obj instanceof PCEPMetricObject) { + pathMetrics.add((PCEPMetricObject) obj); + state = 3; + break; + } + case 4: + state = 5; + if (obj instanceof PCEPIncludeRouteObject) { + pathIro = (PCEPIncludeRouteObject) obj; + state = 6; + break; + } + + } + + if (state == 5) + break; + + objects.remove(0); + + if (state == 6) + break; + } + + return new CompositePathObject(explicitRoute, pathLspa, pathBandwidth, pathMetrics, pathIro); + } + } + + @Override + public List validate(final List objects) throws PCEPDeserializerException { + if (objects == null) + throw new IllegalArgumentException("Passed list can't be null."); + + final List msgs = Lists.newArrayList(); + final List svecList = new ArrayList(); + + CompositeReplySvecObject svecComp; + while (!objects.isEmpty()) { + try { + if ((svecComp = this.getValidSvecComposite(objects)) == null) + break; + } catch (final PCEPDocumentedException e) { + msgs.add(new PCEPErrorMessage(new PCEPErrorObject(e.getError()))); + return msgs; + } + + svecList.add(svecComp); + } + + List subMessages; + final SubReplyValidator subValidator = new SubReplyValidator(); + while (!objects.isEmpty()) { + subMessages = subValidator.validate(objects, svecList); + if (subMessages == null) + break; + msgs.addAll(subMessages); + } + + if (msgs.isEmpty()) { + msgs.add(new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.RP_MISSING))); + return msgs; + } + + if (!objects.isEmpty()) + throw new PCEPDeserializerException("Unprocessed Objects: " + objects); + + return msgs; + } + + private CompositeReplySvecObject getValidSvecComposite(final List objects) throws PCEPDocumentedException { + if (objects == null) + throw new IllegalArgumentException("List cannot be null."); + + if (!(objects.get(0) instanceof PCEPSvecObject)) + return null; + + final PCEPSvecObject svec = (PCEPSvecObject) objects.get(0); + objects.remove(0); + + PCEPObjectiveFunctionObject of = null; + final List metrics = new ArrayList(); + + PCEPObject obj; + int state = 1; + while (!objects.isEmpty()) { + obj = objects.get(0); + + if (obj instanceof UnknownObject) + throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError()); + + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPObjectiveFunctionObject) { + of = (PCEPObjectiveFunctionObject) obj; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPMetricObject) { + metrics.add((PCEPMetricObject) obj); + state = 2; + break; + } + } + + if (state == 3) + break; + + objects.remove(0); + } + + return new CompositeReplySvecObject(svec, of, metrics); + } + + private static PCEPRequestParameterObject copyRP(final PCEPRequestParameterObject origRp, final boolean processed) { + return new PCEPRequestParameterObject(origRp.isLoose(), origRp.isBidirectional(), origRp.isReoptimized(), origRp.isMakeBeforeBreak(), origRp.isReportRequestOrder(), origRp.isSuplyOFOnResponse(), origRp.isFragmentation(), origRp.isP2mp(), origRp.isEroCompression(), origRp.getPriority(), origRp.getRequestID(), origRp.getTlvs(), processed, origRp.isIgnored()); + } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReportMessageParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReportMessageParser.java index 0d1828f794..64f664023b 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReportMessageParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReportMessageParser.java @@ -7,40 +7,23 @@ */ package org.opendaylight.protocol.pcep.impl.message; -import io.netty.buffer.ByteBuf; - -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.spi.AbstractMessageParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import org.opendaylight.protocol.pcep.impl.PCEPMessageParser; +import org.opendaylight.protocol.pcep.impl.PCEPObjectFactory; +import org.opendaylight.protocol.pcep.message.PCEPReportMessage; 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; /** - * Parser for {@link PcrptMessage} + * Parser for {@link org.opendaylight.protocol.pcep.message.PCEPReportMessage PCEPReportMessage} */ -// FIXME : finish -public class PCEPReportMessageParser extends AbstractMessageParser { - - private final int TYPE = 10; - - public PCEPReportMessageParser(HandlerRegistry registry) { - super(registry); - } +public class PCEPReportMessageParser implements PCEPMessageParser { @Override - public void serializeMessage(Message message, ByteBuf buffer) { - if (!(message instanceof PcrptMessage)) - throw new IllegalArgumentException("Wrong instance of Message. Passed instance of " + message.getClass() - + ". Nedded PcrptMessage."); - } + public byte[] put(final Message msg) { + if (!(msg instanceof PCEPReportMessage)) + throw new IllegalArgumentException("Wrong instance of PCEPMessage. Passed instance of " + msg.getClass() + + ". Nedded PCEPReportMessage."); - @Override - public PcrptMessage parseMessage(byte[] buffer) throws PCEPDeserializerException { - return null; + return PCEPObjectFactory.put(((PCEPReportMessage) msg).getAllObjects()); } - @Override - public int getMessageType() { - return TYPE; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReportMessageValidator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReportMessageValidator.java index 536be39c31..f7794ae6a0 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReportMessageValidator.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPReportMessageValidator.java @@ -7,120 +7,139 @@ */ package org.opendaylight.protocol.pcep.impl.message; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPMessageValidator; +import org.opendaylight.protocol.pcep.impl.object.UnknownObject; +import org.opendaylight.protocol.pcep.message.PCEPErrorMessage; +import org.opendaylight.protocol.pcep.message.PCEPReportMessage; +import org.opendaylight.protocol.pcep.object.CompositeRptPathObject; +import org.opendaylight.protocol.pcep.object.CompositeStateReportObject; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPExistingPathBandwidthObject; +import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPLspObject; +import org.opendaylight.protocol.pcep.object.PCEPLspaObject; +import org.opendaylight.protocol.pcep.object.PCEPMetricObject; +import org.opendaylight.protocol.pcep.object.PCEPReportedRouteObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; /** * PCEPReportMessage validator. Validates message integrity. */ -// FIXME: merge with parser -class PCEPReportMessageValidator { - // - // @Override - // public List validate(final List objects) throws PCEPDeserializerException { - // if (objects == null) - // throw new IllegalArgumentException("Passed list can't be null."); - // - // final List report = new ArrayList(); - // - // while (!objects.isEmpty()) { - // if (objects.get(0) instanceof UnknownObject) - // return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(((UnknownObject) - // objects.get(0)).getError()))); - // - // if (!(objects.get(0) instanceof PCEPLspObject)) - // return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.LSP_MISSING))); - // - // final PCEPLspObject lsp = (PCEPLspObject) objects.get(0); - // objects.remove(0); - // - // final List paths = new ArrayList(); - // - // if (!objects.isEmpty()) { - // try { - // CompositeRptPathObject path; - // path = this.getValidCompositePath(objects); - // while (path != null) { - // paths.add(path); - // if (objects.isEmpty()) - // break; - // path = this.getValidCompositePath(objects); - // } - // } catch (final PCEPDocumentedException e) { - // return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(e.getError()))); - // } - // } - // - // report.add(new CompositeStateReportObject(lsp, paths)); - // } - // - // if (report.isEmpty()) - // throw new PCEPDeserializerException("Atleast one CompositeStateReportObject is mandatory."); - // - // if (!objects.isEmpty()) { - // if (objects.get(0) instanceof UnknownObject) - // return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(((UnknownObject) - // objects.get(0)).getError()))); - // throw new PCEPDeserializerException("Unprocessed Objects: " + objects); - // } - // - // return Arrays.asList((Message) new PCEPReportMessage(report)); - // } - // - // private CompositeRptPathObject getValidCompositePath(final List objects) throws PCEPDocumentedException { - // if (objects.get(0) instanceof UnknownObject) - // throw new PCEPDocumentedException("Unknown object", ((UnknownObject) objects.get(0)).getError()); - // if (!(objects.get(0) instanceof PCEPExplicitRouteObject)) - // return null; - // final PCEPExplicitRouteObject explicitRoute = (PCEPExplicitRouteObject) objects.get(0); - // objects.remove(0); - // - // PCEPLspaObject pathLspa = null; - // PCEPExistingPathBandwidthObject pathBandwidth = null; - // PCEPReportedRouteObject pathRro = null; - // final List pathMetrics = new ArrayList(); - // - // Object obj; - // int state = 1; - // while (!objects.isEmpty()) { - // obj = objects.get(0); - // if (obj instanceof UnknownObject) { - // throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError()); - // } - // - // switch (state) { - // case 1: - // state = 2; - // if (obj instanceof PCEPLspaObject) { - // pathLspa = (PCEPLspaObject) obj; - // break; - // } - // case 2: - // state = 3; - // if (obj instanceof PCEPExistingPathBandwidthObject) { - // pathBandwidth = (PCEPExistingPathBandwidthObject) obj; - // break; - // } - // - // case 3: - // state = 4; - // if (obj instanceof PCEPReportedRouteObject) { - // pathRro = (PCEPReportedRouteObject) obj; - // break; - // } - // case 4: - // state = 5; - // if (obj instanceof PCEPMetricObject) { - // pathMetrics.add((PCEPMetricObject) obj); - // state = 4; - // break; - // } - // } - // - // if (state == 5) - // break; - // - // objects.remove(0); - // } - // - // return new CompositeRptPathObject(explicitRoute, pathLspa, pathBandwidth, pathRro, pathMetrics); - // } +public class PCEPReportMessageValidator extends PCEPMessageValidator { + + @Override + public List validate(final List objects) throws PCEPDeserializerException { + if (objects == null) + throw new IllegalArgumentException("Passed list can't be null."); + + final List report = new ArrayList(); + + while (!objects.isEmpty()) { + if (objects.get(0) instanceof UnknownObject) + return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(((UnknownObject) objects.get(0)).getError()))); + + if (!(objects.get(0) instanceof PCEPLspObject)) + return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.LSP_MISSING))); + + final PCEPLspObject lsp = (PCEPLspObject) objects.get(0); + objects.remove(0); + + final List paths = new ArrayList(); + + if (!objects.isEmpty()) { + try { + CompositeRptPathObject path; + path = this.getValidCompositePath(objects); + while (path != null) { + paths.add(path); + if (objects.isEmpty()) + break; + path = this.getValidCompositePath(objects); + } + } catch (final PCEPDocumentedException e) { + return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(e.getError()))); + } + } + + report.add(new CompositeStateReportObject(lsp, paths)); + } + + if (report.isEmpty()) + throw new PCEPDeserializerException("Atleast one CompositeStateReportObject is mandatory."); + + if (!objects.isEmpty()) { + if (objects.get(0) instanceof UnknownObject) + return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(((UnknownObject) objects.get(0)).getError()))); + throw new PCEPDeserializerException("Unprocessed Objects: " + objects); + } + + return Arrays.asList((Message) new PCEPReportMessage(report)); + } + + private CompositeRptPathObject getValidCompositePath(final List objects) throws PCEPDocumentedException { + if (objects.get(0) instanceof UnknownObject) + throw new PCEPDocumentedException("Unknown object", ((UnknownObject) objects.get(0)).getError()); + if (!(objects.get(0) instanceof PCEPExplicitRouteObject)) + return null; + final PCEPExplicitRouteObject explicitRoute = (PCEPExplicitRouteObject) objects.get(0); + objects.remove(0); + + PCEPLspaObject pathLspa = null; + PCEPExistingPathBandwidthObject pathBandwidth = null; + PCEPReportedRouteObject pathRro = null; + final List pathMetrics = new ArrayList(); + + PCEPObject obj; + int state = 1; + while (!objects.isEmpty()) { + obj = objects.get(0); + if (obj instanceof UnknownObject) { + throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError()); + } + + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPLspaObject) { + pathLspa = (PCEPLspaObject) obj; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPExistingPathBandwidthObject) { + pathBandwidth = (PCEPExistingPathBandwidthObject) obj; + break; + } + + case 3: + state = 4; + if (obj instanceof PCEPReportedRouteObject) { + pathRro = (PCEPReportedRouteObject) obj; + break; + } + case 4: + state = 5; + if (obj instanceof PCEPMetricObject) { + pathMetrics.add((PCEPMetricObject) obj); + state = 4; + break; + } + } + + if (state == 5) + break; + + objects.remove(0); + } + + return new CompositeRptPathObject(explicitRoute, pathLspa, pathBandwidth, pathRro, pathMetrics); + } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java index 6d590f7c87..e0fb7f71c2 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageParser.java @@ -7,41 +7,23 @@ */ package org.opendaylight.protocol.pcep.impl.message; -import io.netty.buffer.ByteBuf; - -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.spi.AbstractMessageParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import org.opendaylight.protocol.pcep.impl.PCEPMessageParser; +import org.opendaylight.protocol.pcep.impl.PCEPObjectFactory; +import org.opendaylight.protocol.pcep.message.PCEPRequestMessage; 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.PcrepMessage; /** - * Parser for {@link PcrepMessage} + * Parser for {@link org.opendaylight.protocol.pcep.message.PCEPReportMessage PCEPReportMessage} */ -//FIXME finish -public class PCEPRequestMessageParser extends AbstractMessageParser { - - private final int TYPE = 3; - - public PCEPRequestMessageParser(HandlerRegistry registry) { - super(registry); - } +public class PCEPRequestMessageParser implements PCEPMessageParser { @Override - public void serializeMessage(Message message, ByteBuf buffer) { - if (!(message instanceof PcrepMessage)) - throw new IllegalArgumentException("Wrong instance of PCEPMessage. Passed instance of " + message.getClass() - + ". Needed PcrepMessage."); - } + public byte[] put(final Message msg) { + if (!(msg instanceof PCEPRequestMessage)) + throw new IllegalArgumentException("Wrong instance of PCEPMessage. Passed instance of " + msg.getClass() + + ". Needed PCEPRequestMessage."); - @Override - public PcrepMessage parseMessage(byte[] buffer) throws PCEPDeserializerException { - // TODO Auto-generated method stub - return null; + return PCEPObjectFactory.put(((PCEPRequestMessage) msg).getAllObjects()); } - @Override - public int getMessageType() { - return TYPE; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageValidator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageValidator.java index a35d80c9dd..7cf0213852 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageValidator.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPRequestMessageValidator.java @@ -7,255 +7,276 @@ */ package org.opendaylight.protocol.pcep.impl.message; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPMessageValidator; +import org.opendaylight.protocol.pcep.impl.object.UnknownObject; +import org.opendaylight.protocol.pcep.message.PCEPErrorMessage; +import org.opendaylight.protocol.pcep.message.PCEPRequestMessage; +import org.opendaylight.protocol.pcep.object.CompositeErrorObject; +import org.opendaylight.protocol.pcep.object.CompositeRequestObject; +import org.opendaylight.protocol.pcep.object.CompositeRequestSvecObject; +import org.opendaylight.protocol.pcep.object.PCEPClassTypeObject; +import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPExcludeRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPExistingPathBandwidthObject; +import org.opendaylight.protocol.pcep.object.PCEPGlobalConstraintsObject; +import org.opendaylight.protocol.pcep.object.PCEPIncludeRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPLoadBalancingObject; +import org.opendaylight.protocol.pcep.object.PCEPLspObject; +import org.opendaylight.protocol.pcep.object.PCEPLspaObject; +import org.opendaylight.protocol.pcep.object.PCEPMetricObject; +import org.opendaylight.protocol.pcep.object.PCEPObjectiveFunctionObject; +import org.opendaylight.protocol.pcep.object.PCEPReportedRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject; +import org.opendaylight.protocol.pcep.object.PCEPSvecObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Bandwidth; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; + +import com.google.common.collect.Lists; /** * PCEPRequestMessage validator. Validates message integrity. */ -// FIXME: merge with parser -class PCEPRequestMessageValidator { - - // @Override - // public List validate(final List objects) { - // if (objects == null) - // throw new IllegalArgumentException("Passed list can't be null."); - // - // final List msgs = Lists.newArrayList(); - // final List svecList = new ArrayList(); - // - // CompositeRequestSvecObject svecComp; - // while (!objects.isEmpty()) { - // try { - // if ((svecComp = getValidSvecComposite(objects)) == null) - // break; - // } catch (final PCEPDocumentedException e) { - // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(e.getError()))); - // return msgs; - // } - // - // svecList.add(svecComp); - // } - // - // while (!objects.isEmpty()) { - // final List requests = new ArrayList(); - // PCEPRequestParameterObject rpObj = null; - // boolean requestRejected = false; - // - // if (objects.get(0) instanceof PCEPRequestParameterObject) { - // rpObj = (PCEPRequestParameterObject) objects.get(0); - // objects.remove(rpObj); - // if (!rpObj.isProcessed()) { - // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(rpObj, new PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET)))); - // requestRejected = true; - // } - // - // } else { - // // if RP obj is missing return error only; - // msgs.clear(); - // msgs.add(new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.RP_MISSING))); - // return msgs; - // } - // - // PCEPEndPointsObject endPoints = null; - // if (objects.get(0) instanceof PCEPEndPointsObject) { - // endPoints = (PCEPEndPointsObject) objects.get(0); - // objects.remove(0); - // if (!endPoints.isProcessed()) { - // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new - // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET)))); - // requestRejected = true; - // } - // } else { - // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new - // PCEPErrorObject(PCEPErrors.END_POINTS_MISSING)))); - // requestRejected = true; - // } - // - // // ignore all continual end-points objects - // while (!objects.isEmpty() && objects.get(0) instanceof PCEPEndPointsObject) { - // objects.remove(0); - // } - // - // PCEPClassTypeObject classType = null; - // PCEPLspObject lsp = null; - // PCEPLspaObject lspa = null; - // PCEPRequestedPathBandwidthObject bandwidth = null; - // final List metrics = new ArrayList(); - // PCEPReportedRouteObject rro = null; - // PCEPExistingPathBandwidthObject rroBandwidth = null; - // PCEPIncludeRouteObject iro = null; - // PCEPLoadBalancingObject loadBalancing = null; - // - // int state = 1; - // while (!objects.isEmpty()) { - // final Object obj = objects.get(0); - // if (obj instanceof UnknownObject) { - // if (((UnknownObject) obj).isProcessingRule()) { - // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new PCEPErrorObject(((UnknownObject) - // obj).getError())))); - // requestRejected = true; - // } - // - // objects.remove(0); - // continue; - // } - // switch (state) { - // case 1: - // state = 2; - // if (obj instanceof PCEPClassTypeObject) { - // classType = (PCEPClassTypeObject) obj; - // if (!classType.isProcessed()) { - // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new - // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET)))); - // requestRejected = true; - // } - // break; - // } - // case 2: - // state = 3; - // if (obj instanceof PCEPLspObject) { - // lsp = (PCEPLspObject) obj; - // break; - // } - // case 3: - // state = 4; - // if (obj instanceof PCEPLspaObject) { - // lspa = (PCEPLspaObject) obj; - // break; - // } - // case 4: - // state = 5; - // if (obj instanceof PCEPRequestedPathBandwidthObject) { - // bandwidth = (PCEPRequestedPathBandwidthObject) obj; - // break; - // } - // case 5: - // state = 6; - // if (obj instanceof PCEPMetricObject) { - // metrics.add((PCEPMetricObject) obj); - // state = 5; - // - // break; - // } - // case 6: - // state = 8; - // if (obj instanceof PCEPReportedRouteObject) { - // rro = (PCEPReportedRouteObject) obj; - // state = 7; - // break; - // } - // case 7: - // state = 8; - // if (obj instanceof PCEPExistingPathBandwidthObject) { - // rroBandwidth = (PCEPExistingPathBandwidthObject) obj; - // break; - // } - // case 8: - // state = 9; - // if (obj instanceof PCEPIncludeRouteObject) { - // iro = (PCEPIncludeRouteObject) obj; - // break; - // } - // case 9: - // if (obj instanceof PCEPLoadBalancingObject) { - // loadBalancing = (PCEPLoadBalancingObject) obj; - // break; - // } - // state = 10; - // } - // - // if (state == 10) { - // break; - // } - // - // objects.remove(obj); - // } - // - // if (rpObj.isReoptimized() && bandwidth != null && bandwidth.getBandwidth() != new Bandwidth(new byte[] { 0 }) && - // rro == null) { - // msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new - // PCEPErrorObject(PCEPErrors.RRO_MISSING)))); - // requestRejected = true; - // } - // - // if (!requestRejected) { - // requests.add(new CompositeRequestObject(rpObj, endPoints, classType, lsp, lspa, bandwidth, metrics, rro, - // rroBandwidth, iro, loadBalancing)); - // msgs.add(new PCEPRequestMessage(Collections.unmodifiableList(svecList), Collections.unmodifiableList(requests))); - // } - // } - // - // return msgs; - // } - // - // private static CompositeRequestSvecObject getValidSvecComposite(final List objects) throws - // PCEPDocumentedException { - // if (objects == null || objects.isEmpty()) { - // throw new IllegalArgumentException("List cannot be null or empty."); - // } - // - // PCEPSvecObject svec = null; - // if (objects.get(0) instanceof PCEPSvecObject) { - // svec = (PCEPSvecObject) objects.get(0); - // objects.remove(svec); - // } else - // return null; - // - // PCEPObjectiveFunctionObject of = null; - // PCEPGlobalConstraintsObject gc = null; - // PCEPExcludeRouteObject xro = null; - // final List metrics = new ArrayList(); - // - // int state = 1; - // while (!objects.isEmpty()) { - // final Object obj = objects.get(0); - // - // if (obj instanceof UnknownObject && ((UnknownObject) obj).isProcessingRule()) { - // throw new PCEPDocumentedException("Unknown object in SVEC list.", ((UnknownObject) obj).getError()); - // } - // - // switch (state) { - // case 1: - // state = 2; - // if (obj instanceof PCEPObjectiveFunctionObject) { - // of = (PCEPObjectiveFunctionObject) obj; - // break; - // } - // case 2: - // state = 3; - // if (obj instanceof PCEPGlobalConstraintsObject) { - // gc = (PCEPGlobalConstraintsObject) obj; - // break; - // } - // case 3: - // state = 4; - // if (obj instanceof PCEPExcludeRouteObject) { - // xro = (PCEPExcludeRouteObject) obj; - // break; - // } - // case 4: - // state = 5; - // if (obj instanceof PCEPMetricObject) { - // metrics.add((PCEPMetricObject) obj); - // state = 4; - // - // break; - // } - // } - // - // if (state == 5) - // break; - // - // objects.remove(obj); - // } - // - // return new CompositeRequestSvecObject(svec, of, gc, xro, metrics); - // } - // - // private static PCEPRequestParameterObject copyRP(final PCEPRequestParameterObject origRp, final boolean - // processed) { - // return new PCEPRequestParameterObject(origRp.isLoose(), origRp.isBidirectional(), origRp.isReoptimized(), - // origRp.isMakeBeforeBreak(), origRp.isReportRequestOrder(), origRp.isSuplyOFOnResponse(), - // origRp.isFragmentation(), origRp.isP2mp(), origRp.isEroCompression(), origRp.getPriority(), - // origRp.getRequestID(), origRp.getTlvs(), processed, origRp.isIgnored()); - // } +public class PCEPRequestMessageValidator extends PCEPMessageValidator { + + @Override + public List validate(final List objects) { + if (objects == null) + throw new IllegalArgumentException("Passed list can't be null."); + + final List msgs = Lists.newArrayList(); + final List svecList = new ArrayList(); + + CompositeRequestSvecObject svecComp; + while (!objects.isEmpty()) { + try { + if ((svecComp = getValidSvecComposite(objects)) == null) + break; + } catch (final PCEPDocumentedException e) { + msgs.add(new PCEPErrorMessage(new PCEPErrorObject(e.getError()))); + return msgs; + } + + svecList.add(svecComp); + } + + while (!objects.isEmpty()) { + final List requests = new ArrayList(); + PCEPRequestParameterObject rpObj = null; + boolean requestRejected = false; + + if (objects.get(0) instanceof PCEPRequestParameterObject) { + rpObj = (PCEPRequestParameterObject) objects.get(0); + objects.remove(rpObj); + if (!rpObj.isProcessed()) { + msgs.add(new PCEPErrorMessage(new CompositeErrorObject(rpObj, new PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET)))); + requestRejected = true; + } + + } else { + // if RP obj is missing return error only; + msgs.clear(); + msgs.add(new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.RP_MISSING))); + return msgs; + } + + PCEPEndPointsObject endPoints = null; + if (objects.get(0) instanceof PCEPEndPointsObject) { + endPoints = (PCEPEndPointsObject) objects.get(0); + objects.remove(0); + if (!endPoints.isProcessed()) { + msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET)))); + requestRejected = true; + } + } else { + msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new PCEPErrorObject(PCEPErrors.END_POINTS_MISSING)))); + requestRejected = true; + } + + // ignore all continual end-points objects + while (!objects.isEmpty() && objects.get(0) instanceof PCEPEndPointsObject) { + objects.remove(0); + } + + PCEPClassTypeObject classType = null; + PCEPLspObject lsp = null; + PCEPLspaObject lspa = null; + PCEPRequestedPathBandwidthObject bandwidth = null; + final List metrics = new ArrayList(); + PCEPReportedRouteObject rro = null; + PCEPExistingPathBandwidthObject rroBandwidth = null; + PCEPIncludeRouteObject iro = null; + PCEPLoadBalancingObject loadBalancing = null; + + int state = 1; + while (!objects.isEmpty()) { + final PCEPObject obj = objects.get(0); + if (obj instanceof UnknownObject) { + if (((UnknownObject) obj).isProcessed()) { + msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new PCEPErrorObject(((UnknownObject) obj).getError())))); + requestRejected = true; + } + + objects.remove(0); + continue; + } + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPClassTypeObject) { + classType = (PCEPClassTypeObject) obj; + if (!classType.isProcessed()) { + msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET)))); + requestRejected = true; + } + break; + } + case 2: + state = 3; + if (obj instanceof PCEPLspObject) { + lsp = (PCEPLspObject) obj; + break; + } + case 3: + state = 4; + if (obj instanceof PCEPLspaObject) { + lspa = (PCEPLspaObject) obj; + break; + } + case 4: + state = 5; + if (obj instanceof PCEPRequestedPathBandwidthObject) { + bandwidth = (PCEPRequestedPathBandwidthObject) obj; + break; + } + case 5: + state = 6; + if (obj instanceof PCEPMetricObject) { + metrics.add((PCEPMetricObject) obj); + state = 5; + + break; + } + case 6: + state = 8; + if (obj instanceof PCEPReportedRouteObject) { + rro = (PCEPReportedRouteObject) obj; + state = 7; + break; + } + case 7: + state = 8; + if (obj instanceof PCEPExistingPathBandwidthObject) { + rroBandwidth = (PCEPExistingPathBandwidthObject) obj; + break; + } + case 8: + state = 9; + if (obj instanceof PCEPIncludeRouteObject) { + iro = (PCEPIncludeRouteObject) obj; + break; + } + case 9: + if (obj instanceof PCEPLoadBalancingObject) { + loadBalancing = (PCEPLoadBalancingObject) obj; + break; + } + state = 10; + } + + if (state == 10) { + break; + } + + objects.remove(obj); + } + + if (rpObj.isReoptimized() && bandwidth != null && bandwidth.getBandwidth() != new Bandwidth(new byte[] { 0 }) && rro == null) { + msgs.add(new PCEPErrorMessage(new CompositeErrorObject(copyRP(rpObj, false), new PCEPErrorObject(PCEPErrors.RRO_MISSING)))); + requestRejected = true; + } + + if (!requestRejected) { + requests.add(new CompositeRequestObject(rpObj, endPoints, classType, lsp, lspa, bandwidth, metrics, rro, rroBandwidth, iro, loadBalancing)); + msgs.add(new PCEPRequestMessage(Collections.unmodifiableList(svecList), Collections.unmodifiableList(requests))); + } + } + + return msgs; + } + + private static CompositeRequestSvecObject getValidSvecComposite(final List objects) throws PCEPDocumentedException { + if (objects == null || objects.isEmpty()) { + throw new IllegalArgumentException("List cannot be null or empty."); + } + + PCEPSvecObject svec = null; + if (objects.get(0) instanceof PCEPSvecObject) { + svec = (PCEPSvecObject) objects.get(0); + objects.remove(svec); + } else + return null; + + PCEPObjectiveFunctionObject of = null; + PCEPGlobalConstraintsObject gc = null; + PCEPExcludeRouteObject xro = null; + final List metrics = new ArrayList(); + + int state = 1; + while (!objects.isEmpty()) { + final PCEPObject obj = objects.get(0); + + if (obj instanceof UnknownObject && ((UnknownObject) obj).isProcessed()) { + throw new PCEPDocumentedException("Unknown object in SVEC list.", ((UnknownObject) obj).getError()); + } + + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPObjectiveFunctionObject) { + of = (PCEPObjectiveFunctionObject) obj; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPGlobalConstraintsObject) { + gc = (PCEPGlobalConstraintsObject) obj; + break; + } + case 3: + state = 4; + if (obj instanceof PCEPExcludeRouteObject) { + xro = (PCEPExcludeRouteObject) obj; + break; + } + case 4: + state = 5; + if (obj instanceof PCEPMetricObject) { + metrics.add((PCEPMetricObject) obj); + state = 4; + + break; + } + } + + if (state == 5) + break; + + objects.remove(obj); + } + + return new CompositeRequestSvecObject(svec, of, gc, xro, metrics); + } + + private static PCEPRequestParameterObject copyRP(final PCEPRequestParameterObject origRp, final boolean processed) { + return new PCEPRequestParameterObject(origRp.isLoose(), origRp.isBidirectional(), origRp.isReoptimized(), origRp.isMakeBeforeBreak(), origRp.isReportRequestOrder(), origRp.isSuplyOFOnResponse(), origRp.isFragmentation(), origRp.isP2mp(), origRp.isEroCompression(), origRp.getPriority(), origRp.getRequestID(), origRp.getTlvs(), processed, origRp.isIgnored()); + } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPUpdateRequestMessageParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPUpdateRequestMessageParser.java index 73460aacac..c2254418c3 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPUpdateRequestMessageParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPUpdateRequestMessageParser.java @@ -7,41 +7,19 @@ */ package org.opendaylight.protocol.pcep.impl.message; -import io.netty.buffer.ByteBuf; - -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.spi.AbstractMessageParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import org.opendaylight.protocol.pcep.impl.PCEPMessageParser; +import org.opendaylight.protocol.pcep.impl.PCEPObjectFactory; +import org.opendaylight.protocol.pcep.message.PCEPUpdateRequestMessage; 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.PcupdMessage; - -/** - * Parser for {@link PcupdMessage} - */ -public class PCEPUpdateRequestMessageParser extends AbstractMessageParser { - - private final int TYPE = 11; - - public PCEPUpdateRequestMessageParser(HandlerRegistry registry) { - super(registry); - } +public class PCEPUpdateRequestMessageParser implements PCEPMessageParser { @Override - public void serializeMessage(Message message, ByteBuf buffer) { - if (!(message instanceof PcupdMessage)) - throw new IllegalArgumentException("Wrong instance of PCEPMessage. Passed instance of " + message.getClass() - + ". Nedded PcupdMessage."); + public byte[] put(final Message msg) { + if (!(msg instanceof PCEPUpdateRequestMessage)) + throw new IllegalArgumentException("Wrong instance of PCEPMessage. Passed instance of " + msg.getClass() + + ". Nedded PCEPUpdateRequestMessage."); + return PCEPObjectFactory.put(((PCEPUpdateRequestMessage) msg).getAllObjects()); } - @Override - public PcupdMessage parseMessage(byte[] buffer) throws PCEPDeserializerException { - // TODO Auto-generated method stub - return null; - } - - @Override - public int getMessageType() { - return TYPE; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPUpdateRequestMessageValidator.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPUpdateRequestMessageValidator.java index 12e4982b93..27f78e95ec 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPUpdateRequestMessageValidator.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/PCEPUpdateRequestMessageValidator.java @@ -7,9 +7,26 @@ */ package org.opendaylight.protocol.pcep.impl.message; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPMessageValidator; +import org.opendaylight.protocol.pcep.impl.object.UnknownObject; +import org.opendaylight.protocol.pcep.message.PCEPErrorMessage; +import org.opendaylight.protocol.pcep.message.PCEPUpdateRequestMessage; +import org.opendaylight.protocol.pcep.object.CompositeUpdPathObject; +import org.opendaylight.protocol.pcep.object.CompositeUpdateRequestObject; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPLspObject; +import org.opendaylight.protocol.pcep.object.PCEPLspaObject; +import org.opendaylight.protocol.pcep.object.PCEPMetricObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,110 +34,108 @@ import org.slf4j.LoggerFactory; /** * PCEPUpdateRequestMessage validator. Validates message integrity. */ -// FIXME: merge with parser -class PCEPUpdateRequestMessageValidator { +public class PCEPUpdateRequestMessageValidator extends PCEPMessageValidator { private static final Logger logger = LoggerFactory.getLogger(PCEPUpdateRequestMessageValidator.class); - public List validate(final List objects) throws PCEPDeserializerException { + @Override + public List validate(final List objects) throws PCEPDeserializerException { if (objects == null) throw new IllegalArgumentException("Passed list can't be null."); - // final List updateRequests = new ArrayList(); - // - // while (!objects.isEmpty()) { - // if (objects.get(0) instanceof UnknownObject) { - // logger.warn("Unknown object found (should be Lsp) - {}.", objects.get(0)); - // return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(((UnknownObject) - // objects.get(0)).getError()))); - // } - // if (!(objects.get(0) instanceof PCEPLspObject)) - // return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.LSP_MISSING))); - // - // final PCEPLspObject lsp = (PCEPLspObject) objects.get(0); - // objects.remove(0); - // - // final List paths = new ArrayList(); - // - // if (!objects.isEmpty()) { - // try { - // CompositeUpdPathObject path; - // path = this.getValidCompositePath(objects); - // while (path != null) { - // paths.add(path); - // if (objects.isEmpty()) - // break; - // path = this.getValidCompositePath(objects); - // } - // } catch (final PCEPDocumentedException e) { - // logger.warn("Serializing failed: {}.", e); - // return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(e.getError()))); - // } - // } - // - // updateRequests.add(new CompositeUpdateRequestObject(lsp, paths)); - // } - // - // if (updateRequests.isEmpty()) - // return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.LSP_MISSING))); - // - // if (!objects.isEmpty()) - // throw new PCEPDeserializerException("Unprocessed Objects: " + objects); - // - // return Arrays.asList((Message) new PCEPUpdateRequestMessage(updateRequests)); - return null; + final List updateRequests = new ArrayList(); + + while (!objects.isEmpty()) { + if (objects.get(0) instanceof UnknownObject) { + logger.warn("Unknown object found (should be Lsp) - {}.", objects.get(0)); + return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(((UnknownObject) objects.get(0)).getError()))); + } + if (!(objects.get(0) instanceof PCEPLspObject)) + return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.LSP_MISSING))); + + final PCEPLspObject lsp = (PCEPLspObject) objects.get(0); + objects.remove(0); + + final List paths = new ArrayList(); + + if (!objects.isEmpty()) { + try { + CompositeUpdPathObject path; + path = this.getValidCompositePath(objects); + while (path != null) { + paths.add(path); + if (objects.isEmpty()) + break; + path = this.getValidCompositePath(objects); + } + } catch (final PCEPDocumentedException e) { + logger.warn("Serializing failed: {}.", e); + return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(e.getError()))); + } + } + + updateRequests.add(new CompositeUpdateRequestObject(lsp, paths)); + } + + if (updateRequests.isEmpty()) + return Arrays.asList((Message) new PCEPErrorMessage(new PCEPErrorObject(PCEPErrors.LSP_MISSING))); + + if (!objects.isEmpty()) + throw new PCEPDeserializerException("Unprocessed Objects: " + objects); + + return Arrays.asList((Message) new PCEPUpdateRequestMessage(updateRequests)); } - // private CompositeUpdPathObject getValidCompositePath(final List objects) throws PCEPDocumentedException { - // if (!(objects.get(0) instanceof PCEPExplicitRouteObject)) - // return null; - // - // if (objects.get(0) instanceof UnknownObject) - // throw new PCEPDocumentedException("Unknown object", ((UnknownObject) objects.get(0)).getError()); - // final PCEPExplicitRouteObject explicitRoute = (PCEPExplicitRouteObject) objects.get(0); - // objects.remove(0); - // - // PCEPLspaObject pathLspa = null; - // PCEPRequestedPathBandwidthObject pathBandwidth = null; - // final List pathMetrics = new ArrayList(); - // - // Object obj; - // int state = 1; - // while (!objects.isEmpty()) { - // obj = objects.get(0); - // if (obj instanceof UnknownObject) { - // throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError()); - // } - // - // switch (state) { - // case 1: - // state = 2; - // if (obj instanceof PCEPLspaObject) { - // pathLspa = (PCEPLspaObject) obj; - // break; - // } - // case 2: - // state = 3; - // if (obj instanceof PCEPRequestedPathBandwidthObject) { - // pathBandwidth = (PCEPRequestedPathBandwidthObject) obj; - // break; - // } - // case 3: - // state = 4; - // if (obj instanceof PCEPMetricObject) { - // pathMetrics.add((PCEPMetricObject) obj); - // state = 3; - // break; - // } - // } - // - // if (state == 4) - // break; - // - // objects.remove(0); - // } - // - // return new CompositeUpdPathObject(explicitRoute, pathLspa, pathBandwidth, pathMetrics); - // } + private CompositeUpdPathObject getValidCompositePath(final List objects) throws PCEPDocumentedException { + if (!(objects.get(0) instanceof PCEPExplicitRouteObject)) + return null; + + if (objects.get(0) instanceof UnknownObject) + throw new PCEPDocumentedException("Unknown object", ((UnknownObject) objects.get(0)).getError()); + final PCEPExplicitRouteObject explicitRoute = (PCEPExplicitRouteObject) objects.get(0); + objects.remove(0); + + PCEPLspaObject pathLspa = null; + PCEPRequestedPathBandwidthObject pathBandwidth = null; + final List pathMetrics = new ArrayList(); + + PCEPObject obj; + int state = 1; + while (!objects.isEmpty()) { + obj = objects.get(0); + if (obj instanceof UnknownObject) { + throw new PCEPDocumentedException("Unknown object", ((UnknownObject) obj).getError()); + } + + switch (state) { + case 1: + state = 2; + if (obj instanceof PCEPLspaObject) { + pathLspa = (PCEPLspaObject) obj; + break; + } + case 2: + state = 3; + if (obj instanceof PCEPRequestedPathBandwidthObject) { + pathBandwidth = (PCEPRequestedPathBandwidthObject) obj; + break; + } + case 3: + state = 4; + if (obj instanceof PCEPMetricObject) { + pathMetrics.add((PCEPMetricObject) obj); + state = 3; + break; + } + } + + if (state == 4) + break; + + objects.remove(0); + } + + return new CompositeUpdPathObject(explicitRoute, pathLspa, pathBandwidth, pathMetrics); + } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPBandwidthObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPBandwidthObjectParser.java deleted file mode 100644 index bd7b025d52..0000000000 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPBandwidthObjectParser.java +++ /dev/null @@ -1,89 +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.object; - -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; -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; -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.requests.segment.computation.p2p.reported.route.BandwidthBuilder; - -/** - * Parser for {@link BandwidthObject} - */ -public class PCEPBandwidthObjectParser extends AbstractObjectParser { - - public static final int E_CLASS = 5; - - public static final int E_TYPE = 1; - - public static final int CLASS = 5; - - public static final int TYPE = 2; - - private static final int BANDWIDTH_F_LENGTH = 4; - - public PCEPBandwidthObjectParser(final HandlerRegistry registry) { - super(registry); - } - - @Override - public BandwidthObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, - PCEPDocumentedException { - if (bytes == null || bytes.length == 0) - throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty."); - if (bytes.length != BANDWIDTH_F_LENGTH) - 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(); - } - - @Override - public void addTlv(final BandwidthBuilder builder, final Tlv tlv) { - // No tlvs defined - } - - @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof BandwidthObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed BandwidthObject."); - - return ((BandwidthObject) object).getBandwidth().getValue(); - } - - @Override - public int getObjectType() { - return TYPE; - } - - @Override - public int getObjectClass() { - return CLASS; - } - - public int getEObjectType() { - return E_TYPE; - } - - public int getEObjectClass() { - return E_CLASS; - } -} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPBranchNodeListObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPBranchNodeListObjectParser.java new file mode 100644 index 0000000000..2a572198b1 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPBranchNodeListObjectParser.java @@ -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.impl.object; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPEROSubobjectParser; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.object.PCEPBranchNodeListObject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; + +public class PCEPBranchNodeListObjectParser implements PCEPObjectParser { + + @Override + public PCEPBranchNodeListObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException, PCEPDocumentedException { + if (bytes == null || bytes.length == 0) + throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty."); + + final List subobjects = PCEPEROSubobjectParser.parse(bytes); + if (subobjects.isEmpty()) + throw new PCEPDeserializerException("Empty Branch Node List Object."); + + return new PCEPBranchNodeListObject(subobjects, processed, ignored); + } + + @Override + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPBranchNodeListObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPBranchNodeListObject."); + + assert !(((PCEPBranchNodeListObject) obj).getSubobjects().isEmpty()) : "Empty Branch Node List Object."; + + return PCEPEROSubobjectParser.put(((PCEPBranchNodeListObject) obj).getSubobjects()); + } + +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPClassTypeObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPClassTypeObjectParser.java index cba23bdb0b..5ffcea9194 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPClassTypeObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPClassTypeObjectParser.java @@ -10,23 +10,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.PCEPErrors; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; -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; -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.lsp.attributes.ClassTypeBuilder; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.object.PCEPClassTypeObject; +import org.opendaylight.protocol.util.ByteArray; /** * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPClassTypeObject PCEPClassTypeObject} */ -public class PCEPClassTypeObjectParser extends AbstractObjectParser { - - public static final int CLASS = 22; - - public static final int TYPE = 1; +public class PCEPClassTypeObjectParser implements PCEPObjectParser { /** * Length of Class Type field in bits. @@ -43,57 +35,29 @@ public class PCEPClassTypeObjectParser extends AbstractObjectParser 8) { - throw new PCEPDocumentedException("Invalid class type " + ct, PCEPErrors.INVALID_CT); + final short classType = (short) (bytes[SIZE-1] & 0xFF); + if (classType < 0 || classType > 8) { + throw new PCEPDocumentedException("Invalid class type " + classType, PCEPErrors.INVALID_CT); } - return builder.build(); + return new PCEPClassTypeObject(classType); } @Override - public void addTlv(final ClassTypeBuilder builder, final Tlv tlv) { - // No tlvs defined - } - - @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof ClasstypeObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed ClasstypeObject."); + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPClassTypeObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPClassTypeObject."); final byte[] retBytes = new byte[SIZE]; - retBytes[SIZE - 1] = ((ClasstypeObject) object).getClassType().getValue().byteValue(); + retBytes[SIZE-1] = ByteArray.shortToBytes(((PCEPClassTypeObject) obj).getClassType())[1]; return retBytes; } - - @Override - public int getObjectType() { - return TYPE; - } - - @Override - public int getObjectClass() { - return CLASS; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPCloseObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPCloseObjectParser.java index b21d80f489..8676d25651 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPCloseObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPCloseObjectParser.java @@ -8,27 +8,17 @@ 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.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.impl.PCEPTlvParser; +import org.opendaylight.protocol.pcep.object.PCEPCloseObject; +import org.opendaylight.protocol.pcep.object.PCEPCloseObject.Reason; import org.opendaylight.protocol.util.ByteArray; -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.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.close.message.c.close.message.CClose; -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; /** * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPCloseObject PCEPCloseObject} */ -public class PCEPCloseObjectParser extends AbstractObjectParser { - - public static final int CLASS = 15; - - public static final int TYPE = 1; +public class PCEPCloseObjectParser implements PCEPObjectParser { /* * lengths of fields in bytes @@ -45,69 +35,75 @@ public class PCEPCloseObjectParser extends AbstractObjectParser { /* * total size of object in bytes */ - public static final int TLVS_OFFSET = REASON_F_OFFSET + REASON_F_LENGTH; - - public PCEPCloseObjectParser(final HandlerRegistry registry) { - super(registry); - } + public static final int TLVS_F_OFFSET = REASON_F_OFFSET + REASON_F_LENGTH; @Override - public CloseObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException { + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException { 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)); - - return builder.build(); - } - - @Override - public void addTlv(final CCloseBuilder builder, final Tlv tlv) { - // No tlvs defined + if (bytes.length != TLVS_F_OFFSET) + throw new PCEPDeserializerException("Size of byte array doesn't match defined size. Expected: " + TLVS_F_OFFSET + "; Passed: " + bytes.length); + + Reason reason; + switch ((short) (bytes[REASON_F_OFFSET] & 0xFF)) { + case 1: + reason = Reason.UNKNOWN; + break; + case 2: + reason = Reason.EXP_DEADTIMER; + break; + case 3: + reason = Reason.MALFORMED_MSG; + break; + case 4: + reason = Reason.TOO_MANY_UNKNOWN_REQ_REP; + break; + case 5: + reason = Reason.TOO_MANY_UNKNOWN_MSG; + break; + default: + reason = Reason.UNKNOWN; + break; + } + + return new PCEPCloseObject(reason, PCEPTlvParser.parse(ByteArray.cutBytes(bytes, TLVS_F_OFFSET))); } @Override - public byte[] serializeObject(final Object object) { - 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()); - int tlvsLength = 0; - if (tlvs != null) - tlvsLength = tlvs.length; - final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)]; - - if (tlvs != null) - ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET); - - final int reason = ((CClose) obj).getReason().intValue(); + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPCloseObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPCloseObject."); + + final byte[] tlvs = PCEPTlvParser.put(((PCEPCloseObject) obj).getTlvs()); + final byte[] retBytes = new byte[TLVS_F_OFFSET + tlvs.length]; + ByteArray.copyWhole(tlvs, retBytes, TLVS_F_OFFSET); + + int reason; + switch (((PCEPCloseObject) obj).getReason()) { + case UNKNOWN: + reason = 1; + break; + case EXP_DEADTIMER: + reason = 2; + break; + case MALFORMED_MSG: + reason = 3; + break; + case TOO_MANY_UNKNOWN_REQ_REP: + reason = 4; + break; + case TOO_MANY_UNKNOWN_MSG: + reason = 5; + break; + default: + reason = 1; + break; + } retBytes[REASON_F_OFFSET] = (byte) reason; return retBytes; } - public byte[] serializeTlvs(final Tlvs tlvs) { - // No tlvs defined - return new byte[0]; - } - - @Override - public int getObjectType() { - return TYPE; - } - - @Override - public int getObjectClass() { - return CLASS; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsIPv4ObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsIPv4ObjectParser.java new file mode 100644 index 0000000000..4beaa2b04b --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsIPv4ObjectParser.java @@ -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.pcep.impl.object; + +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject; +import org.opendaylight.protocol.util.ByteArray; + +/** + * Parser for IPv4 {@link org.opendaylight.protocol.pcep.object.PCEPEndPointsObject + * PCEPEndPointsObject} + */ +public class PCEPEndPointsIPv4ObjectParser implements PCEPObjectParser { + + /* + * fields lengths and offsets for IPv4 in bytes + */ + public static final int SRC4_F_LENGTH = 4; + public 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; + + @Override + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException, PCEPDocumentedException { + if (bytes == null) + throw new IllegalArgumentException("Array of bytes is mandatory"); + if (bytes.length != SRC4_F_LENGTH + DEST4_F_LENGTH) + throw new PCEPDeserializerException("Wrong length of array of bytes."); + + //FIXME: create new constructor which allows processed parameter - needed for validation + return new PCEPEndPointsObject( + new IPv4Address(ByteArray.subByte(bytes, SRC4_F_OFFSET, SRC4_F_LENGTH)), + new IPv4Address(ByteArray.subByte(bytes, DEST4_F_OFFSET, DEST4_F_LENGTH))); + } + + @Override + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPEndPointsObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPEndPointsObject."); + + final PCEPEndPointsObject ePObj = (PCEPEndPointsObject) obj; + + if (!(ePObj.getSourceAddress() instanceof IPv4Address)) + throw new IllegalArgumentException("Wrong instance of NetworkAddress. Passed " + ePObj.getSourceAddress().getClass() + ". Needed IPv4Address"); + + final byte[] retBytes = new byte[SRC4_F_LENGTH + DEST4_F_LENGTH]; + ByteArray.copyWhole(((IPv4Address) ePObj.getSourceAddress()).getAddress(), retBytes, SRC4_F_OFFSET); + ByteArray.copyWhole(((IPv4Address) ePObj.getDestinationAddress()).getAddress(), retBytes, DEST4_F_OFFSET); + + return retBytes; + } +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsIPv6ObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsIPv6ObjectParser.java new file mode 100644 index 0000000000..2be773f951 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsIPv6ObjectParser.java @@ -0,0 +1,63 @@ +/* + * 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.object; + +import org.opendaylight.protocol.concepts.IPv6Address; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject; +import org.opendaylight.protocol.util.ByteArray; + +/** + * Parser for IPv6 {@link org.opendaylight.protocol.pcep.object.PCEPEndPointsObject + * PCEPEndPointsObject} + */ +public class PCEPEndPointsIPv6ObjectParser implements PCEPObjectParser { + + public static final int SRC6_F_LENGTH = 16; + public static final int DEST6_F_LENGT = 16; + + public static final int SRC6_F_OFFSET = 0; + public static final int DEST6_F_OFFSET = SRC6_F_OFFSET + SRC6_F_LENGTH; + + @Override + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException, PCEPDocumentedException { + if (bytes == null) + throw new IllegalArgumentException("Array of bytes is mandatory"); + if (bytes.length != SRC6_F_LENGTH + DEST6_F_LENGT) + throw new PCEPDeserializerException("Wrong length of array of bytes."); + + if (!processed) + throw new PCEPDocumentedException("Processed flag not set", PCEPErrors.P_FLAG_NOT_SET); + + return new PCEPEndPointsObject( + new IPv6Address(ByteArray.subByte(bytes, SRC6_F_OFFSET, SRC6_F_LENGTH)), + new IPv6Address(ByteArray.subByte(bytes, DEST6_F_OFFSET, DEST6_F_LENGT))); + } + + @Override + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPEndPointsObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPEndPointsObject."); + + final PCEPEndPointsObject ePObj = (PCEPEndPointsObject) obj; + + if (!(ePObj.getSourceAddress() instanceof IPv6Address)) + throw new IllegalArgumentException("Wrong instance of NetworkAddress. Passed " + ePObj.getSourceAddress().getClass() + ". Needed IPv6Address"); + + final byte[] retBytes = new byte[SRC6_F_LENGTH + DEST6_F_LENGT]; + ByteArray.copyWhole(((IPv6Address) ePObj.getSourceAddress()).getAddress(), retBytes, SRC6_F_OFFSET); + ByteArray.copyWhole(((IPv6Address) ePObj.getDestinationAddress()).getAddress(), retBytes, DEST6_F_OFFSET); + + return retBytes; + } + +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsObjectParser.java deleted file mode 100644 index 434e7dfa64..0000000000 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsObjectParser.java +++ /dev/null @@ -1,134 +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.object; - -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.PCEPErrors; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; -import org.opendaylight.protocol.util.ByteArray; -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.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.endpoints.object.AddressFamily; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.address.family.Ipv4; -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.Ipv6; -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.pcinitiate.message.pcinitiate.message.requests.EndpointsBuilder; - -/** - * Parser for IPv4 {@link EndpointsObject} - */ -public class PCEPEndPointsObjectParser extends AbstractObjectParser { - - public static final int CLASS = 4; - - public static final int TYPE = 1; - - /* - * fields lengths and offsets for IPv4 in bytes - */ - public static final int SRC4_F_LENGTH = 4; - public 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; - - public static final int SRC6_F_LENGTH = 16; - public 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; - - public PCEPEndPointsObjectParser(final HandlerRegistry registry) { - super(registry); - } - - @Override - public EndpointsObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, - PCEPDocumentedException { - if (bytes == null) - throw new IllegalArgumentException("Array of bytes is mandatory"); - - if (!header.isProcessingRule()) - throw new PCEPDocumentedException("Processed flag not set", PCEPErrors.P_FLAG_NOT_SET); - - final EndpointsBuilder builder = new EndpointsBuilder(); - builder.setIgnore(header.isIgnore()); - builder.setProcessingRule(header.isProcessingRule()); - - if (bytes.length == SRC4_F_LENGTH + DEST4_F_LENGTH) { - final Ipv4Builder b = new Ipv4Builder(); - b.setSourceIpv4Address(Ipv4Util.addressForBytes(ByteArray.subByte(bytes, SRC4_F_OFFSET, SRC4_F_LENGTH))); - b.setDestinationIpv4Address((Ipv4Util.addressForBytes(ByteArray.subByte(bytes, DEST4_F_OFFSET, DEST4_F_LENGTH)))); - builder.setAddressFamily(b.build()); - } else if (bytes.length == SRC6_F_LENGTH + DEST6_F_LENGTH) { - final Ipv6Builder b = new Ipv6Builder(); - b.setSourceIpv6Address(Ipv6Util.addressForBytes(ByteArray.subByte(bytes, SRC6_F_OFFSET, SRC6_F_LENGTH))); - b.setDestinationIpv6Address((Ipv6Util.addressForBytes(ByteArray.subByte(bytes, DEST6_F_OFFSET, DEST6_F_LENGTH)))); - builder.setAddressFamily(b.build()); - } else - throw new PCEPDeserializerException("Wrong length of array of bytes."); - return builder.build(); - } - - @Override - public void addTlv(final EndpointsBuilder builder, final Tlv tlv) { - // No tlvs defined - } - - @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof EndpointsObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed EndpointsObject."); - - final EndpointsObject ePObj = (EndpointsObject) object; - - final AddressFamily afi = ePObj.getAddressFamily(); - - if (afi instanceof Ipv4) { - final byte[] retBytes = new byte[SRC4_F_LENGTH + DEST4_F_LENGTH]; - ByteArray.copyWhole(Ipv4Util.bytesForAddress(((Ipv4) afi).getSourceIpv4Address()), retBytes, SRC4_F_OFFSET); - ByteArray.copyWhole(Ipv4Util.bytesForAddress(((Ipv4) afi).getDestinationIpv4Address()), retBytes, DEST4_F_OFFSET); - return retBytes; - } else if (afi instanceof Ipv6) { - final byte[] retBytes = new byte[SRC6_F_LENGTH + DEST6_F_LENGTH]; - ByteArray.copyWhole(Ipv6Util.bytesForAddress(((Ipv6) afi).getSourceIpv6Address()), retBytes, SRC6_F_OFFSET); - ByteArray.copyWhole(Ipv6Util.bytesForAddress(((Ipv6) afi).getDestinationIpv6Address()), retBytes, DEST6_F_OFFSET); - return retBytes; - } else - throw new IllegalArgumentException("Wrong instance of NetworkAddress. Passed " + afi.getClass() + ". Needed IPv4"); - } - - @Override - public int getObjectType() { - return TYPE; - } - - @Override - public int getObjectClass() { - return CLASS; - } - - public int get6ObjectType() { - return TYPE_6; - } - - public int get6ObjectClass() { - return CLASS_6; - } -} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPErrorObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPErrorObjectParser.java index dda846eca6..64f850f8b2 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPErrorObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPErrorObjectParser.java @@ -7,107 +7,237 @@ */ 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.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import java.util.HashMap; +import java.util.Map; +import java.util.NoSuchElementException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + 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.PcepErrorObject; -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.Tlv; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.Tlvs; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.TlvsBuilder; -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.pcerr.message.pcerr.message.Errors; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.impl.PCEPTlvParser; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; /** * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPErrorObject PCEPErrorObject} */ -public class PCEPErrorObjectParser extends AbstractObjectParser { +public class PCEPErrorObjectParser implements PCEPObjectParser { + /** + * Caret for combination of Error-type and Error-value + */ + public static class PCEPErrorIdentifier { + public final short type; + public final short value; + + private PCEPErrorIdentifier(final short type, final short value) { + this.type = type; + this.value = value; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + this.type; + result = prime * result + this.value; + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (this.getClass() != obj.getClass()) + return false; + final PCEPErrorIdentifier other = (PCEPErrorIdentifier) obj; + if (this.type != other.type) + return false; + if (this.value != other.value) + return false; + return true; + } + + @Override + public String toString() { + return "type " + this.type + " value " + this.value; + } + } + + /** + * Bidirectional mapping of {@link org.opendaylight.protocol.pcep.PCEPErrors PCEPErrors} + * and + * {@link org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser.PCEPErrorIdentifier + * ErrorIdentifier} + */ + public static class PCEPErrorsMaping { + private static final PCEPErrorsMaping instance = new PCEPErrorsMaping(); + + private final Map errorsMap = new HashMap(); + private final Map errorIdsMap = new HashMap(); + + private PCEPErrorsMaping() { + this.fillIn(); + } + + private void fillIn() { + this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 1), PCEPErrors.NON_OR_INVALID_OPEN_MSG); + this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 2), PCEPErrors.NO_OPEN_BEFORE_EXP_OPENWAIT); + this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 3), PCEPErrors.NON_ACC_NON_NEG_SESSION_CHAR); + this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 4), PCEPErrors.NON_ACC_NEG_SESSION_CHAR); + this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 5), PCEPErrors.SECOND_OPEN_MSG); + this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 6), PCEPErrors.PCERR_NON_ACC_SESSION_CHAR); + this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 7), PCEPErrors.NO_MSG_BEFORE_EXP_KEEPWAIT); + this.fillIn(new PCEPErrorIdentifier((short) 1, (short) 8), PCEPErrors.PCEP_VERSION_NOT_SUPPORTED); + + this.fillIn(new PCEPErrorIdentifier((short) 2, (short) 0), PCEPErrors.CAPABILITY_NOT_SUPPORTED); + + this.fillIn(new PCEPErrorIdentifier((short) 3, (short) 1), PCEPErrors.UNRECOGNIZED_OBJ_CLASS); + this.fillIn(new PCEPErrorIdentifier((short) 3, (short) 2), PCEPErrors.UNRECOGNIZED_OBJ_TYPE); + + this.fillIn(new PCEPErrorIdentifier((short) 4, (short) 1), PCEPErrors.NOT_SUPPORTED_OBJ_CLASS); + this.fillIn(new PCEPErrorIdentifier((short) 4, (short) 2), PCEPErrors.NOT_SUPPORTED_OBJ_TYPE); + + this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 1), PCEPErrors.C_BIT_SET); + this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 2), PCEPErrors.O_BIT_SET); + this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 3), PCEPErrors.OF_NOT_ALLOWED); + this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 4), PCEPErrors.OF_BIT_SET); + this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 5), PCEPErrors.GCO_NOT_ALLOWED); + this.fillIn(new PCEPErrorIdentifier((short) 5, (short) 7), PCEPErrors.P2MP_COMPUTATION_NOT_ALLOWED); + + this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 1), PCEPErrors.RP_MISSING); + this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 2), PCEPErrors.RRO_MISSING); + this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 3), PCEPErrors.END_POINTS_MISSING); + this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 8), PCEPErrors.LSP_MISSING); + this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 9), PCEPErrors.ERO_MISSING); + this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 10), PCEPErrors.BANDWIDTH_MISSING); + this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 11), PCEPErrors.LSPA_MISSING); + this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 12), PCEPErrors.DB_VERSION_TLV_MISSING); + + this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 13), PCEPErrors.LSP_CLEANUP_TLV_MISSING); + this.fillIn(new PCEPErrorIdentifier((short) 6, (short) 14), PCEPErrors.SYMBOLIC_PATH_NAME_MISSING); + + this.fillIn(new PCEPErrorIdentifier((short) 7, (short) 0), PCEPErrors.SYNC_PATH_COMP_REQ_MISSING); + + this.fillIn(new PCEPErrorIdentifier((short) 8, (short) 0), PCEPErrors.UNKNOWN_REQ_REF); + + this.fillIn(new PCEPErrorIdentifier((short) 9, (short) 0), PCEPErrors.ATTEMPT_2ND_SESSION); + + this.fillIn(new PCEPErrorIdentifier((short) 10, (short) 1), PCEPErrors.P_FLAG_NOT_SET); + + this.fillIn(new PCEPErrorIdentifier((short) 12, (short) 1), PCEPErrors.UNSUPPORTED_CT); + this.fillIn(new PCEPErrorIdentifier((short) 12, (short) 2), PCEPErrors.INVALID_CT); + this.fillIn(new PCEPErrorIdentifier((short) 12, (short) 3), PCEPErrors.CT_AND_SETUP_PRIORITY_DO_NOT_FORM_TE_CLASS); - public static final int CLASS = 13; + this.fillIn(new PCEPErrorIdentifier((short) 15, (short) 1), PCEPErrors.INSUFFICIENT_MEMORY); + this.fillIn(new PCEPErrorIdentifier((short) 15, (short) 2), PCEPErrors.GCO_NOT_SUPPORTED); - public static final int TYPE = 1; + this.fillIn(new PCEPErrorIdentifier((short) 16, (short) 1), PCEPErrors.CANNOT_SATISFY_P2MP_REQUEST_DUE_TO_INSUFFISIENT_MEMMORY); + this.fillIn(new PCEPErrorIdentifier((short) 16, (short) 2), PCEPErrors.NOT_CAPPABLE_P2MP_COMPUTATION); + + this.fillIn(new PCEPErrorIdentifier((short) 17, (short) 1), PCEPErrors.P2MP_NOT_CAPPABLE_SATISFY_REQ_DUE_LT2); + this.fillIn(new PCEPErrorIdentifier((short) 17, (short) 2), PCEPErrors.P2MP_NOT_CAPPABLE_SATISFY_REQ_DUE_LT3); + this.fillIn(new PCEPErrorIdentifier((short) 17, (short) 3), PCEPErrors.P2MP_NOT_CAPPABLE_SATISFY_REQ_DUE_LT4); + this.fillIn(new PCEPErrorIdentifier((short) 17, (short) 4), PCEPErrors.P2MP_NOT_CAPPABLE_SATISFY_REQ_DUE_INCONSISTENT_EP); + + this.fillIn(new PCEPErrorIdentifier((short) 18, (short) 1), PCEPErrors.P2MP_FRAGMENTATION_FAILRUE); + + this.fillIn(new PCEPErrorIdentifier((short) 19, (short) 1), PCEPErrors.UPDATE_REQ_FOR_NON_LSP); + this.fillIn(new PCEPErrorIdentifier((short) 19, (short) 2), PCEPErrors.UPDATE_REQ_FOR_NO_STATEFUL); + //TODO: value TBD + this.fillIn(new PCEPErrorIdentifier((short) 19, (short) 3), PCEPErrors.LSP_LIMIT_REACHED); + this.fillIn(new PCEPErrorIdentifier((short) 19, (short) 4), PCEPErrors.DELEGATION_NOT_REVOKED); + + this.fillIn(new PCEPErrorIdentifier((short) 20, (short) 1), PCEPErrors.CANNOT_PROCESS_STATE_REPORT); + this.fillIn(new PCEPErrorIdentifier((short) 20, (short) 2), PCEPErrors.LSP_DB_VERSION_MISMATCH); + this.fillIn(new PCEPErrorIdentifier((short) 20, (short) 3), PCEPErrors.DB_VERSION_TLV_MISSING_WHEN_SYNC_ALLOWED); + + this.fillIn(new PCEPErrorIdentifier((short) 23, (short) 1), PCEPErrors.USED_SYMBOLIC_PATH_NAME); + } + + private void fillIn(final PCEPErrorIdentifier identifier, final PCEPErrors error) { + this.errorsMap.put(error, identifier); + this.errorIdsMap.put(identifier, error); + } + + public PCEPErrorIdentifier getFromErrorsEnum(final PCEPErrors error) { + final PCEPErrorIdentifier ei = this.errorsMap.get(error); + if (ei == null) { + logger.debug("Unknown PCEPErrors type: {}.", error); + throw new NoSuchElementException("Unknown PCEPErrors type: " + error); + } + return ei; + } + + public PCEPErrors getFromErrorIdentifier(final PCEPErrorIdentifier identifier) { + final PCEPErrors e = this.errorIdsMap.get(identifier); + if (e == null) { + logger.debug("Unknown error type/value combination: {}.", identifier); + throw new NoSuchElementException("Unknown error type/value combination: " + identifier); + } + return e; + } + + public static PCEPErrorsMaping getInstance() { + return instance; + } + } public static final int FLAGS_F_LENGTH = 1; public static final int ET_F_LENGTH = 1; public static final int EV_F_LENGTH = 1; - public static final int FLAGS_F_OFFSET = 1; // added reserved field of size 1 byte + public static final int FLAGS_F_OFFSET = 1; //added reserved field of size 1 byte public static final int ET_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH; public static final int EV_F_OFFSET = ET_F_OFFSET + ET_F_LENGTH; public static final int TLVS_OFFSET = EV_F_OFFSET + EV_F_LENGTH; - public PCEPErrorObjectParser(final HandlerRegistry registry) { - super(registry); - } + private final static Logger logger = LoggerFactory.getLogger(PCEPErrorObjectParser.class); @Override - public PcepErrorObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, - PCEPDocumentedException { + public PCEPObject parse(final byte[] bytes, final boolean processed, final boolean ignored) throws PCEPDeserializerException { if (bytes == null) throw new IllegalArgumentException("Array of bytes is mandatory."); - final ErrorsBuilder builder = new ErrorsBuilder(); + if (bytes.length < TLVS_OFFSET) + throw new PCEPDeserializerException("Wrong size of array of bytes. Passed: " + bytes.length + "; Expected: >=" + TLVS_OFFSET); - parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_OFFSET)); + final PCEPErrorIdentifier eid = new PCEPErrorIdentifier((short) (bytes[ET_F_OFFSET] & 0xFF), (short) (bytes[EV_F_OFFSET] & 0xFF)); + final PCEPErrors error; - builder.setIgnore(header.isIgnore()); - builder.setProcessingRule(header.isProcessingRule()); - - builder.setType((short) (bytes[ET_F_OFFSET] & 0xFF)); - builder.setValue((short) (bytes[EV_F_OFFSET] & 0xFF)); + try { + error = PCEPErrorsMaping.getInstance().getFromErrorIdentifier(eid); + } catch (final NoSuchElementException e) { + logger.debug("Failed to identify error {}", eid, e); + throw new PCEPDeserializerException(e, "Error object has unknown identifier."); + } - return builder.build(); + return new PCEPErrorObject(error, PCEPTlvParser.parse(ByteArray.cutBytes(bytes, TLVS_OFFSET))); } @Override - public void addTlv(final ErrorsBuilder builder, final Tlv tlv) { - if (tlv instanceof ReqMissingTlv && builder.getType() == 7) - builder.setTlvs(new TlvsBuilder().setReqMissing( - new ReqMissingBuilder().setRequestId(((ReqMissingTlv) tlv).getRequestId()).build()).build()); - } + public byte[] put(final PCEPObject obj) { + if (!(obj instanceof PCEPErrorObject)) + throw new IllegalArgumentException("Unknown PCEPObject instance."); - @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof PcepErrorObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed PcepErrorObject."); + final PCEPErrorObject errObj = (PCEPErrorObject) obj; - final PcepErrorObject errObj = (PcepErrorObject) object; + final byte[] tlvs = PCEPTlvParser.put(errObj.getTlvs()); + final byte[] retBytes = new byte[TLVS_OFFSET + tlvs.length]; - final byte[] tlvs = serializeTlvs(((Errors) errObj).getTlvs()); - int tlvsLength = 0; - if (tlvs != null) - tlvsLength = tlvs.length; - final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)]; + ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET); - if (tlvs != null) - ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET); + final PCEPErrorIdentifier identifier = PCEPErrorsMaping.getInstance().getFromErrorsEnum(errObj.getError()); - retBytes[ET_F_OFFSET] = ByteArray.shortToBytes(errObj.getType())[1]; - retBytes[EV_F_OFFSET] = ByteArray.shortToBytes(errObj.getValue())[1]; + retBytes[ET_F_OFFSET] = ByteArray.shortToBytes(identifier.type)[1]; + retBytes[EV_F_OFFSET] = ByteArray.shortToBytes(identifier.value)[1]; return retBytes; } - public byte[] serializeTlvs(final Tlvs tlvs) { - if (tlvs.getReqMissing() != null) { - return serializeTlv(new ReqMissingBuilder().setRequestId(tlvs.getReqMissing().getRequestId()).build()); - } - return null; - } - - @Override - public int getObjectType() { - return TYPE; - } - - @Override - public int getObjectClass() { - return CLASS; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExcludeRouteObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExcludeRouteObjectParser.java index 0617e315ec..e511e2f021 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExcludeRouteObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExcludeRouteObjectParser.java @@ -7,63 +7,70 @@ */ package org.opendaylight.protocol.pcep.impl.object; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExcludeRouteObject; +import java.util.Arrays; +import java.util.BitSet; +import java.util.List; + +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.impl.PCEPXROSubobjectParser; +import org.opendaylight.protocol.pcep.object.PCEPExcludeRouteObject; +import org.opendaylight.protocol.pcep.subobject.ExcludeRouteSubobject; /** - * Parser for {@link ExcludeRouteObject} + * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPExcludeRouteObject + * PCEPExcludeRouteObject} */ -// FIXME: fix model, this object is not used in a message -public final class PCEPExcludeRouteObjectParser { // extends AbstractObjectParser { +public class PCEPExcludeRouteObjectParser implements PCEPObjectParser { + + /* + * lengths of fields in bytes + */ + public final int FLAGS_F_LENGTH = 2; + + /* + * offsets of fields in bytes + */ + public final int FLAGS_F_OFFSET = 2; // added reserved 2 bytes + public final int SO_F_OFFSET = this.FLAGS_F_OFFSET + this.FLAGS_F_LENGTH; + + /* + * Flag offsets inside flags field in bits + */ + public final int F_FLAG_OFFSET = 15; + + @Override + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException, PCEPDocumentedException { + if (bytes == null || bytes.length == 0) + throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty."); + + final BitSet flags = ByteArray.bytesToBitSet(Arrays.copyOfRange(bytes, this.FLAGS_F_OFFSET, this.FLAGS_F_LENGTH)); + + final List subobjects = PCEPXROSubobjectParser.parse(ByteArray.cutBytes(bytes, this.SO_F_OFFSET)); + if (subobjects.isEmpty()) + throw new PCEPDeserializerException("Empty Exclude Route Object."); + + return new PCEPExcludeRouteObject(subobjects, flags.get(this.F_FLAG_OFFSET), processed, ignored); + } + + @Override + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPExcludeRouteObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPExcludeRouteObject."); + + assert !(((PCEPExcludeRouteObject) obj).getSubobjects().isEmpty()) : "Empty Exclude Route Object."; - public static final int CLASS = 7; // FIXME: to actual value + final byte[] subObjsBytes = PCEPXROSubobjectParser.put(((PCEPExcludeRouteObject) obj).getSubobjects()); + final byte[] retBytes = new byte[this.SO_F_OFFSET + subObjsBytes.length]; + final BitSet flags = new BitSet(this.FLAGS_F_LENGTH * Byte.SIZE); + flags.set(this.F_FLAG_OFFSET, ((PCEPExcludeRouteObject) obj).isFail()); + ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, this.FLAGS_F_LENGTH), retBytes, this.FLAGS_F_OFFSET); + ByteArray.copyWhole(subObjsBytes, retBytes, this.SO_F_OFFSET); - public static final int TYPE = 1; + return retBytes; + } - // public PCEPExcludeRouteObjectParser(final HandlerRegistry registry) { - // super(registry); - // } - // - // @Override - // public ExcludeRouteObject parseObject(final ObjectHeader header, final byte[] bytes) throws - // PCEPDeserializerException, - // PCEPDocumentedException { - // if (bytes == null || bytes.length == 0) - // throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty."); - // - // final ExcludeRouterBuilder builder = new ExcludeRouterBuilder(); - // - // builder.setIgnore(header.isIgnore()); - // builder.setProcessingRule(header.isProcessingRule()); - // // FIXME: add subobjects - // return builder.build(); - // } - // - // @Override - // public void addTlv(final ExcludeRouterBuilder builder, final Tlv tlv) { - // // No tlvs defined - // } - // - // @Override - // public byte[] serializeObject(final Object object) { - // if (!(object instanceof ExcludeRouteObject)) - // throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + - // ". Needed ExcludeRouteObject."); - // - // assert !(((ExcludeRouteObject) object).getSubobjects().isEmpty()) : "Empty Excluded Route Object."; - // - // // return PCEPEROSubobjectParser.put(((ExplicitRouteObject) obj).getSubobjects()); - // - // // FIXME: add subobjects - // return null; - // } - // - // @Override - // public int getObjectType() { - // return TYPE; - // } - // - // @Override - // public int getObjectClass() { - // return CLASS; - // } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExistingPathBandwidthObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExistingPathBandwidthObjectParser.java new file mode 100644 index 0000000000..93ef01514f --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExistingPathBandwidthObjectParser.java @@ -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.protocol.pcep.impl.object; + +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.object.PCEPExistingPathBandwidthObject; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Bandwidth; + +/** + * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPExistingPathBandwidthObject + * PCEPExistingPathBandwidthObject} + */ +public class PCEPExistingPathBandwidthObjectParser implements PCEPObjectParser { + + private static final int BANDWIDTH_F_LENGTH = 4; + + @Override + public PCEPObject parse(final byte[] bytes, final boolean processed, final boolean ignored) throws PCEPDeserializerException { + if (bytes == null) + throw new IllegalArgumentException("Array of bytes is mandatory"); + if (bytes.length != BANDWIDTH_F_LENGTH) + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: " + + BANDWIDTH_F_LENGTH + "."); + + return new PCEPExistingPathBandwidthObject(new Bandwidth(bytes), processed, ignored); + } + + @Override + public byte[] put(final PCEPObject obj) { + if (!(obj instanceof PCEPExistingPathBandwidthObject)) + throw new IllegalArgumentException("Unknown PCEPObject instance."); + + return ((PCEPExistingPathBandwidthObject) obj).getBandwidth().getValue(); + } +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExplicitRouteObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExplicitRouteObjectParser.java index 46ecbaae8e..aad0c00c3b 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExplicitRouteObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPExplicitRouteObjectParser.java @@ -7,104 +7,41 @@ */ package org.opendaylight.protocol.pcep.impl.object; -import java.util.Map; +import java.util.List; import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; -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.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.explicit.route.object.Subobjects; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.definition.ExplicitRouteBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject; - -import com.google.common.collect.Maps; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPEROSubobjectParser; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; /** - * Parser for {@link ExplicitRouteObject} + * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject + * PCEPExplicitRouteObject} */ -public class PCEPExplicitRouteObjectParser extends AbstractObjectParser { - - public static final int CLASS = 7; - - public static final int TYPE = 1; - - public PCEPExplicitRouteObjectParser(final HandlerRegistry registry) { - super(registry); - } +public class PCEPExplicitRouteObjectParser implements PCEPObjectParser { @Override - public ExplicitRouteObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, - PCEPDocumentedException { + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException { if (bytes == null || bytes.length == 0) throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty."); - final ExplicitRouteBuilder builder = new ExplicitRouteBuilder(); - - builder.setIgnore(header.isIgnore()); - builder.setProcessingRule(header.isProcessingRule()); - - parseSubobjects(builder, bytes); - return builder.build(); - } + final List subobjects = PCEPEROSubobjectParser.parse(bytes); + if (subobjects.isEmpty()) + throw new PCEPDeserializerException("Empty Explicit Route Object."); - @Override - public void addTlv(final ExplicitRouteBuilder builder, final Tlv tlv) { - // No tlvs defined + return new PCEPExplicitRouteObject(subobjects, ignored); } @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof ExplicitRouteObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() - + ". Needed ExplicitRouteObject."); - - final ExplicitRouteObject ero = ((ExplicitRouteObject) object); - - assert !(ero.getSubobjects().isEmpty()) : "Empty Explicit Route Object."; - - final Map subs = Maps.newHashMap(); - for (final Subobjects s : ero.getSubobjects()) { - subs.put((CSubobject) s, s.isLoose()); - } - return serializeSubobject(subs); - } + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPExplicitRouteObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPExplicitRouteObject."); - // @Override - // public void addSubobject(ExplicitRouteBuilder builder, Map subobjects) { - // List subs = Lists.newArrayList(); - // for (Entry entry : subobjects.entrySet()) { - // SubobjectsBuilder b = new SubobjectsBuilder(); - // b.setLoose(entry.getValue()); - // CSubobject sub = entry.getKey(); - // if (sub instanceof IpPrefixSubobject) { - // b.setSubobjectType(new IpPrefixBuilder().setIpPrefix(((IpPrefix)sub).getIpPrefix()).build()); - // subs.add(b.build()); - // } else if (sub instanceof AsNumberSubobject) { - // b.setSubobjectType(new AsNumberBuilder().setAsNumber((AsNumber)sub).build()); - // subs.add(b.build()); - // } else if (sub instanceof LabelSubobject) { - // b.setSubobjectType(new LabelBuilder().setLabels(((Label)sub).getLabels()).build()); - // subs.add(b.build()); - // } else if (sub instanceof UnnumberedSubobject) { - // b.setSubobjectType(new - // UnnumberedBuilder().setInterfaceId(((Unnumbered)sub).getInterfaceId()).setRouterId(((Unnumbered)sub).getRouterId()).build()); - // subs.add(b.build()); - // } - // } - // builder.setSubobjects(subs); - // } + assert !(((PCEPExplicitRouteObject) obj).getSubobjects().isEmpty()) : "Empty Explicit Route Object."; - @Override - public int getObjectType() { - return TYPE; + return PCEPEROSubobjectParser.put(((PCEPExplicitRouteObject) obj).getSubobjects()); } - @Override - public int getObjectClass() { - return CLASS; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPGlobalConstraintsObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPGlobalConstraintsObjectParser.java index 3836b6da39..13795b47d4 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPGlobalConstraintsObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPGlobalConstraintsObjectParser.java @@ -9,23 +9,17 @@ package org.opendaylight.protocol.pcep.impl.object; import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.impl.PCEPTlvParser; +import org.opendaylight.protocol.pcep.object.PCEPGlobalConstraintsObject; 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; /** - * Parser for {@link GcObject} + * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPGlobalConstraintsObject + * PCEPGlobalConstraints} */ -public class PCEPGlobalConstraintsObjectParser extends AbstractObjectParser { - - public static final int CLASS = 24; - - public static final int TYPE = 1; +public class PCEPGlobalConstraintsObjectParser implements PCEPObjectParser { private final static int MAX_HOP_F_LENGTH = 1; private final static int MAX_UTIL_F_LENGTH = 1; @@ -39,62 +33,37 @@ public class PCEPGlobalConstraintsObjectParser extends AbstractObjectParser=" + TLVS_OFFSET + "."); - 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)); - - return builder.build(); + return new PCEPGlobalConstraintsObject((short) (bytes[MAX_HOP_F_OFFSET] & 0xFF), (short) (bytes[MAX_UTIL_F_OFFSET] & 0xFF), + (short) (bytes[MIN_UTIL_F_OFFSET] & 0xFF), (short) (bytes[OVER_BOOKING_FACTOR_F_OFFSET] & 0xFF), PCEPTlvParser.parse(ByteArray.cutBytes(bytes, + TLVS_OFFSET)), processed, ignored); } @Override - public void addTlv(final GcBuilder builder, final Tlv tlv) { - // No tlvs defined - } + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPGlobalConstraintsObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPGlobalConstraints."); - @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof GcObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed GcObject."); - - final GcObject specObj = (GcObject) object; + final PCEPGlobalConstraintsObject specObj = (PCEPGlobalConstraintsObject) obj; - // final byte[] tlvs = PCEPTlvParser.put(specObj.getTlvs()); - final byte[] retBytes = new byte[TLVS_OFFSET + 0]; + final byte[] tlvs = PCEPTlvParser.put(specObj.getTlvs()); + final byte[] retBytes = new byte[TLVS_OFFSET + tlvs.length]; - 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(); + retBytes[MAX_HOP_F_OFFSET] = (byte) specObj.getMaxHop(); + retBytes[MAX_UTIL_F_OFFSET] = (byte) specObj.getMaxUtilization(); + retBytes[MIN_UTIL_F_OFFSET] = (byte) specObj.getMinUtilization(); + retBytes[OVER_BOOKING_FACTOR_F_OFFSET] = (byte) specObj.getOverBookingFactor(); - // ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET); + ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET); return retBytes; } - @Override - public int getObjectType() { - return TYPE; - } - - @Override - public int getObjectClass() { - return CLASS; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPIncludeRouteObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPIncludeRouteObjectParser.java index 2cf506db80..60e1cc3b78 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPIncludeRouteObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPIncludeRouteObjectParser.java @@ -7,67 +7,41 @@ */ package org.opendaylight.protocol.pcep.impl.object; +import java.util.List; + import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; -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.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.lsp.attributes.IncludeRouteBuilder; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPEROSubobjectParser; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.object.PCEPIncludeRouteObject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; /** - * Parser for {@link IncludeRouteObject} + * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPIncludeRouteObject + * PCEPIncludeRouteObject} */ -public class PCEPIncludeRouteObjectParser extends AbstractObjectParser { - - public static final int CLASS = 10; - - public static final int TYPE = 1; - - public PCEPIncludeRouteObjectParser(final HandlerRegistry registry) { - super(registry); - } +public class PCEPIncludeRouteObjectParser implements PCEPObjectParser { @Override - public IncludeRouteObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, - PCEPDocumentedException { + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException { if (bytes == null || bytes.length == 0) throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty."); - final IncludeRouteBuilder builder = new IncludeRouteBuilder(); + final List subobjects = PCEPEROSubobjectParser.parse(bytes); + if (subobjects.isEmpty()) + throw new PCEPDeserializerException("Empty Include Route Object."); - builder.setIgnore(header.isIgnore()); - builder.setProcessingRule(header.isProcessingRule()); - // FIXME: add subobjects - return builder.build(); + return new PCEPIncludeRouteObject(subobjects, processed, ignored); } @Override - public void addTlv(final IncludeRouteBuilder builder, final Tlv tlv) { - // No tlvs defined - } + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPIncludeRouteObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPIncludeRouteObject."); - @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof IncludeRouteObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed IncludeRouteObject."); + assert !(((PCEPIncludeRouteObject) obj).getSubobjects().isEmpty()) : "Empty Include Route Object."; - assert !(((IncludeRouteObject) object).getSubobjects().isEmpty()) : "Empty Include Route Object."; - - // return PCEPEROSubobjectParser.put(((PCEPIncludeRouteObject) object).getSubobjects()); - // FIXME add subobjects - return null; - } - - @Override - public int getObjectType() { - return TYPE; + return PCEPEROSubobjectParser.put(((PCEPIncludeRouteObject) obj).getSubobjects()); } - @Override - public int getObjectClass() { - return CLASS; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLoadBalancingObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLoadBalancingObjectParser.java index 3127a55010..f16b8fcc95 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLoadBalancingObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLoadBalancingObjectParser.java @@ -8,25 +8,16 @@ package org.opendaylight.protocol.pcep.impl.object; import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.object.PCEPLoadBalancingObject; 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.LoadBalancingObject; -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.requests.segment.computation.p2p.LoadBalancingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Bandwidth; /** * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPLoadBalancingObject PCEPLoadBalancingObject} */ -public class PCEPLoadBalancingObjectParser extends AbstractObjectParser { - - public static final int CLASS = 14; - - public static final int TYPE = 1; +public class PCEPLoadBalancingObjectParser implements PCEPObjectParser { public static final int FLAGS_F_LENGTH = 1; public static final int MAX_LSP_F_LENGTH = 1; @@ -38,58 +29,31 @@ public class PCEPLoadBalancingObjectParser extends AbstractObjectParser { - - public static final int CLASS = 32; - - public static final int TYPE = 1; +public class PCEPLspObjectParser implements PCEPObjectParser { /* * offset of TLVs offset of other fields are not defined as constants @@ -43,76 +35,48 @@ public class PCEPLspObjectParser extends AbstractObjectParser { private static final int SYNC_FLAG_OFFSET = 14; private static final int REMOVE_FLAG_OFFSET = 12; - public PCEPLspObjectParser(final HandlerRegistry registry) { - super(registry); - } - @Override - public LspObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException { + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException { if (bytes == null || bytes.length == 0) throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty."); - final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(bytes, 2, 2)); - - final LspBuilder builder = new LspBuilder(); - - parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_OFFSET)); - - builder.setIgnore(header.isIgnore()); - builder.setProcessingRule(header.isProcessingRule()); - - // builder.setPlspId(new PlspId(ByteArray.bytesToLong(ByteArray.subByte(bytes, 0, 2)) & 0xFFFF) << 4 | (bytes[2] - // & 0xFF) >> 4)); - builder.setDelegate(flags.get(DELEGATE_FLAG_OFFSET)); - builder.setSync(flags.get(SYNC_FLAG_OFFSET)); - // builder.setOperational(Operational.flags.get(OPERATIONAL_FLAG_OFFSET)); - builder.setRemove(flags.get(REMOVE_FLAG_OFFSET)); + if (bytes.length < TLVS_OFFSET) + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: >=" + TLVS_OFFSET + "."); - return builder.build(); - } + final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(bytes, 2, 2)); - @Override - public void addTlv(final LspBuilder builder, final Tlv tlv) { - // FIXME : finish + return new PCEPLspObject((ByteArray.bytesToShort(ByteArray.subByte(bytes, 0, 2)) & 0xFFFF) << 4 | (bytes[2] & 0xFF) >> 4, + flags.get(DELEGATE_FLAG_OFFSET), flags.get(SYNC_FLAG_OFFSET), flags.get(OPERATIONAL_FLAG_OFFSET), flags.get(REMOVE_FLAG_OFFSET), + PCEPTlvParser.parse(ByteArray.cutBytes(bytes, TLVS_OFFSET))); } @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof LspObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed LspObject."); + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPLspObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPLspObject."); - final LspObject specObj = (LspObject) object; + final PCEPLspObject specObj = (PCEPLspObject) obj; - // final byte[] tlvs = PCEPTlvParser.put(specObj.getTlvs()); + final byte[] tlvs = PCEPTlvParser.put(specObj.getTlvs()); - final byte[] retBytes = new byte[0 + TLVS_OFFSET]; + final byte[] retBytes = new byte[tlvs.length + TLVS_OFFSET]; - final int lspID = specObj.getPlspId().getValue().intValue(); + final int lspID = specObj.getLspID(); retBytes[0] = (byte) (lspID >> 12); retBytes[1] = (byte) (lspID >> 4); retBytes[2] = (byte) (lspID << 4); if (specObj.isDelegate()) retBytes[3] |= 1 << (Byte.SIZE - (DELEGATE_FLAG_OFFSET - Byte.SIZE) - 1); - // FIXME: !! - // if (specObj.isOperational()) - // retBytes[3] |= 1 << (Byte.SIZE - (OPERATIONAL_FLAG_OFFSET - Byte.SIZE) - 1); + if (specObj.isOperational()) + retBytes[3] |= 1 << (Byte.SIZE - (OPERATIONAL_FLAG_OFFSET - Byte.SIZE) - 1); if (specObj.isRemove()) retBytes[3] |= 1 << (Byte.SIZE - (REMOVE_FLAG_OFFSET - Byte.SIZE) - 1); if (specObj.isSync()) retBytes[3] |= 1 << (Byte.SIZE - (SYNC_FLAG_OFFSET - Byte.SIZE) - 1); - // ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET); + ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET); return retBytes; } - @Override - public int getObjectType() { - return TYPE; - } - - @Override - public int getObjectClass() { - return CLASS; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspaObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspaObjectParser.java index 489e1a2a04..6cbe71dd4c 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspaObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspaObjectParser.java @@ -10,28 +10,20 @@ package org.opendaylight.protocol.pcep.impl.object; import java.util.BitSet; import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.impl.PCEPTlvParser; +import org.opendaylight.protocol.pcep.object.PCEPLspaObject; import org.opendaylight.protocol.util.ByteArray; -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.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.lsp.attributes.LspaBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AttributeFilter; +import com.google.common.primitives.UnsignedInts; /** - * Parser for {@link LspaObject} + * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPLspaObject PCEPLspaObject} */ -public class PCEPLspaObjectParser extends AbstractObjectParser { - - public static final int CLASS = 9; - - public static final int TYPE = 1; +public class PCEPLspaObjectParser implements PCEPObjectParser { /* - * lengths of fields in bytes + * lenghts of fields in bytes */ public static final int EXC_ANY_F_LENGTH = 4; public static final int INC_ANY_F_LENGTH = 4; @@ -55,75 +47,45 @@ public class PCEPLspaObjectParser extends AbstractObjectParser { 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 - - public PCEPLspaObjectParser(final HandlerRegistry registry) { - super(registry); - } + public static final int TLVS_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH + 1; //added reserved field of length 1B @Override - public LspaObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException { + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException { 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.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(); + return new PCEPLspaObject(UnsignedInts.toLong(ByteArray.bytesToInt(ByteArray.subByte(bytes, EXC_ANY_F_OFFSET, EXC_ANY_F_LENGTH))), + UnsignedInts.toLong(ByteArray.bytesToInt(ByteArray.subByte(bytes, INC_ANY_F_OFFSET, INC_ANY_F_LENGTH))), UnsignedInts.toLong(ByteArray + .bytesToInt(ByteArray.subByte(bytes, INC_ALL_F_OFFSET, INC_ALL_F_LENGTH))), (short) (bytes[SET_PRIO_F_OFFSET] & 0xFF), + (short) (bytes[HOLD_PRIO_F_OFFSET] & 0xFF), flags.get(S_FLAG_OFFSET), flags.get(L_FLAG_OFFSET), PCEPTlvParser.parse(ByteArray.cutBytes(bytes, TLVS_F_OFFSET)), processed, + ignored); } @Override - public void addTlv(final LspaBuilder builder, final Tlv tlv) { - // No tlvs defined - } + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPLspaObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPLspaObject."); - @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof LspaObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed LspaObject."); - - final LspaObject lspaObj = (LspaObject) object; + final PCEPLspaObject lspaObj = (PCEPLspaObject) obj; - // 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[] 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); + System.arraycopy(ByteArray.longToBytes(lspaObj.getExcludeAny()), 4, retBytes, EXC_ANY_F_OFFSET, EXC_ANY_F_LENGTH); + System.arraycopy(ByteArray.longToBytes(lspaObj.getIncludeAny()), 4, retBytes, INC_ANY_F_OFFSET, INC_ANY_F_LENGTH); + System.arraycopy(ByteArray.longToBytes(lspaObj.getIncludeAll()), 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[HOLD_PRIO_F_OFFSET] = ByteArray.shortToBytes(lspaObj.getHoldingPriority())[Short.SIZE / Byte.SIZE - 1]; final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE); - flags.set(L_FLAG_OFFSET, lspaObj.isLocalProtectionDesired()); + flags.set(S_FLAG_OFFSET, lspaObj.isStandByPath()); + flags.set(L_FLAG_OFFSET, lspaObj.isLocalProtected()); ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS_F_OFFSET); return retBytes; } - @Override - public int getObjectType() { - return TYPE; - } - - @Override - public int getObjectClass() { - return CLASS; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPMetricObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPMetricObjectParser.java index 2f50386bc1..2696e29667 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPMetricObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPMetricObjectParser.java @@ -8,28 +8,31 @@ package org.opendaylight.protocol.pcep.impl.object; import java.util.BitSet; +import java.util.HashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import org.opendaylight.protocol.concepts.AbstractMetric; +import org.opendaylight.protocol.concepts.IGPMetric; +import org.opendaylight.protocol.concepts.TEMetric; import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.concepts.AggregateBandwidthConsumptionMetric; +import org.opendaylight.protocol.pcep.concepts.CumulativeIGPCostMetric; +import org.opendaylight.protocol.pcep.concepts.CumulativeTECostMetric; +import org.opendaylight.protocol.pcep.concepts.MostLoadedLinkLoadMetric; +import org.opendaylight.protocol.pcep.concepts.P2MPHopCountMetric; +import org.opendaylight.protocol.pcep.concepts.P2MPIGPMetric; +import org.opendaylight.protocol.pcep.concepts.P2MPTEMetric; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.object.PCEPMetricObject; 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.MetricObject; -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.Metric; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.MetricBuilder; /** - * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPMetricObject PCEPMetricObject} + * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPMetricObject + * PCEPMetricObject} */ -public class PCEPMetricObjectParser extends AbstractObjectParser { - - public static final int CLASS = 6; - - public static final int TYPE = 1; +public class PCEPMetricObjectParser implements PCEPObjectParser { /* * lengths of fields in bytes @@ -53,64 +56,164 @@ public class PCEPMetricObjectParser extends AbstractObjectParser public static final int SIZE = METRIC_VALUE_F_OFFSET + METRIC_VALUE_F_LENGTH; - public PCEPMetricObjectParser(final HandlerRegistry registry) { - super(registry); + /** + * Bidirectional mapping for metrics. Maps metric class to integer and + * integer to metrics instantiable. + */ + public static class PCEPMetricsMapping { + private static final PCEPMetricsMapping instance = new PCEPMetricsMapping(); + + private final Map, Integer> metricsMap = new HashMap, Integer>(); + private final Map metrictTypesMap = new HashMap(); + + private interface InstantiableMetric { + public AbstractMetric getMetric(long metric); + } + + private PCEPMetricsMapping() { + this.fillIn(); + } + + private void fillIn() { + this.fillIn(1, IGPMetric.class, new InstantiableMetric() { + + @Override + public AbstractMetric getMetric(long metric) { + return new IGPMetric(metric); + } + + }); + this.fillIn(2, TEMetric.class, new InstantiableMetric() { + + @Override + public AbstractMetric getMetric(long metric) { + return new TEMetric(metric); + } + + }); + this.fillIn(4, AggregateBandwidthConsumptionMetric.class, new InstantiableMetric() { + + @Override + public AbstractMetric getMetric(long metric) { + return new AggregateBandwidthConsumptionMetric(metric); + } + + }); + this.fillIn(5, MostLoadedLinkLoadMetric.class, new InstantiableMetric() { + + @Override + public AbstractMetric getMetric(long metric) { + return new MostLoadedLinkLoadMetric(metric); + } + + }); + this.fillIn(6, CumulativeIGPCostMetric.class, new InstantiableMetric() { + + @Override + public AbstractMetric getMetric(long metric) { + return new CumulativeIGPCostMetric(metric); + } + + }); + this.fillIn(7, CumulativeTECostMetric.class, new InstantiableMetric() { + + @Override + public AbstractMetric getMetric(long metric) { + return new CumulativeTECostMetric(metric); + } + + }); + this.fillIn(8, P2MPIGPMetric.class, new InstantiableMetric() { + + @Override + public AbstractMetric getMetric(long metric) { + return new P2MPIGPMetric(metric); + } + + }); + this.fillIn(9, P2MPTEMetric.class, new InstantiableMetric() { + + @Override + public AbstractMetric getMetric(long metric) { + return new P2MPHopCountMetric(metric); + } + + }); + this.fillIn(10, P2MPHopCountMetric.class, new InstantiableMetric() { + + @Override + public AbstractMetric getMetric(long metric) { + return new P2MPHopCountMetric(metric); + } + + }); + } + + private void fillIn(int type, Class metricClazz, InstantiableMetric instantiable) { + this.metricsMap.put(metricClazz, type); + this.metrictTypesMap.put(type, instantiable); + } + + public int getFromMetricClass(Class> clazz) { + final Integer mi = this.metricsMap.get(clazz); + if (mi == null) + throw new NoSuchElementException("Unknown Metric: " + clazz); + return mi; + } + + public AbstractMetric getFromMetricTypeIdentifier(int identifier, long metric) { + final InstantiableMetric e = this.metrictTypesMap.get(identifier); + if (e == null) + throw new NoSuchElementException("Unknown metric type identifier. Passed: " + identifier); + return e.getMetric(metric); + } + + public static PCEPMetricsMapping getInstance() { + return instance; + } } @Override - public MetricObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, - PCEPDocumentedException { + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException { if (bytes == null || bytes.length == 0) throw new IllegalArgumentException("Array of bytes 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 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.setValue(new Float32(ByteArray.subByte(bytes, METRIC_VALUE_F_OFFSET, METRIC_VALUE_F_LENGTH))); - - return builder.build(); + try { + return new PCEPMetricObject(flags.get(B_FLAG_OFFSET), flags.get(C_FLAG_OFFSET), PCEPMetricsMapping.getInstance().getFromMetricTypeIdentifier( + (short) (bytes[TYPE_F_OFFSET] & 0xFF), + (long) ByteArray.bytesToFloat(ByteArray.subByte(bytes, METRIC_VALUE_F_OFFSET, METRIC_VALUE_F_LENGTH))), processed, ignored); + } catch (final NoSuchElementException e) { + throw new PCEPDeserializerException(e, "Metric object has unknown identifier."); + } } @Override - public void addTlv(final MetricBuilder builder, final Tlv tlv) { - // No tlvs defined - } - - @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof MetricObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed MetricObject."); + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPMetricObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPMetricObject."); - final MetricObject mObj = (MetricObject) object; + final PCEPMetricObject mObj = (PCEPMetricObject) obj; 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(C_FLAG_OFFSET, mObj.isComputedMetric()); flags.set(B_FLAG_OFFSET, mObj.isBound()); ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS_F_OFFSET); - System.arraycopy(mObj.getValue().getValue(), 0, retBytes, METRIC_VALUE_F_OFFSET, METRIC_VALUE_F_LENGTH); + final AbstractMetric metric = mObj.getMetric(); + @SuppressWarnings("unchecked") + final Class> metricClazz = (Class>) metric.getClass(); + retBytes[TYPE_F_OFFSET] = (byte) PCEPMetricsMapping.getInstance().getFromMetricClass(metricClazz); - return retBytes; - } + System.arraycopy(ByteArray.floatToBytes(mObj.getMetric().getValue()), 0, retBytes, METRIC_VALUE_F_OFFSET, METRIC_VALUE_F_LENGTH); - @Override - public int getObjectType() { - return TYPE; + return retBytes; } - @Override - public int getObjectClass() { - return CLASS; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNoPathObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNoPathObjectParser.java index 8d5f41a0b0..95468317c3 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNoPathObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNoPathObjectParser.java @@ -10,32 +10,22 @@ package org.opendaylight.protocol.pcep.impl.object; 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.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.impl.PCEPTlvParser; +import org.opendaylight.protocol.pcep.object.PCEPNoPathObject; import org.opendaylight.protocol.util.ByteArray; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.pcrep.pcrep.message.replies.result.failure.NoPath; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.pcrep.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.NoPathBuilder; /** - * Parser for {@link NoPathObject} + * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPNoPathObject + * PCEPNoPathObject} */ -public class PCEPNoPathObjectParser extends AbstractObjectParser { - - public static final int CLASS = 3; - - public static final int TYPE = 1; +public class PCEPNoPathObjectParser implements PCEPObjectParser { /* * lengths of fields in bytes */ - public static final int NI_F_LENGTH = 1; // multi-field + public static final int NI_F_LENGTH = 1; //multi-field public static final int FLAGS_F_LENGTH = 2; public static final int RESERVED_F_LENGTH = 1; @@ -54,53 +44,31 @@ public class PCEPNoPathObjectParser extends AbstractObjectParser public static final int C_FLAG_OFFSET = 0; - public PCEPNoPathObjectParser(final HandlerRegistry registry) { - super(registry); - } - @Override - public NoPathObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, - PCEPDocumentedException { + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException { if (bytes == null || bytes.length == 0) throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty."); final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(bytes, FLAGS_F_OFFSET, FLAGS_F_LENGTH)); - final NoPathBuilder builder = new NoPathBuilder(); - - parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_OFFSET)); - - builder.setIgnore(header.isIgnore()); - builder.setProcessingRule(header.isProcessingRule()); - - builder.setNatureOfIssue((short) (bytes[NI_F_OFFSET] & 0xFF)); - builder.setUnsatisfiedConstraints(flags.get(C_FLAG_OFFSET)); - - return builder.build(); - } + if (bytes.length < TLVS_OFFSET) + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: >=" + TLVS_OFFSET + "."); - @Override - public void addTlv(final NoPathBuilder builder, final Tlv tlv) { - // FIXME : add no-path-vector-tlv + return new PCEPNoPathObject((short) (bytes[NI_F_OFFSET] & 0xFF), flags.get(C_FLAG_OFFSET), PCEPTlvParser.parse(ByteArray.cutBytes(bytes, TLVS_OFFSET)), + ignored); } @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof NoPathObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed NoPathObject."); - - final NoPathObject nPObj = (NoPathObject) object; + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPNoPathObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPNoPathObject."); - final byte[] tlvs = serializeTlvs(((NoPath) nPObj).getTlvs()); - int tlvsLength = 0; - if (tlvs != null) - tlvsLength = tlvs.length; - final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)]; + final PCEPNoPathObject nPObj = (PCEPNoPathObject) obj; - if (tlvs != null) - ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET); + final byte[] tlvs = PCEPTlvParser.put(nPObj.getTlvs()); + final byte[] retBytes = new byte[tlvs.length + TLVS_OFFSET]; final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE); - flags.set(C_FLAG_OFFSET, nPObj.isUnsatisfiedConstraints()); + flags.set(C_FLAG_OFFSET, nPObj.isConstrained()); retBytes[NI_F_OFFSET] = ByteArray.shortToBytes(nPObj.getNatureOfIssue())[1]; ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS_F_OFFSET); ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET); @@ -108,21 +76,4 @@ public class PCEPNoPathObjectParser extends AbstractObjectParser return retBytes; } - public byte[] serializeTlvs(final Tlvs tlvs) { - if (tlvs.getNoPathVector() != null) { - // FIXME : add NoPath - // return serializeTlv(new NoPathVectorBuilder().setFlags(tlvs.getNoPathVector()).build()); - } - return null; - } - - @Override - public int getObjectType() { - return TYPE; - } - - @Override - public int getObjectClass() { - return CLASS; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNonBranchNodeListObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNonBranchNodeListObjectParser.java new file mode 100644 index 0000000000..dd1fb9bb70 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNonBranchNodeListObjectParser.java @@ -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.impl.object; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPEROSubobjectParser; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.object.PCEPNonBranchNodeListObject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; + +public class PCEPNonBranchNodeListObjectParser implements PCEPObjectParser { + + @Override + public PCEPNonBranchNodeListObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException, PCEPDocumentedException { + if (bytes == null || bytes.length == 0) + throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty."); + + final List subobjects = PCEPEROSubobjectParser.parse(bytes); + if (subobjects.isEmpty()) + throw new PCEPDeserializerException("Empty Non-Branch Node List Object."); + + return new PCEPNonBranchNodeListObject(subobjects, processed, ignored); + } + + @Override + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPNonBranchNodeListObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPNonBranchNodeListObject."); + + assert !(((PCEPNonBranchNodeListObject) obj).getSubobjects().isEmpty()) : "Empty Non-Branch Node List Object."; + + return PCEPEROSubobjectParser.put(((PCEPNonBranchNodeListObject) obj).getSubobjects()); + } + +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNotificationObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNotificationObjectParser.java index 9c654954a6..7f277b7130 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNotificationObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNotificationObjectParser.java @@ -8,29 +8,17 @@ 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.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.impl.PCEPTlvParser; +import org.opendaylight.protocol.pcep.object.PCEPNotificationObject; import org.opendaylight.protocol.util.ByteArray; -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.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.OverloadDurationTlv; -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.notification.object.Tlvs; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.TlvsBuilder; -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.pcntf.message.pcntf.message.notifications.NotificationsBuilder; /** - * Parser for {@link NotificationObject} + * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPNotificationObject + * PCEPNotificationObject} */ -public class PCEPNotificationObjectParser extends AbstractObjectParser { - - public static final int CLASS = 12; - - public static final int TYPE = 1; +public class PCEPNotificationObjectParser implements PCEPObjectParser { /* * lengths of fields @@ -42,56 +30,34 @@ public class PCEPNotificationObjectParser extends AbstractObjectParser=" + TLVS_OFFSET + "."); - builder.setIgnore(header.isIgnore()); - builder.setProcessingRule(header.isProcessingRule()); - - builder.setType((short) (bytes[NT_F_OFFSET] & 0xFF)); - builder.setValue((short) (bytes[NV_F_OFFSET] & 0xFF)); - - return builder.build(); + return new PCEPNotificationObject((short) (bytes[NT_F_OFFSET] & 0xFF), (short) (bytes[NV_F_OFFSET] & 0xFF), PCEPTlvParser.parse(ByteArray.cutBytes( + bytes, TLVS_OFFSET))); } @Override - public void addTlv(final NotificationsBuilder builder, final Tlv tlv) { - if (tlv instanceof OverloadDurationTlv && builder.getType() == 2 && builder.getValue() == 1) - builder.setTlvs(new TlvsBuilder().setOverloadDuration( - new OverloadDurationBuilder().setDuration(((OverloadDurationTlv) tlv).getDuration()).build()).build()); - } + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPNotificationObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPNotificationObject."); - @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof NotificationObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed NotificationObject."); + final PCEPNotificationObject notObj = (PCEPNotificationObject) obj; - final NotificationObject notObj = (NotificationObject) object; + final byte[] tlvs = PCEPTlvParser.put(notObj.getTlvs()); + final byte[] retBytes = new byte[TLVS_OFFSET + tlvs.length]; - final byte[] tlvs = serializeTlvs(notObj.getTlvs()); - int tlvsLength = 0; - if (tlvs != null) - tlvsLength = tlvs.length; - final byte[] retBytes = new byte[TLVS_OFFSET + tlvsLength + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)]; - - if (tlvs != null) - ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET); + ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET); retBytes[NT_F_OFFSET] = ByteArray.shortToBytes(notObj.getType())[1]; retBytes[NV_F_OFFSET] = ByteArray.shortToBytes(notObj.getValue())[1]; @@ -99,21 +65,4 @@ public class PCEPNotificationObjectParser extends AbstractObjectParser { - - public static final int CLASS = 21; +public class PCEPObjectiveFunctionObjectParser implements PCEPObjectParser { - public static final int TYPE = 1; /* * lengths of fields */ @@ -38,56 +34,37 @@ public class PCEPObjectiveFunctionObjectParser extends AbstractObjectParser=" + TLVS_OFFSET + "."); + try { + return new PCEPObjectiveFunctionObject(PCEPOFCodesMapping.getInstance().getFromCodeIdentifier( + ByteArray.bytesToShort(ByteArray.subByte(bytes, OF_CODE_F_OFFSET, OF_CODE_F_LENGTH)) & 0xFFFF), PCEPTlvParser.parse(ByteArray.cutBytes( + bytes, TLVS_OFFSET)), processed, ignored); + } catch (final NoSuchElementException e) { + throw new PCEPDeserializerException(e, "Objective function object has unknown identifier."); + } } @Override - public void addTlv(final OfBuilder builder, final Tlv tlv) { - // No tlvs defined - } + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPObjectiveFunctionObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPObjectiveFunction."); - @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof OfObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() - + ". Needed PCEPObjectiveFunction."); + final PCEPObjectiveFunctionObject specObj = (PCEPObjectiveFunctionObject) obj; - final OfObject specObj = (OfObject) object; - // FIXME - // final byte[] tlvs = PCEPTlvParser.put(specObj.getTlvs()); - final byte[] retBytes = new byte[TLVS_OFFSET + 0]; + final byte[] tlvs = PCEPTlvParser.put(specObj.getTlvs()); + final byte[] retBytes = new byte[TLVS_OFFSET + tlvs.length]; - // ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET); + ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET); - ByteArray.copyWhole(ByteArray.shortToBytes(specObj.getCode().getValue().shortValue()), retBytes, OF_CODE_F_OFFSET); + ByteArray.copyWhole(ByteArray.shortToBytes((short) PCEPOFCodesMapping.getInstance().getFromOFCodesEnum(specObj.getCode())), retBytes, OF_CODE_F_OFFSET); return retBytes; } - @Override - public int getObjectType() { - return TYPE; - } - - @Override - public int getObjectClass() { - return CLASS; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPOpenObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPOpenObjectParser.java index 556d20b8cb..e9f7b3902a 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPOpenObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPOpenObjectParser.java @@ -8,41 +8,26 @@ package org.opendaylight.protocol.pcep.impl.object; +import java.util.List; + import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.PCEPDocumentedException; import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.PCEPTlv; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.impl.PCEPTlvParser; import org.opendaylight.protocol.pcep.impl.Util; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; +import org.opendaylight.protocol.pcep.tlv.OFListTlv; import org.opendaylight.protocol.util.ByteArray; -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.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.OfListTlv; -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.PredundancyGroupIdTlv; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion; -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.Tlv; -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.Tlvs; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.TlvsBuilder; -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 com.google.common.primitives.UnsignedBytes; /** - * Parser for {@link OpenObject} + * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPOpenObject PCEPOpenObject} */ -public class PCEPOpenObjectParser extends AbstractObjectParser { - - public static final int CLASS = 1; - - public static final int TYPE = 1; +public class PCEPOpenObjectParser implements PCEPObjectParser { /* * lengths of fields in bytes @@ -75,96 +60,65 @@ public class PCEPOpenObjectParser extends AbstractObjectParser { public static final int VERSION_SF_OFFSET = 0; public static final int FLAGS_SF_OFFSET = VERSION_SF_LENGTH + VERSION_SF_OFFSET; - private static final int PCEP_VERSION = 1; - - public PCEPOpenObjectParser(final HandlerRegistry registry) { - super(registry); - } + public static final int PADDED_TO = 4; @Override - public OpenObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException { + public PCEPOpenObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException, PCEPDocumentedException { if (bytes == null || bytes.length == 0) throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty."); + if (bytes.length < TLVS_OFFSET) + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: >=" + TLVS_OFFSET + "."); + + // parse version final int versionValue = ByteArray.copyBitsRange(bytes[VER_FLAGS_MF_OFFSET], VERSION_SF_OFFSET, VERSION_SF_LENGTH); - if (versionValue != PCEP_VERSION) + if (versionValue != PCEPOpenObject.PCEP_VERSION) throw new PCEPDocumentedException("Unsupported PCEP version " + versionValue, PCEPErrors.PCEP_VERSION_NOT_SUPPORTED); - final OpenBuilder builder = new OpenBuilder(); + final List tlvs = PCEPTlvParser.parse(ByteArray.cutBytes(bytes, TLVS_OFFSET)); + boolean ofListOccure = false; - parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_OFFSET)); + for (final PCEPTlv tlv : tlvs) { + if (tlv instanceof OFListTlv) { + if (ofListOccure) + throw new PCEPDocumentedException("Invalid or unexpected message", PCEPErrors.NON_OR_INVALID_OPEN_MSG); - builder.setVersion(new ProtocolVersion((short) versionValue)); - builder.setProcessingRule(header.isProcessingRule()); - builder.setIgnore(header.isIgnore()); - builder.setDeadTimer((short) UnsignedBytes.toInt(bytes[DEAD_TIMER_OFFSET])); - builder.setKeepalive((short) UnsignedBytes.toInt(bytes[KEEPALIVE_F_OFFSET])); - builder.setSessionId((short) UnsignedBytes.toInt(bytes[SID_F_OFFSET])); - return builder.build(); - } + ofListOccure = true; + } + } - @Override - public void addTlv(final OpenBuilder builder, final Tlv tlv) { - final TlvsBuilder tbuilder = new TlvsBuilder(); - if (tlv instanceof OfListTlv) - tbuilder.setOfList(new OfListBuilder().setCodes(((OfListTlv) tlv).getCodes()).build()); - else if (tlv instanceof StatefulCapabilityTlv) - tbuilder.setStateful(new StatefulBuilder().setFlags(((StatefulCapabilityTlv) tlv).getFlags()).build()); - else if (tlv instanceof PredundancyGroupIdTlv) - tbuilder.setPredundancyGroupId(new PredundancyGroupIdBuilder().setIdentifier(((PredundancyGroupIdTlv) tlv).getIdentifier()).build()); - else if (tlv instanceof LspDbVersionTlv) - tbuilder.setLspDbVersion(new LspDbVersionBuilder().build()); - builder.setTlvs(tbuilder.build()); + return new PCEPOpenObject(UnsignedBytes.toInt(bytes[KEEPALIVE_F_OFFSET]), UnsignedBytes.toInt(bytes[DEAD_TIMER_OFFSET]), + UnsignedBytes.toInt(bytes[SID_F_OFFSET]), tlvs); } @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof OpenObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed OpenObject."); - final OpenObject open = (OpenObject) object; + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPOpenObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPOpenObject."); - final byte versionFlagMF = (byte) (PCEP_VERSION << (Byte.SIZE - VERSION_SF_LENGTH)); + final PCEPOpenObject openObj = (PCEPOpenObject) obj; - final byte[] tlvs = serializeTlvs(open.getTlvs()); + final byte versionFlagMF = (byte) (PCEPOpenObject.PCEP_VERSION << (Byte.SIZE - VERSION_SF_LENGTH)); + final byte[] tlvs = PCEPTlvParser.put(openObj.getTlvs()); final byte[] bytes = new byte[TLVS_OFFSET + tlvs.length + Util.getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)]; + // serialize version_flags multi-field bytes[VER_FLAGS_MF_OFFSET] = versionFlagMF; - bytes[KEEPALIVE_F_OFFSET] = ByteArray.shortToBytes(open.getKeepalive())[1]; - bytes[DEAD_TIMER_OFFSET] = ByteArray.shortToBytes(open.getDeadTimer())[1]; - bytes[SID_F_OFFSET] = ByteArray.shortToBytes(open.getSessionId())[1]; - ByteArray.copyWhole(tlvs, bytes, TLVS_OFFSET); - return bytes; - } + // serialize keepalive + bytes[KEEPALIVE_F_OFFSET] = (byte) openObj.getKeepAliveTimerValue(); - public byte[] serializeTlvs(final Tlvs tlvs) { - int finalLength = 0; - if (tlvs.getLspDbVersion() != null) { - final byte[] lspDbBytes = serializeTlv(new LspDbVersionBuilder().setVersion(tlvs.getLspDbVersion().getVersion()).build()); - finalLength = lspDbBytes.length; - } - if (tlvs.getOfList() != null) { - final byte[] ofListBytes = serializeTlv(new OfListBuilder().setCodes(tlvs.getOfList().getCodes()).build()); - finalLength = ofListBytes.length; - } + // serialize dead timer + bytes[DEAD_TIMER_OFFSET] = (byte) openObj.getDeadTimerValue(); - // FIXME: finish + // serialize SID + bytes[SID_F_OFFSET] = (byte) openObj.getSessionId(); - final byte[] bytes = new byte[finalLength]; + // serialize tlvs + ByteArray.copyWhole(tlvs, bytes, TLVS_OFFSET); - // FIXME copy result bytes return bytes; } - - @Override - public int getObjectType() { - return TYPE; - } - - @Override - public int getObjectClass() { - return CLASS; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPP2MPEndPointsIPv4ObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPP2MPEndPointsIPv4ObjectParser.java new file mode 100644 index 0000000000..5b1196a0d4 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPP2MPEndPointsIPv4ObjectParser.java @@ -0,0 +1,68 @@ +/* + * 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.object; + +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.concepts.IPv4; +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.impl.Util; +import org.opendaylight.protocol.pcep.object.PCEPP2MPEndPointsObject; +import com.google.common.primitives.UnsignedInts; + +/** + * Parser for IPv4 {@link org.opendaylight.protocol.pcep.object.PCEPP2MPEndPointsObject + * PCEPP2MPEndPointsObject} + */ +public class PCEPP2MPEndPointsIPv4ObjectParser implements PCEPObjectParser { + + /* + * fields lengths and offsets for IPv4 in bytes + */ + public static final int LEAF_TYPE_F_LENGTH = 4; + public static final int SRC4_F_LENGTH = 4; + public static final int DEST4_F_LENGTH = 4; + + public static final int LEAF_TYPE_F_OFFSET = 0; + public static final int SRC4_F_OFFSET = LEAF_TYPE_F_OFFSET + LEAF_TYPE_F_LENGTH; + public static final int DEST4_F_OFFSET = SRC4_F_OFFSET + SRC4_F_LENGTH; + + @Override + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException, PCEPDocumentedException { + if (bytes == null) + throw new IllegalArgumentException("Array of bytes is mandatory"); + if (bytes.length < LEAF_TYPE_F_LENGTH + SRC4_F_LENGTH + DEST4_F_LENGTH) + throw new PCEPDeserializerException("Wrong length of array of bytes."); + + final long leafType = UnsignedInts.toLong(ByteArray.bytesToInt(ByteArray.subByte(bytes, LEAF_TYPE_F_OFFSET, LEAF_TYPE_F_LENGTH))); + + return new PCEPP2MPEndPointsObject(leafType, new IPv4Address( + ByteArray.subByte(bytes, SRC4_F_OFFSET, SRC4_F_LENGTH)), Util.parseAddresses(bytes, DEST4_F_OFFSET, IPv4.FAMILY, + DEST4_F_LENGTH), processed, ignored); + } + + @Override + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPP2MPEndPointsObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPP2MPEndPointsObject."); + + final PCEPP2MPEndPointsObject ePObj = (PCEPP2MPEndPointsObject) obj; + + if (!(ePObj.getSourceAddress() instanceof IPv4Address)) + throw new IllegalArgumentException("Wrong instance of NetworkAddress. Passed " + ePObj.getSourceAddress().getClass() + ". Needed IPv4Address"); + + final byte[] retBytes = new byte[LEAF_TYPE_F_LENGTH + SRC4_F_LENGTH + DEST4_F_LENGTH * ePObj.getDestinationAddresses().size()]; + ByteArray.copyWhole(ByteArray.intToBytes((int) ePObj.getLeafType()), retBytes, LEAF_TYPE_F_OFFSET); + ByteArray.copyWhole(((IPv4Address) ePObj.getSourceAddress()).getAddress(), retBytes, SRC4_F_OFFSET); + Util.putAddresses(retBytes, DEST4_F_OFFSET, ePObj.getDestinationAddresses(), DEST4_F_LENGTH); + return retBytes; + } +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPP2MPEndPointsIPv6ObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPP2MPEndPointsIPv6ObjectParser.java new file mode 100644 index 0000000000..38f218c769 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPP2MPEndPointsIPv6ObjectParser.java @@ -0,0 +1,68 @@ +/* + * 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.object; + +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.concepts.IPv6; +import org.opendaylight.protocol.concepts.IPv6Address; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.impl.Util; +import org.opendaylight.protocol.pcep.object.PCEPP2MPEndPointsObject; +import com.google.common.primitives.UnsignedInts; + +/** + * Parser for IPv4 {@link org.opendaylight.protocol.pcep.object.PCEPP2MPEndPointsObject + * PCEPP2MPEndPointsObject} + */ +public class PCEPP2MPEndPointsIPv6ObjectParser implements PCEPObjectParser { + + /* + * fields lengths and offsets for IPv4 in bytes + */ + public static final int LEAF_TYPE_F_LENGTH = 4; + public static final int SRC6_F_LENGTH = 16; + public static final int DEST6_F_LENGTH = 16; + + public static final int LEAF_TYPE_F_OFFSET = 0; + public static final int SRC6_F_OFFSET = LEAF_TYPE_F_OFFSET + LEAF_TYPE_F_LENGTH; + public static final int DEST6_F_OFFSET = SRC6_F_OFFSET + SRC6_F_LENGTH; + + @Override + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException, PCEPDocumentedException { + if (bytes == null) + throw new IllegalArgumentException("Array of bytes is mandatory"); + if (bytes.length < LEAF_TYPE_F_LENGTH + SRC6_F_LENGTH + DEST6_F_LENGTH) + throw new PCEPDeserializerException("Wrong length of array of bytes."); + + final long leafType = UnsignedInts.toLong(ByteArray.bytesToInt(ByteArray.subByte(bytes, LEAF_TYPE_F_OFFSET, LEAF_TYPE_F_LENGTH))); + + return new PCEPP2MPEndPointsObject(leafType, new IPv6Address( + ByteArray.subByte(bytes, SRC6_F_OFFSET, SRC6_F_LENGTH)), Util.parseAddresses(bytes, DEST6_F_OFFSET, IPv6.FAMILY, + DEST6_F_LENGTH), processed, ignored); + } + + @Override + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPP2MPEndPointsObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPP2MPEndPointsObject."); + + final PCEPP2MPEndPointsObject ePObj = (PCEPP2MPEndPointsObject) obj; + + if (!(ePObj.getSourceAddress() instanceof IPv6Address)) + throw new IllegalArgumentException("Wrong instance of NetworkAddress. Passed " + ePObj.getSourceAddress().getClass() + ". Needed IPv6Address"); + + final byte[] retBytes = new byte[LEAF_TYPE_F_LENGTH + SRC6_F_LENGTH + DEST6_F_LENGTH * ePObj.getDestinationAddresses().size()]; + ByteArray.copyWhole(ByteArray.intToBytes((int) ePObj.getLeafType()), retBytes, LEAF_TYPE_F_OFFSET); + ByteArray.copyWhole(((IPv6Address) ePObj.getSourceAddress()).getAddress(), retBytes, SRC6_F_OFFSET); + Util.putAddresses(retBytes, DEST6_F_OFFSET, ePObj.getDestinationAddresses(), DEST6_F_LENGTH); + return retBytes; + } +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPPathKeyObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPPathKeyObjectParser.java deleted file mode 100644 index 274f4463b3..0000000000 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPPathKeyObjectParser.java +++ /dev/null @@ -1,74 +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.object; - -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; -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.PathKeyObject; -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.path.key.expansion.PathKeyBuilder; - -/** - * Parser for {@link PathKeyObject} - */ -public class PCEPPathKeyObjectParser extends AbstractObjectParser { - - public static final int CLASS = 16; - - public static final int TYPE = 1; - - public PCEPPathKeyObjectParser(final HandlerRegistry registry) { - super(registry); - } - - @Override - public PathKeyObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, - PCEPDocumentedException { - // FIXME : finish - - final PathKeyBuilder builder = new PathKeyBuilder(); - - builder.setIgnore(header.isIgnore()); - builder.setProcessingRule(header.isProcessingRule()); - - return builder.build(); - } - - @Override - public void addTlv(final PathKeyBuilder builder, final Tlv tlv) { - // No tlvs defined - } - - @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof PathKeyObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed PathKeyObject."); - - final PathKeyObject pkey = (PathKeyObject) 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); - return new byte[0]; - } - - @Override - public int getObjectType() { - return TYPE; - } - - @Override - public int getObjectClass() { - return CLASS; - } -} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPReportedRouteObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPReportedRouteObjectParser.java index b2b1ecc8d3..f6fc8c31fe 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPReportedRouteObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPReportedRouteObjectParser.java @@ -7,67 +7,42 @@ */ package org.opendaylight.protocol.pcep.impl.object; +import java.util.List; + import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; -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.ReportedRouteObject; -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.ReportedRouteBuilder; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.impl.PCEPRROSubobjectParser; +import org.opendaylight.protocol.pcep.object.PCEPReportedRouteObject; +import org.opendaylight.protocol.pcep.subobject.ReportedRouteSubobject; /** - * Parser for {@link ReportedRouteObject} + * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPReportedRouteObject + * PCEPReportedRouteObject} */ -public class PCEPReportedRouteObjectParser extends AbstractObjectParser { - - public static final int CLASS = 8; - - public static final int TYPE = 1; - - public PCEPReportedRouteObjectParser(final HandlerRegistry registry) { - super(registry); - } +public class PCEPReportedRouteObjectParser implements PCEPObjectParser { @Override - public ReportedRouteObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, - PCEPDocumentedException { + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException { if (bytes == null || bytes.length == 0) throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty."); - final ReportedRouteBuilder builder = new ReportedRouteBuilder(); + final List subobjects = PCEPRROSubobjectParser.parse(bytes); + if (subobjects.isEmpty()) + throw new PCEPDeserializerException("Empty Reported Route Object."); - builder.setIgnore(header.isIgnore()); - builder.setProcessingRule(header.isProcessingRule()); - // FIXME: add subobjects - return builder.build(); + return new PCEPReportedRouteObject(subobjects, processed); } @Override - public void addTlv(final ReportedRouteBuilder builder, final Tlv tlv) { - // No tlvs defined - } + public byte[] put(PCEPObject obj) { - @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof ReportedRouteObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() - + ". Needed ReportedRouteObject."); + if (!(obj instanceof PCEPReportedRouteObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPReportedRouteObject."); - assert !(((ReportedRouteObject) object).getSubobjects().isEmpty()) : "Empty Reported Route Object."; - // FIXME add subobjects - // return PCEPRROSubobjectParser.put(((ReportedRouteObject) object).getSubobjects()); - return null; - } + assert !(((PCEPReportedRouteObject) obj).getSubobjects().isEmpty()) : "Empty Reported Route Object."; - @Override - public int getObjectType() { - return TYPE; + return PCEPRROSubobjectParser.put(((PCEPReportedRouteObject) obj).getSubobjects()); } - @Override - public int getObjectClass() { - return CLASS; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPRequestParameterObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPRequestParameterObjectParser.java index a7a00e318b..aa5f27aa95 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPRequestParameterObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPRequestParameterObjectParser.java @@ -12,36 +12,23 @@ import java.util.Arrays; 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.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.impl.PCEPTlvParser; +import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject; 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.OrderTlv; -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.RpObject; -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.RpBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Tlvs; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.TlvsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.tlvs.OrderBuilder; /** - * Parser for {@link RpObject} + * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject + * PCEPRequestParameterObject} */ -public class PCEPRequestParameterObjectParser extends AbstractObjectParser { - - public static final int CLASS = 2; - - public static final int TYPE = 1; +public class PCEPRequestParameterObjectParser implements PCEPObjectParser { /* * lengths of fields in bytes */ - public static final int FLAGS_PRI_MF_LENGTH = 4; // multi-field + public static final int FLAGS_PRI_MF_LENGTH = 4; //multi-field public static final int RID_F_LENGTH = 4; /* @@ -83,7 +70,7 @@ public class PCEPRequestParameterObjectParser extends AbstractObjectParser=" + TLVS_OFFSET + "."); + + final BitSet flags = ByteArray.bytesToBitSet(Arrays.copyOfRange(bytes, FLAGS_PRI_MF_OFFSET, FLAGS_PRI_MF_OFFSET + FLAGS_PRI_MF_LENGTH)); short priority = 0; priority |= flags.get(PRI_SF_OFFSET + 2) ? 1 : 0; priority |= (flags.get(PRI_SF_OFFSET + 1) ? 1 : 0) << 1; priority |= (flags.get(PRI_SF_OFFSET) ? 1 : 0) << 2; - final RpBuilder builder = new RpBuilder(); - - parseTlvs(builder, ByteArray.cutBytes(bytes, TLVS_OFFSET)); - - builder.setIgnore(header.isIgnore()); - builder.setProcessingRule(header.isProcessingRule()); - - builder.setBiDirectional(flags.get(B_FLAG_OFFSET)); - builder.setEroCompression(flags.get(E_FLAG_OFFSET)); - builder.setFragmentation(flags.get(F_FLAG_OFFSET)); - builder.setLoose(flags.get(O_FLAG_OFFSET)); - builder.setMakeBeforeBreak(flags.get(M_FLAG_OFFSET)); - builder.setOrder(flags.get(D_FLAG_OFFSET)); - builder.setP2mp(flags.get(N_FLAG_OFFSET)); - builder.setReoptimization(flags.get(R_FLAG_OFFSET)); - builder.setSupplyOf(flags.get(S_FLAG_OFFSET)); - builder.setPriority(priority); - builder.setRequestId(new RequestId(ByteArray.bytesToLong(Arrays.copyOfRange(bytes, RID_F_OFFSET, RID_F_OFFSET + RID_F_LENGTH)))); - - return builder.build(); + return new PCEPRequestParameterObject(flags.get(O_FLAG_OFFSET), flags.get(B_FLAG_OFFSET), flags.get(R_FLAG_OFFSET), flags.get(M_FLAG_OFFSET), + flags.get(D_FLAG_OFFSET), flags.get(S_FLAG_OFFSET), flags.get(F_FLAG_OFFSET), flags.get(N_FLAG_OFFSET), flags.get(E_FLAG_OFFSET), priority, + ByteArray.bytesToLong(Arrays.copyOfRange(bytes, RID_F_OFFSET, RID_F_OFFSET + RID_F_LENGTH)), PCEPTlvParser.parse(ByteArray.cutBytes(bytes, + TLVS_OFFSET)), processed, ignored); } @Override - public void addTlv(final RpBuilder builder, final Tlv tlv) { - final TlvsBuilder tbuilder = new TlvsBuilder(); - if (tlv instanceof OrderTlv) { - final OrderBuilder b = new OrderBuilder(); - b.setDelete(((OrderTlv) tlv).getDelete()); - b.setSetup(((OrderTlv) tlv).getSetup()); - tbuilder.setOrder(b.build()); - } - builder.setTlvs(tbuilder.build()); - } + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPRequestParameterObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPRequestParameterObject."); - @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof RpObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed RpObject."); - - final RpObject rPObj = (RpObject) object; + final PCEPRequestParameterObject rPObj = (PCEPRequestParameterObject) obj; final BitSet flags_priority = new BitSet(FLAGS_PRI_MF_LENGTH * Byte.SIZE); - flags_priority.set(R_FLAG_OFFSET, rPObj.isReoptimization()); - flags_priority.set(B_FLAG_OFFSET, rPObj.isBiDirectional()); + flags_priority.set(R_FLAG_OFFSET, rPObj.isReoptimized()); + flags_priority.set(B_FLAG_OFFSET, rPObj.isBidirectional()); flags_priority.set(O_FLAG_OFFSET, rPObj.isLoose()); flags_priority.set(M_FLAG_OFFSET, rPObj.isMakeBeforeBreak()); - flags_priority.set(D_FLAG_OFFSET, rPObj.isOrder()); - flags_priority.set(S_FLAG_OFFSET, rPObj.isSupplyOf()); + flags_priority.set(D_FLAG_OFFSET, rPObj.isReportRequestOrder()); + flags_priority.set(S_FLAG_OFFSET, rPObj.isSuplyOFOnResponse()); flags_priority.set(F_FLAG_OFFSET, rPObj.isFragmentation()); flags_priority.set(N_FLAG_OFFSET, rPObj.isP2mp()); flags_priority.set(E_FLAG_OFFSET, rPObj.isEroCompression()); @@ -167,36 +124,14 @@ public class PCEPRequestParameterObjectParser extends AbstractObjectParser subobjects = PCEPEROSubobjectParser.parse(bytes); + if (subobjects.isEmpty()) + throw new PCEPDeserializerException("Empty Secondary Explicit Route Object."); + + return new PCEPSecondaryExplicitRouteObject(subobjects, processed, ignored); + } + + @Override + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPSecondaryExplicitRouteObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPSecondaryExplicitRouteObject."); + + assert !(((PCEPSecondaryExplicitRouteObject) obj).getSubobjects().isEmpty()) : "Empty Secondary Explicit Route Object."; + + return PCEPEROSubobjectParser.put(((PCEPSecondaryExplicitRouteObject) obj).getSubobjects()); + } + +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSecondaryRecordRouteObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSecondaryRecordRouteObjectParser.java new file mode 100644 index 0000000000..523a61dad2 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSecondaryRecordRouteObjectParser.java @@ -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.impl.object; + +import java.util.List; + +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.impl.PCEPRROSubobjectParser; +import org.opendaylight.protocol.pcep.object.PCEPSecondaryRecordRouteObject; +import org.opendaylight.protocol.pcep.subobject.ReportedRouteSubobject; + +public class PCEPSecondaryRecordRouteObjectParser implements PCEPObjectParser { + + @Override + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException { + if (bytes == null || bytes.length == 0) + throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty."); + + final List subobjects = PCEPRROSubobjectParser.parse(bytes); + if (subobjects.isEmpty()) + throw new PCEPDeserializerException("Empty Secondary Recorded Route Object."); + + return new PCEPSecondaryRecordRouteObject(subobjects, processed, ignored); + } + + @Override + public byte[] put(PCEPObject obj) { + + if (!(obj instanceof PCEPSecondaryRecordRouteObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPSecondaryRecordRouteObject."); + + assert !(((PCEPSecondaryRecordRouteObject) obj).getSubobjects().isEmpty()) : "Empty Secondary Record Route Object."; + + return PCEPRROSubobjectParser.put(((PCEPSecondaryRecordRouteObject) obj).getSubobjects()); + } + +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSrpObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSrpObjectParser.java deleted file mode 100644 index 3c0cc378d1..0000000000 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSrpObjectParser.java +++ /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.pcep.impl.object; - -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; -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.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; - -public final class PCEPSrpObjectParser extends AbstractObjectParser { - - public static final int CLASS = 33; - - public static final int TYPE = 1; - - public PCEPSrpObjectParser(final HandlerRegistry registry) { - super(registry); - } - - @Override - public SrpObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException { - - // FIXME: finish - - final SrpBuilder builder = new SrpBuilder(); - - builder.setIgnore(header.isIgnore()); - builder.setProcessingRule(header.isProcessingRule()); - - return builder.build(); - } - - @Override - public void addTlv(final SrpBuilder builder, final Tlv tlv) { - // No tlvs defined - } - - @Override - public byte[] serializeObject(final Object object) { - 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]; - } - - @Override - public int getObjectType() { - return TYPE; - } - - @Override - public int getObjectClass() { - return CLASS; - } -} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSvecObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSvecObjectParser.java index 6ae579c2ee..863fd8c4e1 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSvecObjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSvecObjectParser.java @@ -7,31 +7,21 @@ */ package org.opendaylight.protocol.pcep.impl.object; +import java.util.ArrayList; import java.util.BitSet; import java.util.List; import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.spi.AbstractObjectParser; -import org.opendaylight.protocol.pcep.spi.HandlerRegistry; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.object.PCEPSvecObject; 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.RequestId; -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.Tlv; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.SvecBuilder; - -import com.google.common.collect.Lists; +import com.google.common.primitives.UnsignedInts; /** - * Parser for {@link SvecObject} + * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPSvecObject PCEPSvecObject} */ -public class PCEPSvecObjectParser extends AbstractObjectParser { - - public static final int CLASS = 11; - - public static final int TYPE = 1; +public class PCEPSvecObjectParser implements PCEPObjectParser { /* * field lengths in bytes @@ -52,69 +42,57 @@ public class PCEPSvecObjectParser extends AbstractObjectParser { public static final int N_FLAG_OFFSET = 22; public static final int L_FLAG_OFFSET = 23; + public static final int P_FLAG_OFFSET = 19; + public static final int D_FLAG_OFFSET = 20; + /* * min size in bytes */ - public static final int MIN_SIZE = FLAGS_F_LENGTH + FLAGS_F_OFFSET; - public PCEPSvecObjectParser(final HandlerRegistry registry) { - super(registry); - } + public static final int MIN_SIZE = FLAGS_F_LENGTH + FLAGS_F_OFFSET; @Override - public SvecObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException { + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException { 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 - + "."); + 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 requestIDs = Lists.newArrayList(); + final int numOfRIDs = (bytes.length - FLAGS_F_LENGTH - FLAGS_F_OFFSET) / REQ_LIST_ITEM_LENGTH; + final List requestIDs = new ArrayList(numOfRIDs); 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)))); + requestIDs.add(UnsignedInts.toLong(ByteArray.bytesToInt(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()); - builder.setProcessingRule(header.isProcessingRule()); - - builder.setLinkDiverse(flags.get(L_FLAG_OFFSET)); - builder.setNodeDiverse(flags.get(N_FLAG_OFFSET)); - builder.setSrlgDiverse(flags.get(S_FLAG_OFFSET)); - builder.setRequestsIds(requestIDs); - return builder.build(); + return new PCEPSvecObject(flags.get(L_FLAG_OFFSET), flags.get(N_FLAG_OFFSET), flags.get(S_FLAG_OFFSET), flags.get(P_FLAG_OFFSET), + flags.get(D_FLAG_OFFSET), requestIDs, processed); } @Override - public void addTlv(final SvecBuilder builder, final Tlv tlv) { - // No tlvs defined - } - - @Override - public byte[] serializeObject(final Object object) { - if (!(object instanceof SvecObject)) - throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed SvecObject."); + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPSvecObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPSvecObject."); - final SvecObject svecObj = (SvecObject) object; - final byte[] retBytes = new byte[svecObj.getRequestsIds().size() * REQ_LIST_ITEM_LENGTH + REQ_ID_LIST_OFFSET]; - final List requestIDs = svecObj.getRequestsIds(); + final PCEPSvecObject svecObj = (PCEPSvecObject) obj; + final byte[] retBytes = new byte[svecObj.getRequestIDs().size() * REQ_LIST_ITEM_LENGTH + REQ_ID_LIST_OFFSET]; + final List requestIDs = svecObj.getRequestIDs(); final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE); - flags.set(L_FLAG_OFFSET, svecObj.isLinkDiverse()); - flags.set(N_FLAG_OFFSET, svecObj.isNodeDiverse()); - flags.set(S_FLAG_OFFSET, svecObj.isSrlgDiverse()); + flags.set(L_FLAG_OFFSET, svecObj.isLinkDiversed()); + flags.set(N_FLAG_OFFSET, svecObj.isNodeDiversed()); + flags.set(S_FLAG_OFFSET, svecObj.isSrlgDiversed()); + flags.set(P_FLAG_OFFSET, svecObj.isParitialPathDiversed()); + flags.set(D_FLAG_OFFSET, svecObj.isLinkDirectionDiversed()); ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS_F_OFFSET); for (int i = 0; i < requestIDs.size(); i++) { - System.arraycopy(ByteArray.longToBytes(requestIDs.get(i).getValue()), 4, retBytes, REQ_LIST_ITEM_LENGTH * i - + REQ_ID_LIST_OFFSET, REQ_LIST_ITEM_LENGTH); + System.arraycopy(ByteArray.longToBytes(requestIDs.get(i)), 4, retBytes, REQ_LIST_ITEM_LENGTH * i + REQ_ID_LIST_OFFSET, REQ_LIST_ITEM_LENGTH); } assert !(requestIDs.isEmpty()) : "Empty Svec Object - no request ids."; @@ -122,13 +100,4 @@ public class PCEPSvecObjectParser extends AbstractObjectParser { return retBytes; } - @Override - public int getObjectType() { - return TYPE; - } - - @Override - public int getObjectClass() { - return CLASS; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPUnreachedIPv4DestinationObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPUnreachedIPv4DestinationObjectParser.java new file mode 100644 index 0000000000..d0bed459c5 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPUnreachedIPv4DestinationObjectParser.java @@ -0,0 +1,54 @@ +/* + * 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.object; + +import org.opendaylight.protocol.concepts.IPv4; +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.impl.Util; +import org.opendaylight.protocol.pcep.object.PCEPUnreachedDestinationObject; + +public class PCEPUnreachedIPv4DestinationObjectParser implements PCEPObjectParser { + + /* + * fields lengths and offsets for IPv4 in bytes + */ + public static final int DEST4_F_LENGTH = 4; + + public static final int DEST4_F_OFFSET = 0; + + @Override + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException, PCEPDocumentedException { + if (bytes == null) + throw new IllegalArgumentException("Array of bytes is mandatory"); + + return new PCEPUnreachedDestinationObject(Util.parseAddresses(bytes, DEST4_F_OFFSET, IPv4.FAMILY, DEST4_F_LENGTH), processed, ignored); + } + + @Override + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPUnreachedDestinationObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPUnreachedDestinationObject."); + + final PCEPUnreachedDestinationObject uDObj = (PCEPUnreachedDestinationObject) obj; + + if (uDObj.getUnreachedDestinations().isEmpty()) + return new byte[0]; + + if (!(uDObj.getUnreachedDestinations().get(0) instanceof IPv4Address)) + throw new IllegalArgumentException("Wrong instance of NetworkAddress. Passed " + uDObj.getUnreachedDestinations().get(0).getClass() + + ". Needed IPv4Address"); + + final byte[] retBytes = new byte[DEST4_F_LENGTH * uDObj.getUnreachedDestinations().size()]; + Util.putAddresses(retBytes, DEST4_F_OFFSET, uDObj.getUnreachedDestinations(), DEST4_F_LENGTH); + return retBytes; + } +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPUnreachedIPv6DestinationObjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPUnreachedIPv6DestinationObjectParser.java new file mode 100644 index 0000000000..77e7c8dddf --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPUnreachedIPv6DestinationObjectParser.java @@ -0,0 +1,54 @@ +/* + * 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.object; + +import org.opendaylight.protocol.concepts.IPv6; +import org.opendaylight.protocol.concepts.IPv6Address; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.impl.PCEPObjectParser; +import org.opendaylight.protocol.pcep.impl.Util; +import org.opendaylight.protocol.pcep.object.PCEPUnreachedDestinationObject; + +public class PCEPUnreachedIPv6DestinationObjectParser implements PCEPObjectParser { + + /* + * fields lengths and offsets for IPv6 in bytes + */ + public static final int DEST6_F_LENGTH = 16; + + public static final int DEST6_F_OFFSET = 0; + + @Override + public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException, PCEPDocumentedException { + if (bytes == null) + throw new IllegalArgumentException("Array of bytes is mandatory"); + + return new PCEPUnreachedDestinationObject(Util.parseAddresses(bytes, DEST6_F_OFFSET, IPv6.FAMILY, DEST6_F_LENGTH), processed, ignored); + } + + @Override + public byte[] put(PCEPObject obj) { + if (!(obj instanceof PCEPUnreachedDestinationObject)) + throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPUnreachedDestinationObject."); + + final PCEPUnreachedDestinationObject uDObj = (PCEPUnreachedDestinationObject) obj; + + if (uDObj.getUnreachedDestinations().isEmpty()) + return new byte[0]; + + if (!(uDObj.getUnreachedDestinations().get(0) instanceof IPv6Address)) + throw new IllegalArgumentException("Wrong instance of NetworkAddress. Passed " + uDObj.getUnreachedDestinations().get(0).getClass() + + ". Needed IPv6Address"); + + final byte[] retBytes = new byte[DEST6_F_LENGTH * uDObj.getUnreachedDestinations().size()]; + Util.putAddresses(retBytes, DEST6_F_OFFSET, uDObj.getUnreachedDestinations(), DEST6_F_LENGTH); + return retBytes; + } +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/UnknownObject.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/UnknownObject.java new file mode 100644 index 0000000000..f47e627961 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/UnknownObject.java @@ -0,0 +1,27 @@ +/* + * 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.object; + +import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPObject; + +public class UnknownObject extends PCEPObject { + + private final PCEPErrors error; + + public UnknownObject(boolean processed, boolean ignored, PCEPErrors error) { + super(processed, ignored); + + this.error = error; + } + + public PCEPErrors getError() { + return this.error; + } + +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROAsNumberSubobjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROAsNumberSubobjectParser.java index 7ef9fe05c8..60d14e9680 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROAsNumberSubobjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROAsNumberSubobjectParser.java @@ -8,53 +8,42 @@ package org.opendaylight.protocol.pcep.impl.subobject; import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.spi.SubobjectParser; -import org.opendaylight.protocol.pcep.spi.SubobjectSerializer; +import org.opendaylight.protocol.pcep.subobject.EROAsNumberSubobject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; 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.rsvp.rev130820.AsNumberSubobject; -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.route.subobjects.subobject.type.AsNumberBuilder; /** - * Parser for {@link AsNumberSubobject} + * Parser for {@link org.opendaylight.protocol.pcep.subobject.EROAsNumberSubobject EROAsNumberSubobject} */ -public class EROAsNumberSubobjectParser implements SubobjectParser, SubobjectSerializer { - - public static final int TYPE = 32; - - public static final int AS_NUMBER_LENGTH = 4; +public class EROAsNumberSubobjectParser { + 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; - public AsNumberSubobject parseSubobject(byte[] buffer) throws PCEPDeserializerException { - if (buffer == null || buffer.length == 0) + public static EROAsNumberSubobject parse(final byte[] soContentsBytes, final boolean loose) throws PCEPDeserializerException { + if (soContentsBytes == null || soContentsBytes.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: " + if (soContentsBytes.length != CONTENT_LENGTH) + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + soContentsBytes.length + "; Expected: " + CONTENT_LENGTH + "."); - return new AsNumberBuilder().setAsNumber(new AsNumber(ByteArray.bytesToLong(buffer))).build(); + return new EROAsNumberSubobject(new AsNumber((long) (ByteArray.bytesToShort(soContentsBytes) & 0xFFFF)), loose); } - public byte[] serializeSubobject(CSubobject subobject) { - if (!(subobject instanceof AsNumberSubobject)) - throw new IllegalArgumentException("Unknown subobject instance. Passed " + subobject.getClass() - + ". Needed AsNumberSubobject."); + public static byte[] put(final ExplicitRouteSubobject objToSerialize) { + if (!(objToSerialize instanceof EROAsNumberSubobject)) + throw new IllegalArgumentException("Unknown ExplicitRouteSubobject instance. Passed " + objToSerialize.getClass() + + ". Needed EROAsNumberSubobject."); final byte[] retBytes = new byte[CONTENT_LENGTH]; - System.arraycopy(ByteArray.longToBytes(((AsNumberSubobject) subobject).getAsNumber().getValue()), Long.SIZE / Byte.SIZE + System.arraycopy(ByteArray.longToBytes(((EROAsNumberSubobject) objToSerialize).getASNumber().getValue()), Long.SIZE / Byte.SIZE - AS_NUMBER_LENGTH, retBytes, AS_NUMBER_OFFSET, AS_NUMBER_LENGTH); return retBytes; } - - @Override - public int getType() { - return TYPE; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROIPv4PrefixSubobjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROIPv4PrefixSubobjectParser.java new file mode 100644 index 0000000000..cb063cc679 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROIPv4PrefixSubobjectParser.java @@ -0,0 +1,61 @@ +/* + * 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.util.ByteArray; +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.concepts.IPv4Prefix; +import org.opendaylight.protocol.concepts.Prefix; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; +import com.google.common.primitives.UnsignedBytes; + +/** + * Parser for {@link org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject + * EROIPPrefixSubobject} + */ +public class EROIPv4PrefixSubobjectParser { + public static final int IP_F_LENGTH = 4; + public 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; + + public static final int CONTENT_LENGTH = PREFIX_F_OFFSET + PREFIX_F_LENGTH + 1; //added reserved field of size 1 byte + + public static EROIPPrefixSubobject parse(byte[] soContentsBytes, boolean loose) throws PCEPDeserializerException { + if (soContentsBytes == null || soContentsBytes.length == 0) + throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty."); + if (soContentsBytes.length != CONTENT_LENGTH) + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + soContentsBytes.length + "; Expected: " + CONTENT_LENGTH + "."); + + final IPv4Address address = new IPv4Address(ByteArray.subByte(soContentsBytes, IP_F_OFFSET, IP_F_LENGTH)); + final int length = UnsignedBytes.toInt(soContentsBytes[PREFIX_F_OFFSET]); + + return new EROIPPrefixSubobject(new IPv4Prefix(address, length), loose); + } + + public static byte[] put(ExplicitRouteSubobject objToSerialize) { + if (!(objToSerialize instanceof EROIPPrefixSubobject)) + throw new IllegalArgumentException("Unknown ExplicitRouteSubobject instance. Passed " + objToSerialize.getClass() + + ". Needed EROIPPrefixSubobject."); + + final EROIPPrefixSubobject specObj = (EROIPPrefixSubobject) objToSerialize; + final Prefix prefix = specObj.getPrefix(); + + if (!(prefix instanceof IPv4Prefix)) + throw new IllegalArgumentException("Unknown AbstractPrefix instance. Passed " + prefix.getClass() + ". Needed IPv4Prefix."); + + final byte[] retBytes = new byte[CONTENT_LENGTH]; + ByteArray.copyWhole(prefix.getAddress().getAddress(), retBytes, IP_F_OFFSET); + retBytes[PREFIX_F_OFFSET] = ByteArray.intToBytes(prefix.getLength())[Integer.SIZE / Byte.SIZE - 1]; + + return retBytes; + } +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROIPv6PrefixSubobjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROIPv6PrefixSubobjectParser.java new file mode 100644 index 0000000000..869ee280c7 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROIPv6PrefixSubobjectParser.java @@ -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.pcep.impl.subobject; + +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.concepts.IPv6Address; +import org.opendaylight.protocol.concepts.IPv6Prefix; +import org.opendaylight.protocol.concepts.Prefix; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; +import com.google.common.primitives.UnsignedBytes; + +/** + * Parser for {@link org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject + * EROIPPrefixSubobject} + */ +public class EROIPv6PrefixSubobjectParser { + public static final int IP_F_LENGTH = 16; + public 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; + + public static final int CONTENT_LENGTH = PREFIX_F_OFFSET + PREFIX_F_LENGTH + 1; // added reserved field of size 1 byte + + public static EROIPPrefixSubobject parse(byte[] soContentsBytes, boolean loose) throws PCEPDeserializerException { + if (soContentsBytes == null || soContentsBytes.length == 0) + throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty."); + if (soContentsBytes.length != CONTENT_LENGTH) + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + soContentsBytes.length + "; Expected: " + CONTENT_LENGTH + "."); + + final IPv6Address address = new IPv6Address(ByteArray.subByte(soContentsBytes, IP_F_OFFSET, IP_F_LENGTH)); + final int length = UnsignedBytes.toInt(soContentsBytes[PREFIX_F_OFFSET]); + + return new EROIPPrefixSubobject(new IPv6Prefix(address, length), loose); + } + + public static byte[] put(ExplicitRouteSubobject objToSerialize) { + if (!(objToSerialize instanceof EROIPPrefixSubobject)) + throw new IllegalArgumentException("Unknown ExplicitRouteSubobject instance. Passed " + objToSerialize.getClass() + + ". Needed EROIPPrefixSubobject."); + + final EROIPPrefixSubobject specObj = (EROIPPrefixSubobject) objToSerialize; + final Prefix prefix = specObj.getPrefix(); + + if (!(prefix instanceof IPv6Prefix)) + throw new IllegalArgumentException("Unknown AbstractPrefix instance. Passed " + prefix.getClass() + ". Needed IPv6Prefix."); + + final byte[] retBytes = new byte[CONTENT_LENGTH]; + + ByteArray.copyWhole(prefix.getAddress().getAddress(), retBytes, IP_F_OFFSET); + retBytes[PREFIX_F_OFFSET] = ByteArray.intToBytes(prefix.getLength())[Integer.SIZE / Byte.SIZE - 1]; + + return retBytes; + } +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROIpPrefixSubobjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROIpPrefixSubobjectParser.java deleted file mode 100644 index 01a688d4d7..0000000000 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROIpPrefixSubobjectParser.java +++ /dev/null @@ -1,84 +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.util.ByteArray; -import org.opendaylight.protocol.concepts.Ipv4Util; -import org.opendaylight.protocol.concepts.Ipv6Util; -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.spi.SubobjectParser; -import org.opendaylight.protocol.pcep.spi.SubobjectSerializer; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix; -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.IpPrefixSubobject; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.route.subobjects.subobject.type.IpPrefixBuilder; - -import com.google.common.primitives.UnsignedBytes; - -/** - * Parser for {@link IpPrefixSubobject} - */ -public class EROIpPrefixSubobjectParser implements SubobjectParser, SubobjectSerializer { - - public static final int TYPE = 32; - - public static final int IP4_F_LENGTH = 4; - public static final int PREFIX4_F_LENGTH = 1; - - public 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 byte - - public static final int IP_F_LENGTH = 16; - public 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; - - public static final int CONTENT_LENGTH = PREFIX_F_OFFSET + PREFIX_F_LENGTH + 1; // added reserved field of size 1 byte - - public IpPrefixSubobject parseSubobject(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 == CONTENT4_LENGTH) { - final int length = UnsignedBytes.toInt(buffer[PREFIX4_F_OFFSET]); - return new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.subByte(buffer, 0, IP4_F_LENGTH), length))).build(); - } else if (buffer.length == CONTENT_LENGTH) { - final int length = UnsignedBytes.toInt(buffer[PREFIX_F_OFFSET]); - return new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.subByte(buffer, 0, IP_F_LENGTH), length))).build(); - } else - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + ";"); - } - - public byte[] serializeSubobject(CSubobject subobject) { - if (!(subobject instanceof IpPrefixSubobject)) - throw new IllegalArgumentException("Unknown subobject instance. Passed " + subobject.getClass() - + ". Needed IpPrefixSubobject."); - - final IpPrefixSubobject specObj = (IpPrefixSubobject) subobject; - final IpPrefix prefix = specObj.getIpPrefix(); - - if (prefix.getIpv4Prefix() != null) { - final byte[] retBytes = new byte[CONTENT4_LENGTH]; - ByteArray.copyWhole(prefix.getIpv4Prefix().getValue().getBytes(), retBytes, 0); - return retBytes; - } else if (prefix.getIpv6Prefix() != null) { - final byte[] retBytes = new byte[CONTENT4_LENGTH]; - ByteArray.copyWhole(prefix.getIpv4Prefix().getValue().getBytes(), retBytes, 0); - return retBytes; - //retBytes[PREFIX_F_OFFSET] = ByteArray.intToBytes(prefix.getLength())[Integer.SIZE / Byte.SIZE - 1]; - } - return new byte[0]; - } - - @Override - public int getType() { - return TYPE; - } -} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROUnnumberedInterfaceSubobjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROUnnumberedInterfaceSubobjectParser.java index 64ce60b086..81dfec0e21 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROUnnumberedInterfaceSubobjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROUnnumberedInterfaceSubobjectParser.java @@ -7,13 +7,17 @@ */ package org.opendaylight.protocol.pcep.impl.subobject; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.concepts.IPv4Address; import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.concepts.UnnumberedInterfaceIdentifier; import org.opendaylight.protocol.pcep.subobject.EROUnnumberedInterfaceSubobject; import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; -import org.opendaylight.protocol.util.ByteArray; +import com.google.common.primitives.UnsignedInts; /** - * Parser for {@link org.opendaylight.protocol.pcep.subobject.EROUnnumberedInterfaceSubobject + * Parser for + * {@link org.opendaylight.protocol.pcep.subobject.EROUnnumberedInterfaceSubobject * EROUnnumberedInterfaceSubobject} */ public class EROUnnumberedInterfaceSubobjectParser { @@ -25,21 +29,17 @@ public class EROUnnumberedInterfaceSubobjectParser { public static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH; - public static EROUnnumberedInterfaceSubobject parse(final byte[] soContentsBytes, final boolean loose) throws PCEPDeserializerException { + public static EROUnnumberedInterfaceSubobject parse(byte[] soContentsBytes, boolean loose) throws PCEPDeserializerException { if (soContentsBytes == null || soContentsBytes.length == 0) throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty."); if (soContentsBytes.length != CONTENT_LENGTH) - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + soContentsBytes.length + "; Expected: " - + CONTENT_LENGTH + "."); - - // return new EROUnnumberedInterfaceSubobject(new IPv4Address(ByteArray.subByte(soContentsBytes, - // ROUTER_ID_NUMBER_OFFSET, ROUTER_ID_NUMBER_LENGTH)), new UnnumberedInterfaceIdentifier( - // UnsignedInts.toLong(ByteArray.bytesToInt(ByteArray.subByte(soContentsBytes, INTERFACE_ID_NUMBER_OFFSET, - // INTERFACE_ID_NUMBER_LENGTH)))), loose); - return null; + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + soContentsBytes.length + "; Expected: " + CONTENT_LENGTH + "."); + + return new EROUnnumberedInterfaceSubobject(new IPv4Address(ByteArray.subByte(soContentsBytes, ROUTER_ID_NUMBER_OFFSET, ROUTER_ID_NUMBER_LENGTH)), new UnnumberedInterfaceIdentifier( + UnsignedInts.toLong(ByteArray.bytesToInt(ByteArray.subByte(soContentsBytes, INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH)))), loose); } - public static byte[] put(final ExplicitRouteSubobject objToSerialize) { + public static byte[] put(ExplicitRouteSubobject objToSerialize) { if (!(objToSerialize instanceof EROUnnumberedInterfaceSubobject)) throw new IllegalArgumentException("Unknown ExplicitRouteSubobject instance. Passed " + objToSerialize.getClass() + ". Needed EROUnnumberedInterfaceSubobject."); @@ -49,8 +49,8 @@ public class EROUnnumberedInterfaceSubobjectParser { final EROUnnumberedInterfaceSubobject specObj = (EROUnnumberedInterfaceSubobject) objToSerialize; ByteArray.copyWhole(specObj.getRouterID().getAddress(), retBytes, ROUTER_ID_NUMBER_OFFSET); - System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceID().getInterfaceId()), Long.SIZE / Byte.SIZE - - INTERFACE_ID_NUMBER_LENGTH, retBytes, INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH); + System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceID().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/RROUnnumberedInterfaceSubobjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROUnnumberedInterfaceSubobjectParser.java index 8606b66a13..edcea4ec34 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROUnnumberedInterfaceSubobjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROUnnumberedInterfaceSubobjectParser.java @@ -7,13 +7,17 @@ */ package org.opendaylight.protocol.pcep.impl.subobject; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.concepts.IPv4Address; import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.concepts.UnnumberedInterfaceIdentifier; import org.opendaylight.protocol.pcep.subobject.RROUnnumberedInterfaceSubobject; import org.opendaylight.protocol.pcep.subobject.ReportedRouteSubobject; -import org.opendaylight.protocol.util.ByteArray; +import com.google.common.primitives.UnsignedInts; /** - * Parser for {@link org.opendaylight.protocol.pcep.subobject.RROUnnumberedInterfaceSubobject + * Parser for + * {@link org.opendaylight.protocol.pcep.subobject.RROUnnumberedInterfaceSubobject * RROUnnumberedInterfaceSubobject} */ public class RROUnnumberedInterfaceSubobjectParser { @@ -25,22 +29,18 @@ public class RROUnnumberedInterfaceSubobjectParser { public static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH; - public static RROUnnumberedInterfaceSubobject parse(final byte[] soContentsBytes) throws PCEPDeserializerException { + public static RROUnnumberedInterfaceSubobject parse(byte[] soContentsBytes) throws PCEPDeserializerException { if (soContentsBytes == null || soContentsBytes.length == 0) throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty."); if (soContentsBytes.length != CONTENT_LENGTH) - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + soContentsBytes.length + "; Expected: " - + CONTENT_LENGTH + "."); - - // return new RROUnnumberedInterfaceSubobject(new IPv4Address( - // ByteArray.subByte(soContentsBytes, ROUTER_ID_NUMBER_OFFSET, ROUTER_ID_NUMBER_LENGTH)), new - // UnnumberedInterfaceIdentifier( - // UnsignedInts.toLong(ByteArray.bytesToInt(ByteArray.subByte(soContentsBytes, INTERFACE_ID_NUMBER_OFFSET, - // INTERFACE_ID_NUMBER_LENGTH))))); - return null; + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + soContentsBytes.length + "; Expected: " + CONTENT_LENGTH + "."); + + return new RROUnnumberedInterfaceSubobject(new IPv4Address( + ByteArray.subByte(soContentsBytes, ROUTER_ID_NUMBER_OFFSET, ROUTER_ID_NUMBER_LENGTH)), new UnnumberedInterfaceIdentifier( + UnsignedInts.toLong(ByteArray.bytesToInt(ByteArray.subByte(soContentsBytes, INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH))))); } - public static byte[] put(final ReportedRouteSubobject objToSerialize) { + public static byte[] put(ReportedRouteSubobject objToSerialize) { if (!(objToSerialize instanceof RROUnnumberedInterfaceSubobject)) throw new IllegalArgumentException("Unknown ReportedRouteSubobject instance. Passed " + objToSerialize.getClass() + ". Needed RROUnnumberedInterfaceSubobject."); @@ -50,8 +50,8 @@ public class RROUnnumberedInterfaceSubobjectParser { final RROUnnumberedInterfaceSubobject specObj = (RROUnnumberedInterfaceSubobject) objToSerialize; ByteArray.copyWhole(specObj.getRouterID().getAddress(), retBytes, ROUTER_ID_NUMBER_OFFSET); - System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceID().getInterfaceId()), Long.SIZE / Byte.SIZE - - INTERFACE_ID_NUMBER_LENGTH, retBytes, INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH); + System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceID().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/XROUnnumberedInterfaceSubobjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROUnnumberedInterfaceSubobjectParser.java index 9d3c84fbe7..9b7f40094d 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROUnnumberedInterfaceSubobjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/XROUnnumberedInterfaceSubobjectParser.java @@ -7,13 +7,17 @@ */ package org.opendaylight.protocol.pcep.impl.subobject; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.concepts.IPv4Address; import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.concepts.UnnumberedInterfaceIdentifier; import org.opendaylight.protocol.pcep.subobject.ExcludeRouteSubobject; import org.opendaylight.protocol.pcep.subobject.XROUnnumberedInterfaceSubobject; -import org.opendaylight.protocol.util.ByteArray; +import com.google.common.primitives.UnsignedInts; /** - * Parser for {@link org.opendaylight.protocol.pcep.subobject.XROUnnumberedInterfaceSubobject + * Parser for + * {@link org.opendaylight.protocol.pcep.subobject.XROUnnumberedInterfaceSubobject * XROUnnumberedInterfaceSubobject} */ public class XROUnnumberedInterfaceSubobjectParser { @@ -27,25 +31,19 @@ public class XROUnnumberedInterfaceSubobjectParser { public static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH; - public static XROUnnumberedInterfaceSubobject parse(final byte[] soContentsBytes, final boolean mandatory) - throws PCEPDeserializerException { + public static XROUnnumberedInterfaceSubobject parse(byte[] soContentsBytes, boolean mandatory) throws PCEPDeserializerException { if (soContentsBytes == null || soContentsBytes.length == 0) throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty."); if (soContentsBytes.length != CONTENT_LENGTH) - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + soContentsBytes.length + "; Expected: " - + CONTENT_LENGTH + "."); + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + soContentsBytes.length + "; Expected: " + CONTENT_LENGTH + "."); - // return new XROUnnumberedInterfaceSubobject(new IPv4Address( - // ByteArray.subByte(soContentsBytes, ROUTER_ID_NUMBER_OFFSET, ROUTER_ID_NUMBER_LENGTH)), new - // UnnumberedInterfaceIdentifier( - // UnsignedInts.toLong(ByteArray.bytesToInt(ByteArray.subByte(soContentsBytes, INTERFACE_ID_NUMBER_OFFSET, - // INTERFACE_ID_NUMBER_LENGTH)))), - // mandatory, XROSubobjectAttributeMapping.getInstance().getFromAttributeIdentifier((short) - // (soContentsBytes[ATTRIBUTE_OFFSET] & 0xFF))); - return null; + return new XROUnnumberedInterfaceSubobject(new IPv4Address( + ByteArray.subByte(soContentsBytes, ROUTER_ID_NUMBER_OFFSET, ROUTER_ID_NUMBER_LENGTH)), new UnnumberedInterfaceIdentifier( + UnsignedInts.toLong(ByteArray.bytesToInt(ByteArray.subByte(soContentsBytes, INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH)))), + mandatory, XROSubobjectAttributeMapping.getInstance().getFromAttributeIdentifier((short) (soContentsBytes[ATTRIBUTE_OFFSET] & 0xFF))); } - public static byte[] put(final ExcludeRouteSubobject objToSerialize) { + public static byte[] put(ExcludeRouteSubobject objToSerialize) { if (!(objToSerialize instanceof XROUnnumberedInterfaceSubobject)) throw new IllegalArgumentException("Unknown PCEPXROSubobject instance. Passed " + objToSerialize.getClass() + ". Needed XROUnnumberedInterfaceSubobject."); @@ -56,8 +54,8 @@ public class XROUnnumberedInterfaceSubobjectParser { retBytes[ATTRIBUTE_OFFSET] = (byte) XROSubobjectAttributeMapping.getInstance().getFromAttributeEnum(specObj.getAttribute()); ByteArray.copyWhole(specObj.getRouterID().getAddress(), retBytes, ROUTER_ID_NUMBER_OFFSET); - System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceID().getInterfaceId()), Long.SIZE / Byte.SIZE - - INTERFACE_ID_NUMBER_LENGTH, retBytes, INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH); + System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceID().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 index 7f93243d2d..995e952db2 100644 --- 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 @@ -7,79 +7,56 @@ */ package org.opendaylight.protocol.pcep.impl.tlv; -import org.opendaylight.protocol.concepts.Ipv4Util; +import org.opendaylight.protocol.concepts.IPv4Address; import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.spi.TlvParser; -import org.opendaylight.protocol.pcep.spi.TlvSerializer; +import org.opendaylight.protocol.pcep.concepts.IPv4ExtendedTunnelIdentifier; +import org.opendaylight.protocol.pcep.concepts.LSPIdentifier; +import org.opendaylight.protocol.pcep.concepts.TunnelIdentifier; +import org.opendaylight.protocol.pcep.tlv.IPv4LSPIdentifiersTlv; 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} + * Parser for {@link org.opendaylight.protocol.pcep.tlv.LSPIdentifiersTlv LSPIdentifiersTlv} + * parameterized as IPv4Address */ -public class LSPIdentifierIPv4TlvParser implements TlvParser, TlvSerializer { - - public static final int TYPE = 18; +public class LSPIdentifierIPv4TlvParser { 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; + private static final int IP_F_OFFSET = 0; + private static final int LSP_ID_F_OFFSET = IP_F_OFFSET + IP_F_LENGTH; + private static final int TUNNLE_ID_F_OFFSET = LSP_ID_F_OFFSET + LSP_ID_F_LENGTH; + private static final int EX_TUNNEL_ID_F_OFFSET = TUNNLE_ID_F_OFFSET + TUNNEL_ID_F_LENGTH; + + private static final int SIZE = EX_TUNNEL_ID_F_OFFSET + EX_TUNNEL_ID_F_LENGTH; + + public static IPv4LSPIdentifiersTlv parse(byte[] valueBytes) throws PCEPDeserializerException { if (valueBytes == null || valueBytes.length == 0) throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty."); + if (valueBytes.length != SIZE) + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + "; Expected: " + SIZE + "."); - 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(); + return new IPv4LSPIdentifiersTlv(new IPv4Address( + ByteArray.subByte(valueBytes, IP_F_OFFSET, IP_F_LENGTH)), new LSPIdentifier(ByteArray.subByte(valueBytes, LSP_ID_F_OFFSET, LSP_ID_F_LENGTH)), + new TunnelIdentifier(ByteArray.subByte(valueBytes, TUNNLE_ID_F_OFFSET, TUNNEL_ID_F_LENGTH)), + new IPv4ExtendedTunnelIdentifier(new IPv4Address(ByteArray.subByte(valueBytes, EX_TUNNEL_ID_F_OFFSET, EX_TUNNEL_ID_F_LENGTH)))); } - @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; - } + public static byte[] put(IPv4LSPIdentifiersTlv objToSerialize) { + if (objToSerialize == null) + throw new IllegalArgumentException("IPv4LSPIdentifiersTlv is mandatory."); + + final byte[] retBytes = new byte[SIZE]; - @Override - public int getType() { - return TYPE; + ByteArray.copyWhole(objToSerialize.getSenderAddress().getAddress(), retBytes, IP_F_OFFSET); + ByteArray.copyWhole(objToSerialize.getLspID().getLspId(), retBytes, LSP_ID_F_OFFSET); + ByteArray.copyWhole(objToSerialize.getTunnelID().getBytes(), retBytes, TUNNLE_ID_F_OFFSET); + ByteArray.copyWhole(objToSerialize.getExtendedTunnelID().getIdentifier().getAddress(), retBytes, EX_TUNNEL_ID_F_OFFSET); + + return retBytes; } + } 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 index 11206a5fbb..0133e85b55 100644 --- 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 @@ -7,47 +7,57 @@ */ package org.opendaylight.protocol.pcep.impl.tlv; -import org.opendaylight.protocol.concepts.Ipv6Util; +import org.opendaylight.protocol.concepts.IPv6Address; import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.spi.TlvParser; +import org.opendaylight.protocol.pcep.concepts.IPv6ExtendedTunnelIdentifier; +import org.opendaylight.protocol.pcep.concepts.LSPIdentifier; +import org.opendaylight.protocol.pcep.concepts.TunnelIdentifier; +import org.opendaylight.protocol.pcep.tlv.IPv6LSPIdentifiersTlv; +import org.opendaylight.protocol.pcep.tlv.LSPIdentifiersTlv; 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} + * Parser for {@link org.opendaylight.protocol.pcep.tlv.LSPIdentifiersTlv LSPIdentifiersTlv} + * parameterized as IPv6Address */ -public class LSPIdentifierIPv6TlvParser implements TlvParser { - - public static final int TYPE = 19; +public class LSPIdentifierIPv6TlvParser { 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; + private static final int IP_F_OFFSET = 0; + private static final int LSP_ID_F_OFFSET = IP_F_OFFSET + IP_F_LENGTH; + private static final int TUNNLE_ID_F_OFFSET = LSP_ID_F_OFFSET + LSP_ID_F_LENGTH; + private static final int EX_TUNNEL_ID_F_OFFSET = TUNNLE_ID_F_OFFSET + TUNNEL_ID_F_LENGTH; + + private static final int SIZE = EX_TUNNEL_ID_F_OFFSET + EX_TUNNEL_ID_F_LENGTH; + + public static LSPIdentifiersTlv parse(byte[] valueBytes) throws PCEPDeserializerException { if (valueBytes == null || valueBytes.length == 0) throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty."); + if (valueBytes.length != SIZE) + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + "; Expected: " + SIZE + "."); - 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(); + return new IPv6LSPIdentifiersTlv(new IPv6Address( + ByteArray.subByte(valueBytes, IP_F_OFFSET, IP_F_LENGTH)), new LSPIdentifier(ByteArray.subByte(valueBytes, LSP_ID_F_OFFSET, LSP_ID_F_LENGTH)), + new TunnelIdentifier(ByteArray.subByte(valueBytes, TUNNLE_ID_F_OFFSET, TUNNEL_ID_F_LENGTH)), + new IPv6ExtendedTunnelIdentifier(new IPv6Address(ByteArray.subByte(valueBytes, EX_TUNNEL_ID_F_OFFSET, EX_TUNNEL_ID_F_LENGTH)))); } - public int getType() { - return TYPE; + public static byte[] put(IPv6LSPIdentifiersTlv objToSerialize) { + if (objToSerialize == null) + throw new IllegalArgumentException("IPv6LSPIdentifiersTlv is mandatory."); + + final byte[] retBytes = new byte[SIZE]; + + ByteArray.copyWhole(objToSerialize.getSenderAddress().getAddress(), retBytes, IP_F_OFFSET); + ByteArray.copyWhole(objToSerialize.getLspID().getLspId(), retBytes, LSP_ID_F_OFFSET); + ByteArray.copyWhole(objToSerialize.getTunnelID().getBytes(), retBytes, TUNNLE_ID_F_OFFSET); + ByteArray.copyWhole(objToSerialize.getExtendedTunnelID().getIdentifier().getAddress(), retBytes, EX_TUNNEL_ID_F_OFFSET); + + return retBytes; } + } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspDbVersionTlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspDbVersionTlvParser.java deleted file mode 100644 index 904cf1b52c..0000000000 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspDbVersionTlvParser.java +++ /dev/null @@ -1,46 +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 java.math.BigInteger; - -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.LspDbVersionTlv; -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.open.object.tlvs.LspDbVersionBuilder; - -/** - * Parser for {@link LspDbVersionTlv} - */ -public class LspDbVersionTlvParser implements TlvParser, TlvSerializer { - - public static final int TYPE = 23; - - private static final int DBV_F_LENGTH = 8; - - @Override - public LspDbVersionTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException { - return new LspDbVersionBuilder().setVersion(BigInteger.valueOf(ByteArray.bytesToLong(ByteArray.subByte(buffer, 0, DBV_F_LENGTH)))).build(); - } - - @Override - public byte[] serializeTlv(final Tlv tlv) { - if (tlv == null) - throw new IllegalArgumentException("LspDbVersionTlv is mandatory."); - final LspDbVersionTlv lsp = (LspDbVersionTlv) tlv; - return ByteArray.subByte(lsp.getVersion().toByteArray(), 0, DBV_F_LENGTH); - } - - @Override - public int getType() { - return TYPE; - } -} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspSymbolicNameTlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspSymbolicNameTlvParser.java deleted file mode 100644 index 1b1ccbcfb6..0000000000 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspSymbolicNameTlvParser.java +++ /dev/null @@ -1,41 +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.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.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; - -/** - * Parser for {@link SymbolicPathNameTlv} - */ -public class LspSymbolicNameTlvParser implements TlvParser, TlvSerializer { - - public static final int TYPE = 17; - - @Override - public SymbolicPathNameTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException { - return new SymblicPathNameBuilder().setPathName(buffer).build(); - } - - @Override - public byte[] serializeTlv(final Tlv tlv) { - if (tlv == null) - throw new IllegalArgumentException("SymbolicPathNameTlv is mandatory."); - final SymbolicPathNameTlv spn = (SymbolicPathNameTlv) tlv; - return spn.getPathName(); - } - - @Override - public int getType() { - return TYPE; - } -} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspUpdateErrorTlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspUpdateErrorTlvParser.java deleted file mode 100644 index ad2f67616a..0000000000 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspUpdateErrorTlvParser.java +++ /dev/null @@ -1,44 +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.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.LspErrorCodeTlv; -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.LspErrorCodeBuilder; - -/** - * Parser for {@link LspErrorCodeTlv} - */ -public class LspUpdateErrorTlvParser implements TlvParser, TlvSerializer { - - public static final int TYPE = 20; - - private static final int UPDATE_ERR_CODE_LENGTH = 4; - - @Override - public LspErrorCodeTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException { - return new LspErrorCodeBuilder().setErrorCode(ByteArray.bytesToLong(buffer)).build(); - } - - @Override - public byte[] serializeTlv(final Tlv tlv) { - 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); - } - - @Override - public int getType() { - return TYPE; - } -} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/NoPathVectorTlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/NoPathVectorTlvParser.java index 510d678043..1f651defc9 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/NoPathVectorTlvParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/NoPathVectorTlvParser.java @@ -10,20 +10,13 @@ package org.opendaylight.protocol.pcep.impl.tlv; import java.util.BitSet; import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.spi.TlvParser; -import org.opendaylight.protocol.pcep.spi.TlvSerializer; +import org.opendaylight.protocol.pcep.tlv.NoPathVectorTlv; import org.opendaylight.protocol.util.ByteArray; -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.NoPathVectorTlv.Flags; -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.no.path.tlvs.NoPathVectorBuilder; /** - * Parser for {@link NoPathVectorTlv} + * Parser for {@link org.opendaylight.protocol.pcep.tlv.NoPathVectorTlv NoPathVectorTlv} */ -public class NoPathVectorTlvParser implements TlvParser, TlvSerializer { - - public static final int TYPE = 1; +public class NoPathVectorTlvParser { public static final int FLAGS_F_LENGTH = 4; @@ -45,41 +38,31 @@ public class NoPathVectorTlvParser implements TlvParser, TlvSerializer { */ public static final int REACHABLITY_PROBLEM = 24; - @Override - public NoPathVectorTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException { + public static NoPathVectorTlv parse(byte[] valueBytes) throws PCEPDeserializerException { 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) - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + "; Expected: >=" - + 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(); + return new NoPathVectorTlv(flags.get(PCE_UNAVAILABLE), flags.get(UNKNOWN_DEST), flags.get(UNKNOWN_SRC), flags.get(NO_GCO_SOLUTION), + flags.get(NO_GCO_MIGRATION_PATH), flags.get(REACHABLITY_PROBLEM)); } - @Override - public byte[] serializeTlv(final Tlv tlvs) { - if (tlvs == null) + public static byte[] put(NoPathVectorTlv obj) { + if (obj == 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(NO_GCO_SOLUTION, tlv.getFlags().isNoGcoSolution()); - flags.set(NO_GCO_MIGRATION_PATH, tlv.getFlags().isNoGcoMigration()); - flags.set(REACHABLITY_PROBLEM, tlv.getFlags().isP2mpUnreachable()); + flags.set(PCE_UNAVAILABLE, obj.isPceUnavailable()); + flags.set(UNKNOWN_DEST, obj.isUnknownDest()); + flags.set(UNKNOWN_SRC, obj.isUnknownSrc()); + flags.set(NO_GCO_SOLUTION, obj.isNoGCOSolution()); + flags.set(NO_GCO_MIGRATION_PATH, obj.isNoGCOMigrationPath()); + flags.set(REACHABLITY_PROBLEM, obj.isReachablityProblem()); return ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH); } - - @Override - public int getType() { - return TYPE; - } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OFListTlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OFListTlvParser.java index 6be36248c7..1c98f17116 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OFListTlvParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OFListTlvParser.java @@ -7,66 +7,56 @@ */ package org.opendaylight.protocol.pcep.impl.tlv; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.NoSuchElementException; import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.spi.TlvParser; -import org.opendaylight.protocol.pcep.spi.TlvSerializer; +import org.opendaylight.protocol.pcep.PCEPOFCodes; +import org.opendaylight.protocol.pcep.impl.PCEPOFCodesMapping; +import org.opendaylight.protocol.pcep.tlv.OFListTlv; import org.opendaylight.protocol.util.ByteArray; -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.Tlv; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.OfListBuilder; - -import com.google.common.collect.Lists; /** - * Parser for {@link OfListTlv} + * Parser for {@link org.opendaylight.protocol.pcep.tlv.OFListTlv OFListTlv} */ -public class OFListTlvParser implements TlvParser, TlvSerializer { - - public static final int TYPE = 4; +public class OFListTlvParser { private static final int OF_CODE_ELEMENT_LENGTH = 2; - @Override - public OfListTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException { + public static OFListTlv parse(byte[] valueBytes) throws PCEPDeserializerException { 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) throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + "."); - final List ofCodes = Lists.newArrayList(); + final List ofCodes = new ArrayList(); for (int i = 0; i < valueBytes.length; i += OF_CODE_ELEMENT_LENGTH) { try { - ofCodes.add(new OfId(ByteArray.bytesToShort(Arrays.copyOfRange(valueBytes, i, i + OF_CODE_ELEMENT_LENGTH)) & 0xFFFF)); + ofCodes.add(PCEPOFCodesMapping.getInstance().getFromCodeIdentifier( + ByteArray.bytesToShort(Arrays.copyOfRange(valueBytes, i, i + OF_CODE_ELEMENT_LENGTH)) & 0xFFFF)); } catch (final NoSuchElementException nsee) { throw new PCEPDeserializerException(nsee, "Unknown OF Code inside OF Code list Tlv."); } } - return new OfListBuilder().setCodes(ofCodes).build(); + + return new OFListTlv(ofCodes); } - @Override - public byte[] serializeTlv(final Tlv tlv) { - if (tlv == null) + public static byte[] put(OFListTlv objToSerialize) { + if (objToSerialize == null) throw new IllegalArgumentException("OFListTlv is mandatory."); - final OfListTlv oft = (OfListTlv) tlv; - final List ofCodes = oft.getCodes(); + final List ofCodes = objToSerialize.getOfCodes(); final byte[] retBytes = new byte[ofCodes.size() * OF_CODE_ELEMENT_LENGTH]; final int size = ofCodes.size(); for (int i = 0; i < size; i++) { - ByteArray.copyWhole(ByteArray.shortToBytes(ofCodes.get(i).getValue().shortValue()), retBytes, i * OF_CODE_ELEMENT_LENGTH); + ByteArray.copyWhole(ByteArray.shortToBytes((short) PCEPOFCodesMapping.getInstance().getFromOFCodesEnum(ofCodes.get(i))), retBytes, i + * OF_CODE_ELEMENT_LENGTH); } - return retBytes; - } - @Override - public int getType() { - return TYPE; + return retBytes; } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OrderTlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OrderTlvParser.java deleted file mode 100644 index 13b441dce9..0000000000 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OrderTlvParser.java +++ /dev/null @@ -1,56 +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.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.OrderTlv; -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.rp.object.tlvs.OrderBuilder; - -/** - * Parser for {@link OrderTlv} - */ -public class OrderTlvParser implements TlvParser, TlvSerializer { - - public static final int TYPE = 5; - - private static final int ORDR_DEL_LENGTH = 4; - - private static final int ORDR_SETUP_LENGTH = 4; - - @Override - public OrderTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException { - return new OrderBuilder().setDelete(Long.valueOf(ByteArray.bytesToLong(ByteArray.subByte(buffer, 0, ORDR_DEL_LENGTH)))).setSetup( - ByteArray.bytesToLong(ByteArray.subByte(buffer, ORDR_DEL_LENGTH, ORDR_SETUP_LENGTH))).build(); - } - - @Override - public byte[] serializeTlv(final Tlv tlv) { - 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]; - } - - @Override - public int getType() { - return TYPE; - } -} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OverloadedDurationTlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OverloadedDurationTlvParser.java deleted file mode 100644 index b75a748dd8..0000000000 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OverloadedDurationTlvParser.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * - */ -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.protocol.util.ByteArray; -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.Tlv; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.tlvs.OverloadDurationBuilder; - -/** - * Parser for {@link OverloadDurationTlv} - */ -public class OverloadedDurationTlvParser implements TlvParser, TlvSerializer { - - public static final int TYPE = 2; - - private static final int OVERLOADED_DURATION_LENGTH = 4; - - @Override - public OverloadDurationTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException { - final long l = ByteArray.bytesToInt(ByteArray.subByte(buffer, 0, OVERLOADED_DURATION_LENGTH)); - return new OverloadDurationBuilder().setDuration(l).build(); - } - - @Override - public byte[] serializeTlv(final Tlv tlv) { - 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); - } - - @Override - public int getType() { - return TYPE; - } -} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/PCEStatefulCapabilityTlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/PCEStatefulCapabilityTlvParser.java index a20a9b1cb8..c19febe6f1 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/PCEStatefulCapabilityTlvParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/PCEStatefulCapabilityTlvParser.java @@ -10,60 +10,49 @@ package org.opendaylight.protocol.pcep.impl.tlv; import java.util.BitSet; import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.spi.TlvParser; -import org.opendaylight.protocol.pcep.spi.TlvSerializer; +import org.opendaylight.protocol.pcep.tlv.PCEStatefulCapabilityTlv; import org.opendaylight.protocol.util.ByteArray; -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.Tlv; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.StatefulBuilder; /** - * Parser for {@link StatefulCapabilityTlv} + * Parser for {@link org.opendaylight.protocol.pcep.tlv.PCEStatefulCapabilityTlv + * PCEStatefulCapabilityTlv} + * + * @see + * Stateful PCE Capability TLV */ -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; - - @Override - public StatefulCapabilityTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException { - 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) - 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(); - } - - @Override - public byte[] serializeTlv(final Tlv tlv) { - if (tlv == null) - throw new IllegalArgumentException("StatefulCapabilityTlv is mandatory."); - final StatefulCapabilityTlv sct = (StatefulCapabilityTlv) tlv; - - final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE); - flags.set(I_FLAG_OFFSET, sct.getFlags().isInitiation()); - flags.set(U_FLAG_OFFSET, sct.getFlags().isLspUpdateCapability()); - flags.set(S_FLAG_OFFSET, sct.getFlags().isIncludeDbVersion()); - - return ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH); - } - - @Override - public int getType() { - return TYPE; - } +public final class PCEStatefulCapabilityTlvParser { + /* + * 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; + + public static PCEStatefulCapabilityTlv deserializeValueField(byte[] valueBytes) throws PCEPDeserializerException { + if (valueBytes == null || valueBytes.length == 0) + throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty."); + 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(ByteArray.subByte(valueBytes, 0, FLAGS_F_LENGTH)); + return new PCEStatefulCapabilityTlv(flags.get(I_FLAG_OFFSET), flags.get(U_FLAG_OFFSET), flags.get(S_FLAG_OFFSET)); + } + + public static byte[] serializeValueField(PCEStatefulCapabilityTlv objToSerialize) { + if (objToSerialize == null) + throw new IllegalArgumentException("PCEStatefulCapabilityTlv is mandatory."); + + final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE); + flags.set(I_FLAG_OFFSET, objToSerialize.isInstantiated()); + flags.set(U_FLAG_OFFSET, objToSerialize.isUpdate()); + flags.set(S_FLAG_OFFSET, objToSerialize.isVersioned()); + + return ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH); + } } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/PredundancyGroupTlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/PredundancyGroupTlvParser.java deleted file mode 100644 index 4f7ff939cf..0000000000 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/PredundancyGroupTlvParser.java +++ /dev/null @@ -1,41 +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.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.PredundancyGroupIdTlv; -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.open.object.tlvs.PredundancyGroupIdBuilder; - -/** - * Parser for {@link PredundancyGroupIdTlv} - */ -public class PredundancyGroupTlvParser implements TlvParser, TlvSerializer { - - public static final int TYPE = 24; - - @Override - public PredundancyGroupIdTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException { - return new PredundancyGroupIdBuilder().setIdentifier(buffer).build(); - } - - @Override - public byte[] serializeTlv(final Tlv tlv) { - if (tlv == null) - throw new IllegalArgumentException("PredundancyGroupIdTlv is mandatory."); - final PredundancyGroupIdTlv pgt = (PredundancyGroupIdTlv) tlv; - return pgt.getIdentifier(); - } - - @Override - public int getType() { - return TYPE; - } -} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/RSVPErrorSpecIPv4TlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/RSVPErrorSpecIPv4TlvParser.java new file mode 100644 index 0000000000..bcb0e45e84 --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/RSVPErrorSpecIPv4TlvParser.java @@ -0,0 +1,78 @@ +/* + * 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 java.util.BitSet; + +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.tlv.RSVPErrorSpecTlv; +import org.opendaylight.protocol.util.ByteArray; + +/** + * Parser for {@link org.opendaylight.protocol.pcep.tlv.RSVPErrorSpecTlv RSVPErrorSpecTlv} + * parameterized as IPv4Address + */ +public class RSVPErrorSpecIPv4TlvParser { + + private static final int IP_F_LENGTH = 4; + private static final int FLAGS_F_LENGTH = 1; + private static final int ERROR_CODE_F_LENGTH = 1; + private static final int ERROR_VALUE_F_LENGTH = 2; + + private static final int IP_F_OFFSET = 0; + private static final int FLAGS_F_OFFSET = IP_F_OFFSET + IP_F_LENGTH; + private static final int ERROR_CODE_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH; + private static final int ERROR_VALUE_F_OFFSET = ERROR_CODE_F_OFFSET + ERROR_CODE_F_LENGTH; + + private static final int SIZE = ERROR_VALUE_F_OFFSET + ERROR_VALUE_F_LENGTH; + + /* + * 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; + + public static RSVPErrorSpecTlv parse(byte[] valueBytes) throws PCEPDeserializerException { + if (valueBytes == null || valueBytes.length == 0) + throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty."); + if (valueBytes.length != SIZE) + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + "; Expected: " + SIZE + "."); + + final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(valueBytes, FLAGS_F_OFFSET, FLAGS_F_LENGTH)); + + return new RSVPErrorSpecTlv(new IPv4Address( + ByteArray.subByte(valueBytes, IP_F_OFFSET, IP_F_LENGTH)), flags.get(IN_PLACE_FLAG_OFFSET), flags.get(NOT_GUILTY_FLAGS_OFFSET), + valueBytes[ERROR_CODE_F_OFFSET] & 0xFF, + ByteArray.bytesToShort(ByteArray.subByte(valueBytes, ERROR_VALUE_F_OFFSET, ERROR_VALUE_F_LENGTH)) & 0xFFFF); + } + + public static byte[] put(RSVPErrorSpecTlv objToSerialize) { + if (objToSerialize == null) + throw new IllegalArgumentException("RSVPErrorSpecTlv is mandatory."); + + if (!(((RSVPErrorSpecTlv) objToSerialize).getErrorNodeAddress() instanceof IPv4Address)) + throw new IllegalArgumentException("Unknown parametrized type of RSVPErrorSpecTlv. Passed " + + ((RSVPErrorSpecTlv) objToSerialize).getErrorNodeAddress().getClass() + ". Needed IPv4Address."); + + final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE); + flags.set(IN_PLACE_FLAG_OFFSET, objToSerialize.isInPlace()); + flags.set(NOT_GUILTY_FLAGS_OFFSET, objToSerialize.isGuilty()); + + final byte[] retBytes = new byte[SIZE]; + + ByteArray.copyWhole(((IPv4Address) objToSerialize.getErrorNodeAddress()).getAddress(), retBytes, IP_F_OFFSET); + retBytes[ERROR_CODE_F_OFFSET] = ByteArray.intToBytes(objToSerialize.getErrorCode())[Integer.SIZE / Byte.SIZE - 1]; + System.arraycopy(ByteArray.intToBytes(objToSerialize.getErrorValue()), Integer.SIZE / Byte.SIZE - ERROR_VALUE_F_LENGTH, retBytes, ERROR_VALUE_F_OFFSET, + ERROR_VALUE_F_LENGTH); + ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS_F_OFFSET); + + return retBytes; + } + +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/RSVPErrorSpecIPv6TlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/RSVPErrorSpecIPv6TlvParser.java new file mode 100644 index 0000000000..6a2b8c691d --- /dev/null +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/RSVPErrorSpecIPv6TlvParser.java @@ -0,0 +1,79 @@ +/* + * 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 java.util.BitSet; + +import org.opendaylight.protocol.concepts.IPv6Address; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.tlv.RSVPErrorSpecTlv; +import org.opendaylight.protocol.util.ByteArray; + +/** + * Parser for {@link org.opendaylight.protocol.pcep.tlv.RSVPErrorSpecTlv RSVPErrorSpecTlv} + * parameterized as IPv6Address + */ +public class RSVPErrorSpecIPv6TlvParser { + + private static final int IP_F_LENGTH = 16; + private static final int FLAGS_F_LENGTH = 1; + private static final int ERROR_CODE_F_LENGTH = 1; + private static final int ERROR_VALUE_F_LENGTH = 2; + + private static final int IP_F_OFFSET = 0; + private static final int FLAGS_F_OFFSET = IP_F_OFFSET + IP_F_LENGTH; + private static final int ERROR_CODE_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH; + private static final int ERROR_VALUE_F_OFFSET = ERROR_CODE_F_OFFSET + ERROR_CODE_F_LENGTH; + + private static final int SIZE = ERROR_VALUE_F_OFFSET + ERROR_VALUE_F_LENGTH; + + /* + * 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; + + public static RSVPErrorSpecTlv parse(byte[] valueBytes) throws PCEPDeserializerException { + if (valueBytes == null || valueBytes.length == 0) + throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty."); + if (valueBytes.length != SIZE) { + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + "; Expected: " + SIZE + "."); + } + + final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(valueBytes, FLAGS_F_OFFSET, FLAGS_F_LENGTH)); + + return new RSVPErrorSpecTlv(new IPv6Address( + ByteArray.subByte(valueBytes, IP_F_OFFSET, IP_F_LENGTH)), flags.get(IN_PLACE_FLAG_OFFSET), flags.get(NOT_GUILTY_FLAGS_OFFSET), + valueBytes[ERROR_CODE_F_OFFSET] & 0xFF, + ByteArray.bytesToShort(ByteArray.subByte(valueBytes, ERROR_VALUE_F_OFFSET, ERROR_VALUE_F_LENGTH)) & 0xFFFF); + } + + public static byte[] put(RSVPErrorSpecTlv objToSerialize) { + if (objToSerialize == null) + throw new IllegalArgumentException("RSVPErrorSpecTlv is mandatory."); + + if (!(((RSVPErrorSpecTlv) objToSerialize).getErrorNodeAddress() instanceof IPv6Address)) + throw new IllegalArgumentException("Unknown parametrized type of RSVPErrorSpecTlv. Passed " + + ((RSVPErrorSpecTlv) objToSerialize).getErrorNodeAddress().getClass() + ". Needed IPv6Address."); + + final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE); + flags.set(IN_PLACE_FLAG_OFFSET, objToSerialize.isInPlace()); + flags.set(NOT_GUILTY_FLAGS_OFFSET, objToSerialize.isGuilty()); + + final byte[] retBytes = new byte[SIZE]; + + ByteArray.copyWhole(((IPv6Address) objToSerialize.getErrorNodeAddress()).getAddress(), retBytes, IP_F_OFFSET); + retBytes[ERROR_CODE_F_OFFSET] = ByteArray.intToBytes(objToSerialize.getErrorCode())[Integer.SIZE / Byte.SIZE - 1]; + System.arraycopy(ByteArray.intToBytes(objToSerialize.getErrorValue()), Integer.SIZE / Byte.SIZE - ERROR_VALUE_F_LENGTH, retBytes, ERROR_VALUE_F_OFFSET, + ERROR_VALUE_F_LENGTH); + ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS_F_OFFSET); + + return retBytes; + } + +} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/RSVPErrorSpecTlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/RSVPErrorSpecTlvParser.java deleted file mode 100644 index c7513a232f..0000000000 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/RSVPErrorSpecTlvParser.java +++ /dev/null @@ -1,145 +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 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.TlvParser; -import org.opendaylight.protocol.pcep.spi.TlvSerializer; -import org.opendaylight.protocol.util.ByteArray; -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; -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.RsvpErrorSpecBuilder; -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.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.UserErrorBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ErrorSpec.Flags; - -import com.google.common.primitives.UnsignedBytes; - -/** - * Parser for {@link RsvpErrorSpecTlv} - */ -public class RSVPErrorSpecTlvParser implements TlvParser, TlvSerializer { - - private static final int IP4_F_LENGTH = 4; - private static final int IP6_F_LENGTH = 16; - private static final int FLAGS_F_LENGTH = 1; - private static final int ERROR_CODE_F_LENGTH = 1; - private static final int ERROR_VALUE_F_LENGTH = 2; - - private static final int ENTERPRISE_F_LENGTH = 4; - private static final int SUB_ORG_F_LENGTH = 1; - private static final int ERR_DESCR_LENGTH_F_LENGTH = 1; - private static final int USER_VALUE_F_LENGTH = 2; - - private static final int RSVP_ERROR_CLASS_NUM = 6; - private static final int RSVP_IPV4_ERROR_CLASS_TYPE = 1; - private static final int RSVP_IPV6_ERROR_CLASS_TYPE = 2; - - 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; - - @Override - public RsvpErrorSpecTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException { - 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)); - - ErrorType errorType = null; - int byteOffset = 0; - - 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(); - } 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(); - } - - return new RsvpErrorSpecBuilder().setErrorType(errorType).build(); - } - - @Override - public byte[] serializeTlv(final Tlv tlv) { - if (tlv == null) - throw new IllegalArgumentException("RSVPErrorSpecTlv is mandatory."); - final RsvpErrorSpecTlv rsvp = (RsvpErrorSpecTlv) tlv; - - if (rsvp.getErrorType().getClass().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) { - - } - - } else { - - } - // TODO: finish - return null; - } - - @Override - public int getType() { - return TYPE; - } -} diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/ReqMissingTlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/ReqMissingTlvParser.java deleted file mode 100644 index ee967b4352..0000000000 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/ReqMissingTlvParser.java +++ /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.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.protocol.util.ByteArray; -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.Tlv; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.tlvs.ReqMissingBuilder; - -/** - * Parser {@link ReqMissingTlv} - */ -public class ReqMissingTlvParser implements TlvParser, TlvSerializer { - - private static final int REQ_ID_LENGTH = 4; - - public static final int TYPE = 3; - - @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(); - } - - @Override - public byte[] serializeTlv(final Tlv tlv) { - 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); - } - - @Override - public int getType() { - return TYPE; - } -} diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/CompositeTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/CompositeTest.java new file mode 100644 index 0000000000..ad31d5029e --- /dev/null +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/CompositeTest.java @@ -0,0 +1,438 @@ +/* + * 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.assertEquals; +import static org.junit.Assert.assertNull; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.concepts.TEMetric; +import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.PCEPTlv; +import org.opendaylight.protocol.pcep.object.CompositeErrorObject; +import org.opendaylight.protocol.pcep.object.CompositeNotifyObject; +import org.opendaylight.protocol.pcep.object.CompositePathObject; +import org.opendaylight.protocol.pcep.object.CompositeRequestObject; +import org.opendaylight.protocol.pcep.object.CompositeResponseObject; +import org.opendaylight.protocol.pcep.object.CompositeRptPathObject; +import org.opendaylight.protocol.pcep.object.CompositeStateReportObject; +import org.opendaylight.protocol.pcep.object.CompositeUpdPathObject; +import org.opendaylight.protocol.pcep.object.CompositeUpdateRequestObject; +import org.opendaylight.protocol.pcep.object.PCEPClassTypeObject; +import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPExistingPathBandwidthObject; +import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPIncludeRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPLoadBalancingObject; +import org.opendaylight.protocol.pcep.object.PCEPLspObject; +import org.opendaylight.protocol.pcep.object.PCEPLspaObject; +import org.opendaylight.protocol.pcep.object.PCEPMetricObject; +import org.opendaylight.protocol.pcep.object.PCEPNoPathObject; +import org.opendaylight.protocol.pcep.object.PCEPNotificationObject; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; +import org.opendaylight.protocol.pcep.object.PCEPReportedRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject; +import org.opendaylight.protocol.pcep.subobject.EROAsNumberSubobject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; +import org.opendaylight.protocol.pcep.subobject.RROAsNumberSubobject; +import org.opendaylight.protocol.pcep.subobject.ReportedRouteSubobject; +import org.opendaylight.protocol.pcep.tlv.LSPCleanupTlv; +import org.opendaylight.protocol.pcep.tlv.PCEStatefulCapabilityTlv; +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.nps.concepts.rev130930.Bandwidth; + +public class CompositeTest { + + public PCEPExplicitRouteObject ero; + public PCEPClassTypeObject ct; + public PCEPLspaObject lspa; + public List metrics = new ArrayList(); + public PCEPIncludeRouteObject iro = new PCEPIncludeRouteObject(new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new EROAsNumberSubobject(new AsNumber(0L), true)); + } + }, false, false); + public PCEPRequestParameterObject requestParameter; + public PCEPNoPathObject noPath; + public PCEPRequestedPathBandwidthObject bandwidth; + + public List requestParameters = new ArrayList(); + public PCEPErrorObject error; + public List errors = new ArrayList(); + + public PCEPNotificationObject notification; + public List notifications = new ArrayList(); + + private PCEPReportedRouteObject reportedRoute; + private PCEPExistingPathBandwidthObject rroBandwidth; + private PCEPIncludeRouteObject includeRoute; + private PCEPLoadBalancingObject loadBalancing; + private PCEPEndPointsObject endPoints; + + private PCEPLspObject lsp; + private final List compositePaths = new ArrayList(); + private final List compositeRptPaths = new ArrayList(); + private final List compositeUpdPaths = new ArrayList(); + public PCEPReportedRouteObject rro = new PCEPReportedRouteObject(new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new RROAsNumberSubobject(new AsNumber(0L))); + } + }, false); + + @Before + public void setUp() { + this.ero = new PCEPExplicitRouteObject(new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new EROAsNumberSubobject(new AsNumber(0L), true)); + } + }, false); + this.ct = new PCEPClassTypeObject((short) 5); + this.lspa = new PCEPLspaObject(0, 0, 0, (short) 0, (short) 0, false, false, false, false); + this.metrics.add(new PCEPMetricObject(false, false, new TEMetric(1000), false, false)); + this.metrics.add(new PCEPMetricObject(false, false, new TEMetric(1000), false, false)); + + this.requestParameter = new PCEPRequestParameterObject(false, false, false, false, false, false, false, false, (short) 0, 0, false, false); + this.noPath = new PCEPNoPathObject((short) 2, false, false); + this.bandwidth = new PCEPRequestedPathBandwidthObject(new Bandwidth(new byte[] { 0 }), false, false); + + this.requestParameters.add(this.requestParameter); + this.requestParameters.add(this.requestParameter); + + this.error = new PCEPErrorObject(PCEPErrors.BANDWIDTH_MISSING); + + this.errors.add(this.error); + this.errors.add(this.error); + this.errors.add(this.error); + + this.notification = new PCEPNotificationObject((short) 1, (short) 1); + + this.notifications.add(this.notification); + this.notifications.add(this.notification); + + final List eroSubobjects = new ArrayList(); + eroSubobjects.add(new EROAsNumberSubobject(new AsNumber(0x0L), false)); + eroSubobjects.add(new EROAsNumberSubobject(new AsNumber(0x0L), false)); + eroSubobjects.add(new EROAsNumberSubobject(new AsNumber(0x0L), false)); + + final List rroSubobjects = new ArrayList(); + rroSubobjects.add(new RROAsNumberSubobject(new AsNumber(0x0L))); + rroSubobjects.add(new RROAsNumberSubobject(new AsNumber(0x0L))); + rroSubobjects.add(new RROAsNumberSubobject(new AsNumber(0x0L))); + + this.reportedRoute = new PCEPReportedRouteObject(rroSubobjects, true); + this.rroBandwidth = new PCEPExistingPathBandwidthObject(new Bandwidth(new byte[] { (byte) 0xFF }), true, false); + this.includeRoute = new PCEPIncludeRouteObject(eroSubobjects, true, false); + this.loadBalancing = new PCEPLoadBalancingObject(0x0, new Bandwidth(new byte[] { 0 }), false); + final byte[] ipbytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }; + this.endPoints = new PCEPEndPointsObject(new IPv4Address(ipbytes), new IPv4Address(ipbytes)); + + this.lsp = new PCEPLspObject(0, false, false, true, true, null); + this.compositePaths.add(new CompositePathObject(new PCEPExplicitRouteObject(eroSubobjects, true), this.lspa, this.bandwidth, this.metrics, this.includeRoute)); + this.compositePaths.add(new CompositePathObject(new PCEPExplicitRouteObject(eroSubobjects, true))); + + this.compositeUpdPaths.add(new CompositeUpdPathObject(new PCEPExplicitRouteObject(eroSubobjects, true), this.lspa, this.bandwidth, this.metrics)); + this.compositeUpdPaths.add(new CompositeUpdPathObject(new PCEPExplicitRouteObject(eroSubobjects, true))); + + } + + @Test + public void testCompositePathObject() { + final List objects = new ArrayList(); + objects.add(this.ero); + objects.add(this.lspa); + objects.add(this.metrics.get(0)); + objects.add(this.metrics.get(1)); + objects.add(this.iro); + objects.add(new PCEPMetricObject(false, false, new TEMetric(1000), false, false)); + final CompositePathObject path = CompositePathObject.getCompositeFromList(objects); + assertEquals(path.getExcludedRoute(), this.ero); + assertEquals(path.getLspa(), this.lspa); + assertNull(path.getBandwidth()); + assertEquals(path.getMetrics().get(0), this.metrics.get(0)); + assertEquals(path.getMetrics().get(1), this.metrics.get(1)); + assertEquals(path.getIncludeRoute(), this.iro); + } + + @Test + public void testCompositeRptPathObject() { + final List objects = new ArrayList(); + objects.add(this.ero); + objects.add(this.lspa); + objects.add(this.rro); + objects.add(this.metrics.get(0)); + objects.add(this.metrics.get(1)); + objects.add(new PCEPMetricObject(false, false, new TEMetric(1000), false, false)); + final CompositeRptPathObject path = CompositeRptPathObject.getCompositeFromList(objects); + assertEquals(path.getExcludedRoute(), this.ero); + assertEquals(path.getLspa(), this.lspa); + assertNull(path.getBandwidth()); + assertEquals(path.getMetrics().get(0), this.metrics.get(0)); + assertEquals(path.getMetrics().get(1), this.metrics.get(1)); + assertEquals(path.getReportedRoute(), this.rro); + } + + @Test + public void testCompositeResponseObject() { + final List objects = new ArrayList(); + objects.add(this.requestParameter); + objects.add(this.noPath); + objects.add(this.bandwidth); + objects.add(this.metrics.get(0)); + objects.add(this.metrics.get(1)); + objects.add(this.iro); + // add one path + objects.add(this.ero); + objects.add(this.lspa); + objects.add(this.metrics.get(0)); + objects.add(this.metrics.get(1)); + objects.add(this.iro); + // add another path + objects.add(this.ero); + objects.add(this.lspa); + objects.add(this.metrics.get(0)); + objects.add(new PCEPMetricObject(false, false, new TEMetric(1000), false, false)); + objects.add(this.iro); + // + objects.add(this.requestParameter); + final List list = new ArrayList(); + while (!objects.isEmpty()) { + list.add(CompositeResponseObject.getCompositeFromList(objects)); + } + assertEquals(2, list.size()); + final CompositeResponseObject response = list.get(0); + + assertEquals(response.getRequestParameter(), this.requestParameter); + assertEquals(response.getNoPath(), this.noPath); + assertNull(response.getLspa()); + assertEquals(response.getBandwidth(), this.bandwidth); + assertEquals(response.getMetrics().get(0), this.metrics.get(0)); + assertEquals(response.getMetrics().get(1), this.metrics.get(1)); + assertEquals(response.getIncludeRoute(), this.iro); + // check path + CompositePathObject path = response.getPaths().get(0); + assertEquals(path.getExcludedRoute(), this.ero); + assertEquals(path.getLspa(), this.lspa); + assertNull(path.getBandwidth()); + assertEquals(path.getMetrics().get(0), this.metrics.get(0)); + assertEquals(path.getMetrics().get(1), this.metrics.get(1)); + assertEquals(path.getIncludeRoute(), this.iro); + // check path + path = response.getPaths().get(1); + assertEquals(path.getExcludedRoute(), this.ero); + assertEquals(path.getLspa(), this.lspa); + assertNull(path.getBandwidth()); + assertEquals(path.getMetrics().get(0), this.metrics.get(0)); + assertEquals(path.getMetrics().get(1), new PCEPMetricObject(false, false, new TEMetric(1000), false, false)); + assertEquals(path.getIncludeRoute(), this.iro); + } + + @Test + public void testCompositeErrorObject() { + final List objects = new ArrayList(); + CompositeErrorObject compositeErrors; + + objects.addAll(this.requestParameters); + objects.addAll(this.errors); + compositeErrors = new CompositeErrorObject(this.requestParameters.subList(0, this.requestParameters.size()), this.errors.subList(0, + this.errors.size())); + assertEquals(compositeErrors, CompositeErrorObject.getCompositeFromList(objects)); + + objects.clear(); + objects.addAll(this.errors); + compositeErrors = new CompositeErrorObject(null, this.errors.subList(0, this.errors.size())); + assertEquals(compositeErrors, CompositeErrorObject.getCompositeFromList(objects)); + + } + + @Test + public void testCompositeNotifyObject() { + final List objects = new ArrayList(); + CompositeNotifyObject compositeNotifications; + + objects.addAll(this.requestParameters); + objects.addAll(this.notifications); + compositeNotifications = new CompositeNotifyObject(this.requestParameters.subList(0, this.requestParameters.size()), this.notifications.subList( + 0, this.notifications.size())); + assertEquals(compositeNotifications, CompositeNotifyObject.getCompositeFromList(objects)); + + objects.clear(); + // first + objects.addAll(this.requestParameters); + objects.addAll(this.notifications); + // second + objects.addAll(this.requestParameters); + objects.addAll(this.notifications); + while (!objects.isEmpty()) { + assertEquals(compositeNotifications, CompositeNotifyObject.getCompositeFromList(objects)); + } + + objects.clear(); + objects.addAll(this.notifications); + compositeNotifications = new CompositeNotifyObject(null, this.notifications.subList(0, this.notifications.size())); + assertEquals(compositeNotifications, CompositeNotifyObject.getCompositeFromList(objects)); + + } + + @Test + public void testCompositeRequestObject() { + final List objects = new ArrayList(); + CompositeRequestObject compositeRequest; + + objects.add(this.requestParameter); + objects.add(this.endPoints); + objects.add(this.ct); + objects.add(this.lsp); + objects.add(this.lspa); + objects.add(this.bandwidth); + objects.addAll(this.metrics); + objects.add(this.reportedRoute); + objects.add(this.rroBandwidth); + objects.add(this.includeRoute); + objects.add(this.loadBalancing); + + compositeRequest = new CompositeRequestObject(this.requestParameter, this.endPoints, this.ct, this.lsp, this.lspa, this.bandwidth, this.metrics.subList( + 0, this.metrics.size()), this.reportedRoute, this.rroBandwidth, this.includeRoute, this.loadBalancing); + assertEquals(compositeRequest, CompositeRequestObject.getCompositeFromList(objects)); + + objects.clear(); + // first + objects.add(this.requestParameter); + objects.add(this.endPoints); + objects.add(this.ct); + objects.add(this.lsp); + objects.add(this.lspa); + objects.add(this.bandwidth); + objects.addAll(this.metrics); + objects.add(this.reportedRoute); + objects.add(this.rroBandwidth); + objects.add(this.includeRoute); + objects.add(this.loadBalancing); + // second + objects.add(this.requestParameter); + objects.add(this.endPoints); + objects.add(this.ct); + objects.add(this.lsp); + objects.add(this.lspa); + objects.add(this.bandwidth); + objects.addAll(this.metrics); + objects.add(this.reportedRoute); + objects.add(this.rroBandwidth); + objects.add(this.includeRoute); + objects.add(this.loadBalancing); + while (!objects.isEmpty()) { + assertEquals(compositeRequest, CompositeRequestObject.getCompositeFromList(objects)); + } + + objects.clear(); + objects.add(this.requestParameter); + objects.add(this.endPoints); + compositeRequest = new CompositeRequestObject(this.requestParameter, this.endPoints); + assertEquals(compositeRequest, CompositeRequestObject.getCompositeFromList(objects)); + + } + + @Test + public void testCompositeStateReportObject() { + final List objects = new ArrayList(); + CompositeStateReportObject compositeStateReport; + + objects.add(this.lsp); + for (final CompositeRptPathObject compositeRptPath : this.compositeRptPaths) { + objects.addAll(compositeRptPath.getCompositeAsList()); + } + + compositeStateReport = new CompositeStateReportObject(this.lsp, this.compositeRptPaths); + assertEquals(compositeStateReport, CompositeStateReportObject.getCompositeFromList(objects)); + + objects.clear(); + // first + objects.add(this.lsp); + for (final CompositeRptPathObject compositeRptPath : this.compositeRptPaths) { + objects.addAll(compositeRptPath.getCompositeAsList()); + } + // second + objects.add(this.lsp); + for (final CompositeRptPathObject compositeRptPath : this.compositeRptPaths) { + objects.addAll(compositeRptPath.getCompositeAsList()); + } + while (!objects.isEmpty()) { + assertEquals(compositeStateReport, CompositeStateReportObject.getCompositeFromList(objects)); + } + + objects.clear(); + objects.add(this.lsp); + for (final CompositeRptPathObject compositeRptPath : this.compositeRptPaths) { + objects.addAll(compositeRptPath.getCompositeAsList()); + } + compositeStateReport = new CompositeStateReportObject(this.lsp, this.compositeRptPaths); + assertEquals(compositeStateReport, CompositeStateReportObject.getCompositeFromList(objects)); + + } + + @Test + public void testCompositeUpdateRequestObject() { + final List objects = new ArrayList(); + CompositeUpdateRequestObject compositeStateReport; + + objects.add(this.lsp); + for (final CompositeUpdPathObject compositePath : this.compositeUpdPaths) { + objects.addAll(compositePath.getCompositeAsList()); + } + + compositeStateReport = new CompositeUpdateRequestObject(this.lsp, this.compositeUpdPaths); + assertEquals(compositeStateReport, CompositeUpdateRequestObject.getCompositeFromList(objects)); + + objects.clear(); + // first + objects.add(this.lsp); + for (final CompositeUpdPathObject compositePath : this.compositeUpdPaths) { + objects.addAll(compositePath.getCompositeAsList()); + } + // second + objects.add(this.lsp); + for (final CompositeUpdPathObject compositePath : this.compositeUpdPaths) { + objects.addAll(compositePath.getCompositeAsList()); + } + while (!objects.isEmpty()) { + assertEquals(compositeStateReport, CompositeUpdateRequestObject.getCompositeFromList(objects)); + } + + objects.clear(); + objects.add(this.lsp); + for (final CompositeUpdPathObject compositePath : this.compositeUpdPaths) { + objects.addAll(compositePath.getCompositeAsList()); + } + compositeStateReport = new CompositeUpdateRequestObject(this.lsp, this.compositeUpdPaths); + assertEquals(compositeStateReport, CompositeUpdateRequestObject.getCompositeFromList(objects)); + + } + + @Test + public void testSessionProposalFactory() throws IOException { + final PCEPSessionProposalFactoryImpl spf = new PCEPSessionProposalFactoryImpl(10, 2, true, false, true, true, 5); + final List tlvs = new ArrayList(); + tlvs.add(new PCEStatefulCapabilityTlv(true, false, true)); + tlvs.add(new LSPCleanupTlv(5)); + assertEquals(new PCEPOpenObject(2, 10, 0, tlvs), spf.getSessionProposal(null, 0)); + } +} diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/FiniteStateMachineTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/FiniteStateMachineTest.java index 358be3d533..713e984f17 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/FiniteStateMachineTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/FiniteStateMachineTest.java @@ -10,14 +10,22 @@ package org.opendaylight.protocol.pcep.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.util.ArrayList; + import org.junit.After; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.message.PCEPErrorMessage; +import org.opendaylight.protocol.pcep.message.PCEPNotificationMessage; +import org.opendaylight.protocol.pcep.message.PCEPOpenMessage; +import org.opendaylight.protocol.pcep.object.CompositeNotifyObject; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPNotificationObject; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; 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.Message; -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.keepalive.message.KeepaliveMessageBuilder; public class FiniteStateMachineTest { @@ -46,8 +54,8 @@ public class FiniteStateMachineTest { public void testSessionCharsAccBoth() throws InterruptedException { // this.serverSession.startSession(); assertEquals(1, this.client.getListMsg().size()); - assertTrue(this.client.getListMsg().get(0) instanceof OpenMessage); - // this.client.sendMessage(new PCEPOpenMessage(new PCEPOpenObject(3, 9, 2))); + assertTrue(this.client.getListMsg().get(0) instanceof PCEPOpenMessage); + this.client.sendMessage(new PCEPOpenMessage(new PCEPOpenObject(3, 9, 2))); assertEquals(2, this.client.getListMsg().size()); assertTrue(this.client.getListMsg().get(1) instanceof KeepaliveMessage); this.client.sendMessage((Message) new KeepaliveMessageBuilder().build()); @@ -64,15 +72,15 @@ public class FiniteStateMachineTest { // Thread.sleep(PCEPSessionImpl.KEEP_ALIVE_TIMER_VALUE * 1000); // assertEquals(3, this.client.getListMsg().size()); // assertTrue(this.client.getListMsg().get(2) instanceof PCEPKeepAliveMessage); // test of keepalive timer - // this.client.sendMessage(new PCEPOpenMessage(new PCEPOpenObject(1, 1, 1))); - // assertEquals(3, this.client.getListMsg().size()); - // assertTrue(this.client.getListMsg().get(2) instanceof PCEPErrorMessage); - // for (final Message m : this.client.getListMsg()) { - // if (m instanceof PCEPErrorMessage) { - // final PCEPErrorObject obj = ((PCEPErrorMessage) m).getErrorObjects().get(0); - // assertEquals(PCEPErrors.ATTEMPT_2ND_SESSION, obj.getError()); // test of error type 9 - // } - // } + this.client.sendMessage(new PCEPOpenMessage(new PCEPOpenObject(1, 1, 1))); + assertEquals(3, this.client.getListMsg().size()); + assertTrue(this.client.getListMsg().get(2) instanceof PCEPErrorMessage); + for (final Message m : this.client.getListMsg()) { + if (m instanceof PCEPErrorMessage) { + final PCEPErrorObject obj = ((PCEPErrorMessage) m).getErrorObjects().get(0); + assertEquals(PCEPErrors.ATTEMPT_2ND_SESSION, obj.getError()); // test of error type 9 + } + } } /** @@ -84,13 +92,13 @@ public class FiniteStateMachineTest { @Ignore public void testSessionCharsAccMe() throws InterruptedException { // this.serverSession.startSession(); - // this.client.sendMessage(new PCEPOpenMessage(new PCEPOpenObject(4, 9, 2))); + this.client.sendMessage(new PCEPOpenMessage(new PCEPOpenObject(4, 9, 2))); assertEquals(2, this.client.getListMsg().size()); - assertTrue(this.client.getListMsg().get(0) instanceof OpenMessage); + assertTrue(this.client.getListMsg().get(0) instanceof PCEPOpenMessage); assertTrue(this.client.getListMsg().get(1) instanceof KeepaliveMessage); - // this.client.sendErrorMessage(PCEPErrors.NON_ACC_NEG_SESSION_CHAR, new PCEPOpenObject(3, 7, 2, null)); + this.client.sendErrorMessage(PCEPErrors.NON_ACC_NEG_SESSION_CHAR, new PCEPOpenObject(3, 7, 2, null)); assertEquals(3, this.client.getListMsg().size()); - assertTrue(this.client.getListMsg().get(2) instanceof OpenMessage); + assertTrue(this.client.getListMsg().get(2) instanceof PCEPOpenMessage); this.client.sendMessage((Message) new KeepaliveMessageBuilder().build()); synchronized (this.serverListener) { while (!this.serverListener.up) { @@ -114,26 +122,26 @@ public class FiniteStateMachineTest { public void testErrorOneOne() throws InterruptedException { // this.serverSession.startSession(); assertEquals(1, this.client.getListMsg().size()); - // assertTrue(this.client.getListMsg().get(0) instanceof OpenMessage); - // this.client.sendMessage(new PCEPNotificationMessage(new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new CompositeNotifyObject(new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPNotificationObject((short) 1, (short) 1)); - // } - // })); - // } - // })); - // for (final Message m : this.client.getListMsg()) { - // if (m instanceof PCEPErrorMessage) { - // final PCEPErrorObject obj = ((PCEPErrorMessage) m).getErrorObjects().get(0); - // assertEquals(PCEPErrors.NON_OR_INVALID_OPEN_MSG, obj.getError()); - // } - // } + assertTrue(this.client.getListMsg().get(0) instanceof PCEPOpenMessage); + this.client.sendMessage(new PCEPNotificationMessage(new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new CompositeNotifyObject(new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPNotificationObject((short) 1, (short) 1)); + } + })); + } + })); + for (final Message m : this.client.getListMsg()) { + if (m instanceof PCEPErrorMessage) { + final PCEPErrorObject obj = ((PCEPErrorMessage) m).getErrorObjects().get(0); + assertEquals(PCEPErrors.NON_OR_INVALID_OPEN_MSG, obj.getError()); + } + } } /************* Tests commented because of their long duration (tested timers) **************/ @@ -148,14 +156,14 @@ public class FiniteStateMachineTest { public void testErrorOneTwo() throws InterruptedException { // this.serverSession.startSession(); assertEquals(1, this.client.getListMsg().size()); - assertTrue(this.client.getListMsg().get(0) instanceof OpenMessage); - // Thread.sleep(60 * 1000); - // for (final Message m : this.client.getListMsg()) { - // if (m instanceof PcerrMessage) { - // final PCEPErrorObject obj = ((PCEPErrorMessage) m).getErrorObjects().get(0); - // assertEquals(PCEPErrors.NO_OPEN_BEFORE_EXP_OPENWAIT, obj.getError()); - // } - // } + assertTrue(this.client.getListMsg().get(0) instanceof PCEPOpenMessage); + Thread.sleep(60 * 1000); + for (final Message m : this.client.getListMsg()) { + if (m instanceof PCEPErrorMessage) { + final PCEPErrorObject obj = ((PCEPErrorMessage) m).getErrorObjects().get(0); + assertEquals(PCEPErrors.NO_OPEN_BEFORE_EXP_OPENWAIT, obj.getError()); + } + } } /** @@ -166,17 +174,17 @@ public class FiniteStateMachineTest { @Test @Ignore public void testErrorOneSeven() throws InterruptedException { - // // this.serverSession.startSession(); - // assertEquals(1, this.client.getListMsg().size()); - // assertTrue(this.client.getListMsg().get(0) instanceof OpenMessage); - // this.client.sendMessage(new PCEPOpenMessage(new OpenObject(3, 9, 2))); - // Thread.sleep(this.serverSession.getKeepAliveTimerValue() * 1000); - // for (final Message m : this.client.getListMsg()) { - // if (m instanceof PcerrMessage) { - // final PCEPErrorObject obj = ((PCEPErrorMessage) m).getErrorObjects().get(0); - // assertEquals(PCEPErrors.NO_MSG_BEFORE_EXP_KEEPWAIT, obj.getError()); - // } - // } + // this.serverSession.startSession(); + assertEquals(1, this.client.getListMsg().size()); + assertTrue(this.client.getListMsg().get(0) instanceof PCEPOpenMessage); + this.client.sendMessage(new PCEPOpenMessage(new PCEPOpenObject(3, 9, 2))); + Thread.sleep(this.serverSession.getKeepAliveTimerValue() * 1000); + for (final Message m : this.client.getListMsg()) { + if (m instanceof PCEPErrorMessage) { + final PCEPErrorObject obj = ((PCEPErrorMessage) m).getErrorObjects().get(0); + assertEquals(PCEPErrors.NO_MSG_BEFORE_EXP_KEEPWAIT, obj.getError()); + } + } } @Test diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/MockPCE.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/MockPCE.java index b3e3f5dfdb..c6a0d0fcb1 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/MockPCE.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/MockPCE.java @@ -14,8 +14,10 @@ import org.opendaylight.protocol.pcep.PCEPErrors; import org.opendaylight.protocol.pcep.PCEPSession; import org.opendaylight.protocol.pcep.PCEPSessionListener; import org.opendaylight.protocol.pcep.PCEPTerminationReason; +import org.opendaylight.protocol.pcep.message.PCEPErrorMessage; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; 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.OpenObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,8 +40,11 @@ public class MockPCE implements PCEPSessionListener { this.session.handleMessage(msg); } - public void sendErrorMessage(final PCEPErrors value, final OpenObject open) { - this.sendMessage(Util.createErrorMessage(value, open)); + public void sendErrorMessage(final PCEPErrors value, final PCEPOpenObject open) { + final PCEPErrorObject error = new PCEPErrorObject(value); + final List errors = new ArrayList(); + errors.add(error); + this.sendMessage(new PCEPErrorMessage(open, errors, null)); } public List getListMsg() { diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java index d36eb10655..8ce700c719 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java @@ -7,6 +7,77 @@ */ package org.opendaylight.protocol.pcep.impl; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.NoSuchElementException; + +import org.junit.Ignore; +import org.junit.Test; +import org.opendaylight.protocol.concepts.IGPMetric; +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.concepts.IPv4Prefix; +import org.opendaylight.protocol.concepts.IPv6Address; +import org.opendaylight.protocol.concepts.IPv6Prefix; +import org.opendaylight.protocol.concepts.TEMetric; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPOFCodes; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.PCEPTlv; +import org.opendaylight.protocol.pcep.impl.object.PCEPClassTypeObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser; +import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser.PCEPErrorIdentifier; +import org.opendaylight.protocol.pcep.impl.object.UnknownObject; +import org.opendaylight.protocol.pcep.object.PCEPBranchNodeListObject; +import org.opendaylight.protocol.pcep.object.PCEPClassTypeObject; +import org.opendaylight.protocol.pcep.object.PCEPCloseObject; +import org.opendaylight.protocol.pcep.object.PCEPCloseObject.Reason; +import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPGlobalConstraintsObject; +import org.opendaylight.protocol.pcep.object.PCEPIncludeRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPLoadBalancingObject; +import org.opendaylight.protocol.pcep.object.PCEPLspObject; +import org.opendaylight.protocol.pcep.object.PCEPLspaObject; +import org.opendaylight.protocol.pcep.object.PCEPMetricObject; +import org.opendaylight.protocol.pcep.object.PCEPNoPathObject; +import org.opendaylight.protocol.pcep.object.PCEPNonBranchNodeListObject; +import org.opendaylight.protocol.pcep.object.PCEPNotificationObject; +import org.opendaylight.protocol.pcep.object.PCEPObjectiveFunctionObject; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; +import org.opendaylight.protocol.pcep.object.PCEPP2MPEndPointsObject; +import org.opendaylight.protocol.pcep.object.PCEPReportedRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject; +import org.opendaylight.protocol.pcep.object.PCEPSecondaryExplicitRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPSecondaryRecordRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPSvecObject; +import org.opendaylight.protocol.pcep.object.PCEPUnreachedDestinationObject; +import org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject; +import org.opendaylight.protocol.pcep.subobject.ExcludeRouteSubobject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; +import org.opendaylight.protocol.pcep.subobject.RROIPAddressSubobject; +import org.opendaylight.protocol.pcep.subobject.ReportedRouteSubobject; +import org.opendaylight.protocol.pcep.subobject.XROAsNumberSubobject; +import org.opendaylight.protocol.pcep.subobject.XROIPPrefixSubobject; +import org.opendaylight.protocol.pcep.subobject.XROSubobjectAttribute; +import org.opendaylight.protocol.pcep.tlv.LSPStateDBVersionTlv; +import org.opendaylight.protocol.pcep.tlv.NoPathVectorTlv; +import org.opendaylight.protocol.pcep.tlv.NodeIdentifierTlv; +import org.opendaylight.protocol.pcep.tlv.OrderTlv; +import org.opendaylight.protocol.pcep.tlv.OverloadedDurationTlv; +import org.opendaylight.protocol.pcep.tlv.PCEStatefulCapabilityTlv; +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.nps.concepts.rev130930.Bandwidth; /** * Used resources
@@ -320,601 +391,538 @@ package org.opendaylight.protocol.pcep.impl; * - XROIPv4PreffixSubobject(192.168.0.0/16, exclude, node)
* - XROASnumber(0x1234)
*/ + 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 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
- // * Used resources:
- // * - PCEPOpenObject1.bin
- // * - // * @throws PCEPDeserializerException - // * @throws IOException - // * @throws PCEPDocumentedException - // */ - // @Test - // @Ignore - // // FIXME: temporary - // public void testObjectDeserialization() throws PCEPDeserializerException, IOException, PCEPDocumentedException { - // PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin")); - // } - // - // @Test - // public void testUnknownClass() throws PCEPDeserializerException, IOException, PCEPDocumentedException { - // - // final PCEPObject obj = - // PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPObject1UnknownClass.bin")).get( - // 0); - // - // // assertTrue(obj instanceof UnknownObject); - // // assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_CLASS); - // } - // - // // @Test - // // public void testUnknownType() throws PCEPDeserializerException, IOException, PCEPDocumentedException { - // // final PCEPObject obj = - // PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPObject2UnknownType.bin")).get(0); - // // - // // assertTrue(obj instanceof UnknownObject); - // // 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 testLspObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException { - // serDeserTest("src/test/resources/PCEPLspObject1NoTlvsUpperBounds.bin", new PCEPLspObject(0xFFFFF, true, false, - // true, false, null)); - // } - // - // @Test - // public void testERObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException { - // final byte[] bytesFromFile = - // ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin"); - // - // MockitoAnnotations.initMocks(this); - // PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(registry); - // doReturn(parser).when(registry).getObjectParser(PCEPExplicitRouteObjectParser.TYPE, - // PCEPExplicitRouteObjectParser.CLASS); - // doReturn(new EROAsNumberSubobjectParser()).when(registry).getSubobjectParser(EROAsNumberSubobjectParser.TYPE); - // ObjectHeader h = new ObjectHeader() { - // - // @Override - // public Class getImplementedInterface() { - // // TODO Auto-generated method stub - // return null; - // } - // - // @Override - // public Boolean isProcessingRule() { - // return false; - // } - // - // @Override - // public Boolean isIgnore() { - // return false; - // } - // }; - // - // final ExplicitRouteSubobject specObj = (ExplicitRouteSubobject) - // registry.getObjectParser(PCEPExplicitRouteObjectParser.TYPE, PCEPExplicitRouteObjectParser.CLASS).parseObject(h, - // bytesFromFile); - // - // System.out.println(specObj.toString()); - // - // //final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj)); - // //assertArrayEquals(bytesFromFile, bytesActual); - // } - // - // @Test - // public void testIRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException { - // final byte[] bytesFromFile = - // ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin"); - // - // final PCEPIncludeRouteObject specObj = (PCEPIncludeRouteObject) - // PCEPObjectFactory.parseObjects(bytesFromFile).get(0); - // - // assertEquals(8, specObj.getSubobjects().size()); - // - // final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj)); - // assertArrayEquals(bytesFromFile, bytesActual); - // } - // - // @Test - // public void tesRRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException { - // final byte[] bytesFromFile = - // ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin"); - // - // final PCEPReportedRouteObject specObj = (PCEPReportedRouteObject) - // PCEPObjectFactory.parseObjects(bytesFromFile).get(0); - // - // assertEquals(6, specObj.getSubobjects().size()); - // - // final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj)); - // assertArrayEquals(bytesFromFile, bytesActual); - // } - // - // /** - // * Test for upper/lower bounds (Serialization/Deserialization)
- // * Used resources:
- // * - PCEPBandwidthObject2UpperBounds.bin
- // * - PCEPBandwidthObject1LowerBounds.bin
- // * - // * @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)
- // * Used resources:
- // * - PCEPEndPointsObject1IPv4.bin
- // * - // * @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(new IPv4Address(srcIPBytes), new IPv4Address(destIPBytes))); - // } - // - // /** - // * Test for upper/lower bounds of IPv6 EndPoints (Serialization/Deserialization)
- // * Used resources:
- // * - PCEPEndPointsObject2IPv6.bin
- // * - // * @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(new IPv6Address(srcIPBytes), new IPv6Address(destIPBytes))); - // } - // - // /** - // * Test of Serialization/Deserialization of PCEPErrorObjectParser.
- // *
- // * Used resources:
- // * - PCEPErrorObject1.bin
- // * - PCEPErrorObject3.bin
- // * - // * @throws PCEPDeserializerException - // * @throws IOException - // * @throws PCEPDocumentedException - // */ - // @Test - // public void testErrorObjectSerDeserWithTlv() throws PCEPDeserializerException, IOException, - // PCEPDocumentedException { - // serDeserTest("src/test/resources/PCEPErrorObject1.bin", new PCEPErrorObject(PCEPErrors.NON_OR_INVALID_OPEN_MSG)); - // serDeserTest("src/test/resources/PCEPErrorObject3.bin", new - // PCEPErrorObject(PCEPErrors.CAPABILITY_NOT_SUPPORTED)); - // } - // - // /** - // * Test of validity of PCEPErrorObjectParser. Expect throwed NoSuchElementException.
- // *
- // * Used resources:
- // * - PCEPErrorObject2Invalid.bin
- // * - // * @throws NoSuchElementException - // * @throws IOException - // * @throws PCEPDocumentedException - // */ - // @Test(expected = PCEPDeserializerException.class) - // public void testUnknownError() throws PCEPDeserializerException, IOException, PCEPDocumentedException { - // PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject2Invalid.bin")).get(0); - // } - // - // /** - // * Test for upper/lower bounds of PCEPLspaObject (Serialization/Deserialization)
- // * Used resources:
- // * - PCEPLspaObject1LowerBounds.bin
- // * - PCEPLspaObject2UpperBounds.bin
- // * - PCEPLspaObject3RandVals.bin
- // * - // * @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
- // * Used resources:
- // * - NoPathObject1WithTLV.bin
- // * - NoPathObject2WithoutTLV.bin
- // * - // * @throws PCEPDeserializerException - // * @throws IOException - // * @throws PCEPDocumentedException - // */ - // @Test - // public void testNoPathObjectDeserialization() throws PCEPDeserializerException, IOException, - // PCEPDocumentedException { - // // final List tlvs = new ArrayList(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
- // * Used resources:
- // * - NoPathObject1WithTLV.bin
- // * - NoPathObject2WithoutTLV.bin
- // * - // * @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)); - // assertArrayEquals(bytesFromFile, bytesActual); - // - // bytesFromFile = ByteArray.fileToBytes("src/test/resources/NoPathObject1WithTLV.bin"); - // noPathObject = (PCEPNoPathObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0); - // bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) noPathObject)); - // assertArrayEquals(bytesFromFile, bytesActual); - // } - // - // /** - // * Specific test with/without tlvs (Ser/Deser)
- // * Used resources:
- // * - PCEPNotificationObject1WithTlv.bin - PCEPNotificationObject2WithoutTlv.bin - // * - // * @throws PCEPDeserializerException - // * @throws IOException - // * @throws PCEPDocumentedException - // */ - // @Test - // public void testNotifyObjectSerDeserWithTlv() throws PCEPDeserializerException, IOException, - // PCEPDocumentedException { - // // FINAL LIST TLVS = NEW ARRAYLIST(1); - // // TLVS.ADD(NEW OVERLOADEDDURATIONTLV(0XFF0000A2)); - // // SERDESERTEST("src/test/resources/PCEPNotificationObject1WithTlv.bin", new PCEPNotificationObject((short) 1, - // (short) 1, tlvs)); - // serDeserTest("src/test/resources/PCEPNotificationObject2WithoutTlv.bin", new PCEPNotificationObject((short) 0xFF, - // (short) 0xFF)); - // } - // - // /** - // * Standard ser deser test
- // * used resources:
- // * - PCEPOpenObject1.bin - // * - // * @throws PCEPDeserializerException - // * @throws IOException - // * @throws PCEPDocumentedException - // */ - // @Test - // @Ignore - // // FIXME: temporary - // public void testOpenObjectSerDeser() throws PCEPDeserializerException, IOException, PCEPDocumentedException { - // // final List tlvs = new ArrayList(); - // // tlvs.add(new PCEStatefulCapabilityTlv(false, true, true)); - // // tlvs.add(new LSPStateDBVersionTlv(0x80)); - // // final byte[] valueBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, - // (byte) 0xDE, (byte) 0xF0 }; - // // tlvs.add(new NodeIdentifierTlv(valueBytes)); - // // final PCEPOpenObject specObject = new PCEPOpenObject(30, 120, 1, tlvs); - // // - // // serDeserTest("src/test/resources/PCEPOpenObject1.bin", specObject); - // } - // - // /** - // * Specific test for upper bounds and without tlvs
- // * Used resources:
- // * - PCEPOpenObject2UpperBoundsNoTlv.bin - // * - // * @throws PCEPDeserializerException - // * @throws IOException - // * @throws PCEPDocumentedException - // */ - // @Test - // public void testOpenObjectBoundsWithoutTlvs() throws IOException, PCEPDeserializerException, - // PCEPDocumentedException { - // // final List tlvs = new ArrayList(); - // // serDeserTest("src/test/resources/PCEPOpenObject2UpperBoundsNoTlv.bin", new PCEPOpenObject(0xFF, 0xFF, 0xFF, - // tlvs)); - // serDeserTest("src/test/resources/PCEPOpenObject2UpperBoundsNoTlv.bin", new PCEPOpenObject(0xFF, 0xFF, 0xFF, - // null)); - // } - // - // /** - // * Standard deserialization test
- // * Used resources:
- // * - PCEPRPObject1.bin - // * - // * @throws PCEPDeserializerException - // * @throws IOException - // * @throws PCEPDocumentedException - // */ - // @Test - // public void testRPObjectSerDeser() throws PCEPDeserializerException, IOException, PCEPDocumentedException { - // serDeserTest("src/test/resources/PCEPRPObject1.bin", - // new PCEPRequestParameterObject(true, false, true, true, false, false, false, false, (short) 5, 0xdeadbeefL, - // false, false)); - // // serDeserTest( - // // "src/test/resources/PCEPRPObject2.bin", - // // new PCEPRequestParameterObject(true, false, false, false, true, false, true, false, true, (short) 5, - // 0xdeadbeefL, new ArrayList() { - // // private static final long serialVersionUID = 1L; - // // - // // { - // // this.add(new OrderTlv(0xFFFFFFFFL, 0x00000001L)); - // // } - // // }, false, false)); - // } - // - // /** - // * Test for upper/lower bounds of PCEPSvecObject (Serialization/Deserialization)
- // * Used resources:
- // * - PCEPSvecObject1_10ReqIDs.bin
- // * - // * @throws IOException - // * @throws PCEPDeserializerException - // * @throws PCEPDocumentedException - // */ - // @Test - // public void testSvecObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException { - // final List requestIDs = new ArrayList(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)
- // * Used resources:
- // * - PCEPSvecObject2.bin
- // * - // * @throws IOException - // * @throws PCEPDeserializerException - // * @throws PCEPDocumentedException - // */ - // @Test - // public void testSvecObjectSerDeserNoReqIDs() throws IOException, PCEPDeserializerException, - // PCEPDocumentedException { - // final List requestIDs = new ArrayList(); - // 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 PCEPExcludeRouteObjectObject (Serialization/Deserialization)
- // * Used resources:
- // * - PCEPExcludeRouteObject.1.bin
- // * - // * @throws IOException - // * @throws PCEPDeserializerException - // * @throws PCEPDocumentedException - // */ - // @Test - // public void testExcludeRouteObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException { - // final List xroSubobjects = new ArrayList(); - // xroSubobjects.add(new XROIPPrefixSubobject(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 192, - // (byte) 168, - // (byte) 100, (byte) 100 }), 16), true, XROSubobjectAttribute.NODE)); - // xroSubobjects.add(new XROAsNumberSubobject(new AsNumber(0x1234L), false)); - // - // } - // - // @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)); - // } - // - // // FIXME: add at least one test with true value - // @Test - // public void openObjectWithTlv() throws PCEPDeserializerException, PCEPDocumentedException { - // // this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, false, false)); - // // this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, false, true)); - // // this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, true, false)); - // // this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, true, true)); - // } - // - // // private void testOpenObjectWithSpecTlv(final PCEPTlv tlv) throws PCEPDeserializerException, - // PCEPDocumentedException { - // // final List objs = new ArrayList(); - // // final List tlvs = new ArrayList(); - // // tlvs.add(tlv); - // // final PCEPOpenObject oo = new PCEPOpenObject(30, 120, 0, tlvs); - // // objs.add(oo); - // // final byte[] bytes = PCEPObjectFactory.put(objs); - // // final PCEPObject obj = PCEPObjectFactory.parseObjects(bytes).get(0); - // // assertEquals(oo, obj); - // // } - // - // @Test - // public void testErrorsMapping() { - // final PCEPErrorObjectParser.PCEPErrorsMaping mapper = PCEPErrorObjectParser.PCEPErrorsMaping.getInstance(); - // - // for (final PCEPErrors error : PCEPErrors.values()) { - // final PCEPErrorIdentifier errorId = mapper.getFromErrorsEnum(error); - // assertEquals(error, mapper.getFromErrorIdentifier(errorId)); - // } - // } - // - // @Test - // public void testOFCodesMapping() { - // final PCEPOFCodesMapping mapper = PCEPOFCodesMapping.getInstance(); - // - // for (final PCEPOFCodes ofCode : PCEPOFCodes.values()) { - // final int ofCodeId = mapper.getFromOFCodesEnum(ofCode); - // assertEquals(ofCode, mapper.getFromCodeIdentifier(ofCodeId)); - // } - // } - // - // @SuppressWarnings("unchecked") - // private static void serDeserTestWithoutBin(final T object) throws - // PCEPDeserializerException, - // PCEPDocumentedException { - // final byte[] serBytes = PCEPObjectFactory.put(Arrays.asList((PCEPObject) object)); - // final T deserObj = (T) PCEPObjectFactory.parseObjects(serBytes).get(0); - // - // assertEquals(object, deserObj); - // } - // - // @Test - // public void testSERObjects() throws PCEPDocumentedException, PCEPDeserializerException { - // final List eroSubobjects = new ArrayList(); - // eroSubobjects.add(new EROIPPrefixSubobject(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 192, - // (byte) 168, 1, 8 }), 16), false)); - // eroSubobjects.add(new EROIPPrefixSubobject(new IPv6Prefix(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 }), 64), false)); - // - // serDeserTestWithoutBin(new PCEPSecondaryExplicitRouteObject(eroSubobjects, true, false)); - // } - // - // @Test - // public void testSRRObject() throws PCEPDocumentedException, PCEPDeserializerException { - // final List rroSubobjects = new ArrayList(); - // rroSubobjects.add(new RROIPAddressSubobject(new IPv4Prefix(this.ipv4addr, 16), true, false)); - // rroSubobjects.add(new RROIPAddressSubobject(new IPv6Prefix(this.ipv6addr, 64), false, true)); - // - // serDeserTestWithoutBin(new PCEPSecondaryRecordRouteObject(rroSubobjects, true, false)); - // } - // - // @Test - // public void testP2MPEndpointsObjects() throws PCEPDeserializerException, PCEPDocumentedException { - // serDeserTestWithoutBin(new PCEPP2MPEndPointsObject(2, this.ipv4addr, Arrays.asList(this.ipv4addr, - // this.ipv4addr, - // this.ipv4addr), true, false)); - // serDeserTestWithoutBin(new PCEPP2MPEndPointsObject(1, this.ipv4addr, Arrays.asList(this.ipv4addr), - // true, false)); - // serDeserTestWithoutBin(new PCEPP2MPEndPointsObject(2, this.ipv6addr, Arrays.asList(this.ipv6addr, - // this.ipv6addr, - // this.ipv6addr), true, false)); - // serDeserTestWithoutBin(new PCEPP2MPEndPointsObject(1, this.ipv6addr, Arrays.asList(this.ipv6addr), - // true, false)); - // } - // - // @Test - // public void testUnreachedDestinationObjects() throws PCEPDeserializerException, PCEPDocumentedException { - // serDeserTestWithoutBin(new PCEPUnreachedDestinationObject(Arrays.asList(this.ipv4addr, - // this.ipv4addr, this.ipv4addr), true, false)); - // serDeserTestWithoutBin(new PCEPUnreachedDestinationObject(Arrays.asList(this.ipv4addr), true, - // false)); - // serDeserTestWithoutBin(new PCEPUnreachedDestinationObject(Arrays.asList(this.ipv6addr, - // this.ipv6addr, this.ipv6addr), true, false)); - // serDeserTestWithoutBin(new PCEPUnreachedDestinationObject(Arrays.asList(this.ipv6addr), true, - // false)); - // } + 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 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
+ * Used resources:
+ * - PCEPOpenObject1.bin
+ * + * @throws PCEPDeserializerException + * @throws IOException + * @throws PCEPDocumentedException + */ + @Test + @Ignore + // FIXME: temporary + public void testObjectDeserialization() throws PCEPDeserializerException, IOException, PCEPDocumentedException { + PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin")); + } + + @Test + public void testUnknownClass() throws PCEPDeserializerException, IOException, PCEPDocumentedException { + + final PCEPObject obj = PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPObject1UnknownClass.bin")).get( + 0); + + assertTrue(obj instanceof UnknownObject); + assertEquals(((UnknownObject) obj).getError(), PCEPErrors.UNRECOGNIZED_OBJ_CLASS); + } + + @Test + public void testUnknownType() throws PCEPDeserializerException, IOException, PCEPDocumentedException { + final PCEPObject obj = PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPObject2UnknownType.bin")).get(0); + + assertTrue(obj instanceof UnknownObject); + 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 testLspObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException { + serDeserTest("src/test/resources/PCEPLspObject1NoTlvsUpperBounds.bin", new PCEPLspObject(0xFFFFF, true, false, true, false, null)); + } + + @Test + public void testERObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException { + final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin"); + + final PCEPExplicitRouteObject specObj = (PCEPExplicitRouteObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0); + + assertEquals(8, specObj.getSubobjects().size()); + + final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj)); + assertArrayEquals(bytesFromFile, bytesActual); + } + + @Test + public void testIRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException { + final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PCEPIncludeRouteObject1PackOfSubobjects.bin"); + + final PCEPIncludeRouteObject specObj = (PCEPIncludeRouteObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0); + + assertEquals(8, specObj.getSubobjects().size()); + + final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj)); + assertArrayEquals(bytesFromFile, bytesActual); + } + + @Test + public void tesRRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException { + final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PCEPReportedRouteObject1PackOfSubobjects.bin"); + + final PCEPReportedRouteObject specObj = (PCEPReportedRouteObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0); + + assertEquals(6, specObj.getSubobjects().size()); + + final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj)); + assertArrayEquals(bytesFromFile, bytesActual); + } + + /** + * Test for upper/lower bounds (Serialization/Deserialization)
+ * Used resources:
+ * - PCEPBandwidthObject2UpperBounds.bin
+ * - PCEPBandwidthObject1LowerBounds.bin
+ * + * @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)
+ * Used resources:
+ * - PCEPEndPointsObject1IPv4.bin
+ * + * @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(new IPv4Address(srcIPBytes), new IPv4Address(destIPBytes))); + } + + /** + * Test for upper/lower bounds of IPv6 EndPoints (Serialization/Deserialization)
+ * Used resources:
+ * - PCEPEndPointsObject2IPv6.bin
+ * + * @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(new IPv6Address(srcIPBytes), new IPv6Address(destIPBytes))); + } + + /** + * Test of Serialization/Deserialization of PCEPErrorObjectParser.
+ *
+ * Used resources:
+ * - PCEPErrorObject1.bin
+ * - PCEPErrorObject3.bin
+ * + * @throws PCEPDeserializerException + * @throws IOException + * @throws PCEPDocumentedException + */ + @Test + public void testErrorObjectSerDeserWithTlv() throws PCEPDeserializerException, IOException, PCEPDocumentedException { + serDeserTest("src/test/resources/PCEPErrorObject1.bin", new PCEPErrorObject(PCEPErrors.NON_OR_INVALID_OPEN_MSG)); + serDeserTest("src/test/resources/PCEPErrorObject3.bin", new PCEPErrorObject(PCEPErrors.CAPABILITY_NOT_SUPPORTED)); + } + + /** + * Test of validity of PCEPErrorObjectParser. Expect throwed NoSuchElementException.
+ *
+ * Used resources:
+ * - PCEPErrorObject2Invalid.bin
+ * + * @throws NoSuchElementException + * @throws IOException + * @throws PCEPDocumentedException + */ + @Test(expected = PCEPDeserializerException.class) + public void testUnknownError() throws PCEPDeserializerException, IOException, PCEPDocumentedException { + PCEPObjectFactory.parseObjects(ByteArray.fileToBytes("src/test/resources/PCEPErrorObject2Invalid.bin")).get(0); + } + + /** + * Test for upper/lower bounds of PCEPLspaObject (Serialization/Deserialization)
+ * Used resources:
+ * - PCEPLspaObject1LowerBounds.bin
+ * - PCEPLspaObject2UpperBounds.bin
+ * - PCEPLspaObject3RandVals.bin
+ * + * @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
+ * Used resources:
+ * - NoPathObject1WithTLV.bin
+ * - NoPathObject2WithoutTLV.bin
+ * + * @throws PCEPDeserializerException + * @throws IOException + * @throws PCEPDocumentedException + */ + @Test + public void testNoPathObjectDeserialization() throws PCEPDeserializerException, IOException, PCEPDocumentedException { + final List tlvs = new ArrayList(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
+ * Used resources:
+ * - NoPathObject1WithTLV.bin
+ * - NoPathObject2WithoutTLV.bin
+ * + * @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)); + assertArrayEquals(bytesFromFile, bytesActual); + + bytesFromFile = ByteArray.fileToBytes("src/test/resources/NoPathObject1WithTLV.bin"); + noPathObject = (PCEPNoPathObject) PCEPObjectFactory.parseObjects(bytesFromFile).get(0); + bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) noPathObject)); + assertArrayEquals(bytesFromFile, bytesActual); + } + + /** + * Specific test with/without tlvs (Ser/Deser)
+ * Used resources:
+ * - PCEPNotificationObject1WithTlv.bin - PCEPNotificationObject2WithoutTlv.bin + * + * @throws PCEPDeserializerException + * @throws IOException + * @throws PCEPDocumentedException + */ + @Test + public void testNotifyObjectSerDeserWithTlv() throws PCEPDeserializerException, IOException, PCEPDocumentedException { + final List tlvs = new ArrayList(1); + tlvs.add(new OverloadedDurationTlv(0xFF0000A2)); + serDeserTest("src/test/resources/PCEPNotificationObject1WithTlv.bin", new PCEPNotificationObject((short) 1, (short) 1, tlvs)); + serDeserTest("src/test/resources/PCEPNotificationObject2WithoutTlv.bin", new PCEPNotificationObject((short) 0xFF, (short) 0xFF)); + } + + /** + * Standard ser deser test
+ * used resources:
+ * - PCEPOpenObject1.bin + * + * @throws PCEPDeserializerException + * @throws IOException + * @throws PCEPDocumentedException + */ + @Test + @Ignore + // FIXME: temporary + public void testOpenObjectSerDeser() throws PCEPDeserializerException, IOException, PCEPDocumentedException { + final List tlvs = new ArrayList(); + tlvs.add(new PCEStatefulCapabilityTlv(false, true, true)); + tlvs.add(new LSPStateDBVersionTlv(0x80)); + final byte[] valueBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0 }; + tlvs.add(new NodeIdentifierTlv(valueBytes)); + final PCEPOpenObject specObject = new PCEPOpenObject(30, 120, 1, tlvs); + + serDeserTest("src/test/resources/PCEPOpenObject1.bin", specObject); + } + + /** + * Specific test for upper bounds and without tlvs
+ * Used resources:
+ * - PCEPOpenObject2UpperBoundsNoTlv.bin + * + * @throws PCEPDeserializerException + * @throws IOException + * @throws PCEPDocumentedException + */ + @Test + public void testOpenObjectBoundsWithoutTlvs() throws IOException, PCEPDeserializerException, PCEPDocumentedException { + final List tlvs = new ArrayList(); + serDeserTest("src/test/resources/PCEPOpenObject2UpperBoundsNoTlv.bin", new PCEPOpenObject(0xFF, 0xFF, 0xFF, tlvs)); + serDeserTest("src/test/resources/PCEPOpenObject2UpperBoundsNoTlv.bin", new PCEPOpenObject(0xFF, 0xFF, 0xFF, null)); + } + + /** + * Standard deserialization test
+ * Used resources:
+ * - PCEPRPObject1.bin + * + * @throws PCEPDeserializerException + * @throws IOException + * @throws PCEPDocumentedException + */ + @Test + public void testRPObjectSerDeser() throws PCEPDeserializerException, IOException, PCEPDocumentedException { + serDeserTest("src/test/resources/PCEPRPObject1.bin", + new PCEPRequestParameterObject(true, false, true, true, false, false, false, false, (short) 5, 0xdeadbeefL, false, false)); + serDeserTest( + "src/test/resources/PCEPRPObject2.bin", + new PCEPRequestParameterObject(true, false, false, false, true, false, true, false, true, (short) 5, 0xdeadbeefL, new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new OrderTlv(0xFFFFFFFFL, 0x00000001L)); + } + }, false, false)); + } + + /** + * Test for upper/lower bounds of PCEPSvecObject (Serialization/Deserialization)
+ * Used resources:
+ * - PCEPSvecObject1_10ReqIDs.bin
+ * + * @throws IOException + * @throws PCEPDeserializerException + * @throws PCEPDocumentedException + */ + @Test + public void testSvecObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException { + final List requestIDs = new ArrayList(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)
+ * Used resources:
+ * - PCEPSvecObject2.bin
+ * + * @throws IOException + * @throws PCEPDeserializerException + * @throws PCEPDocumentedException + */ + @Test + public void testSvecObjectSerDeserNoReqIDs() throws IOException, PCEPDeserializerException, PCEPDocumentedException { + final List requestIDs = new ArrayList(); + 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 PCEPExcludeRouteObjectObject (Serialization/Deserialization)
+ * Used resources:
+ * - PCEPExcludeRouteObject.1.bin
+ * + * @throws IOException + * @throws PCEPDeserializerException + * @throws PCEPDocumentedException + */ + @Test + public void testExcludeRouteObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException { + final List xroSubobjects = new ArrayList(); + xroSubobjects.add(new XROIPPrefixSubobject(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 192, (byte) 168, + (byte) 100, (byte) 100 }), 16), true, XROSubobjectAttribute.NODE)); + xroSubobjects.add(new XROAsNumberSubobject(new AsNumber(0x1234L), false)); + + } + + @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)); + } + + // FIXME: add at least one test with true value + @Test + public void openObjectWithTlv() throws PCEPDeserializerException, PCEPDocumentedException { + this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, false, false)); + this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, false, true)); + this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, true, false)); + this.testOpenObjectWithSpecTlv(new PCEStatefulCapabilityTlv(false, true, true)); + } + + private void testOpenObjectWithSpecTlv(final PCEPTlv tlv) throws PCEPDeserializerException, PCEPDocumentedException { + final List objs = new ArrayList(); + final List tlvs = new ArrayList(); + tlvs.add(tlv); + final PCEPOpenObject oo = new PCEPOpenObject(30, 120, 0, tlvs); + objs.add(oo); + final byte[] bytes = PCEPObjectFactory.put(objs); + final PCEPObject obj = PCEPObjectFactory.parseObjects(bytes).get(0); + assertEquals(oo, obj); + } + + @Test + public void testErrorsMapping() { + final PCEPErrorObjectParser.PCEPErrorsMaping mapper = PCEPErrorObjectParser.PCEPErrorsMaping.getInstance(); + + for (final PCEPErrors error : PCEPErrors.values()) { + final PCEPErrorIdentifier errorId = mapper.getFromErrorsEnum(error); + assertEquals(error, mapper.getFromErrorIdentifier(errorId)); + } + } + + @Test + public void testOFCodesMapping() { + final PCEPOFCodesMapping mapper = PCEPOFCodesMapping.getInstance(); + + for (final PCEPOFCodes ofCode : PCEPOFCodes.values()) { + final int ofCodeId = mapper.getFromOFCodesEnum(ofCode); + assertEquals(ofCode, mapper.getFromCodeIdentifier(ofCodeId)); + } + } + + @SuppressWarnings("unchecked") + private static void serDeserTestWithoutBin(final T object) throws PCEPDeserializerException, + PCEPDocumentedException { + final byte[] serBytes = PCEPObjectFactory.put(Arrays.asList((PCEPObject) object)); + final T deserObj = (T) PCEPObjectFactory.parseObjects(serBytes).get(0); + + assertEquals(object, deserObj); + } + + /* + * tests without the need of binary files + */ + @Test + public void testBranchNodeObjects() throws PCEPDocumentedException, PCEPDeserializerException { + final List eroSubobjects = new ArrayList(); + eroSubobjects.add(new EROIPPrefixSubobject(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 192, (byte) 168, 1, 8 }), 16), false)); + eroSubobjects.add(new EROIPPrefixSubobject(new IPv6Prefix(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 }), 64), false)); + + serDeserTestWithoutBin(new PCEPBranchNodeListObject(eroSubobjects, true, false)); + serDeserTestWithoutBin(new PCEPNonBranchNodeListObject(eroSubobjects, true, false)); + + } + + @Test + public void testSERObjects() throws PCEPDocumentedException, PCEPDeserializerException { + final List eroSubobjects = new ArrayList(); + eroSubobjects.add(new EROIPPrefixSubobject(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 192, (byte) 168, 1, 8 }), 16), false)); + eroSubobjects.add(new EROIPPrefixSubobject(new IPv6Prefix(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 }), 64), false)); + + serDeserTestWithoutBin(new PCEPSecondaryExplicitRouteObject(eroSubobjects, true, false)); + } + + @Test + public void testSRRObject() throws PCEPDocumentedException, PCEPDeserializerException { + final List rroSubobjects = new ArrayList(); + rroSubobjects.add(new RROIPAddressSubobject(new IPv4Prefix(this.ipv4addr, 16), true, false)); + rroSubobjects.add(new RROIPAddressSubobject(new IPv6Prefix(this.ipv6addr, 64), false, true)); + + serDeserTestWithoutBin(new PCEPSecondaryRecordRouteObject(rroSubobjects, true, false)); + } + + @Test + public void testP2MPEndpointsObjects() throws PCEPDeserializerException, PCEPDocumentedException { + serDeserTestWithoutBin(new PCEPP2MPEndPointsObject(2, this.ipv4addr, Arrays.asList(this.ipv4addr, this.ipv4addr, + this.ipv4addr), true, false)); + serDeserTestWithoutBin(new PCEPP2MPEndPointsObject(1, this.ipv4addr, Arrays.asList(this.ipv4addr), true, false)); + serDeserTestWithoutBin(new PCEPP2MPEndPointsObject(2, this.ipv6addr, Arrays.asList(this.ipv6addr, this.ipv6addr, + this.ipv6addr), true, false)); + serDeserTestWithoutBin(new PCEPP2MPEndPointsObject(1, this.ipv6addr, Arrays.asList(this.ipv6addr), true, false)); + } + + @Test + public void testUnreachedDestinationObjects() throws PCEPDeserializerException, PCEPDocumentedException { + serDeserTestWithoutBin(new PCEPUnreachedDestinationObject(Arrays.asList(this.ipv4addr, this.ipv4addr, this.ipv4addr), true, false)); + serDeserTestWithoutBin(new PCEPUnreachedDestinationObject(Arrays.asList(this.ipv4addr), true, false)); + serDeserTestWithoutBin(new PCEPUnreachedDestinationObject(Arrays.asList(this.ipv6addr, this.ipv6addr, this.ipv6addr), true, false)); + serDeserTestWithoutBin(new PCEPUnreachedDestinationObject(Arrays.asList(this.ipv6addr), true, false)); + } } 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 index 0a89b438b9..280a7e6896 100644 --- 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 @@ -7,6 +7,7 @@ */ package org.opendaylight.protocol.pcep.impl; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -22,16 +23,21 @@ import org.opendaylight.protocol.concepts.IPv6Address; import org.opendaylight.protocol.concepts.IPv6Prefix; import org.opendaylight.protocol.concepts.SharedRiskLinkGroup; import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.concepts.UnnumberedInterfaceIdentifier; import org.opendaylight.protocol.pcep.impl.subobject.EROAsNumberSubobjectParser; -import org.opendaylight.protocol.pcep.impl.subobject.EROIpPrefixSubobjectParser; +import org.opendaylight.protocol.pcep.impl.subobject.EROIPv4PrefixSubobjectParser; +import org.opendaylight.protocol.pcep.impl.subobject.EROIPv6PrefixSubobjectParser; import org.opendaylight.protocol.pcep.impl.subobject.EROUnnumberedInterfaceSubobjectParser; +import org.opendaylight.protocol.pcep.subobject.EROAsNumberSubobject; import org.opendaylight.protocol.pcep.subobject.EROExplicitExclusionRouteSubobject; import org.opendaylight.protocol.pcep.subobject.EROGeneralizedLabelSubobject; +import org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject; import org.opendaylight.protocol.pcep.subobject.EROPathKeyWith128PCEIDSubobject; import org.opendaylight.protocol.pcep.subobject.EROPathKeyWith32PCEIDSubobject; import org.opendaylight.protocol.pcep.subobject.EROProtectionType1Subobject; import org.opendaylight.protocol.pcep.subobject.EROProtectionType2Subobject; import org.opendaylight.protocol.pcep.subobject.EROType1LabelSubobject; +import org.opendaylight.protocol.pcep.subobject.EROUnnumberedInterfaceSubobject; import org.opendaylight.protocol.pcep.subobject.EROWavebandSwitchingLabelSubobject; import org.opendaylight.protocol.pcep.subobject.ExcludeRouteSubobject; import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; @@ -49,10 +55,9 @@ import org.opendaylight.protocol.pcep.subobject.XROAsNumberSubobject; import org.opendaylight.protocol.pcep.subobject.XROIPPrefixSubobject; import org.opendaylight.protocol.pcep.subobject.XROSRLGSubobject; import org.opendaylight.protocol.pcep.subobject.XROSubobjectAttribute; +import org.opendaylight.protocol.pcep.subobject.XROUnnumberedInterfaceSubobject; 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.rsvp.rev130820.CSubobject; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.route.subobjects.subobject.type.AsNumberBuilder; /** * Tests for subobjects @@ -66,42 +71,30 @@ public class PCEPSubobjectParserTest { 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 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(new IPv4Prefix(new - // IPv4Address(this.ipv4bytes1), 0x20), true)); - // - // assertEquals(objsToTest.get(3), new EROIPPrefixSubobject(new IPv4Prefix(new - // IPv4Address(this.ipv4bytes2), 0x15), false)); - // assertEquals(objsToTest.get(4), new EROIPPrefixSubobject(new IPv6Prefix(new - // IPv6Address(this.ipv6bytes1), 0x80), true)); - // - // assertEquals(objsToTest.get(5), new EROIPPrefixSubobject(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)); + final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PackOfSubobjects.bin"); + final List objsToTest = PCEPEROSubobjectParser.parse(bytesFromFile); + + assertEquals(8, objsToTest.size()); + + assertEquals(objsToTest.get(0), new EROAsNumberSubobject(new AsNumber(0xFFFFL), true)); + assertEquals(objsToTest.get(1), new EROAsNumberSubobject(new AsNumber(0x0010L), false)); + assertEquals(objsToTest.get(2), new EROIPPrefixSubobject(new IPv4Prefix(new IPv4Address(this.ipv4bytes1), 0x20), true)); + + assertEquals(objsToTest.get(3), new EROIPPrefixSubobject(new IPv4Prefix(new IPv4Address(this.ipv4bytes2), 0x15), false)); + assertEquals(objsToTest.get(4), new EROIPPrefixSubobject(new IPv6Prefix(new IPv6Address(this.ipv6bytes1), 0x80), true)); + + assertEquals(objsToTest.get(5), new EROIPPrefixSubobject(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)); } @@ -151,37 +144,41 @@ public class PCEPSubobjectParserTest { objsToTest.add(new XROIPPrefixSubobject(new IPv6Prefix(new IPv6Address(this.ipv6bytes2), 0x16), true, XROSubobjectAttribute.INTERFACE)); objsToTest.add(new XROIPPrefixSubobject(new IPv4Prefix(new IPv4Address(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 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 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 { + EROIPv4PrefixSubobjectParser.parse(bytes, true); + fail(""); + } catch (final PCEPDeserializerException e) { + } + + try { + EROIPv6PrefixSubobjectParser.parse(bytes, true); + fail(""); + } catch (final PCEPDeserializerException e) { + } + } @Test public void testNullExceptions() throws PCEPDeserializerException { @@ -189,7 +186,7 @@ public class PCEPSubobjectParserTest { // subobjects try { - new EROAsNumberSubobjectParser().parseSubobject(bytes); + EROAsNumberSubobjectParser.parse(bytes, true); fail(""); } catch (final IllegalArgumentException e) { } @@ -201,7 +198,13 @@ public class PCEPSubobjectParserTest { } try { - new EROIpPrefixSubobjectParser().parseSubobject(bytes); + EROIPv4PrefixSubobjectParser.parse(bytes, true); + fail(""); + } catch (final IllegalArgumentException e) { + } + + try { + EROIPv6PrefixSubobjectParser.parse(bytes, true); fail(""); } catch (final IllegalArgumentException e) { } @@ -213,11 +216,11 @@ public class PCEPSubobjectParserTest { final ExplicitRouteSubobject instance = new ExplicitRouteSubobject() { }; - // try { - // new EROAsNumberSubobjectParser().serializeSubobject(instance); - // fail(""); - // } catch (final IllegalArgumentException e) { - // } + try { + EROAsNumberSubobjectParser.put(instance); + fail(""); + } catch (final IllegalArgumentException e) { + } try { EROUnnumberedInterfaceSubobjectParser.put(instance); @@ -225,36 +228,63 @@ public class PCEPSubobjectParserTest { } 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(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(new IPv4Prefix(new - // IPv4Address(ipv4addr), 1), false)); - // fail(""); - // } catch (final IllegalArgumentException e) { - // } + try { + EROIPv4PrefixSubobjectParser.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 }; + EROIPv4PrefixSubobjectParser.put(new EROIPPrefixSubobject(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(new IPv4Prefix(new IPv4Address(ipv4addr), 1), false)); + fail(""); + } catch (final IllegalArgumentException e) { + } + + } + + @Test + public void testEmptyExceptions() throws PCEPDeserializerException { + final byte[] bytes = {}; // not empty but not enought data for parsing + // subobjects + + try { + EROAsNumberSubobjectParser.parse(bytes, true); + fail(""); + } catch (final IllegalArgumentException e) { + } + + try { + EROUnnumberedInterfaceSubobjectParser.parse(bytes, true); + fail(""); + } catch (final IllegalArgumentException e) { + } + try { + EROIPv4PrefixSubobjectParser.parse(bytes, true); + fail(""); + } catch (final IllegalArgumentException e) { + } + + try { + EROIPv6PrefixSubobjectParser.parse(bytes, true); + fail(""); + } catch (final IllegalArgumentException e) { + } } + } diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParserTest.java index 021b8891f8..20347cd382 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParserTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParserTest.java @@ -7,188 +7,222 @@ */ package org.opendaylight.protocol.pcep.impl; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.concepts.IPv6Address; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPOFCodes; +import org.opendaylight.protocol.pcep.PCEPTlv; +import org.opendaylight.protocol.pcep.concepts.IPv4ExtendedTunnelIdentifier; +import org.opendaylight.protocol.pcep.concepts.IPv6ExtendedTunnelIdentifier; +import org.opendaylight.protocol.pcep.concepts.LSPIdentifier; +import org.opendaylight.protocol.pcep.concepts.LSPSymbolicName; +import org.opendaylight.protocol.pcep.concepts.TunnelIdentifier; +import org.opendaylight.protocol.pcep.impl.tlv.LSPIdentifierIPv4TlvParser; +import org.opendaylight.protocol.pcep.impl.tlv.LSPIdentifierIPv6TlvParser; +import org.opendaylight.protocol.pcep.impl.tlv.OFListTlvParser; +import org.opendaylight.protocol.pcep.impl.tlv.PCEStatefulCapabilityTlvParser; +import org.opendaylight.protocol.pcep.impl.tlv.RSVPErrorSpecIPv4TlvParser; +import org.opendaylight.protocol.pcep.impl.tlv.RSVPErrorSpecIPv6TlvParser; +import org.opendaylight.protocol.pcep.tlv.IPv4LSPIdentifiersTlv; +import org.opendaylight.protocol.pcep.tlv.IPv6LSPIdentifiersTlv; +import org.opendaylight.protocol.pcep.tlv.LSPStateDBVersionTlv; +import org.opendaylight.protocol.pcep.tlv.LSPSymbolicNameTlv; +import org.opendaylight.protocol.pcep.tlv.LSPUpdateErrorTlv; +import org.opendaylight.protocol.pcep.tlv.NoPathVectorTlv; +import org.opendaylight.protocol.pcep.tlv.NodeIdentifierTlv; +import org.opendaylight.protocol.pcep.tlv.OFListTlv; +import org.opendaylight.protocol.pcep.tlv.OrderTlv; +import org.opendaylight.protocol.pcep.tlv.OverloadedDurationTlv; +import org.opendaylight.protocol.pcep.tlv.P2MPCapabilityTlv; +import org.opendaylight.protocol.pcep.tlv.PCEStatefulCapabilityTlv; +import org.opendaylight.protocol.pcep.tlv.RSVPErrorSpecTlv; +import org.opendaylight.protocol.pcep.tlv.ReqMissingTlv; /** * 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 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(new IPv4Address(ipv4Address), false, true, - // 0x92, 0x1602)); - // assertEquals(tlvsToTest.get(11), new RSVPErrorSpecTlv(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() { - // 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) { - // } - // } + @Test + public void testDeserialization() throws PCEPDeserializerException, IOException { + final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PackOfTlvs.bin"); + final List tlvsToTest = PCEPTlvParser.parse(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(new IPv4Address(ipv4Address), false, true, 0x92, 0x1602)); + assertEquals(tlvsToTest.get(11), new RSVPErrorSpecTlv(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() { + 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 { + RSVPErrorSpecIPv4TlvParser.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 { + RSVPErrorSpecIPv4TlvParser.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 { + RSVPErrorSpecIPv4TlvParser.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) { + } + } } diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java index ae8ed9cd7c..1dad2fce44 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPValidatorTest.java @@ -7,788 +7,757 @@ */ package org.opendaylight.protocol.pcep.impl; +import static java.util.Arrays.asList; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.opendaylight.protocol.concepts.IGPMetric; +import org.opendaylight.protocol.concepts.IPv4; +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.concepts.TEMetric; +import org.opendaylight.protocol.framework.DeserializerException; +import org.opendaylight.protocol.framework.DocumentedException; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import org.opendaylight.protocol.pcep.PCEPErrors; +import org.opendaylight.protocol.pcep.PCEPOFCodes; +import org.opendaylight.protocol.pcep.PCEPObject; +import org.opendaylight.protocol.pcep.PCEPTlv; +import org.opendaylight.protocol.pcep.concepts.LSPSymbolicName; +import org.opendaylight.protocol.pcep.concepts.UnnumberedInterfaceIdentifier; +import org.opendaylight.protocol.pcep.impl.object.UnknownObject; +import org.opendaylight.protocol.pcep.message.PCCreateMessage; +import org.opendaylight.protocol.pcep.message.PCEPCloseMessage; +import org.opendaylight.protocol.pcep.message.PCEPErrorMessage; +import org.opendaylight.protocol.pcep.message.PCEPNotificationMessage; +import org.opendaylight.protocol.pcep.message.PCEPOpenMessage; +import org.opendaylight.protocol.pcep.message.PCEPReplyMessage; +import org.opendaylight.protocol.pcep.message.PCEPReportMessage; +import org.opendaylight.protocol.pcep.message.PCEPRequestMessage; +import org.opendaylight.protocol.pcep.message.PCEPUpdateRequestMessage; +import org.opendaylight.protocol.pcep.object.CompositeErrorObject; +import org.opendaylight.protocol.pcep.object.CompositeInstantiationObject; +import org.opendaylight.protocol.pcep.object.CompositeNotifyObject; +import org.opendaylight.protocol.pcep.object.CompositePathObject; +import org.opendaylight.protocol.pcep.object.CompositeReplySvecObject; +import org.opendaylight.protocol.pcep.object.CompositeRequestObject; +import org.opendaylight.protocol.pcep.object.CompositeRequestSvecObject; +import org.opendaylight.protocol.pcep.object.CompositeResponseObject; +import org.opendaylight.protocol.pcep.object.CompositeRptPathObject; +import org.opendaylight.protocol.pcep.object.CompositeStateReportObject; +import org.opendaylight.protocol.pcep.object.CompositeUpdPathObject; +import org.opendaylight.protocol.pcep.object.CompositeUpdateRequestObject; +import org.opendaylight.protocol.pcep.object.PCEPCloseObject; +import org.opendaylight.protocol.pcep.object.PCEPCloseObject.Reason; +import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject; +import org.opendaylight.protocol.pcep.object.PCEPErrorObject; +import org.opendaylight.protocol.pcep.object.PCEPExcludeRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPExistingPathBandwidthObject; +import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPGlobalConstraintsObject; +import org.opendaylight.protocol.pcep.object.PCEPIncludeRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPLoadBalancingObject; +import org.opendaylight.protocol.pcep.object.PCEPLspObject; +import org.opendaylight.protocol.pcep.object.PCEPLspaObject; +import org.opendaylight.protocol.pcep.object.PCEPMetricObject; +import org.opendaylight.protocol.pcep.object.PCEPNoPathObject; +import org.opendaylight.protocol.pcep.object.PCEPNotificationObject; +import org.opendaylight.protocol.pcep.object.PCEPObjectiveFunctionObject; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; +import org.opendaylight.protocol.pcep.object.PCEPReportedRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject; +import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject; +import org.opendaylight.protocol.pcep.object.PCEPSvecObject; +import org.opendaylight.protocol.pcep.spi.PCEPMessageType; +import org.opendaylight.protocol.pcep.spi.RawMessage; +import org.opendaylight.protocol.pcep.subobject.EROAsNumberSubobject; +import org.opendaylight.protocol.pcep.subobject.EROUnnumberedInterfaceSubobject; +import org.opendaylight.protocol.pcep.subobject.ExcludeRouteSubobject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; +import org.opendaylight.protocol.pcep.subobject.RROUnnumberedInterfaceSubobject; +import org.opendaylight.protocol.pcep.subobject.ReportedRouteSubobject; +import org.opendaylight.protocol.pcep.subobject.XROAsNumberSubobject; +import org.opendaylight.protocol.pcep.tlv.LSPStateDBVersionTlv; +import org.opendaylight.protocol.pcep.tlv.LSPSymbolicNameTlv; +import org.opendaylight.protocol.pcep.tlv.PCEStatefulCapabilityTlv; +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.nps.concepts.rev130930.Bandwidth; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder; +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.keepalive.message.KeepaliveMessageBuilder; + +import com.google.common.collect.Lists; public class PCEPValidatorTest { - // private static final LspaObject lspa = new PCEPLspaObject(0L, 0L, 0L, (short) 0, (short) 0, false, false, false, - // false); - // - // private final List eroSubobjects = asList( - // new EROAsNumberSubobject(new AsNumber(0xFFFFL), false), - // new EROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { (byte) 0x00, (byte) 0x11, (byte) 0x22, (byte) - // 0x33 }), new UnnumberedInterfaceIdentifier(0x00FF00FF), false)); - // - // private final List rroSubobjects = asList((ReportedRouteSubobject) new - // RROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { - // (byte) 0x00, (byte) 0x11, (byte) 0x22, (byte) 0x33 }), new UnnumberedInterfaceIdentifier(0x00FF00FF))); - // - // private final List requestIds = asList(0x000001L); - // - // private final IPv4Address ip4addr = new IPv4Address(new byte[] { (byte) 0xFF, 0x00, 0x00, 0x01 }); - // - // private final PCEPSvecObject svecObj = new PCEPSvecObject(true, true, true, false, false, - // PCEPValidatorTest.this.requestIds, true); - // - // private final PCEPRequestParameterObject requestParameter = new PCEPRequestParameterObject(true, false, false, - // false, false, false, false, false, (short) 3, 1, true, false); - // - // // private final PCEPEndPointsObject endPoints = new - // // PCEPEndPointsObject(this.ip4addr, this.ip4addr); - // - // private final PCEPEndPointsObject endPoints = new PCEPEndPointsObject(this.ip4addr, - // this.ip4addr); - // - // private static final RawPCEPMessageFactory msgFactory = new RawPCEPMessageFactory(); - // - // // private final PCEPClassTypeObject classType = new - // // PCEPClassTypeObject((short) 7); - // // private final PCEPClassTypeObjectProvider classTypeProvider = new - // // PCEPClassTypeObjectProvider((short) 7, true); - // - // private static List deserMsg(final String srcFile) throws IOException, DeserializerException, - // DocumentedException, - // PCEPDeserializerException { - // final byte[] bytesFromFile = ByteArray.fileToBytes(srcFile); - // final RawMessage rawMessage = (RawMessage) msgFactory.parse(bytesFromFile).get(0); - // - // return PCEPMessageValidator.getValidator(rawMessage.getMsgType()).validate(rawMessage.getAllObjects()); - // } - // - // @Test - // public void testOpenMessageValidationFromBin() throws IOException, DeserializerException, DocumentedException, - // PCEPDeserializerException { - // assertEquals( - // deserMsg("src/test/resources/PCEPOpenMessage1.bin").toString(), - // asList( - // new PCEPOpenMessage(new PCEPOpenObject(30, 120, 1, asList(new PCEStatefulCapabilityTlv(false, true, true), - // new LSPStateDBVersionTlv(0x80))))).toString()); - // - // assertEquals(deserMsg("src/test/resources/Open.1.bin").toString(), - // asList(new PCEPOpenMessage(new PCEPOpenObject(1, 4, 1))).toString()); - // - // assertEquals( - // deserMsg("src/test/resources/Open.3.bin").toString(), - // asList( - // new PCEPOpenMessage(new PCEPOpenObject(1, 4, 1, asList(new PCEStatefulCapabilityTlv(false, true, true), - // new LSPStateDBVersionTlv(53))))).toString()); - // } - // - // @Test - // public void testKeepAliveMessageValidationFromBin() throws IOException, PCEPDeserializerException, - // PCEPDocumentedException, - // DeserializerException, DocumentedException { - // assertEquals(deserMsg("src/test/resources/PCEPKeepAliveMessage1.bin").toString(), - // asList(new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build()).toString()); - // assertEquals(deserMsg("src/test/resources/Keepalive.1.bin").toString(), - // asList(new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build()).toString()); - // } - // - // @Test - // @Ignore - // // FIXME: should be fixed when we remove PCEPObject - // public void testCloseMsg() throws PCEPDeserializerException, IOException, PCEPDocumentedException, - // DeserializerException, - // DocumentedException { - // assertEquals( - // deserMsg("src/test/resources/PCEPCloseMessage1.bin"), - // asList(new CloseBuilder().setCCloseMessage( - // new CCloseMessageBuilder().setCClose( - // new CCloseBuilder().setReason(TerminationReason.TooManyUnknownMsg.getShortValue()).build()).build()).build())); - // assertEquals( - // deserMsg("src/test/resources/Close.1.bin").toString(), - // asList(new CloseBuilder().setCCloseMessage( - // new CCloseMessageBuilder().setCClose( - // new CCloseBuilder().setReason(TerminationReason.Unknown.getShortValue()).build()).build()).build())); - // } - // - // @Test - // public void testRequestMessageValidationFromBin() throws IOException, PCEPDeserializerException, - // PCEPDocumentedException, - // DeserializerException, DocumentedException { - // List requests = new ArrayList(); - // final byte[] ipAdress = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }; - // requests.add(new CompositeRequestObject(new PCEPRequestParameterObject(true, false, false, false, false, false, - // false, false, (short) 5, 0xDEADBEEFL, true, false), new PCEPEndPointsObject(new - // IPv4Address(ipAdress), new IPv4Address(ipAdress)))); - // PCEPRequestMessage specMessage = new PCEPRequestMessage(requests); - // List deserMsgs = deserMsg("src/test/resources/PCEPRequestMessage1.bin"); - // final List specMessages = Lists.newArrayList(); - // specMessages.add(specMessage); - // - // assertEquals(deserMsgs.toString(), specMessages.toString()); - // - // requests = new ArrayList(); - // final byte[] ipAdress2 = { (byte) 0x7F, (byte) 0x00, (byte) 0x00, (byte) 0x01 }; - // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject(new - // IPv4Address(ipAdress2), new IPv4Address(ipAdress2)))); - // specMessage = new PCEPRequestMessage(requests); - // deserMsgs = deserMsg("src/test/resources/PCReq.1.bin"); - // specMessages.clear(); - // specMessages.add(specMessage); - // assertEquals(deserMsgs.toString(), specMessages.toString()); - // - // requests = new ArrayList(); - // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject(new - // IPv4Address(ipAdress2), new IPv4Address(ipAdress2)), null, null, null, null, null, null, null, null, new - // PCEPLoadBalancingObject(3, new Bandwidth(ByteArray.floatToBytes((float) 1024.75)), false))); - // specMessage = new PCEPRequestMessage(requests); - // deserMsgs = deserMsg("src/test/resources/PCReq.2.bin"); - // specMessages.clear(); - // specMessages.add(specMessage); - // assertEquals(deserMsgs.toString(), specMessages.toString()); - // - // requests = new ArrayList(); - // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject(new - // IPv4Address(ipAdress2), new IPv4Address(ipAdress2)), null, new PCEPLspObject(1, false, false, true, false), - // PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(1000)), false, - // false), new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, true, new IGPMetric(53L), false, false)); - // } - // }, new PCEPReportedRouteObject(this.rroSubobjects, false), new PCEPExistingPathBandwidthObject(new - // Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPIncludeRouteObject(this.eroSubobjects, false, - // false), new PCEPLoadBalancingObject(5, new Bandwidth(ByteArray.floatToBytes(3)), false))); - // - // List svecList = new ArrayList(); - // svecList.add(new CompositeRequestSvecObject(new PCEPSvecObject(true, false, false, false, false, this.requestIds, - // false))); - // - // specMessage = new PCEPRequestMessage(svecList, requests); - // deserMsgs = deserMsg("src/test/resources/PCReq.3.bin"); - // specMessages.clear(); - // specMessages.add(specMessage); - // // FIXME BUG-89 - // // assertEquals(deserMsgs, specMessages); - // - // specMessages.clear(); - // requests = new ArrayList(); - // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject(new - // IPv4Address(ipAdress2), new IPv4Address(ipAdress2)), null, null, null, null, null, null, null, null, null)); - // specMessages.add(new PCEPRequestMessage(requests)); - // - // final byte[] ipAdress3 = { (byte) 0x7F, (byte) 0x00, (byte) 0x30, (byte) 0x01 }; - // requests = new ArrayList(); - // requests.add(new CompositeRequestObject(new PCEPRequestParameterObject(false, false, false, false, false, false, - // false, false, (short) 4, 1, true, false), new PCEPEndPointsObject(new IPv4Address(ipAdress3), new - // IPv4Address(ipAdress2)), null, null, null, null, null, null, null, null, null)); - // specMessages.add(new PCEPRequestMessage(requests)); - // - // final byte[] ipAdress4 = { (byte) 0x7F, (byte) 0x30, (byte) 0x00, (byte) 0x01 }; - // requests = new ArrayList(); - // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject(new - // IPv4Address(ipAdress2), new IPv4Address(ipAdress4)), null, null, null, null, null, null, null, null, null)); - // specMessages.add(new PCEPRequestMessage(requests)); - // - // final byte[] ipAdress5 = { (byte) 0x7F, (byte) 0xd0, (byte) 0x00, (byte) 0x01 }; - // requests = new ArrayList(); - // requests.add(new CompositeRequestObject(new PCEPRequestParameterObject(true, false, false, false, false, false, - // false, false, (short) 1, 1, true, false), new PCEPEndPointsObject(new IPv4Address(ipAdress5), new - // IPv4Address(ipAdress5)), null, null, null, null, null, null, null, null, null)); - // - // specMessages.add(new PCEPRequestMessage(requests)); - // deserMsgs = deserMsg("src/test/resources/PCReq.4.bin"); - // assertEquals(deserMsgs.toString(), specMessages.toString()); - // - // specMessages.clear(); - // svecList = new ArrayList(); - // svecList.add(new CompositeRequestSvecObject(new PCEPSvecObject(true, false, false, false, false, this.requestIds, - // false))); - // svecList.add(new CompositeRequestSvecObject(new PCEPSvecObject(false, true, true, false, false, this.requestIds, - // false), new PCEPObjectiveFunctionObject(PCEPOFCodes.MCC, true, false), new PCEPGlobalConstraintsObject((short) - // 0x55, (short) 1, (short) 100, (short) 0x26, true, false), new PCEPExcludeRouteObject(new - // ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new XROAsNumberSubobject(new AsNumber((long) 0x12), true)); - // } - // }, true, true, false), new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, true, new TEMetric(123456L), true, false)); - // } - // })); - // - // requests = new ArrayList(); - // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject(new - // IPv4Address(ipAdress2), new IPv4Address(ipAdress2)), null, null, PCEPValidatorTest.lspa, new - // PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(1000)), false, false), new - // ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, true, new IGPMetric(53L), false, false)); - // this.add(new PCEPMetricObject(true, true, new IGPMetric(5335L), false, false)); - // this.add(new PCEPMetricObject(true, true, new IGPMetric(128256), false, false)); - // } - // }, new PCEPReportedRouteObject(this.rroSubobjects, false), new PCEPExistingPathBandwidthObject(new - // Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPIncludeRouteObject(this.eroSubobjects, false, - // false), new PCEPLoadBalancingObject(5, new Bandwidth(ByteArray.floatToBytes(3)), false))); - // - // final byte[] ipAdress6 = { (byte) 0x7F, (byte) 0xF0, (byte) 0x00, (byte) 0x01 }; - // specMessages.add(new PCEPRequestMessage(svecList, requests)); - // - // requests = new ArrayList(); - // requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject(new - // IPv4Address(ipAdress6), new IPv4Address(ipAdress6)), null, null, PCEPValidatorTest.lspa, new - // PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(1000)), false, false), new - // ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, true, new IGPMetric(53L), false, false)); - // } - // }, new PCEPReportedRouteObject(this.rroSubobjects, false), new PCEPExistingPathBandwidthObject(new - // Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPIncludeRouteObject(this.eroSubobjects, false, - // false), new PCEPLoadBalancingObject(5, new Bandwidth(ByteArray.floatToBytes(3f)), false))); - // deserMsgs = deserMsg("src/test/resources/PCReq.5.bin"); - // specMessages.add(new PCEPRequestMessage(svecList, requests)); - // // FIXME - // // assertEquals(deserMsgs, specMessages); - // - // // FIXME: need construct with invalid processed parameter - // // assertEquals(deserMsg("src/test/resources/PCReq.6.invalid.bin"), - // // asList( - // // new PCEPErrorMessage(new CompositeErrorObject(new - // // PCEPRequestParameterObject(true, false, false, false, false, false, - // // false, false, (short) 3, - // // 1L, false, false), new PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))), - // // new PCEPRequestMessage(asList(new - // // CompositeRequestObject(this.requestParameter, new - // // PCEPEndPointsObject(IPv4Address - // // .getNetworkAddressFactory().getNetworkAddressForBytes(new byte[] { - // // 127, 0, 0, 1 }), IPv4Address.getNetworkAddressFactory() - // // .getNetworkAddressForBytes(new byte[] { 127, 0, 0, 1 })), null, null, - // // null, null, null, null, null, null, new PCEPLoadBalancingObject( - // // 3, new Bandwidth(1024.75), false)))))); - // - // } - // - // @Test - // public void testRequestMessageValidationFromRawMsg() throws PCEPDeserializerException { - // List objs = new ArrayList(); - // List msgs; - // PCEPRequestParameterObject tmpRP; - // - // // test unrecognized object in svec list - // objs.add(this.svecObj); - // objs.add(new UnknownObject(true, false, PCEPErrors.UNRECOGNIZED_OBJ_CLASS)); - // objs.add(new PCEPSvecObject(true, true, true, false, false, PCEPValidatorTest.this.requestIds, true)); - // - // msgs = PCEPMessageValidator.getValidator(PCEPMessageType.REQUEST).validate(objs); - // - // assertEquals(msgs.get(0).toString(), new PCEPErrorMessage(new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPErrorObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS)); - // } - // }).toString()); - // - // // test with request p flag not set and ignoracion of more than one - // // end-points objects - // objs = new ArrayList(); - // objs.add(this.svecObj); - // objs.add(this.svecObj); - // tmpRP = new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 3, 1, - // false, false); - // objs.add(tmpRP); - // objs.add(this.endPoints); - // - // objs.add(this.requestParameter); - // objs.add(this.endPoints); - // objs.add(this.endPoints); - // // FIXME:mv use object constructor with set processed flag - // // objs.add(this.classTypeProvider); - // // objs.add(this.requestParameter); - // // objs.add(this.endPointsProvider); - // // objs.add(new PCEPClassTypeObjectProvider((short) 7, false)); - // - // msgs = PCEPMessageValidator.getValidator(PCEPMessageType.REQUEST).validate(objs); - // // FIXME:mv use object constructor with set processed flag - // // assertEquals(msgs.get(0), new PCEPErrorMessage(new - // // CompositeErrorObject(tmpRP, new - // // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET)))); - // // assertEquals( - // // msgs.get(1), - // // new PCEPRequestMessage(asList(new - // // CompositeRequestSvecObject(this.svecObj), new - // // CompositeRequestSvecObject(this.svecObj)), Util - // // .asList(new CompositeRequestObject(this.requestParameter, - // // this.endPoints, this.classType, null, null, null, null, null, null, - // // null, - // // null)))); - // // assertEquals(msgs.get(2), new PCEPErrorMessage(new - // // CompositeErrorObject(tmpRP, new - // // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET)))); - // } - // - // @Test - // public void testReplyMessageValidatorFromBin() throws IOException, PCEPDeserializerException, - // PCEPDocumentedException, - // DeserializerException, DocumentedException { - // - // List specMessages = new ArrayList(); - // specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, - // false, false, false, false, false, false, false, (short) 5, 0xDEADBEEFL, true, true))))); - // specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, - // true, true, false, false, false, false, false, (short) 7, 0x12345678L, false, false))))); - // assertEquals(deserMsg("src/test/resources/PCEPReplyMessage1.bin").toString(), specMessages.toString()); - // - // specMessages = new ArrayList(); - // specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, - // false, false, false, false, false, false, false, (short) 3, 1, false, false))))); - // assertEquals(deserMsg("src/test/resources/PCRep.1.bin").toString(), specMessages.toString()); - // - // specMessages = new ArrayList(); - // specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, - // false, false, false, false, false, false, false, (short) 3, 1, false, false))))); - // specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(false, - // false, false, false, false, false, false, false, (short) 5, 2, false, false), new PCEPNoPathObject((short) 0, - // false, false), null, null, null, null, null, null)))); - // assertEquals(deserMsg("src/test/resources/PCRep.2.bin").toString(), specMessages.toString()); - // - // specMessages = new ArrayList(); - // specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, - // false, false, false, false, false, false, false, (short) 3, 1, false, false), new PCEPNoPathObject((short) 1, - // true, false), new PCEPLspObject(1, true, true, false, true), PCEPValidatorTest.lspa, new - // PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(500)), false, false), new - // ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, true, new IGPMetric(234), false, false)); - // } - // }, new PCEPIncludeRouteObject(this.eroSubobjects, false, false), new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new CompositePathObject(new PCEPExplicitRouteObject(PCEPValidatorTest.this.eroSubobjects, false), lspa, - // new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(500)), false, false), new - // ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, true, new IGPMetric(234L), false, false)); - // } - // }, new PCEPIncludeRouteObject(PCEPValidatorTest.this.eroSubobjects, false, false))); - // } - // })))); - // // FIXME BUG-89 - // // assertEquals(deserMsg("src/test/resources/PCRep.3.bin"), specMessages); - // - // specMessages = new ArrayList(); - // specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, - // false, false, false, false, false, false, false, (short) 7, 1, false, false))))); - // specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, - // false, false, false, false, false, false, false, (short) 1, 2, false, false))))); - // specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, - // false, false, false, false, false, false, false, (short) 2, 4, false, false))))); - // specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(false, - // false, false, false, false, false, false, false, (short) 3, 4, false, false))))); - // specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(false, - // false, false, false, false, false, false, false, (short) 6, 5, false, false))))); - // assertEquals(deserMsg("src/test/resources/PCRep.4.bin").toString(), specMessages.toString()); - // - // specMessages = new ArrayList(); - // final List requestIDs = new ArrayList(); - // requestIDs.add(0x25069045L); - // - // final List metrics = new ArrayList(); - // metrics.add(new PCEPMetricObject(true, true, new IGPMetric(234L), true, false)); - // - // final List svecList = new ArrayList(); - // svecList.add(new CompositeReplySvecObject(new PCEPSvecObject(true, true, true, false, false, requestIDs, true), - // new PCEPObjectiveFunctionObject(PCEPOFCodes.MCC, true, false), metrics)); - // - // specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, - // false, false, false, false, false, false, false, (short) 3, 1, false, false), new PCEPNoPathObject((short) 1, - // true, false), null, PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new - // Bandwidth(ByteArray.floatToBytes(500)), false, false), new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, true, new IGPMetric(234), false, false)); - // } - // }, new PCEPIncludeRouteObject(this.eroSubobjects, false, false), new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new CompositePathObject(new PCEPExplicitRouteObject(PCEPValidatorTest.this.eroSubobjects, false), lspa, - // new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(500)), false, false), new - // ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, true, new IGPMetric(234L), false, false)); - // this.add(new PCEPMetricObject(true, true, new IGPMetric(5355L), false, false)); - // this.add(new PCEPMetricObject(true, true, new IGPMetric(5353L), false, false)); - // } - // }, new PCEPIncludeRouteObject(PCEPValidatorTest.this.eroSubobjects, false, false))); - // } - // })), svecList)); - // specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, - // false, false, false, false, false, false, false, (short) 3, 1, false, false), new PCEPNoPathObject((short) 1, - // true, false), null, PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new - // Bandwidth(ByteArray.floatToBytes(500)), false, false), new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, true, new IGPMetric(234), false, false)); - // } - // }, new PCEPIncludeRouteObject(this.eroSubobjects, false, false), new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new CompositePathObject(new PCEPExplicitRouteObject(PCEPValidatorTest.this.eroSubobjects, false), lspa, - // new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(500)), false, false), new - // ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, true, new IGPMetric(234L), false, false)); - // } - // }, new PCEPIncludeRouteObject(PCEPValidatorTest.this.eroSubobjects, false, false))); - // this.add(new CompositePathObject(new PCEPExplicitRouteObject(PCEPValidatorTest.this.eroSubobjects, false), lspa, - // new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(500)), false, false), new - // ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, true, new IGPMetric(234L), false, false)); - // } - // }, new PCEPIncludeRouteObject(PCEPValidatorTest.this.eroSubobjects, false, false))); - // } - // })), svecList)); - // assertEquals(deserMsg("src/test/resources/PCRep.5.bin").toString(), specMessages.toString()); - // } - // - // @Test - // public void testUpdMessageValidatorFromBin() throws IOException, PCEPDeserializerException, - // PCEPDocumentedException, - // DeserializerException, DocumentedException { - // List specMessages = Lists.newArrayList(); - // - // List requests = new ArrayList(); - // requests.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, false, true, true))); - // - // specMessages.add(new PCEPUpdateRequestMessage(requests)); - // assertEquals(deserMsg("src/test/resources/PCUpd.1.bin").toString(), specMessages.toString()); - // - // specMessages = Lists.newArrayList(); - // List paths = new ArrayList(); - // paths.add(new CompositeUpdPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), - // PCEPValidatorTest.lspa, null, null)); - // requests = new ArrayList(); - // requests.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, false, true, true), paths)); - // specMessages.add(new PCEPUpdateRequestMessage(requests)); - // assertEquals(deserMsg("src/test/resources/PCUpd.2.bin").toString(), specMessages.toString()); - // - // specMessages = Lists.newArrayList(); - // paths = new ArrayList(); - // paths.add(new CompositeUpdPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), - // PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, - // false), new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); - // } - // })); - // requests = new ArrayList(); - // requests.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, false, true, true), paths)); - // specMessages.add(new PCEPUpdateRequestMessage(requests)); - // assertEquals(deserMsg("src/test/resources/PCUpd.3.bin").toString(), specMessages.toString()); - // - // specMessages = Lists.newArrayList(); - // requests = new ArrayList(); - // requests.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, false, true, true))); - // requests.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, false, true, true))); - // specMessages.add(new PCEPUpdateRequestMessage(requests)); - // assertEquals(deserMsg("src/test/resources/PCUpd.4.bin").toString(), specMessages.toString()); - // - // specMessages = Lists.newArrayList(); - // requests = new ArrayList(); - // requests.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, false, true, true))); - // paths = new ArrayList(); - // paths.add(new CompositeUpdPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), - // PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, - // false), new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); - // } - // })); - // requests.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, false, true, true), paths)); - // paths = new ArrayList(); - // paths.add(new CompositeUpdPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), - // PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, - // false), new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); - // } - // })); - // paths.add(new CompositeUpdPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), - // PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, - // false), new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); - // } - // })); - // paths.add(new CompositeUpdPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), - // PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, - // false), new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); - // this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); - // } - // })); - // requests.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, false, true, true), paths)); - // specMessages.add(new PCEPUpdateRequestMessage(requests)); - // assertEquals(deserMsg("src/test/resources/PCUpd.5.bin").toString(), specMessages.toString()); - // } - // - // @Test - // public void testRptMessageValidatorFromBin() throws IOException, PCEPDeserializerException, - // PCEPDocumentedException, - // DeserializerException, DocumentedException { - // List specMessages = Lists.newArrayList(); - // List reports = new ArrayList(); - // reports.add(new CompositeStateReportObject(new PCEPLspObject(1, true, false, true, true))); - // specMessages.add(new PCEPReportMessage(reports)); - // assertEquals(deserMsg("src/test/resources/PCRpt.1.bin").toString(), specMessages.toString()); - // - // specMessages = Lists.newArrayList(); - // List paths = new ArrayList(); - // paths.add(new CompositeRptPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), - // PCEPValidatorTest.lspa, null, null, null)); - // reports = new ArrayList(); - // reports.add(new CompositeStateReportObject(new PCEPLspObject(1, true, false, true, true), paths)); - // specMessages.add(new PCEPReportMessage(reports)); - // assertEquals(deserMsg("src/test/resources/PCRpt.2.bin").toString(), specMessages.toString()); - // - // specMessages = Lists.newArrayList(); - // paths = new ArrayList(); - // paths.add(new CompositeRptPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), - // PCEPValidatorTest.lspa, new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, - // false), new PCEPReportedRouteObject(this.rroSubobjects, false), new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); - // } - // })); - // - // reports = new ArrayList(); - // reports.add(new CompositeStateReportObject(new PCEPLspObject(1, true, false, true, true), paths)); - // specMessages.add(new PCEPReportMessage(reports)); - // - // // FIXME - // // assertEquals(deserMsg("src/test/resources/PCRpt.3.bin"), specMessages); - // - // specMessages = Lists.newArrayList(); - // reports = new ArrayList(); - // reports.add(new CompositeStateReportObject(new PCEPLspObject(1, true, false, true, true))); - // reports.add(new CompositeStateReportObject(new PCEPLspObject(1, true, false, true, true))); - // reports.add(new CompositeStateReportObject(new PCEPLspObject(1, true, false, true, true))); - // specMessages.add(new PCEPReportMessage(reports)); - // assertEquals(deserMsg("src/test/resources/PCRpt.4.bin").toString(), specMessages.toString()); - // - // specMessages = Lists.newArrayList(); - // reports = new ArrayList(); - // paths = new ArrayList(); - // paths.add(new CompositeRptPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), - // PCEPValidatorTest.lspa, new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, - // false), new PCEPReportedRouteObject(this.rroSubobjects, false), new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); - // } - // })); - // reports.add(new CompositeStateReportObject(new PCEPLspObject(1, true, false, true, true), paths)); - // paths = new ArrayList(); - // paths.add(new CompositeRptPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), - // PCEPValidatorTest.lspa, new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, - // false), new PCEPReportedRouteObject(this.rroSubobjects, false), new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); - // this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); - // this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); - // } - // })); - // paths.add(new CompositeRptPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), - // PCEPValidatorTest.lspa, new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, - // false), new PCEPReportedRouteObject(this.rroSubobjects, false), new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); - // } - // })); - // reports.add(new CompositeStateReportObject(new PCEPLspObject(1, true, false, true, true), paths)); - // specMessages.add(new PCEPReportMessage(reports)); - // // FIXME - // // assertEquals(deserMsg("src/test/resources/PCRpt.5.bin").toString(), specMessages.toString()); - // } - // - // @Test - // public void testPCCreateMessage() throws DeserializerException, DocumentedException, PCEPDeserializerException { - // final List insts = new ArrayList(); - // final List subs = new ArrayList(); - // subs.add(new EROAsNumberSubobject(new AsNumber((long) 10), false)); - // final List tlvs = new ArrayList(); - // final LSPSymbolicNameTlv tlv = new LSPSymbolicNameTlv(new LSPSymbolicName(new byte[] { 5, 4 })); - // tlvs.add(tlv); - // insts.add(new CompositeInstantiationObject(new - // PCEPEndPointsObject(IPv4.FAMILY.addressForString("127.0.0.2"), - // IPv4.FAMILY.addressForString("127.0.0.1")), PCEPValidatorTest.lspa, new PCEPExplicitRouteObject(subs, true), - // null, new ArrayList() { - // private static final long serialVersionUID = 1L; - // - // { - // this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); - // this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); - // this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); - // } - // })); - // final PCCreateMessage msg = new PCCreateMessage(insts); - // - // final byte[] bytes = msgFactory.put(msg); - // - // // FIXME: need construct with invalid processed parameter - // final RawMessage rawMessage = (RawMessage) msgFactory.parse(bytes).get(0); - // - // assertEquals(PCEPMessageValidator.getValidator(rawMessage.getMsgType()).validate(rawMessage.getAllObjects()).toString(), - // asList((Message) msg).toString()); - // } - // - // @Test - // public void testNotificationValidatorFromBin() throws IOException, PCEPDeserializerException, - // PCEPDocumentedException, - // DeserializerException, DocumentedException { - // List notifications = new ArrayList(); - // List notificationsList = new ArrayList(); - // notificationsList.add(new PCEPNotificationObject((short) 1, (short) 1)); - // notifications.add(new CompositeNotifyObject(notificationsList)); - // PCEPNotificationMessage specMessage = new PCEPNotificationMessage(notifications); - // assertEquals(deserMsg("src/test/resources/PCNtf.1.bin").toString(), asList((Message) specMessage).toString()); - // - // notifications = new ArrayList(); - // notificationsList = new ArrayList(); - // notificationsList.add(new PCEPNotificationObject((short) 1, (short) 1)); - // List requestsList = new ArrayList(); - // requestsList.add(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 3, - // 1, false, false)); - // notifications.add(new CompositeNotifyObject(requestsList, notificationsList)); - // specMessage = new PCEPNotificationMessage(notifications); - // assertEquals(deserMsg("src/test/resources/PCNtf.2.bin").toString(), asList((Message) specMessage).toString()); - // - // notifications = new ArrayList(); - // notificationsList = new ArrayList(); - // notificationsList.add(new PCEPNotificationObject((short) 1, (short) 1)); - // requestsList = new ArrayList(); - // requestsList.add(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 1, - // 10, false, false)); - // notifications.add(new CompositeNotifyObject(requestsList, notificationsList)); - // specMessage = new PCEPNotificationMessage(notifications); - // assertEquals(deserMsg("src/test/resources/PCNtf.3.bin").toString(), asList((Message) specMessage).toString()); - // - // notifications = new ArrayList(); - // notificationsList = new ArrayList(); - // notificationsList.add(new PCEPNotificationObject((short) 1, (short) 1)); - // notificationsList.add(new PCEPNotificationObject((short) 1, (short) 2)); - // notificationsList.add(new PCEPNotificationObject((short) 2, (short) 1)); - // notificationsList.add(new PCEPNotificationObject((short) 2, (short) 2)); - // notifications.add(new CompositeNotifyObject(notificationsList)); - // specMessage = new PCEPNotificationMessage(notifications); - // assertEquals(deserMsg("src/test/resources/PCNtf.4.bin").toString(), asList((Message) specMessage).toString()); - // - // notifications = new ArrayList(); - // notificationsList = new ArrayList(); - // notificationsList.add(new PCEPNotificationObject((short) 1, (short) 1)); - // requestsList = new ArrayList(); - // requestsList.add(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 1, - // 10, false, false)); - // notifications.add(new CompositeNotifyObject(requestsList, notificationsList)); - // notificationsList = new ArrayList(); - // notificationsList.add(new PCEPNotificationObject((short) 1, (short) 1)); - // notificationsList.add(new PCEPNotificationObject((short) 1, (short) 1)); - // requestsList = new ArrayList(); - // requestsList.add(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 1, - // 10, false, false)); - // requestsList.add(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 1, - // 10, false, false)); - // notifications.add(new CompositeNotifyObject(requestsList, notificationsList)); - // specMessage = new PCEPNotificationMessage(notifications); - // assertEquals(deserMsg("src/test/resources/PCNtf.5.bin").toString(), asList((Message) specMessage).toString()); - // } - // - // @Test - // public void testErrorMessageValidatoinFromBin() throws IOException, PCEPDeserializerException, - // PCEPDocumentedException, - // DeserializerException, DocumentedException { - // List errorsList = new ArrayList(); - // errorsList.add(new PCEPErrorObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS)); - // - // PCEPErrorMessage specMessage = new PCEPErrorMessage(errorsList); - // assertEquals(deserMsg("src/test/resources/PCErr.1.bin").toString(), asList((Message) specMessage).toString()); - // - // List requests = new ArrayList(); - // requests.add(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 3, 1, - // false, false)); - // - // List errors = new ArrayList(); - // errors.add(new CompositeErrorObject(requests, errorsList)); - // - // specMessage = new PCEPErrorMessage(errors); - // assertEquals(deserMsg("src/test/resources/PCErr.2.bin").toString(), asList((Message) specMessage).toString()); - // - // specMessage = new PCEPErrorMessage(new PCEPOpenObject(0, 0, 0), errorsList, null); - // assertEquals(deserMsg("src/test/resources/PCErr.3.bin").toString(), asList((Message) specMessage).toString()); - // - // requests = new ArrayList(); - // requests.add(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 1, 53, - // false, false)); - // - // errors = new ArrayList(); - // errors.add(new CompositeErrorObject(requests, errorsList)); - // - // specMessage = new PCEPErrorMessage(errors); - // assertEquals(deserMsg("src/test/resources/PCErr.3b.bin").toString(), asList((Message) specMessage).toString()); - // - // errorsList = new ArrayList(); - // errorsList.add(new PCEPErrorObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS)); - // errorsList.add(new PCEPErrorObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS)); - // errorsList.add(new PCEPErrorObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS)); - // - // specMessage = new PCEPErrorMessage(null, errorsList, null); - // assertEquals(deserMsg("src/test/resources/PCErr.4.bin").toString(), asList((Message) specMessage).toString()); - // - // requests = new ArrayList(); - // requests.add(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 1, 53, - // false, false)); - // - // errorsList = new ArrayList(); - // errorsList.add(new PCEPErrorObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS)); - // - // errors = new ArrayList(); - // errors.add(new CompositeErrorObject(requests, errorsList)); - // errors.add(new CompositeErrorObject(requests, errorsList)); - // - // specMessage = new PCEPErrorMessage(errors); - // assertEquals(deserMsg("src/test/resources/PCErr.5.bin").toString(), asList((Message) specMessage).toString()); - // } + private static final PCEPLspaObject lspa = new PCEPLspaObject(0L, 0L, 0L, (short) 0, (short) 0, false, false, false, false); + + private final List eroSubobjects = asList( + new EROAsNumberSubobject(new AsNumber(0xFFFFL), false), + new EROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { (byte) 0x00, (byte) 0x11, (byte) 0x22, (byte) 0x33 }), new UnnumberedInterfaceIdentifier(0x00FF00FF), false)); + + private final List rroSubobjects = asList((ReportedRouteSubobject) new RROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { + (byte) 0x00, (byte) 0x11, (byte) 0x22, (byte) 0x33 }), new UnnumberedInterfaceIdentifier(0x00FF00FF))); + + private final List requestIds = asList(0x000001L); + + private final IPv4Address ip4addr = new IPv4Address(new byte[] { (byte) 0xFF, 0x00, 0x00, 0x01 }); + + private final PCEPSvecObject svecObj = new PCEPSvecObject(true, true, true, false, false, PCEPValidatorTest.this.requestIds, true); + + private final PCEPRequestParameterObject requestParameter = new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 3, 1, true, false); + + // private final PCEPEndPointsObject endPoints = new + // PCEPEndPointsObject(this.ip4addr, this.ip4addr); + + private final PCEPEndPointsObject endPoints = new PCEPEndPointsObject(this.ip4addr, this.ip4addr); + + private static final RawPCEPMessageFactory msgFactory = new RawPCEPMessageFactory(); + + // private final PCEPClassTypeObject classType = new + // PCEPClassTypeObject((short) 7); + // private final PCEPClassTypeObjectProvider classTypeProvider = new + // PCEPClassTypeObjectProvider((short) 7, true); + + private static List deserMsg(final String srcFile) throws IOException, DeserializerException, DocumentedException, + PCEPDeserializerException { + final byte[] bytesFromFile = ByteArray.fileToBytes(srcFile); + final RawMessage rawMessage = (RawMessage) msgFactory.parse(bytesFromFile).get(0); + + return PCEPMessageValidator.getValidator(rawMessage.getMsgType()).validate(rawMessage.getAllObjects()); + } + + @Test + public void testOpenMessageValidationFromBin() throws IOException, DeserializerException, DocumentedException, + PCEPDeserializerException { + assertEquals( + deserMsg("src/test/resources/PCEPOpenMessage1.bin").toString(), + asList( + new PCEPOpenMessage(new PCEPOpenObject(30, 120, 1, asList(new PCEStatefulCapabilityTlv(false, true, true), + new LSPStateDBVersionTlv(0x80))))).toString()); + + assertEquals(deserMsg("src/test/resources/Open.1.bin").toString(), + asList(new PCEPOpenMessage(new PCEPOpenObject(1, 4, 1))).toString()); + + assertEquals( + deserMsg("src/test/resources/Open.3.bin").toString(), + asList( + new PCEPOpenMessage(new PCEPOpenObject(1, 4, 1, asList(new PCEStatefulCapabilityTlv(false, true, true), + new LSPStateDBVersionTlv(53))))).toString()); + } + + @Test + public void testKeepAliveMessageValidationFromBin() throws IOException, PCEPDeserializerException, PCEPDocumentedException, + DeserializerException, DocumentedException { + assertEquals(deserMsg("src/test/resources/PCEPKeepAliveMessage1.bin").toString(), + asList(new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build()).toString()); + assertEquals(deserMsg("src/test/resources/Keepalive.1.bin").toString(), + asList(new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build()).toString()); + } + + @Test + public void testCloseMsg() throws PCEPDeserializerException, IOException, PCEPDocumentedException, DeserializerException, + DocumentedException { + assertEquals(deserMsg("src/test/resources/PCEPCloseMessage1.bin").toString(), + asList(new PCEPCloseMessage(new PCEPCloseObject(Reason.TOO_MANY_UNKNOWN_MSG))).toString()); + assertEquals(deserMsg("src/test/resources/Close.1.bin").toString(), + asList(new PCEPCloseMessage(new PCEPCloseObject(Reason.UNKNOWN))).toString()); + } + + @Test + public void testRequestMessageValidationFromBin() throws IOException, PCEPDeserializerException, PCEPDocumentedException, + DeserializerException, DocumentedException { + List requests = new ArrayList(); + final byte[] ipAdress = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }; + requests.add(new CompositeRequestObject(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 5, 0xDEADBEEFL, true, false), new PCEPEndPointsObject(new IPv4Address(ipAdress), new IPv4Address(ipAdress)))); + PCEPRequestMessage specMessage = new PCEPRequestMessage(requests); + List deserMsgs = deserMsg("src/test/resources/PCEPRequestMessage1.bin"); + final List specMessages = Lists.newArrayList(); + specMessages.add(specMessage); + + assertEquals(deserMsgs.toString(), specMessages.toString()); + + requests = new ArrayList(); + final byte[] ipAdress2 = { (byte) 0x7F, (byte) 0x00, (byte) 0x00, (byte) 0x01 }; + requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject(new IPv4Address(ipAdress2), new IPv4Address(ipAdress2)))); + specMessage = new PCEPRequestMessage(requests); + deserMsgs = deserMsg("src/test/resources/PCReq.1.bin"); + specMessages.clear(); + specMessages.add(specMessage); + assertEquals(deserMsgs.toString(), specMessages.toString()); + + requests = new ArrayList(); + requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject(new IPv4Address(ipAdress2), new IPv4Address(ipAdress2)), null, null, null, null, null, null, null, null, new PCEPLoadBalancingObject(3, new Bandwidth(ByteArray.floatToBytes((float) 1024.75)), false))); + specMessage = new PCEPRequestMessage(requests); + deserMsgs = deserMsg("src/test/resources/PCReq.2.bin"); + specMessages.clear(); + specMessages.add(specMessage); + assertEquals(deserMsgs.toString(), specMessages.toString()); + + requests = new ArrayList(); + requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject(new IPv4Address(ipAdress2), new IPv4Address(ipAdress2)), null, new PCEPLspObject(1, false, false, true, false), PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(1000)), false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new IGPMetric(53L), false, false)); + } + }, new PCEPReportedRouteObject(this.rroSubobjects, false), new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPIncludeRouteObject(this.eroSubobjects, false, false), new PCEPLoadBalancingObject(5, new Bandwidth(ByteArray.floatToBytes(3)), false))); + + List svecList = new ArrayList(); + svecList.add(new CompositeRequestSvecObject(new PCEPSvecObject(true, false, false, false, false, this.requestIds, false))); + + specMessage = new PCEPRequestMessage(svecList, requests); + deserMsgs = deserMsg("src/test/resources/PCReq.3.bin"); + specMessages.clear(); + specMessages.add(specMessage); + // FIXME BUG-89 + // assertEquals(deserMsgs, specMessages); + + specMessages.clear(); + requests = new ArrayList(); + requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject(new IPv4Address(ipAdress2), new IPv4Address(ipAdress2)), null, null, null, null, null, null, null, null, null)); + specMessages.add(new PCEPRequestMessage(requests)); + + final byte[] ipAdress3 = { (byte) 0x7F, (byte) 0x00, (byte) 0x30, (byte) 0x01 }; + requests = new ArrayList(); + requests.add(new CompositeRequestObject(new PCEPRequestParameterObject(false, false, false, false, false, false, false, false, (short) 4, 1, true, false), new PCEPEndPointsObject(new IPv4Address(ipAdress3), new IPv4Address(ipAdress2)), null, null, null, null, null, null, null, null, null)); + specMessages.add(new PCEPRequestMessage(requests)); + + final byte[] ipAdress4 = { (byte) 0x7F, (byte) 0x30, (byte) 0x00, (byte) 0x01 }; + requests = new ArrayList(); + requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject(new IPv4Address(ipAdress2), new IPv4Address(ipAdress4)), null, null, null, null, null, null, null, null, null)); + specMessages.add(new PCEPRequestMessage(requests)); + + final byte[] ipAdress5 = { (byte) 0x7F, (byte) 0xd0, (byte) 0x00, (byte) 0x01 }; + requests = new ArrayList(); + requests.add(new CompositeRequestObject(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 1, 1, true, false), new PCEPEndPointsObject(new IPv4Address(ipAdress5), new IPv4Address(ipAdress5)), null, null, null, null, null, null, null, null, null)); + + specMessages.add(new PCEPRequestMessage(requests)); + deserMsgs = deserMsg("src/test/resources/PCReq.4.bin"); + assertEquals(deserMsgs.toString(), specMessages.toString()); + + specMessages.clear(); + svecList = new ArrayList(); + svecList.add(new CompositeRequestSvecObject(new PCEPSvecObject(true, false, false, false, false, this.requestIds, false))); + svecList.add(new CompositeRequestSvecObject(new PCEPSvecObject(false, true, true, false, false, this.requestIds, false), new PCEPObjectiveFunctionObject(PCEPOFCodes.MCC, true, false), new PCEPGlobalConstraintsObject((short) 0x55, (short) 1, (short) 100, (short) 0x26, true, false), new PCEPExcludeRouteObject(new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new XROAsNumberSubobject(new AsNumber((long) 0x12), true)); + } + }, true, true, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new TEMetric(123456L), true, false)); + } + })); + + requests = new ArrayList(); + requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject(new IPv4Address(ipAdress2), new IPv4Address(ipAdress2)), null, null, PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(1000)), false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new IGPMetric(53L), false, false)); + this.add(new PCEPMetricObject(true, true, new IGPMetric(5335L), false, false)); + this.add(new PCEPMetricObject(true, true, new IGPMetric(128256), false, false)); + } + }, new PCEPReportedRouteObject(this.rroSubobjects, false), new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPIncludeRouteObject(this.eroSubobjects, false, false), new PCEPLoadBalancingObject(5, new Bandwidth(ByteArray.floatToBytes(3)), false))); + + final byte[] ipAdress6 = { (byte) 0x7F, (byte) 0xF0, (byte) 0x00, (byte) 0x01 }; + specMessages.add(new PCEPRequestMessage(svecList, requests)); + + requests = new ArrayList(); + requests.add(new CompositeRequestObject(this.requestParameter, new PCEPEndPointsObject(new IPv4Address(ipAdress6), new IPv4Address(ipAdress6)), null, null, PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(1000)), false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new IGPMetric(53L), false, false)); + } + }, new PCEPReportedRouteObject(this.rroSubobjects, false), new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPIncludeRouteObject(this.eroSubobjects, false, false), new PCEPLoadBalancingObject(5, new Bandwidth(ByteArray.floatToBytes(3f)), false))); + deserMsgs = deserMsg("src/test/resources/PCReq.5.bin"); + specMessages.add(new PCEPRequestMessage(svecList, requests)); + // FIXME + // assertEquals(deserMsgs, specMessages); + + // FIXME: need construct with invalid processed parameter + // assertEquals(deserMsg("src/test/resources/PCReq.6.invalid.bin"), + // asList( + // new PCEPErrorMessage(new CompositeErrorObject(new + // PCEPRequestParameterObject(true, false, false, false, false, false, + // false, false, (short) 3, + // 1L, false, false), new PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET))), + // new PCEPRequestMessage(asList(new + // CompositeRequestObject(this.requestParameter, new + // PCEPEndPointsObject(IPv4Address + // .getNetworkAddressFactory().getNetworkAddressForBytes(new byte[] { + // 127, 0, 0, 1 }), IPv4Address.getNetworkAddressFactory() + // .getNetworkAddressForBytes(new byte[] { 127, 0, 0, 1 })), null, null, + // null, null, null, null, null, null, new PCEPLoadBalancingObject( + // 3, new Bandwidth(1024.75), false)))))); + + } + + @Test + public void testRequestMessageValidationFromRawMsg() throws PCEPDeserializerException { + List objs = new ArrayList(); + List msgs; + PCEPRequestParameterObject tmpRP; + + // test unrecognized object in svec list + objs.add(this.svecObj); + objs.add(new UnknownObject(true, false, PCEPErrors.UNRECOGNIZED_OBJ_CLASS)); + objs.add(new PCEPSvecObject(true, true, true, false, false, PCEPValidatorTest.this.requestIds, true)); + + msgs = PCEPMessageValidator.getValidator(PCEPMessageType.REQUEST).validate(objs); + + assertEquals(msgs.get(0).toString(), new PCEPErrorMessage(new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPErrorObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS)); + } + }).toString()); + + // test with request p flag not set and ignoracion of more than one + // end-points objects + objs = new ArrayList(); + objs.add(this.svecObj); + objs.add(this.svecObj); + tmpRP = new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 3, 1, false, false); + objs.add(tmpRP); + objs.add(this.endPoints); + + objs.add(this.requestParameter); + objs.add(this.endPoints); + objs.add(this.endPoints); + // FIXME:mv use object constructor with set processed flag + // objs.add(this.classTypeProvider); + // objs.add(this.requestParameter); + // objs.add(this.endPointsProvider); + // objs.add(new PCEPClassTypeObjectProvider((short) 7, false)); + + msgs = PCEPMessageValidator.getValidator(PCEPMessageType.REQUEST).validate(objs); + // FIXME:mv use object constructor with set processed flag + // assertEquals(msgs.get(0), new PCEPErrorMessage(new + // CompositeErrorObject(tmpRP, new + // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET)))); + // assertEquals( + // msgs.get(1), + // new PCEPRequestMessage(asList(new + // CompositeRequestSvecObject(this.svecObj), new + // CompositeRequestSvecObject(this.svecObj)), Util + // .asList(new CompositeRequestObject(this.requestParameter, + // this.endPoints, this.classType, null, null, null, null, null, null, + // null, + // null)))); + // assertEquals(msgs.get(2), new PCEPErrorMessage(new + // CompositeErrorObject(tmpRP, new + // PCEPErrorObject(PCEPErrors.P_FLAG_NOT_SET)))); + } + + @Test + public void testReplyMessageValidatorFromBin() throws IOException, PCEPDeserializerException, PCEPDocumentedException, + DeserializerException, DocumentedException { + + List specMessages = new ArrayList(); + specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 5, 0xDEADBEEFL, true, true))))); + specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, true, true, false, false, false, false, false, (short) 7, 0x12345678L, false, false))))); + assertEquals(deserMsg("src/test/resources/PCEPReplyMessage1.bin").toString(), specMessages.toString()); + + specMessages = new ArrayList(); + specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 3, 1, false, false))))); + assertEquals(deserMsg("src/test/resources/PCRep.1.bin").toString(), specMessages.toString()); + + specMessages = new ArrayList(); + specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 3, 1, false, false))))); + specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(false, false, false, false, false, false, false, false, (short) 5, 2, false, false), new PCEPNoPathObject((short) 0, false, false), null, null, null, null, null, null)))); + assertEquals(deserMsg("src/test/resources/PCRep.2.bin").toString(), specMessages.toString()); + + specMessages = new ArrayList(); + specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 3, 1, false, false), new PCEPNoPathObject((short) 1, true, false), new PCEPLspObject(1, true, true, false, true), PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(500)), false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new IGPMetric(234), false, false)); + } + }, new PCEPIncludeRouteObject(this.eroSubobjects, false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new CompositePathObject(new PCEPExplicitRouteObject(PCEPValidatorTest.this.eroSubobjects, false), lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(500)), false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new IGPMetric(234L), false, false)); + } + }, new PCEPIncludeRouteObject(PCEPValidatorTest.this.eroSubobjects, false, false))); + } + })))); + // FIXME BUG-89 + // assertEquals(deserMsg("src/test/resources/PCRep.3.bin"), specMessages); + + specMessages = new ArrayList(); + specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 7, 1, false, false))))); + specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 1, 2, false, false))))); + specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 2, 4, false, false))))); + specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(false, false, false, false, false, false, false, false, (short) 3, 4, false, false))))); + specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(false, false, false, false, false, false, false, false, (short) 6, 5, false, false))))); + assertEquals(deserMsg("src/test/resources/PCRep.4.bin").toString(), specMessages.toString()); + + specMessages = new ArrayList(); + final List requestIDs = new ArrayList(); + requestIDs.add(0x25069045L); + + final List metrics = new ArrayList(); + metrics.add(new PCEPMetricObject(true, true, new IGPMetric(234L), true, false)); + + final List svecList = new ArrayList(); + svecList.add(new CompositeReplySvecObject(new PCEPSvecObject(true, true, true, false, false, requestIDs, true), new PCEPObjectiveFunctionObject(PCEPOFCodes.MCC, true, false), metrics)); + + specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 3, 1, false, false), new PCEPNoPathObject((short) 1, true, false), null, PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(500)), false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new IGPMetric(234), false, false)); + } + }, new PCEPIncludeRouteObject(this.eroSubobjects, false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new CompositePathObject(new PCEPExplicitRouteObject(PCEPValidatorTest.this.eroSubobjects, false), lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(500)), false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new IGPMetric(234L), false, false)); + this.add(new PCEPMetricObject(true, true, new IGPMetric(5355L), false, false)); + this.add(new PCEPMetricObject(true, true, new IGPMetric(5353L), false, false)); + } + }, new PCEPIncludeRouteObject(PCEPValidatorTest.this.eroSubobjects, false, false))); + } + })), svecList)); + specMessages.add(new PCEPReplyMessage(asList(new CompositeResponseObject(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 3, 1, false, false), new PCEPNoPathObject((short) 1, true, false), null, PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(500)), false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new IGPMetric(234), false, false)); + } + }, new PCEPIncludeRouteObject(this.eroSubobjects, false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new CompositePathObject(new PCEPExplicitRouteObject(PCEPValidatorTest.this.eroSubobjects, false), lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(500)), false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new IGPMetric(234L), false, false)); + } + }, new PCEPIncludeRouteObject(PCEPValidatorTest.this.eroSubobjects, false, false))); + this.add(new CompositePathObject(new PCEPExplicitRouteObject(PCEPValidatorTest.this.eroSubobjects, false), lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(500)), false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, true, new IGPMetric(234L), false, false)); + } + }, new PCEPIncludeRouteObject(PCEPValidatorTest.this.eroSubobjects, false, false))); + } + })), svecList)); + assertEquals(deserMsg("src/test/resources/PCRep.5.bin").toString(), specMessages.toString()); + } + + @Test + public void testUpdMessageValidatorFromBin() throws IOException, PCEPDeserializerException, PCEPDocumentedException, + DeserializerException, DocumentedException { + List specMessages = Lists.newArrayList(); + + List requests = new ArrayList(); + requests.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, false, true, true))); + + specMessages.add(new PCEPUpdateRequestMessage(requests)); + assertEquals(deserMsg("src/test/resources/PCUpd.1.bin").toString(), specMessages.toString()); + + specMessages = Lists.newArrayList(); + List paths = new ArrayList(); + paths.add(new CompositeUpdPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), PCEPValidatorTest.lspa, null, null)); + requests = new ArrayList(); + requests.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, false, true, true), paths)); + specMessages.add(new PCEPUpdateRequestMessage(requests)); + assertEquals(deserMsg("src/test/resources/PCUpd.2.bin").toString(), specMessages.toString()); + + specMessages = Lists.newArrayList(); + paths = new ArrayList(); + paths.add(new CompositeUpdPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); + } + })); + requests = new ArrayList(); + requests.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, false, true, true), paths)); + specMessages.add(new PCEPUpdateRequestMessage(requests)); + assertEquals(deserMsg("src/test/resources/PCUpd.3.bin").toString(), specMessages.toString()); + + specMessages = Lists.newArrayList(); + requests = new ArrayList(); + requests.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, false, true, true))); + requests.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, false, true, true))); + specMessages.add(new PCEPUpdateRequestMessage(requests)); + assertEquals(deserMsg("src/test/resources/PCUpd.4.bin").toString(), specMessages.toString()); + + specMessages = Lists.newArrayList(); + requests = new ArrayList(); + requests.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, false, true, true))); + paths = new ArrayList(); + paths.add(new CompositeUpdPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); + } + })); + requests.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, false, true, true), paths)); + paths = new ArrayList(); + paths.add(new CompositeUpdPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); + } + })); + paths.add(new CompositeUpdPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); + } + })); + paths.add(new CompositeUpdPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), PCEPValidatorTest.lspa, new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); + this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); + } + })); + requests.add(new CompositeUpdateRequestObject(new PCEPLspObject(1, true, false, true, true), paths)); + specMessages.add(new PCEPUpdateRequestMessage(requests)); + assertEquals(deserMsg("src/test/resources/PCUpd.5.bin").toString(), specMessages.toString()); + } + + @Test + public void testRptMessageValidatorFromBin() throws IOException, PCEPDeserializerException, PCEPDocumentedException, + DeserializerException, DocumentedException { + List specMessages = Lists.newArrayList(); + List reports = new ArrayList(); + reports.add(new CompositeStateReportObject(new PCEPLspObject(1, true, false, true, true))); + specMessages.add(new PCEPReportMessage(reports)); + assertEquals(deserMsg("src/test/resources/PCRpt.1.bin").toString(), specMessages.toString()); + + specMessages = Lists.newArrayList(); + List paths = new ArrayList(); + paths.add(new CompositeRptPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), PCEPValidatorTest.lspa, null, null, null)); + reports = new ArrayList(); + reports.add(new CompositeStateReportObject(new PCEPLspObject(1, true, false, true, true), paths)); + specMessages.add(new PCEPReportMessage(reports)); + assertEquals(deserMsg("src/test/resources/PCRpt.2.bin").toString(), specMessages.toString()); + + specMessages = Lists.newArrayList(); + paths = new ArrayList(); + paths.add(new CompositeRptPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), PCEPValidatorTest.lspa, new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPReportedRouteObject(this.rroSubobjects, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); + } + })); + + reports = new ArrayList(); + reports.add(new CompositeStateReportObject(new PCEPLspObject(1, true, false, true, true), paths)); + specMessages.add(new PCEPReportMessage(reports)); + + // FIXME + // assertEquals(deserMsg("src/test/resources/PCRpt.3.bin"), specMessages); + + specMessages = Lists.newArrayList(); + reports = new ArrayList(); + reports.add(new CompositeStateReportObject(new PCEPLspObject(1, true, false, true, true))); + reports.add(new CompositeStateReportObject(new PCEPLspObject(1, true, false, true, true))); + reports.add(new CompositeStateReportObject(new PCEPLspObject(1, true, false, true, true))); + specMessages.add(new PCEPReportMessage(reports)); + assertEquals(deserMsg("src/test/resources/PCRpt.4.bin").toString(), specMessages.toString()); + + specMessages = Lists.newArrayList(); + reports = new ArrayList(); + paths = new ArrayList(); + paths.add(new CompositeRptPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), PCEPValidatorTest.lspa, new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPReportedRouteObject(this.rroSubobjects, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); + } + })); + reports.add(new CompositeStateReportObject(new PCEPLspObject(1, true, false, true, true), paths)); + paths = new ArrayList(); + paths.add(new CompositeRptPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), PCEPValidatorTest.lspa, new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPReportedRouteObject(this.rroSubobjects, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); + this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); + this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); + } + })); + paths.add(new CompositeRptPathObject(new PCEPExplicitRouteObject(this.eroSubobjects, false), PCEPValidatorTest.lspa, new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(5353)), false, false), new PCEPReportedRouteObject(this.rroSubobjects, false), new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); + } + })); + reports.add(new CompositeStateReportObject(new PCEPLspObject(1, true, false, true, true), paths)); + specMessages.add(new PCEPReportMessage(reports)); + // FIXME + // assertEquals(deserMsg("src/test/resources/PCRpt.5.bin").toString(), specMessages.toString()); + } + + @Test + public void testPCCreateMessage() throws DeserializerException, DocumentedException, PCEPDeserializerException { + final List insts = new ArrayList(); + final List subs = new ArrayList(); + subs.add(new EROAsNumberSubobject(new AsNumber((long) 10), false)); + final List tlvs = new ArrayList(); + final LSPSymbolicNameTlv tlv = new LSPSymbolicNameTlv(new LSPSymbolicName(new byte[] { 5, 4 })); + tlvs.add(tlv); + insts.add(new CompositeInstantiationObject(new PCEPEndPointsObject(IPv4.FAMILY.addressForString("127.0.0.2"), IPv4.FAMILY.addressForString("127.0.0.1")), PCEPValidatorTest.lspa, new PCEPExplicitRouteObject(subs, true), null, new ArrayList() { + private static final long serialVersionUID = 1L; + + { + this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); + this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); + this.add(new PCEPMetricObject(true, false, new IGPMetric(4L), false, false)); + } + })); + final PCCreateMessage msg = new PCCreateMessage(insts); + + final byte[] bytes = msgFactory.put(msg); + + // FIXME: need construct with invalid processed parameter + final RawMessage rawMessage = (RawMessage) msgFactory.parse(bytes).get(0); + + assertEquals(PCEPMessageValidator.getValidator(rawMessage.getMsgType()).validate(rawMessage.getAllObjects()).toString(), + asList((Message) msg).toString()); + } + + @Test + public void testNotificationValidatorFromBin() throws IOException, PCEPDeserializerException, PCEPDocumentedException, + DeserializerException, DocumentedException { + List notifications = new ArrayList(); + List notificationsList = new ArrayList(); + notificationsList.add(new PCEPNotificationObject((short) 1, (short) 1)); + notifications.add(new CompositeNotifyObject(notificationsList)); + PCEPNotificationMessage specMessage = new PCEPNotificationMessage(notifications); + assertEquals(deserMsg("src/test/resources/PCNtf.1.bin").toString(), asList((Message) specMessage).toString()); + + notifications = new ArrayList(); + notificationsList = new ArrayList(); + notificationsList.add(new PCEPNotificationObject((short) 1, (short) 1)); + List requestsList = new ArrayList(); + requestsList.add(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 3, 1, false, false)); + notifications.add(new CompositeNotifyObject(requestsList, notificationsList)); + specMessage = new PCEPNotificationMessage(notifications); + assertEquals(deserMsg("src/test/resources/PCNtf.2.bin").toString(), asList((Message) specMessage).toString()); + + notifications = new ArrayList(); + notificationsList = new ArrayList(); + notificationsList.add(new PCEPNotificationObject((short) 1, (short) 1)); + requestsList = new ArrayList(); + requestsList.add(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 1, 10, false, false)); + notifications.add(new CompositeNotifyObject(requestsList, notificationsList)); + specMessage = new PCEPNotificationMessage(notifications); + assertEquals(deserMsg("src/test/resources/PCNtf.3.bin").toString(), asList((Message) specMessage).toString()); + + notifications = new ArrayList(); + notificationsList = new ArrayList(); + notificationsList.add(new PCEPNotificationObject((short) 1, (short) 1)); + notificationsList.add(new PCEPNotificationObject((short) 1, (short) 2)); + notificationsList.add(new PCEPNotificationObject((short) 2, (short) 1)); + notificationsList.add(new PCEPNotificationObject((short) 2, (short) 2)); + notifications.add(new CompositeNotifyObject(notificationsList)); + specMessage = new PCEPNotificationMessage(notifications); + assertEquals(deserMsg("src/test/resources/PCNtf.4.bin").toString(), asList((Message) specMessage).toString()); + + notifications = new ArrayList(); + notificationsList = new ArrayList(); + notificationsList.add(new PCEPNotificationObject((short) 1, (short) 1)); + requestsList = new ArrayList(); + requestsList.add(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 1, 10, false, false)); + notifications.add(new CompositeNotifyObject(requestsList, notificationsList)); + notificationsList = new ArrayList(); + notificationsList.add(new PCEPNotificationObject((short) 1, (short) 1)); + notificationsList.add(new PCEPNotificationObject((short) 1, (short) 1)); + requestsList = new ArrayList(); + requestsList.add(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 1, 10, false, false)); + requestsList.add(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 1, 10, false, false)); + notifications.add(new CompositeNotifyObject(requestsList, notificationsList)); + specMessage = new PCEPNotificationMessage(notifications); + assertEquals(deserMsg("src/test/resources/PCNtf.5.bin").toString(), asList((Message) specMessage).toString()); + } + + @Test + public void testErrorMessageValidatoinFromBin() throws IOException, PCEPDeserializerException, PCEPDocumentedException, + DeserializerException, DocumentedException { + List errorsList = new ArrayList(); + errorsList.add(new PCEPErrorObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS)); + + PCEPErrorMessage specMessage = new PCEPErrorMessage(errorsList); + assertEquals(deserMsg("src/test/resources/PCErr.1.bin").toString(), asList((Message) specMessage).toString()); + + List requests = new ArrayList(); + requests.add(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 3, 1, false, false)); + + List errors = new ArrayList(); + errors.add(new CompositeErrorObject(requests, errorsList)); + + specMessage = new PCEPErrorMessage(errors); + assertEquals(deserMsg("src/test/resources/PCErr.2.bin").toString(), asList((Message) specMessage).toString()); + + specMessage = new PCEPErrorMessage(new PCEPOpenObject(0, 0, 0), errorsList, null); + assertEquals(deserMsg("src/test/resources/PCErr.3.bin").toString(), asList((Message) specMessage).toString()); + + requests = new ArrayList(); + requests.add(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 1, 53, false, false)); + + errors = new ArrayList(); + errors.add(new CompositeErrorObject(requests, errorsList)); + + specMessage = new PCEPErrorMessage(errors); + assertEquals(deserMsg("src/test/resources/PCErr.3b.bin").toString(), asList((Message) specMessage).toString()); + + errorsList = new ArrayList(); + errorsList.add(new PCEPErrorObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS)); + errorsList.add(new PCEPErrorObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS)); + errorsList.add(new PCEPErrorObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS)); + + specMessage = new PCEPErrorMessage(null, errorsList, null); + assertEquals(deserMsg("src/test/resources/PCErr.4.bin").toString(), asList((Message) specMessage).toString()); + + requests = new ArrayList(); + requests.add(new PCEPRequestParameterObject(true, false, false, false, false, false, false, false, (short) 1, 53, false, false)); + + errorsList = new ArrayList(); + errorsList.add(new PCEPErrorObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS)); + + errors = new ArrayList(); + errors.add(new CompositeErrorObject(requests, errorsList)); + errors.add(new CompositeErrorObject(requests, errorsList)); + + specMessage = new PCEPErrorMessage(errors); + assertEquals(deserMsg("src/test/resources/PCErr.5.bin").toString(), asList((Message) specMessage).toString()); + } } diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPXROSubobjectParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPXROSubobjectParserTest.java index 1b14e640ff..762cb98437 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPXROSubobjectParserTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPXROSubobjectParserTest.java @@ -7,6 +7,7 @@ */ package org.opendaylight.protocol.pcep.impl; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -20,6 +21,7 @@ import org.opendaylight.protocol.concepts.IPv6Address; import org.opendaylight.protocol.concepts.IPv6Prefix; import org.opendaylight.protocol.concepts.SharedRiskLinkGroup; import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.concepts.UnnumberedInterfaceIdentifier; import org.opendaylight.protocol.pcep.impl.subobject.XROAsNumberSubobjectParser; import org.opendaylight.protocol.pcep.impl.subobject.XROIPv4PrefixSubobjectParser; import org.opendaylight.protocol.pcep.impl.subobject.XROIPv6PrefixSubobjectParser; @@ -29,6 +31,7 @@ import org.opendaylight.protocol.pcep.subobject.XROAsNumberSubobject; import org.opendaylight.protocol.pcep.subobject.XROIPPrefixSubobject; import org.opendaylight.protocol.pcep.subobject.XROSRLGSubobject; import org.opendaylight.protocol.pcep.subobject.XROSubobjectAttribute; +import org.opendaylight.protocol.pcep.subobject.XROUnnumberedInterfaceSubobject; import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber; @@ -46,13 +49,12 @@ public class PCEPXROSubobjectParserTest { assertEquals(objsToTest.get(1), new XROIPPrefixSubobject(new IPv6Prefix(new IPv6Address(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(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)); - // assertArrayEquals(bytesFromFile, PCEPXROSubobjectParser.put(objsToTest)); + assertArrayEquals(bytesFromFile, PCEPXROSubobjectParser.put(objsToTest)); } diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/ServerSessionMock.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/ServerSessionMock.java index 15ed6582d4..567c1e14b3 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/ServerSessionMock.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/ServerSessionMock.java @@ -13,17 +13,16 @@ import io.netty.util.HashedWheelTimer; import org.opendaylight.protocol.pcep.PCEPCloseTermination; import org.opendaylight.protocol.pcep.PCEPSessionListener; -import org.opendaylight.protocol.pcep.TerminationReason; +import org.opendaylight.protocol.pcep.object.PCEPCloseObject.Reason; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; 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; public class ServerSessionMock extends PCEPSessionImpl { private final MockPCE client; public ServerSessionMock(final PCEPSessionListener listener, final PCEPSessionListener client) { - super(new HashedWheelTimer(), listener, 5, mock(Channel.class), new OpenBuilder().setKeepalive((short) 4).setDeadTimer((short) 9).setSessionId( - (short) 2).build(), new OpenBuilder().setKeepalive((short) 4).setDeadTimer((short) 9).setSessionId((short) 2).build()); + super(new HashedWheelTimer(), listener, 5, mock(Channel.class), new PCEPOpenObject(4, 9, 2), new PCEPOpenObject(4, 9, 2)); this.client = (MockPCE) client; } @@ -35,6 +34,6 @@ public class ServerSessionMock extends PCEPSessionImpl { @Override public void close() { - this.client.onSessionTerminated(this, new PCEPCloseTermination(TerminationReason.Unknown)); + this.client.onSessionTerminated(this, new PCEPCloseTermination(Reason.UNKNOWN)); } } diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/tlv/LSPStateDBVersionTlvParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/tlv/LSPStateDBVersionTlvParserTest.java new file mode 100644 index 0000000000..ec35bd5aef --- /dev/null +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/tlv/LSPStateDBVersionTlvParserTest.java @@ -0,0 +1,68 @@ +/* + * 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 static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.junit.Test; + +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.impl.PCEPTlvParser; +import org.opendaylight.protocol.pcep.tlv.LSPStateDBVersionTlv; +import org.opendaylight.protocol.util.ByteArray; + +public class LSPStateDBVersionTlvParserTest { + @Test + public void testEquality() throws IOException, PCEPDeserializerException { + final LSPStateDBVersionTlv objToTest1a = (LSPStateDBVersionTlv) PCEPTlvParser.parse( + ByteArray.fileToBytes("src/test/resources/LSPStateDBVersionTlv1.bin")).get(0); + final LSPStateDBVersionTlv objToTest1b = (LSPStateDBVersionTlv) PCEPTlvParser.parse( + ByteArray.fileToBytes("src/test/resources/LSPStateDBVersionTlv1.bin")).get(0); + final LSPStateDBVersionTlv objToTest2 = (LSPStateDBVersionTlv) PCEPTlvParser.parse( + ByteArray.fileToBytes("src/test/resources/LSPStateDBVersionTlv2.bin")).get(0); + + assertTrue(objToTest1a.equals(objToTest1a)); + assertFalse(objToTest1a.equals(objToTest2)); + assertFalse(objToTest1a == objToTest1b); + assertTrue(objToTest1a.equals(objToTest1b)); + } + + @Test + public void testSerialization() throws PCEPDeserializerException, IOException { + final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/LSPStateDBVersionTlv1.bin"); + + final LSPStateDBVersionTlv objToTest = (LSPStateDBVersionTlv) PCEPTlvParser.parse(bytesFromFile).get(0); + assertEquals(objToTest.getDbVersion(), 128L); + + final byte[] bytesActual = PCEPTlvParser.put(objToTest); + + assertArrayEquals(bytesFromFile, bytesActual); + } + + @Test + public void testConstruction() throws PCEPDeserializerException, IOException { + final LSPStateDBVersionTlv expected = (LSPStateDBVersionTlv) PCEPTlvParser.parse( + ByteArray.fileToBytes("src/test/resources/LSPStateDBVersionTlv1.bin")).get(0); + final LSPStateDBVersionTlv actual = new LSPStateDBVersionTlv(128L); + + assertEquals(expected, actual); + } + + @Test(expected = PCEPDeserializerException.class) + public void testValidityControl() throws Exception { + /* + * Should throw exception + */ + PCEPTlvParser.parse(ByteArray.fileToBytes("src/test/resources/PCEStatefulCapabilityTlvInvalid1.bin")); + } +} diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/tlv/PCEStatefulCapabilityTlvParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/tlv/PCEStatefulCapabilityTlvParserTest.java new file mode 100644 index 0000000000..0b024f6aef --- /dev/null +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/tlv/PCEStatefulCapabilityTlvParserTest.java @@ -0,0 +1,72 @@ +/* + * 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 static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.junit.Test; + +import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import org.opendaylight.protocol.pcep.impl.PCEPTlvParser; +import org.opendaylight.protocol.pcep.tlv.PCEStatefulCapabilityTlv; +import org.opendaylight.protocol.util.ByteArray; + +public class PCEStatefulCapabilityTlvParserTest { + @Test + public void testEquality() throws IOException, PCEPDeserializerException { + final PCEStatefulCapabilityTlv objToTest1a = (PCEStatefulCapabilityTlv) PCEPTlvParser.parse( + ByteArray.fileToBytes("src/test/resources/PCEStatefulCapabilityTlv1.bin")).get(0); + final PCEStatefulCapabilityTlv objToTest1b = (PCEStatefulCapabilityTlv) PCEPTlvParser.parse( + ByteArray.fileToBytes("src/test/resources/PCEStatefulCapabilityTlv1.bin")).get(0); + final PCEStatefulCapabilityTlv objToTest2 = (PCEStatefulCapabilityTlv) PCEPTlvParser.parse( + ByteArray.fileToBytes("src/test/resources/PCEStatefulCapabilityTlv2.bin")).get(0); + + assertTrue(objToTest1a.equals(objToTest1a)); + assertFalse(objToTest1a.equals(objToTest2)); + assertFalse(objToTest1a == objToTest1b); + assertTrue(objToTest1a.equals(objToTest1b)); + } + + @Test + public void testSerialization() throws PCEPDeserializerException, IOException { + final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PCEStatefulCapabilityTlv1.bin"); + + final PCEStatefulCapabilityTlv objToTest = (PCEStatefulCapabilityTlv) PCEPTlvParser.parse(bytesFromFile).get(0); + assertTrue(objToTest.isUpdate()); + assertTrue(objToTest.isVersioned()); + + final byte[] bytesActual = PCEPTlvParser.put(objToTest); + + assertArrayEquals(bytesFromFile, bytesActual); + } + + @Test + public void testConstruction() throws PCEPDeserializerException, IOException { + final PCEStatefulCapabilityTlv expected = (PCEStatefulCapabilityTlv) PCEPTlvParser.parse( + ByteArray.fileToBytes("src/test/resources/PCEStatefulCapabilityTlv1.bin")).get(0); + + final PCEStatefulCapabilityTlv actual = new PCEStatefulCapabilityTlv(false, true, true); + + assertEquals(expected, actual); + } + + @Test(expected = PCEPDeserializerException.class) + public void testValidityControl() throws Exception { + /* + * Should throw exception + */ + PCEPTlvParser.parse(ByteArray.fileToBytes("src/test/resources/PCEStatefulCapabilityTlvInvalid1.bin")); + } + +} diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractMessageParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractMessageParser.java deleted file mode 100644 index 2f699ea228..0000000000 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractMessageParser.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.opendaylight.protocol.pcep.spi; - -import java.util.Arrays; -import java.util.BitSet; -import java.util.List; - -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; -import org.opendaylight.protocol.pcep.PCEPErrors; -import org.opendaylight.protocol.pcep.UnknownObject; -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 com.google.common.collect.Lists; -import com.google.common.primitives.UnsignedBytes; - -public abstract class AbstractMessageParser implements MessageParser, MessageSerializer { - - private final static int COMMON_OBJECT_HEADER_LENGTH = 4; - - private final static int OC_F_LENGTH = 1; - private final static int OT_FLAGS_MF_LENGTH = 1; // multi-field - private final static int OBJ_LENGTH_F_LENGTH = 2; - - private final static int OC_F_OFFSET = 0; - private final static int OT_FLAGS_MF_OFFSET = OC_F_OFFSET + OC_F_LENGTH; - private final static int OBJ_LENGTH_F_OFFSET = OT_FLAGS_MF_OFFSET + OT_FLAGS_MF_LENGTH; - - private final static int OT_SF_LENGTH = 4; - private final static int FLAGS_SF_LENGTH = 4; - - /* - * offsets of fields inside of multi-field in bits - */ - private final static int OT_SF_OFFSET = 0; - private final static int FLAGS_SF_OFFSET = OT_SF_OFFSET + OT_SF_LENGTH; - - /* - * flags offsets inside multi-filed - */ - private final static int P_FLAG_OFFSET = 6; - private final static int I_FLAG_OFFSET = 7; - - private final HandlerRegistry registry; - - protected AbstractMessageParser(final HandlerRegistry registry) { - this.registry = registry; - } - - protected byte[] serializeObject(final Object object) { - if (object == null) - throw new IllegalArgumentException("Null object passed."); - - final ObjectSerializer serializer = this.registry.getObjectSerializer(object); - - final byte[] valueBytes = serializer.serializeObject(object); - - final byte[] retBytes = new byte[COMMON_OBJECT_HEADER_LENGTH + valueBytes.length]; - - // objClass - retBytes[OC_F_OFFSET] = (byte) serializer.getObjectClass(); - - // objType_flags multi-field - retBytes[OT_FLAGS_MF_OFFSET] = (byte) (serializer.getObjectType() << (Byte.SIZE - OT_SF_LENGTH)); - if (object.isProcessingRule()) - retBytes[OT_FLAGS_MF_OFFSET] |= 1 << Byte.SIZE - (P_FLAG_OFFSET) - 1; - if (object.isIgnore()) - retBytes[OT_FLAGS_MF_OFFSET] |= 1 << Byte.SIZE - (I_FLAG_OFFSET) - 1; - - // objLength - System.arraycopy(ByteArray.intToBytes(valueBytes.length), Integer.SIZE / Byte.SIZE - OBJ_LENGTH_F_LENGTH, retBytes, - OBJ_LENGTH_F_OFFSET, OBJ_LENGTH_F_LENGTH); - - System.arraycopy(valueBytes, 0, retBytes, COMMON_OBJECT_HEADER_LENGTH, valueBytes.length); - - return retBytes; - } - - protected List parseObjects(final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException { - int offset = 0; - final List objs = Lists.newArrayList(); - while (bytes.length - offset > 0) { - if (bytes.length - offset < COMMON_OBJECT_HEADER_LENGTH) - throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + (bytes.length - offset) + " Expected: >= " - + COMMON_OBJECT_HEADER_LENGTH + "."); - - final int objClass = ByteArray.bytesToInt(Arrays.copyOfRange(bytes, OC_F_OFFSET, OC_F_OFFSET + OC_F_LENGTH)); - - final int objType = UnsignedBytes.toInt(ByteArray.copyBitsRange(bytes[OT_FLAGS_MF_OFFSET], OT_SF_OFFSET, OT_SF_LENGTH)); - - final int objLength = ByteArray.bytesToInt(Arrays.copyOfRange(bytes, OBJ_LENGTH_F_OFFSET, OBJ_LENGTH_F_OFFSET - + OBJ_LENGTH_F_LENGTH)); - - final byte[] flagsBytes = { ByteArray.copyBitsRange(bytes[OT_FLAGS_MF_OFFSET], FLAGS_SF_OFFSET, FLAGS_SF_LENGTH) }; - - final BitSet flags = ByteArray.bytesToBitSet(flagsBytes); - - if (bytes.length - offset < objLength) - throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + (bytes.length - offset) + " Expected: >= " - + objLength + "."); - - // copy bytes for deeper parsing - final byte[] bytesToPass = ByteArray.subByte(bytes, offset + COMMON_OBJECT_HEADER_LENGTH, objLength - - COMMON_OBJECT_HEADER_LENGTH); - - offset += objLength; - - final ObjectParser parser = this.registry.getObjectParser(objClass, objType); - - final ObjectHeader header = new ObjectHeaderImpl(flags.get(P_FLAG_OFFSET), flags.get(I_FLAG_OFFSET)); - - try { - objs.add(parser.parseObject(header, bytesToPass)); - } catch (final PCEPDocumentedException e) { - if (e.getError() == PCEPErrors.UNRECOGNIZED_OBJ_CLASS | e.getError() == PCEPErrors.UNRECOGNIZED_OBJ_TYPE - | e.getError() == PCEPErrors.NOT_SUPPORTED_OBJ_CLASS | e.getError() == PCEPErrors.NOT_SUPPORTED_OBJ_TYPE) { - objs.add(new UnknownObject(e.getError())); - } else - throw e; - } - } - return objs; - } - - public abstract int getMessageType(); -} diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectParser.java deleted file mode 100644 index 045fd791d0..0000000000 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractObjectParser.java +++ /dev/null @@ -1,179 +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.spi; - -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.util.ByteArray; -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.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - -public abstract class AbstractObjectParser implements ObjectParser, ObjectSerializer { - - private static final Logger logger = LoggerFactory.getLogger(AbstractObjectParser.class); - - private static final int TLV_TYPE_F_LENGTH = 2; - private static final int TLV_LENGTH_F_LENGTH = 2; - private static final int TLV_HEADER_LENGTH = TLV_LENGTH_F_LENGTH + TLV_TYPE_F_LENGTH; - - 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; - - public static final int TYPE_FLAG_F_OFFSET = 0; - public static final int LENGTH_F_OFFSET = TYPE_FLAG_F_OFFSET + SUB_TYPE_FLAG_F_LENGTH; - public static final int SO_CONTENTS_OFFSET = LENGTH_F_OFFSET + SUB_LENGTH_F_LENGTH; - - protected static final int PADDED_TO = 4; - - private final HandlerRegistry registry; - - protected AbstractObjectParser(final HandlerRegistry registry) { - this.registry = registry; - } - - protected final void parseTlvs(final BUILDER builder, final byte[] bytes) throws PCEPDeserializerException { - if (bytes == null) - throw new IllegalArgumentException("Byte array is mandatory."); - - int length; - int byteOffset = 0; - int type = 0; - - while (byteOffset < bytes.length) { - type = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, TLV_TYPE_F_LENGTH)); - byteOffset += TLV_TYPE_F_LENGTH; - length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, TLV_LENGTH_F_LENGTH)); - byteOffset += TLV_LENGTH_F_LENGTH; - - if (TLV_HEADER_LENGTH + length > bytes.length - byteOffset) - throw new PCEPDeserializerException("Wrong length specified. Passed: " + (TLV_HEADER_LENGTH + length) + "; Expected: <= " - + (bytes.length - byteOffset) + "."); - - final byte[] tlvBytes = ByteArray.subByte(bytes, byteOffset, length); - - logger.trace("Attempt to parse tlv from bytes: {}", ByteArray.bytesToHexString(tlvBytes)); - final Tlv tlv = this.registry.getTlvParser(type).parseTlv(tlvBytes); - logger.trace("Tlv was parsed. {}", tlv); - - addTlv(builder, tlv); - - byteOffset += length + getPadding(TLV_HEADER_LENGTH + length, PADDED_TO); - } - } - - protected final byte[] serializeTlv(final Tlv tlv) { - - final TlvSerializer serializer = this.registry.getTlvSerializer(tlv); - - final byte[] typeBytes = (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - TLV_TYPE_F_LENGTH)); - - final byte[] valueBytes = serializer.serializeTlv(tlv); - - final byte[] lengthBytes = ByteArray.cutBytes(ByteArray.intToBytes(valueBytes.length), (Integer.SIZE / 8) - TLV_LENGTH_F_LENGTH); - - final byte[] bytes = new byte[TLV_HEADER_LENGTH + valueBytes.length + getPadding(TLV_HEADER_LENGTH + valueBytes.length, PADDED_TO)]; - - int byteOffset = 0; - System.arraycopy(typeBytes, 0, bytes, byteOffset, TLV_TYPE_F_LENGTH); - System.arraycopy(lengthBytes, 0, bytes, byteOffset += TLV_TYPE_F_LENGTH, TLV_LENGTH_F_LENGTH); - System.arraycopy(valueBytes, 0, bytes, byteOffset += TLV_LENGTH_F_LENGTH, valueBytes.length); - return bytes; - } - - protected final void parseSubobjects(final BUILDER builder, final byte[] bytes) throws PCEPDeserializerException { - if (bytes == null) - throw new IllegalArgumentException("Byte array is mandatory."); - - boolean loose_flag = false; - int type; - - final Map subs = Maps.newHashMap(); - - byte[] soContentsBytes; - int length; - int offset = 0; - - while (offset < bytes.length) { - - loose_flag = ((bytes[offset + TYPE_FLAG_F_OFFSET] & (1 << 7)) != 0) ? true : false; - length = ByteArray.bytesToInt(ByteArray.subByte(bytes, offset + LENGTH_F_OFFSET, SUB_LENGTH_F_LENGTH)); - - 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); - - logger.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes)); - final CSubobject subObj = this.registry.getSubobjectParser(type).parseSubobject(soContentsBytes); - logger.debug("Subobject was parsed. {}", subObj); - - subs.put(subObj, loose_flag); - - offset += length; - } - // addSubobject(builder, subs); - } - - protected final byte[] serializeSubobject(final Map subobjects) { - - final List result = Lists.newArrayList(); - - int finalLength = 0; - - for (final Entry entry : subobjects.entrySet()) { - - final CSubobject subobject = entry.getKey(); - - final SubobjectSerializer serializer = this.registry.getSubobjectSerializer(subobject); - - 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] | (entry.getValue() ? 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; - } - - // public abstract void addSubobject(final BUILDER builder, final Map subobjects); - - public abstract void addTlv(final BUILDER builder, final Tlv tlv); - - private static int getPadding(final int length, final int padding) { - return (padding - (length % padding)) % padding; - } -} diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/HandlerRegistry.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/HandlerRegistry.java index fed1e4af1f..edbb91c2d6 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/HandlerRegistry.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/HandlerRegistry.java @@ -10,7 +10,6 @@ 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; public interface HandlerRegistry { public AutoCloseable registerMessageParser(int messageType, MessageParser parser); @@ -30,10 +29,4 @@ public interface HandlerRegistry { public AutoCloseable registerTlvSerializer(Class tlvClass, TlvSerializer serializer); public TlvSerializer getTlvSerializer(Tlv tlv); - - public AutoCloseable registerSubobjectParser(int subobjectType, SubobjectParser parser); - public SubobjectParser getSubobjectParser(int subobjectType); - - public AutoCloseable registerSubobjectSerializer(Class subobjectClass, SubobjectSerializer serializer); - public SubobjectSerializer getSubobjectSerializer(CSubobject subobject); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageParser.java index e5db62769c..8e28bf7c75 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageParser.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/MessageParser.java @@ -7,10 +7,10 @@ */ package org.opendaylight.protocol.pcep.spi; -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import io.netty.buffer.ByteBuf; + import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; public interface MessageParser { - public Message parseMessage(byte[] buffer) throws PCEPDeserializerException, PCEPDocumentedException; + public Message parseMessage(ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectHeaderImpl.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectHeaderImpl.java deleted file mode 100644 index ba8a1b6ef4..0000000000 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectHeaderImpl.java +++ /dev/null @@ -1,116 +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.spi; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader; -import org.opendaylight.yangtools.yang.binding.DataContainer; - -/** - * Header parser for {@link org.opendaylight.protocol.pcep.PCEPObject PCEPObject} - */ -public class ObjectHeaderImpl implements ObjectHeader { - - /* - * Common object header fields lengths in bytes - */ - public final static int OC_F_LENGTH = 1; - public final static int OT_FLAGS_MF_LENGTH = 1; // multi-field - public final static int OBJ_LENGTH_F_LENGTH = 2; - - /* - * size of fields inside of multi-filed in bits - */ - public final static int OT_SF_LENGTH = 4; - public final static int FLAGS_SF_LENGTH = 4; - - /* - * offsets of fields inside of multi-field in bits - */ - public final static int OT_SF_OFFSET = 0; - public final static int FLAGS_SF_OFFSET = OT_SF_OFFSET + OT_SF_LENGTH; - - /* - * flags offsets inside multi-filed - */ - public final static int P_FLAG_OFFSET = 6; - public final static int I_FLAG_OFFSET = 7; - - /* - * Common object header fields offsets in bytes; - */ - public final static int OC_F_OFFSET = 0; - public final static int OT_FLAGS_MF_OFFSET = OC_F_OFFSET + OC_F_LENGTH; - public final static int OBJ_LENGTH_F_OFFSET = OT_FLAGS_MF_OFFSET + OT_FLAGS_MF_LENGTH; - public final static int OBJ_BODY_OFFSET = OBJ_LENGTH_F_OFFSET + OBJ_LENGTH_F_LENGTH; - - /* - * Common object header length in bytes - */ - public final static int COMMON_OBJECT_HEADER_LENGTH = (OC_F_LENGTH + OT_FLAGS_MF_LENGTH + OBJ_LENGTH_F_LENGTH); - - public final boolean processed; - public final boolean ignored; - - public ObjectHeaderImpl(final boolean processed, final boolean ignore) { - this.processed = processed; - this.ignored = ignore; - - } - - @Override - public Class getImplementedInterface() { - return ObjectHeader.class; - } - - @Override - public Boolean isIgnore() { - return this.ignored; - } - - @Override - public Boolean isProcessingRule() { - return this.processed; - } - - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("ObjectHeader [objClass="); - builder.append(", processed="); - builder.append(this.processed); - builder.append(", ignored="); - builder.append(this.ignored); - builder.append("]"); - return builder.toString(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (this.ignored ? 1231 : 1237); - result = prime * result + (this.processed ? 1231 : 1237); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (this.getClass() != obj.getClass()) - return false; - final ObjectHeaderImpl other = (ObjectHeaderImpl) obj; - if (this.ignored != other.ignored) - return false; - if (this.processed != other.processed) - return false; - return true; - } -} diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectParser.java index 2c0e3d6f07..803cad52ba 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectParser.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectParser.java @@ -7,12 +7,10 @@ */ package org.opendaylight.protocol.pcep.spi; -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; +import io.netty.buffer.ByteBuf; + 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; public interface ObjectParser { - - public Object parseObject(final ObjectHeader header, final byte[] buffer) throws PCEPDeserializerException, PCEPDocumentedException; + public Object parseObject(ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectSerializer.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectSerializer.java index d5ca955fb5..afedda0102 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectSerializer.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectSerializer.java @@ -7,15 +7,10 @@ */ package org.opendaylight.protocol.pcep.spi; +import io.netty.buffer.ByteBuf; + import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object; public interface ObjectSerializer { - - @Deprecated - public int getObjectType(); - - @Deprecated - public int getObjectClass(); - - public byte[] serializeObject(Object object); + public ByteBuf serializeObject(Object object, ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RawMessage.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RawMessage.java index 51c8df5796..6e50ba15ba 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RawMessage.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/RawMessage.java @@ -9,6 +9,7 @@ package org.opendaylight.protocol.pcep.spi; import java.util.List; +import org.opendaylight.protocol.pcep.PCEPObject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; /** @@ -16,9 +17,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ */ public class RawMessage implements Message { private final PCEPMessageType msgType; - private final List objects; + private final List objects; - public RawMessage(final List objects, final PCEPMessageType msgType) { + public RawMessage(final List objects, final PCEPMessageType msgType) { this.msgType = msgType; if (objects.contains(null)) { throw new IllegalArgumentException("Object list contains null element at offset " + objects.indexOf(null)); @@ -30,7 +31,7 @@ public class RawMessage implements Message { return this.msgType; } - public List getAllObjects() { + public List getAllObjects() { return this.objects; } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/SubobjectParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/SubobjectParser.java deleted file mode 100644 index ba9044f94a..0000000000 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/SubobjectParser.java +++ /dev/null @@ -1,15 +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.spi; - -import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject; - -public interface SubobjectParser { - public CSubobject parseSubobject(final byte[] buffer) throws PCEPDeserializerException; -} diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvParser.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvParser.java index df1bf54fef..d6787c947f 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvParser.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvParser.java @@ -7,9 +7,10 @@ */ package org.opendaylight.protocol.pcep.spi; -import org.opendaylight.protocol.pcep.PCEPDeserializerException; +import io.netty.buffer.ByteBuf; + import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv; public interface TlvParser { - public Tlv parseTlv(final byte[] buffer) throws PCEPDeserializerException; + public Tlv parseTlv(ByteBuf buffer); } diff --git a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvSerializer.java b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvSerializer.java index cfe9c94c5d..5bc46c0dc5 100644 --- a/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvSerializer.java +++ b/pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/TlvSerializer.java @@ -7,12 +7,10 @@ */ package org.opendaylight.protocol.pcep.spi; +import io.netty.buffer.ByteBuf; + import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv; public interface TlvSerializer { - - @Deprecated - public int getType(); - - public byte[] serializeTlv(Tlv tlv); + public void serializeTlv(Tlv tlv, ByteBuf buffer); } diff --git a/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java b/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java index 006d336288..ba29b91845 100644 --- a/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java +++ b/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java @@ -16,7 +16,7 @@ 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject; +import org.opendaylight.protocol.pcep.object.PCEPOpenObject; public class Main { @@ -115,7 +115,7 @@ public class Main { final PCEPSessionProposalFactory spf = new PCEPSessionProposalFactoryImpl(deadTimerValue, keepAliveValue, stateful, active, versioned, instant, timeout); - final OpenObject prefs = spf.getSessionProposal(address, 0); + final PCEPOpenObject prefs = spf.getSessionProposal(address, 0); final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5)); diff --git a/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/SimpleSessionListener.java b/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/SimpleSessionListener.java index 4e67547eaf..6485ca76dc 100644 --- a/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/SimpleSessionListener.java +++ b/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/SimpleSessionListener.java @@ -7,11 +7,23 @@ */ package org.opendaylight.protocol.pcep.testtool; +import java.util.ArrayList; import java.util.List; +import org.opendaylight.protocol.concepts.IPv4; +import org.opendaylight.protocol.concepts.IPv4Address; +import org.opendaylight.protocol.concepts.IPv4Prefix; +import org.opendaylight.protocol.concepts.Prefix; import org.opendaylight.protocol.pcep.PCEPSession; import org.opendaylight.protocol.pcep.PCEPSessionListener; import org.opendaylight.protocol.pcep.PCEPTerminationReason; +import org.opendaylight.protocol.pcep.message.PCCreateMessage; +import org.opendaylight.protocol.pcep.object.CompositeInstantiationObject; +import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject; +import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject; +import org.opendaylight.protocol.pcep.object.PCEPLspaObject; +import org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,17 +51,13 @@ public class SimpleSessionListener implements PCEPSessionListener { @Override public void onSessionUp(final PCEPSession session) { logger.debug("Session up."); - // final List subs = new ArrayList(); - // subs.add(new EROIPPrefixSubobject>(new IPv4Prefix(new IPv4Address(new byte[] { 10, 1, 1, 2 }), 32), - // false)); - // subs.add(new EROIPPrefixSubobject>(new IPv4Prefix(new IPv4Address(new byte[] { 2, 2, 2, 2 }), 32), - // false)); - // final CompositeInstantiationObject cpo = new CompositeInstantiationObject(new - // PCEPEndPointsObject(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))); + final List subs = new ArrayList(); + subs.add(new EROIPPrefixSubobject>(new IPv4Prefix(new IPv4Address(new byte[] { 10, 1, 1, 2 }), 32), false)); + subs.add(new EROIPPrefixSubobject>(new IPv4Prefix(new IPv4Address(new byte[] { 2, 2, 2, 2 }), 32), false)); + final CompositeInstantiationObject cpo = new CompositeInstantiationObject(new PCEPEndPointsObject(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 diff --git a/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java b/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java index 0f7f052050..d40c22aa40 100644 --- a/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java +++ b/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java @@ -15,6 +15,7 @@ import io.netty.util.concurrent.GlobalEventExecutor; import io.netty.util.concurrent.Promise; import java.net.InetSocketAddress; +import java.util.List; import org.opendaylight.protocol.framework.AbstractDispatcher; import org.opendaylight.protocol.framework.NeverReconnectStrategy; @@ -25,15 +26,16 @@ import org.opendaylight.protocol.framework.SessionListener; import org.opendaylight.protocol.framework.SessionListenerFactory; import org.opendaylight.protocol.framework.SessionNegotiatorFactory; import org.opendaylight.protocol.pcep.PCEPSessionListener; +import org.opendaylight.protocol.pcep.PCEPTlv; 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.object.PCEPOpenObject; +import org.opendaylight.protocol.pcep.tlv.NodeIdentifierTlv; 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; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.PredundancyGroupIdBuilder; import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; public class PCCMock, L extends SessionListener> extends AbstractDispatcher { @@ -59,11 +61,10 @@ public class PCCMock, L extends SessionListener< } public static void main(final String[] args) throws Exception { - final TlvsBuilder builder = new TlvsBuilder(); - builder.setPredundancyGroupId(new PredundancyGroupIdBuilder().setIdentifier(new byte[] { (byte) 127, (byte) 2, (byte) 3, (byte) 7 }).build()); + final List tlvs = Lists.newArrayList(); + tlvs.add(new NodeIdentifierTlv(new byte[] { (byte) 127, (byte) 2, (byte) 3, (byte) 7 })); - final SessionNegotiatorFactory snf = new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), new OpenBuilder().setKeepalive( - (short) 30).setDeadTimer((short) 120).setSessionId((short) 0).setTlvs(builder.build()).build(), 0); + final SessionNegotiatorFactory snf = new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), new PCEPOpenObject(30, 120, 0, tlvs), 0); final PCCMock pcc = new PCCMock<>(snf, new PCEPHandlerFactory(), new DefaultPromise(GlobalEventExecutor.INSTANCE)); -- 2.36.6