aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/bgp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/bgp')
-rwxr-xr-xframework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpCfg.java (renamed from framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPCfg.java)12
-rwxr-xr-xframework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpConnectPeer.java28
-rwxr-xr-xframework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpController.java (renamed from framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java)41
-rwxr-xr-xframework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpDpid.java130
-rwxr-xr-xframework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpId.java (renamed from framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPId.java)18
-rwxr-xr-xframework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpLinkListener.java35
-rwxr-xr-xframework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpLocalRib.java60
-rwxr-xr-xframework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpNodeListener.java35
-rwxr-xr-xframework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpPacketStats.java (renamed from framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPacketStats.java)2
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpPeer.java (renamed from framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeer.java)22
-rwxr-xr-xframework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpPeerCfg.java (renamed from framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeerCfg.java)2
-rwxr-xr-xframework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpPeerManager.java8
-rwxr-xr-xframework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpSessionInfo.java70
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/exceptions/BgpParseException.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/exceptions/BGPParseException.java)12
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpFactories.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPFactories.java)32
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpFactory.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPFactory.java)12
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpKeepaliveMsg.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPKeepaliveMsg.java)16
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLSNlri.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPLSNlri.java)10
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java6
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpMessage.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPMessage.java)20
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpMessageReader.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPMessageReader.java)10
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpMessageWriter.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPMessageWriter.java)8
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpNodeLSNlri.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPNodeLSNlri.java)6
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpNotificationMsg.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPNotificationMsg.java)8
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpOpenMsg.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPOpenMsg.java)24
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpPrefixLSNlri.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPPrefixLSNlri.java)8
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpType.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPType.java)4
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java2
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpVersion.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPVersion.java)4
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/Writeable.java6
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpLinkLSIdentifier.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPLinkLSIdentifier.java)118
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpLinkLsNlriVer4.java210
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpNodeLSIdentifier.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSIdentifier.java)39
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpNodeLSNlriVer4.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSNlriVer4.java)52
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpPrefixIPv4LSNlriVer4.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixIPv4LSNlriVer4.java)52
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpPrefixLSIdentifier.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixLSIdentifier.java)113
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/NodeDescriptors.java77
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/PathAttrNlriDetails.java135
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/PathAttrNlriDetailsLocalRib.java122
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPFactoryVer4.java58
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpFactoryVer4.java58
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpKeepaliveMsgVer4.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPKeepaliveMsgVer4.java)56
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpMessageVer4.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPMessageVer4.java)56
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpNotificationMsgVer4.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPNotificationMsgVer4.java)76
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpOpenMsgVer4.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPOpenMsgVer4.java)130
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpPathAttributes.java36
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java72
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AreaIDTlv.java14
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java22
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java22
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AutonomousSystemTlv.java14
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpErrorType.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java)4
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpHeader.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPHeader.java)12
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpLSIdentifierTlv.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPLSIdentifierTlv.java)58
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpValueType.java (renamed from framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPValueType.java)10
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/FourOctetAsNumCapabilityTlv.java8
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java18
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java27
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java27
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsNonPseudonode.java27
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java72
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java19
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkStateAttributes.java314
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java18
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java18
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java50
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java52
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MultiProtocolExtnCapabilityTlv.java10
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java20
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFNonPseudonode.java15
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFPseudonode.java19
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFRouteTypeTlv.java39
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java20
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/RouteDistinguisher.java19
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeFlagBitTlv.java22
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeIsIsAreaId.java136
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java43
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeName.java135
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrOpaqueNode.java138
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV4.java22
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6.java22
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIgpMetric.java22
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java22
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java22
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMplsProtocolMask.java22
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java22
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java22
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrProtectionType.java22
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrSrlg.java136
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java22
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrUnRsrvdLinkBandwidth.java163
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrExtRouteTag.java145
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlags.java22
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrMetric.java22
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java21
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOspfFwdAddr.java22
-rw-r--r--[-rwxr-xr-x]framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java22
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/util/Validation.java14
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpKeepaliveMsgTest.java (renamed from framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BGPKeepaliveMsgTest.java)16
-rw-r--r--framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpNotificationMsgTest.java70
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpOpenMsgTest.java (renamed from framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BGPOpenMsgTest.java)94
-rw-r--r--framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AreaIdTest.java38
-rw-r--r--framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BgpLSIdentifierTest.java (renamed from framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BGPLSIdentifierTest.java)8
-rw-r--r--framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsNonPseudonodeTest.java39
-rw-r--r--framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java26
-rw-r--r--framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LocalPrefTest.java8
-rw-r--r--framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/MedTest.java8
-rw-r--r--framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidthTest.java43
-rw-r--r--framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrNameTest.java38
-rw-r--r--framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttribTest.java41
-rw-r--r--framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetricTest.java40
-rw-r--r--framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrUnRsrvdLinkBandwidthTest.java56
-rw-r--r--framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueDataTest.java41
-rw-r--r--framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTagTest.java54
-rw-r--r--framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/AdjRibIn.java132
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerImpl.java161
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpChannelHandler.java (renamed from framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPChannelHandler.java)294
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpConfig.java (renamed from framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPConfig.java)56
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpConnectPeerImpl.java133
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpControllerImpl.java (renamed from framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPControllerImpl.java)84
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpKeepAliveTimer.java (renamed from framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPKeepAliveTimer.java)8
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpMessageDecoder.java (renamed from framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPMessageDecoder.java)20
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpMessageEncoder.java (renamed from framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPMessageEncoder.java)10
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpPacketStatsImpl.java (renamed from framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPacketStatsImpl.java)6
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpPeerConfig.java (renamed from framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerConfig.java)6
-rw-r--r--framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpPeerImpl.java297
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpPipelineFactory.java (renamed from framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPipelineFactory.java)14
-rw-r--r--framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpSelectionAlgo.java242
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpSessionInfoImpl.java93
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/Controller.java35
-rw-r--r--framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/VpnAdjRibIn.java209
-rwxr-xr-xframework/src/onos/bgp/ctl/src/test/java/org/onosproject/bgp/BgpControllerImplTest.java300
-rwxr-xr-xframework/src/onos/bgp/ctl/src/test/java/org/onosproject/bgp/BgpPeerChannelHandlerTest.java107
-rwxr-xr-xframework/src/onos/bgp/ctl/src/test/java/org/onosproject/bgp/BgpPeerFrameDecoderTest.java168
-rw-r--r--framework/src/onos/bgp/ctl/src/test/java/org/onosproject/controller/impl/BgpSelectionAlgoTest.java595
135 files changed, 6372 insertions, 1538 deletions
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPCfg.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpCfg.java
index 46165d87..6f64d2bb 100755
--- a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPCfg.java
+++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpCfg.java
@@ -20,7 +20,7 @@ import java.util.TreeMap;
/**
* Abstraction of an BGP configuration. Manages the BGP configuration from CLI to the BGP controller.
*/
-public interface BGPCfg {
+public interface BgpCfg {
enum State {
/**
@@ -233,7 +233,7 @@ public interface BGPCfg {
*
* @return return the tree map with IP as key and BGPPeerCfg as object
*/
- TreeMap<String, BGPPeerCfg> displayPeers();
+ TreeMap<String, BgpPeerCfg> displayPeers();
/**
* Return the BGP Peer information with this matching IP.
@@ -242,7 +242,7 @@ public interface BGPCfg {
*
* @return BGPPeerCfg object
*/
- BGPPeerCfg displayPeers(String routerid);
+ BgpPeerCfg displayPeers(String routerid);
/**
* Check if this BGP peer is configured.
@@ -267,7 +267,7 @@ public interface BGPCfg {
*
* @return return the tree map with IP as key and BGPPeerCfg as object
*/
- TreeMap<String, BGPPeerCfg> getPeerTree();
+ TreeMap<String, BgpPeerCfg> getPeerTree();
/**
* Set the current connection state information.
@@ -275,7 +275,7 @@ public interface BGPCfg {
* @param routerid router IP address in string format
* @param state state information
*/
- void setPeerConnState(String routerid, BGPPeerCfg.State state);
+ void setPeerConnState(String routerid, BgpPeerCfg.State state);
/**
* Check if the peer can be connected or not.
@@ -293,5 +293,5 @@ public interface BGPCfg {
*
* @return state information
*/
- BGPPeerCfg.State getPeerConnState(String routerid);
+ BgpPeerCfg.State getPeerConnState(String routerid);
}
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpConnectPeer.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpConnectPeer.java
new file mode 100755
index 00000000..8f33ee87
--- /dev/null
+++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpConnectPeer.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.onosproject.bgp.controller;
+
+/**
+ * Abstraction of an BGP connect peer, initiate remote connection to BGP peer on configuration.
+ */
+public interface BgpConnectPeer {
+ /**
+ * Initiate bgp peer connection.
+ */
+ void connectPeer();
+
+ /**
+ * End bgp peer connection.
+ */
+ void disconnectPeer();
+}
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpController.java
index 9d44041e..cc87eb32 100755
--- a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java
+++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpController.java
@@ -19,21 +19,21 @@ package org.onosproject.bgp.controller;
import java.util.Map;
import java.util.Set;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.protocol.BGPMessage;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpMessage;
/**
* Abstraction of an BGP controller. Serves as a one stop shop for obtaining BGP devices and (un)register listeners on
* bgp events
*/
-public interface BGPController {
+public interface BgpController {
/**
* Returns list of bgp peers connected to this BGP controller.
*
* @return Iterable of BGPPeer elements
*/
- Iterable<BGPPeer> getPeers();
+ Iterable<BgpPeer> getPeers();
/**
* Returns the actual bgp peer for the given ip address.
@@ -41,7 +41,7 @@ public interface BGPController {
* @param bgpId the id of the bgp peer to fetch
* @return the interface to this bgp peer
*/
- BGPPeer getPeer(BGPId bgpId);
+ BgpPeer getPeer(BgpId bgpId);
/**
* Register a listener for BGP message events.
@@ -58,35 +58,21 @@ public interface BGPController {
void removeListener(BgpNodeListener listener);
/**
- * Register a listener for BGP message events.
- *
- * @param listener the listener to notify
- */
- void addLinkListener(BgpLinkListener listener);
-
- /**
- * Unregister a listener.
- *
- * @param listener the listener to unregister
- */
- void removeLinkListener(BgpLinkListener listener);
-
- /**
* Send a message to a particular bgp peer.
*
* @param bgpId the id of the peer to send message.
* @param msg the message to send
*/
- void writeMsg(BGPId bgpId, BGPMessage msg);
+ void writeMsg(BgpId bgpId, BgpMessage msg);
/**
* Process a message and notify the appropriate listeners.
*
* @param bgpId id of the peer the message arrived on
* @param msg the message to process.
- * @throws BGPParseException on data processing error
+ * @throws BgpParseException on data processing error
*/
- void processBGPPacket(BGPId bgpId, BGPMessage msg) throws BGPParseException;
+ void processBGPPacket(BgpId bgpId, BgpMessage msg) throws BgpParseException;
/**
* Close all connected BGP peers.
@@ -99,7 +85,7 @@ public interface BGPController {
*
* @return configuration object
*/
- BGPCfg getConfig();
+ BgpCfg getConfig();
/**
* Get the BGP connected peers to this controller.
@@ -120,7 +106,7 @@ public interface BGPController {
*
* @return connectedPeers connected peers
*/
- Map<BGPId, BGPPeer> connectedPeers();
+ Map<BgpId, BgpPeer> connectedPeers();
/**
* Return BGP node listener.
@@ -128,11 +114,4 @@ public interface BGPController {
* @return node listener
*/
Set<BgpNodeListener> listener();
-
- /**
- * Return BGP link listener.
- *
- * @return link listener
- */
- Set<BgpLinkListener> linkListener();
}
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpDpid.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpDpid.java
new file mode 100755
index 00000000..ed04dc94
--- /dev/null
+++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpDpid.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package org.onosproject.bgp.controller;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The class representing a network bgp device id. This class is immutable.
+ */
+public final class BgpDpid {
+ private static final Logger log = LoggerFactory.getLogger(BgpDpid.class);
+
+ private static final String SCHEME = "bgp";
+ private static final long UNKNOWN = 0;
+ private StringBuilder stringBuilder;
+ public static final int NODE_DESCRIPTOR_LOCAL = 1;
+ public static final int NODE_DESCRIPTOR_REMOTE = 2;
+
+ /**
+ * Initialize bgp id to generate URI.
+ *
+ * @param linkNlri node Nlri.
+ * @param nodeDescriptorType node descriptor type, local/remote
+ */
+ public BgpDpid(final BgpLinkLsNlriVer4 linkNlri, int nodeDescriptorType) {
+ this.stringBuilder = new StringBuilder("bgpls://");
+
+ if (linkNlri.getRouteDistinguisher() != null) {
+ this.stringBuilder.append(linkNlri.getRouteDistinguisher().getRouteDistinguisher()).append(':');
+ }
+
+ try {
+ this.stringBuilder.append(linkNlri.getProtocolId()).append(':').append(linkNlri.getIdentifier())
+ .append('/');
+
+ if (nodeDescriptorType == NODE_DESCRIPTOR_LOCAL) {
+ add(linkNlri.localNodeDescriptors());
+ } else if (nodeDescriptorType == NODE_DESCRIPTOR_REMOTE) {
+ add(linkNlri.remoteNodeDescriptors());
+ }
+ } catch (BgpParseException e) {
+ log.info("Exception BgpId string: " + e.toString());
+ }
+
+ }
+
+ /**
+ * Initialize bgp id to generate URI.
+ *
+ * @param nodeNlri node Nlri.
+ */
+ public BgpDpid(final BgpNodeLSNlriVer4 nodeNlri) {
+ this.stringBuilder = new StringBuilder("bgpls://");
+
+ if (nodeNlri.getRouteDistinguisher() != null) {
+ this.stringBuilder.append(nodeNlri.getRouteDistinguisher().getRouteDistinguisher()).append(':');
+ }
+
+ try {
+
+ this.stringBuilder.append(nodeNlri.getProtocolId()).append(':').append(nodeNlri.getIdentifier())
+ .append('/');
+
+ add(nodeNlri.getLocalNodeDescriptors());
+
+ } catch (BgpParseException e) {
+ log.info("Exception node string: " + e.toString());
+ }
+ }
+
+ BgpDpid add(final Object value) {
+ if (value != null) {
+ this.stringBuilder.append('&').append('=').append(value.toString());
+ }
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return this.stringBuilder.toString();
+ }
+
+ /**
+ * Produces bgp URI.
+ *
+ * @param value string to get URI
+ * @return bgp URI, otherwise null
+ */
+ public static URI uri(String value) {
+ try {
+ return new URI(SCHEME, value, null);
+ } catch (URISyntaxException e) {
+ log.info("Exception BgpId URI: " + e.toString());
+ }
+ return null;
+ }
+
+ /**
+ * Returns bgpDpid created from the given device URI.
+ *
+ * @param uri device URI
+ * @return object of BgpDpid
+ */
+ public static BgpDpid bgpDpid(URI uri) {
+ checkArgument(uri.getScheme().equals(SCHEME), "Unsupported URI scheme");
+
+ // TODO: return BgpDpid generated from uri
+ return null;
+ }
+}
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPId.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpId.java
index 636e72f3..7a6c625d 100755
--- a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPId.java
+++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpId.java
@@ -27,7 +27,7 @@ import static com.google.common.base.Preconditions.checkArgument;
* The class representing a network peer bgp ip.
* This class is immutable.
*/
-public final class BGPId {
+public final class BgpId {
private static final String SCHEME = "bgp";
private static final long UNKNOWN = 0;
@@ -36,7 +36,7 @@ public final class BGPId {
/**
* Private constructor.
*/
- private BGPId(IpAddress ipAddress) {
+ private BgpId(IpAddress ipAddress) {
this.ipAddress = ipAddress;
}
@@ -46,8 +46,8 @@ public final class BGPId {
* @param ipAddress IP address
* @return object of BGPId
*/
- public static BGPId bgpId(IpAddress ipAddress) {
- return new BGPId(ipAddress);
+ public static BgpId bgpId(IpAddress ipAddress) {
+ return new BgpId(ipAddress);
}
/**
@@ -71,11 +71,11 @@ public final class BGPId {
@Override
public boolean equals(Object other) {
- if (!(other instanceof BGPId)) {
+ if (!(other instanceof BgpId)) {
return false;
}
- BGPId otherBGPid = (BGPId) other;
+ BgpId otherBGPid = (BgpId) other;
return Objects.equals(ipAddress, otherBGPid.ipAddress);
}
@@ -90,9 +90,9 @@ public final class BGPId {
* @param uri device URI
* @return object of BGPId
*/
- public static BGPId bgpId(URI uri) {
+ public static BgpId bgpId(URI uri) {
checkArgument(uri.getScheme().equals(SCHEME), "Unsupported URI scheme");
- return new BGPId(IpAddress.valueOf(uri.getSchemeSpecificPart()));
+ return new BgpId(IpAddress.valueOf(uri.getSchemeSpecificPart()));
}
/**
@@ -101,7 +101,7 @@ public final class BGPId {
* @param bgpId device bgpId
* @return device URI
*/
- public static URI uri(BGPId bgpId) {
+ public static URI uri(BgpId bgpId) {
return uri(bgpId.ipAddress());
}
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpLinkListener.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpLinkListener.java
new file mode 100755
index 00000000..8b34e314
--- /dev/null
+++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpLinkListener.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.onosproject.bgp.controller;
+
+import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
+
+/**
+ * Allows for providers interested in Link events to be notified.
+ */
+public interface BgpLinkListener {
+
+ /**
+ * Notify that got a packet of link from network and need do processing.
+ *
+ * @param linkNlri bgp link
+ */
+ void addLink(BgpLinkLsNlriVer4 linkNlri);
+
+ /**
+ * Notify that got a packet of link from network and need do processing.
+ *
+ * @param linkNlri bgp link
+ */
+ void deleteLink(BgpLinkLsNlriVer4 linkNlri);
+}
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpLocalRib.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpLocalRib.java
new file mode 100755
index 00000000..636c1c85
--- /dev/null
+++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpLocalRib.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package org.onosproject.bgp.controller;
+
+import org.onosproject.bgpio.protocol.BgpLSNlri;
+import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails;
+import org.onosproject.bgpio.types.RouteDistinguisher;
+
+/**
+ * Abstraction of BGP local RIB.
+ */
+public interface BgpLocalRib {
+
+ /**
+ * Add NLRI to local RIB.
+ *
+ * @param sessionInfo session info
+ * @param nlri network layer reach info
+ * @param details nlri details
+ */
+ void add(BgpSessionInfo sessionInfo, BgpLSNlri nlri, PathAttrNlriDetails details);
+
+ /**
+ * Removes NLRI identifier if it exists.
+ *
+ * @param nlri info
+ */
+ void delete(BgpLSNlri nlri);
+
+ /**
+ * Update NLRI identifier mapped with route distinguisher if it exists in tree otherwise add NLRI infomation mapped
+ * to respective route distinguisher.
+ *
+ * @param sessionInfo BGP session info
+ * @param nlri info
+ * @param details has pathattribute, protocol id and identifier
+ * @param routeDistinguisher unique for each VPN
+ */
+ void add(BgpSessionInfo sessionInfo, BgpLSNlri nlri, PathAttrNlriDetails details,
+ RouteDistinguisher routeDistinguisher);
+
+ /**
+ * Removes VPN NLRI identifier mapped to route distinguisher if it exists.
+ *
+ * @param nlri info
+ * @param routeDistinguisher unique for each VPN
+ */
+ void delete(BgpLSNlri nlri, RouteDistinguisher routeDistinguisher);
+}
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpNodeListener.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpNodeListener.java
new file mode 100755
index 00000000..726d931b
--- /dev/null
+++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpNodeListener.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.onosproject.bgp.controller;
+
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
+
+/**
+ * Allows for providers interested in node events to be notified.
+ */
+public interface BgpNodeListener {
+
+ /**
+ * Notifies that the node was added.
+ *
+ * @param nodeNlri node rechability info
+ */
+ void addNode(BgpNodeLSNlriVer4 nodeNlri);
+
+ /**
+ * Notifies that the node was removed.
+ *
+ * @param nodeNlri node rechability info
+ */
+ void deleteNode(BgpNodeLSNlriVer4 nodeNlri);
+}
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPacketStats.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpPacketStats.java
index 95f83a2d..8fd3c688 100755
--- a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPacketStats.java
+++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpPacketStats.java
@@ -21,7 +21,7 @@ package org.onosproject.bgp.controller;
* to the event if blocked has been called. This packet context can be used to react to the packet in event with a
* packet out.
*/
-public interface BGPPacketStats {
+public interface BgpPacketStats {
/**
* Returns the count for no of packets sent out.
*
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeer.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpPeer.java
index aafaf06e..9f4d47da 100755..100644
--- a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeer.java
+++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpPeer.java
@@ -16,14 +16,16 @@
package org.onosproject.bgp.controller;
import java.util.List;
import org.jboss.netty.channel.Channel;
-import org.onosproject.bgpio.protocol.BGPFactory;
-import org.onosproject.bgpio.protocol.BGPMessage;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpFactory;
+import org.onosproject.bgpio.protocol.BgpMessage;
+import org.onosproject.bgpio.types.BgpValueType;
/**
* Represents the peer side of an BGP peer.
*
*/
-public interface BGPPeer {
+public interface BgpPeer {
/**
* Sets the associated Netty channel for this bgp peer.
@@ -58,21 +60,21 @@ public interface BGPPeer {
*
* @param msg the message to write
*/
- void sendMessage(BGPMessage msg);
+ void sendMessage(BgpMessage msg);
/**
* Writes the BGPMessage list to the peer.
*
* @param msgs the messages to be written
*/
- void sendMessage(List<BGPMessage> msgs);
+ void sendMessage(List<BgpMessage> msgs);
/**
* Provides the factory for BGP version.
*
* @return BGP version specific factory.
*/
- BGPFactory factory();
+ BgpFactory factory();
/**
* Checks if the bgp peer is still connected.
@@ -95,6 +97,14 @@ public interface BGPPeer {
String channelId();
/**
+ * Maintaining Adj-RIB-In separately for each peer.
+ *
+ * @param pathAttr list of Bgp path attributes
+ * @throws BgpParseException while building Adj-Rib-In
+ */
+ void buildAdjRibIn(List<BgpValueType> pathAttr) throws BgpParseException;
+
+ /**
* Return the BGP session info.
*
* @return sessionInfo bgp session info
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeerCfg.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpPeerCfg.java
index e7c5d9b4..2fb970fc 100755
--- a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeerCfg.java
+++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpPeerCfg.java
@@ -18,7 +18,7 @@ package org.onosproject.bgp.controller;
/**
* BGP Peer configuration information.
*/
-public interface BGPPeerCfg {
+public interface BgpPeerCfg {
enum State {
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpPeerManager.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpPeerManager.java
index d2230967..895cc145 100755
--- a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpPeerManager.java
+++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpPeerManager.java
@@ -26,7 +26,7 @@ public interface BgpPeerManager {
*
* @return false if peer already exist, otherwise true
*/
- public boolean addConnectedPeer(BGPId bgpId, BGPPeer bgpPeer);
+ public boolean addConnectedPeer(BgpId bgpId, BgpPeer bgpPeer);
/**
* Validate wheather peer is connected.
@@ -35,14 +35,14 @@ public interface BgpPeerManager {
*
* @return true if peer exist, otherwise false
*/
- public boolean isPeerConnected(BGPId bgpId);
+ public boolean isPeerConnected(BgpId bgpId);
/**
* Remove connected peer.
*
* @param bgpId BGP ID
*/
- public void removeConnectedPeer(BGPId bgpId);
+ public void removeConnectedPeer(BgpId bgpId);
/**
* Gets connected peer.
@@ -50,5 +50,5 @@ public interface BgpPeerManager {
* @param bgpId BGP ID
* @return BGPPeer the connected peer, otherwise null
*/
- public BGPPeer getPeer(BGPId bgpId);
+ public BgpPeer getPeer(BgpId bgpId);
}
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpSessionInfo.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpSessionInfo.java
new file mode 100755
index 00000000..a21a23d2
--- /dev/null
+++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BgpSessionInfo.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package org.onosproject.bgp.controller;
+
+import org.onosproject.bgpio.protocol.BgpVersion;
+
+/**
+ * Abstraction of an BGP session info. Maintian session parameters obtained during session creation.
+ */
+public interface BgpSessionInfo {
+ /**
+ * Gets the bgp session type iBGP/eBGP.
+ *
+ * @return isiBGPSession, true if session is of type internal, otherwise false.
+ */
+ boolean isIbgpSession();
+
+ /**
+ * Gets the negotiated hold time for the session.
+ *
+ * @return negotiated hold time.
+ */
+ short negotiatedholdTime();
+
+ /**
+ * Gets the BGP ID of BGP peer.
+ *
+ * @return bgp ID.
+ */
+ BgpId remoteBgpId();
+
+ /**
+ * Gets the BGP version of peer.
+ *
+ * @return bgp version.
+ */
+ BgpVersion remoteBgpVersion();
+
+ /**
+ * Gets the BGP remote bgp AS number.
+ *
+ * @return remoteBgpASNum peer AS number.
+ */
+ long remoteBgpASNum();
+
+ /**
+ * Gets the BGP peer hold time.
+ *
+ * @return bgp hold time.
+ */
+ short remoteBgpHoldTime();
+
+ /**
+ * Gets the BGP version for this bgp peer.
+ *
+ * @return bgp identifier.
+ */
+ int remoteBgpIdentifier();
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/exceptions/BGPParseException.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/exceptions/BgpParseException.java
index 62427a44..d0890320 100755
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/exceptions/BGPParseException.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/exceptions/BgpParseException.java
@@ -21,7 +21,7 @@ import org.jboss.netty.buffer.ChannelBuffer;
/**
* Custom Exception for BGP IO.
*/
-public class BGPParseException extends Exception {
+public class BgpParseException extends Exception {
private static final long serialVersionUID = 1L;
private byte errorCode;
@@ -31,7 +31,7 @@ public class BGPParseException extends Exception {
/**
* Default constructor to create a new exception.
*/
- public BGPParseException() {
+ public BgpParseException() {
super();
}
@@ -41,7 +41,7 @@ public class BGPParseException extends Exception {
* @param message the detail of exception in string
* @param cause underlying cause of the error
*/
- public BGPParseException(final String message, final Throwable cause) {
+ public BgpParseException(final String message, final Throwable cause) {
super(message, cause);
}
@@ -50,7 +50,7 @@ public class BGPParseException extends Exception {
*
* @param message the detail of exception in string
*/
- public BGPParseException(final String message) {
+ public BgpParseException(final String message) {
super(message);
}
@@ -59,7 +59,7 @@ public class BGPParseException extends Exception {
*
* @param cause underlying cause of the error
*/
- public BGPParseException(final Throwable cause) {
+ public BgpParseException(final Throwable cause) {
super(cause);
}
@@ -70,7 +70,7 @@ public class BGPParseException extends Exception {
* @param errorSubCode error subcode of BGP message
* @param data error data of BGP message
*/
- public BGPParseException(final byte errorCode, final byte errorSubCode, final ChannelBuffer data) {
+ public BgpParseException(final byte errorCode, final byte errorSubCode, final ChannelBuffer data) {
super();
this.errorCode = errorCode;
this.errorSubCode = errorSubCode;
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPFactories.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpFactories.java
index 71b9cbff..eb18c7d1 100755
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPFactories.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpFactories.java
@@ -17,22 +17,22 @@
package org.onosproject.bgpio.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.protocol.ver4.BGPFactoryVer4;
-import org.onosproject.bgpio.types.BGPHeader;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.ver4.BgpFactoryVer4;
+import org.onosproject.bgpio.types.BgpHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Abstraction to provide the version for BGP.
*/
-public final class BGPFactories {
+public final class BgpFactories {
- protected static final Logger log = LoggerFactory.getLogger(BGPFactories.class);
+ protected static final Logger log = LoggerFactory.getLogger(BgpFactories.class);
private static final GenericReader GENERIC_READER = new GenericReader();
- private BGPFactories() {
+ private BgpFactories() {
}
/**
@@ -41,12 +41,12 @@ public final class BGPFactories {
* @param version BGP version
* @return BGP version
*/
- public static BGPFactory getFactory(BGPVersion version) {
+ public static BgpFactory getFactory(BgpVersion version) {
switch (version) {
case BGP_4:
- return BGPFactoryVer4.INSTANCE;
+ return BgpFactoryVer4.INSTANCE;
default:
- throw new IllegalArgumentException("[BGPFactory:]Unknown version: " + version);
+ throw new IllegalArgumentException("[BgpFactory:]Unknown version: " + version);
}
}
@@ -54,19 +54,19 @@ public final class BGPFactories {
* Reader class for reading BGP messages from channel buffer.
*
*/
- private static class GenericReader implements BGPMessageReader<BGPMessage> {
+ private static class GenericReader implements BgpMessageReader<BgpMessage> {
@Override
- public BGPMessage readFrom(ChannelBuffer bb, BGPHeader bgpHeader)
- throws BGPParseException {
- BGPFactory factory;
+ public BgpMessage readFrom(ChannelBuffer bb, BgpHeader bgpHeader)
+ throws BgpParseException {
+ BgpFactory factory;
if (!bb.readable()) {
log.error("Empty message received");
- throw new BGPParseException("Empty message received");
+ throw new BgpParseException("Empty message received");
}
// TODO: Currently only BGP version 4 is supported
- factory = org.onosproject.bgpio.protocol.ver4.BGPFactoryVer4.INSTANCE;
+ factory = org.onosproject.bgpio.protocol.ver4.BgpFactoryVer4.INSTANCE;
return factory.getReader().readFrom(bb, bgpHeader);
}
}
@@ -76,7 +76,7 @@ public final class BGPFactories {
*
* @return bgp message generic reader
*/
- public static BGPMessageReader<BGPMessage> getGenericReader() {
+ public static BgpMessageReader<BgpMessage> getGenericReader() {
return GENERIC_READER;
}
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPFactory.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpFactory.java
index cf6bf008..11a85ff8 100755
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPFactory.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpFactory.java
@@ -21,40 +21,40 @@ package org.onosproject.bgpio.protocol;
* and objects.
*
*/
-public interface BGPFactory {
+public interface BgpFactory {
/**
* Gets the builder object for a open message.
*
* @return builder object for open message
*/
- BGPOpenMsg.Builder openMessageBuilder();
+ BgpOpenMsg.Builder openMessageBuilder();
/**
* Gets the builder object for a keepalive message.
*
* @return builder object for keepalive message
*/
- BGPKeepaliveMsg.Builder keepaliveMessageBuilder();
+ BgpKeepaliveMsg.Builder keepaliveMessageBuilder();
/**
* Gets the builder object for a notification message.
*
* @return builder object for notification message.
*/
- BGPNotificationMsg.Builder notificationMessageBuilder();
+ BgpNotificationMsg.Builder notificationMessageBuilder();
/**
* Gets the BGP message reader.
*
* @return BGP message reader
*/
- BGPMessageReader<BGPMessage> getReader();
+ BgpMessageReader<BgpMessage> getReader();
/**
* Returns BGP version.
*
* @return BGP version
*/
- BGPVersion getVersion();
+ BgpVersion getVersion();
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPKeepaliveMsg.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpKeepaliveMsg.java
index ae773889..0cb776a0 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPKeepaliveMsg.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpKeepaliveMsg.java
@@ -16,33 +16,33 @@
package org.onosproject.bgpio.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.types.BGPHeader;
+import org.onosproject.bgpio.types.BgpHeader;
/**
* Abstraction of an entity providing BGP Keepalive Message.
*/
-public interface BGPKeepaliveMsg extends BGPMessage {
+public interface BgpKeepaliveMsg extends BgpMessage {
@Override
- BGPVersion getVersion();
+ BgpVersion getVersion();
@Override
- BGPType getType();
+ BgpType getType();
@Override
void writeTo(ChannelBuffer channelBuffer);
@Override
- BGPHeader getHeader();
+ BgpHeader getHeader();
/**
* Builder interface with get and set functions to build Keepalive message.
*/
- interface Builder extends BGPMessage.Builder {
+ interface Builder extends BgpMessage.Builder {
@Override
- BGPKeepaliveMsg build();
+ BgpKeepaliveMsg build();
@Override
- Builder setHeader(BGPHeader bgpMsgHeader);
+ Builder setHeader(BgpHeader bgpMsgHeader);
}
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPLSNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLSNlri.java
index 189edb88..dd8857a7 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPLSNlri.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLSNlri.java
@@ -15,14 +15,14 @@
*/
package org.onosproject.bgpio.protocol;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4.PROTOCOLTYPE;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType;
import org.onosproject.bgpio.types.RouteDistinguisher;
/**
* Abstraction of an entity providing BGP-LS NLRI.
*/
-public interface BGPLSNlri {
+public interface BgpLSNlri {
/**
* Returns NlriType of BGP-LS NLRI.
*
@@ -41,9 +41,9 @@ public interface BGPLSNlri {
* Returns Protocol Id in Nlri.
*
* @return Protocol Id in Nlri
- * @throws BGPParseException while getting protocol ID
+ * @throws BgpParseException while getting protocol ID
*/
- PROTOCOLTYPE getProtocolId() throws BGPParseException;
+ ProtocolType getProtocolId() throws BgpParseException;
/**
* Returns Route distinguisher in Nlri.
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java
index dab7a3d2..3924a13b 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java
@@ -17,13 +17,13 @@ package org.onosproject.bgpio.protocol;
import java.util.List;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors;
/**
* Abstraction of an entity providing BGP-LS Link NLRI.
*/
-public interface BgpLinkLsNlri extends BGPLSNlri {
+public interface BgpLinkLsNlri extends BgpLSNlri {
/**
* Returns local node descriptors.
*
@@ -43,5 +43,5 @@ public interface BgpLinkLsNlri extends BGPLSNlri {
*
* @return link descriptors
*/
- List<BGPValueType> linkDescriptors();
+ List<BgpValueType> linkDescriptors();
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPMessage.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpMessage.java
index 309ef435..f1e1b96f 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPMessage.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpMessage.java
@@ -17,36 +17,36 @@
package org.onosproject.bgpio.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPHeader;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpHeader;
/**
* Abstraction of an entity providing BGP Messages.
*/
-public interface BGPMessage extends Writeable {
+public interface BgpMessage extends Writeable {
/**
* Returns BGP Header of BGP Message.
*
* @return BGP Header of BGP Message
*/
- BGPHeader getHeader();
+ BgpHeader getHeader();
/**
* Returns version of BGP Message.
*
* @return version of BGP Message
*/
- BGPVersion getVersion();
+ BgpVersion getVersion();
/**
* Returns BGP Type of BGP Message.
*
* @return BGP Type of BGP Message
*/
- BGPType getType();
+ BgpType getType();
@Override
- void writeTo(ChannelBuffer cb) throws BGPParseException;
+ void writeTo(ChannelBuffer cb) throws BgpParseException;
/**
* Builder interface with get and set functions to build BGP Message.
@@ -56,9 +56,9 @@ public interface BGPMessage extends Writeable {
* Builds BGP Message.
*
* @return BGP Message
- * @throws BGPParseException while building bgp message
+ * @throws BgpParseException while building bgp message
*/
- BGPMessage build() throws BGPParseException;
+ BgpMessage build() throws BgpParseException;
/**
* Sets BgpHeader and return its builder.
@@ -66,6 +66,6 @@ public interface BGPMessage extends Writeable {
* @param bgpMsgHeader BGP Message Header
* @return builder by setting BGP message header
*/
- Builder setHeader(BGPHeader bgpMsgHeader);
+ Builder setHeader(BgpHeader bgpMsgHeader);
}
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPMessageReader.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpMessageReader.java
index 18b8f58d..b8318b29 100755
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPMessageReader.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpMessageReader.java
@@ -16,13 +16,13 @@
package org.onosproject.bgpio.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPHeader;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpHeader;
/**
* Abstraction of an entity providing BGP Message Reader.
*/
-public interface BGPMessageReader<T> {
+public interface BgpMessageReader<T> {
/**
* Reads the Objects in the BGP Message and Returns BGP Message.
@@ -30,7 +30,7 @@ public interface BGPMessageReader<T> {
* @param cb Channel Buffer
* @param bgpHeader BGP message header
* @return BGP Message
- * @throws BGPParseException while parsing BGP message.
+ * @throws BgpParseException while parsing BGP message.
*/
- T readFrom(ChannelBuffer cb, BGPHeader bgpHeader) throws BGPParseException;
+ T readFrom(ChannelBuffer cb, BgpHeader bgpHeader) throws BgpParseException;
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPMessageWriter.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpMessageWriter.java
index 11f161c4..bb75b5ea 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPMessageWriter.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpMessageWriter.java
@@ -17,20 +17,20 @@
package org.onosproject.bgpio.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.exceptions.BgpParseException;
/**
* Abstraction of an entity providing BGP Message Writer.
*/
-public interface BGPMessageWriter<T> {
+public interface BgpMessageWriter<T> {
/**
* Writes the Objects of the BGP Message into Channel Buffer.
*
* @param cb Channel Buffer
* @param message BGP Message
- * @throws BGPParseException
+ * @throws BgpParseException
* While writing message
*/
- void write(ChannelBuffer cb, T message) throws BGPParseException;
+ void write(ChannelBuffer cb, T message) throws BgpParseException;
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPNodeLSNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpNodeLSNlri.java
index b6e4a3a0..13ef5cc5 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPNodeLSNlri.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpNodeLSNlri.java
@@ -15,16 +15,16 @@
*/
package org.onosproject.bgpio.protocol;
-import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSIdentifier;
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier;
/**
* Abstraction of an entity providing BGP-LS Node NLRI.
*/
-public interface BGPNodeLSNlri extends BGPLSNlri {
+public interface BgpNodeLSNlri extends BgpLSNlri {
/**
* Returns local node descriptors.
*
* @return local node descriptors
*/
- BGPNodeLSIdentifier getLocalNodeDescriptors();
+ BgpNodeLSIdentifier getLocalNodeDescriptors();
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPNotificationMsg.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpNotificationMsg.java
index a1d9d578..e3361aa7 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPNotificationMsg.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpNotificationMsg.java
@@ -15,12 +15,12 @@
*/
package org.onosproject.bgpio.protocol;
-import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.exceptions.BgpParseException;
/**
* Abstraction of an entity providing BGP notification message.
*/
-public interface BGPNotificationMsg extends BGPMessage {
+public interface BgpNotificationMsg extends BgpMessage {
/**
* Returns errorCode in notification message.
*
@@ -45,10 +45,10 @@ public interface BGPNotificationMsg extends BGPMessage {
/**
* Builder interface with get and set functions to build notification message.
*/
- public interface Builder extends BGPMessage.Builder {
+ public interface Builder extends BgpMessage.Builder {
@Override
- BGPNotificationMsg build() throws BGPParseException;
+ BgpNotificationMsg build() throws BgpParseException;
/**
* Sets errorCode in notification message and return its builder.
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPOpenMsg.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpOpenMsg.java
index bf5d05f4..94ec2235 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPOpenMsg.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpOpenMsg.java
@@ -17,23 +17,23 @@ package org.onosproject.bgpio.protocol;
import java.util.LinkedList;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPHeader;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpHeader;
+import org.onosproject.bgpio.types.BgpValueType;
/**
* Abstraction of an entity providing BGP Open Message.
*/
-public interface BGPOpenMsg extends BGPMessage {
+public interface BgpOpenMsg extends BgpMessage {
@Override
- BGPHeader getHeader();
+ BgpHeader getHeader();
@Override
- BGPVersion getVersion();
+ BgpVersion getVersion();
@Override
- BGPType getType();
+ BgpType getType();
/**
* Returns hold time of Open Message.
@@ -61,15 +61,15 @@ public interface BGPOpenMsg extends BGPMessage {
*
* @return capabilities of Open Message
*/
- LinkedList<BGPValueType> getCapabilityTlv();
+ LinkedList<BgpValueType> getCapabilityTlv();
/**
* Builder interface with get and set functions to build Open message.
*/
- interface Builder extends BGPMessage.Builder {
+ interface Builder extends BgpMessage.Builder {
@Override
- BGPOpenMsg build() throws BGPParseException;
+ BgpOpenMsg build() throws BgpParseException;
/**
* Sets hold time in Open Message and return its builder.
@@ -101,7 +101,7 @@ public interface BGPOpenMsg extends BGPMessage {
* @param capabilityTlv capabilities in open message
* @return builder by setting capabilities
*/
- Builder setCapabilityTlv(LinkedList<BGPValueType> capabilityTlv);
+ Builder setCapabilityTlv(LinkedList<BgpValueType> capabilityTlv);
/**
* Sets isLargeAsCapabilityTlvSet and return its builder.
@@ -122,6 +122,6 @@ public interface BGPOpenMsg extends BGPMessage {
Builder setLsCapabilityTlv(boolean isLsCapabilitySet);
@Override
- Builder setHeader(BGPHeader bgpMsgHeader);
+ Builder setHeader(BgpHeader bgpMsgHeader);
}
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPPrefixLSNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpPrefixLSNlri.java
index 2c331a2e..54bcdba3 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPPrefixLSNlri.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpPrefixLSNlri.java
@@ -15,15 +15,15 @@
*/
package org.onosproject.bgpio.protocol;
-import java.util.LinkedList;
+import java.util.List;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors;
/**
* Abstraction of an entity providing BGP-LS Prefix NLRI.
*/
-public interface BGPPrefixLSNlri extends BGPLSNlri {
+public interface BgpPrefixLSNlri extends BgpLSNlri {
/**
* Returns local node descriptors.
*
@@ -36,5 +36,5 @@ public interface BGPPrefixLSNlri extends BGPLSNlri {
*
* @return list of Prefix descriptor
*/
- LinkedList<BGPValueType> getPrefixdescriptor();
+ List<BgpValueType> getPrefixdescriptor();
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPType.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpType.java
index d3349156..b90721d5 100755
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPType.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpType.java
@@ -19,7 +19,7 @@ package org.onosproject.bgpio.protocol;
/**
* Enum to Provide the Different types of BGP messages.
*/
-public enum BGPType {
+public enum BgpType {
NONE(0), OPEN(1), UPDATE(2), NOTIFICATION(3), KEEP_ALIVE(4);
@@ -30,7 +30,7 @@ public enum BGPType {
*
* @param val type of BGP message
*/
- BGPType(int val) {
+ BgpType(int val) {
value = val;
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java
index 969936c8..d79a4236 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java
@@ -24,7 +24,7 @@ import org.onosproject.bgpio.protocol.ver4.BgpPathAttributes;
/**
* Abstraction of an entity providing BGP Update Message.
*/
-public interface BgpUpdateMsg extends BGPMessage {
+public interface BgpUpdateMsg extends BgpMessage {
/**
* Returns path attributes in BGP Update Message.
*
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPVersion.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpVersion.java
index 97bc7dce..b1f037f4 100755
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPVersion.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpVersion.java
@@ -19,7 +19,7 @@ package org.onosproject.bgpio.protocol;
/**
* Enum to provide BGP Message Version.
*/
-public enum BGPVersion {
+public enum BgpVersion {
BGP_4(4);
@@ -30,7 +30,7 @@ public enum BGPVersion {
*
* @param packetVersion version of BGP
*/
- BGPVersion(final int packetVersion) {
+ BgpVersion(final int packetVersion) {
this.packetVersion = packetVersion;
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/Writeable.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/Writeable.java
index 72df7f32..1c6f7fc2 100755
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/Writeable.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/Writeable.java
@@ -17,7 +17,7 @@
package org.onosproject.bgpio.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.exceptions.BgpParseException;
/**
* Abstraction of an entity providing functionality to write byte streams of
@@ -29,7 +29,7 @@ public interface Writeable {
* Writes byte streams of messages to channel buffer.
*
* @param cb channelBuffer
- * @throws BGPParseException when error occurs while writing BGP message to channel buffer
+ * @throws BgpParseException when error occurs while writing BGP message to channel buffer
*/
- void writeTo(ChannelBuffer cb) throws BGPParseException;
+ void writeTo(ChannelBuffer cb) throws BgpParseException;
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPLinkLSIdentifier.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpLinkLSIdentifier.java
index ffea74db..3967a221 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPLinkLSIdentifier.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpLinkLSIdentifier.java
@@ -18,16 +18,18 @@ package org.onosproject.bgpio.protocol.linkstate;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.ListIterator;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.types.IPv4AddressTlv;
import org.onosproject.bgpio.types.IPv6AddressTlv;
import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv;
import org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId;
+import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.UnSupportedAttribute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,22 +40,21 @@ import com.google.common.base.Preconditions;
/**
* Implementation of local node descriptors, remote node descriptors and link descriptors.
*/
-public class BGPLinkLSIdentifier {
- private static final Logger log = LoggerFactory.getLogger(BGPLinkLSIdentifier.class);
+public class BgpLinkLSIdentifier implements Comparable<Object> {
+ private static final Logger log = LoggerFactory.getLogger(BgpLinkLSIdentifier.class);
public static final short IPV4_INTERFACE_ADDRESS_TYPE = 259;
public static final short IPV4_NEIGHBOR_ADDRESS_TYPE = 260;
public static final short IPV6_INTERFACE_ADDRESS_TYPE = 261;
public static final short IPV6_NEIGHBOR_ADDRESS_TYPE = 262;
- public static final int TYPE_AND_LEN = 4;
private NodeDescriptors localNodeDescriptors;
private NodeDescriptors remoteNodeDescriptors;
- private List<BGPValueType> linkDescriptor;
+ private List<BgpValueType> linkDescriptor;
/**
* Initialize fields.
*/
- public BGPLinkLSIdentifier() {
+ public BgpLinkLSIdentifier() {
this.localNodeDescriptors = null;
this.remoteNodeDescriptors = null;
this.linkDescriptor = null;
@@ -66,8 +67,8 @@ public class BGPLinkLSIdentifier {
* @param remoteNodeDescriptors remote node descriptors
* @param linkDescriptor link descriptors
*/
- public BGPLinkLSIdentifier(NodeDescriptors localNodeDescriptors, NodeDescriptors remoteNodeDescriptors,
- LinkedList<BGPValueType> linkDescriptor) {
+ public BgpLinkLSIdentifier(NodeDescriptors localNodeDescriptors, NodeDescriptors remoteNodeDescriptors,
+ LinkedList<BgpValueType> linkDescriptor) {
this.localNodeDescriptors = Preconditions.checkNotNull(localNodeDescriptors);
this.remoteNodeDescriptors = Preconditions.checkNotNull(remoteNodeDescriptors);
this.linkDescriptor = Preconditions.checkNotNull(linkDescriptor);
@@ -79,9 +80,9 @@ public class BGPLinkLSIdentifier {
* @param cb ChannelBuffer
* @param protocolId in linkstate nlri
* @return object of BGPLinkLSIdentifier
- * @throws BGPParseException while parsing link identifier
+ * @throws BgpParseException while parsing link identifier
*/
- public static BGPLinkLSIdentifier parseLinkIdendifier(ChannelBuffer cb, byte protocolId) throws BGPParseException {
+ public static BgpLinkLSIdentifier parseLinkIdendifier(ChannelBuffer cb, byte protocolId) throws BgpParseException {
//Parse local node descriptor
NodeDescriptors localNodeDescriptors = new NodeDescriptors();
localNodeDescriptors = parseNodeDescriptors(cb, NodeDescriptors.LOCAL_NODE_DES_TYPE, protocolId);
@@ -91,9 +92,9 @@ public class BGPLinkLSIdentifier {
remoteNodeDescriptors = parseNodeDescriptors(cb, NodeDescriptors.REMOTE_NODE_DES_TYPE, protocolId);
//Parse link descriptor
- LinkedList<BGPValueType> linkDescriptor = new LinkedList<>();
+ LinkedList<BgpValueType> linkDescriptor = new LinkedList<>();
linkDescriptor = parseLinkDescriptors(cb);
- return new BGPLinkLSIdentifier(localNodeDescriptors, remoteNodeDescriptors, linkDescriptor);
+ return new BgpLinkLSIdentifier(localNodeDescriptors, remoteNodeDescriptors, linkDescriptor);
}
/**
@@ -103,16 +104,17 @@ public class BGPLinkLSIdentifier {
* @param desType descriptor type
* @param protocolId protocol identifier
* @return object of NodeDescriptors
- * @throws BGPParseException while parsing Local/Remote node descriptors
+ * @throws BgpParseException while parsing Local/Remote node descriptors
*/
public static NodeDescriptors parseNodeDescriptors(ChannelBuffer cb, short desType, byte protocolId)
- throws BGPParseException {
- ChannelBuffer tempBuf = cb;
+ throws BgpParseException {
+ log.debug("parse Node descriptors");
+ ChannelBuffer tempBuf = cb.copy();
short type = cb.readShort();
short length = cb.readShort();
if (cb.readableBytes() < length) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
- tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN));
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
+ tempBuf.readBytes(cb.readableBytes() + Constants.TYPE_AND_LEN_AS_SHORT));
}
NodeDescriptors nodeIdentifier = new NodeDescriptors();
ChannelBuffer tempCb = cb.readBytes(length);
@@ -120,7 +122,7 @@ public class BGPLinkLSIdentifier {
if (type == desType) {
nodeIdentifier = NodeDescriptors.read(tempCb, length, desType, protocolId);
} else {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.MALFORMED_ATTRIBUTE_LIST, null);
}
return nodeIdentifier;
}
@@ -130,20 +132,20 @@ public class BGPLinkLSIdentifier {
*
* @param cb ChannelBuffer
* @return list of link descriptors
- * @throws BGPParseException while parsing link descriptors
+ * @throws BgpParseException while parsing link descriptors
*/
- public static LinkedList<BGPValueType> parseLinkDescriptors(ChannelBuffer cb) throws BGPParseException {
- LinkedList<BGPValueType> linkDescriptor = new LinkedList<>();
- BGPValueType tlv = null;
+ public static LinkedList<BgpValueType> parseLinkDescriptors(ChannelBuffer cb) throws BgpParseException {
+ LinkedList<BgpValueType> linkDescriptor = new LinkedList<>();
+ BgpValueType tlv = null;
int count = 0;
while (cb.readableBytes() > 0) {
- ChannelBuffer tempBuf = cb;
+ ChannelBuffer tempBuf = cb.copy();
short type = cb.readShort();
short length = cb.readShort();
if (cb.readableBytes() < length) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
- tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN));
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
+ tempBuf.readBytes(cb.readableBytes() + Constants.TYPE_AND_LEN_AS_SHORT));
}
ChannelBuffer tempCb = cb.readBytes(length);
switch (type) {
@@ -168,9 +170,9 @@ public class BGPLinkLSIdentifier {
//MultiTopologyId TLV cannot repeat more than once
if (count > 1) {
//length + 4 implies data contains type, length and value
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR, tempBuf.readBytes(length
- + TYPE_AND_LEN));
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR, tempBuf.readBytes(length
+ + Constants.TYPE_AND_LEN_AS_SHORT));
}
break;
default:
@@ -204,7 +206,7 @@ public class BGPLinkLSIdentifier {
*
* @return link descriptors
*/
- public List<BGPValueType> linkDescriptors() {
+ public List<BgpValueType> linkDescriptors() {
return this.linkDescriptor;
}
@@ -218,21 +220,25 @@ public class BGPLinkLSIdentifier {
if (this == obj) {
return true;
}
- if (obj instanceof BGPLinkLSIdentifier) {
+ if (obj instanceof BgpLinkLSIdentifier) {
int countObjSubTlv = 0;
int countOtherSubTlv = 0;
boolean isCommonSubTlv = true;
- BGPLinkLSIdentifier other = (BGPLinkLSIdentifier) obj;
- Iterator<BGPValueType> objListIterator = other.linkDescriptor.iterator();
+ BgpLinkLSIdentifier other = (BgpLinkLSIdentifier) obj;
+ Iterator<BgpValueType> objListIterator = other.linkDescriptor.iterator();
countOtherSubTlv = other.linkDescriptor.size();
countObjSubTlv = linkDescriptor.size();
if (countObjSubTlv != countOtherSubTlv) {
return false;
} else {
while (objListIterator.hasNext() && isCommonSubTlv) {
- BGPValueType subTlv = objListIterator.next();
- isCommonSubTlv = Objects.equals(linkDescriptor.contains(subTlv),
- other.linkDescriptor.contains(subTlv));
+ BgpValueType subTlv = objListIterator.next();
+ if (linkDescriptor.contains(subTlv) && other.linkDescriptor.contains(subTlv)) {
+ isCommonSubTlv = Objects.equals(linkDescriptor.get(linkDescriptor.indexOf(subTlv)),
+ other.linkDescriptor.get(other.linkDescriptor.indexOf(subTlv)));
+ } else {
+ isCommonSubTlv = false;
+ }
}
return isCommonSubTlv && Objects.equals(this.localNodeDescriptors, other.localNodeDescriptors)
&& Objects.equals(this.remoteNodeDescriptors, other.remoteNodeDescriptors);
@@ -249,4 +255,42 @@ public class BGPLinkLSIdentifier {
.add("linkDescriptor", linkDescriptor)
.toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ int result = this.localNodeDescriptors.compareTo(((BgpLinkLSIdentifier) o).localNodeDescriptors);
+ if (result != 0) {
+ return result;
+ } else if (this.remoteNodeDescriptors.compareTo(((BgpLinkLSIdentifier) o).remoteNodeDescriptors) != 0) {
+ return this.remoteNodeDescriptors.compareTo(((BgpLinkLSIdentifier) o).remoteNodeDescriptors);
+ } else {
+ int countOtherSubTlv = ((BgpLinkLSIdentifier) o).linkDescriptor.size();
+ int countObjSubTlv = linkDescriptor.size();
+ if (countOtherSubTlv != countObjSubTlv) {
+ if (countOtherSubTlv > countObjSubTlv) {
+ return 1;
+ } else {
+ return -1;
+ }
+ }
+ ListIterator<BgpValueType> listIterator = linkDescriptor.listIterator();
+ ListIterator<BgpValueType> listIteratorOther = ((BgpLinkLSIdentifier) o).linkDescriptor.listIterator();
+ while (listIterator.hasNext()) {
+ BgpValueType tlv = listIterator.next();
+ BgpValueType tlv1 = listIteratorOther.next();
+ if (linkDescriptor.contains(tlv) && ((BgpLinkLSIdentifier) o).linkDescriptor.contains(tlv1)) {
+ int res = linkDescriptor.get(linkDescriptor.indexOf(tlv)).compareTo(
+ ((BgpLinkLSIdentifier) o).linkDescriptor.get(((BgpLinkLSIdentifier) o).linkDescriptor
+ .indexOf(tlv1)));
+ if (res != 0) {
+ return res;
+ }
+ }
+ }
+ }
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpLinkLsNlriVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpLinkLsNlriVer4.java
new file mode 100755
index 00000000..01d369e4
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpLinkLsNlriVer4.java
@@ -0,0 +1,210 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.protocol.linkstate;
+
+import java.util.List;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpLinkLsNlri;
+import org.onosproject.bgpio.protocol.NlriType;
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.types.RouteDistinguisher;
+import org.onosproject.bgpio.util.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implementation of Link LS NLRI.
+ */
+public class BgpLinkLsNlriVer4 implements BgpLinkLsNlri {
+
+ /*
+ * REFERENCE : draft-ietf-idr-ls-distribution-11
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+
+ | Protocol-ID |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Identifier |
+ | (64 bits) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ // Local Node Descriptors (variable) //
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ // Remote Node Descriptors (variable) //
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ // Link Descriptors (variable) //
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Figure : The Link NLRI format
+ */
+ private static final Logger log = LoggerFactory.getLogger(BgpLinkLsNlriVer4.class);
+ public static final int LINK_NLRITYPE = 2;
+
+ private BgpLinkLSIdentifier linkLSIdentifier;
+ private byte protocolId;
+ private long identifier;
+ private RouteDistinguisher routeDistinguisher;
+ private boolean isVpn;
+
+ /**
+ * Initialize fields.
+ */
+ public BgpLinkLsNlriVer4() {
+ this.protocolId = 0;
+ this.identifier = 0;
+ this.linkLSIdentifier = null;
+ this.routeDistinguisher = null;
+ this.isVpn = false;
+ }
+
+ /**
+ * Constructor to initialize parameters for BGP LinkLSNlri.
+ *
+ * @param protocolId protocol Id
+ * @param identifier field in BGP LinkLSNlri
+ * @param linkLSIdentifier link LS identifier
+ * @param routeDistinguisher route distinguisher from message
+ * @param isVpn vpn info availability in message
+ */
+ public BgpLinkLsNlriVer4(byte protocolId, long identifier, BgpLinkLSIdentifier linkLSIdentifier,
+ RouteDistinguisher routeDistinguisher, boolean isVpn) {
+ this.protocolId = protocolId;
+ this.identifier = identifier;
+ this.linkLSIdentifier = linkLSIdentifier;
+ this.routeDistinguisher = routeDistinguisher;
+ this.isVpn = isVpn;
+ }
+
+ /**
+ * Reads from channelBuffer and parses Link LS Nlri.
+ *
+ * @param cb ChannelBuffer
+ * @param afi Address Family Identifier
+ * @param safi Subsequent Address Family Identifier
+ * @return object of this class
+ * @throws BgpParseException while parsing Link LS NLRI
+ */
+ public static BgpLinkLsNlriVer4 read(ChannelBuffer cb, short afi, byte safi) throws BgpParseException {
+ boolean isVpn = false;
+ RouteDistinguisher routeDistinguisher = null;
+ if ((afi == Constants.AFI_VALUE) && (safi == Constants.VPN_SAFI_VALUE)) {
+ routeDistinguisher = new RouteDistinguisher();
+ routeDistinguisher = RouteDistinguisher.read(cb);
+ isVpn = true;
+ } else {
+ isVpn = false;
+ }
+ byte protocolId = cb.readByte();
+ long identifier = cb.readLong();
+
+ BgpLinkLSIdentifier linkLSIdentifier = new BgpLinkLSIdentifier();
+ linkLSIdentifier = BgpLinkLSIdentifier.parseLinkIdendifier(cb, protocolId);
+ return new BgpLinkLsNlriVer4(protocolId, identifier, linkLSIdentifier, routeDistinguisher, isVpn);
+ }
+
+ @Override
+ public NlriType getNlriType() {
+ return NlriType.LINK;
+ }
+
+ @Override
+ public long getIdentifier() {
+ return this.identifier;
+ }
+
+ /**
+ * Set the link LS identifier.
+ *
+ * @param linkLSIdentifier link LS identifier to set
+ */
+ public void setLinkLSIdentifier(BgpLinkLSIdentifier linkLSIdentifier) {
+ this.linkLSIdentifier = linkLSIdentifier;
+ }
+
+ @Override
+ public ProtocolType getProtocolId() throws BgpParseException {
+ switch (protocolId) {
+ case Constants.ISIS_LEVELONE:
+ return ProtocolType.ISIS_LEVEL_ONE;
+ case Constants.ISIS_LEVELTWO:
+ return ProtocolType.ISIS_LEVEL_TWO;
+ case Constants.OSPFV2:
+ return ProtocolType.OSPF_V2;
+ case Constants.DIRECT:
+ return ProtocolType.DIRECT;
+ case Constants.STATIC_CONFIGURATION:
+ return ProtocolType.STATIC_CONFIGURATION;
+ case Constants.OSPFV3:
+ return ProtocolType.OSPF_V3;
+ default:
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
+ }
+ }
+
+ @Override
+ public NodeDescriptors localNodeDescriptors() {
+ return this.linkLSIdentifier.localNodeDescriptors();
+ }
+
+ @Override
+ public NodeDescriptors remoteNodeDescriptors() {
+ return this.linkLSIdentifier.remoteNodeDescriptors();
+ }
+
+ /**
+ * Returns whether VPN is present or not.
+ *
+ * @return whether VPN is present or not
+ */
+ public boolean isVpnPresent() {
+ return this.isVpn;
+ }
+
+ @Override
+ public RouteDistinguisher getRouteDistinguisher() {
+ return this.routeDistinguisher;
+ }
+
+ /**
+ * Returns link identifier.
+ *
+ * @return link identifier
+ */
+ public BgpLinkLSIdentifier getLinkIdentifier() {
+ return this.linkLSIdentifier;
+ }
+
+ @Override
+ public List<BgpValueType> linkDescriptors() {
+ return this.linkLSIdentifier.linkDescriptors();
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("protocolId", protocolId)
+ .add("identifier", identifier)
+ .add("RouteDistinguisher ", routeDistinguisher)
+ .add("linkLSIdentifier", linkLSIdentifier)
+ .toString();
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSIdentifier.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpNodeLSIdentifier.java
index 603bf6ec..6c2c96d9 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSIdentifier.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpNodeLSIdentifier.java
@@ -18,8 +18,8 @@ package org.onosproject.bgpio.protocol.linkstate;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
import org.onosproject.bgpio.util.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -29,15 +29,15 @@ import com.google.common.base.MoreObjects;
/**
* Implementation of Node Identifier which includes local node descriptor/remote node descriptors.
*/
-public class BGPNodeLSIdentifier {
+public class BgpNodeLSIdentifier implements Comparable<Object> {
- protected static final Logger log = LoggerFactory.getLogger(BGPNodeLSIdentifier.class);
+ private static final Logger log = LoggerFactory.getLogger(BgpNodeLSIdentifier.class);
private NodeDescriptors nodeDescriptors;
/**
* Resets fields.
*/
- public BGPNodeLSIdentifier() {
+ public BgpNodeLSIdentifier() {
this.nodeDescriptors = null;
}
@@ -46,7 +46,7 @@ public class BGPNodeLSIdentifier {
*
* @param nodeDescriptors local/remote node descriptor
*/
- public BGPNodeLSIdentifier(NodeDescriptors nodeDescriptors) {
+ public BgpNodeLSIdentifier(NodeDescriptors nodeDescriptors) {
this.nodeDescriptors = nodeDescriptors;
}
@@ -56,15 +56,16 @@ public class BGPNodeLSIdentifier {
* @param cb ChannelBuffer
* @param protocolId protocol identifier
* @return object of this BGPNodeLSIdentifier
- * @throws BGPParseException while parsing local node descriptors
+ * @throws BgpParseException while parsing local node descriptors
*/
- public static BGPNodeLSIdentifier parseLocalNodeDescriptors(ChannelBuffer cb, byte protocolId)
- throws BGPParseException {
- ChannelBuffer tempBuf = cb;
+ public static BgpNodeLSIdentifier parseLocalNodeDescriptors(ChannelBuffer cb, byte protocolId)
+ throws BgpParseException {
+ log.debug("parse Local node descriptor");
+ ChannelBuffer tempBuf = cb.copy();
short type = cb.readShort();
short length = cb.readShort();
if (cb.readableBytes() < length) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
tempBuf.readBytes(cb.readableBytes() + Constants.TYPE_AND_LEN));
}
NodeDescriptors nodeDescriptors = new NodeDescriptors();
@@ -73,9 +74,9 @@ public class BGPNodeLSIdentifier {
if (type == NodeDescriptors.LOCAL_NODE_DES_TYPE) {
nodeDescriptors = NodeDescriptors.read(tempCb, length, type, protocolId);
} else {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.MALFORMED_ATTRIBUTE_LIST, null);
}
- return new BGPNodeLSIdentifier(nodeDescriptors);
+ return new BgpNodeLSIdentifier(nodeDescriptors);
}
/**
@@ -92,8 +93,8 @@ public class BGPNodeLSIdentifier {
if (this == obj) {
return true;
}
- if (obj instanceof BGPNodeLSIdentifier) {
- BGPNodeLSIdentifier other = (BGPNodeLSIdentifier) obj;
+ if (obj instanceof BgpNodeLSIdentifier) {
+ BgpNodeLSIdentifier other = (BgpNodeLSIdentifier) obj;
return Objects.equals(nodeDescriptors, other.nodeDescriptors);
}
return false;
@@ -110,4 +111,12 @@ public class BGPNodeLSIdentifier {
.add("NodeDescriptors", nodeDescriptors)
.toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ return this.nodeDescriptors.compareTo(((BgpNodeLSIdentifier) o).nodeDescriptors);
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSNlriVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpNodeLSNlriVer4.java
index 54837ee8..b27096cf 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSNlriVer4.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpNodeLSNlriVer4.java
@@ -16,10 +16,10 @@
package org.onosproject.bgpio.protocol.linkstate;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.protocol.BGPNodeLSNlri;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpNodeLSNlri;
import org.onosproject.bgpio.protocol.NlriType;
-import org.onosproject.bgpio.types.BGPErrorType;
+import org.onosproject.bgpio.types.BgpErrorType;
import org.onosproject.bgpio.types.RouteDistinguisher;
import org.onosproject.bgpio.util.Constants;
import org.slf4j.Logger;
@@ -30,7 +30,7 @@ import com.google.common.base.MoreObjects;
/**
* Implementation of Node LS NLRI.
*/
-public class BGPNodeLSNlriVer4 implements BGPNodeLSNlri {
+public class BgpNodeLSNlriVer4 implements BgpNodeLSNlri {
/*
*REFERENCE : draft-ietf-idr-ls-distribution-11
@@ -48,21 +48,21 @@ public class BGPNodeLSNlriVer4 implements BGPNodeLSNlri {
Figure : The Node NLRI format
*/
- protected static final Logger log = LoggerFactory.getLogger(BGPNodeLSNlriVer4.class);
+ protected static final Logger log = LoggerFactory.getLogger(BgpNodeLSNlriVer4.class);
public static final int NODE_NLRITYPE = 1;
public static final int IDENTIFIER_LENGTH = 16;
private long identifier;
private byte protocolId;
- private BGPNodeLSIdentifier localNodeDescriptors;
+ private BgpNodeLSIdentifier localNodeDescriptors;
private RouteDistinguisher routeDistinguisher;
private boolean isVpn;
/**
* Enum to provide PROTOCOLTYPE.
*/
- public enum PROTOCOLTYPE {
- ISIS_LevelOne(1), ISIS_LevelTwo(2), OSPFv2(3), Direct(4), Static_Configuration(5), OSPFv3(6);
+ public enum ProtocolType {
+ ISIS_LEVEL_ONE(1), ISIS_LEVEL_TWO(2), OSPF_V2(3), DIRECT(4), STATIC_CONFIGURATION(5), OSPF_V3(6);
int value;
/**
@@ -70,7 +70,7 @@ public class BGPNodeLSNlriVer4 implements BGPNodeLSNlri {
*
* @param val protocol type
*/
- PROTOCOLTYPE(int val) {
+ ProtocolType(int val) {
value = val;
}
@@ -87,7 +87,7 @@ public class BGPNodeLSNlriVer4 implements BGPNodeLSNlri {
/**
* Reset fields.
*/
- public BGPNodeLSNlriVer4() {
+ public BgpNodeLSNlriVer4() {
this.identifier = 0;
this.protocolId = 0;
this.localNodeDescriptors = null;
@@ -104,7 +104,7 @@ public class BGPNodeLSNlriVer4 implements BGPNodeLSNlri {
* @param isVpn true if VPN info is present
* @param routeDistinguisher unique for each VPN
*/
- BGPNodeLSNlriVer4(long identifier, byte protocolId, BGPNodeLSIdentifier localNodeDescriptors, boolean isVpn,
+ public BgpNodeLSNlriVer4(long identifier, byte protocolId, BgpNodeLSIdentifier localNodeDescriptors, boolean isVpn,
RouteDistinguisher routeDistinguisher) {
this.identifier = identifier;
this.protocolId = protocolId;
@@ -120,9 +120,9 @@ public class BGPNodeLSNlriVer4 implements BGPNodeLSNlri {
* @param afi Address Family Identifier
* @param safi Subsequent Address Family Identifier
* @return object of this class
- * @throws BGPParseException while parsing node descriptors
+ * @throws BgpParseException while parsing node descriptors
*/
- public static BGPNodeLSNlriVer4 read(ChannelBuffer cb, short afi, byte safi) throws BGPParseException {
+ public static BgpNodeLSNlriVer4 read(ChannelBuffer cb, short afi, byte safi) throws BgpParseException {
boolean isVpn = false;
RouteDistinguisher routeDistinguisher = null;
if ((afi == Constants.AFI_VALUE) && (safi == Constants.VPN_SAFI_VALUE)) {
@@ -136,9 +136,9 @@ public class BGPNodeLSNlriVer4 implements BGPNodeLSNlri {
long identifier = cb.readLong();
// Parse Local Node Descriptors
- BGPNodeLSIdentifier localNodeDescriptors = new BGPNodeLSIdentifier();
- localNodeDescriptors = BGPNodeLSIdentifier.parseLocalNodeDescriptors(cb, protocolId);
- return new BGPNodeLSNlriVer4(identifier, protocolId, localNodeDescriptors, isVpn, routeDistinguisher);
+ BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier();
+ localNodeDescriptors = BgpNodeLSIdentifier.parseLocalNodeDescriptors(cb, protocolId);
+ return new BgpNodeLSNlriVer4(identifier, protocolId, localNodeDescriptors, isVpn, routeDistinguisher);
}
@Override
@@ -147,7 +147,7 @@ public class BGPNodeLSNlriVer4 implements BGPNodeLSNlri {
}
@Override
- public BGPNodeLSIdentifier getLocalNodeDescriptors() {
+ public BgpNodeLSIdentifier getLocalNodeDescriptors() {
return this.localNodeDescriptors;
}
@@ -175,27 +175,27 @@ public class BGPNodeLSNlriVer4 implements BGPNodeLSNlri {
*
* @param localNodeDescriptors node LS identifier to set
*/
- public void setNodeLSIdentifier(BGPNodeLSIdentifier localNodeDescriptors) {
+ public void setNodeLSIdentifier(BgpNodeLSIdentifier localNodeDescriptors) {
this.localNodeDescriptors = localNodeDescriptors;
}
@Override
- public PROTOCOLTYPE getProtocolId() throws BGPParseException {
+ public ProtocolType getProtocolId() throws BgpParseException {
switch (protocolId) {
case Constants.ISIS_LEVELONE:
- return PROTOCOLTYPE.ISIS_LevelOne;
+ return ProtocolType.ISIS_LEVEL_ONE;
case Constants.ISIS_LEVELTWO:
- return PROTOCOLTYPE.ISIS_LevelTwo;
+ return ProtocolType.ISIS_LEVEL_TWO;
case Constants.OSPFV2:
- return PROTOCOLTYPE.OSPFv2;
+ return ProtocolType.OSPF_V2;
case Constants.DIRECT:
- return PROTOCOLTYPE.Direct;
+ return ProtocolType.DIRECT;
case Constants.STATIC_CONFIGURATION:
- return PROTOCOLTYPE.Static_Configuration;
+ return ProtocolType.STATIC_CONFIGURATION;
case Constants.OSPFV3:
- return PROTOCOLTYPE.OSPFv3;
+ return ProtocolType.OSPF_V3;
default:
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
}
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixIPv4LSNlriVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpPrefixIPv4LSNlriVer4.java
index 6d6f48b1..49cb74bd 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixIPv4LSNlriVer4.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpPrefixIPv4LSNlriVer4.java
@@ -15,14 +15,14 @@
*/
package org.onosproject.bgpio.protocol.linkstate;
-import java.util.LinkedList;
+import java.util.List;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.protocol.BGPPrefixLSNlri;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpPrefixLSNlri;
import org.onosproject.bgpio.protocol.NlriType;
-import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4.PROTOCOLTYPE;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.types.RouteDistinguisher;
import org.onosproject.bgpio.util.Constants;
import org.slf4j.Logger;
@@ -33,7 +33,7 @@ import com.google.common.base.MoreObjects;
/**
* Implementation of Prefix IPV4 LS NLRI.
*/
-public class BGPPrefixIPv4LSNlriVer4 implements BGPPrefixLSNlri {
+public class BgpPrefixIPv4LSNlriVer4 implements BgpPrefixLSNlri {
/*
* REFERENCE : draft-ietf-idr-ls-distribution-11
@@ -53,7 +53,7 @@ public class BGPPrefixIPv4LSNlriVer4 implements BGPPrefixLSNlri {
Figure : The IPv4/IPv6 Topology Prefix NLRI format
*/
- protected static final Logger log = LoggerFactory.getLogger(BGPPrefixIPv4LSNlriVer4.class);
+ protected static final Logger log = LoggerFactory.getLogger(BgpPrefixIPv4LSNlriVer4.class);
public static final int PREFIX_IPV4_NLRITYPE = 3;
public static final int IDENTIFIER_LENGTH = 16;
@@ -61,12 +61,12 @@ public class BGPPrefixIPv4LSNlriVer4 implements BGPPrefixLSNlri {
private byte protocolId;
private RouteDistinguisher routeDistinguisher;
private boolean isVpn;
- private BGPPrefixLSIdentifier bgpPrefixLSIdentifier;
+ private BgpPrefixLSIdentifier bgpPrefixLSIdentifier;
/**
* Resets parameters.
*/
- public BGPPrefixIPv4LSNlriVer4() {
+ public BgpPrefixIPv4LSNlriVer4() {
this.identifier = 0;
this.protocolId = 0;
this.bgpPrefixLSIdentifier = null;
@@ -83,7 +83,7 @@ public class BGPPrefixIPv4LSNlriVer4 implements BGPPrefixLSNlri {
* @param routeDistinguisher RouteDistinguisher
* @param isVpn vpn availability in message
*/
- public BGPPrefixIPv4LSNlriVer4(long identifier, byte protocolId, BGPPrefixLSIdentifier bgpPrefixLSIdentifier,
+ public BgpPrefixIPv4LSNlriVer4(long identifier, byte protocolId, BgpPrefixLSIdentifier bgpPrefixLSIdentifier,
RouteDistinguisher routeDistinguisher, boolean isVpn) {
this.identifier = identifier;
this.protocolId = protocolId;
@@ -99,9 +99,9 @@ public class BGPPrefixIPv4LSNlriVer4 implements BGPPrefixLSNlri {
* @param afi Address family identifier
* @param safi Subsequent address family identifier
* @return object of BGPPrefixIPv4LSNlriVer4
- * @throws BGPParseException while parsing Prefix LS Nlri
+ * @throws BgpParseException while parsing Prefix LS Nlri
*/
- public static BGPPrefixIPv4LSNlriVer4 read(ChannelBuffer cb, short afi, byte safi) throws BGPParseException {
+ public static BgpPrefixIPv4LSNlriVer4 read(ChannelBuffer cb, short afi, byte safi) throws BgpParseException {
boolean isVpn = false;
RouteDistinguisher routeDistinguisher = null;
@@ -115,9 +115,9 @@ public class BGPPrefixIPv4LSNlriVer4 implements BGPPrefixLSNlri {
byte protocolId = cb.readByte();
long identifier = cb.readLong();
- BGPPrefixLSIdentifier bgpPrefixLSIdentifier = new BGPPrefixLSIdentifier();
- bgpPrefixLSIdentifier = BGPPrefixLSIdentifier.parsePrefixIdendifier(cb, protocolId);
- return new BGPPrefixIPv4LSNlriVer4(identifier, protocolId, bgpPrefixLSIdentifier, routeDistinguisher, isVpn);
+ BgpPrefixLSIdentifier bgpPrefixLSIdentifier = new BgpPrefixLSIdentifier();
+ bgpPrefixLSIdentifier = BgpPrefixLSIdentifier.parsePrefixIdendifier(cb, protocolId);
+ return new BgpPrefixIPv4LSNlriVer4(identifier, protocolId, bgpPrefixLSIdentifier, routeDistinguisher, isVpn);
}
@Override
@@ -140,27 +140,27 @@ public class BGPPrefixIPv4LSNlriVer4 implements BGPPrefixLSNlri {
*
* @param bgpPrefixLSIdentifier prefix identifier to set
*/
- public void setPrefixLSIdentifier(BGPPrefixLSIdentifier bgpPrefixLSIdentifier) {
+ public void setPrefixLSIdentifier(BgpPrefixLSIdentifier bgpPrefixLSIdentifier) {
this.bgpPrefixLSIdentifier = bgpPrefixLSIdentifier;
}
@Override
- public PROTOCOLTYPE getProtocolId() throws BGPParseException {
+ public ProtocolType getProtocolId() throws BgpParseException {
switch (protocolId) {
case Constants.ISIS_LEVELONE:
- return PROTOCOLTYPE.ISIS_LevelOne;
+ return ProtocolType.ISIS_LEVEL_ONE;
case Constants.ISIS_LEVELTWO:
- return PROTOCOLTYPE.ISIS_LevelTwo;
+ return ProtocolType.ISIS_LEVEL_TWO;
case Constants.OSPFV2:
- return PROTOCOLTYPE.OSPFv2;
+ return ProtocolType.OSPF_V2;
case Constants.DIRECT:
- return PROTOCOLTYPE.Direct;
+ return ProtocolType.DIRECT;
case Constants.STATIC_CONFIGURATION:
- return PROTOCOLTYPE.Static_Configuration;
+ return ProtocolType.STATIC_CONFIGURATION;
case Constants.OSPFV3:
- return PROTOCOLTYPE.OSPFv3;
+ return ProtocolType.OSPF_V3;
default:
- throw new BGPParseException("protocol id not valid");
+ throw new BgpParseException("protocol id not valid");
}
}
@@ -178,7 +178,7 @@ public class BGPPrefixIPv4LSNlriVer4 implements BGPPrefixLSNlri {
*
* @return Prefix Identifier
*/
- public BGPPrefixLSIdentifier getPrefixIdentifier() {
+ public BgpPrefixLSIdentifier getPrefixIdentifier() {
return this.bgpPrefixLSIdentifier;
}
@@ -188,7 +188,7 @@ public class BGPPrefixIPv4LSNlriVer4 implements BGPPrefixLSNlri {
}
@Override
- public LinkedList<BGPValueType> getPrefixdescriptor() {
+ public List<BgpValueType> getPrefixdescriptor() {
return this.bgpPrefixLSIdentifier.getPrefixdescriptor();
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixLSIdentifier.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpPrefixLSIdentifier.java
index 23f41794..d3beaaee 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixLSIdentifier.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BgpPrefixLSIdentifier.java
@@ -18,12 +18,14 @@ package org.onosproject.bgpio.protocol.linkstate;
import java.util.Iterator;
import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.types.IPReachabilityInformationTlv;
import org.onosproject.bgpio.types.OSPFRouteTypeTlv;
import org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId;
@@ -36,17 +38,17 @@ import com.google.common.base.MoreObjects;
/**
* Provides Implementation of Local node descriptors and prefix descriptors.
*/
-public class BGPPrefixLSIdentifier {
+public class BgpPrefixLSIdentifier implements Comparable<Object> {
- protected static final Logger log = LoggerFactory.getLogger(BGPPrefixLSIdentifier.class);
+ protected static final Logger log = LoggerFactory.getLogger(BgpPrefixLSIdentifier.class);
public static final int TYPE_AND_LEN = 4;
private NodeDescriptors localNodeDescriptors;
- private LinkedList<BGPValueType> prefixDescriptor;
+ private List<BgpValueType> prefixDescriptor;
/**
* Resets parameters.
*/
- public BGPPrefixLSIdentifier() {
+ public BgpPrefixLSIdentifier() {
this.localNodeDescriptors = null;
this.prefixDescriptor = null;
}
@@ -57,7 +59,7 @@ public class BGPPrefixLSIdentifier {
* @param localNodeDescriptors Local node descriptors
* @param prefixDescriptor Prefix Descriptors
*/
- public BGPPrefixLSIdentifier(NodeDescriptors localNodeDescriptors, LinkedList<BGPValueType> prefixDescriptor) {
+ public BgpPrefixLSIdentifier(NodeDescriptors localNodeDescriptors, List<BgpValueType> prefixDescriptor) {
this.localNodeDescriptors = localNodeDescriptors;
this.prefixDescriptor = prefixDescriptor;
}
@@ -68,18 +70,18 @@ public class BGPPrefixLSIdentifier {
* @param cb ChannelBuffer
* @param protocolId protocol ID
* @return object of this class
- * @throws BGPParseException while parsing Prefix Identifier
+ * @throws BgpParseException while parsing Prefix Identifier
*/
- public static BGPPrefixLSIdentifier parsePrefixIdendifier(ChannelBuffer cb, byte protocolId)
- throws BGPParseException {
+ public static BgpPrefixLSIdentifier parsePrefixIdendifier(ChannelBuffer cb, byte protocolId)
+ throws BgpParseException {
//Parse Local Node descriptor
NodeDescriptors localNodeDescriptors = new NodeDescriptors();
localNodeDescriptors = parseLocalNodeDescriptors(cb, protocolId);
//Parse Prefix descriptor
- LinkedList<BGPValueType> prefixDescriptor = new LinkedList<>();
+ List<BgpValueType> prefixDescriptor = new LinkedList<>();
prefixDescriptor = parsePrefixDescriptors(cb);
- return new BGPPrefixLSIdentifier(localNodeDescriptors, prefixDescriptor);
+ return new BgpPrefixLSIdentifier(localNodeDescriptors, prefixDescriptor);
}
/**
@@ -88,16 +90,16 @@ public class BGPPrefixLSIdentifier {
* @param cb ChannelBuffer
* @param protocolId protocol identifier
* @return LocalNodeDescriptors
- * @throws BGPParseException while parsing local node descriptors
+ * @throws BgpParseException while parsing local node descriptors
*/
public static NodeDescriptors parseLocalNodeDescriptors(ChannelBuffer cb, byte protocolId)
- throws BGPParseException {
- ChannelBuffer tempBuf = cb;
+ throws BgpParseException {
+ ChannelBuffer tempBuf = cb.copy();
short type = cb.readShort();
short length = cb.readShort();
if (cb.readableBytes() < length) {
//length + 4 implies data contains type, length and value
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN));
}
NodeDescriptors localNodeDescriptors = new NodeDescriptors();
@@ -106,8 +108,8 @@ public class BGPPrefixLSIdentifier {
if (type == NodeDescriptors.LOCAL_NODE_DES_TYPE) {
localNodeDescriptors = NodeDescriptors.read(tempCb, length, type, protocolId);
} else {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.MALFORMED_ATTRIBUTE_LIST, null);
}
return localNodeDescriptors;
}
@@ -117,22 +119,22 @@ public class BGPPrefixLSIdentifier {
*
* @param cb ChannelBuffer
* @return list of prefix descriptors
- * @throws BGPParseException while parsing list of prefix descriptors
+ * @throws BgpParseException while parsing list of prefix descriptors
*/
- public static LinkedList<BGPValueType> parsePrefixDescriptors(ChannelBuffer cb) throws BGPParseException {
- LinkedList<BGPValueType> prefixDescriptor = new LinkedList<>();
- BGPValueType tlv = null;
+ public static List<BgpValueType> parsePrefixDescriptors(ChannelBuffer cb) throws BgpParseException {
+ LinkedList<BgpValueType> prefixDescriptor = new LinkedList<>();
+ BgpValueType tlv = null;
boolean isIpReachInfo = false;
ChannelBuffer tempCb;
int count = 0;
while (cb.readableBytes() > 0) {
- ChannelBuffer tempBuf = cb;
+ ChannelBuffer tempBuf = cb.copy();
short type = cb.readShort();
short length = cb.readShort();
if (cb.readableBytes() < length) {
//length + 4 implies data contains type, length and value
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN));
}
tempCb = cb.readBytes(length);
@@ -149,8 +151,8 @@ public class BGPPrefixLSIdentifier {
count = count + 1;
if (count > 1) {
//length + 4 implies data contains type, length and value
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR, tempBuf.readBytes(length + TYPE_AND_LEN));
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR, tempBuf.readBytes(length + TYPE_AND_LEN));
}
break;
default:
@@ -160,7 +162,7 @@ public class BGPPrefixLSIdentifier {
}
if (!isIpReachInfo) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
null);
}
return prefixDescriptor;
@@ -180,7 +182,7 @@ public class BGPPrefixLSIdentifier {
*
* @return Prefix descriptors
*/
- public LinkedList<BGPValueType> getPrefixdescriptor() {
+ public List<BgpValueType> getPrefixdescriptor() {
return this.prefixDescriptor;
}
@@ -195,22 +197,26 @@ public class BGPPrefixLSIdentifier {
return true;
}
- if (obj instanceof BGPPrefixLSIdentifier) {
+ if (obj instanceof BgpPrefixLSIdentifier) {
int countObjSubTlv = 0;
int countOtherSubTlv = 0;
boolean isCommonSubTlv = true;
- BGPPrefixLSIdentifier other = (BGPPrefixLSIdentifier) obj;
+ BgpPrefixLSIdentifier other = (BgpPrefixLSIdentifier) obj;
- Iterator<BGPValueType> objListIterator = other.prefixDescriptor.iterator();
+ Iterator<BgpValueType> objListIterator = other.prefixDescriptor.iterator();
countOtherSubTlv = other.prefixDescriptor.size();
countObjSubTlv = prefixDescriptor.size();
if (countObjSubTlv != countOtherSubTlv) {
return false;
} else {
while (objListIterator.hasNext() && isCommonSubTlv) {
- BGPValueType subTlv = objListIterator.next();
- isCommonSubTlv = Objects.equals(prefixDescriptor.contains(subTlv),
- other.prefixDescriptor.contains(subTlv));
+ BgpValueType subTlv = objListIterator.next();
+ if (prefixDescriptor.contains(subTlv) && other.prefixDescriptor.contains(subTlv)) {
+ isCommonSubTlv = Objects.equals(prefixDescriptor.get(prefixDescriptor.indexOf(subTlv)),
+ other.prefixDescriptor.get(other.prefixDescriptor.indexOf(subTlv)));
+ } else {
+ isCommonSubTlv = false;
+ }
}
return isCommonSubTlv && Objects.equals(this.localNodeDescriptors, other.localNodeDescriptors);
}
@@ -225,4 +231,41 @@ public class BGPPrefixLSIdentifier {
.add("prefixDescriptor", prefixDescriptor)
.toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ int result = this.localNodeDescriptors.compareTo(((BgpPrefixLSIdentifier) o).localNodeDescriptors);
+ if (result != 0) {
+ return result;
+ } else {
+ int countOtherSubTlv = ((BgpPrefixLSIdentifier) o).prefixDescriptor.size();
+ int countObjSubTlv = prefixDescriptor.size();
+ if (countOtherSubTlv != countObjSubTlv) {
+ if (countOtherSubTlv > countObjSubTlv) {
+ return 1;
+ } else {
+ return -1;
+ }
+ }
+
+ ListIterator<BgpValueType> listIterator = prefixDescriptor.listIterator();
+ ListIterator<BgpValueType> listIteratorOther = ((BgpPrefixLSIdentifier) o).prefixDescriptor.listIterator();
+ while (listIterator.hasNext()) {
+ BgpValueType tlv = listIterator.next();
+ BgpValueType tlv1 = listIteratorOther.next();
+ if (prefixDescriptor.contains(tlv) && ((BgpPrefixLSIdentifier) o).prefixDescriptor.contains(tlv1)) {
+ int res = prefixDescriptor.get(prefixDescriptor.indexOf(tlv)).compareTo(
+ ((BgpPrefixLSIdentifier) o).prefixDescriptor
+ .get(((BgpPrefixLSIdentifier) o).prefixDescriptor.indexOf(tlv1)));
+ if (res != 0) {
+ return res;
+ }
+ }
+ }
+ }
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/NodeDescriptors.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/NodeDescriptors.java
index 74637c7e..7fb1b316 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/NodeDescriptors.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/NodeDescriptors.java
@@ -18,15 +18,17 @@ package org.onosproject.bgpio.protocol.linkstate;
import java.util.Iterator;
import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.exceptions.BgpParseException;
import org.onosproject.bgpio.types.AreaIDTlv;
import org.onosproject.bgpio.types.AutonomousSystemTlv;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPLSIdentifierTlv;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpLSIdentifierTlv;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.types.IsIsNonPseudonode;
import org.onosproject.bgpio.types.IsIsPseudonode;
import org.onosproject.bgpio.types.OSPFNonPseudonode;
@@ -57,7 +59,7 @@ public class NodeDescriptors {
Figure : Local or Remote Node Descriptors TLV format
*/
- protected static final Logger log = LoggerFactory.getLogger(NodeDescriptors.class);
+ private static final Logger log = LoggerFactory.getLogger(NodeDescriptors.class);
public static final short LOCAL_NODE_DES_TYPE = 256;
public static final short REMOTE_NODE_DES_TYPE = 257;
@@ -71,7 +73,7 @@ public class NodeDescriptors {
public static final int ISISPSEUDONODE_LEN = 7;
public static final int OSPFNONPSEUDONODE_LEN = 4;
public static final int OSPFPSEUDONODE_LEN = 8;
- private LinkedList<BGPValueType> subTlvs;
+ private List<BgpValueType> subTlvs;
private short deslength;
private short desType;
@@ -91,7 +93,7 @@ public class NodeDescriptors {
* @param deslength Descriptors length
* @param desType local node descriptor or remote node descriptor type
*/
- public NodeDescriptors(LinkedList<BGPValueType> subTlvs, short deslength, short desType) {
+ public NodeDescriptors(List<BgpValueType> subTlvs, short deslength, short desType) {
this.subTlvs = subTlvs;
this.deslength = deslength;
this.desType = desType;
@@ -102,7 +104,7 @@ public class NodeDescriptors {
*
* @return subTlvs list of subTlvs
*/
- public LinkedList<BGPValueType> getSubTlvs() {
+ public List<BgpValueType> getSubTlvs() {
return subTlvs;
}
@@ -122,15 +124,20 @@ public class NodeDescriptors {
int countOtherSubTlv = 0;
boolean isCommonSubTlv = true;
NodeDescriptors other = (NodeDescriptors) obj;
- Iterator<BGPValueType> objListIterator = other.subTlvs.iterator();
+ Iterator<BgpValueType> objListIterator = other.subTlvs.iterator();
countOtherSubTlv = other.subTlvs.size();
countObjSubTlv = subTlvs.size();
if (countObjSubTlv != countOtherSubTlv) {
return false;
} else {
while (objListIterator.hasNext() && isCommonSubTlv) {
- BGPValueType subTlv = objListIterator.next();
- isCommonSubTlv = Objects.equals(subTlvs.contains(subTlv), other.subTlvs.contains(subTlv));
+ BgpValueType subTlv = objListIterator.next();
+ if (subTlvs.contains(subTlv) && other.subTlvs.contains(subTlv)) {
+ isCommonSubTlv = Objects.equals(subTlvs.get(subTlvs.indexOf(subTlv)),
+ other.subTlvs.get(other.subTlvs.indexOf(subTlv)));
+ } else {
+ isCommonSubTlv = false;
+ }
}
return isCommonSubTlv;
}
@@ -146,20 +153,20 @@ public class NodeDescriptors {
* @param desType local node descriptor or remote node descriptor type
* @param protocolId protocol ID
* @return object of NodeDescriptors
- * @throws BGPParseException while parsing node descriptors
+ * @throws BgpParseException while parsing node descriptors
*/
public static NodeDescriptors read(ChannelBuffer cb, short desLength, short desType, byte protocolId)
- throws BGPParseException {
- LinkedList<BGPValueType> subTlvs;
- subTlvs = new LinkedList<>();
- BGPValueType tlv = null;
+ throws BgpParseException {
+ log.debug("Read NodeDescriptor");
+ List<BgpValueType> subTlvs = new LinkedList<>();
+ BgpValueType tlv = null;
while (cb.readableBytes() > 0) {
- ChannelBuffer tempBuf = cb;
+ ChannelBuffer tempBuf = cb.copy();
short type = cb.readShort();
short length = cb.readShort();
if (cb.readableBytes() < length) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR,
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN));
}
ChannelBuffer tempCb = cb.readBytes(length);
@@ -167,8 +174,8 @@ public class NodeDescriptors {
case AutonomousSystemTlv.TYPE:
tlv = AutonomousSystemTlv.read(tempCb);
break;
- case BGPLSIdentifierTlv.TYPE:
- tlv = BGPLSIdentifierTlv.read(tempCb);
+ case BgpLSIdentifierTlv.TYPE:
+ tlv = BgpLSIdentifierTlv.read(tempCb);
break;
case AreaIDTlv.TYPE:
tlv = AreaIDTlv.read(tempCb);
@@ -222,4 +229,34 @@ public class NodeDescriptors {
.add("subTlvs", subTlvs)
.toString();
}
+
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ ListIterator<BgpValueType> listIterator = subTlvs.listIterator();
+ ListIterator<BgpValueType> listIteratorOther = ((NodeDescriptors) o).subTlvs.listIterator();
+ int countOtherSubTlv = ((NodeDescriptors) o).subTlvs.size();
+ int countObjSubTlv = subTlvs.size();
+ if (countOtherSubTlv != countObjSubTlv) {
+ if (countOtherSubTlv > countObjSubTlv) {
+ return 1;
+ } else {
+ return -1;
+ }
+ } else {
+ while (listIterator.hasNext()) {
+ BgpValueType tlv = listIterator.next();
+ BgpValueType tlv1 = listIteratorOther.next();
+ if (subTlvs.contains(tlv) && ((NodeDescriptors) o).subTlvs.contains(tlv1)) {
+ int result = subTlvs.get(subTlvs.indexOf(tlv)).compareTo(
+ ((NodeDescriptors) o).subTlvs.get(((NodeDescriptors) o).subTlvs.indexOf(tlv1)));
+ if (result != 0) {
+ return result;
+ }
+ }
+ }
+ }
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/PathAttrNlriDetails.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/PathAttrNlriDetails.java
new file mode 100755
index 00000000..9578ccfe
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/PathAttrNlriDetails.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.protocol.linkstate;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Objects;
+
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType;
+import org.onosproject.bgpio.types.BgpValueType;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * This Class stores path Attributes, protocol ID and Identifier of LinkState NLRI.
+ */
+public class PathAttrNlriDetails {
+ private List<BgpValueType> pathAttributes;
+ private ProtocolType protocolID;
+ private long identifier;
+
+ /**
+ * Sets path attribute with specified path attribute.
+ *
+ * @param pathAttributes in update message
+ */
+ public void setPathAttribute(List<BgpValueType> pathAttributes) {
+ this.pathAttributes = pathAttributes;
+ }
+
+ /**
+ * Returns path attributes.
+ *
+ * @return path attributes
+ */
+ public List<BgpValueType> pathAttributes() {
+ return this.pathAttributes;
+ }
+
+ /**
+ * Sets protocolID with specified protocolID.
+ *
+ * @param protocolID in linkstate nlri
+ */
+ public void setProtocolID(ProtocolType protocolID) {
+ this.protocolID = protocolID;
+ }
+
+ /**
+ * Returns protocolID.
+ *
+ * @return protocolID
+ */
+ public ProtocolType protocolID() {
+ return this.protocolID;
+ }
+
+ /**
+ * Sets identifier with specified identifier.
+ *
+ * @param identifier in linkstate nlri
+ */
+ public void setIdentifier(long identifier) {
+ this.identifier = identifier;
+ }
+
+ /**
+ * Returns Identifier.
+ *
+ * @return Identifier
+ */
+ public long identifier() {
+ return this.identifier;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(pathAttributes, protocolID, identifier);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof PathAttrNlriDetails) {
+ int countObjSubTlv = 0;
+ int countOtherSubTlv = 0;
+ boolean isCommonSubTlv = true;
+ PathAttrNlriDetails other = (PathAttrNlriDetails) obj;
+ Iterator<BgpValueType> objListIterator = other.pathAttributes.iterator();
+ countOtherSubTlv = other.pathAttributes.size();
+ countObjSubTlv = pathAttributes.size();
+ if (countObjSubTlv != countOtherSubTlv) {
+ return false;
+ } else {
+ while (objListIterator.hasNext() && isCommonSubTlv) {
+ BgpValueType subTlv = objListIterator.next();
+ if (pathAttributes.contains(subTlv) && other.pathAttributes.contains(subTlv)) {
+ isCommonSubTlv = Objects.equals(pathAttributes.get(pathAttributes.indexOf(subTlv)),
+ other.pathAttributes.get(other.pathAttributes.indexOf(subTlv)));
+ } else {
+ isCommonSubTlv = false;
+ }
+ }
+ return isCommonSubTlv && Objects.equals(identifier, other.identifier)
+ && Objects.equals(protocolID, other.protocolID);
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("identifier", identifier)
+ .add("protocolID", protocolID)
+ .add("pathAttributes", pathAttributes)
+ .toString();
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/PathAttrNlriDetailsLocalRib.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/PathAttrNlriDetailsLocalRib.java
new file mode 100755
index 00000000..4172ae46
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/PathAttrNlriDetailsLocalRib.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.onosproject.bgpio.protocol.linkstate;
+
+import java.util.Objects;
+
+import org.onlab.packet.IpAddress;
+import com.google.common.base.MoreObjects;
+
+/**
+ * This Class stores path Attributes, protocol ID and Identifier of LinkState nlri.
+ */
+public class PathAttrNlriDetailsLocalRib {
+
+ private IpAddress localRibIpAddress;
+ private long localRibAsNum;
+ private int localRibIdentifier;
+ private boolean isLocalRibIbgpSession;
+ private PathAttrNlriDetails localRibNlridetails;
+
+ /**
+ * Constructor to initialize parameter.
+ *
+ * @param localRibIpAddress peer ip address
+ * @param localRibIdentifier peer identifier
+ * @param localRibAsNum peer As number
+ * @param isLocalRibIbgpSession flag to indicate is Ibgp session
+ * @param localRibNlridetails Nlri details
+ *
+ */
+ public PathAttrNlriDetailsLocalRib(IpAddress localRibIpAddress, int localRibIdentifier, long localRibAsNum,
+ boolean isLocalRibIbgpSession, PathAttrNlriDetails localRibNlridetails) {
+ this.localRibIpAddress = localRibIpAddress;
+ this.localRibAsNum = localRibAsNum;
+ this.localRibIdentifier = localRibIdentifier;
+ this.isLocalRibIbgpSession = isLocalRibIbgpSession;
+ this.localRibNlridetails = localRibNlridetails;
+ }
+
+ /**
+ * Gets the Ipaddress updated in local rib.
+ *
+ * @return localRibIpAddress ip address
+ */
+ public IpAddress localRibIpAddress() {
+ return localRibIpAddress;
+ }
+
+ /**
+ * Gets the autonomous system number updated in local rib.
+ *
+ * @return localRibAsNum autonomous system number
+ */
+ public long localRibAsNum() {
+ return localRibAsNum;
+ }
+
+ /**
+ * Gets the indetifier updated in local rib.
+ *
+ * @return localRibIdentifier identifier
+ */
+ public int localRibIdentifier() {
+ return localRibIdentifier;
+ }
+
+ /**
+ * Gets the bgp session type updated in local rib.
+ *
+ * @return isLocalRibIbgpSession session type
+ */
+ public boolean isLocalRibIbgpSession() {
+ return isLocalRibIbgpSession;
+ }
+
+ /**
+ * Returns local RIB Nlri details.
+ *
+ * @return localRibNlridetails Nlri details in local rib
+ */
+ public PathAttrNlriDetails localRibNlridetails() {
+ return this.localRibNlridetails;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(localRibIpAddress, localRibIdentifier, localRibAsNum, isLocalRibIbgpSession,
+ localRibNlridetails.hashCode());
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof PathAttrNlriDetailsLocalRib) {
+ PathAttrNlriDetailsLocalRib other = (PathAttrNlriDetailsLocalRib) obj;
+ return Objects.equals(localRibIpAddress, other.localRibIpAddress)
+ && Objects.equals(localRibIdentifier, other.localRibIdentifier)
+ && Objects.equals(localRibAsNum, other.localRibAsNum)
+ && Objects.equals(isLocalRibIbgpSession, other.isLocalRibIbgpSession)
+ && Objects.equals(localRibNlridetails, other.localRibNlridetails);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).add("peerIdentifier", localRibIdentifier)
+ .add("localRibpathAttributes", localRibNlridetails.pathAttributes()).toString();
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPFactoryVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPFactoryVer4.java
deleted file mode 100755
index 32af3854..00000000
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPFactoryVer4.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.bgpio.protocol.ver4;
-
-import org.onosproject.bgpio.protocol.BGPFactory;
-import org.onosproject.bgpio.protocol.BGPKeepaliveMsg;
-import org.onosproject.bgpio.protocol.BGPMessage;
-import org.onosproject.bgpio.protocol.BGPMessageReader;
-import org.onosproject.bgpio.protocol.BGPNotificationMsg;
-import org.onosproject.bgpio.protocol.BGPOpenMsg;
-import org.onosproject.bgpio.protocol.BGPVersion;
-
-/**
- * Provides BGP Factory and returns builder classes for all objects and messages.
- */
-public class BGPFactoryVer4 implements BGPFactory {
-
- public static final BGPFactoryVer4 INSTANCE = new BGPFactoryVer4();
-
- @Override
- public BGPOpenMsg.Builder openMessageBuilder() {
- return new BGPOpenMsgVer4.Builder();
- }
-
- @Override
- public BGPKeepaliveMsg.Builder keepaliveMessageBuilder() {
- return new BGPKeepaliveMsgVer4.Builder();
- }
-
- @Override
- public BGPNotificationMsg.Builder notificationMessageBuilder() {
- return new BGPNotificationMsgVer4.Builder();
- }
-
- @Override
- public BGPMessageReader<BGPMessage> getReader() {
- return BGPMessageVer4.READER;
- }
-
- @Override
- public BGPVersion getVersion() {
- return BGPVersion.BGP_4;
- }
-} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpFactoryVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpFactoryVer4.java
new file mode 100755
index 00000000..c57832b6
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpFactoryVer4.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.bgpio.protocol.ver4;
+
+import org.onosproject.bgpio.protocol.BgpFactory;
+import org.onosproject.bgpio.protocol.BgpKeepaliveMsg;
+import org.onosproject.bgpio.protocol.BgpMessage;
+import org.onosproject.bgpio.protocol.BgpMessageReader;
+import org.onosproject.bgpio.protocol.BgpNotificationMsg;
+import org.onosproject.bgpio.protocol.BgpOpenMsg;
+import org.onosproject.bgpio.protocol.BgpVersion;
+
+/**
+ * Provides BGP Factory and returns builder classes for all objects and messages.
+ */
+public class BgpFactoryVer4 implements BgpFactory {
+
+ public static final BgpFactoryVer4 INSTANCE = new BgpFactoryVer4();
+
+ @Override
+ public BgpOpenMsg.Builder openMessageBuilder() {
+ return new BgpOpenMsgVer4.Builder();
+ }
+
+ @Override
+ public BgpKeepaliveMsg.Builder keepaliveMessageBuilder() {
+ return new BgpKeepaliveMsgVer4.Builder();
+ }
+
+ @Override
+ public BgpNotificationMsg.Builder notificationMessageBuilder() {
+ return new BgpNotificationMsgVer4.Builder();
+ }
+
+ @Override
+ public BgpMessageReader<BgpMessage> getReader() {
+ return BgpMessageVer4.READER;
+ }
+
+ @Override
+ public BgpVersion getVersion() {
+ return BgpVersion.BGP_4;
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPKeepaliveMsgVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpKeepaliveMsgVer4.java
index 10e6bb95..2c141586 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPKeepaliveMsgVer4.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpKeepaliveMsgVer4.java
@@ -16,13 +16,13 @@
package org.onosproject.bgpio.protocol.ver4;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.protocol.BGPKeepaliveMsg;
-import org.onosproject.bgpio.protocol.BGPMessageReader;
-import org.onosproject.bgpio.protocol.BGPMessageWriter;
-import org.onosproject.bgpio.types.BGPHeader;
-import org.onosproject.bgpio.protocol.BGPType;
-import org.onosproject.bgpio.protocol.BGPVersion;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpKeepaliveMsg;
+import org.onosproject.bgpio.protocol.BgpMessageReader;
+import org.onosproject.bgpio.protocol.BgpMessageWriter;
+import org.onosproject.bgpio.types.BgpHeader;
+import org.onosproject.bgpio.protocol.BgpType;
+import org.onosproject.bgpio.protocol.BgpVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,7 +31,7 @@ import com.google.common.base.MoreObjects;
/**
* Provides BGP keep alive message.
*/
-class BGPKeepaliveMsgVer4 implements BGPKeepaliveMsg {
+public class BgpKeepaliveMsgVer4 implements BgpKeepaliveMsg {
/*
<Keepalive Message>::= <Common Header>
@@ -56,56 +56,56 @@ class BGPKeepaliveMsgVer4 implements BGPKeepaliveMsg {
*/
protected static final Logger log = LoggerFactory
- .getLogger(BGPKeepaliveMsgVer4.class);
+ .getLogger(BgpKeepaliveMsgVer4.class);
- private BGPHeader bgpMsgHeader;
+ private BgpHeader bgpMsgHeader;
public static final byte PACKET_VERSION = 4;
public static final int PACKET_MINIMUM_LENGTH = 19;
public static final int MARKER_LENGTH = 16;
- public static final BGPType MSG_TYPE = BGPType.KEEP_ALIVE;
+ public static final BgpType MSG_TYPE = BgpType.KEEP_ALIVE;
public static byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff};
- public static final BGPKeepaliveMsgVer4.Reader READER = new Reader();
+ public static final BgpKeepaliveMsgVer4.Reader READER = new Reader();
/**
* Reader class for reading BGP keepalive message from channel buffer.
*/
- static class Reader implements BGPMessageReader<BGPKeepaliveMsg> {
+ static class Reader implements BgpMessageReader<BgpKeepaliveMsg> {
@Override
- public BGPKeepaliveMsg readFrom(ChannelBuffer cb, BGPHeader bgpHeader)
- throws BGPParseException {
+ public BgpKeepaliveMsg readFrom(ChannelBuffer cb, BgpHeader bgpHeader)
+ throws BgpParseException {
/* bgpHeader is not required in case of keepalive message and
Header is already read and no other fields except header in keepalive message.*/
- return new BGPKeepaliveMsgVer4();
+ return new BgpKeepaliveMsgVer4();
}
}
/**
* Default constructor.
*/
- BGPKeepaliveMsgVer4() {
+ public BgpKeepaliveMsgVer4() {
}
/**
* Builder class for BGP keepalive message.
*/
- static class Builder implements BGPKeepaliveMsg.Builder {
- BGPHeader bgpMsgHeader;
+ static class Builder implements BgpKeepaliveMsg.Builder {
+ BgpHeader bgpMsgHeader;
@Override
- public Builder setHeader(BGPHeader bgpMsgHeader) {
+ public Builder setHeader(BgpHeader bgpMsgHeader) {
this.bgpMsgHeader = bgpMsgHeader;
return this;
}
@Override
- public BGPKeepaliveMsg build() {
- return new BGPKeepaliveMsgVer4();
+ public BgpKeepaliveMsg build() {
+ return new BgpKeepaliveMsgVer4();
}
}
@@ -119,10 +119,10 @@ class BGPKeepaliveMsgVer4 implements BGPKeepaliveMsg {
/**
* Writer class for writing the BGP keepalive message to channel buffer.
*/
- static class Writer implements BGPMessageWriter<BGPKeepaliveMsgVer4> {
+ static class Writer implements BgpMessageWriter<BgpKeepaliveMsgVer4> {
@Override
- public void write(ChannelBuffer cb, BGPKeepaliveMsgVer4 message) {
+ public void write(ChannelBuffer cb, BgpKeepaliveMsgVer4 message) {
// write marker
cb.writeBytes(marker, 0, MARKER_LENGTH);
@@ -136,17 +136,17 @@ class BGPKeepaliveMsgVer4 implements BGPKeepaliveMsg {
}
@Override
- public BGPVersion getVersion() {
- return BGPVersion.BGP_4;
+ public BgpVersion getVersion() {
+ return BgpVersion.BGP_4;
}
@Override
- public BGPType getType() {
+ public BgpType getType() {
return MSG_TYPE;
}
@Override
- public BGPHeader getHeader() {
+ public BgpHeader getHeader() {
return this.bgpMsgHeader;
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPMessageVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpMessageVer4.java
index d45e3de1..1c05dae4 100755
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPMessageVer4.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpMessageVer4.java
@@ -17,12 +17,12 @@
package org.onosproject.bgpio.protocol.ver4;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.protocol.BGPFactories;
-import org.onosproject.bgpio.protocol.BGPMessage;
-import org.onosproject.bgpio.protocol.BGPMessageReader;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPHeader;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpFactories;
+import org.onosproject.bgpio.protocol.BgpMessage;
+import org.onosproject.bgpio.protocol.BgpMessageReader;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpHeader;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,9 +30,9 @@ import org.slf4j.LoggerFactory;
/**
* Provides BGP messages.
*/
-public abstract class BGPMessageVer4 {
+public abstract class BgpMessageVer4 {
- protected static final Logger log = LoggerFactory.getLogger(BGPFactories.class);
+ protected static final Logger log = LoggerFactory.getLogger(BgpFactories.class);
static final byte OPEN_MSG_TYPE = 0x1;
static final byte KEEPALIVE_MSG_TYPE = 0x4;
@@ -42,41 +42,42 @@ public abstract class BGPMessageVer4 {
static final int HEADER_AND_MSG_LEN = 18;
static final int MAXIMUM_PACKET_LENGTH = 4096;
- public static final BGPMessageVer4.Reader READER = new Reader();
+ public static final BgpMessageVer4.Reader READER = new Reader();
/**
* Reader class for reading BGP messages from channel buffer.
*
*/
- static class Reader implements BGPMessageReader<BGPMessage> {
+ static class Reader implements BgpMessageReader<BgpMessage> {
@Override
- public BGPMessage readFrom(ChannelBuffer cb, BGPHeader bgpHeader)
- throws BGPParseException {
+ public BgpMessage readFrom(ChannelBuffer cb, BgpHeader bgpHeader)
+ throws BgpParseException {
if (cb.readableBytes() < MINIMUM_COMMON_HEADER_LENGTH) {
log.error("Packet should have minimum length.");
- Validation.validateLen(BGPErrorType.MESSAGE_HEADER_ERROR, BGPErrorType.BAD_MESSAGE_LENGTH,
+ Validation.validateLen(BgpErrorType.MESSAGE_HEADER_ERROR, BgpErrorType.BAD_MESSAGE_LENGTH,
cb.readableBytes());
}
if (cb.readableBytes() > MAXIMUM_PACKET_LENGTH) {
log.error("Packet length should not exceed {}.", MAXIMUM_PACKET_LENGTH);
- Validation.validateLen(BGPErrorType.MESSAGE_HEADER_ERROR, BGPErrorType.BAD_MESSAGE_LENGTH,
+ Validation.validateLen(BgpErrorType.MESSAGE_HEADER_ERROR, BgpErrorType.BAD_MESSAGE_LENGTH,
cb.readableBytes());
}
try {
// fixed value property version == 4
- byte[] marker = new byte[BGPHeader.MARKER_LENGTH];
- cb.readBytes(marker, 0, BGPHeader.MARKER_LENGTH);
+ byte[] marker = new byte[BgpHeader.MARKER_LENGTH];
+ cb.readBytes(marker, 0, BgpHeader.MARKER_LENGTH);
bgpHeader.setMarker(marker);
- for (int i = 0; i < BGPHeader.MARKER_LENGTH; i++) {
+ for (int i = 0; i < BgpHeader.MARKER_LENGTH; i++) {
if (marker[i] != (byte) 0xff) {
- throw new BGPParseException(BGPErrorType.MESSAGE_HEADER_ERROR,
- BGPErrorType.CONNECTION_NOT_SYNCHRONIZED, null);
+ throw new BgpParseException(BgpErrorType.MESSAGE_HEADER_ERROR,
+ BgpErrorType.CONNECTION_NOT_SYNCHRONIZED, null);
}
}
short length = cb.readShort();
- if (length != (cb.readableBytes() + HEADER_AND_MSG_LEN)) {
- Validation.validateLen(BGPErrorType.MESSAGE_HEADER_ERROR, BGPErrorType.BAD_MESSAGE_LENGTH, length);
+ if (length > cb.readableBytes() + HEADER_AND_MSG_LEN) {
+ Validation.validateLen(BgpErrorType.MESSAGE_HEADER_ERROR,
+ BgpErrorType.BAD_MESSAGE_LENGTH, length);
}
bgpHeader.setLength(length);
byte type = cb.readByte();
@@ -87,22 +88,23 @@ public abstract class BGPMessageVer4 {
switch (type) {
case OPEN_MSG_TYPE:
log.debug("OPEN MESSAGE is received");
- return BGPOpenMsgVer4.READER.readFrom(cb.readBytes(len), bgpHeader);
+ return BgpOpenMsgVer4.READER.readFrom(cb.readBytes(len), bgpHeader);
case KEEPALIVE_MSG_TYPE:
log.debug("KEEPALIVE MESSAGE is received");
- return BGPKeepaliveMsgVer4.READER.readFrom(cb.readBytes(len), bgpHeader);
+ return BgpKeepaliveMsgVer4.READER.readFrom(cb.readBytes(len), bgpHeader);
case UPDATE_MSG_TYPE:
log.debug("UPDATE MESSAGE is received");
- // TODO: Update message version 4
+ return BgpUpdateMsgVer4.READER.readFrom(cb.readBytes(len), bgpHeader);
case NOTIFICATION_MSG_TYPE:
log.debug("NOTIFICATION MESSAGE is received");
- return BGPNotificationMsgVer4.READER.readFrom(cb.readBytes(len), bgpHeader);
+ return BgpNotificationMsgVer4.READER.readFrom(cb.readBytes(len), bgpHeader);
default:
- Validation.validateType(BGPErrorType.MESSAGE_HEADER_ERROR, BGPErrorType.BAD_MESSAGE_TYPE, type);
+ Validation.validateType(BgpErrorType.MESSAGE_HEADER_ERROR, BgpErrorType.BAD_MESSAGE_TYPE, type);
return null;
}
} catch (IndexOutOfBoundsException e) {
- throw new BGPParseException(BGPErrorType.MESSAGE_HEADER_ERROR, BGPErrorType.BAD_MESSAGE_LENGTH, null);
+ throw new BgpParseException(BgpErrorType.MESSAGE_HEADER_ERROR,
+ BgpErrorType.BAD_MESSAGE_LENGTH, null);
}
}
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPNotificationMsgVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpNotificationMsgVer4.java
index 3bddd375..d25db24e 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPNotificationMsgVer4.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpNotificationMsgVer4.java
@@ -16,14 +16,14 @@
package org.onosproject.bgpio.protocol.ver4;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.protocol.BGPMessageReader;
-import org.onosproject.bgpio.protocol.BGPMessageWriter;
-import org.onosproject.bgpio.protocol.BGPNotificationMsg;
-import org.onosproject.bgpio.protocol.BGPType;
-import org.onosproject.bgpio.protocol.BGPVersion;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPHeader;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpMessageReader;
+import org.onosproject.bgpio.protocol.BgpMessageWriter;
+import org.onosproject.bgpio.protocol.BgpNotificationMsg;
+import org.onosproject.bgpio.protocol.BgpType;
+import org.onosproject.bgpio.protocol.BgpVersion;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,7 +33,7 @@ import com.google.common.base.MoreObjects;
* A NOTIFICATION message is sent when an error condition is detected. The BGP connection is closed immediately after it
* is sent.
*/
-class BGPNotificationMsgVer4 implements BGPNotificationMsg {
+class BgpNotificationMsgVer4 implements BgpNotificationMsg {
/*
0 1 2 3
@@ -44,32 +44,32 @@ class BGPNotificationMsgVer4 implements BGPNotificationMsg {
REFERENCE : RFC 4271
*/
- private static final Logger log = LoggerFactory.getLogger(BGPNotificationMsgVer4.class);
+ private static final Logger log = LoggerFactory.getLogger(BgpNotificationMsgVer4.class);
static final byte PACKET_VERSION = 4;
//BGPHeader(19) + Error code(1) + Error subcode(1)
static final int TOTAL_MESSAGE_MIN_LENGTH = 21;
static final int PACKET_MINIMUM_LENGTH = 2;
- static final BGPType MSG_TYPE = BGPType.NOTIFICATION;
+ static final BgpType MSG_TYPE = BgpType.NOTIFICATION;
static final byte DEFAULT_ERRORSUBCODE = 0;
static final byte[] MARKER = {(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 };
static final byte MESSAGE_TYPE = 3;
- static final BGPHeader DEFAULT_MESSAGE_HEADER = new BGPHeader(MARKER, BGPHeader.DEFAULT_HEADER_LENGTH,
+ static final BgpHeader DEFAULT_MESSAGE_HEADER = new BgpHeader(MARKER, BgpHeader.DEFAULT_HEADER_LENGTH,
MESSAGE_TYPE);
private byte errorCode;
private byte errorSubCode;
private byte[] data;
- private BGPHeader bgpHeader;
- public static final BGPNotificationMsgVer4.Reader READER = new Reader();
+ private BgpHeader bgpHeader;
+ public static final BgpNotificationMsgVer4.Reader READER = new Reader();
/**
* Initialize fields.
*/
- public BGPNotificationMsgVer4() {
+ public BgpNotificationMsgVer4() {
this.bgpHeader = null;
this.data = null;
this.errorCode = 0;
@@ -84,7 +84,7 @@ class BGPNotificationMsgVer4 implements BGPNotificationMsg {
* @param errorSubCode error subcode
* @param data field
*/
- public BGPNotificationMsgVer4(BGPHeader bgpHeader, byte errorCode, byte errorSubCode, byte[] data) {
+ public BgpNotificationMsgVer4(BgpHeader bgpHeader, byte errorCode, byte errorSubCode, byte[] data) {
this.bgpHeader = bgpHeader;
this.data = data;
this.errorCode = errorCode;
@@ -94,13 +94,13 @@ class BGPNotificationMsgVer4 implements BGPNotificationMsg {
/**
* Reader reads BGP Notification Message from the channel buffer.
*/
- static class Reader implements BGPMessageReader<BGPNotificationMsg> {
+ static class Reader implements BgpMessageReader<BgpNotificationMsg> {
@Override
- public BGPNotificationMsg readFrom(ChannelBuffer cb, BGPHeader bgpHeader) throws BGPParseException {
+ public BgpNotificationMsg readFrom(ChannelBuffer cb, BgpHeader bgpHeader) throws BgpParseException {
byte errorCode;
byte errorSubCode;
if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) {
- throw new BGPParseException("Not enough readable bytes");
+ throw new BgpParseException("Not enough readable bytes");
}
errorCode = cb.readByte();
errorSubCode = cb.readByte();
@@ -108,31 +108,31 @@ class BGPNotificationMsgVer4 implements BGPNotificationMsg {
int dataLength = bgpHeader.getLength() - TOTAL_MESSAGE_MIN_LENGTH;
byte[] data = new byte[dataLength];
cb.readBytes(data, 0, dataLength);
- return new BGPNotificationMsgVer4(bgpHeader, errorCode, errorSubCode, data);
+ return new BgpNotificationMsgVer4(bgpHeader, errorCode, errorSubCode, data);
}
}
/**
* Builder class for BGP notification message.
*/
- static class Builder implements BGPNotificationMsg.Builder {
+ static class Builder implements BgpNotificationMsg.Builder {
private byte errorCode;
private byte errorSubCode;
private byte[] data;
- private BGPHeader bgpHeader;
+ private BgpHeader bgpHeader;
private boolean isErrorCodeSet = false;
private boolean isErrorSubCodeSet = false;
private boolean isBGPHeaderSet = false;
@Override
- public BGPNotificationMsg build() throws BGPParseException {
- BGPHeader bgpHeader = this.isBGPHeaderSet ? this.bgpHeader : DEFAULT_MESSAGE_HEADER;
+ public BgpNotificationMsg build() throws BgpParseException {
+ BgpHeader bgpHeader = this.isBGPHeaderSet ? this.bgpHeader : DEFAULT_MESSAGE_HEADER;
if (!this.isErrorCodeSet) {
- throw new BGPParseException("Error code must be present");
+ throw new BgpParseException("Error code must be present");
}
byte errorSubCode = this.isErrorSubCodeSet ? this.errorSubCode : DEFAULT_ERRORSUBCODE;
- return new BGPNotificationMsgVer4(bgpHeader, this.errorCode, errorSubCode, this.data);
+ return new BgpNotificationMsgVer4(bgpHeader, this.errorCode, errorSubCode, this.data);
}
@Override
@@ -151,29 +151,31 @@ class BGPNotificationMsgVer4 implements BGPNotificationMsg {
@Override
public Builder setData(byte[] data) {
- this.data = data;
+ if (data != null) {
+ this.data = data;
+ }
return this;
}
@Override
- public Builder setHeader(BGPHeader bgpMsgHeader) {
+ public Builder setHeader(BgpHeader bgpMsgHeader) {
this.bgpHeader = bgpMsgHeader;
return this;
}
}
@Override
- public BGPVersion getVersion() {
- return BGPVersion.BGP_4;
+ public BgpVersion getVersion() {
+ return BgpVersion.BGP_4;
}
@Override
- public BGPType getType() {
- return BGPType.NOTIFICATION;
+ public BgpType getType() {
+ return BgpType.NOTIFICATION;
}
@Override
- public void writeTo(ChannelBuffer cb) throws BGPParseException {
+ public void writeTo(ChannelBuffer cb) throws BgpParseException {
WRITER.write(cb, this);
}
@@ -182,13 +184,13 @@ class BGPNotificationMsgVer4 implements BGPNotificationMsg {
/**
* Writer writes BGP notification message to channel buffer.
*/
- static class Writer implements BGPMessageWriter<BGPNotificationMsgVer4> {
+ static class Writer implements BgpMessageWriter<BgpNotificationMsgVer4> {
@Override
- public void write(ChannelBuffer cb, BGPNotificationMsgVer4 message) throws BGPParseException {
+ public void write(ChannelBuffer cb, BgpNotificationMsgVer4 message) throws BgpParseException {
int msgStartIndex = cb.writerIndex();
int headerLenIndex = message.bgpHeader.write(cb);
if (headerLenIndex <= 0) {
- throw new BGPParseException(BGPErrorType.MESSAGE_HEADER_ERROR, (byte) 0, null);
+ throw new BgpParseException(BgpErrorType.MESSAGE_HEADER_ERROR, (byte) 0, null);
}
cb.writeByte(message.errorCode);
cb.writeByte(message.errorSubCode);
@@ -244,7 +246,7 @@ class BGPNotificationMsgVer4 implements BGPNotificationMsg {
}
@Override
- public BGPHeader getHeader() {
+ public BgpHeader getHeader() {
return this.bgpHeader;
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPOpenMsgVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpOpenMsgVer4.java
index fccbf5f7..359eec25 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPOpenMsgVer4.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpOpenMsgVer4.java
@@ -19,15 +19,15 @@ import java.util.LinkedList;
import java.util.ListIterator;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.protocol.BGPMessageReader;
-import org.onosproject.bgpio.protocol.BGPMessageWriter;
-import org.onosproject.bgpio.protocol.BGPOpenMsg;
-import org.onosproject.bgpio.protocol.BGPType;
-import org.onosproject.bgpio.protocol.BGPVersion;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPHeader;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpMessageReader;
+import org.onosproject.bgpio.protocol.BgpMessageWriter;
+import org.onosproject.bgpio.protocol.BgpOpenMsg;
+import org.onosproject.bgpio.protocol.BgpType;
+import org.onosproject.bgpio.protocol.BgpVersion;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpHeader;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv;
import org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv;
import org.onosproject.bgpio.util.Validation;
@@ -39,7 +39,7 @@ import com.google.common.base.MoreObjects;
/**
* Provides BGP open message.
*/
-public class BGPOpenMsgVer4 implements BGPOpenMsg {
+public class BgpOpenMsgVer4 implements BgpOpenMsg {
/*
0 1 2 3
@@ -61,7 +61,7 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
REFERENCE : RFC 4271
*/
- protected static final Logger log = LoggerFactory.getLogger(BGPOpenMsgVer4.class);
+ protected static final Logger log = LoggerFactory.getLogger(BgpOpenMsgVer4.class);
public static final byte PACKET_VERSION = 4;
public static final int OPEN_MSG_MINIMUM_LENGTH = 10;
@@ -70,7 +70,7 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
public static final int DEFAULT_HOLD_TIME = 120;
public static final short AS_TRANS = 23456;
public static final int OPT_PARA_TYPE_CAPABILITY = 2;
- public static final BGPType MSG_TYPE = BGPType.OPEN;
+ public static final BgpType MSG_TYPE = BgpType.OPEN;
public static final short AFI = 16388;
public static final byte SAFI = 71;
public static final byte RES = 0;
@@ -78,22 +78,22 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
public static final byte[] MARKER = new byte[]{(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff};
- public static final BGPHeader DEFAULT_OPEN_HEADER = new BGPHeader(MARKER,
+ public static final BgpHeader DEFAULT_OPEN_HEADER = new BgpHeader(MARKER,
(short) OPEN_MSG_MINIMUM_LENGTH, (byte) 0X01);
- private BGPHeader bgpMsgHeader;
+ private BgpHeader bgpMsgHeader;
private byte version;
private short asNumber;
private short holdTime;
private int bgpId;
private boolean isLargeAsCapabilitySet;
- private LinkedList<BGPValueType> capabilityTlv;
+ private LinkedList<BgpValueType> capabilityTlv;
- public static final BGPOpenMsgVer4.Reader READER = new Reader();
+ public static final BgpOpenMsgVer4.Reader READER = new Reader();
/**
* reset variables.
*/
- public BGPOpenMsgVer4() {
+ public BgpOpenMsgVer4() {
this.bgpMsgHeader = null;
this.version = 0;
this.holdTime = 0;
@@ -112,8 +112,8 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
* @param bgpId BGP identifier in open message
* @param capabilityTlv capabilities in open message
*/
- public BGPOpenMsgVer4(BGPHeader bgpMsgHeader, byte version, short asNumber, short holdTime,
- int bgpId, LinkedList<BGPValueType> capabilityTlv) {
+ public BgpOpenMsgVer4(BgpHeader bgpMsgHeader, byte version, short asNumber, short holdTime,
+ int bgpId, LinkedList<BgpValueType> capabilityTlv) {
this.bgpMsgHeader = bgpMsgHeader;
this.version = version;
this.asNumber = asNumber;
@@ -123,17 +123,17 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
}
@Override
- public BGPHeader getHeader() {
+ public BgpHeader getHeader() {
return this.bgpMsgHeader;
}
@Override
- public BGPVersion getVersion() {
- return BGPVersion.BGP_4;
+ public BgpVersion getVersion() {
+ return BgpVersion.BGP_4;
}
@Override
- public BGPType getType() {
+ public BgpType getType() {
return MSG_TYPE;
}
@@ -153,17 +153,17 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
}
@Override
- public LinkedList<BGPValueType> getCapabilityTlv() {
+ public LinkedList<BgpValueType> getCapabilityTlv() {
return this.capabilityTlv;
}
/**
* Reader class for reading BGP open message from channel buffer.
*/
- public static class Reader implements BGPMessageReader<BGPOpenMsg> {
+ public static class Reader implements BgpMessageReader<BgpOpenMsg> {
@Override
- public BGPOpenMsg readFrom(ChannelBuffer cb, BGPHeader bgpHeader) throws BGPParseException {
+ public BgpOpenMsg readFrom(ChannelBuffer cb, BgpHeader bgpHeader) throws BgpParseException {
byte version;
short holdTime;
@@ -172,11 +172,11 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
byte optParaLen = 0;
byte optParaType;
byte capParaLen = 0;
- LinkedList<BGPValueType> capabilityTlv = new LinkedList<>();
+ LinkedList<BgpValueType> capabilityTlv = new LinkedList<>();
if (cb.readableBytes() < OPEN_MSG_MINIMUM_LENGTH) {
log.error("[readFrom] Invalid length: Packet size is less than the minimum length ");
- Validation.validateLen(BGPErrorType.OPEN_MESSAGE_ERROR, BGPErrorType.BAD_MESSAGE_LENGTH,
+ Validation.validateLen(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.BAD_MESSAGE_LENGTH,
cb.readableBytes());
}
@@ -184,8 +184,8 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
version = cb.readByte();
if (version != PACKET_VERSION) {
log.error("[readFrom] Invalid version: " + version);
- throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR,
- BGPErrorType.UNSUPPORTED_VERSION_NUMBER, null);
+ throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR,
+ BgpErrorType.UNSUPPORTED_VERSION_NUMBER, null);
}
// Read AS number
@@ -209,7 +209,7 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
capParaLen = cb.readByte();
if (cb.readableBytes() < capParaLen) {
- throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, (byte) 0, null);
+ throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, (byte) 0, null);
}
ChannelBuffer capaCb = cb.readBytes(capParaLen);
@@ -218,11 +218,11 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
if ((optParaType == OPT_PARA_TYPE_CAPABILITY) && (capParaLen != 0)) {
capabilityTlv = parseCapabilityTlv(capaCb);
} else {
- throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR,
- BGPErrorType.UNSUPPORTED_OPTIONAL_PARAMETER, null);
+ throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR,
+ BgpErrorType.UNSUPPORTED_OPTIONAL_PARAMETER, null);
}
}
- return new BGPOpenMsgVer4(bgpHeader, version, asNumber, holdTime, bgpId, capabilityTlv);
+ return new BgpOpenMsgVer4(bgpHeader, version, asNumber, holdTime, bgpId, capabilityTlv);
}
}
@@ -231,14 +231,14 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
*
* @param cb of type channel buffer
* @return capabilityTlv of open message
- * @throws BGPParseException while parsing capabilities
+ * @throws BgpParseException while parsing capabilities
*/
- protected static LinkedList<BGPValueType> parseCapabilityTlv(ChannelBuffer cb) throws BGPParseException {
+ protected static LinkedList<BgpValueType> parseCapabilityTlv(ChannelBuffer cb) throws BgpParseException {
- LinkedList<BGPValueType> capabilityTlv = new LinkedList<>();
+ LinkedList<BgpValueType> capabilityTlv = new LinkedList<>();
while (cb.readableBytes() > 0) {
- BGPValueType tlv;
+ BgpValueType tlv;
short type = cb.readByte();
short length = cb.readByte();
@@ -246,10 +246,10 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
case FourOctetAsNumCapabilityTlv.TYPE:
log.debug("FourOctetAsNumCapabilityTlv");
if (FourOctetAsNumCapabilityTlv.LENGTH != length) {
- throw new BGPParseException("Invalid length received for FourOctetAsNumCapabilityTlv.");
+ throw new BgpParseException("Invalid length received for FourOctetAsNumCapabilityTlv.");
}
if (length > cb.readableBytes()) {
- throw new BGPParseException("Four octet as num tlv length"
+ throw new BgpParseException("Four octet as num tlv length"
+ " is more than readableBytes.");
}
int as4Num = cb.readInt();
@@ -258,10 +258,10 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
case MultiProtocolExtnCapabilityTlv.TYPE:
log.debug("MultiProtocolExtnCapabilityTlv");
if (MultiProtocolExtnCapabilityTlv.LENGTH != length) {
- throw new BGPParseException("Invalid length received for MultiProtocolExtnCapabilityTlv.");
+ throw new BgpParseException("Invalid length received for MultiProtocolExtnCapabilityTlv.");
}
if (length > cb.readableBytes()) {
- throw new BGPParseException("BGP LS tlv length is more than readableBytes.");
+ throw new BgpParseException("BGP LS tlv length is more than readableBytes.");
}
short afi = cb.readShort();
byte res = cb.readByte();
@@ -281,10 +281,10 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
/**
* Builder class for BGP open message.
*/
- static class Builder implements BGPOpenMsg.Builder {
+ static class Builder implements BgpOpenMsg.Builder {
private boolean isHeaderSet = false;
- private BGPHeader bgpMsgHeader;
+ private BgpHeader bgpMsgHeader;
private boolean isHoldTimeSet = false;
private short holdTime;
private boolean isAsNumSet = false;
@@ -294,40 +294,40 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
private boolean isLargeAsCapabilityTlvSet = false;
private boolean isLsCapabilityTlvSet = false;
- LinkedList<BGPValueType> capabilityTlv = new LinkedList<>();
+ LinkedList<BgpValueType> capabilityTlv = new LinkedList<>();
@Override
- public BGPOpenMsg build() throws BGPParseException {
- BGPHeader bgpMsgHeader = this.isHeaderSet ? this.bgpMsgHeader : DEFAULT_OPEN_HEADER;
+ public BgpOpenMsg build() throws BgpParseException {
+ BgpHeader bgpMsgHeader = this.isHeaderSet ? this.bgpMsgHeader : DEFAULT_OPEN_HEADER;
short holdTime = this.isHoldTimeSet ? this.holdTime : DEFAULT_HOLD_TIME;
if (!this.isAsNumSet) {
- throw new BGPParseException("BGP AS number is not set (mandatory)");
+ throw new BgpParseException("BGP AS number is not set (mandatory)");
}
if (!this.isBgpIdSet) {
- throw new BGPParseException("BGPID is not set (mandatory)");
+ throw new BgpParseException("BGPID is not set (mandatory)");
}
if (this.isLargeAsCapabilityTlvSet) {
- BGPValueType tlv;
+ BgpValueType tlv;
int value = this.asNumber;
tlv = new FourOctetAsNumCapabilityTlv(value);
this.capabilityTlv.add(tlv);
}
if (this.isLsCapabilityTlvSet) {
- BGPValueType tlv;
+ BgpValueType tlv;
tlv = new MultiProtocolExtnCapabilityTlv(AFI, RES, SAFI);
this.capabilityTlv.add(tlv);
}
- return new BGPOpenMsgVer4(bgpMsgHeader, PACKET_VERSION, this.asNumber, holdTime, this.bgpId,
+ return new BgpOpenMsgVer4(bgpMsgHeader, PACKET_VERSION, this.asNumber, holdTime, this.bgpId,
this.capabilityTlv);
}
@Override
- public Builder setHeader(BGPHeader bgpMsgHeader) {
+ public Builder setHeader(BgpHeader bgpMsgHeader) {
this.bgpMsgHeader = bgpMsgHeader;
return this;
}
@@ -354,7 +354,7 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
}
@Override
- public Builder setCapabilityTlv(LinkedList<BGPValueType> capabilityTlv) {
+ public Builder setCapabilityTlv(LinkedList<BgpValueType> capabilityTlv) {
this.capabilityTlv = capabilityTlv;
return this;
}
@@ -376,7 +376,7 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
public void writeTo(ChannelBuffer cb) {
try {
WRITER.write(cb, this);
- } catch (BGPParseException e) {
+ } catch (BgpParseException e) {
log.debug("[writeTo] Error: " + e.toString());
}
}
@@ -386,10 +386,10 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
/**
* Writer class for writing BGP open message to channel buffer.
*/
- public static class Writer implements BGPMessageWriter<BGPOpenMsgVer4> {
+ public static class Writer implements BgpMessageWriter<BgpOpenMsgVer4> {
@Override
- public void write(ChannelBuffer cb, BGPOpenMsgVer4 message) throws BGPParseException {
+ public void write(ChannelBuffer cb, BgpOpenMsgVer4 message) throws BgpParseException {
int optParaLen = 0;
int as4num = 0;
@@ -400,7 +400,7 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
int msgLenIndex = message.bgpMsgHeader.write(cb);
if (msgLenIndex <= 0) {
- throw new BGPParseException("Unable to write message header.");
+ throw new BgpParseException("Unable to write message header.");
}
// write version in 1-octet
@@ -408,13 +408,13 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
// get as4num if LS Capability is set
if (message.isLargeAsCapabilitySet) {
- LinkedList<BGPValueType> capabilityTlv = message
+ LinkedList<BgpValueType> capabilityTlv = message
.getCapabilityTlv();
- ListIterator<BGPValueType> listIterator = capabilityTlv
+ ListIterator<BgpValueType> listIterator = capabilityTlv
.listIterator();
while (listIterator.hasNext()) {
- BGPValueType tlv = listIterator.next();
+ BgpValueType tlv = listIterator.next();
if (tlv.getType() == FOUR_OCTET_AS_NUM_CAPA_TYPE) {
as4num = ((FourOctetAsNumCapabilityTlv) tlv).getInt();
break;
@@ -464,13 +464,13 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
* @param message of type BGPOpenMsgVer4
* @return capParaLen of open message
*/
- protected int packCapabilityTlv(ChannelBuffer cb, BGPOpenMsgVer4 message) {
+ protected int packCapabilityTlv(ChannelBuffer cb, BgpOpenMsgVer4 message) {
int startIndex = cb.writerIndex();
int capParaLen = 0;
int capParaLenIndex = 0;
- LinkedList<BGPValueType> capabilityTlv = message.capabilityTlv;
- ListIterator<BGPValueType> listIterator = capabilityTlv.listIterator();
+ LinkedList<BgpValueType> capabilityTlv = message.capabilityTlv;
+ ListIterator<BgpValueType> listIterator = capabilityTlv.listIterator();
if (listIterator.hasNext()) {
// Set optional parameter type as 2
@@ -487,7 +487,7 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg {
}
while (listIterator.hasNext()) {
- BGPValueType tlv = listIterator.next();
+ BgpValueType tlv = listIterator.next();
if (tlv == null) {
log.debug("Warning: tlv is null from CapabilityTlv list");
continue;
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpPathAttributes.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpPathAttributes.java
index 20a7ba03..9ffddf68 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpPathAttributes.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpPathAttributes.java
@@ -19,11 +19,11 @@ import java.util.LinkedList;
import java.util.List;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.exceptions.BgpParseException;
import org.onosproject.bgpio.types.As4Path;
import org.onosproject.bgpio.types.AsPath;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.types.LocalPref;
import org.onosproject.bgpio.types.Med;
import org.onosproject.bgpio.types.NextHop;
@@ -58,7 +58,7 @@ public class BgpPathAttributes {
public static final int MPREACHNLRI_TYPE = 14;
public static final int MPUNREACHNLRI_TYPE = 15;
- private final List<BGPValueType> pathAttribute;
+ private final List<BgpValueType> pathAttribute;
/**
* Initialize parameter.
@@ -72,7 +72,7 @@ public class BgpPathAttributes {
*
* @param pathAttribute list of path attributes
*/
- public BgpPathAttributes(List<BGPValueType> pathAttribute) {
+ public BgpPathAttributes(List<BgpValueType> pathAttribute) {
this.pathAttribute = pathAttribute;
}
@@ -81,7 +81,7 @@ public class BgpPathAttributes {
*
* @return list of path attributes
*/
- public List<BGPValueType> pathAttributes() {
+ public List<BgpValueType> pathAttributes() {
return this.pathAttribute;
}
@@ -90,13 +90,13 @@ public class BgpPathAttributes {
*
* @param cb channelBuffer
* @return object of BgpPathAttributes
- * @throws BGPParseException while parsing BGP path attributes
+ * @throws BgpParseException while parsing BGP path attributes
*/
public static BgpPathAttributes read(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
- BGPValueType pathAttribute = null;
- List<BGPValueType> pathAttributeList = new LinkedList<>();
+ BgpValueType pathAttribute = null;
+ List<BgpValueType> pathAttributeList = new LinkedList<>();
boolean isOrigin = false;
boolean isAsPath = false;
boolean isNextHop = false;
@@ -161,27 +161,27 @@ public class BgpPathAttributes {
* @param isNextHop say whether nexthop attribute is present
* @param isMpReach say whether mpreach attribute is present
* @param isMpUnReach say whether mpunreach attribute is present
- * @throws BGPParseException if mandatory path attribute is not present
+ * @throws BgpParseException if mandatory path attribute is not present
*/
public static void checkMandatoryAttr(boolean isOrigin, boolean isAsPath,
boolean isNextHop, boolean isMpReach, boolean isMpUnReach)
- throws BGPParseException {
+ throws BgpParseException {
if (!isOrigin) {
log.debug("Mandatory Attributes not Present");
- Validation.validateType(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.MISSING_WELLKNOWN_ATTRIBUTE,
+ Validation.validateType(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.MISSING_WELLKNOWN_ATTRIBUTE,
Origin.ORIGIN_TYPE);
}
if (!isAsPath) {
log.debug("Mandatory Attributes not Present");
- Validation.validateType(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.MISSING_WELLKNOWN_ATTRIBUTE,
+ Validation.validateType(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.MISSING_WELLKNOWN_ATTRIBUTE,
AsPath.ASPATH_TYPE);
}
if (!isMpUnReach && !isMpReach && !isNextHop) {
log.debug("Mandatory Attributes not Present");
- Validation.validateType(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.MISSING_WELLKNOWN_ATTRIBUTE,
+ Validation.validateType(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.MISSING_WELLKNOWN_ATTRIBUTE,
NextHop.NEXTHOP_TYPE);
}
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java
index 9f4cf9b9..4d6af594 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java
@@ -20,14 +20,14 @@ import java.util.List;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.IpPrefix;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.protocol.BGPMessageReader;
-import org.onosproject.bgpio.protocol.BGPType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpMessageReader;
+import org.onosproject.bgpio.protocol.BgpType;
import org.onosproject.bgpio.protocol.BgpUpdateMsg;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPHeader;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpHeader;
import org.onosproject.bgpio.util.Validation;
-import org.onosproject.bgpio.protocol.BGPVersion;
+import org.onosproject.bgpio.protocol.BgpVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -75,12 +75,12 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg {
public static final int BYTE_IN_BITS = 8;
public static final int MIN_LEN_AFTER_WITHDRW_ROUTES = 2;
public static final int MINIMUM_COMMON_HEADER_LENGTH = 19;
- public static final BGPType MSG_TYPE = BGPType.UPDATE;
+ public static final BgpType MSG_TYPE = BgpType.UPDATE;
public static final BgpUpdateMsgVer4.Reader READER = new Reader();
private List<IpPrefix> withdrawnRoutes;
private BgpPathAttributes bgpPathAttributes;
- private BGPHeader bgpHeader;
+ private BgpHeader bgpHeader;
private List<IpPrefix> nlri;
/**
@@ -91,7 +91,7 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg {
* @param bgpPathAttributes BGP Path attributes
* @param nlri Network Layer Reachability Information
*/
- public BgpUpdateMsgVer4(BGPHeader bgpHeader, List<IpPrefix> withdrawnRoutes,
+ public BgpUpdateMsgVer4(BgpHeader bgpHeader, List<IpPrefix> withdrawnRoutes,
BgpPathAttributes bgpPathAttributes, List<IpPrefix> nlri) {
this.bgpHeader = bgpHeader;
this.withdrawnRoutes = withdrawnRoutes;
@@ -102,15 +102,15 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg {
/**
* Reader reads BGP Update Message from the channel buffer.
*/
- static class Reader implements BGPMessageReader<BgpUpdateMsg> {
+ static class Reader implements BgpMessageReader<BgpUpdateMsg> {
@Override
- public BgpUpdateMsg readFrom(ChannelBuffer cb, BGPHeader bgpHeader)
- throws BGPParseException {
+ public BgpUpdateMsg readFrom(ChannelBuffer cb, BgpHeader bgpHeader)
+ throws BgpParseException {
if (cb.readableBytes() != (bgpHeader.getLength() - MINIMUM_COMMON_HEADER_LENGTH)) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.BAD_MESSAGE_LENGTH, bgpHeader.getLength());
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.BAD_MESSAGE_LENGTH, bgpHeader.getLength());
}
LinkedList<IpPrefix> withDrwRoutes = new LinkedList<>();
@@ -120,8 +120,8 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg {
Short withDrwLen = cb.readShort();
if (cb.readableBytes() < withDrwLen) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.MALFORMED_ATTRIBUTE_LIST,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.MALFORMED_ATTRIBUTE_LIST,
cb.readableBytes());
}
ChannelBuffer tempCb = cb.readBytes(withDrwLen);
@@ -131,23 +131,23 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg {
}
if (cb.readableBytes() < MIN_LEN_AFTER_WITHDRW_ROUTES) {
log.debug("Bgp Path Attribute len field not present");
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.MALFORMED_ATTRIBUTE_LIST, null);
}
// Reading Total Path Attribute Length
short totPathAttrLen = cb.readShort();
int len = withDrwLen + totPathAttrLen + PACKET_MINIMUM_LENGTH;
if (len > bgpHeader.getLength()) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.MALFORMED_ATTRIBUTE_LIST, null);
}
if (totPathAttrLen != 0) {
// Parsing BGPPathAttributes
if (cb.readableBytes() < totPathAttrLen) {
Validation
- .validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.MALFORMED_ATTRIBUTE_LIST,
+ .validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.MALFORMED_ATTRIBUTE_LIST,
cb.readableBytes());
}
tempCb = cb.readBytes(totPathAttrLen);
@@ -167,10 +167,10 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg {
*
* @param cb channelBuffer
* @return list of IP Prefix
- * @throws BGPParseException while parsing NLRI
+ * @throws BgpParseException while parsing NLRI
*/
public static LinkedList<IpPrefix> parseNlri(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
LinkedList<IpPrefix> nlri = new LinkedList<>();
while (cb.readableBytes() > 0) {
int length = cb.readByte();
@@ -186,8 +186,8 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg {
len = len + 1;
}
if (cb.readableBytes() < len) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.MALFORMED_ATTRIBUTE_LIST,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.MALFORMED_ATTRIBUTE_LIST,
cb.readableBytes());
}
byte[] prefix = new byte[len];
@@ -204,10 +204,10 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg {
*
* @param cb channelBuffer
* @return list of IP prefix
- * @throws BGPParseException while parsing withdrawn routes
+ * @throws BgpParseException while parsing withdrawn routes
*/
public static LinkedList<IpPrefix> parseWithdrawnRoutes(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
LinkedList<IpPrefix> withDrwRoutes = new LinkedList<>();
while (cb.readableBytes() > 0) {
int length = cb.readByte();
@@ -224,8 +224,8 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg {
}
if (cb.readableBytes() < len) {
Validation
- .validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.MALFORMED_ATTRIBUTE_LIST,
+ .validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.MALFORMED_ATTRIBUTE_LIST,
cb.readableBytes());
}
byte[] prefix = new byte[len];
@@ -238,17 +238,17 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg {
}
@Override
- public BGPVersion getVersion() {
- return BGPVersion.BGP_4;
+ public BgpVersion getVersion() {
+ return BgpVersion.BGP_4;
}
@Override
- public BGPType getType() {
- return BGPType.UPDATE;
+ public BgpType getType() {
+ return BgpType.UPDATE;
}
@Override
- public void writeTo(ChannelBuffer channelBuffer) throws BGPParseException {
+ public void writeTo(ChannelBuffer channelBuffer) throws BgpParseException {
//Not to be implemented as of now
}
@@ -268,7 +268,7 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg {
}
@Override
- public BGPHeader getHeader() {
+ public BgpHeader getHeader() {
return this.bgpHeader;
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AreaIDTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AreaIDTlv.java
index 52bae466..842c6f02 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AreaIDTlv.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AreaIDTlv.java
@@ -18,15 +18,13 @@ package org.onosproject.bgpio.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides AreaID Tlv which contains opaque value (32 Bit Area-ID).
*/
-public class AreaIDTlv implements BGPValueType {
+public class AreaIDTlv implements BgpValueType {
/* Reference :draft-ietf-idr-ls-distribution-11
* 0 1 2 3
@@ -38,8 +36,6 @@ public class AreaIDTlv implements BGPValueType {
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
- protected static final Logger log = LoggerFactory.getLogger(AreaIDTlv.class);
-
public static final short TYPE = 514;
public static final short LENGTH = 4;
@@ -116,6 +112,14 @@ public class AreaIDTlv implements BGPValueType {
}
@Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ return ((Integer) (this.areaID)).compareTo((Integer) (((AreaIDTlv) o).areaID));
+ }
+
+ @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("Type", TYPE)
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java
index e9df3999..3ceca2ce 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java
@@ -20,7 +20,7 @@ import java.util.List;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.exceptions.BgpParseException;
import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
@@ -31,7 +31,7 @@ import com.google.common.base.MoreObjects;
/**
* Provides Implementation of As4Path BGP Path Attribute.
*/
-public class As4Path implements BGPValueType {
+public class As4Path implements BgpValueType {
private static final Logger log = LoggerFactory.getLogger(AsPath.class);
public static final byte AS4PATH_TYPE = 17;
public static final byte ASNUM_SIZE = 4;
@@ -63,16 +63,16 @@ public class As4Path implements BGPValueType {
*
* @param cb ChannelBuffer
* @return object of As4Path
- * @throws BGPParseException while parsing As4Path
+ * @throws BgpParseException while parsing As4Path
*/
- public static As4Path read(ChannelBuffer cb) throws BGPParseException {
+ public static As4Path read(ChannelBuffer cb) throws BgpParseException {
List<Integer> as4pathSet = new ArrayList<>();
List<Integer> as4pathSeq = new ArrayList<>();
ChannelBuffer tempCb = cb.copy();
Validation validation = Validation.parseAttributeHeader(cb);
if (cb.readableBytes() < validation.getLength()) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
validation.getLength());
}
//if fourth bit is set length is read as short otherwise as byte , len includes type, length and value
@@ -80,7 +80,7 @@ public class As4Path implements BGPValueType {
.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
}
ChannelBuffer tempBuf = cb.readBytes(validation.getLength());
@@ -91,8 +91,8 @@ public class As4Path implements BGPValueType {
//length = no of Ases * ASnum size (4 bytes)
int length = pathSegLen * ASNUM_SIZE;
if (tempBuf.readableBytes() < length) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR, length);
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR, length);
}
ChannelBuffer aspathBuf = tempBuf.readBytes(length);
while (aspathBuf.readableBytes() > 0) {
@@ -166,4 +166,10 @@ public class As4Path implements BGPValueType {
//Not required to Implement as of now
return 0;
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
index e3eb2c51..2a050c44 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
@@ -21,7 +21,7 @@ import java.util.List;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.exceptions.BgpParseException;
import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
@@ -32,7 +32,7 @@ import com.google.common.base.MoreObjects;
/**
* Provides Implementation of AsPath mandatory BGP Path Attribute.
*/
-public class AsPath implements BGPValueType {
+public class AsPath implements BgpValueType {
/**
* Enum to provide AS types.
*/
@@ -94,16 +94,16 @@ public class AsPath implements BGPValueType {
*
* @param cb ChannelBuffer
* @return object of AsPath
- * @throws BGPParseException while parsing AsPath
+ * @throws BgpParseException while parsing AsPath
*/
- public static AsPath read(ChannelBuffer cb) throws BGPParseException {
+ public static AsPath read(ChannelBuffer cb) throws BgpParseException {
List<Short> aspathSet = new ArrayList<>();
List<Short> aspathSeq = new ArrayList<>();
ChannelBuffer tempCb = cb.copy();
Validation validation = Validation.parseAttributeHeader(cb);
if (cb.readableBytes() < validation.getLength()) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
validation.getLength());
}
//if fourth bit is set, length is read as short otherwise as byte , len includes type, length and value
@@ -111,7 +111,7 @@ public class AsPath implements BGPValueType {
.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
}
ChannelBuffer tempBuf = cb.readBytes(validation.getLength());
@@ -121,8 +121,8 @@ public class AsPath implements BGPValueType {
byte pathSegLen = tempBuf.readByte();
int length = pathSegLen * ASNUM_SIZE;
if (tempBuf.readableBytes() < length) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR, length);
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR, length);
}
ChannelBuffer aspathBuf = tempBuf.readBytes(length);
while (aspathBuf.readableBytes() > 0) {
@@ -205,4 +205,10 @@ public class AsPath implements BGPValueType {
//Not required to Implement as of now
return 0;
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AutonomousSystemTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AutonomousSystemTlv.java
index 5d8a9193..119926c8 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AutonomousSystemTlv.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AutonomousSystemTlv.java
@@ -18,15 +18,13 @@ package org.onosproject.bgpio.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides Autonomous System Tlv which contains opaque value (32 Bit AS Number).
*/
-public class AutonomousSystemTlv implements BGPValueType {
+public class AutonomousSystemTlv implements BgpValueType {
/* Reference :draft-ietf-idr-ls-distribution-11
* 0 1 2 3
@@ -38,8 +36,6 @@ public class AutonomousSystemTlv implements BGPValueType {
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
- protected static final Logger log = LoggerFactory.getLogger(AutonomousSystemTlv.class);
-
public static final short TYPE = 512;
public static final short LENGTH = 4;
@@ -116,6 +112,14 @@ public class AutonomousSystemTlv implements BGPValueType {
}
@Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ return ((Integer) (this.asNum)).compareTo((Integer) (((AutonomousSystemTlv) o).asNum));
+ }
+
+ @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("Type", TYPE)
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpErrorType.java
index dfcfc9dc..c0932ebe 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpErrorType.java
@@ -19,8 +19,8 @@ package org.onosproject.bgpio.types;
/**
* BgpErrorType class defines all errorCodes and error Subcodes required for Notification message.
*/
-public final class BGPErrorType {
- private BGPErrorType() {
+public final class BgpErrorType {
+ private BgpErrorType() {
}
//Error Codes
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPHeader.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpHeader.java
index 6acda0d6..ad637753 100755
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPHeader.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpHeader.java
@@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory;
* Provides BGP Message Header which is common for all the Messages.
*/
-public class BGPHeader {
+public class BgpHeader {
/* 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@@ -40,7 +40,7 @@ public class BGPHeader {
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
- protected static final Logger log = LoggerFactory.getLogger(BGPHeader.class);
+ protected static final Logger log = LoggerFactory.getLogger(BgpHeader.class);
public static final int MARKER_LENGTH = 16;
public static final short DEFAULT_HEADER_LENGTH = 19;
@@ -52,7 +52,7 @@ public class BGPHeader {
/**
* Reset fields.
*/
- public BGPHeader() {
+ public BgpHeader() {
this.marker = null;
this.length = 0;
this.type = 0;
@@ -65,7 +65,7 @@ public class BGPHeader {
* @param length message length
* @param type message type
*/
- public BGPHeader(byte[] marker, short length, byte type) {
+ public BgpHeader(byte[] marker, short length, byte type) {
this.marker = marker;
this.length = length;
this.type = type;
@@ -148,7 +148,7 @@ public class BGPHeader {
* @param cb ChannelBuffer
* @return object of BGPHeader
*/
- public static BGPHeader read(ChannelBuffer cb) {
+ public static BgpHeader read(ChannelBuffer cb) {
byte[] marker = new byte[MARKER_LENGTH];
byte type;
@@ -156,6 +156,6 @@ public class BGPHeader {
cb.readBytes(marker, 0, MARKER_LENGTH);
length = cb.readShort();
type = cb.readByte();
- return new BGPHeader(marker, length, type);
+ return new BgpHeader(marker, length, type);
}
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPLSIdentifierTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpLSIdentifierTlv.java
index f723d2ca..58645d4f 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPLSIdentifierTlv.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpLSIdentifierTlv.java
@@ -19,15 +19,13 @@ package org.onosproject.bgpio.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides BGPLSIdentifier Tlv which contains opaque value (32 Bit BGPLS-Identifier).
*/
-public class BGPLSIdentifierTlv implements BGPValueType {
+public class BgpLSIdentifierTlv implements BgpValueType {
/* Reference :draft-ietf-idr-ls-distribution-11
* 0 1 2 3
@@ -39,44 +37,42 @@ public class BGPLSIdentifierTlv implements BGPValueType {
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
- protected static final Logger log = LoggerFactory.getLogger(BGPLSIdentifierTlv.class);
-
public static final short TYPE = 513;
public static final short LENGTH = 4;
- private final int bgpLSIdentifier;
+ private final int bgpLsIdentifier;
/**
- * Constructor to initialize bgpLSIdentifier.
+ * Constructor to initialize bgpLsIdentifier.
*
- * @param bgpLSIdentifier BgpLS-Identifier
+ * @param bgpLsIdentifier BGPLS-Identifier
*/
- public BGPLSIdentifierTlv(int bgpLSIdentifier) {
- this.bgpLSIdentifier = bgpLSIdentifier;
+ public BgpLSIdentifierTlv(int bgpLsIdentifier) {
+ this.bgpLsIdentifier = bgpLsIdentifier;
}
/**
- * Returns object of this class with specified rbgpLSIdentifier.
+ * Returns object of this class with specified bgpLsIdentifier.
*
- * @param bgpLSIdentifier BgpLS-Identifier
- * @return BgpLS-Identifier
+ * @param bgpLsIdentifier BGPLS-Identifier
+ * @return BGPLS-Identifier
*/
- public static BGPLSIdentifierTlv of(final int bgpLSIdentifier) {
- return new BGPLSIdentifierTlv(bgpLSIdentifier);
+ public static BgpLSIdentifierTlv of(final int bgpLsIdentifier) {
+ return new BgpLSIdentifierTlv(bgpLsIdentifier);
}
/**
- * Returns opaque value of BgpLS-Identifier.
+ * Returns opaque value of BGPLS-Identifier.
*
- * @return opaque value of BgpLS-Identifier
+ * @return opaque value of BGPLS-Identifier
*/
- public int getBgpLSIdentifier() {
- return bgpLSIdentifier;
+ public int getBgpLsIdentifier() {
+ return bgpLsIdentifier;
}
@Override
public int hashCode() {
- return Objects.hash(bgpLSIdentifier);
+ return Objects.hash(bgpLsIdentifier);
}
@Override
@@ -85,9 +81,9 @@ public class BGPLSIdentifierTlv implements BGPValueType {
return true;
}
- if (obj instanceof BGPLSIdentifierTlv) {
- BGPLSIdentifierTlv other = (BGPLSIdentifierTlv) obj;
- return Objects.equals(bgpLSIdentifier, other.bgpLSIdentifier);
+ if (obj instanceof BgpLSIdentifierTlv) {
+ BgpLSIdentifierTlv other = (BgpLSIdentifierTlv) obj;
+ return Objects.equals(bgpLsIdentifier, other.bgpLsIdentifier);
}
return false;
}
@@ -97,7 +93,7 @@ public class BGPLSIdentifierTlv implements BGPValueType {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
- c.writeInt(bgpLSIdentifier);
+ c.writeInt(bgpLsIdentifier);
return c.writerIndex() - iLenStartIndex;
}
@@ -107,8 +103,8 @@ public class BGPLSIdentifierTlv implements BGPValueType {
* @param cb ChannelBuffer
* @return object of BGPLSIdentifierTlv
*/
- public static BGPLSIdentifierTlv read(ChannelBuffer cb) {
- return BGPLSIdentifierTlv.of(cb.readInt());
+ public static BgpLSIdentifierTlv read(ChannelBuffer cb) {
+ return BgpLSIdentifierTlv.of(cb.readInt());
}
@Override
@@ -117,11 +113,19 @@ public class BGPLSIdentifierTlv implements BGPValueType {
}
@Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ return ((Integer) (this.bgpLsIdentifier)).compareTo((Integer) (((BgpLSIdentifierTlv) o).bgpLsIdentifier));
+ }
+
+ @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("Type", TYPE)
.add("Length", LENGTH)
- .add("Value", bgpLSIdentifier)
+ .add("Value", bgpLsIdentifier)
.toString();
}
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPValueType.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpValueType.java
index 54a8b43c..af7f4b75 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPValueType.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpValueType.java
@@ -21,7 +21,7 @@ import org.jboss.netty.buffer.ChannelBuffer;
/**
* Abstraction which Provides the BGP of TLV format.
*/
-public interface BGPValueType {
+public interface BgpValueType {
/**
* Returns the Type of BGP Message.
*
@@ -36,4 +36,12 @@ public interface BGPValueType {
* @return length written to channel buffer
*/
int write(ChannelBuffer cb);
+
+ /**
+ * Compares two objects.
+ *
+ * @param o object
+ * @return result after comparing two objects
+ */
+ int compareTo(Object o);
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/FourOctetAsNumCapabilityTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/FourOctetAsNumCapabilityTlv.java
index 61570285..59db3318 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/FourOctetAsNumCapabilityTlv.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/FourOctetAsNumCapabilityTlv.java
@@ -26,7 +26,7 @@ import com.google.common.base.MoreObjects;
/**
* Provides FourOctetAsNumCapabilityTlv Capability Tlv.
*/
-public class FourOctetAsNumCapabilityTlv implements BGPValueType {
+public class FourOctetAsNumCapabilityTlv implements BgpValueType {
/**
* support to indicate its support for four-octet AS numbers -CAPABILITY TLV format.
@@ -111,4 +111,10 @@ public class FourOctetAsNumCapabilityTlv implements BGPValueType {
.add("Length", LENGTH)
.add("Value", rawValue).toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java
index 59afbed6..d97537e8 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java
@@ -15,21 +15,20 @@
*/
package org.onosproject.bgpio.types;
+import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.IpPrefix;
import org.onosproject.bgpio.util.Validation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides IP Reachability InformationTlv Tlv which contains IP Prefix.
*/
-public class IPReachabilityInformationTlv implements BGPValueType {
+public class IPReachabilityInformationTlv implements BgpValueType {
/*
* Reference :draft-ietf-idr-ls-distribution-11
@@ -45,10 +44,9 @@ public class IPReachabilityInformationTlv implements BGPValueType {
Figure 14: IP Reachability Information TLV Format
*/
- protected static final Logger log = LoggerFactory.getLogger(IPReachabilityInformationTlv.class);
-
public static final short TYPE = 265;
public static final int ONE_BYTE_LEN = 8;
+
private byte prefixLen;
private byte[] ipPrefix;
public short length;
@@ -146,6 +144,16 @@ public class IPReachabilityInformationTlv implements BGPValueType {
}
@Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ ByteBuffer value1 = ByteBuffer.wrap(this.ipPrefix);
+ ByteBuffer value2 = ByteBuffer.wrap(((IPReachabilityInformationTlv) o).ipPrefix);
+ return value1.compareTo(value2);
+ }
+
+ @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("Type", TYPE)
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java
index d5f03268..4efde70e 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java
@@ -20,9 +20,8 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip4Address;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.util.Validation;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
@@ -30,8 +29,7 @@ import com.google.common.base.Preconditions;
/**
* Provides Implementation of IPv4AddressTlv.
*/
-public class IPv4AddressTlv implements BGPValueType {
- private static final Logger log = LoggerFactory.getLogger(IPv4AddressTlv.class);
+public class IPv4AddressTlv implements BgpValueType {
private static final int LENGTH = 4;
private Ip4Address address;
@@ -53,7 +51,7 @@ public class IPv4AddressTlv implements BGPValueType {
*
* @return Ipv4 address of interface/neighbor
*/
- public Ip4Address getValue() {
+ public Ip4Address address() {
return address;
}
@@ -94,13 +92,12 @@ public class IPv4AddressTlv implements BGPValueType {
* @param cb channelBuffer
* @param type address type
* @return object of IPv4AddressTlv
- * @throws BGPParseException while parsing IPv4AddressTlv
+ * @throws BgpParseException while parsing IPv4AddressTlv
*/
- public static IPv4AddressTlv read(ChannelBuffer cb, short type) throws BGPParseException {
- //TODO: use Validation.toInetAddress once Validation is merged
- InetAddress ipAddress = (InetAddress) cb.readBytes(LENGTH);
+ public static IPv4AddressTlv read(ChannelBuffer cb, short type) throws BgpParseException {
+ InetAddress ipAddress = Validation.toInetAddress(LENGTH, cb);
if (ipAddress.isMulticastAddress()) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
}
Ip4Address address = Ip4Address.valueOf(ipAddress);
return IPv4AddressTlv.of(address, type);
@@ -118,6 +115,14 @@ public class IPv4AddressTlv implements BGPValueType {
}
@Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ return ((Ip4Address) (this.address)).compareTo((Ip4Address) (((IPv4AddressTlv) o).address));
+ }
+
+ @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("type", type)
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java
index 65b7c16d..087cd5c6 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java
@@ -20,9 +20,8 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip6Address;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.util.Validation;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
@@ -30,8 +29,7 @@ import com.google.common.base.Preconditions;
/**
* Provides Implementation of IPv6AddressTlv.
*/
-public class IPv6AddressTlv implements BGPValueType {
- private static final Logger log = LoggerFactory.getLogger(IPv6AddressTlv.class);
+public class IPv6AddressTlv implements BgpValueType {
private static final int LENGTH = 16;
private final Ip6Address address;
@@ -53,7 +51,7 @@ public class IPv6AddressTlv implements BGPValueType {
*
* @return Ipv6 address of interface/neighbor
*/
- public Ip6Address getValue() {
+ public Ip6Address address() {
return address;
}
@@ -94,13 +92,12 @@ public class IPv6AddressTlv implements BGPValueType {
* @param cb channelBuffer
* @param type address type
* @return object of IPv6AddressTlv
- * @throws BGPParseException while parsing IPv6AddressTlv
+ * @throws BgpParseException while parsing IPv6AddressTlv
*/
- public static IPv6AddressTlv read(ChannelBuffer cb, short type) throws BGPParseException {
- //TODO: use Validation.toInetAddress once Validation is merged
- InetAddress ipAddress = (InetAddress) cb.readBytes(LENGTH);
+ public static IPv6AddressTlv read(ChannelBuffer cb, short type) throws BgpParseException {
+ InetAddress ipAddress = Validation.toInetAddress(LENGTH, cb);
if (ipAddress.isMulticastAddress()) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
}
Ip6Address address = Ip6Address.valueOf(ipAddress);
return IPv6AddressTlv.of(address, type);
@@ -118,6 +115,14 @@ public class IPv6AddressTlv implements BGPValueType {
}
@Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ return ((Ip6Address) (this.address)).compareTo((Ip6Address) (((IPv6AddressTlv) o).address));
+ }
+
+ @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("type", type)
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsNonPseudonode.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsNonPseudonode.java
index d5f3e7f3..427aa929 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsNonPseudonode.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsNonPseudonode.java
@@ -15,21 +15,18 @@
*/
package org.onosproject.bgpio.types;
-import java.util.Objects;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.protocol.IGPRouterID;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides Implementation of IsIsNonPseudonode Tlv.
*/
-public class IsIsNonPseudonode implements IGPRouterID, BGPValueType {
- protected static final Logger log = LoggerFactory.getLogger(IsIsNonPseudonode.class);
-
+public class IsIsNonPseudonode implements IGPRouterID, BgpValueType {
public static final short TYPE = 515;
public static final short LENGTH = 6;
@@ -41,7 +38,7 @@ public class IsIsNonPseudonode implements IGPRouterID, BGPValueType {
* @param isoNodeID ISO system-ID
*/
public IsIsNonPseudonode(byte[] isoNodeID) {
- this.isoNodeID = isoNodeID;
+ this.isoNodeID = Arrays.copyOf(isoNodeID, isoNodeID.length);
}
/**
@@ -65,7 +62,7 @@ public class IsIsNonPseudonode implements IGPRouterID, BGPValueType {
@Override
public int hashCode() {
- return Objects.hash(isoNodeID);
+ return Arrays.hashCode(isoNodeID);
}
@Override
@@ -75,7 +72,7 @@ public class IsIsNonPseudonode implements IGPRouterID, BGPValueType {
}
if (obj instanceof IsIsNonPseudonode) {
IsIsNonPseudonode other = (IsIsNonPseudonode) obj;
- return Objects.equals(isoNodeID, other.isoNodeID);
+ return Arrays.equals(isoNodeID, other.isoNodeID);
}
return false;
}
@@ -97,7 +94,7 @@ public class IsIsNonPseudonode implements IGPRouterID, BGPValueType {
*/
public static IsIsNonPseudonode read(ChannelBuffer cb) {
byte[] isoNodeID = new byte[LENGTH];
- cb.readBytes(isoNodeID, 0, LENGTH);
+ cb.readBytes(isoNodeID);
return IsIsNonPseudonode.of(isoNodeID);
}
@@ -107,6 +104,16 @@ public class IsIsNonPseudonode implements IGPRouterID, BGPValueType {
}
@Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ ByteBuffer value1 = ByteBuffer.wrap(this.isoNodeID);
+ ByteBuffer value2 = ByteBuffer.wrap(((IsIsNonPseudonode) o).isoNodeID);
+ return value1.compareTo(value2);
+ }
+
+ @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("Type", TYPE)
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java
index 35fd2493..094c4382 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java
@@ -15,28 +15,23 @@
*/
package org.onosproject.bgpio.types;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.protocol.IGPRouterID;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides implementation of IsIsPseudonode Tlv.
*/
-public class IsIsPseudonode implements IGPRouterID, BGPValueType {
- private static final Logger log = LoggerFactory.getLogger(IsIsPseudonode.class);
-
+public class IsIsPseudonode implements IGPRouterID, BgpValueType {
public static final short TYPE = 515;
public static final short LENGTH = 7;
- private final List<Byte> isoNodeID;
+ private final byte[] isoNodeID;
private byte psnIdentifier;
/**
@@ -45,8 +40,8 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
* @param isoNodeID ISO system-ID
* @param psnIdentifier PSN identifier
*/
- public IsIsPseudonode(List<Byte> isoNodeID, byte psnIdentifier) {
- this.isoNodeID = isoNodeID;
+ public IsIsPseudonode(byte[] isoNodeID, byte psnIdentifier) {
+ this.isoNodeID = Arrays.copyOf(isoNodeID, isoNodeID.length);
this.psnIdentifier = psnIdentifier;
}
@@ -57,7 +52,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
* @param psnIdentifier PSN identifier
* @return object of IsIsPseudonode
*/
- public static IsIsPseudonode of(final List<Byte> isoNodeID,
+ public static IsIsPseudonode of(final byte[] isoNodeID,
final byte psnIdentifier) {
return new IsIsPseudonode(isoNodeID, psnIdentifier);
}
@@ -67,7 +62,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
*
* @return ISO NodeID
*/
- public List<Byte> getISONodeID() {
+ public byte[] getISONodeID() {
return isoNodeID;
}
@@ -82,7 +77,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
@Override
public int hashCode() {
- return Objects.hash(isoNodeID) & Objects.hash(psnIdentifier);
+ return Arrays.hashCode(isoNodeID) & Objects.hash(psnIdentifier);
}
@Override
@@ -91,27 +86,9 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
return true;
}
if (obj instanceof IsIsPseudonode) {
- int countObjSubTlv = 0;
- int countOtherSubTlv = 0;
- boolean isCommonSubTlv = true;
IsIsPseudonode other = (IsIsPseudonode) obj;
- Iterator<Byte> objListIterator = other.isoNodeID.iterator();
- countOtherSubTlv = other.isoNodeID.size();
- countObjSubTlv = isoNodeID.size();
- if (countObjSubTlv != countOtherSubTlv) {
- return false;
- } else {
- while (objListIterator.hasNext() && isCommonSubTlv) {
- Byte subTlv = objListIterator.next();
- if (isoNodeID.contains(subTlv) && other.isoNodeID.contains(subTlv)) {
- isCommonSubTlv = Objects.equals(isoNodeID.get(isoNodeID.indexOf(subTlv)),
- other.isoNodeID.get(other.isoNodeID.indexOf(subTlv)));
- } else {
- isCommonSubTlv = false;
- }
- }
- return isCommonSubTlv && Objects.equals(psnIdentifier, other.psnIdentifier);
- }
+ return Arrays.equals(isoNodeID, other.isoNodeID)
+ && Objects.equals(psnIdentifier, other.psnIdentifier);
}
return false;
}
@@ -121,11 +98,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
- Iterator<Byte> objListIterator = isoNodeID.iterator();
- while (objListIterator.hasNext()) {
- byte value = objListIterator.next();
- c.writeByte(value);
- }
+ c.writeBytes(isoNodeID, 0, LENGTH - 1);
c.writeByte(psnIdentifier);
return c.writerIndex() - iLenStartIndex;
}
@@ -137,12 +110,8 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
* @return object of IsIsPseudonode
*/
public static IsIsPseudonode read(ChannelBuffer cb) {
- List<Byte> isoNodeID = new ArrayList<Byte>();
- byte value;
- for (int i = 0; i < LENGTH; i++) {
- value = cb.readByte();
- isoNodeID.add(value);
- }
+ byte[] isoNodeID = new byte[LENGTH - 1];
+ cb.readBytes(isoNodeID);
byte psnIdentifier = cb.readByte();
return IsIsPseudonode.of(isoNodeID, psnIdentifier);
}
@@ -153,6 +122,19 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
}
@Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ ByteBuffer value1 = ByteBuffer.wrap(this.isoNodeID);
+ ByteBuffer value2 = ByteBuffer.wrap(((IsIsPseudonode) o).isoNodeID);
+ if (value1.compareTo(value2) != 0) {
+ return value1.compareTo(value2);
+ }
+ return ((Byte) (this.psnIdentifier)).compareTo((Byte) (((IsIsPseudonode) o).psnIdentifier));
+ }
+
+ @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("Type", TYPE)
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java
index 988925f5..0c412432 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java
@@ -18,16 +18,13 @@ package org.onosproject.bgpio.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides Implementation of Link Local/Remote IdentifiersTlv.
*/
-public class LinkLocalRemoteIdentifiersTlv implements BGPValueType {
- private static final Logger log = LoggerFactory.getLogger(LinkLocalRemoteIdentifiersTlv.class);
+public class LinkLocalRemoteIdentifiersTlv implements BgpValueType {
public static final short TYPE = 258;
private static final int LENGTH = 8;
@@ -120,6 +117,20 @@ public class LinkLocalRemoteIdentifiersTlv implements BGPValueType {
}
@Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ int result = ((Integer) (this.linkLocalIdentifer))
+ .compareTo((Integer) (((LinkLocalRemoteIdentifiersTlv) o).linkLocalIdentifer));
+ if (result != 0) {
+ return result;
+ }
+ return ((Integer) (this.linkRemoteIdentifer))
+ .compareTo((Integer) (((LinkLocalRemoteIdentifiersTlv) o).linkRemoteIdentifer));
+ }
+
+ @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("TYPE", TYPE)
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkStateAttributes.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkStateAttributes.java
new file mode 100644
index 00000000..cdf6ebeb
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkStateAttributes.java
@@ -0,0 +1,314 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.attr.BgpAttrNodeFlagBitTlv;
+import org.onosproject.bgpio.types.attr.BgpAttrNodeIsIsAreaId;
+import org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId;
+import org.onosproject.bgpio.types.attr.BgpAttrNodeName;
+import org.onosproject.bgpio.types.attr.BgpAttrOpaqueNode;
+import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV4;
+import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV6;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrIgpMetric;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrIsIsAdminstGrp;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrMplsProtocolMask;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrMaxLinkBandwidth;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrName;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrOpaqLnkAttrib;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrProtectionType;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrSrlg;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrTeDefaultMetric;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrUnRsrvdLinkBandwidth;
+import org.onosproject.bgpio.types.attr.BgpPrefixAttrExtRouteTag;
+import org.onosproject.bgpio.types.attr.BgpPrefixAttrIgpFlags;
+import org.onosproject.bgpio.types.attr.BgpPrefixAttrMetric;
+import org.onosproject.bgpio.types.attr.BgpPrefixAttrOspfFwdAddr;
+import org.onosproject.bgpio.types.attr.BgpPrefixAttrOpaqueData;
+import org.onosproject.bgpio.types.attr.BgpPrefixAttrRouteTag;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP Link state attribute.
+ */
+public class LinkStateAttributes implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(LinkStateAttributes.class);
+
+ /* Node Attributes */
+ public static final short ATTR_NODE_MT_TOPOLOGY_ID = 263;
+ public static final short ATTR_NODE_FLAG_BITS = 1024;
+ public static final short ATTR_NODE_OPAQUE_NODE = 1025;
+ public static final short ATTR_NODE_NAME = 1026;
+ public static final short ATTR_NODE_ISIS_AREA_ID = 1027;
+ public static final short ATTR_NODE_IPV4_LOCAL_ROUTER_ID = 1028;
+ public static final short ATTR_NODE_IPV6_LOCAL_ROUTER_ID = 1029;
+
+ /* Link Attributes */
+ public static final short ATTR_LINK_IPV4_REMOTE_ROUTER_ID = 1030;
+ public static final short ATTR_LINK_IPV6_REMOTE_ROUTER_ID = 1031;
+ public static final short ATTR_LINK_ADMINISTRATIVE_GRPS = 1088;
+ public static final short ATTR_LINK_MAX_BANDWIDTH = 1089;
+ public static final short ATTR_LINK_MAX_RES_BANDWIDTH = 1090;
+ public static final short ATTR_LINK_UNRES_BANDWIDTH = 1091;
+ public static final short ATTR_LINK_TE_DEFAULT_METRIC = 1092;
+ public static final short ATTR_LINK_PROTECTION_TYPE = 1093;
+ public static final short ATTR_LINK_MPLS_PROTOCOL_MASK = 1094;
+ public static final short ATTR_LINK_IGP_METRIC = 1095;
+ public static final short ATTR_LINK_SHR_RISK_GRP = 1096;
+ public static final short ATTR_LINK_OPAQUE_ATTR = 1097;
+ public static final short ATTR_LINK_NAME_ATTR = 1098;
+
+ /* Prefix Attributes */
+ public static final short ATTR_PREFIX_IGP_FLAG = 1152;
+ public static final short ATTR_PREFIX_ROUTE_TAG = 1153;
+ public static final short ATTR_PREFIX_EXTENDED_TAG = 1154;
+ public static final short ATTR_PREFIX_METRIC = 1155;
+ public static final short ATTR_PREFIX_OSPF_FWD_ADDR = 1156;
+ public static final short ATTR_PREFIX_OPAQUE_ATTR = 1157;
+
+ public static final byte LINKSTATE_ATTRIB_TYPE = 50;
+ public static final byte TYPE_AND_LEN = 4;
+ private boolean isLinkStateAttribute = false;
+ private List<BgpValueType> linkStateAttribList;
+
+ /**
+ * Constructor to reset parameters.
+ */
+ LinkStateAttributes() {
+ this.linkStateAttribList = null;
+ }
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param linkStateAttribList Linked list of Link, Node and Prefix TLVs
+ */
+ LinkStateAttributes(List<BgpValueType> linkStateAttribList) {
+ this.linkStateAttribList = linkStateAttribList;
+ this.isLinkStateAttribute = true;
+ }
+
+ /**
+ * Returns linked list of Link, Node and Prefix TLVs.
+ *
+ * @return linked list of Link, Node and Prefix TLVs
+ */
+ public List<BgpValueType> linkStateAttributes() {
+ return this.linkStateAttribList;
+ }
+
+ /**
+ * Returns if the Link state attributes are set or not.
+ *
+ * @return a boolean value to to check if the LS attributes are set or not
+ */
+ public boolean isLinkStateAttributeSet() {
+ return this.isLinkStateAttribute;
+ }
+
+ /**
+ * Reads the Link state attribute TLVs.
+ *
+ * @param cb ChannelBuffer
+ * @return constructor of LinkStateAttributes
+ * @throws BgpParseException while parsing link state attributes
+ */
+ public static LinkStateAttributes read(ChannelBuffer cb)
+ throws BgpParseException {
+
+ ChannelBuffer tempBuf = cb;
+ Validation parseFlags = Validation.parseAttributeHeader(cb);
+ int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN
+ : parseFlags.getLength() + 3;
+
+ ChannelBuffer data = tempBuf.readBytes(len);
+ if (!parseFlags.getFirstBit() || parseFlags.getSecondBit()
+ || parseFlags.getThirdBit()) {
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_FLAGS_ERROR,
+ data);
+ }
+
+ if (cb.readableBytes() < parseFlags.getLength()) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.BAD_MESSAGE_LENGTH,
+ parseFlags.getLength());
+ }
+
+ BgpValueType bgpLSAttrib = null;
+ LinkedList<BgpValueType> linkStateAttribList;
+ linkStateAttribList = new LinkedList<BgpValueType>();
+ ChannelBuffer tempCb = cb.readBytes(parseFlags.getLength());
+ while (tempCb.readableBytes() > 0) {
+ short tlvCodePoint = tempCb.readShort();
+ switch (tlvCodePoint) {
+
+ /********* 7 NODE ATTRIBUTES ********/
+ case ATTR_NODE_MT_TOPOLOGY_ID: /* 263 Multi-Topology Identifier*/
+ bgpLSAttrib = BgpAttrNodeMultiTopologyId.read(tempCb);
+ break;
+
+ case ATTR_NODE_FLAG_BITS: /*Node flag bit TLV*/
+ bgpLSAttrib = BgpAttrNodeFlagBitTlv.read(tempCb);
+ break;
+
+ case ATTR_NODE_OPAQUE_NODE: /*Opaque Node Attribute*/
+ bgpLSAttrib = BgpAttrOpaqueNode.read(tempCb);
+ break;
+
+ case ATTR_NODE_NAME: /*Node Name*/
+ bgpLSAttrib = BgpAttrNodeName.read(tempCb);
+ break;
+
+ case ATTR_NODE_ISIS_AREA_ID: /*IS-IS Area Identifier TLV*/
+ bgpLSAttrib = BgpAttrNodeIsIsAreaId.read(tempCb);
+ break;
+
+ case ATTR_NODE_IPV4_LOCAL_ROUTER_ID: /*IPv4 Router-ID of Local Node*/
+ bgpLSAttrib = BgpAttrRouterIdV4.read(tempCb, (short) ATTR_NODE_IPV4_LOCAL_ROUTER_ID);
+ break;
+
+ case ATTR_NODE_IPV6_LOCAL_ROUTER_ID: /*IPv6 Router-ID of Local Node*/
+ bgpLSAttrib = BgpAttrRouterIdV6.read(tempCb, (short) ATTR_NODE_IPV6_LOCAL_ROUTER_ID);
+ break;
+
+ /********* 15 LINK ATTRIBUTES ********/
+
+ case ATTR_LINK_IPV4_REMOTE_ROUTER_ID: /*IPv4 Router-ID of Remote Node*/
+ bgpLSAttrib = BgpAttrRouterIdV4.read(tempCb, (short) 1030);
+ break;
+
+ case ATTR_LINK_IPV6_REMOTE_ROUTER_ID: /*IPv6 Router-ID of Remote Node*/
+ bgpLSAttrib = BgpAttrRouterIdV6.read(tempCb, (short) 1031);
+ break;
+
+ case ATTR_LINK_ADMINISTRATIVE_GRPS: /*ISIS Administrative group STLV 3*/
+ bgpLSAttrib = BgpLinkAttrIsIsAdminstGrp.read(tempCb);
+ break;
+
+ case ATTR_LINK_MAX_BANDWIDTH: /*Maximum link bandwidth*/
+ bgpLSAttrib = BgpLinkAttrMaxLinkBandwidth.read(tempCb,
+ (short) 1089);
+ break;
+
+ case ATTR_LINK_MAX_RES_BANDWIDTH: /* Maximum Reservable link bandwidth */
+ bgpLSAttrib = BgpLinkAttrMaxLinkBandwidth.read(tempCb,
+ (short) 1090);
+ break;
+
+ case ATTR_LINK_UNRES_BANDWIDTH: /* UnReserved link bandwidth */
+ bgpLSAttrib = BgpLinkAttrUnRsrvdLinkBandwidth
+ .read(tempCb, (short) 1091);
+ break;
+
+ case ATTR_LINK_TE_DEFAULT_METRIC: /* TE Default Metric */
+ bgpLSAttrib = BgpLinkAttrTeDefaultMetric.read(tempCb);
+ break;
+
+ case ATTR_LINK_PROTECTION_TYPE:/* Link Protection type */
+ bgpLSAttrib = BgpLinkAttrProtectionType.read(tempCb);
+ break;
+
+ case ATTR_LINK_MPLS_PROTOCOL_MASK: /* MPLS Protocol Mask */
+ bgpLSAttrib = BgpLinkAttrMplsProtocolMask.read(tempCb); // 2
+ break;
+
+ case ATTR_LINK_IGP_METRIC: /* IGP Metric */
+ bgpLSAttrib = BgpLinkAttrIgpMetric.read(tempCb); // 2
+ break;
+
+ case ATTR_LINK_SHR_RISK_GRP: /* Shared Risk Link Group */
+ bgpLSAttrib = BgpLinkAttrSrlg.read(tempCb); // 3
+ break;
+
+ case ATTR_LINK_OPAQUE_ATTR: /* Opaque link attribute */
+ bgpLSAttrib = BgpLinkAttrOpaqLnkAttrib.read(tempCb);
+ break;
+
+ case ATTR_LINK_NAME_ATTR: /* Link Name attribute */
+ bgpLSAttrib = BgpLinkAttrName.read(tempCb);
+ break;
+
+ /********* 6 PREFIX ATTRIBUTES ********/
+
+ case ATTR_PREFIX_IGP_FLAG: /* IGP Flags */
+ bgpLSAttrib = BgpPrefixAttrIgpFlags.read(tempCb);
+ break;
+
+ case ATTR_PREFIX_ROUTE_TAG: /* Route Tag */
+ bgpLSAttrib = BgpPrefixAttrRouteTag.read(tempCb);
+ break;
+
+ case ATTR_PREFIX_EXTENDED_TAG: /* Extended Tag */
+ bgpLSAttrib = BgpPrefixAttrExtRouteTag.read(tempCb);
+ break;
+
+ case ATTR_PREFIX_METRIC: /* Prefix Metric */
+ bgpLSAttrib = BgpPrefixAttrMetric.read(tempCb);
+ break;
+
+ case ATTR_PREFIX_OSPF_FWD_ADDR: /* OSPF Forwarding Address */
+ bgpLSAttrib = BgpPrefixAttrOspfFwdAddr.read(tempCb);
+ break;
+
+ case ATTR_PREFIX_OPAQUE_ATTR: /* Opaque Prefix Attribute */
+ bgpLSAttrib = BgpPrefixAttrOpaqueData.read(tempCb);
+ break;
+
+ default:
+ throw new BgpParseException(
+ "The Bgp-LS Attribute is not supported : "
+ + tlvCodePoint);
+ }
+
+ linkStateAttribList.add(bgpLSAttrib);
+ }
+ return new LinkStateAttributes(linkStateAttribList);
+ }
+
+ @Override
+ public short getType() {
+ return LINKSTATE_ATTRIB_TYPE;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("linkStateAttribList", linkStateAttribList).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java
index 0f78ab77..36793c18 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java
@@ -18,7 +18,7 @@ package org.onosproject.bgpio.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.exceptions.BgpParseException;
import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
@@ -27,7 +27,7 @@ import com.google.common.base.MoreObjects;
/**
* Provides implementation of LocalPref BGP Path Attribute.
*/
-public class LocalPref implements BGPValueType {
+public class LocalPref implements BgpValueType {
public static final byte LOCAL_PREF_TYPE = 5;
public static final byte LOCAL_PREF_MAX_LEN = 4;
@@ -56,14 +56,14 @@ public class LocalPref implements BGPValueType {
*
* @param cb channelBuffer
* @return object of LocalPref
- * @throws BGPParseException while parsing localPref attribute
+ * @throws BgpParseException while parsing localPref attribute
*/
- public static LocalPref read(ChannelBuffer cb) throws BGPParseException {
+ public static LocalPref read(ChannelBuffer cb) throws BgpParseException {
int localPref;
ChannelBuffer tempCb = cb.copy();
Validation parseFlags = Validation.parseAttributeHeader(cb);
if ((parseFlags.getLength() > LOCAL_PREF_MAX_LEN) || cb.readableBytes() < parseFlags.getLength()) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
parseFlags.getLength());
}
@@ -71,7 +71,7 @@ public class LocalPref implements BGPValueType {
Constants.TYPE_AND_LEN_AS_SHORT : parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (parseFlags.getFirstBit()) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
}
localPref = cb.readInt();
@@ -112,4 +112,10 @@ public class LocalPref implements BGPValueType {
//Not to implement as of now
return 0;
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java
index 23402c26..7f1ab53f 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java
@@ -18,7 +18,7 @@ package org.onosproject.bgpio.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.exceptions.BgpParseException;
import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
@@ -27,7 +27,7 @@ import com.google.common.base.MoreObjects;
/**
* Provides Implementation of Med BGP Path Attribute.
*/
-public class Med implements BGPValueType {
+public class Med implements BgpValueType {
public static final byte MED_TYPE = 4;
public static final byte MED_MAX_LEN = 4;
@@ -56,22 +56,22 @@ public class Med implements BGPValueType {
*
* @param cb ChannelBuffer
* @return object of Med
- * @throws BGPParseException while parsing Med path attribute
+ * @throws BgpParseException while parsing Med path attribute
*/
- public static Med read(ChannelBuffer cb) throws BGPParseException {
+ public static Med read(ChannelBuffer cb) throws BgpParseException {
int med;
ChannelBuffer tempCb = cb.copy();
Validation parseFlags = Validation.parseAttributeHeader(cb);
if ((parseFlags.getLength() > MED_MAX_LEN) || cb.readableBytes() < parseFlags.getLength()) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
parseFlags.getLength());
}
int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (!parseFlags.getFirstBit() && parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
}
med = cb.readInt();
@@ -112,4 +112,10 @@ public class Med implements BGPValueType {
//Not to implement as of now
return 0;
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java
index fe99d28d..689f30ea 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java
@@ -22,10 +22,10 @@ import java.util.List;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip4Address;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.protocol.BGPLSNlri;
-import org.onosproject.bgpio.protocol.linkstate.BGPPrefixIPv4LSNlriVer4;
-import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpLSNlri;
+import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
@@ -37,14 +37,14 @@ import com.google.common.base.MoreObjects;
/*
* Provides Implementation of MpReach Nlri BGP Path Attribute.
*/
-public class MpReachNlri implements BGPValueType {
+public class MpReachNlri implements BgpValueType {
private static final Logger log = LoggerFactory.getLogger(MpReachNlri.class);
public static final byte MPREACHNLRI_TYPE = 14;
public static final byte LINK_NLRITYPE = 2;
private boolean isMpReachNlri = false;
- private final List<BGPLSNlri> mpReachNlri;
+ private final List<BgpLSNlri> mpReachNlri;
private final int length;
private final short afi;
private final byte safi;
@@ -59,7 +59,7 @@ public class MpReachNlri implements BGPValueType {
* @param ipNextHop nexthop IpAddress
* @param length of MpReachNlri
*/
- public MpReachNlri(List<BGPLSNlri> mpReachNlri, short afi, byte safi, Ip4Address ipNextHop, int length) {
+ public MpReachNlri(List<BgpLSNlri> mpReachNlri, short afi, byte safi, Ip4Address ipNextHop, int length) {
this.mpReachNlri = mpReachNlri;
this.isMpReachNlri = true;
this.ipNextHop = ipNextHop;
@@ -82,7 +82,7 @@ public class MpReachNlri implements BGPValueType {
*
* @return list of MpReach Nlri
*/
- public List<BGPLSNlri> mpReachNlri() {
+ public List<BgpLSNlri> mpReachNlri() {
return this.mpReachNlri;
}
@@ -100,9 +100,9 @@ public class MpReachNlri implements BGPValueType {
*
* @param cb channelBuffer
* @return object of MpReachNlri
- * @throws BGPParseException while parsing MpReachNlri
+ * @throws BgpParseException while parsing MpReachNlri
*/
- public static MpReachNlri read(ChannelBuffer cb) throws BGPParseException {
+ public static MpReachNlri read(ChannelBuffer cb) throws BgpParseException {
ChannelBuffer tempBuf = cb.copy();
Validation parseFlags = Validation.parseAttributeHeader(cb);
int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT :
@@ -110,15 +110,15 @@ public class MpReachNlri implements BGPValueType {
ChannelBuffer data = tempBuf.readBytes(len);
if (cb.readableBytes() < parseFlags.getLength()) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
parseFlags.getLength());
}
if (!parseFlags.getFirstBit() && parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
}
- BGPLSNlri bgpLSNlri = null;
- List<BGPLSNlri> mpReachNlri = new LinkedList<>();
+ BgpLSNlri bgpLSNlri = null;
+ List<BgpLSNlri> mpReachNlri = new LinkedList<>();
ChannelBuffer tempCb = cb.readBytes(parseFlags.getLength());
short afi = 0;
byte safi = 0;
@@ -133,7 +133,7 @@ public class MpReachNlri implements BGPValueType {
byte nextHopLen = tempCb.readByte();
InetAddress ipAddress = Validation.toInetAddress(nextHopLen, cb);
if (ipAddress.isMulticastAddress()) {
- throw new BGPParseException("Multicast not supported");
+ throw new BgpParseException("Multicast not supported");
}
ipNextHop = Ip4Address.valueOf(ipAddress);
byte reserved = tempCb.readByte();
@@ -142,19 +142,19 @@ public class MpReachNlri implements BGPValueType {
short nlriType = tempCb.readShort();
short totNlriLen = tempCb.readShort();
if (tempCb.readableBytes() < totNlriLen) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen);
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen);
}
tempBuf = tempCb.readBytes(totNlriLen);
switch (nlriType) {
- case BGPNodeLSNlriVer4.NODE_NLRITYPE:
- bgpLSNlri = BGPNodeLSNlriVer4.read(tempBuf, afi, safi);
+ case BgpNodeLSNlriVer4.NODE_NLRITYPE:
+ bgpLSNlri = BgpNodeLSNlriVer4.read(tempBuf, afi, safi);
break;
case BgpLinkLsNlriVer4.LINK_NLRITYPE:
bgpLSNlri = BgpLinkLsNlriVer4.read(tempBuf, afi, safi);
break;
- case BGPPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE:
- bgpLSNlri = BGPPrefixIPv4LSNlriVer4.read(tempBuf, afi, safi);
+ case BgpPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE:
+ bgpLSNlri = BgpPrefixIPv4LSNlriVer4.read(tempBuf, afi, safi);
break;
default:
log.debug("nlriType not supported" + nlriType);
@@ -162,7 +162,7 @@ public class MpReachNlri implements BGPValueType {
mpReachNlri.add(bgpLSNlri);
}
} else {
- throw new BGPParseException("Not Supporting afi " + afi + "safi " + safi);
+ throw new BgpParseException("Not Supporting afi " + afi + "safi " + safi);
}
}
return new MpReachNlri(mpReachNlri, afi, safi, ipNextHop, parseFlags.getLength());
@@ -216,4 +216,10 @@ public class MpReachNlri implements BGPValueType {
.add("length", length)
.toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java
index 8763ec59..f354b3ea 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java
@@ -20,10 +20,10 @@ import java.util.LinkedList;
import java.util.List;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.protocol.BGPLSNlri;
-import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4;
-import org.onosproject.bgpio.protocol.linkstate.BGPPrefixIPv4LSNlriVer4;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpLSNlri;
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4;
import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
@@ -35,7 +35,7 @@ import com.google.common.base.MoreObjects;
/**
* Provides Implementation of MpUnReach Nlri BGP Path Attribute.
*/
-public class MpUnReachNlri implements BGPValueType {
+public class MpUnReachNlri implements BgpValueType {
private static final Logger log = LoggerFactory.getLogger(MpUnReachNlri.class);
public static final byte MPUNREACHNLRI_TYPE = 15;
@@ -44,7 +44,7 @@ public class MpUnReachNlri implements BGPValueType {
private boolean isMpUnReachNlri = false;
private final short afi;
private final byte safi;
- private final List<BGPLSNlri> mpUnReachNlri;
+ private final List<BgpLSNlri> mpUnReachNlri;
private final int length;
/**
@@ -55,7 +55,7 @@ public class MpUnReachNlri implements BGPValueType {
* @param safi subsequent address family identifier
* @param length of MpUnReachNlri
*/
- public MpUnReachNlri(List<BGPLSNlri> mpUnReachNlri, short afi, byte safi,
+ public MpUnReachNlri(List<BgpLSNlri> mpUnReachNlri, short afi, byte safi,
int length) {
this.mpUnReachNlri = mpUnReachNlri;
this.isMpUnReachNlri = true;
@@ -69,9 +69,9 @@ public class MpUnReachNlri implements BGPValueType {
*
* @param cb ChannelBuffer
* @return object of MpUnReachNlri
- * @throws BGPParseException while parsing MpUnReachNlri
+ * @throws BgpParseException while parsing MpUnReachNlri
*/
- public static MpUnReachNlri read(ChannelBuffer cb) throws BGPParseException {
+ public static MpUnReachNlri read(ChannelBuffer cb) throws BgpParseException {
ChannelBuffer tempBuf = cb.copy();
Validation parseFlags = Validation.parseAttributeHeader(cb);
int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT
@@ -80,17 +80,17 @@ public class MpUnReachNlri implements BGPValueType {
if (!parseFlags.getFirstBit() && parseFlags.getSecondBit()
&& parseFlags.getThirdBit()) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
}
if (cb.readableBytes() < parseFlags.getLength()) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR, parseFlags.getLength());
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR, parseFlags.getLength());
}
- LinkedList<BGPLSNlri> mpUnReachNlri = new LinkedList<>();
- BGPLSNlri bgpLSNlri = null;
+ LinkedList<BgpLSNlri> mpUnReachNlri = new LinkedList<>();
+ BgpLSNlri bgpLSNlri = null;
short afi = 0;
byte safi = 0;
ChannelBuffer tempCb = cb.readBytes(parseFlags.getLength());
@@ -106,19 +106,19 @@ public class MpUnReachNlri implements BGPValueType {
short totNlriLen = tempCb.readShort();
if (tempCb.readableBytes() < totNlriLen) {
Validation.validateLen(
- BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen);
+ BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen);
}
tempBuf = tempCb.readBytes(totNlriLen);
switch (nlriType) {
- case BGPNodeLSNlriVer4.NODE_NLRITYPE:
- bgpLSNlri = BGPNodeLSNlriVer4.read(tempBuf, afi, safi);
+ case BgpNodeLSNlriVer4.NODE_NLRITYPE:
+ bgpLSNlri = BgpNodeLSNlriVer4.read(tempBuf, afi, safi);
break;
case BgpLinkLsNlriVer4.LINK_NLRITYPE:
bgpLSNlri = BgpLinkLsNlriVer4.read(tempBuf, afi, safi);
break;
- case BGPPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE:
- bgpLSNlri = BGPPrefixIPv4LSNlriVer4.read(tempBuf, afi,
+ case BgpPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE:
+ bgpLSNlri = BgpPrefixIPv4LSNlriVer4.read(tempBuf, afi,
safi);
break;
default:
@@ -128,7 +128,7 @@ public class MpUnReachNlri implements BGPValueType {
}
} else {
//TODO: check with the values got from capability
- throw new BGPParseException("Not Supporting afi " + afi
+ throw new BgpParseException("Not Supporting afi " + afi
+ "safi " + safi);
}
}
@@ -164,7 +164,7 @@ public class MpUnReachNlri implements BGPValueType {
*
* @return list of MpUnReach Nlri
*/
- public List<BGPLSNlri> mpUnReachNlri() {
+ public List<BgpLSNlri> mpUnReachNlri() {
return this.mpUnReachNlri;
}
@@ -193,6 +193,12 @@ public class MpUnReachNlri implements BGPValueType {
}
@Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("mpReachNlri", mpUnReachNlri)
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MultiProtocolExtnCapabilityTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MultiProtocolExtnCapabilityTlv.java
index 9beff68c..7082483e 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MultiProtocolExtnCapabilityTlv.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MultiProtocolExtnCapabilityTlv.java
@@ -25,7 +25,7 @@ import com.google.common.base.MoreObjects;
/**
* Provides MultiProtocolExtnCapabilityTlv.
*/
-public class MultiProtocolExtnCapabilityTlv implements BGPValueType {
+public class MultiProtocolExtnCapabilityTlv implements BgpValueType {
/*
0 7 15 23 31
@@ -141,7 +141,7 @@ public class MultiProtocolExtnCapabilityTlv implements BGPValueType {
* @param cb of type channel buffer
* @return object of MultiProtocolExtnCapabilityTlv
*/
- public static BGPValueType read(ChannelBuffer cb) {
+ public static BgpValueType read(ChannelBuffer cb) {
short afi = cb.readShort();
byte res = cb.readByte();
byte safi = cb.readByte();
@@ -157,4 +157,10 @@ public class MultiProtocolExtnCapabilityTlv implements BGPValueType {
.add("Reserved", res)
.add("SAFI", safi).toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java
index 1d083b72..806efe52 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java
@@ -20,7 +20,7 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip4Address;
-import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.exceptions.BgpParseException;
import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
@@ -30,7 +30,7 @@ import com.google.common.base.Preconditions;
/**
* Implementation of NextHop BGP Path Attribute.
*/
-public class NextHop implements BGPValueType {
+public class NextHop implements BgpValueType {
public static final byte NEXTHOP_TYPE = 3;
private boolean isNextHop = false;
@@ -60,27 +60,27 @@ public class NextHop implements BGPValueType {
*
* @param cb ChannelBuffer
* @return object of NextHop
- * @throws BGPParseException while parsing nexthop attribute
+ * @throws BgpParseException while parsing nexthop attribute
*/
- public static NextHop read(ChannelBuffer cb) throws BGPParseException {
+ public static NextHop read(ChannelBuffer cb) throws BgpParseException {
Ip4Address nextHop;
ChannelBuffer tempCb = cb.copy();
Validation parseFlags = Validation.parseAttributeHeader(cb);
if (cb.readableBytes() < parseFlags.getLength()) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
parseFlags.getLength());
}
int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (parseFlags.getFirstBit() && !parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
}
InetAddress ipAddress = Validation.toInetAddress(parseFlags.getLength(), cb);
if (ipAddress.isMulticastAddress()) {
- throw new BGPParseException("Multicast address is not supported");
+ throw new BgpParseException("Multicast address is not supported");
}
nextHop = Ip4Address.valueOf(ipAddress);
@@ -130,4 +130,10 @@ public class NextHop implements BGPValueType {
.add("nextHop", nextHop)
.toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFNonPseudonode.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFNonPseudonode.java
index 6d8282b7..d281a4ef 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFNonPseudonode.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFNonPseudonode.java
@@ -20,18 +20,13 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.protocol.IGPRouterID;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides implementation of OSPFNonPseudonode Tlv.
*/
-public class OSPFNonPseudonode implements IGPRouterID, BGPValueType {
-
- protected static final Logger log = LoggerFactory.getLogger(OSPFNonPseudonode.class);
-
+public class OSPFNonPseudonode implements IGPRouterID, BgpValueType {
public static final short TYPE = 515;
public static final short LENGTH = 4;
@@ -108,6 +103,14 @@ public class OSPFNonPseudonode implements IGPRouterID, BGPValueType {
}
@Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ return ((Integer) (this.routerID)).compareTo((Integer) (((OSPFNonPseudonode) o).routerID));
+ }
+
+ @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("Type", TYPE)
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFPseudonode.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFPseudonode.java
index 82a39bd1..0d17651a 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFPseudonode.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFPseudonode.java
@@ -20,18 +20,13 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip4Address;
import org.onosproject.bgpio.protocol.IGPRouterID;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
/**
* Provides implementation of OSPFPseudonode Tlv.
*/
-public class OSPFPseudonode implements IGPRouterID, BGPValueType {
-
- protected static final Logger log = LoggerFactory.getLogger(OSPFPseudonode.class);
-
+public class OSPFPseudonode implements IGPRouterID, BgpValueType {
public static final short TYPE = 515;
public static final short LENGTH = 8;
@@ -114,6 +109,18 @@ public class OSPFPseudonode implements IGPRouterID, BGPValueType {
}
@Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ int result = ((Integer) (this.routerID)).compareTo((Integer) (((OSPFPseudonode) o).routerID));
+ if (result != 0) {
+ return this.drInterface.compareTo(((OSPFPseudonode) o).drInterface);
+ }
+ return result;
+ }
+
+ @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("Type", TYPE)
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFRouteTypeTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFRouteTypeTlv.java
index 20fffbfa..be321c95 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFRouteTypeTlv.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFRouteTypeTlv.java
@@ -18,16 +18,14 @@ package org.onosproject.bgpio.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.onosproject.bgpio.exceptions.BgpParseException;
import com.google.common.base.MoreObjects;
/**
* Provides OSPF Route Type Tlv which contains route type.
*/
-public class OSPFRouteTypeTlv implements BGPValueType {
+public class OSPFRouteTypeTlv implements BgpValueType {
/* Reference :draft-ietf-idr-ls-distribution-11
0 1 2 3
@@ -41,8 +39,6 @@ public class OSPFRouteTypeTlv implements BGPValueType {
Figure : OSPF Route Type TLV Format
*/
- protected static final Logger log = LoggerFactory.getLogger(OSPFRouteTypeTlv.class);
-
public static final short TYPE = 264;
public static final short LENGTH = 1;
public static final int INTRA_AREA_TYPE = 1;
@@ -51,15 +47,16 @@ public class OSPFRouteTypeTlv implements BGPValueType {
public static final short EXTERNAL_TYPE_2 = 4;
public static final short NSSA_TYPE_1 = 5;
public static final short NSSA_TYPE_2 = 6;
+
private final byte routeType;
/**
* Enum for Route Type.
*/
- public enum ROUTETYPE {
+ public enum RouteType {
Intra_Area(1), Inter_Area(2), External_1(3), External_2(4), NSSA_1(5), NSSA_2(6);
int value;
- ROUTETYPE(int val) {
+ RouteType(int val) {
value = val;
}
public byte getType() {
@@ -90,24 +87,24 @@ public class OSPFRouteTypeTlv implements BGPValueType {
* Returns RouteType.
*
* @return RouteType
- * @throws BGPParseException if routeType is not matched
+ * @throws BgpParseException if routeType is not matched
*/
- public ROUTETYPE getValue() throws BGPParseException {
+ public RouteType getValue() throws BgpParseException {
switch (routeType) {
case INTRA_AREA_TYPE:
- return ROUTETYPE.Intra_Area;
+ return RouteType.Intra_Area;
case INTER_AREA_TYPE:
- return ROUTETYPE.Inter_Area;
+ return RouteType.Inter_Area;
case EXTERNAL_TYPE_1:
- return ROUTETYPE.External_1;
+ return RouteType.External_1;
case EXTERNAL_TYPE_2:
- return ROUTETYPE.External_2;
+ return RouteType.External_2;
case NSSA_TYPE_1:
- return ROUTETYPE.NSSA_1;
+ return RouteType.NSSA_1;
case NSSA_TYPE_2:
- return ROUTETYPE.NSSA_2;
+ return RouteType.NSSA_2;
default:
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
}
}
@@ -153,6 +150,14 @@ public class OSPFRouteTypeTlv implements BGPValueType {
}
@Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ return ((Byte) (this.routeType)).compareTo((Byte) (((OSPFRouteTypeTlv) o).routeType));
+ }
+
+ @Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("Type", TYPE)
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java
index 2052e965..d642d83c 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java
@@ -18,7 +18,7 @@ package org.onosproject.bgpio.types;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.exceptions.BgpParseException;
import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
@@ -27,7 +27,7 @@ import com.google.common.base.MoreObjects;
/**
* Provides Implementation of mandatory BGP Origin path attribute.
*/
-public class Origin implements BGPValueType {
+public class Origin implements BgpValueType {
/**
* Enum to provide ORIGIN types.
@@ -99,9 +99,9 @@ public class Origin implements BGPValueType {
*
* @param cb ChannelBuffer
* @return object of Origin
- * @throws BGPParseException while parsing Origin path attribute
+ * @throws BgpParseException while parsing Origin path attribute
*/
- public static Origin read(ChannelBuffer cb) throws BGPParseException {
+ public static Origin read(ChannelBuffer cb) throws BgpParseException {
ChannelBuffer tempCb = cb.copy();
Validation parseFlags = Validation.parseAttributeHeader(cb);
@@ -109,18 +109,18 @@ public class Origin implements BGPValueType {
.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if ((parseFlags.getLength() > ORIGIN_VALUE_LEN) || (cb.readableBytes() < parseFlags.getLength())) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
parseFlags.getLength());
}
if (parseFlags.getFirstBit() && !parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
}
byte originValue;
originValue = cb.readByte();
if ((originValue != ORIGINTYPE.INCOMPLETE.value) && (originValue != ORIGINTYPE.IGP.value) &&
(originValue != ORIGINTYPE.EGP.value)) {
- throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.INVALID_ORIGIN_ATTRIBUTE, data);
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.INVALID_ORIGIN_ATTRIBUTE, data);
}
return new Origin(originValue);
}
@@ -159,4 +159,10 @@ public class Origin implements BGPValueType {
.add("origin", origin)
.toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/RouteDistinguisher.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/RouteDistinguisher.java
index d0267092..37632ad8 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/RouteDistinguisher.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/RouteDistinguisher.java
@@ -18,10 +18,12 @@ package org.onosproject.bgpio.types;
import org.jboss.netty.buffer.ChannelBuffer;
+import com.google.common.base.MoreObjects;
+
/**
* Implementation of RouteDistinguisher.
*/
-public class RouteDistinguisher {
+public class RouteDistinguisher implements Comparable<RouteDistinguisher> {
private long routeDistinguisher;
@@ -59,4 +61,19 @@ public class RouteDistinguisher {
public long getRouteDistinguisher() {
return this.routeDistinguisher;
}
+
+ @Override
+ public int compareTo(RouteDistinguisher rd) {
+ if (this.equals(rd)) {
+ return 0;
+ }
+ return ((Long) (this.getRouteDistinguisher())).compareTo((Long) (rd.getRouteDistinguisher()));
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("routeDistinguisher", routeDistinguisher)
+ .toString();
+ }
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeFlagBitTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeFlagBitTlv.java
index e7f4a4c0..e0fef7c8 100755
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeFlagBitTlv.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeFlagBitTlv.java
@@ -18,9 +18,9 @@ package org.onosproject.bgpio.types.attr;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,7 +30,7 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP attribute node flag.
*/
-public final class BgpAttrNodeFlagBitTlv implements BGPValueType {
+public final class BgpAttrNodeFlagBitTlv implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpAttrNodeFlagBitTlv.class);
@@ -86,10 +86,10 @@ public final class BgpAttrNodeFlagBitTlv implements BGPValueType {
*
* @param cb ChannelBuffer
* @return attribute node flag bit tlv
- * @throws BGPParseException while parsing BgpAttrNodeFlagBitTlv
+ * @throws BgpParseException while parsing BgpAttrNodeFlagBitTlv
*/
public static BgpAttrNodeFlagBitTlv read(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
boolean bOverloadBit = false;
boolean bAttachedBit = false;
boolean bExternalBit = false;
@@ -98,8 +98,8 @@ public final class BgpAttrNodeFlagBitTlv implements BGPValueType {
short lsAttrLength = cb.readShort();
if ((lsAttrLength != 1) || (cb.readableBytes() < lsAttrLength)) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -190,4 +190,10 @@ public final class BgpAttrNodeFlagBitTlv implements BGPValueType {
.add("bExternalBit", bExternalBit).add("bAbrBit", bAbrBit)
.toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeIsIsAreaId.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeIsIsAreaId.java
new file mode 100644
index 00000000..0435a65f
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeIsIsAreaId.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types.attr;
+
+import java.util.Arrays;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP attribute ISIS Area Identifier.
+ */
+public class BgpAttrNodeIsIsAreaId implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpAttrNodeIsIsAreaId.class);
+
+ public static final int ATTRNODE_ISISAREAID = 1027;
+
+ /* IS-IS Area Identifier TLV */
+ private byte[] isisAreaId;
+
+ /**
+ * Constructor to initialize value.
+ *
+ * @param isisAreaId ISIS area Identifier
+ */
+ public BgpAttrNodeIsIsAreaId(byte[] isisAreaId) {
+ this.isisAreaId = Arrays.copyOf(isisAreaId, isisAreaId.length);
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param isisAreaId ISIS area Identifier
+ * @return object of BgpAttrNodeIsIsAreaId
+ */
+ public static BgpAttrNodeIsIsAreaId of(final byte[] isisAreaId) {
+ return new BgpAttrNodeIsIsAreaId(isisAreaId);
+ }
+
+ /**
+ * Reads the IS-IS Area Identifier.
+ *
+ * @param cb ChannelBuffer
+ * @return object of BgpAttrNodeIsIsAreaId
+ * @throws BgpParseException while parsing BgpAttrNodeIsIsAreaId
+ */
+ public static BgpAttrNodeIsIsAreaId read(ChannelBuffer cb)
+ throws BgpParseException {
+ byte[] isisAreaId;
+
+ short lsAttrLength = cb.readShort();
+
+ if (cb.readableBytes() < lsAttrLength) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ isisAreaId = new byte[lsAttrLength];
+ cb.readBytes(isisAreaId);
+
+ return BgpAttrNodeIsIsAreaId.of(isisAreaId);
+ }
+
+ /**
+ * Returns ISIS area Identifier.
+ *
+ * @return Area ID
+ */
+ public byte[] attrNodeIsIsAreaId() {
+ return isisAreaId;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRNODE_ISISAREAID;
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(isisAreaId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpAttrNodeIsIsAreaId) {
+ BgpAttrNodeIsIsAreaId other = (BgpAttrNodeIsIsAreaId) obj;
+ return Arrays.equals(isisAreaId, other.isisAreaId);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("isisAreaId", isisAreaId).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java
index 4b704fb0..31d855db 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java
@@ -17,12 +17,13 @@ package org.onosproject.bgpio.types.attr;
import java.util.ArrayList;
import java.util.List;
+import java.util.ListIterator;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,7 +33,7 @@ import com.google.common.base.MoreObjects;
/**
* BGP Multi-Topology ID of the LS attribute.
*/
-public class BgpAttrNodeMultiTopologyId implements BGPValueType {
+public class BgpAttrNodeMultiTopologyId implements BgpValueType {
private static final Logger log = LoggerFactory
.getLogger(BgpAttrNodeMultiTopologyId.class);
@@ -66,18 +67,18 @@ public class BgpAttrNodeMultiTopologyId implements BGPValueType {
*
* @param cb ChannelBuffer
* @return Constructor of BgpAttrNodeMultiTopologyId
- * @throws BGPParseException while parsing BgpAttrNodeMultiTopologyId
+ * @throws BgpParseException while parsing BgpAttrNodeMultiTopologyId
*/
public static BgpAttrNodeMultiTopologyId read(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
ArrayList<Short> multiTopologyId = new ArrayList<Short>();
short tempMultiTopologyId;
short lsAttrLength = cb.readShort();
int len = lsAttrLength / 2; // Length is 2*n and n is the number of MT-IDs
if (cb.readableBytes() < lsAttrLength) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -134,4 +135,30 @@ public class BgpAttrNodeMultiTopologyId implements BGPValueType {
.add("multiTopologyId", multiTopologyId)
.toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ int countOtherSubTlv = ((BgpAttrNodeMultiTopologyId) o).multiTopologyId.size();
+ int countObjSubTlv = multiTopologyId.size();
+ if (countOtherSubTlv != countObjSubTlv) {
+ if (countOtherSubTlv > countObjSubTlv) {
+ return 1;
+ } else {
+ return -1;
+ }
+ }
+ ListIterator<Short> listIterator = multiTopologyId.listIterator();
+ ListIterator<Short> listIteratorOther = ((BgpAttrNodeMultiTopologyId) o).multiTopologyId.listIterator();
+ while (listIterator.hasNext()) {
+ short id = listIterator.next();
+ short id1 = listIteratorOther.next();
+ if (((Short) id).compareTo((Short) id1) != 0) {
+ return ((Short) id).compareTo((Short) id1);
+ }
+ }
+ return 0;
+ }
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeName.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeName.java
new file mode 100644
index 00000000..2e1c7a05
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeName.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types.attr;
+
+import java.util.Arrays;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP attribute node name.
+ */
+public class BgpAttrNodeName implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpAttrNodeName.class);
+
+ public static final int ATTRNODE_NAME = 1026;
+
+ /* Node Name */
+ private byte[] nodeName;
+
+ /**
+ * Constructor to initialize value.
+ *
+ * @param nodeName node name
+ */
+ public BgpAttrNodeName(byte[] nodeName) {
+ this.nodeName = Arrays.copyOf(nodeName, nodeName.length);
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param nodeName node name
+ * @return object of BgpAttrNodeName
+ */
+ public static BgpAttrNodeName of(final byte[] nodeName) {
+ return new BgpAttrNodeName(nodeName);
+ }
+
+ /**
+ * Reads the LS attribute node name.
+ *
+ * @param cb ChannelBuffer
+ * @return object of BgpAttrNodeName
+ * @throws BgpParseException while parsing BgpAttrNodeName
+ */
+ public static BgpAttrNodeName read(ChannelBuffer cb)
+ throws BgpParseException {
+ byte[] nodeName;
+
+ short lsAttrLength = cb.readShort();
+
+ if (cb.readableBytes() < lsAttrLength) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ nodeName = new byte[lsAttrLength];
+ cb.readBytes(nodeName);
+ return BgpAttrNodeName.of(nodeName);
+ }
+
+ /**
+ * Returns LS attribute node name.
+ *
+ * @return node name
+ */
+ public byte[] attrNodeName() {
+ return nodeName;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRNODE_NAME;
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(nodeName);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpAttrNodeName) {
+ BgpAttrNodeName other = (BgpAttrNodeName) obj;
+ return Arrays.equals(nodeName, other.nodeName);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("nodeName", nodeName).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrOpaqueNode.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrOpaqueNode.java
new file mode 100644
index 00000000..545755a7
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrOpaqueNode.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types.attr;
+
+import java.util.Arrays;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP attribute opaque node.
+ */
+public class BgpAttrOpaqueNode implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpAttrOpaqueNode.class);
+
+ public static final int ATTRNODE_OPAQUEDATA = 1025;
+
+ /* Opaque Node Attribute */
+ private byte[] opaqueNodeAttribute;
+
+ /**
+ * Constructor to initialize parameter.
+ *
+ * @param opaqueNodeAttribute opaque node attribute
+ */
+ public BgpAttrOpaqueNode(byte[] opaqueNodeAttribute) {
+ this.opaqueNodeAttribute = Arrays.copyOf(opaqueNodeAttribute, opaqueNodeAttribute.length);
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param opaqueNodeAttribute Prefix Metric
+ * @return object of BgpAttrOpaqueNode
+ */
+ public static BgpAttrOpaqueNode of(byte[] opaqueNodeAttribute) {
+ return new BgpAttrOpaqueNode(opaqueNodeAttribute);
+ }
+
+ /**
+ * Reads the Opaque Node Properties.
+ *
+ * @param cb ChannelBuffer
+ * @return object of BgpAttrOpaqueNode
+ * @throws BgpParseException while parsing BgpAttrOpaqueNode
+ */
+ public static BgpAttrOpaqueNode read(ChannelBuffer cb)
+ throws BgpParseException {
+
+ byte[] opaqueNodeAttribute;
+
+ short lsAttrLength = cb.readShort();
+
+ if (cb.readableBytes() < lsAttrLength) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ opaqueNodeAttribute = new byte[lsAttrLength];
+ cb.readBytes(opaqueNodeAttribute);
+
+ return BgpAttrOpaqueNode.of(opaqueNodeAttribute);
+ }
+
+ /**
+ * Returns opaque node attribute.
+ *
+ * @return LS node attribute value
+ */
+ public byte[] attrOpaqueNode() {
+ return opaqueNodeAttribute;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRNODE_OPAQUEDATA;
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(opaqueNodeAttribute);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpAttrOpaqueNode) {
+ BgpAttrOpaqueNode other = (BgpAttrOpaqueNode) obj;
+ return Arrays
+ .equals(opaqueNodeAttribute, other.opaqueNodeAttribute);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("opaqueNodeAttribute", opaqueNodeAttribute).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV4.java
index a10d167a..f3c0d17b 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV4.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV4.java
@@ -19,9 +19,9 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip4Address;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,7 +31,7 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP attribute node router ID.
*/
-public final class BgpAttrRouterIdV4 implements BGPValueType {
+public final class BgpAttrRouterIdV4 implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpAttrRouterIdV4.class);
@@ -70,15 +70,15 @@ public final class BgpAttrRouterIdV4 implements BGPValueType {
* @param cb ChannelBuffer
* @param sType tag type
* @return object of BgpAttrRouterIdV4
- * @throws BGPParseException while parsing BgpAttrRouterIdV4
+ * @throws BgpParseException while parsing BgpAttrRouterIdV4
*/
public static BgpAttrRouterIdV4 read(ChannelBuffer cb, short sType)
- throws BGPParseException {
+ throws BgpParseException {
short lsAttrLength = cb.readShort();
if ((lsAttrLength != 4) || (cb.readableBytes() < lsAttrLength)) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -131,4 +131,10 @@ public final class BgpAttrRouterIdV4 implements BGPValueType {
return MoreObjects.toStringHelper(getClass()).omitNullValues()
.add("ip4RouterId", ip4RouterId).toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6.java
index ea63c379..648fd56e 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6.java
@@ -19,9 +19,9 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip6Address;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,7 +31,7 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP attribute IPv6 router ID.
*/
-public final class BgpAttrRouterIdV6 implements BGPValueType {
+public final class BgpAttrRouterIdV6 implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpAttrRouterIdV6.class);
@@ -70,18 +70,18 @@ public final class BgpAttrRouterIdV6 implements BGPValueType {
* @param cb ChannelBuffer
* @param sType TLV type
* @return object of BgpAttrRouterIdV6
- * @throws BGPParseException while parsing BgpAttrRouterIdV6
+ * @throws BgpParseException while parsing BgpAttrRouterIdV6
*/
public static BgpAttrRouterIdV6 read(ChannelBuffer cb, short sType)
- throws BGPParseException {
+ throws BgpParseException {
byte[] ipBytes;
Ip6Address ip6RouterId;
short lsAttrLength = cb.readShort();
if ((lsAttrLength != 16) || (cb.readableBytes() < lsAttrLength)) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -134,4 +134,10 @@ public final class BgpAttrRouterIdV6 implements BGPValueType {
return MoreObjects.toStringHelper(getClass()).omitNullValues()
.add("ip6RouterId", ip6RouterId).toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIgpMetric.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIgpMetric.java
index c1cb299c..5721cf6c 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIgpMetric.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIgpMetric.java
@@ -18,9 +18,9 @@ package org.onosproject.bgpio.types.attr;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,7 +30,7 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP link IGP metric attribute.
*/
-public class BgpLinkAttrIgpMetric implements BGPValueType {
+public class BgpLinkAttrIgpMetric implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpLinkAttrIgpMetric.class);
@@ -75,10 +75,10 @@ public class BgpLinkAttrIgpMetric implements BGPValueType {
*
* @param cb Channel buffer
* @return object of type BgpLinkAttrIgpMetric
- * @throws BGPParseException while parsing BgpLinkAttrIgpMetric
+ * @throws BgpParseException while parsing BgpLinkAttrIgpMetric
*/
public static BgpLinkAttrIgpMetric read(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
short linkigp;
int igpMetric = 0;
@@ -88,8 +88,8 @@ public class BgpLinkAttrIgpMetric implements BGPValueType {
if (cb.readableBytes() < lsAttrLength
|| lsAttrLength > ATTRLINK_MAX_LEN) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -169,4 +169,10 @@ public class BgpLinkAttrIgpMetric implements BGPValueType {
.add("igpMetric", igpMetric).add("igpMetricLen", igpMetricLen)
.toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java
index 086e8b06..448f1e58 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java
@@ -18,9 +18,9 @@ package org.onosproject.bgpio.types.attr;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,7 +30,7 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP attribute Is Is Administrative area.
*/
-public final class BgpLinkAttrIsIsAdminstGrp implements BGPValueType {
+public final class BgpLinkAttrIsIsAdminstGrp implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpLinkAttrIsIsAdminstGrp.class);
@@ -65,17 +65,17 @@ public final class BgpLinkAttrIsIsAdminstGrp implements BGPValueType {
*
* @param cb Channel buffer
* @return object of type BgpLinkAttrIsIsAdminstGrp
- * @throws BGPParseException while parsing BgpLinkAttrIsIsAdminstGrp
+ * @throws BgpParseException while parsing BgpLinkAttrIsIsAdminstGrp
*/
public static BgpLinkAttrIsIsAdminstGrp read(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
long isisAdminGrp;
short lsAttrLength = cb.readShort();
if ((lsAttrLength != ISIS_ADMIN_DATA_LEN)
|| (cb.readableBytes() < lsAttrLength)) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -127,4 +127,10 @@ public final class BgpLinkAttrIsIsAdminstGrp implements BGPValueType {
return MoreObjects.toStringHelper(getClass())
.add("isisAdminGrp", isisAdminGrp).toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java
index a1f0198b..2711ca94 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java
@@ -18,9 +18,9 @@ package org.onosproject.bgpio.types.attr;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,7 +30,7 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP attribute Max Link bandwidth.
*/
-public final class BgpLinkAttrMaxLinkBandwidth implements BGPValueType {
+public final class BgpLinkAttrMaxLinkBandwidth implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpLinkAttrMaxLinkBandwidth.class);
@@ -72,17 +72,17 @@ public final class BgpLinkAttrMaxLinkBandwidth implements BGPValueType {
* @param cb Channel buffer
* @param type type of this tlv
* @return object of type BgpLinkAttrMaxLinkBandwidth
- * @throws BGPParseException while parsing BgpLinkAttrMaxLinkBandwidth
+ * @throws BgpParseException while parsing BgpLinkAttrMaxLinkBandwidth
*/
public static BgpLinkAttrMaxLinkBandwidth read(ChannelBuffer cb, short type)
- throws BGPParseException {
+ throws BgpParseException {
float maxBandwidth;
short lsAttrLength = cb.readShort();
if ((lsAttrLength != MAX_BANDWIDTH_LEN)
|| (cb.readableBytes() < lsAttrLength)) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -147,4 +147,10 @@ public final class BgpLinkAttrMaxLinkBandwidth implements BGPValueType {
return MoreObjects.toStringHelper(getClass())
.add("maxBandwidth", maxBandwidth).toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMplsProtocolMask.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMplsProtocolMask.java
index 61143fae..2bf1a59d 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMplsProtocolMask.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMplsProtocolMask.java
@@ -18,9 +18,9 @@ package org.onosproject.bgpio.types.attr;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,7 +30,7 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP MPLS protocol mask attribute.
*/
-public class BgpLinkAttrMplsProtocolMask implements BGPValueType {
+public class BgpLinkAttrMplsProtocolMask implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpLinkAttrMplsProtocolMask.class);
@@ -72,10 +72,10 @@ public class BgpLinkAttrMplsProtocolMask implements BGPValueType {
*
* @param cb Channel buffer
* @return object of type BgpLinkAttrMPLSProtocolMask
- * @throws BGPParseException while parsing BgpLinkAttrMplsProtocolMask
+ * @throws BgpParseException while parsing BgpLinkAttrMplsProtocolMask
*/
public static BgpLinkAttrMplsProtocolMask read(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
boolean bLdp = false;
boolean bRsvpTe = false;
@@ -83,8 +83,8 @@ public class BgpLinkAttrMplsProtocolMask implements BGPValueType {
if ((lsAttrLength != MASK_BYTE_LEN)
|| (cb.readableBytes() < lsAttrLength)) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -149,4 +149,10 @@ public class BgpLinkAttrMplsProtocolMask implements BGPValueType {
return MoreObjects.toStringHelper(getClass())
.add("bLdp", bLdp).add("bRsvpTe", bRsvpTe).toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java
index e44ba7e1..856ffc36 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java
@@ -18,9 +18,9 @@ package org.onosproject.bgpio.types.attr;
import java.util.Arrays;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,7 +30,7 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP link name attribute.
*/
-public class BgpLinkAttrName implements BGPValueType {
+public class BgpLinkAttrName implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpLinkAttrName.class);
@@ -64,16 +64,16 @@ public class BgpLinkAttrName implements BGPValueType {
*
* @param cb Channel buffer
* @return object of type BgpLinkAttrName
- * @throws BGPParseException while parsing BgpLinkAttrName
+ * @throws BgpParseException while parsing BgpLinkAttrName
*/
public static BgpLinkAttrName read(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
byte[] linkName;
short lsAttrLength = cb.readShort();
if (cb.readableBytes() < lsAttrLength) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -125,4 +125,10 @@ public class BgpLinkAttrName implements BGPValueType {
return MoreObjects.toStringHelper(getClass()).omitNullValues()
.add("linkName", linkName).toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java
index 258598be..275b85be 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java
@@ -18,9 +18,9 @@ package org.onosproject.bgpio.types.attr;
import java.util.Arrays;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,7 +30,7 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP link opaque attribute.
*/
-public final class BgpLinkAttrOpaqLnkAttrib implements BGPValueType {
+public final class BgpLinkAttrOpaqLnkAttrib implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpLinkAttrOpaqLnkAttrib.class);
@@ -65,18 +65,18 @@ public final class BgpLinkAttrOpaqLnkAttrib implements BGPValueType {
*
* @param cb Channel buffer
* @return object of type BgpLinkAttrOpaqLnkAttrib
- * @throws BGPParseException while parsing BgpLinkAttrOpaqLnkAttrib
+ * @throws BgpParseException while parsing BgpLinkAttrOpaqLnkAttrib
*/
public static BgpLinkAttrOpaqLnkAttrib read(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
byte[] opaqueLinkAttribute;
short lsAttrLength = cb.readShort();
if (cb.readableBytes() < lsAttrLength) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -130,4 +130,10 @@ public final class BgpLinkAttrOpaqLnkAttrib implements BGPValueType {
return MoreObjects.toStringHelper(getClass()).omitNullValues()
.add("opaqueLinkAttribute", opaqueLinkAttribute).toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrProtectionType.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrProtectionType.java
index b45d95b8..59011d97 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrProtectionType.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrProtectionType.java
@@ -18,9 +18,9 @@ package org.onosproject.bgpio.types.attr;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,7 +30,7 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP link protection type attribute.
*/
-public final class BgpLinkAttrProtectionType implements BGPValueType {
+public final class BgpLinkAttrProtectionType implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpLinkAttrProtectionType.class);
@@ -102,10 +102,10 @@ public final class BgpLinkAttrProtectionType implements BGPValueType {
*
* @param cb Channel buffer
* @return object of type BgpLinkAttrProtectionType
- * @throws BGPParseException while parsing BgpLinkAttrProtectionType
+ * @throws BgpParseException while parsing BgpLinkAttrProtectionType
*/
public static BgpLinkAttrProtectionType read(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
short linkProtectionType;
byte higherByte;
short lsAttrLength = cb.readShort();
@@ -119,8 +119,8 @@ public final class BgpLinkAttrProtectionType implements BGPValueType {
if ((lsAttrLength != LINK_PROTECTION_LEN)
|| (cb.readableBytes() < lsAttrLength)) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -237,4 +237,10 @@ public final class BgpLinkAttrProtectionType implements BGPValueType {
.add("bDedOnePlusOne", bDedOnePlusOne)
.add("bEnhanced", bEnhanced).toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrSrlg.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrSrlg.java
new file mode 100644
index 00000000..4a6f23f9
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrSrlg.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types.attr;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP link Shared Risk Link Group attribute.
+ */
+public class BgpLinkAttrSrlg implements BgpValueType {
+
+ public static final short ATTRNODE_SRLG = 1097;
+
+ /* Shared Risk Link Group */
+ private List<Integer> sRlg = new ArrayList<Integer>();
+
+ /**
+ * Constructor to initialize the date.
+ *
+ * @param sRlg Shared Risk link group data
+ */
+ public BgpLinkAttrSrlg(List<Integer> sRlg) {
+ this.sRlg = sRlg;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param sRlg Shared Risk link group data
+ * @return object of BgpLinkAttrSrlg
+ */
+ public static BgpLinkAttrSrlg of(ArrayList<Integer> sRlg) {
+ return new BgpLinkAttrSrlg(sRlg);
+ }
+
+ /**
+ * Reads the BGP link attributes Shared Risk link group data.
+ *
+ * @param cb Channel buffer
+ * @return object of type BgpLinkAttrSrlg
+ * @throws BgpParseException while parsing BgpLinkAttrSrlg
+ */
+ public static BgpLinkAttrSrlg read(ChannelBuffer cb)
+ throws BgpParseException {
+ int tempSrlg;
+ ArrayList<Integer> sRlg = new ArrayList<Integer>();
+
+ short lsAttrLength = cb.readShort();
+ int len = lsAttrLength / Integer.SIZE; // each element is of 4 octets
+
+ if (cb.readableBytes() < lsAttrLength) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ for (int i = 0; i < len; i++) {
+ tempSrlg = cb.readInt();
+ sRlg.add(new Integer(tempSrlg));
+ }
+
+ return BgpLinkAttrSrlg.of(sRlg);
+ }
+
+ /**
+ * Returns the Shared Risk link group data.
+ *
+ * @return array of Shared Risk link group data
+ */
+ public List<Integer> attrSrlg() {
+ return sRlg;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRNODE_SRLG;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(sRlg);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpLinkAttrSrlg) {
+ BgpLinkAttrSrlg other = (BgpLinkAttrSrlg) obj;
+ return Objects.equals(sRlg, other.sRlg);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues().add("sRlg", sRlg).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java
index 7febe3c3..1ae7ecc5 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java
@@ -18,9 +18,9 @@ package org.onosproject.bgpio.types.attr;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,7 +30,7 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP link state Default TE metric link attribute.
*/
-public class BgpLinkAttrTeDefaultMetric implements BGPValueType {
+public class BgpLinkAttrTeDefaultMetric implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpLinkAttrTeDefaultMetric.class);
@@ -66,18 +66,18 @@ public class BgpLinkAttrTeDefaultMetric implements BGPValueType {
*
* @param cb Channel buffer
* @return object of type BgpLinkAttrTeDefaultMetric
- * @throws BGPParseException while parsing BgpLinkAttrTeDefaultMetric
+ * @throws BgpParseException while parsing BgpLinkAttrTeDefaultMetric
*/
public static BgpLinkAttrTeDefaultMetric read(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
int linkTeMetric;
short lsAttrLength = cb.readShort();
if ((lsAttrLength != TE_DATA_LEN)
|| (cb.readableBytes() < lsAttrLength)) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -129,4 +129,10 @@ public class BgpLinkAttrTeDefaultMetric implements BGPValueType {
return MoreObjects.toStringHelper(getClass())
.add("linkTEMetric", linkTeMetric).toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrUnRsrvdLinkBandwidth.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrUnRsrvdLinkBandwidth.java
new file mode 100644
index 00000000..c927eea5
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrUnRsrvdLinkBandwidth.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types.attr;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP unreserved bandwidth attribute.
+ */
+public class BgpLinkAttrUnRsrvdLinkBandwidth implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpLinkAttrUnRsrvdLinkBandwidth.class);
+
+ public static final int MAX_BANDWIDTH_LEN = 4;
+ public static final int NO_OF_BITS = 8;
+ public static final int NO_OF_PRIORITY = 8;
+
+ public short sType;
+
+ /* ISIS administrative group */
+ private List<Float> maxUnResBandwidth = new ArrayList<Float>();
+
+ /**
+ * Constructor to initialize the values.
+ *
+ * @param maxUnResBandwidth Maximum Unreserved bandwidth
+ * @param sType returns the tag value
+ */
+ public BgpLinkAttrUnRsrvdLinkBandwidth(List<Float> maxUnResBandwidth,
+ short sType) {
+ this.maxUnResBandwidth = maxUnResBandwidth;
+ this.sType = sType;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param linkPfxMetric Prefix Metric
+ * @param sType returns the tag value
+ * @return object of BgpLinkAttrUnRsrvdLinkBandwidth
+ */
+ public static BgpLinkAttrUnRsrvdLinkBandwidth of(List<Float> linkPfxMetric, short sType) {
+ return new BgpLinkAttrUnRsrvdLinkBandwidth(linkPfxMetric, sType);
+ }
+
+ /**
+ * Reads the BGP link attributes of Maximum link bandwidth.
+ *
+ * @param cb Channel buffer
+ * @return object of type BgpLinkAttrMaxLinkBandwidth
+ * @throws BgpParseException while parsing BgpLinkAttrMaxLinkBandwidth
+ */
+ public static BgpLinkAttrUnRsrvdLinkBandwidth read(ChannelBuffer cb,
+ short sType)
+ throws BgpParseException {
+ ArrayList<Float> maxUnResBandwidth = new ArrayList<Float>();
+ float tmp;
+ short lsAttrLength = cb.readShort();
+
+ if ((lsAttrLength != MAX_BANDWIDTH_LEN * NO_OF_PRIORITY)
+ || (cb.readableBytes() < lsAttrLength)) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ for (int i = 0; i < NO_OF_PRIORITY; i++) {
+ tmp = ieeeToFloatRead(cb.readInt()) * NO_OF_BITS;
+ maxUnResBandwidth.add(new Float(tmp));
+ }
+
+ return BgpLinkAttrUnRsrvdLinkBandwidth.of(maxUnResBandwidth, sType);
+ }
+
+ /**
+ * Returns maximum unreserved bandwidth.
+ *
+ * @return unreserved bandwidth.
+ */
+ public List<Float> getLinkAttrUnRsrvdLinkBandwidth() {
+ return maxUnResBandwidth;
+ }
+
+ /**
+ * Parse the IEEE floating point notation and returns it in normal float.
+ *
+ * @param iVal IEEE floating point number
+ * @return normal float
+ */
+ static float ieeeToFloatRead(int iVal) {
+ iVal = (((iVal & 0xFF) << 24) | ((iVal & 0xFF00) << 8)
+ | ((iVal & 0xFF0000) >> 8) | ((iVal >> 24) & 0xFF));
+
+ return Float.intBitsToFloat(iVal);
+ }
+
+ @Override
+ public short getType() {
+ return this.sType;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(maxUnResBandwidth);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpLinkAttrUnRsrvdLinkBandwidth) {
+ BgpLinkAttrUnRsrvdLinkBandwidth other = (BgpLinkAttrUnRsrvdLinkBandwidth) obj;
+ return Objects.equals(maxUnResBandwidth, other.maxUnResBandwidth);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("maxUnResBandwidth", maxUnResBandwidth).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrExtRouteTag.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrExtRouteTag.java
new file mode 100644
index 00000000..a2d7c57e
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrExtRouteTag.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types.attr;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP prefix route Extended tag attribute.
+ */
+public class BgpPrefixAttrExtRouteTag implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpPrefixAttrExtRouteTag.class);
+
+ public static final int ATTR_PREFIX_EXTROUTETAG = 1154;
+ public static final int ATTR_PREFIX_EXT_LEN = 8;
+
+ /* Prefix Route Tag */
+ private List<Long> pfxExtRouteTag = new ArrayList<Long>();
+
+ /**
+ * Constructor to initialize the values.
+ *
+ * @param pfxExtRouteTag Extended route tag
+ */
+ public BgpPrefixAttrExtRouteTag(List<Long> pfxExtRouteTag) {
+ this.pfxExtRouteTag = checkNotNull(pfxExtRouteTag);
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param pfxExtRouteTag Prefix Metric
+ * @return object of BgpPrefixAttrMetric
+ */
+ public static BgpPrefixAttrExtRouteTag of(ArrayList<Long> pfxExtRouteTag) {
+ return new BgpPrefixAttrExtRouteTag(pfxExtRouteTag);
+ }
+
+ /**
+ * Reads the Extended Tag.
+ *
+ * @param cb ChannelBuffer
+ * @return object of BgpPrefixAttrExtRouteTag
+ * @throws BgpParseException while parsing BgpPrefixAttrExtRouteTag
+ */
+ public static BgpPrefixAttrExtRouteTag read(ChannelBuffer cb)
+ throws BgpParseException {
+ ArrayList<Long> pfxExtRouteTag = new ArrayList<Long>();
+ long temp;
+
+ short lsAttrLength = cb.readShort();
+ int len = lsAttrLength / ATTR_PREFIX_EXT_LEN;
+
+ if (cb.readableBytes() < lsAttrLength) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ for (int i = 0; i < len; i++) {
+ temp = cb.readLong();
+ pfxExtRouteTag.add(new Long(temp));
+ }
+
+ return new BgpPrefixAttrExtRouteTag(pfxExtRouteTag);
+ }
+
+ /**
+ * Returns Extended route tag.
+ *
+ * @return route tag
+ */
+ public List<Long> pfxExtRouteTag() {
+ return pfxExtRouteTag;
+ }
+
+ @Override
+ public short getType() {
+ return ATTR_PREFIX_EXTROUTETAG;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(pfxExtRouteTag);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpPrefixAttrExtRouteTag) {
+ BgpPrefixAttrExtRouteTag other = (BgpPrefixAttrExtRouteTag) obj;
+ return Objects.equals(pfxExtRouteTag, other.pfxExtRouteTag);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("pfxExtRouteTag", pfxExtRouteTag).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlags.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlags.java
index a215e6f1..4e84191a 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlags.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlags.java
@@ -18,9 +18,9 @@ package org.onosproject.bgpio.types.attr;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,7 +30,7 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP prefix IGP Flag attribute.
*/
-public final class BgpPrefixAttrIgpFlags implements BGPValueType {
+public final class BgpPrefixAttrIgpFlags implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpPrefixAttrIgpFlags.class);
@@ -88,10 +88,10 @@ public final class BgpPrefixAttrIgpFlags implements BGPValueType {
*
* @param cb ChannelBuffer
* @return object of BgpPrefixAttrIGPFlags
- * @throws BGPParseException while parsing BgpPrefixAttrIGPFlags
+ * @throws BgpParseException while parsing BgpPrefixAttrIGPFlags
*/
public static BgpPrefixAttrIgpFlags read(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
boolean bisisUpDownBit = false;
boolean bOspfNoUnicastBit = false;
boolean bOspfLclAddrBit = false;
@@ -101,8 +101,8 @@ public final class BgpPrefixAttrIgpFlags implements BGPValueType {
if ((lsAttrLength != ATTR_PREFIX_FLAG_LEN)
|| (cb.readableBytes() < lsAttrLength)) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -195,4 +195,10 @@ public final class BgpPrefixAttrIgpFlags implements BGPValueType {
.add("bOspfLclAddrBit", bOspfLclAddrBit)
.add("bOspfNSSABit", bOspfNSSABit).toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrMetric.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrMetric.java
index 0678b81f..1886102c 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrMetric.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrMetric.java
@@ -18,9 +18,9 @@ package org.onosproject.bgpio.types.attr;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,7 +30,7 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP prefix metric attribute.
*/
-public class BgpPrefixAttrMetric implements BGPValueType {
+public class BgpPrefixAttrMetric implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpPrefixAttrMetric.class);
@@ -65,18 +65,18 @@ public class BgpPrefixAttrMetric implements BGPValueType {
*
* @param cb ChannelBuffer
* @return object of BgpPrefixAttrMetric
- * @throws BGPParseException while parsing BgpPrefixAttrMetric
+ * @throws BgpParseException while parsing BgpPrefixAttrMetric
*/
public static BgpPrefixAttrMetric read(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
int linkPfxMetric;
short lsAttrLength = cb.readShort(); // 4 Bytes
if ((lsAttrLength != ATTR_PREFIX_LEN)
|| (cb.readableBytes() < lsAttrLength)) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -128,4 +128,10 @@ public class BgpPrefixAttrMetric implements BGPValueType {
return MoreObjects.toStringHelper(getClass())
.add("linkPfxMetric", linkPfxMetric).toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java
index c7008ca1..6f7a74bb 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java
@@ -18,9 +18,9 @@ package org.onosproject.bgpio.types.attr;
import java.util.Arrays;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,7 +30,7 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP prefix opaque data attribute.
*/
-public final class BgpPrefixAttrOpaqueData implements BGPValueType {
+public final class BgpPrefixAttrOpaqueData implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpPrefixAttrOpaqueData.class);
@@ -65,18 +65,18 @@ public final class BgpPrefixAttrOpaqueData implements BGPValueType {
*
* @param cb ChannelBuffer
* @return object of BgpPrefixAttrOpaqueData
- * @throws BGPParseException while parsing BgpPrefixAttrOpaqueData
+ * @throws BgpParseException while parsing BgpPrefixAttrOpaqueData
*/
public static BgpPrefixAttrOpaqueData read(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
byte[] opaquePrefixAttribute;
short lsAttrLength = cb.readShort();
opaquePrefixAttribute = new byte[lsAttrLength];
if (cb.readableBytes() < lsAttrLength) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -131,4 +131,9 @@ public final class BgpPrefixAttrOpaqueData implements BGPValueType {
.toString();
}
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOspfFwdAddr.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOspfFwdAddr.java
index cf043046..4e9db1ee 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOspfFwdAddr.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOspfFwdAddr.java
@@ -20,9 +20,9 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip6Address;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,7 +32,7 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP prefix OSPF Forwarding address attribute.
*/
-public class BgpPrefixAttrOspfFwdAddr implements BGPValueType {
+public class BgpPrefixAttrOspfFwdAddr implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpPrefixAttrOspfFwdAddr.class);
@@ -80,10 +80,10 @@ public class BgpPrefixAttrOspfFwdAddr implements BGPValueType {
*
* @param cb ChannelBuffer
* @return object of BgpPrefixAttrOSPFFwdAddr
- * @throws BGPParseException while parsing BgpPrefixAttrOspfFwdAddr
+ * @throws BgpParseException while parsing BgpPrefixAttrOspfFwdAddr
*/
public static BgpPrefixAttrOspfFwdAddr read(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
short lsAttrLength;
byte[] ipBytes;
Ip4Address ip4RouterId = null;
@@ -93,8 +93,8 @@ public class BgpPrefixAttrOspfFwdAddr implements BGPValueType {
ipBytes = new byte[lsAttrLength];
if ((cb.readableBytes() < lsAttrLength)) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -184,4 +184,10 @@ public class BgpPrefixAttrOspfFwdAddr implements BGPValueType {
.add("ip6RouterId", ip6RouterId).toString();
}
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java
index 426eb274..3894c003 100755..100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java
@@ -20,9 +20,9 @@ import java.util.List;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,7 +32,7 @@ import com.google.common.base.MoreObjects;
/**
* Implements BGP prefix route tag attribute.
*/
-public class BgpPrefixAttrRouteTag implements BGPValueType {
+public class BgpPrefixAttrRouteTag implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpPrefixAttrRouteTag.class);
@@ -66,10 +66,10 @@ public class BgpPrefixAttrRouteTag implements BGPValueType {
*
* @param cb ChannelBuffer
* @return object of BgpPrefixAttrRouteTag
- * @throws BGPParseException while parsing BgpPrefixAttrRouteTag
+ * @throws BgpParseException while parsing BgpPrefixAttrRouteTag
*/
public static BgpPrefixAttrRouteTag read(ChannelBuffer cb)
- throws BGPParseException {
+ throws BgpParseException {
int tmp;
ArrayList<Integer> pfxRouteTag = new ArrayList<Integer>();
@@ -77,8 +77,8 @@ public class BgpPrefixAttrRouteTag implements BGPValueType {
int len = lsAttrLength / Integer.SIZE;
if (cb.readableBytes() < lsAttrLength) {
- Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
- BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
@@ -133,4 +133,10 @@ public class BgpPrefixAttrRouteTag implements BGPValueType {
return MoreObjects.toStringHelper(getClass()).omitNullValues()
.add("pfxRouteTag", pfxRouteTag).toString();
}
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/util/Validation.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/util/Validation.java
index bc131893..23dd1a75 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/util/Validation.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/util/Validation.java
@@ -24,7 +24,7 @@ import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
-import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.exceptions.BgpParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -109,13 +109,13 @@ public class Validation {
* @param errorCode Error code
* @param subErrCode Sub Error Code
* @param length erroneous length
- * @throws BGPParseException for erroneous length
+ * @throws BgpParseException for erroneous length
*/
- public static void validateLen(byte errorCode, byte subErrCode, int length) throws BGPParseException {
+ public static void validateLen(byte errorCode, byte subErrCode, int length) throws BgpParseException {
byte[] errLen = Ints.toByteArray(length);
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errLen);
- throw new BGPParseException(errorCode, subErrCode, buffer);
+ throw new BgpParseException(errorCode, subErrCode, buffer);
}
/**
@@ -124,13 +124,13 @@ public class Validation {
* @param errorCode Error code
* @param subErrCode Sub Error Code
* @param type erroneous type
- * @throws BGPParseException for erroneous type
+ * @throws BgpParseException for erroneous type
*/
- public static void validateType(byte errorCode, byte subErrCode, int type) throws BGPParseException {
+ public static void validateType(byte errorCode, byte subErrCode, int type) throws BgpParseException {
byte[] errType = Ints.toByteArray(type);
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errType);
- throw new BGPParseException(errorCode, subErrCode, buffer);
+ throw new BgpParseException(errorCode, subErrCode, buffer);
}
/**
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BGPKeepaliveMsgTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpKeepaliveMsgTest.java
index 68ce3070..682c1bc0 100755
--- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BGPKeepaliveMsgTest.java
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpKeepaliveMsgTest.java
@@ -18,8 +18,8 @@ package org.onosproject.bgpio.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.Test;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPHeader;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
@@ -28,13 +28,13 @@ import static org.hamcrest.core.Is.is;
/**
* Test case for BGP KEEPALIVE Message.
*/
-public class BGPKeepaliveMsgTest {
+public class BgpKeepaliveMsgTest {
/**
* This test case checks BGP Keepalive message.
*/
@Test
- public void keepaliveMessageTest1() throws BGPParseException {
+ public void keepaliveMessageTest1() throws BgpParseException {
// BGP KEEPALIVE Message
byte[] keepaliveMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
@@ -47,13 +47,13 @@ public class BGPKeepaliveMsgTest {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(keepaliveMsg);
- BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader();
- BGPMessage message;
- BGPHeader bgpHeader = new BGPHeader();
+ BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
+ BgpMessage message;
+ BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
- assertThat(message, instanceOf(BGPKeepaliveMsg.class));
+ assertThat(message, instanceOf(BgpKeepaliveMsg.class));
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpNotificationMsgTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpNotificationMsgTest.java
index 78edf133..6dfa57ee 100644
--- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpNotificationMsgTest.java
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpNotificationMsgTest.java
@@ -18,8 +18,8 @@ package org.onosproject.bgpio.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.Test;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPHeader;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
@@ -33,10 +33,10 @@ public class BgpNotificationMsgTest {
/**
* Notification message with error code, error subcode and data.
*
- * @throws BGPParseException while decoding and encoding notification message
+ * @throws BgpParseException while decoding and encoding notification message
*/
@Test
- public void bgpNotificationMessageTest1() throws BGPParseException {
+ public void bgpNotificationMessageTest1() throws BgpParseException {
byte[] notificationMsg = new byte[] {(byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff,
@@ -52,12 +52,12 @@ public class BgpNotificationMsgTest {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(notificationMsg);
- BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader();
- BGPMessage message = null;
- BGPHeader bgpHeader = new BGPHeader();
+ BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
+ BgpMessage message = null;
+ BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
- assertThat(message, instanceOf(BGPNotificationMsg.class));
+ assertThat(message, instanceOf(BgpNotificationMsg.class));
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
@@ -72,10 +72,10 @@ public class BgpNotificationMsgTest {
/**
* Notification message without data.
*
- * @throws BGPParseException while decoding and encoding notification message
+ * @throws BgpParseException while decoding and encoding notification message
*/
@Test
- public void bgpNotificationMessageTest2() throws BGPParseException {
+ public void bgpNotificationMessageTest2() throws BgpParseException {
byte[] notificationMsg = new byte[] {(byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff,
@@ -90,12 +90,12 @@ public class BgpNotificationMsgTest {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(notificationMsg);
- BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader();
- BGPMessage message = null;
- BGPHeader bgpHeader = new BGPHeader();
+ BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
+ BgpMessage message = null;
+ BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
- assertThat(message, instanceOf(BGPNotificationMsg.class));
+ assertThat(message, instanceOf(BgpNotificationMsg.class));
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
@@ -111,10 +111,10 @@ public class BgpNotificationMsgTest {
/**
* Notification message with wrong maker value.
*
- * @throws BGPParseException while decoding and encoding notification message
+ * @throws BgpParseException while decoding and encoding notification message
*/
- @Test(expected = BGPParseException.class)
- public void bgpNotificationMessageTest3() throws BGPParseException {
+ @Test(expected = BgpParseException.class)
+ public void bgpNotificationMessageTest3() throws BgpParseException {
byte[] notificationMsg = new byte[] {(byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff,
@@ -129,12 +129,12 @@ public class BgpNotificationMsgTest {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(notificationMsg);
- BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader();
- BGPMessage message = null;
- BGPHeader bgpHeader = new BGPHeader();
+ BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
+ BgpMessage message = null;
+ BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
- assertThat(message, instanceOf(BGPNotificationMsg.class));
+ assertThat(message, instanceOf(BgpNotificationMsg.class));
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
@@ -149,10 +149,10 @@ public class BgpNotificationMsgTest {
/**
* Notification message without error subcode.
*
- * @throws BGPParseException while decoding and encoding notification message
+ * @throws BgpParseException while decoding and encoding notification message
*/
- @Test(expected = BGPParseException.class)
- public void bgpNotificationMessageTest4() throws BGPParseException {
+ @Test(expected = BgpParseException.class)
+ public void bgpNotificationMessageTest4() throws BgpParseException {
byte[] notificationMsg = new byte[] {(byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff,
@@ -167,12 +167,12 @@ public class BgpNotificationMsgTest {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(notificationMsg);
- BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader();
- BGPMessage message = null;
- BGPHeader bgpHeader = new BGPHeader();
+ BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
+ BgpMessage message = null;
+ BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
- assertThat(message, instanceOf(BGPNotificationMsg.class));
+ assertThat(message, instanceOf(BgpNotificationMsg.class));
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
@@ -187,10 +187,10 @@ public class BgpNotificationMsgTest {
/**
* Notification message with wrong message length.
*
- * @throws BGPParseException while decoding and encoding notification message
+ * @throws BgpParseException while decoding and encoding notification message
*/
- @Test(expected = BGPParseException.class)
- public void bgpNotificationMessageTest5() throws BGPParseException {
+ @Test(expected = BgpParseException.class)
+ public void bgpNotificationMessageTest5() throws BgpParseException {
byte[] notificationMsg = new byte[] {(byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff,
@@ -205,12 +205,12 @@ public class BgpNotificationMsgTest {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(notificationMsg);
- BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader();
- BGPMessage message = null;
- BGPHeader bgpHeader = new BGPHeader();
+ BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
+ BgpMessage message = null;
+ BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
- assertThat(message, instanceOf(BGPNotificationMsg.class));
+ assertThat(message, instanceOf(BgpNotificationMsg.class));
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BGPOpenMsgTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpOpenMsgTest.java
index d5210177..1fe4036f 100755
--- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BGPOpenMsgTest.java
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpOpenMsgTest.java
@@ -18,8 +18,8 @@ package org.onosproject.bgpio.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.Test;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.types.BGPHeader;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpHeader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
@@ -28,13 +28,13 @@ import static org.hamcrest.core.Is.is;
/**
* Test cases for BGP Open Message.
*/
-public class BGPOpenMsgTest {
+public class BgpOpenMsgTest {
/**
* This test case checks open message without optional parameter.
*/
@Test
- public void openMessageTest1() throws BGPParseException {
+ public void openMessageTest1() throws BgpParseException {
//Open message without optional parameter
byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
@@ -48,12 +48,12 @@ public class BGPOpenMsgTest {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
- BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader();
- BGPMessage message;
- BGPHeader bgpHeader = new BGPHeader();
+ BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
+ BgpMessage message;
+ BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
- assertThat(message, instanceOf(BGPOpenMsg.class));
+ assertThat(message, instanceOf(BgpOpenMsg.class));
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
@@ -69,7 +69,7 @@ public class BGPOpenMsgTest {
* capability.
*/
@Test
- public void openMessageTest2() throws BGPParseException {
+ public void openMessageTest2() throws BgpParseException {
// OPEN Message (MultiProtocolExtension-CAPABILITY).
byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff,
@@ -91,13 +91,13 @@ public class BGPOpenMsgTest {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
- BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader();
- BGPMessage message;
- BGPHeader bgpHeader = new BGPHeader();
+ BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
+ BgpMessage message;
+ BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
- assertThat(message, instanceOf(BGPOpenMsg.class));
+ assertThat(message, instanceOf(BgpOpenMsg.class));
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
@@ -113,7 +113,7 @@ public class BGPOpenMsgTest {
* capability.
*/
@Test
- public void openMessageTest3() throws BGPParseException {
+ public void openMessageTest3() throws BgpParseException {
// OPEN Message (Four-Octet AS number capability).
byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff,
@@ -135,13 +135,13 @@ public class BGPOpenMsgTest {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
- BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader();
- BGPMessage message;
- BGPHeader bgpHeader = new BGPHeader();
+ BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
+ BgpMessage message;
+ BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
- assertThat(message, instanceOf(BGPOpenMsg.class));
+ assertThat(message, instanceOf(BgpOpenMsg.class));
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
@@ -156,7 +156,7 @@ public class BGPOpenMsgTest {
* This test case checks open message with capabilities.
*/
@Test
- public void openMessageTest4() throws BGPParseException {
+ public void openMessageTest4() throws BgpParseException {
// OPEN Message with capabilities.
byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff,
@@ -178,13 +178,13 @@ public class BGPOpenMsgTest {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
- BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader();
- BGPMessage message;
- BGPHeader bgpHeader = new BGPHeader();
+ BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
+ BgpMessage message;
+ BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
- assertThat(message, instanceOf(BGPOpenMsg.class));
+ assertThat(message, instanceOf(BgpOpenMsg.class));
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
@@ -200,8 +200,8 @@ public class BGPOpenMsgTest {
* In this test case, Invalid version is given as input and expecting
* an exception.
*/
- @Test(expected = BGPParseException.class)
- public void openMessageTest5() throws BGPParseException {
+ @Test(expected = BgpParseException.class)
+ public void openMessageTest5() throws BgpParseException {
// OPEN Message with invalid version number.
byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff,
@@ -217,20 +217,20 @@ public class BGPOpenMsgTest {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
- BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader();
- BGPMessage message;
- BGPHeader bgpHeader = new BGPHeader();
+ BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
+ BgpMessage message;
+ BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
- assertThat(message, instanceOf(BGPOpenMsg.class));
+ assertThat(message, instanceOf(BgpOpenMsg.class));
}
/**
* In this test case, Marker is set as 0 in input and expecting
* an exception.
*/
- @Test(expected = BGPParseException.class)
- public void openMessageTest6() throws BGPParseException {
+ @Test(expected = BgpParseException.class)
+ public void openMessageTest6() throws BgpParseException {
// OPEN Message with marker set to 0.
byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff,
@@ -246,20 +246,20 @@ public class BGPOpenMsgTest {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
- BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader();
- BGPMessage message;
- BGPHeader bgpHeader = new BGPHeader();
+ BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
+ BgpMessage message;
+ BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
- assertThat(message, instanceOf(BGPOpenMsg.class));
+ assertThat(message, instanceOf(BgpOpenMsg.class));
}
/**
* In this test case, Invalid message length is given as input and expecting
* an exception.
*/
- @Test(expected = BGPParseException.class)
- public void openMessageTest7() throws BGPParseException {
+ @Test(expected = BgpParseException.class)
+ public void openMessageTest7() throws BgpParseException {
// OPEN Message with invalid header length.
byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff,
@@ -275,20 +275,20 @@ public class BGPOpenMsgTest {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
- BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader();
- BGPMessage message;
- BGPHeader bgpHeader = new BGPHeader();
+ BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
+ BgpMessage message;
+ BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
- assertThat(message, instanceOf(BGPOpenMsg.class));
+ assertThat(message, instanceOf(BgpOpenMsg.class));
}
/**
* In this test case, Invalid message type is given as input and expecting
* an exception.
*/
- @Test(expected = BGPParseException.class)
- public void openMessageTest8() throws BGPParseException {
+ @Test(expected = BgpParseException.class)
+ public void openMessageTest8() throws BgpParseException {
// OPEN Message with invalid message type.
byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff,
@@ -304,11 +304,11 @@ public class BGPOpenMsgTest {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
- BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader();
- BGPMessage message;
- BGPHeader bgpHeader = new BGPHeader();
+ BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
+ BgpMessage message;
+ BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
- assertThat(message, instanceOf(BGPOpenMsg.class));
+ assertThat(message, instanceOf(BgpOpenMsg.class));
}
}
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AreaIdTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AreaIdTest.java
index 6a9e2ec5..e11564ab 100644
--- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AreaIdTest.java
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AreaIdTest.java
@@ -36,42 +36,4 @@ public class AreaIdTest {
.addEqualityGroup(tlv2)
.testEquals();
}
-
- /**
- * Test for OSPFNonPseudonode Tlv.
- */
- public static class OspfNonPseudonodeTest {
- private final int value1 = 0x12121212;
- private final int value2 = 0x12121211;
- private final OSPFNonPseudonode tlv1 = OSPFNonPseudonode.of(value1);
- private final OSPFNonPseudonode sameAsTlv1 = OSPFNonPseudonode.of(value1);
- private final OSPFNonPseudonode tlv2 = OSPFNonPseudonode.of(value2);
-
- @Test
- public void basics() {
- new EqualsTester()
- .addEqualityGroup(tlv1, sameAsTlv1)
- .addEqualityGroup(tlv2)
- .testEquals();
- }
- }
-
- /**
- * Test for IsIsNonPseudonode Tlv.
- */
- public static class IsIsNonPseudonodeTest {
- private final byte[] value1 = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58};
- private final byte[] value2 = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x59};
- private final IsIsNonPseudonode tlv1 = IsIsNonPseudonode.of(value1);
- private final IsIsNonPseudonode sameAsTlv1 = IsIsNonPseudonode.of(value1);
- private final IsIsNonPseudonode tlv2 = IsIsNonPseudonode.of(value2);
-
- @Test
- public void basics() {
- new EqualsTester()
- .addEqualityGroup(tlv1, sameAsTlv1)
- .addEqualityGroup(tlv2)
- .testEquals();
- }
- }
}
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BGPLSIdentifierTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BgpLSIdentifierTest.java
index f3355d35..59cf96fa 100644
--- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BGPLSIdentifierTest.java
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BgpLSIdentifierTest.java
@@ -22,12 +22,12 @@ import com.google.common.testing.EqualsTester;
/**
* Test for BGPLSIdentifier Tlv.
*/
-public class BGPLSIdentifierTest {
+public class BgpLSIdentifierTest {
private final int value1 = 8738;
private final int value2 = 13107;
- private final BGPLSIdentifierTlv tlv1 = BGPLSIdentifierTlv.of(value1);
- private final BGPLSIdentifierTlv sameAsTlv1 = new BGPLSIdentifierTlv(value1);
- private final BGPLSIdentifierTlv tlv2 = new BGPLSIdentifierTlv(value2);
+ private final BgpLSIdentifierTlv tlv1 = BgpLSIdentifierTlv.of(value1);
+ private final BgpLSIdentifierTlv sameAsTlv1 = new BgpLSIdentifierTlv(value1);
+ private final BgpLSIdentifierTlv tlv2 = new BgpLSIdentifierTlv(value2);
@Test
public void basics() {
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsNonPseudonodeTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsNonPseudonodeTest.java
new file mode 100644
index 00000000..7ce4d5d3
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsNonPseudonodeTest.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types;
+
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Test for IsIsNonPseudonode Tlv.
+ */
+public class IsIsNonPseudonodeTest {
+ private final byte[] value1 = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58};
+ private final byte[] value2 = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x59};
+ private final IsIsNonPseudonode tlv1 = IsIsNonPseudonode.of(value1);
+ private final IsIsNonPseudonode sameAsTlv1 = IsIsNonPseudonode.of(value1);
+ private final IsIsNonPseudonode tlv2 = IsIsNonPseudonode.of(value2);
+
+ @Test
+ public void testEquality() {
+ new EqualsTester()
+ .addEqualityGroup(tlv1, sameAsTlv1)
+ .addEqualityGroup(tlv2)
+ .testEquals();
+ }
+}
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java
index 00e85dcf..a2a7c2b5 100644
--- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java
@@ -15,11 +15,6 @@
*/
package org.onosproject.bgpio.types;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.Test;
import com.google.common.testing.EqualsTester;
@@ -29,28 +24,13 @@ import com.google.common.testing.EqualsTester;
*/
public class IsIsPseudonodeTest {
private final byte[] value1 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x02};
- byte value;
- List<Byte> isoNodeID1 = new ArrayList<Byte>();
- ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
private final byte[] value2 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x03};
- List<Byte> isoNodeID2 = new ArrayList<Byte>();
- ChannelBuffer buffer1 = ChannelBuffers.dynamicBuffer();
- private final IsIsPseudonode tlv1 = IsIsPseudonode.of(isoNodeID1, (byte) 1);
- private final IsIsPseudonode sameAsTlv1 = IsIsPseudonode.of(isoNodeID1, (byte) 1);
- private final IsIsPseudonode tlv2 = IsIsPseudonode.of(isoNodeID2, (byte) 1);
+ private final IsIsPseudonode tlv1 = IsIsPseudonode.of(value1, (byte) 1);
+ private final IsIsPseudonode sameAsTlv1 = IsIsPseudonode.of(value1, (byte) 1);
+ private final IsIsPseudonode tlv2 = IsIsPseudonode.of(value2, (byte) 1);
@Test
public void testEquality() {
- buffer.writeBytes(value1);
- for (int i = 0; i < 6; i++) {
- value = buffer.readByte();
- isoNodeID1.add(value);
- }
- buffer1.writeBytes(value2);
- for (int i = 0; i < 6; i++) {
- value = buffer1.readByte();
- isoNodeID1.add(value);
- }
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LocalPrefTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LocalPrefTest.java
index 02a06e05..1bd34385 100644
--- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LocalPrefTest.java
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LocalPrefTest.java
@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.bgpio;
+package org.onosproject.bgpio.types;
import org.junit.Test;
-import org.onosproject.bgpio.types.LocalPref;
import com.google.common.testing.EqualsTester;
@@ -32,9 +31,6 @@ public class LocalPrefTest {
@Test
public void testEquality() {
- new EqualsTester()
- .addEqualityGroup(attr1, sameAsAttr1)
- .addEqualityGroup(attr2)
- .testEquals();
+ new EqualsTester().addEqualityGroup(attr1, sameAsAttr1).addEqualityGroup(attr2).testEquals();
}
}
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/MedTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/MedTest.java
index eafcec74..2ee5b33f 100644
--- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/MedTest.java
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/MedTest.java
@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.bgpio;
+package org.onosproject.bgpio.types;
import org.junit.Test;
-import org.onosproject.bgpio.types.Med;
import com.google.common.testing.EqualsTester;
@@ -32,9 +31,6 @@ public class MedTest {
@Test
public void testEquality() {
- new EqualsTester()
- .addEqualityGroup(attr1, sameAsAttr1)
- .addEqualityGroup(attr2)
- .testEquals();
+ new EqualsTester().addEqualityGroup(attr1, sameAsAttr1).addEqualityGroup(attr2).testEquals();
}
}
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidthTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidthTest.java
new file mode 100644
index 00000000..06fecc92
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidthTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types.attr;
+
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Test for BGP link max bandwidth attribute.
+ */
+public class BgpLinkAttrMaxLinkBandwidthTest {
+ private final float val = 0x010203;
+ private final short valLen = 3;
+ private final float val1 = 0x01020304;
+ private final short val1Len = 4;
+
+ private final BgpLinkAttrMaxLinkBandwidth data = BgpLinkAttrMaxLinkBandwidth
+ .of(val, valLen);
+ private final BgpLinkAttrMaxLinkBandwidth sameAsData = BgpLinkAttrMaxLinkBandwidth
+ .of(val, valLen);
+ private final BgpLinkAttrMaxLinkBandwidth diffData = BgpLinkAttrMaxLinkBandwidth
+ .of(val1, val1Len);
+
+ @Test
+ public void basics() {
+ new EqualsTester().addEqualityGroup(data, sameAsData)
+ .addEqualityGroup(diffData).testEquals();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrNameTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrNameTest.java
new file mode 100644
index 00000000..45048527
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrNameTest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types.attr;
+
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Test for Link attribute name Tlv.
+ */
+public class BgpLinkAttrNameTest {
+ private final byte[] array = new byte[] {0x01, 0x02, 0x03, 0x04};
+ private final byte[] array1 = new byte[] {0x01, 0x02, 0x03, 0x01};
+
+ private final BgpLinkAttrName isisData = BgpLinkAttrName.of(array);
+ private final BgpLinkAttrName sameAsIsisData = BgpLinkAttrName.of(array);
+ private final BgpLinkAttrName isisDiff = BgpLinkAttrName.of(array1);
+
+ @Test
+ public void basics() {
+ new EqualsTester().addEqualityGroup(isisData, sameAsIsisData)
+ .addEqualityGroup(isisDiff).testEquals();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttribTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttribTest.java
new file mode 100644
index 00000000..71d05f85
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttribTest.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types.attr;
+
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Test for Opaque Link attribute Tlv.
+ */
+public class BgpLinkAttrOpaqLnkAttribTest {
+ private final byte[] array = new byte[] {0x01, 0x02, 0x03, 0x04};
+ private final byte[] array1 = new byte[] {0x01, 0x02, 0x03, 0x01};
+
+ private final BgpLinkAttrOpaqLnkAttrib isisData = BgpLinkAttrOpaqLnkAttrib
+ .of(array);
+ private final BgpLinkAttrOpaqLnkAttrib sameAsIsisData = BgpLinkAttrOpaqLnkAttrib
+ .of(array);
+ private final BgpLinkAttrOpaqLnkAttrib isisDiff = BgpLinkAttrOpaqLnkAttrib
+ .of(array1);
+
+ @Test
+ public void basics() {
+ new EqualsTester().addEqualityGroup(isisData, sameAsIsisData)
+ .addEqualityGroup(isisDiff).testEquals();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetricTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetricTest.java
new file mode 100644
index 00000000..9f3a7fad
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetricTest.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types.attr;
+
+import org.junit.Test;
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Test for BGP link TE default metric attribute.
+ */
+public class BgpLinkAttrTeDefaultMetricTest {
+ private final int val = 0x010203;
+ private final int val1 = 0x01020304;
+
+ private final BgpLinkAttrTeDefaultMetric data = BgpLinkAttrTeDefaultMetric
+ .of(val);
+ private final BgpLinkAttrTeDefaultMetric sameAsData = BgpLinkAttrTeDefaultMetric
+ .of(val);
+ private final BgpLinkAttrTeDefaultMetric diffData = BgpLinkAttrTeDefaultMetric
+ .of(val1);
+
+ @Test
+ public void basics() {
+ new EqualsTester().addEqualityGroup(data, sameAsData)
+ .addEqualityGroup(diffData).testEquals();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrUnRsrvdLinkBandwidthTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrUnRsrvdLinkBandwidthTest.java
new file mode 100644
index 00000000..f1d2a1fa
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrUnRsrvdLinkBandwidthTest.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types.attr;
+
+import java.util.ArrayList;
+
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Test for BGP unreserved bandwidth attribute.
+ */
+public class BgpLinkAttrUnRsrvdLinkBandwidthTest {
+ ArrayList<Float> maxUnResBandwidth = new ArrayList<Float>();
+ ArrayList<Float> maxUnResBandwidth1 = new ArrayList<Float>();
+ short sType = 10;
+
+ private final BgpLinkAttrUnRsrvdLinkBandwidth isisData = BgpLinkAttrUnRsrvdLinkBandwidth
+ .of(maxUnResBandwidth, sType);
+ private final BgpLinkAttrUnRsrvdLinkBandwidth sameAsIsisData = BgpLinkAttrUnRsrvdLinkBandwidth
+ .of(maxUnResBandwidth, sType);
+ private final BgpLinkAttrUnRsrvdLinkBandwidth isisDiff = BgpLinkAttrUnRsrvdLinkBandwidth
+ .of(maxUnResBandwidth1, sType);
+
+ @Test
+ public void basics() {
+
+ maxUnResBandwidth.add(new Float(1));
+ maxUnResBandwidth.add(new Float(2));
+ maxUnResBandwidth.add(new Float(3));
+ maxUnResBandwidth.add(new Float(4));
+
+ maxUnResBandwidth1.add(new Float(1));
+ maxUnResBandwidth1.add(new Float(2));
+ maxUnResBandwidth1.add(new Float(3));
+ maxUnResBandwidth1.add(new Float(1));
+
+ new EqualsTester().addEqualityGroup(isisData, sameAsIsisData)
+ .addEqualityGroup(isisDiff).testEquals();
+
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueDataTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueDataTest.java
new file mode 100644
index 00000000..17dafbb7
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueDataTest.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types.attr;
+
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Test for prefix attribute opaque data Tlv.
+ */
+public class BgpPrefixAttrOpaqueDataTest {
+ private final byte[] array = new byte[] {0x01, 0x02, 0x03, 0x04};
+ private final byte[] array1 = new byte[] {0x01, 0x02, 0x03, 0x01};
+
+ private final BgpPrefixAttrOpaqueData isisData = BgpPrefixAttrOpaqueData
+ .of(array);
+ private final BgpPrefixAttrOpaqueData sameAsIsisData = BgpPrefixAttrOpaqueData
+ .of(array);
+ private final BgpPrefixAttrOpaqueData isisDiff = BgpPrefixAttrOpaqueData
+ .of(array1);
+
+ @Test
+ public void basics() {
+ new EqualsTester().addEqualityGroup(isisData, sameAsIsisData)
+ .addEqualityGroup(isisDiff).testEquals();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTagTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTagTest.java
new file mode 100644
index 00000000..25ced61f
--- /dev/null
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTagTest.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types.attr;
+
+import java.util.ArrayList;
+
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Test for BGP prefix route tag attribute.
+ */
+public class BgpPrefixAttrRouteTagTest {
+ ArrayList<Integer> maxUnResBandwidth = new ArrayList<Integer>();
+ ArrayList<Integer> maxUnResBandwidth1 = new ArrayList<Integer>();
+
+ private final BgpPrefixAttrRouteTag isisData = BgpPrefixAttrRouteTag
+ .of(maxUnResBandwidth);
+ private final BgpPrefixAttrRouteTag sameAsIsisData = BgpPrefixAttrRouteTag
+ .of(maxUnResBandwidth);
+ private final BgpPrefixAttrRouteTag isisDiff = BgpPrefixAttrRouteTag
+ .of(maxUnResBandwidth1);
+
+ @Test
+ public void basics() {
+
+ maxUnResBandwidth.add(new Integer(1));
+ maxUnResBandwidth.add(new Integer(2));
+ maxUnResBandwidth.add(new Integer(3));
+ maxUnResBandwidth.add(new Integer(4));
+
+ maxUnResBandwidth1.add(new Integer(1));
+ maxUnResBandwidth1.add(new Integer(2));
+ maxUnResBandwidth1.add(new Integer(3));
+ maxUnResBandwidth1.add(new Integer(1));
+
+ new EqualsTester().addEqualityGroup(isisData, sameAsIsisData)
+ .addEqualityGroup(isisDiff).testEquals();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/AdjRibIn.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/AdjRibIn.java
new file mode 100644
index 00000000..9cbfbf65
--- /dev/null
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/AdjRibIn.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.bgp.controller.impl;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.onosproject.bgpio.protocol.BgpLSNlri;
+import org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier;
+import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier;
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier;
+import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implementation of Adj-RIB-In for each peer.
+ */
+public class AdjRibIn {
+ private Map<BgpNodeLSIdentifier, PathAttrNlriDetails> nodeTree = new TreeMap<>();
+ private Map<BgpLinkLSIdentifier, PathAttrNlriDetails> linkTree = new TreeMap<>();
+ private Map<BgpPrefixLSIdentifier, PathAttrNlriDetails> prefixTree = new TreeMap<>();
+
+ /**
+ * Returns the adjacency node.
+ *
+ * @return node adjacency RIB node
+ */
+ public Map<BgpNodeLSIdentifier, PathAttrNlriDetails> nodeTree() {
+ return nodeTree;
+ }
+
+ /**
+ * Returns the adjacency link.
+ *
+ * @return link adjacency RIB node
+ */
+ public Map<BgpLinkLSIdentifier, PathAttrNlriDetails> linkTree() {
+ return linkTree;
+ }
+
+ /**
+ * Returns the adjacency prefix.
+ *
+ * @return prefix adjacency RIB node
+ */
+ public Map<BgpPrefixLSIdentifier, PathAttrNlriDetails> prefixTree() {
+ return prefixTree;
+ }
+
+ /**
+ * Update nlri identifier into the tree if nlri identifier exists in tree otherwise add this to the tree.
+ *
+ * @param nlri NLRI Info
+ * @param details has pathattribute , protocolID and identifier
+ */
+ public void add(BgpLSNlri nlri, PathAttrNlriDetails details) {
+ if (nlri instanceof BgpNodeLSNlriVer4) {
+ BgpNodeLSIdentifier nodeLSIdentifier = ((BgpNodeLSNlriVer4) nlri).getLocalNodeDescriptors();
+ if (nodeTree.containsKey(nodeLSIdentifier)) {
+ nodeTree.replace(nodeLSIdentifier, details);
+ } else {
+ nodeTree.put(nodeLSIdentifier, details);
+ }
+ } else if (nlri instanceof BgpLinkLsNlriVer4) {
+ BgpLinkLSIdentifier linkLSIdentifier = ((BgpLinkLsNlriVer4) nlri).getLinkIdentifier();
+ if (linkTree.containsKey(linkLSIdentifier)) {
+ linkTree.replace(linkLSIdentifier, details);
+ } else {
+ linkTree.put(linkLSIdentifier, details);
+ }
+ } else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) {
+ BgpPrefixLSIdentifier prefixIdentifier = ((BgpPrefixIPv4LSNlriVer4) nlri).getPrefixIdentifier();
+ if (prefixTree.containsKey(prefixIdentifier)) {
+ prefixTree.replace(prefixIdentifier, details);
+ } else {
+ prefixTree.put(prefixIdentifier, details);
+ }
+ }
+ }
+
+ /**
+ * Removes nlri identifier if it exists in the adjacency tree.
+ *
+ * @param nlri NLRI Info
+ */
+ public void remove(BgpLSNlri nlri) {
+ if (nlri instanceof BgpNodeLSNlriVer4) {
+ BgpNodeLSIdentifier nodeLSIdentifier = ((BgpNodeLSNlriVer4) nlri).getLocalNodeDescriptors();
+ if (nodeTree.containsKey(nodeLSIdentifier)) {
+ nodeTree.remove(nodeLSIdentifier);
+ }
+ } else if (nlri instanceof BgpLinkLsNlriVer4) {
+ BgpLinkLSIdentifier linkLSIdentifier = ((BgpLinkLsNlriVer4) nlri).getLinkIdentifier();
+ if (linkTree.containsKey(linkLSIdentifier)) {
+ linkTree.remove(linkLSIdentifier);
+ }
+ } else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) {
+ BgpPrefixLSIdentifier prefixIdentifier = ((BgpPrefixIPv4LSNlriVer4) nlri).getPrefixIdentifier();
+ if (prefixTree.containsKey(prefixIdentifier)) {
+ prefixTree.remove(prefixIdentifier);
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("nodeTree", nodeTree)
+ .add("linkTree", linkTree)
+ .add("prefixTree", prefixTree)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerImpl.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerImpl.java
deleted file mode 100755
index 45f74634..00000000
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerImpl.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.bgp.controller.impl;
-
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.RejectedExecutionException;
-
-import org.jboss.netty.channel.Channel;
-import org.onlab.packet.IpAddress;
-import org.onosproject.bgp.controller.BGPController;
-import org.onosproject.bgp.controller.BGPPeer;
-import org.onosproject.bgp.controller.BgpSessionInfo;
-import org.onosproject.bgpio.protocol.BGPFactories;
-import org.onosproject.bgpio.protocol.BGPFactory;
-import org.onosproject.bgpio.protocol.BGPMessage;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.MoreObjects;
-
-/**
- * BGPPeerImpl implements BGPPeer, maintains peer information and store updates in RIB .
- */
-public class BGPPeerImpl implements BGPPeer {
-
- protected final Logger log = LoggerFactory.getLogger(BGPPeerImpl.class);
-
- private static final String SHUTDOWN_MSG = "Worker has already been shutdown";
-
- private BGPController bgpController;
- private Channel channel;
- protected String channelId;
- private boolean connected;
- protected boolean isHandShakeComplete = false;
- private BgpSessionInfo sessionInfo;
- private BGPPacketStatsImpl pktStats;
-
-
- @Override
- public BgpSessionInfo sessionInfo() {
- return sessionInfo;
- }
-
- /**
- * Initialize peer.
- *
- *@param bgpController controller instance
- *@param sessionInfo bgp session info
- *@param pktStats packet statistics
- */
- public BGPPeerImpl(BGPController bgpController, BgpSessionInfo sessionInfo, BGPPacketStatsImpl pktStats) {
- this.bgpController = bgpController;
- this.sessionInfo = sessionInfo;
- this.pktStats = pktStats;
- }
-
- // ************************
- // Channel related
- // ************************
-
- @Override
- public final void disconnectPeer() {
- this.channel.close();
- }
-
- @Override
- public final void sendMessage(BGPMessage m) {
- log.debug("Sending message to {}", channel.getRemoteAddress());
- try {
- channel.write(Collections.singletonList(m));
- this.pktStats.addOutPacket();
- } catch (RejectedExecutionException e) {
- log.warn(e.getMessage());
- if (!e.getMessage().contains(SHUTDOWN_MSG)) {
- throw e;
- }
- }
- }
-
- @Override
- public final void sendMessage(List<BGPMessage> msgs) {
- try {
- channel.write(msgs);
- this.pktStats.addOutPacket(msgs.size());
- } catch (RejectedExecutionException e) {
- log.warn(e.getMessage());
- if (!e.getMessage().contains(SHUTDOWN_MSG)) {
- throw e;
- }
- }
- }
-
- @Override
- public final boolean isConnected() {
- return this.connected;
- }
-
- @Override
- public final void setConnected(boolean connected) {
- this.connected = connected;
- };
-
- @Override
- public final void setChannel(Channel channel) {
- this.channel = channel;
- final SocketAddress address = channel.getRemoteAddress();
- if (address instanceof InetSocketAddress) {
- final InetSocketAddress inetAddress = (InetSocketAddress) address;
- final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress());
- if (ipAddress.isIp4()) {
- channelId = ipAddress.toString() + ':' + inetAddress.getPort();
- } else {
- channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort();
- }
- }
- };
-
- @Override
- public final Channel getChannel() {
- return this.channel;
- };
-
- @Override
- public String channelId() {
- return channelId;
- }
-
- @Override
- public BGPFactory factory() {
- return BGPFactories.getFactory(sessionInfo.remoteBgpVersion());
- }
-
- @Override
- public boolean isHandshakeComplete() {
- return isHandShakeComplete;
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(getClass()).omitNullValues()
- .add("channel", channelId())
- .add("bgpId", sessionInfo().remoteBgpId()).toString();
- }
-}
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPChannelHandler.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpChannelHandler.java
index f21c311c..8754563d 100755
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPChannelHandler.java
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpChannelHandler.java
@@ -23,8 +23,8 @@ import java.net.SocketAddress;
import java.net.UnknownHostException;
import java.nio.channels.ClosedChannelException;
import java.util.Collections;
-import java.util.List;
import java.util.LinkedList;
+import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.RejectedExecutionException;
@@ -40,20 +40,20 @@ import org.jboss.netty.handler.timeout.ReadTimeoutException;
import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
-import org.onosproject.bgp.controller.BGPCfg;
-import org.onosproject.bgp.controller.BGPController;
-import org.onosproject.bgp.controller.BGPId;
-import org.onosproject.bgp.controller.BGPPeer;
-import org.onosproject.bgp.controller.BGPPeerCfg;
-import org.onosproject.bgp.controller.impl.BGPControllerImpl.BGPPeerManagerImpl;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.protocol.BGPFactory;
-import org.onosproject.bgpio.protocol.BGPMessage;
-import org.onosproject.bgpio.protocol.BGPOpenMsg;
-import org.onosproject.bgpio.protocol.BGPType;
-import org.onosproject.bgpio.protocol.BGPVersion;
-import org.onosproject.bgpio.types.BGPErrorType;
-import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgp.controller.BgpCfg;
+import org.onosproject.bgp.controller.BgpController;
+import org.onosproject.bgp.controller.BgpId;
+import org.onosproject.bgp.controller.BgpPeer;
+import org.onosproject.bgp.controller.BgpPeerCfg;
+import org.onosproject.bgp.controller.impl.BgpControllerImpl.BgpPeerManagerImpl;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpFactory;
+import org.onosproject.bgpio.protocol.BgpMessage;
+import org.onosproject.bgpio.protocol.BgpOpenMsg;
+import org.onosproject.bgpio.protocol.BgpType;
+import org.onosproject.bgpio.protocol.BgpVersion;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv;
import org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv;
import org.slf4j.Logger;
@@ -62,20 +62,20 @@ import org.slf4j.LoggerFactory;
/**
* Channel handler deals with the bgp peer connection and dispatches messages from peer to the appropriate locations.
*/
-class BGPChannelHandler extends IdleStateAwareChannelHandler {
+class BgpChannelHandler extends IdleStateAwareChannelHandler {
- private static final Logger log = LoggerFactory.getLogger(BGPChannelHandler.class);
+ private static final Logger log = LoggerFactory.getLogger(BgpChannelHandler.class);
static final int BGP_MIN_HOLDTIME = 3;
static final int BGP_MAX_KEEPALIVE_INTERVAL = 3;
- private BGPPeer bgpPeer;
- private BGPId thisbgpId;
+ private BgpPeer bgpPeer;
+ private BgpId thisbgpId;
private Channel channel;
- private BGPKeepAliveTimer keepAliveTimer = null;
+ private BgpKeepAliveTimer keepAliveTimer = null;
private short peerHoldTime = 0;
private short negotiatedHoldTime = 0;
private long peerAsNum;
private int peerIdentifier;
- private BGPPacketStatsImpl bgpPacketStats;
+ private BgpPacketStatsImpl bgpPacketStats;
static final int MAX_WRONG_COUNT_PACKET = 5;
static final byte MULTI_PROTOCOL_EXTN_CAPA_TYPE = 1;
static final byte FOUR_OCTET_AS_NUM_CAPA_TYPE = 65;
@@ -97,30 +97,30 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
// peer state for the older (still connected) peer
private volatile Boolean duplicateBGPIdFound;
// Indicates the bgp version used by this bgp peer
- protected BGPVersion bgpVersion;
- private BGPController bgpController;
- protected BGPFactory factory4;
+ protected BgpVersion bgpVersion;
+ private BgpController bgpController;
+ protected BgpFactory factory4;
private boolean isIbgpSession;
private BgpSessionInfoImpl sessionInfo;
- private BGPPeerManagerImpl peerManager;
+ private BgpPeerManagerImpl peerManager;
private InetSocketAddress inetAddress;
private IpAddress ipAddress;
private SocketAddress address;
private String peerAddr;
- private BGPCfg bgpconfig;
+ private BgpCfg bgpconfig;
/**
* Create a new unconnected BGPChannelHandler.
*
* @param bgpController bgp controller
*/
- BGPChannelHandler(BGPController bgpController) {
+ BgpChannelHandler(BgpController bgpController) {
this.bgpController = bgpController;
- this.peerManager = (BGPPeerManagerImpl) bgpController.peerManager();
+ this.peerManager = (BgpPeerManagerImpl) bgpController.peerManager();
this.state = ChannelState.IDLE;
- this.factory4 = Controller.getBGPMessageFactory4();
+ this.factory4 = Controller.getBgpMessageFactory4();
this.duplicateBGPIdFound = Boolean.FALSE;
- this.bgpPacketStats = new BGPPacketStatsImpl();
+ this.bgpPacketStats = new BgpPacketStatsImpl();
this.bgpconfig = bgpController.getConfig();
}
@@ -147,24 +147,29 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
OPENSENT(false) {
@Override
- void processBGPMessage(BGPChannelHandler h, BGPMessage m) throws IOException, BGPParseException {
+ void processBgpMessage(BgpChannelHandler h, BgpMessage m) throws IOException, BgpParseException {
log.debug("message received in OPENSENT state");
// check for OPEN message
- if (m.getType() != BGPType.OPEN) {
+ if (m.getType() != BgpType.OPEN) {
// When the message type is not keep alive message increment the wrong packet statistics
- h.processUnknownMsg(BGPErrorType.FINITE_STATE_MACHINE_ERROR,
- BGPErrorType.RECEIVE_UNEXPECTED_MESSAGE_IN_OPENSENT_STATE, m.getType()
- .getType());
+ h.processUnknownMsg(BgpErrorType.FINITE_STATE_MACHINE_ERROR,
+ BgpErrorType.RECEIVE_UNEXPECTED_MESSAGE_IN_OPENSENT_STATE,
+ m.getType().getType());
log.debug("Message is not OPEN message");
} else {
log.debug("Sending keep alive message in OPENSENT state");
h.bgpPacketStats.addInPacket();
- BGPOpenMsg pOpenmsg = (BGPOpenMsg) m;
+ BgpOpenMsg pOpenmsg = (BgpOpenMsg) m;
h.peerIdentifier = pOpenmsg.getBgpId();
// validate capabilities and open msg
if (h.openMsgValidation(h, pOpenmsg)) {
+ if (h.connectionCollisionDetection(BgpPeerCfg.State.OPENCONFIRM,
+ h.peerIdentifier, h.peerAddr)) {
+ h.channel.close();
+ return;
+ }
log.debug("Sending handshake OPEN message");
/*
@@ -176,7 +181,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
if (h.peerHoldTime < h.bgpconfig.getHoldTime()) {
h.channel.getPipeline().replace("holdTime",
"holdTime",
- new ReadTimeoutHandler(BGPPipelineFactory.TIMER,
+ new ReadTimeoutHandler(BgpPipelineFactory.TIMER,
h.peerHoldTime));
}
@@ -190,30 +195,35 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
h.sendKeepAliveMessage();
h.bgpPacketStats.addOutPacket();
h.setState(OPENCONFIRM);
- h.bgpconfig.setPeerConnState(h.peerAddr, BGPPeerCfg.State.OPENCONFIRM);
+ h.bgpconfig.setPeerConnState(h.peerAddr, BgpPeerCfg.State.OPENCONFIRM);
}
}
},
OPENWAIT(false) {
@Override
- void processBGPMessage(BGPChannelHandler h, BGPMessage m) throws IOException, BGPParseException {
+ void processBgpMessage(BgpChannelHandler h, BgpMessage m) throws IOException, BgpParseException {
log.debug("Message received in OPEN WAIT State");
// check for open message
- if (m.getType() != BGPType.OPEN) {
+ if (m.getType() != BgpType.OPEN) {
// When the message type is not open message increment the wrong packet statistics
- h.processUnknownMsg(BGPErrorType.FINITE_STATE_MACHINE_ERROR, BGPErrorType.UNSPECIFIED_ERROR, m
- .getType().getType());
+ h.processUnknownMsg(BgpErrorType.FINITE_STATE_MACHINE_ERROR, BgpErrorType.UNSPECIFIED_ERROR,
+ m.getType().getType());
log.debug("Message is not OPEN message");
} else {
h.bgpPacketStats.addInPacket();
- BGPOpenMsg pOpenmsg = (BGPOpenMsg) m;
+ BgpOpenMsg pOpenmsg = (BgpOpenMsg) m;
h.peerIdentifier = pOpenmsg.getBgpId();
// Validate open message
if (h.openMsgValidation(h, pOpenmsg)) {
+ if (h.connectionCollisionDetection(BgpPeerCfg.State.OPENSENT,
+ h.peerIdentifier, h.peerAddr)) {
+ h.channel.close();
+ return;
+ }
log.debug("Sending handshake OPEN message");
/*
@@ -225,7 +235,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
if (h.peerHoldTime < h.bgpconfig.getHoldTime()) {
h.channel.getPipeline().replace("holdTime",
"holdTime",
- new ReadTimeoutHandler(BGPPipelineFactory.TIMER,
+ new ReadTimeoutHandler(BgpPipelineFactory.TIMER,
h.peerHoldTime));
}
@@ -237,6 +247,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
h.sendHandshakeOpenMessage();
h.bgpPacketStats.addOutPacket();
h.setState(OPENCONFIRM);
+ h.bgpconfig.setPeerConnState(h.peerAddr, BgpPeerCfg.State.OPENCONFIRM);
}
}
}
@@ -244,14 +255,14 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
OPENCONFIRM(false) {
@Override
- void processBGPMessage(BGPChannelHandler h, BGPMessage m) throws IOException, BGPParseException {
+ void processBgpMessage(BgpChannelHandler h, BgpMessage m) throws IOException, BgpParseException {
log.debug("Message received in OPENCONFIRM state");
// check for keep alive message
- if (m.getType() != BGPType.KEEP_ALIVE) {
+ if (m.getType() != BgpType.KEEP_ALIVE) {
// When the message type is not keep alive message handle the wrong packet
- h.processUnknownMsg(BGPErrorType.FINITE_STATE_MACHINE_ERROR,
- BGPErrorType.RECEIVE_UNEXPECTED_MESSAGE_IN_OPENCONFIRM_STATE, m.getType()
- .getType());
+ h.processUnknownMsg(BgpErrorType.FINITE_STATE_MACHINE_ERROR,
+ BgpErrorType.RECEIVE_UNEXPECTED_MESSAGE_IN_OPENCONFIRM_STATE,
+ m.getType().getType());
log.debug("Message is not KEEPALIVE message");
} else {
@@ -260,7 +271,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
log.debug("Sending keep alive message in OPENCONFIRM state");
final InetSocketAddress inetAddress = (InetSocketAddress) h.address;
- h.thisbgpId = BGPId.bgpId(IpAddress.valueOf(inetAddress.getAddress()));
+ h.thisbgpId = BgpId.bgpId(IpAddress.valueOf(inetAddress.getAddress()));
// set session parameters
h.negotiatedHoldTime = (h.peerHoldTime < h.bgpconfig.getHoldTime()) ? h.peerHoldTime
@@ -268,7 +279,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
h.sessionInfo = new BgpSessionInfoImpl(h.thisbgpId, h.bgpVersion, h.peerAsNum, h.peerHoldTime,
h.peerIdentifier, h.negotiatedHoldTime, h.isIbgpSession);
- h.bgpPeer = h.peerManager.getBGPPeerInstance(h.bgpController, h.sessionInfo, h.bgpPacketStats);
+ h.bgpPeer = h.peerManager.getBgpPeerInstance(h.bgpController, h.sessionInfo, h.bgpPacketStats);
// set the status of bgp as connected
h.bgpPeer.setConnected(true);
h.bgpPeer.setChannel(h.channel);
@@ -280,8 +291,8 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
*/
if (h.negotiatedHoldTime != 0) {
- h.keepAliveTimer = new BGPKeepAliveTimer(h,
- (h.negotiatedHoldTime / BGP_MAX_KEEPALIVE_INTERVAL));
+ h.keepAliveTimer = new BgpKeepAliveTimer(h,
+ (h.negotiatedHoldTime / BGP_MAX_KEEPALIVE_INTERVAL));
} else {
h.sendKeepAliveMessage();
}
@@ -292,17 +303,10 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
h.setHandshakeComplete(true);
if (!h.peerManager.addConnectedPeer(h.thisbgpId, h.bgpPeer)) {
- /*
- * RFC 4271, Section 6.8, Based on the value of the BGP identifier, a convention is established
- * for detecting which BGP connection is to be preserved when a collision occurs. The convention
- * is to compare the BGP Identifiers of the peers involved in the collision and to retain only
- * the connection initiated by the BGP speaker with the higher-valued BGP Identifier..
- */
- // TODO: Connection collision handling.
disconnectDuplicate(h);
} else {
h.setState(ESTABLISHED);
- h.bgpconfig.setPeerConnState(h.peerAddr, BGPPeerCfg.State.ESTABLISHED);
+ h.bgpconfig.setPeerConnState(h.peerAddr, BgpPeerCfg.State.ESTABLISHED);
}
}
}
@@ -310,7 +314,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
ESTABLISHED(true) {
@Override
- void processBGPMessage(BGPChannelHandler h, BGPMessage m) throws IOException, BGPParseException {
+ void processBgpMessage(BgpChannelHandler h, BgpMessage m) throws IOException, BgpParseException {
log.debug("Message received in established state " + m.getType());
// dispatch the message
h.dispatchMessage(m);
@@ -337,7 +341,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
*
* @param h channel handler
*/
- protected void disconnectDuplicate(BGPChannelHandler h) {
+ protected void disconnectDuplicate(BgpChannelHandler h) {
log.error("Duplicated BGP IP or incompleted cleanup - " + "" + "disconnecting channel {}",
h.getPeerInfoString());
h.duplicateBGPIdFound = Boolean.TRUE;
@@ -349,8 +353,8 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
this.handshakeComplete = handshakeComplete;
}
- void processBGPMessage(BGPChannelHandler bgpChannelHandler, BGPMessage pm)
- throws IOException, BGPParseException {
+ void processBgpMessage(BgpChannelHandler bgpChannelHandler, BgpMessage pm)
+ throws IOException, BgpParseException {
// TODO Auto-generated method stub
log.debug("BGP message stub");
}
@@ -373,7 +377,8 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
}
// Connection should establish only if local ip and Autonomous system number is configured.
- if (bgpconfig.getState() != BGPCfg.State.IP_AS_CONFIGURED) {
+ if (bgpconfig.getState() != BgpCfg.State.IP_AS_CONFIGURED) {
+ sendNotification(BgpErrorType.CEASE, BgpErrorType.CONNECTION_REJECTED, null);
channel.close();
log.info("BGP local AS and router ID not configured");
return;
@@ -385,12 +390,13 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
// if peer is not configured disconnect session
if (!bgpconfig.isPeerConfigured(peerAddr)) {
log.debug("Peer is not configured {}", peerAddr);
+ sendNotification(BgpErrorType.CEASE, BgpErrorType.CONNECTION_REJECTED, null);
channel.close();
return;
}
// if connection is already established close channel
- if (peerManager.isPeerConnected(BGPId.bgpId(IpAddress.valueOf(peerAddr)))) {
+ if (peerManager.isPeerConnected(BgpId.bgpId(IpAddress.valueOf(peerAddr)))) {
log.debug("Duplicate connection received, peer {}", peerAddr);
channel.close();
return;
@@ -406,7 +412,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
sendHandshakeOpenMessage();
bgpPacketStats.addOutPacket();
setState(ChannelState.OPENSENT);
- bgpconfig.setPeerConnState(peerAddr, BGPPeerCfg.State.OPENSENT);
+ bgpconfig.setPeerConnState(peerAddr, BgpPeerCfg.State.OPENSENT);
}
}
@@ -436,6 +442,25 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
if (bgpPeer != null) {
peerManager.removeConnectedPeer(thisbgpId);
}
+
+ // Retry connection if connection is lost to bgp speaker/peer
+ if ((channel != null) && (null != channel.getPipeline().get("ActiveHandler"))) {
+ BgpConnectPeerImpl connectPeer;
+ BgpPeerCfg.State peerCfgState;
+
+ peerCfgState = bgpconfig.getPeerConnState(peerAddr);
+ // on session disconnect using configuration, do not retry
+ if (!peerCfgState.equals(BgpPeerCfg.State.IDLE)) {
+ log.debug("Connection reset by peer, retry, STATE:{}", peerCfgState);
+ BgpPeerConfig peerConfig = (BgpPeerConfig) bgpconfig.displayPeers(peerAddr);
+
+ bgpconfig.setPeerConnState(peerAddr, BgpPeerCfg.State.IDLE);
+ connectPeer = new BgpConnectPeerImpl(bgpController, peerAddr, Controller.getBgpPortNum());
+ peerConfig.setConnectPeer(connectPeer);
+ }
+ } else {
+ bgpconfig.setPeerConnState(peerAddr, BgpPeerCfg.State.IDLE);
+ }
} else {
// A duplicate was disconnected on this ChannelHandler,
// this is the same peer reconnecting, but the original state was
@@ -448,6 +473,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
keepAliveTimer.getKeepAliveTimer().cancel();
}
} else {
+ bgpconfig.setPeerConnState(peerAddr, BgpPeerCfg.State.IDLE);
log.warn("No bgp ip in channelHandler registered for " + "disconnected peer {}", getPeerInfoString());
}
}
@@ -461,14 +487,14 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
if ((ChannelState.OPENWAIT == state) || (ChannelState.OPENSENT == state)) {
// When ReadTimeout timer is expired in OPENWAIT/OPENSENT state, it is considered
- sendNotification(BGPErrorType.HOLD_TIMER_EXPIRED, (byte) 0, null);
+ sendNotification(BgpErrorType.HOLD_TIMER_EXPIRED, (byte) 0, null);
channel.close();
state = ChannelState.IDLE;
return;
} else if (ChannelState.OPENCONFIRM == state) {
// When ReadTimeout timer is expired in OPENCONFIRM state.
- sendNotification(BGPErrorType.HOLD_TIMER_EXPIRED, (byte) 0, null);
+ sendNotification(BgpErrorType.HOLD_TIMER_EXPIRED, (byte) 0, null);
channel.close();
state = ChannelState.IDLE;
return;
@@ -482,9 +508,9 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
log.debug("StackTrace for previous Exception: ", e.getCause());
}
channel.close();
- } else if (e.getCause() instanceof BGPParseException) {
+ } else if (e.getCause() instanceof BgpParseException) {
byte[] data = new byte[] {};
- BGPParseException errMsg = (BGPParseException) e.getCause();
+ BgpParseException errMsg = (BgpParseException) e.getCause();
byte errorCode = errMsg.getErrorCode();
byte errorSubCode = errMsg.getErrorSubCode();
ChannelBuffer tempCb = errMsg.getData();
@@ -511,14 +537,47 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
if (e.getMessage() instanceof List) {
@SuppressWarnings("Unchecked")
- List<BGPMessage> msglist = (List<BGPMessage>) e.getMessage();
- for (BGPMessage pm : msglist) {
+ List<BgpMessage> msglist = (List<BgpMessage>) e.getMessage();
+ for (BgpMessage pm : msglist) {
// Do the actual packet processing
- state.processBGPMessage(this, pm);
+ state.processBgpMessage(this, pm);
}
} else {
- state.processBGPMessage(this, (BGPMessage) e.getMessage());
+ state.processBgpMessage(this, (BgpMessage) e.getMessage());
+ }
+ }
+
+ /**
+ * Check for connection collision.
+ *
+ * @param state connection state
+ * @param peerIdentifier BGP peer identifier
+ * @param peerAddr BGP peer address
+ * @return true if bgp spreakers initiated connection
+ * @throws BgpParseException on error while procession collision detection
+ * @throws IOException on error while procession collision detection
+ */
+ public boolean connectionCollisionDetection(BgpPeerCfg.State state, int peerIdentifier, String peerAddr)
+ throws IOException, BgpParseException {
+ /*
+ * RFC 4271, Section 6.8, Based on the value of the BGP identifier, a convention is established for detecting
+ * which BGP connection is to be preserved when a collision occurs. The convention is to compare the BGP
+ * Identifiers of the peers involved in the collision and to retain only the connection initiated by the BGP
+ * speaker with the higher-valued BGP Identifier..
+ */
+ BgpPeerCfg.State currentState = bgpconfig.getPeerConnState(peerAddr);
+ if (currentState.equals(state)) {
+ if (((Ip4Address.valueOf(bgpconfig.getRouterId())).compareTo(Ip4Address.valueOf(peerIdentifier))) > 0) {
+ // send notification
+ sendNotification(BgpErrorType.CEASE, BgpErrorType.CONNECTION_COLLISION_RESOLUTION, null);
+ log.debug("Connection collision detected, local id: {}, peer id: {}, peer state:{}, in state:{}",
+ (Ip4Address.valueOf(bgpconfig.getRouterId())), (Ip4Address.valueOf(peerIdentifier)),
+ currentState, state);
+ return true;
+ }
}
+
+ return false;
}
// *************************
@@ -546,9 +605,9 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
* To handle the BGP message.
*
* @param m bgp message
- * @throws BGPParseException throw exception
+ * @throws BgpParseException throw exception
*/
- private void dispatchMessage(BGPMessage m) throws BGPParseException {
+ private void dispatchMessage(BgpMessage m) throws BgpParseException {
bgpPacketStats.addInPacket();
bgpController.processBGPPacket(thisbgpId, m);
}
@@ -589,24 +648,22 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
*
* @return packet statistics
*/
- public BGPPacketStatsImpl getBgpPacketStats() {
+ public BgpPacketStatsImpl getBgpPacketStats() {
return bgpPacketStats;
}
/**
* Send handshake open message to the peer.
*
- * @throws IOException, BGPParseException
+ * @throws IOException, BgpParseException
*/
- private void sendHandshakeOpenMessage() throws IOException, BGPParseException {
+ private void sendHandshakeOpenMessage() throws IOException, BgpParseException {
int bgpId;
bgpId = Ip4Address.valueOf(bgpconfig.getRouterId()).toInt();
- BGPMessage msg = factory4.openMessageBuilder().setAsNumber((short) bgpconfig.getAsNumber())
- .setHoldTime(bgpconfig.getHoldTime()).setBgpId(bgpId)
- .setLsCapabilityTlv(bgpconfig.getLsCapability())
- .setLargeAsCapabilityTlv(bgpconfig.getLargeASCapability())
- .build();
+ BgpMessage msg = factory4.openMessageBuilder().setAsNumber((short) bgpconfig.getAsNumber())
+ .setHoldTime(bgpconfig.getHoldTime()).setBgpId(bgpId).setLsCapabilityTlv(bgpconfig.getLsCapability())
+ .setLargeAsCapabilityTlv(bgpconfig.getLargeASCapability()).build();
log.debug("Sending open message to {}", channel.getRemoteAddress());
channel.write(Collections.singletonList(msg));
@@ -618,12 +675,12 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
* @param errorCode error code send in notification
* @param errorSubCode sub error code send in notification
* @param data data to send in notification
- * @throws IOException, BGPParseException while building message
+ * @throws IOException, BgpParseException while building message
*/
private void sendNotification(byte errorCode, byte errorSubCode, byte[] data)
- throws IOException, BGPParseException {
- BGPMessage msg = factory4.notificationMessageBuilder().setErrorCode(errorCode).setErrorSubCode(errorSubCode)
- .setData(data).build();
+ throws IOException, BgpParseException {
+ BgpMessage msg = factory4.notificationMessageBuilder().setErrorCode(errorCode)
+ .setErrorSubCode(errorSubCode).setData(data).build();
log.debug("Sending notification message to {}", channel.getRemoteAddress());
channel.write(Collections.singletonList(msg));
}
@@ -632,11 +689,11 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
* Send keep alive message.
*
* @throws IOException when channel is disconnected
- * @throws BGPParseException while building keep alive message
+ * @throws BgpParseException while building keep alive message
*/
- synchronized void sendKeepAliveMessage() throws IOException, BGPParseException {
+ synchronized void sendKeepAliveMessage() throws IOException, BgpParseException {
- BGPMessage msg = factory4.keepaliveMessageBuilder().build();
+ BgpMessage msg = factory4.keepaliveMessageBuilder().build();
log.debug("Sending keepalive message to {}", channel.getRemoteAddress());
channel.write(Collections.singletonList(msg));
}
@@ -647,10 +704,10 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
* @param errorCode error code
* @param errorSubCode error sub code
* @param data message type
- * @throws BGPParseException while processing error messsage
+ * @throws BgpParseException while processing error messsage
* @throws IOException while processing error message
*/
- public void processUnknownMsg(byte errorCode, byte errorSubCode, byte data) throws BGPParseException, IOException {
+ public void processUnknownMsg(byte errorCode, byte errorSubCode, byte data) throws BgpParseException, IOException {
log.debug("UNKNOWN message received");
byte[] byteArray = new byte[1];
byteArray[0] = data;
@@ -664,26 +721,26 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
* @param h channel handler
* @param openMsg open message
* @return true if valid message, otherwise false
- * @throws BGPParseException throw exception
+ * @throws BgpParseException throw exception
*/
- public boolean openMsgValidation(BGPChannelHandler h, BGPOpenMsg openMsg) throws BGPParseException {
+ public boolean openMsgValidation(BgpChannelHandler h, BgpOpenMsg openMsg) throws BgpParseException {
boolean result;
// Validate BGP ID
result = bgpIdValidation(openMsg);
if (!result) {
- throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, BGPErrorType.BAD_BGP_IDENTIFIER, null);
+ throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.BAD_BGP_IDENTIFIER, null);
}
// Validate AS number
result = asNumberValidation(h, openMsg);
if (!result) {
- throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, BGPErrorType.BAD_PEER_AS, null);
+ throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.BAD_PEER_AS, null);
}
// Validate hold timer
if ((openMsg.getHoldTime() != 0) && (openMsg.getHoldTime() < BGP_MIN_HOLDTIME)) {
- throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, BGPErrorType.UNACCEPTABLE_HOLD_TIME, null);
+ throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.UNACCEPTABLE_HOLD_TIME, null);
}
// Validate capabilities
@@ -697,25 +754,25 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
* @param h channel handler
* @param openmsg open message
* @return success or failure
- * @throws BGPParseException
+ * @throws BgpParseException
*/
- private boolean capabilityValidation(BGPChannelHandler h, BGPOpenMsg openmsg) throws BGPParseException {
+ private boolean capabilityValidation(BgpChannelHandler h, BgpOpenMsg openmsg) throws BgpParseException {
log.debug("capabilityValidation");
boolean isMultiProtocolcapabilityExists = false;
boolean isFourOctetCapabilityExits = false;
int capAsNum = 0;
- List<BGPValueType> capabilityTlv = openmsg.getCapabilityTlv();
- ListIterator<BGPValueType> listIterator = capabilityTlv.listIterator();
- List<BGPValueType> unSupportedCapabilityTlv = new LinkedList<>();
- ListIterator<BGPValueType> unSupportedCaplistIterator = unSupportedCapabilityTlv.listIterator();
- BGPValueType tempTlv;
+ List<BgpValueType> capabilityTlv = openmsg.getCapabilityTlv();
+ ListIterator<BgpValueType> listIterator = capabilityTlv.listIterator();
+ List<BgpValueType> unSupportedCapabilityTlv = new LinkedList<>();
+ ListIterator<BgpValueType> unSupportedCaplistIterator = unSupportedCapabilityTlv.listIterator();
+ BgpValueType tempTlv;
boolean isLargeAsCapabilityCfg = h.bgpconfig.getLargeASCapability();
boolean isLsCapabilityCfg = h.bgpconfig.getLsCapability();
while (listIterator.hasNext()) {
- BGPValueType tlv = listIterator.next();
+ BgpValueType tlv = listIterator.next();
if (tlv.getType() == MULTI_PROTOCOL_EXTN_CAPA_TYPE) {
isMultiProtocolcapabilityExists = true;
}
@@ -728,11 +785,11 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
if (isFourOctetCapabilityExits) {
if (capAsNum > MAX_AS2_NUM) {
if (openmsg.getAsNumber() != AS_TRANS) {
- throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, BGPErrorType.BAD_PEER_AS, null);
+ throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.BAD_PEER_AS, null);
}
} else {
if (capAsNum != openmsg.getAsNumber()) {
- throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, BGPErrorType.BAD_PEER_AS, null);
+ throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.BAD_PEER_AS, null);
}
}
}
@@ -754,11 +811,10 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
if (unSupportedCaplistIterator.hasNext()) {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
while (unSupportedCaplistIterator.hasNext()) {
- BGPValueType tlv = unSupportedCaplistIterator.next();
+ BgpValueType tlv = unSupportedCaplistIterator.next();
tlv.write(buffer);
}
- throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR,
- BGPErrorType.UNSUPPORTED_CAPABILITY, buffer);
+ throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.UNSUPPORTED_CAPABILITY, buffer);
} else {
return true;
}
@@ -771,18 +827,18 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
* @param openMsg open message
* @return true or false
*/
- private boolean asNumberValidation(BGPChannelHandler h, BGPOpenMsg openMsg) {
+ private boolean asNumberValidation(BgpChannelHandler h, BgpOpenMsg openMsg) {
log.debug("AS Num validation");
int capAsNum = 0;
boolean isFourOctetCapabilityExits = false;
- BGPPeerCfg peerCfg = h.bgpconfig.displayPeers(peerAddr);
- List<BGPValueType> capabilityTlv = openMsg.getCapabilityTlv();
- ListIterator<BGPValueType> listIterator = capabilityTlv.listIterator();
+ BgpPeerCfg peerCfg = h.bgpconfig.displayPeers(peerAddr);
+ List<BgpValueType> capabilityTlv = openMsg.getCapabilityTlv();
+ ListIterator<BgpValueType> listIterator = capabilityTlv.listIterator();
while (listIterator.hasNext()) {
- BGPValueType tlv = listIterator.next();
+ BgpValueType tlv = listIterator.next();
if (tlv.getType() == FOUR_OCTET_AS_NUM_CAPA_TYPE) {
isFourOctetCapabilityExits = true;
capAsNum = ((FourOctetAsNumCapabilityTlv) tlv).getInt();
@@ -838,7 +894,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
* @param openMsg open message
* @return true or false
*/
- private boolean bgpIdValidation(BGPOpenMsg openMsg) {
+ private boolean bgpIdValidation(BgpOpenMsg openMsg) {
String openMsgBgpId = Ip4Address.valueOf(openMsg.getBgpId()).toString();
InetAddress ipAddress;
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPConfig.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpConfig.java
index 56877a16..716cc0c5 100755
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPConfig.java
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpConfig.java
@@ -21,17 +21,17 @@ import java.util.Set;
import java.util.TreeMap;
import org.onlab.packet.Ip4Address;
-import org.onosproject.bgp.controller.BGPCfg;
-import org.onosproject.bgp.controller.BGPPeerCfg;
+import org.onosproject.bgp.controller.BgpCfg;
+import org.onosproject.bgp.controller.BgpPeerCfg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Provides BGP configuration of this BGP speaker.
*/
-public class BGPConfig implements BGPCfg {
+public class BgpConfig implements BgpCfg {
- protected static final Logger log = LoggerFactory.getLogger(BGPConfig.class);
+ protected static final Logger log = LoggerFactory.getLogger(BgpConfig.class);
private static final short DEFAULT_HOLD_TIMER = 120;
private static final short DEFAULT_CONN_RETRY_TIME = 120;
@@ -47,12 +47,12 @@ public class BGPConfig implements BGPCfg {
private int maxConnRetryCount;
private Ip4Address routerId = null;
- private TreeMap<String, BGPPeerCfg> bgpPeerTree = new TreeMap<>();
+ private TreeMap<String, BgpPeerCfg> bgpPeerTree = new TreeMap<>();
/**
* Constructor to initialize the values.
*/
- public BGPConfig() {
+ public BgpConfig() {
this.holdTime = DEFAULT_HOLD_TIMER;
this.maxConnRetryTime = DEFAULT_CONN_RETRY_TIME;
@@ -142,13 +142,13 @@ public class BGPConfig implements BGPCfg {
@Override
public boolean addPeer(String routerid, int remoteAs, short holdTime) {
- BGPPeerConfig lspeer = new BGPPeerConfig();
+ BgpPeerConfig lspeer = new BgpPeerConfig();
if (this.bgpPeerTree.get(routerid) == null) {
lspeer.setPeerRouterId(routerid);
lspeer.setAsNumber(remoteAs);
lspeer.setHoldtime(holdTime);
- lspeer.setState(BGPPeerCfg.State.IDLE);
+ lspeer.setState(BgpPeerCfg.State.IDLE);
lspeer.setSelfInnitConnection(false);
if (this.getAsNumber() == remoteAs) {
@@ -168,7 +168,7 @@ public class BGPConfig implements BGPCfg {
@Override
public boolean connectPeer(String routerid) {
- BGPPeerCfg lspeer = this.bgpPeerTree.get(routerid);
+ BgpPeerCfg lspeer = this.bgpPeerTree.get(routerid);
if (lspeer != null) {
lspeer.setSelfInnitConnection(true);
@@ -181,7 +181,7 @@ public class BGPConfig implements BGPCfg {
@Override
public boolean removePeer(String routerid) {
- BGPPeerCfg lspeer = this.bgpPeerTree.get(routerid);
+ BgpPeerCfg lspeer = this.bgpPeerTree.get(routerid);
if (lspeer != null) {
@@ -200,12 +200,12 @@ public class BGPConfig implements BGPCfg {
@Override
public boolean disconnectPeer(String routerid) {
- BGPPeerCfg lspeer = this.bgpPeerTree.get(routerid);
+ BgpPeerCfg lspeer = this.bgpPeerTree.get(routerid);
if (lspeer != null) {
//TODO DISCONNECT PEER
- lspeer.setState(BGPPeerCfg.State.IDLE);
+ lspeer.setState(BgpPeerCfg.State.IDLE);
lspeer.setSelfInnitConnection(false);
log.debug("Disconnected : " + routerid + " successfully");
@@ -217,8 +217,8 @@ public class BGPConfig implements BGPCfg {
}
@Override
- public void setPeerConnState(String routerid, BGPPeerCfg.State state) {
- BGPPeerCfg lspeer = this.bgpPeerTree.get(routerid);
+ public void setPeerConnState(String routerid, BgpPeerCfg.State state) {
+ BgpPeerCfg lspeer = this.bgpPeerTree.get(routerid);
if (lspeer != null) {
lspeer.setState(state);
@@ -232,21 +232,21 @@ public class BGPConfig implements BGPCfg {
}
@Override
- public BGPPeerCfg.State getPeerConnState(String routerid) {
- BGPPeerCfg lspeer = this.bgpPeerTree.get(routerid);
+ public BgpPeerCfg.State getPeerConnState(String routerid) {
+ BgpPeerCfg lspeer = this.bgpPeerTree.get(routerid);
if (lspeer != null) {
return lspeer.getState();
} else {
- return BGPPeerCfg.State.INVALID; //No instance
+ return BgpPeerCfg.State.INVALID; //No instance
}
}
@Override
public boolean isPeerConnectable(String routerid) {
- BGPPeerCfg lspeer = this.bgpPeerTree.get(routerid);
+ BgpPeerCfg lspeer = this.bgpPeerTree.get(routerid);
- if ((lspeer != null) && lspeer.getState().equals(BGPPeerCfg.State.IDLE)) {
+ if ((lspeer != null) && lspeer.getState().equals(BgpPeerCfg.State.IDLE)) {
return true;
}
@@ -254,21 +254,21 @@ public class BGPConfig implements BGPCfg {
}
@Override
- public TreeMap<String, BGPPeerCfg> getPeerTree() {
+ public TreeMap<String, BgpPeerCfg> getPeerTree() {
return this.bgpPeerTree;
}
@Override
- public TreeMap<String, BGPPeerCfg> displayPeers() {
+ public TreeMap<String, BgpPeerCfg> displayPeers() {
if (this.bgpPeerTree.isEmpty()) {
log.debug("There are no BGP peers");
} else {
- Set<Entry<String, BGPPeerCfg>> set = this.bgpPeerTree.entrySet();
- Iterator<Entry<String, BGPPeerCfg>> list = set.iterator();
- BGPPeerCfg lspeer;
+ Set<Entry<String, BgpPeerCfg>> set = this.bgpPeerTree.entrySet();
+ Iterator<Entry<String, BgpPeerCfg>> list = set.iterator();
+ BgpPeerCfg lspeer;
while (list.hasNext()) {
- Entry<String, BGPPeerCfg> me = list.next();
+ Entry<String, BgpPeerCfg> me = list.next();
lspeer = me.getValue();
log.debug("Peer neighbor IP :" + me.getKey());
log.debug(", AS Number : " + lspeer.getAsNumber());
@@ -280,10 +280,10 @@ public class BGPConfig implements BGPCfg {
}
@Override
- public BGPPeerCfg displayPeers(String routerid) {
+ public BgpPeerCfg displayPeers(String routerid) {
if (this.bgpPeerTree.isEmpty()) {
- log.debug("There are no BGP peers");
+ log.debug("There are no Bgp peers");
} else {
return this.bgpPeerTree.get(routerid);
}
@@ -312,7 +312,7 @@ public class BGPConfig implements BGPCfg {
@Override
public boolean isPeerConfigured(String routerid) {
- BGPPeerCfg lspeer = this.bgpPeerTree.get(routerid);
+ BgpPeerCfg lspeer = this.bgpPeerTree.get(routerid);
return (lspeer != null) ? true : false;
}
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpConnectPeerImpl.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpConnectPeerImpl.java
new file mode 100755
index 00000000..27db618d
--- /dev/null
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpConnectPeerImpl.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.onosproject.bgp.controller.impl;
+
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.netty.bootstrap.ClientBootstrap;
+import org.jboss.netty.channel.ChannelFuture;
+import org.jboss.netty.channel.ChannelFutureListener;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.onosproject.bgp.controller.BgpCfg;
+import org.onosproject.bgp.controller.BgpController;
+import org.onosproject.bgp.controller.BgpPeerCfg;
+import org.onosproject.bgp.controller.BgpConnectPeer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implements connection initiation to peer on peer configuration and manage channel using netty channel handler.
+ */
+public class BgpConnectPeerImpl implements BgpConnectPeer {
+ private static final Logger log = LoggerFactory.getLogger(BgpConnectPeerImpl.class);
+
+ private ScheduledExecutorService connectExecutor = null;
+ private final String peerHost;
+ private static final int RETRY_INTERVAL = 4;
+ private final int peerPort;
+ private int connectRetryCounter = 0;
+ private int connectRetryTime;
+ private ChannelPipelineFactory pfact;
+ private ClientBootstrap peerBootstrap;
+ private BgpCfg bgpconfig;
+
+ /**
+ * Initialize timer and initiate pipeline factory.
+ *
+ * @param bgpController parent BGP controller
+ * @param remoteHost remote host to connect
+ * @param remotePort remote port to connect
+ */
+ public BgpConnectPeerImpl(BgpController bgpController, String remoteHost, int remotePort) {
+
+ this.bgpconfig = bgpController.getConfig();
+ this.pfact = new BgpPipelineFactory(bgpController, false);
+ this.peerBootstrap = Controller.peerBootstrap();
+ this.peerBootstrap.setPipelineFactory(pfact);
+ this.peerHost = remoteHost;
+ this.peerPort = remotePort;
+ this.connectRetryTime = 0;
+ }
+
+ @Override
+ public void disconnectPeer() {
+ if (connectExecutor != null) {
+ connectExecutor.shutdown();
+ connectExecutor = null;
+ }
+ }
+
+ @Override
+ public void connectPeer() {
+ scheduleConnectionRetry(this.connectRetryTime);
+ }
+
+ /**
+ * Retry connection with exponential back-off mechanism.
+ *
+ * @param retryDelay retry delay
+ */
+ private void scheduleConnectionRetry(long retryDelay) {
+ if (this.connectExecutor == null) {
+ this.connectExecutor = Executors.newSingleThreadScheduledExecutor();
+ }
+ this.connectExecutor.schedule(new ConnectionRetry(), retryDelay, TimeUnit.MINUTES);
+ }
+
+ /**
+ * Implements BGP connection and manages connection to peer with back-off mechanism in case of failure.
+ */
+ class ConnectionRetry implements Runnable {
+ @Override
+ public void run() {
+ log.debug("Connect to peer {}", peerHost);
+
+ InetSocketAddress connectToSocket = new InetSocketAddress(peerHost, peerPort);
+
+ try {
+ bgpconfig.setPeerConnState(peerHost, BgpPeerCfg.State.CONNECT);
+ peerBootstrap.connect(connectToSocket).addListener(new ChannelFutureListener() {
+ @Override
+ public void operationComplete(ChannelFuture future) throws Exception {
+ if (!future.isSuccess()) {
+ bgpconfig.setPeerConnState(peerHost, BgpPeerCfg.State.ACTIVE);
+ connectRetryCounter++;
+ log.error("Connection failed, ConnectRetryCounter {} remote host {}", connectRetryCounter,
+ peerHost);
+ /*
+ * Reconnect to peer on failure is exponential till 4 mins, later on retry after every 4
+ * mins.
+ */
+ if (connectRetryTime < RETRY_INTERVAL) {
+ connectRetryTime = (connectRetryTime != 0) ? connectRetryTime * 2 : 1;
+ }
+ scheduleConnectionRetry(connectRetryTime);
+ } else {
+
+ connectRetryCounter++;
+ log.info("Connected to remote host {}, Connect Counter {}", peerHost, connectRetryCounter);
+ disconnectPeer();
+ return;
+ }
+ }
+ });
+ } catch (Exception e) {
+ log.info("Connect peer exception : " + e.toString());
+ disconnectPeer();
+ }
+ }
+ }
+}
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPControllerImpl.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpControllerImpl.java
index 35c31ab7..6a14e85c 100755
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPControllerImpl.java
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpControllerImpl.java
@@ -26,34 +26,32 @@ import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
-import org.onosproject.bgp.controller.BGPCfg;
-import org.onosproject.bgp.controller.BGPController;
-import org.onosproject.bgp.controller.BGPId;
-import org.onosproject.bgp.controller.BGPPeer;
-import org.onosproject.bgp.controller.BgpLinkListener;
+import org.onosproject.bgp.controller.BgpCfg;
+import org.onosproject.bgp.controller.BgpController;
+import org.onosproject.bgp.controller.BgpId;
+import org.onosproject.bgp.controller.BgpPeer;
import org.onosproject.bgp.controller.BgpNodeListener;
import org.onosproject.bgp.controller.BgpPeerManager;
-import org.onosproject.bgpio.exceptions.BGPParseException;
-import org.onosproject.bgpio.protocol.BGPMessage;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate = true)
@Service
-public class BGPControllerImpl implements BGPController {
+public class BgpControllerImpl implements BgpController {
- private static final Logger log = LoggerFactory.getLogger(BGPControllerImpl.class);
+ private static final Logger log = LoggerFactory.getLogger(BgpControllerImpl.class);
- protected ConcurrentHashMap<BGPId, BGPPeer> connectedPeers = new ConcurrentHashMap<BGPId, BGPPeer>();
+ protected ConcurrentHashMap<BgpId, BgpPeer> connectedPeers = new ConcurrentHashMap<BgpId, BgpPeer>();
- protected BGPPeerManagerImpl peerManager = new BGPPeerManagerImpl();
+ protected BgpPeerManagerImpl peerManager = new BgpPeerManagerImpl();
protected Set<BgpNodeListener> bgpNodeListener = new CopyOnWriteArraySet<>();
- protected Set<BgpLinkListener> bgpLinkListener = new CopyOnWriteArraySet<>();
final Controller ctrl = new Controller(this);
- private BGPConfig bgpconfig = new BGPConfig();
+ private BgpConfig bgpconfig = new BgpConfig();
@Activate
public void activate() {
@@ -70,12 +68,12 @@ public class BGPControllerImpl implements BGPController {
}
@Override
- public Iterable<BGPPeer> getPeers() {
+ public Iterable<BgpPeer> getPeers() {
return this.connectedPeers.values();
}
@Override
- public BGPPeer getPeer(BGPId bgpId) {
+ public BgpPeer getPeer(BgpId bgpId) {
return this.connectedPeers.get(bgpId);
}
@@ -95,27 +93,12 @@ public class BGPControllerImpl implements BGPController {
}
@Override
- public void addLinkListener(BgpLinkListener listener) {
- this.bgpLinkListener.add(listener);
- }
-
- @Override
- public void removeLinkListener(BgpLinkListener listener) {
- this.bgpLinkListener.remove(listener);
- }
-
- @Override
- public Set<BgpLinkListener> linkListener() {
- return bgpLinkListener;
- }
-
- @Override
- public void writeMsg(BGPId bgpId, BGPMessage msg) {
+ public void writeMsg(BgpId bgpId, BgpMessage msg) {
this.getPeer(bgpId).sendMessage(msg);
}
@Override
- public void processBGPPacket(BGPId bgpId, BGPMessage msg) throws BGPParseException {
+ public void processBGPPacket(BgpId bgpId, BgpMessage msg) throws BgpParseException {
switch (msg.getType()) {
case OPEN:
@@ -138,8 +121,8 @@ public class BGPControllerImpl implements BGPController {
@Override
public void closeConnectedPeers() {
- BGPPeer bgpPeer;
- for (BGPId id : this.connectedPeers.keySet()) {
+ BgpPeer bgpPeer;
+ for (BgpId id : this.connectedPeers.keySet()) {
bgpPeer = getPeer(id);
bgpPeer.disconnectPeer();
}
@@ -149,13 +132,13 @@ public class BGPControllerImpl implements BGPController {
* Implementation of an BGP Peer which is responsible for keeping track of connected peers and the state in which
* they are.
*/
- public class BGPPeerManagerImpl implements BgpPeerManager {
+ public class BgpPeerManagerImpl implements BgpPeerManager {
- private final Logger log = LoggerFactory.getLogger(BGPPeerManagerImpl.class);
+ private final Logger log = LoggerFactory.getLogger(BgpPeerManagerImpl.class);
private final Lock peerLock = new ReentrantLock();
@Override
- public boolean addConnectedPeer(BGPId bgpId, BGPPeer bgpPeer) {
+ public boolean addConnectedPeer(BgpId bgpId, BgpPeer bgpPeer) {
if (connectedPeers.get(bgpId) != null) {
this.log.error("Trying to add connectedPeer but found previous " + "value for bgp ip: {}",
@@ -169,7 +152,7 @@ public class BGPControllerImpl implements BGPController {
}
@Override
- public boolean isPeerConnected(BGPId bgpId) {
+ public boolean isPeerConnected(BgpId bgpId) {
if (connectedPeers.get(bgpId) == null) {
this.log.error("Is peer connected: bgpIp {}.", bgpId.toString());
return false;
@@ -179,12 +162,12 @@ public class BGPControllerImpl implements BGPController {
}
@Override
- public void removeConnectedPeer(BGPId bgpId) {
+ public void removeConnectedPeer(BgpId bgpId) {
connectedPeers.remove(bgpId);
}
@Override
- public BGPPeer getPeer(BGPId bgpId) {
+ public BgpPeer getPeer(BgpId bgpId) {
return connectedPeers.get(bgpId);
}
@@ -196,26 +179,35 @@ public class BGPControllerImpl implements BGPController {
* @param pktStats packet statistics.
* @return BGPPeer peer instance.
*/
- public BGPPeer getBGPPeerInstance(BGPController bgpController, BgpSessionInfoImpl sessionInfo,
- BGPPacketStatsImpl pktStats) {
- BGPPeer bgpPeer = new BGPPeerImpl(bgpController, sessionInfo, pktStats);
+ public BgpPeer getBgpPeerInstance(BgpController bgpController, BgpSessionInfoImpl sessionInfo,
+ BgpPacketStatsImpl pktStats) {
+ BgpPeer bgpPeer = new BgpPeerImpl(bgpController, sessionInfo, pktStats);
return bgpPeer;
}
}
+ /**
+ * Returns controller.
+ *
+ * @return controller
+ */
+ public Controller controller() {
+ return this.ctrl;
+ }
+
@Override
- public ConcurrentHashMap<BGPId, BGPPeer> connectedPeers() {
+ public ConcurrentHashMap<BgpId, BgpPeer> connectedPeers() {
return connectedPeers;
}
@Override
- public BGPPeerManagerImpl peerManager() {
+ public BgpPeerManagerImpl peerManager() {
return peerManager;
}
@Override
- public BGPCfg getConfig() {
+ public BgpCfg getConfig() {
return this.bgpconfig;
}
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPKeepAliveTimer.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpKeepAliveTimer.java
index 1c95804a..524ac4c1 100755
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPKeepAliveTimer.java
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpKeepAliveTimer.java
@@ -25,11 +25,11 @@ import org.slf4j.LoggerFactory;
/**
* Implement sending keepalive message to connected peer periodically based on negotiated holdtime.
*/
-public class BGPKeepAliveTimer {
+public class BgpKeepAliveTimer {
private Timer keepAliveTimer;
- private BGPChannelHandler handler;
- private static final Logger log = LoggerFactory.getLogger(BGPKeepAliveTimer.class);
+ private BgpChannelHandler handler;
+ private static final Logger log = LoggerFactory.getLogger(BgpKeepAliveTimer.class);
/**
* Gets keepalive timer object.
@@ -46,7 +46,7 @@ public class BGPKeepAliveTimer {
* @param h channel handler
* @param seconds time interval.
*/
- public BGPKeepAliveTimer(BGPChannelHandler h, int seconds) {
+ public BgpKeepAliveTimer(BgpChannelHandler h, int seconds) {
this.handler = h;
this.keepAliveTimer = new Timer();
this.keepAliveTimer.schedule(new SendKeepAlive(), 0, seconds * 1000);
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPMessageDecoder.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpMessageDecoder.java
index 636b78cc..431c6210 100755
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPMessageDecoder.java
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpMessageDecoder.java
@@ -22,20 +22,20 @@ import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.frame.FrameDecoder;
-import org.onosproject.bgpio.protocol.BGPMessage;
+import org.onosproject.bgpio.protocol.BgpMessage;
import org.onlab.util.HexDump;
-import org.onosproject.bgpio.protocol.BGPFactories;
-import org.onosproject.bgpio.protocol.BGPMessageReader;
-import org.onosproject.bgpio.types.BGPHeader;
+import org.onosproject.bgpio.protocol.BgpFactories;
+import org.onosproject.bgpio.protocol.BgpMessageReader;
+import org.onosproject.bgpio.types.BgpHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Decode an bgp message from a Channel, for use in a netty pipeline.
*/
-public class BGPMessageDecoder extends FrameDecoder {
+public class BgpMessageDecoder extends FrameDecoder {
- protected static final Logger log = LoggerFactory.getLogger(BGPMessageDecoder.class);
+ protected static final Logger log = LoggerFactory.getLogger(BgpMessageDecoder.class);
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
@@ -47,12 +47,12 @@ public class BGPMessageDecoder extends FrameDecoder {
HexDump.dump(buffer);
- BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader();
- List<BGPMessage> msgList = new LinkedList<BGPMessage>();
+ BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
+ List<BgpMessage> msgList = new LinkedList<BgpMessage>();
while (buffer.readableBytes() > 0) {
- BGPHeader bgpHeader = new BGPHeader();
- BGPMessage message = reader.readFrom(buffer, bgpHeader);
+ BgpHeader bgpHeader = new BgpHeader();
+ BgpMessage message = reader.readFrom(buffer, bgpHeader);
msgList.add(message);
}
return msgList;
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPMessageEncoder.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpMessageEncoder.java
index f0d38c3d..3e56d6ff 100755
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPMessageEncoder.java
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpMessageEncoder.java
@@ -22,7 +22,7 @@ import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
-import org.onosproject.bgpio.protocol.BGPMessage;
+import org.onosproject.bgpio.protocol.BgpMessage;
import org.onlab.util.HexDump;
import org.slf4j.Logger;
@@ -32,8 +32,8 @@ import org.slf4j.LoggerFactory;
* Encode an bgp message for output into a ChannelBuffer, for use in a
* netty pipeline.
*/
-public class BGPMessageEncoder extends OneToOneEncoder {
- protected static final Logger log = LoggerFactory.getLogger(BGPMessageEncoder.class);
+public class BgpMessageEncoder extends OneToOneEncoder {
+ protected static final Logger log = LoggerFactory.getLogger(BgpMessageEncoder.class);
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
@@ -44,12 +44,12 @@ public class BGPMessageEncoder extends OneToOneEncoder {
}
@SuppressWarnings("unchecked")
- List<BGPMessage> msglist = (List<BGPMessage>) msg;
+ List<BgpMessage> msglist = (List<BgpMessage>) msg;
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
log.debug("SENDING MESSAGE");
- for (BGPMessage pm : msglist) {
+ for (BgpMessage pm : msglist) {
pm.writeTo(buf);
}
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPacketStatsImpl.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpPacketStatsImpl.java
index 09f4d452..7494c814 100755
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPacketStatsImpl.java
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpPacketStatsImpl.java
@@ -15,7 +15,7 @@
*/
package org.onosproject.bgp.controller.impl;
-import org.onosproject.bgp.controller.BGPPacketStats;
+import org.onosproject.bgp.controller.BgpPacketStats;
/**
* A representation of a packet context which allows any provider
@@ -23,7 +23,7 @@ import org.onosproject.bgp.controller.BGPPacketStats;
* event if blocked has been called. This packet context can be used
* to react to the packet in event with a packet out.
*/
-public class BGPPacketStatsImpl implements BGPPacketStats {
+public class BgpPacketStatsImpl implements BgpPacketStats {
private int inPacketCount;
private int outPacketCount;
@@ -33,7 +33,7 @@ public class BGPPacketStatsImpl implements BGPPacketStats {
/**
* Resets parameter.
*/
- public BGPPacketStatsImpl() {
+ public BgpPacketStatsImpl() {
this.inPacketCount = 0;
this.outPacketCount = 0;
this.wrongPacketCount = 0;
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerConfig.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpPeerConfig.java
index 14a68cf6..a8eaee3c 100755
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerConfig.java
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpPeerConfig.java
@@ -17,12 +17,12 @@ package org.onosproject.bgp.controller.impl;
import org.onlab.packet.Ip4Address;
import org.onosproject.bgp.controller.BgpConnectPeer;
-import org.onosproject.bgp.controller.BGPPeerCfg;
+import org.onosproject.bgp.controller.BgpPeerCfg;
/**
* BGP Peer configuration information.
*/
-public class BGPPeerConfig implements BGPPeerCfg {
+public class BgpPeerConfig implements BgpPeerCfg {
private int asNumber;
private short holdTime;
private boolean isIBgp;
@@ -34,7 +34,7 @@ public class BGPPeerConfig implements BGPPeerCfg {
/**
* Constructor to initialize the values.
*/
- BGPPeerConfig() {
+ BgpPeerConfig() {
state = State.IDLE;
selfInitiated = false;
}
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpPeerImpl.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpPeerImpl.java
new file mode 100644
index 00000000..57a924a8
--- /dev/null
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpPeerImpl.java
@@ -0,0 +1,297 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.bgp.controller.impl;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.util.Collections;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.concurrent.RejectedExecutionException;
+
+import org.jboss.netty.channel.Channel;
+import org.onlab.packet.IpAddress;
+import org.onosproject.bgp.controller.BgpController;
+import org.onosproject.bgp.controller.BgpPeer;
+import org.onosproject.bgp.controller.BgpSessionInfo;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpFactories;
+import org.onosproject.bgpio.protocol.BgpFactory;
+import org.onosproject.bgpio.protocol.BgpLSNlri;
+import org.onosproject.bgpio.protocol.BgpMessage;
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.types.MpReachNlri;
+import org.onosproject.bgpio.types.MpUnReachNlri;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * BGPPeerImpl implements BGPPeer, maintains peer information and store updates in RIB .
+ */
+public class BgpPeerImpl implements BgpPeer {
+
+ protected final Logger log = LoggerFactory.getLogger(BgpPeerImpl.class);
+
+ private static final String SHUTDOWN_MSG = "Worker has already been shutdown";
+
+ private BgpController bgpController;
+ private Channel channel;
+ protected String channelId;
+ private boolean connected;
+ protected boolean isHandShakeComplete = false;
+ private BgpSessionInfo sessionInfo;
+ private BgpPacketStatsImpl pktStats;
+ private AdjRibIn adjRib;
+ private VpnAdjRibIn vpnAdjRib;
+
+
+ @Override
+ public BgpSessionInfo sessionInfo() {
+ return sessionInfo;
+ }
+
+ /**
+ * Initialize peer.
+ *
+ *@param bgpController controller instance
+ *@param sessionInfo bgp session info
+ *@param pktStats packet statistics
+ */
+ public BgpPeerImpl(BgpController bgpController, BgpSessionInfo sessionInfo, BgpPacketStatsImpl pktStats) {
+ this.bgpController = bgpController;
+ this.sessionInfo = sessionInfo;
+ this.pktStats = pktStats;
+ this.adjRib = new AdjRibIn();
+ this.vpnAdjRib = new VpnAdjRibIn();
+ }
+
+
+ @Override
+ public void buildAdjRibIn(List<BgpValueType> pathAttr) throws BgpParseException {
+ ListIterator<BgpValueType> iterator = pathAttr.listIterator();
+ while (iterator.hasNext()) {
+ BgpValueType attr = iterator.next();
+ if (attr instanceof MpReachNlri) {
+ List<BgpLSNlri> nlri = ((MpReachNlri) attr).mpReachNlri();
+ callAdd(this, nlri, pathAttr);
+ }
+ if (attr instanceof MpUnReachNlri) {
+ List<BgpLSNlri> nlri = ((MpUnReachNlri) attr).mpUnReachNlri();
+ callRemove(this, nlri);
+ }
+ }
+ }
+
+ /**
+ * Updates NLRI identifier node in a tree separately based on afi and safi.
+ *
+ * @param peerImpl BGP peer instance
+ * @param nlri MpReachNlri path attribute
+ * @param pathAttr list of BGP path attributes
+ * @throws BgpParseException throws exception
+ */
+ public void callAdd(BgpPeerImpl peerImpl, List<BgpLSNlri> nlri, List<BgpValueType> pathAttr)
+ throws BgpParseException {
+ ListIterator<BgpLSNlri> listIterator = nlri.listIterator();
+ while (listIterator.hasNext()) {
+ BgpLSNlri nlriInfo = listIterator.next();
+ if (nlriInfo instanceof BgpNodeLSNlriVer4) {
+ PathAttrNlriDetails details = setPathAttrDetails(nlriInfo, pathAttr);
+ if (!((BgpNodeLSNlriVer4) nlriInfo).isVpnPresent()) {
+ adjRib.add(nlriInfo, details);
+ } else {
+ vpnAdjRib.addVpn(nlriInfo, details, ((BgpNodeLSNlriVer4) nlriInfo).getRouteDistinguisher());
+ }
+ } else if (nlriInfo instanceof BgpLinkLsNlriVer4) {
+ PathAttrNlriDetails details = setPathAttrDetails(nlriInfo, pathAttr);
+ if (!((BgpLinkLsNlriVer4) nlriInfo).isVpnPresent()) {
+ adjRib.add(nlriInfo, details);
+ } else {
+ vpnAdjRib.addVpn(nlriInfo, details, ((BgpLinkLsNlriVer4) nlriInfo).getRouteDistinguisher());
+ }
+ } else if (nlriInfo instanceof BgpPrefixIPv4LSNlriVer4) {
+ PathAttrNlriDetails details = setPathAttrDetails(nlriInfo, pathAttr);
+ if (!((BgpPrefixIPv4LSNlriVer4) nlriInfo).isVpnPresent()) {
+ adjRib.add(nlriInfo, details);
+ } else {
+ vpnAdjRib.addVpn(nlriInfo, details, ((BgpPrefixIPv4LSNlriVer4) nlriInfo).getRouteDistinguisher());
+ }
+ }
+ }
+ }
+
+ /**
+ * Sets BGP path attribute and NLRI details.
+ *
+ * @param nlriInfo MpReachNlri path attribute
+ * @param pathAttr list of BGP path attributes
+ * @return details object of PathAttrNlriDetails
+ * @throws BgpParseException throw exception
+ */
+ public PathAttrNlriDetails setPathAttrDetails(BgpLSNlri nlriInfo, List<BgpValueType> pathAttr)
+ throws BgpParseException {
+ PathAttrNlriDetails details = new PathAttrNlriDetails();
+ details.setProtocolID(nlriInfo.getProtocolId());
+ details.setIdentifier(nlriInfo.getIdentifier());
+ details.setPathAttribute(pathAttr);
+ return details;
+ }
+
+ /**
+ * Removes NLRI identifier node in a tree separately based on afi and safi.
+ *
+ * @param peerImpl BGP peer instance
+ * @param nlri NLRI information
+ */
+ public void callRemove(BgpPeerImpl peerImpl, List<BgpLSNlri> nlri) {
+ ListIterator<BgpLSNlri> listIterator = nlri.listIterator();
+ while (listIterator.hasNext()) {
+ BgpLSNlri nlriInfo = listIterator.next();
+ if (nlriInfo instanceof BgpNodeLSNlriVer4) {
+ if (!((BgpNodeLSNlriVer4) nlriInfo).isVpnPresent()) {
+ adjRib.remove(nlriInfo);
+ } else {
+ vpnAdjRib.removeVpn(nlriInfo, ((BgpNodeLSNlriVer4) nlriInfo).getRouteDistinguisher());
+ }
+ } else if (nlriInfo instanceof BgpLinkLsNlriVer4) {
+ if (!((BgpLinkLsNlriVer4) nlriInfo).isVpnPresent()) {
+ adjRib.remove(nlriInfo);
+ } else {
+ vpnAdjRib.removeVpn(nlriInfo, ((BgpLinkLsNlriVer4) nlriInfo).getRouteDistinguisher());
+ }
+ } else if (nlriInfo instanceof BgpPrefixIPv4LSNlriVer4) {
+ if (!((BgpPrefixIPv4LSNlriVer4) nlriInfo).isVpnPresent()) {
+ adjRib.remove(nlriInfo);
+ } else {
+ vpnAdjRib.removeVpn(nlriInfo, ((BgpPrefixIPv4LSNlriVer4) nlriInfo).getRouteDistinguisher());
+ }
+ }
+ }
+ }
+
+ /**
+ * Return the adjacency RIB-IN.
+ *
+ * @return adjRib the adjacency RIB-IN
+ */
+ public AdjRibIn adjRib() {
+ return adjRib;
+ }
+
+ /**
+ * Return the adjacency RIB-IN with VPN.
+ *
+ * @return vpnAdjRib the adjacency RIB-IN with VPN
+ */
+ public VpnAdjRibIn vpnAdjRib() {
+ return vpnAdjRib;
+ }
+
+ // ************************
+ // Channel related
+ // ************************
+
+ @Override
+ public final void disconnectPeer() {
+ this.channel.close();
+ }
+
+ @Override
+ public final void sendMessage(BgpMessage m) {
+ log.debug("Sending message to {}", channel.getRemoteAddress());
+ try {
+ channel.write(Collections.singletonList(m));
+ this.pktStats.addOutPacket();
+ } catch (RejectedExecutionException e) {
+ log.warn(e.getMessage());
+ if (!e.getMessage().contains(SHUTDOWN_MSG)) {
+ throw e;
+ }
+ }
+ }
+
+ @Override
+ public final void sendMessage(List<BgpMessage> msgs) {
+ try {
+ channel.write(msgs);
+ this.pktStats.addOutPacket(msgs.size());
+ } catch (RejectedExecutionException e) {
+ log.warn(e.getMessage());
+ if (!e.getMessage().contains(SHUTDOWN_MSG)) {
+ throw e;
+ }
+ }
+ }
+
+ @Override
+ public final boolean isConnected() {
+ return this.connected;
+ }
+
+ @Override
+ public final void setConnected(boolean connected) {
+ this.connected = connected;
+ };
+
+ @Override
+ public final void setChannel(Channel channel) {
+ this.channel = channel;
+ final SocketAddress address = channel.getRemoteAddress();
+ if (address instanceof InetSocketAddress) {
+ final InetSocketAddress inetAddress = (InetSocketAddress) address;
+ final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress());
+ if (ipAddress.isIp4()) {
+ channelId = ipAddress.toString() + ':' + inetAddress.getPort();
+ } else {
+ channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort();
+ }
+ }
+ };
+
+ @Override
+ public final Channel getChannel() {
+ return this.channel;
+ };
+
+ @Override
+ public String channelId() {
+ return channelId;
+ }
+
+ @Override
+ public BgpFactory factory() {
+ return BgpFactories.getFactory(sessionInfo.remoteBgpVersion());
+ }
+
+ @Override
+ public boolean isHandshakeComplete() {
+ return isHandShakeComplete;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("channel", channelId())
+ .add("BgpId", sessionInfo().remoteBgpId()).toString();
+ }
+}
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPipelineFactory.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpPipelineFactory.java
index e6f09f20..28e1041c 100755
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPipelineFactory.java
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpPipelineFactory.java
@@ -23,18 +23,18 @@ import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
import org.jboss.netty.util.ExternalResourceReleasable;
import org.jboss.netty.util.HashedWheelTimer;
import org.jboss.netty.util.Timer;
-import org.onosproject.bgp.controller.BGPController;
+import org.onosproject.bgp.controller.BgpController;
/**
* Creates a ChannelPipeline for a server-side bgp channel.
*/
-public class BGPPipelineFactory
+public class BgpPipelineFactory
implements ChannelPipelineFactory, ExternalResourceReleasable {
static final Timer TIMER = new HashedWheelTimer();
protected ReadTimeoutHandler readTimeoutHandler;
private boolean isBgpServ;
- private BGPController bgpController;
+ private BgpController bgpController;
/**
* Constructor to initialize the values.
@@ -42,7 +42,7 @@ public class BGPPipelineFactory
* @param bgpController parent controller
* @param isBgpServ if it is a server or remote peer
*/
- public BGPPipelineFactory(BGPController bgpController, boolean isBgpServ) {
+ public BgpPipelineFactory(BgpController bgpController, boolean isBgpServ) {
super();
this.isBgpServ = isBgpServ;
this.bgpController = bgpController;
@@ -52,11 +52,11 @@ public class BGPPipelineFactory
@Override
public ChannelPipeline getPipeline() throws Exception {
- BGPChannelHandler handler = new BGPChannelHandler(bgpController);
+ BgpChannelHandler handler = new BgpChannelHandler(bgpController);
ChannelPipeline pipeline = Channels.pipeline();
- pipeline.addLast("bgpmessagedecoder", new BGPMessageDecoder());
- pipeline.addLast("bgpmessageencoder", new BGPMessageEncoder());
+ pipeline.addLast("bgpmessagedecoder", new BgpMessageDecoder());
+ pipeline.addLast("bgpmessageencoder", new BgpMessageEncoder());
pipeline.addLast("holdTime", readTimeoutHandler);
if (isBgpServ) {
pipeline.addLast("PassiveHandler", handler);
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpSelectionAlgo.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpSelectionAlgo.java
new file mode 100644
index 00000000..d3065f43
--- /dev/null
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpSelectionAlgo.java
@@ -0,0 +1,242 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgp.controller.impl;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib;
+import org.onosproject.bgpio.types.AsPath;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.types.LocalPref;
+import org.onosproject.bgpio.types.Med;
+import org.onosproject.bgpio.types.Origin;
+import org.onosproject.bgpio.types.Origin.ORIGINTYPE;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implementation of BGP best path Selection process.
+ */
+public final class BgpSelectionAlgo implements Comparator<PathAttrNlriDetailsLocalRib> {
+ private static final Logger log = LoggerFactory.getLogger(BgpSelectionAlgo.class);
+ LocalPref obj1LocPref = null;
+ AsPath obj1Aspath = null;
+ Origin obj1Origin = null;
+ Med obj1Med = null;
+ LocalPref obj2LocPref = null;
+ AsPath obj2Aspath = null;
+ Origin obj2Origin = null;
+ Med obj2Med = null;
+
+ @Override
+ public int compare(PathAttrNlriDetailsLocalRib pathNlriDetails1, PathAttrNlriDetailsLocalRib pathNlriDetails2) {
+ if (pathNlriDetails1 == null) {
+ return -1;
+ }
+ if (pathNlriDetails2 == null) {
+ return 1;
+ }
+ if (pathNlriDetails1.equals(pathNlriDetails2)) {
+ return 0;
+ }
+
+ List<BgpValueType> o1 = pathNlriDetails1.localRibNlridetails().pathAttributes();
+ List<BgpValueType> o2 = pathNlriDetails2.localRibNlridetails().pathAttributes();
+ ListIterator<BgpValueType> listIteratorObj1 = o1.listIterator();
+ ListIterator<BgpValueType> listIteratorObj2 = o2.listIterator();
+ storeAttr(listIteratorObj1, listIteratorObj2);
+
+ // prefer attribute with higher local preference
+ if (obj1LocPref != null || obj2LocPref != null && (obj1LocPref != null && !obj1LocPref.equals(obj2LocPref))) {
+ return compareLocalPref(obj1LocPref, obj2LocPref);
+ }
+
+ // prefer attribute with shortest Aspath
+ if (!obj1Aspath.equals(obj2Aspath)) {
+ Integer obj1Size = countASSize(obj1Aspath);
+ Integer obj2Size = countASSize(obj2Aspath);
+ if (obj1Size != obj2Size) {
+ return compareAsPath(obj1Size, obj2Size);
+ }
+ }
+
+ // prefer attribute with lowest origin type
+ if (!obj1Origin.equals(obj2Origin)) {
+ return compareOrigin(obj1Origin, obj2Origin);
+ }
+
+ // prefer attribute with lowest MED
+ if (obj1Med != null || obj2Med != null && (obj1Med != null && !obj1Med.equals(obj2Med))) {
+ return compareMed(obj1Med, obj2Med);
+ }
+
+ if ((pathNlriDetails1 != null || pathNlriDetails2 != null) && (pathNlriDetails1 != null && !pathNlriDetails1
+ .equals(pathNlriDetails2))) {
+ return comparePeerDetails(pathNlriDetails1, pathNlriDetails2);
+ }
+ return 0;
+ }
+
+ /**
+ * Compares local preference of two objects and returns object with higher preference.
+ *
+ * @param obj1LocPref local preference object1
+ * @param obj2LocPref local preference object2
+ * @return object with higher preference
+ */
+ int compareLocalPref(LocalPref obj1LocPref, LocalPref obj2LocPref) {
+ return ((Integer) (obj1LocPref.localPref())).compareTo((Integer) (obj2LocPref.localPref()));
+ }
+
+ /**
+ * Compares AsPath of two objects and returns object with shortest AsPath.
+ *
+ * @param obj1Size object1 AS count
+ * @param obj2Size object2 AS count
+ * @return
+ */
+ int compareAsPath(Integer obj1Size, Integer obj2Size) {
+ return obj1Size.compareTo(obj2Size);
+ }
+
+ /**
+ * Compare Origin of two objects and returns object with lowest origin value.
+ *
+ * @param obj1Origin Origin object1
+ * @param obj2Origin Origin object1
+ * @return object with lowest origin value
+ */
+ int compareOrigin(Origin obj1Origin, Origin obj2Origin) {
+ if (obj1Origin.origin() == ORIGINTYPE.IGP) {
+ return 1;
+ }
+ if (obj2Origin.origin() == ORIGINTYPE.IGP) {
+ return -1;
+ }
+ if (obj1Origin.origin() == ORIGINTYPE.EGP) {
+ return 1;
+ } else {
+ return -1;
+ }
+ }
+
+ /**
+ * Compare Med of two objects and returns object with lowestMed value.
+ *
+ * @param obj1Med Med object1
+ * @param obj2Med Med object2
+ * @return returns object with lowestMed value
+ */
+ int compareMed(Med obj1Med, Med obj2Med) {
+ return ((Integer) (obj2Med.med())).compareTo((Integer) (obj1Med.med()));
+ }
+
+ /**
+ * Compares EBGP over IBGP, BGP identifier value and peer address.
+ *
+ * @param pathNlriDetails1 PathAttrNlriDetailsLocalRib object1
+ * @param pathNlriDetails2 PathAttrNlriDetailsLocalRib object2
+ * @return object which as EBGP over IBGP, lowest BGP identifier value and lowest peer address
+ */
+ int comparePeerDetails(PathAttrNlriDetailsLocalRib pathNlriDetails1, PathAttrNlriDetailsLocalRib pathNlriDetails2) {
+ // consider EBGP over IBGP
+ if (pathNlriDetails1.isLocalRibIbgpSession() != pathNlriDetails2.isLocalRibIbgpSession()) {
+ if (pathNlriDetails1 == null || pathNlriDetails1.isLocalRibIbgpSession()) {
+ return -1;
+ }
+ if (pathNlriDetails2 == null || pathNlriDetails2.isLocalRibIbgpSession()) {
+ return 1;
+ }
+ }
+ // prefer lowest BGP identifier value.
+ if (pathNlriDetails1.localRibIdentifier() != pathNlriDetails2.localRibIdentifier()) {
+ return ((Integer) pathNlriDetails2.localRibIdentifier())
+ .compareTo(pathNlriDetails1.localRibIdentifier());
+ }
+ //prefer lowest peer address
+ if (pathNlriDetails1.localRibIpAddress() != pathNlriDetails2.localRibIpAddress()) {
+ return pathNlriDetails2.localRibIpAddress().compareTo(pathNlriDetails1.localRibIpAddress());
+ }
+ return 0;
+ }
+
+ /**
+ * Returns ASes count of AsPath attribute , if AS_SET is present then count as 1.
+ *
+ * @param aspath object of AsPath
+ * @return count of ASes
+ */
+ Integer countASSize(AsPath aspath) {
+ boolean isASSet = false;
+ int count = 0;
+ if (!aspath.asPathSet().isEmpty()) {
+ isASSet = true;
+ }
+ if (!aspath.asPathSeq().isEmpty()) {
+ count = aspath.asPathSeq().size();
+ }
+ return isASSet ? ++count : count;
+ }
+
+ /**
+ * Stores BGP basic attributes of two objects.
+ *
+ * @param listIteratorObj1 list iterator of object1
+ * @param listIteratorObj2 list iterator of object2
+ */
+ void storeAttr(ListIterator<BgpValueType> listIteratorObj1, ListIterator<BgpValueType> listIteratorObj2) {
+ while (listIteratorObj1.hasNext()) {
+ BgpValueType pathAttributeObj1 = listIteratorObj1.next();
+ switch (pathAttributeObj1.getType()) {
+ case LocalPref.LOCAL_PREF_TYPE:
+ obj1LocPref = (LocalPref) pathAttributeObj1;
+ break;
+ case AsPath.ASPATH_TYPE:
+ obj1Aspath = (AsPath) pathAttributeObj1;
+ break;
+ case Origin.ORIGIN_TYPE:
+ obj1Origin = (Origin) pathAttributeObj1;
+ break;
+ case Med.MED_TYPE:
+ obj1Med = (Med) pathAttributeObj1;
+ break;
+ default:
+ log.debug("Got other type, Not required: " + pathAttributeObj1.getType());
+ }
+ }
+ while (listIteratorObj2.hasNext()) {
+ BgpValueType pathAttributeObj2 = listIteratorObj2.next();
+ switch (pathAttributeObj2.getType()) {
+ case LocalPref.LOCAL_PREF_TYPE:
+ obj2LocPref = (LocalPref) pathAttributeObj2;
+ break;
+ case AsPath.ASPATH_TYPE:
+ obj2Aspath = (AsPath) pathAttributeObj2;
+ break;
+ case Origin.ORIGIN_TYPE:
+ obj2Origin = (Origin) pathAttributeObj2;
+ break;
+ case Med.MED_TYPE:
+ obj2Med = (Med) pathAttributeObj2;
+ break;
+ default:
+ log.debug("Got other type, Not required: " + pathAttributeObj2.getType());
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpSessionInfoImpl.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpSessionInfoImpl.java
new file mode 100755
index 00000000..33623dc2
--- /dev/null
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpSessionInfoImpl.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package org.onosproject.bgp.controller.impl;
+
+import org.onosproject.bgp.controller.BgpId;
+import org.onosproject.bgp.controller.BgpSessionInfo;
+import org.onosproject.bgpio.protocol.BgpVersion;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class maintains BGP peer session info.
+ */
+public class BgpSessionInfoImpl implements BgpSessionInfo {
+
+ protected final Logger log = LoggerFactory.getLogger(BgpSessionInfoImpl.class);
+ private BgpId remoteBgpId;
+ private BgpVersion remoteBgpVersion;
+ private long remoteBgpASNum;
+ private short remoteBgpholdTime;
+ private int remoteBgpIdentifier;
+ private short negotiatedholdTime;
+ private boolean isIbgpSession;
+
+ /**
+ * Initialize session info.
+ *
+ *@param remoteBgpId remote peer id
+ *@param remoteBgpVersion remote peer version
+ *@param remoteBgpASNum remote peer AS number
+ *@param remoteBgpholdTime remote peer hold time
+ *@param remoteBgpIdentifier remote peer identifier
+ *@param negotiatedholdTime negotiated hold time
+ *@param isIbgpSession session type ibgp/ebgp
+ */
+ public BgpSessionInfoImpl(BgpId remoteBgpId, BgpVersion remoteBgpVersion, long remoteBgpASNum,
+ short remoteBgpholdTime, int remoteBgpIdentifier, short negotiatedholdTime,
+ boolean isIbgpSession) {
+ this.remoteBgpId = remoteBgpId;
+ this.remoteBgpVersion = remoteBgpVersion;
+ this.remoteBgpASNum = remoteBgpASNum;
+ this.remoteBgpholdTime = remoteBgpholdTime;
+ this.remoteBgpIdentifier = remoteBgpIdentifier;
+ this.negotiatedholdTime = negotiatedholdTime;
+ this.isIbgpSession = isIbgpSession;
+ }
+
+ @Override
+ public boolean isIbgpSession() {
+ return isIbgpSession;
+ }
+
+ @Override
+ public short negotiatedholdTime() {
+ return negotiatedholdTime;
+ }
+
+ @Override
+ public BgpId remoteBgpId() {
+ return remoteBgpId;
+ }
+
+ @Override
+ public BgpVersion remoteBgpVersion() {
+ return remoteBgpVersion;
+ }
+
+ @Override
+ public long remoteBgpASNum() {
+ return remoteBgpASNum;
+ }
+
+ @Override
+ public short remoteBgpHoldTime() {
+ return remoteBgpholdTime;
+ }
+
+ @Override
+ public int remoteBgpIdentifier() {
+ return remoteBgpIdentifier;
+ }
+}
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/Controller.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/Controller.java
index 017c39e5..f02cee8a 100755
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/Controller.java
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/Controller.java
@@ -26,15 +26,16 @@ import java.util.concurrent.Executors;
import org.jboss.netty.bootstrap.ClientBootstrap;
import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.group.ChannelGroup;
import org.jboss.netty.channel.group.DefaultChannelGroup;
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
-import org.onosproject.bgp.controller.BGPController;
-import org.onosproject.bgpio.protocol.BGPFactories;
-import org.onosproject.bgpio.protocol.BGPFactory;
-import org.onosproject.bgpio.protocol.BGPVersion;
+import org.onosproject.bgp.controller.BgpController;
+import org.onosproject.bgpio.protocol.BgpFactories;
+import org.onosproject.bgpio.protocol.BgpFactory;
+import org.onosproject.bgpio.protocol.BgpVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,12 +47,15 @@ public class Controller {
private static final Logger log = LoggerFactory.getLogger(Controller.class);
- private static final BGPFactory FACTORY4 = BGPFactories.getFactory(BGPVersion.BGP_4);
+ private static final BgpFactory FACTORY4 = BgpFactories.getFactory(BgpVersion.BGP_4);
private ChannelGroup cg;
+ public Channel serverChannel;
// Configuration options
private static final short BGP_PORT_NUM = 179;
+ private static final short PORT_NUM_ZERO = 0;
+ private static boolean isPortNumSet = false;
private final int workerThreads = 16;
private final int peerWorkerThreads = 16;
@@ -61,7 +65,7 @@ public class Controller {
private NioServerSocketChannelFactory serverExecFactory;
private NioClientSocketChannelFactory peerExecFactory;
private static ClientBootstrap peerBootstrap;
- private BGPController bgpController;
+ private BgpController bgpController;
// Perf. related configuration
private static final int SEND_BUFFER_SIZE = 4 * 1024 * 1024;
@@ -71,7 +75,7 @@ public class Controller {
*
* @param bgpController bgp controller instance
*/
- public Controller(BGPController bgpController) {
+ public Controller(BgpController bgpController) {
this.bgpController = bgpController;
}
@@ -80,7 +84,7 @@ public class Controller {
*
* @return instance of factory version
*/
- static BGPFactory getBGPMessageFactory4() {
+ static BgpFactory getBgpMessageFactory4() {
return FACTORY4;
}
@@ -114,12 +118,13 @@ public class Controller {
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);
- ChannelPipelineFactory pfact = new BGPPipelineFactory(bgpController, true);
+ ChannelPipelineFactory pfact = new BgpPipelineFactory(bgpController, true);
bootstrap.setPipelineFactory(pfact);
InetSocketAddress sa = new InetSocketAddress(getBgpPortNum());
cg = new DefaultChannelGroup();
- cg.add(bootstrap.bind(sa));
+ serverChannel = bootstrap.bind(sa);
+ cg.add(serverChannel);
log.info("Listening for Peer connection on {}", sa);
} catch (Exception e) {
throw new RuntimeException(e);
@@ -234,6 +239,16 @@ public class Controller {
* @return port number
*/
public static short getBgpPortNum() {
+ if (isPortNumSet) {
+ return PORT_NUM_ZERO;
+ }
return BGP_PORT_NUM;
}
+
+ /**
+ * sets the isPortNumSet as true.
+ */
+ public void setBgpPortNum() {
+ isPortNumSet = true;
+ }
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/VpnAdjRibIn.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/VpnAdjRibIn.java
new file mode 100644
index 00000000..8a9ea91c
--- /dev/null
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/VpnAdjRibIn.java
@@ -0,0 +1,209 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.bgp.controller.impl;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.onosproject.bgpio.protocol.BgpLSNlri;
+import org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier;
+import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier;
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier;
+import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails;
+import org.onosproject.bgpio.types.RouteDistinguisher;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implementation of Adj-RIB-In with VPN for each peer.
+ */
+public class VpnAdjRibIn {
+ private Map<BgpNodeLSIdentifier, PathAttrNlriDetails> nodeTree = new TreeMap<>();
+ private Map<BgpLinkLSIdentifier, PathAttrNlriDetails> linkTree = new TreeMap<>();
+ private Map<BgpPrefixLSIdentifier, PathAttrNlriDetails> prefixTree = new TreeMap<>();
+
+ private Map<RouteDistinguisher, Map<BgpNodeLSIdentifier, PathAttrNlriDetails>> vpnNodeTree
+ = new TreeMap<>();
+ private Map<RouteDistinguisher, Map<BgpLinkLSIdentifier, PathAttrNlriDetails>> vpnLinkTree
+ = new TreeMap<>();
+ private Map<RouteDistinguisher, Map<BgpPrefixLSIdentifier, PathAttrNlriDetails>> vpnPrefixTree
+ = new TreeMap<>();
+ /**
+ * Returns the adjacency node.
+ *
+ * @return node adjacency RIB node
+ */
+ public Map<BgpNodeLSIdentifier, PathAttrNlriDetails> nodeTree() {
+ return nodeTree;
+ }
+
+ /**
+ * Returns the adjacency link.
+ *
+ * @return link adjacency RIB node
+ */
+ public Map<BgpLinkLSIdentifier, PathAttrNlriDetails> linkTree() {
+ return linkTree;
+ }
+
+ /**
+ * Returns the adjacency prefix.
+ *
+ * @return prefix adjacency RIB node
+ */
+ public Map<BgpPrefixLSIdentifier, PathAttrNlriDetails> prefixTree() {
+ return prefixTree;
+ }
+
+ /**
+ * Returns the adjacency vpnNode.
+ *
+ * @return vpnNode adjacency RIB node
+ */
+ public Map<RouteDistinguisher, Map<BgpNodeLSIdentifier, PathAttrNlriDetails>> vpnNodeTree() {
+ return vpnNodeTree;
+ }
+
+ /**
+ * Returns the adjacency vpnLink.
+ *
+ * @return vpnLink adjacency RIB node
+ */
+ public Map<RouteDistinguisher, Map<BgpLinkLSIdentifier, PathAttrNlriDetails>> vpnLinkTree() {
+ return vpnLinkTree;
+ }
+
+ /**
+ * Returns the adjacency vpnPrefix.
+ *
+ * @return vpnPrefix adjacency RIB node
+ */
+ public Map<RouteDistinguisher, Map<BgpPrefixLSIdentifier, PathAttrNlriDetails>> vpnPrefixTree() {
+ return vpnPrefixTree;
+ }
+
+ /**
+ * Update vpn nlri identifier into the tree if nlri identifier exists in tree otherwise add this to the tree.
+ *
+ * @param nlri NLRI info
+ * @param details has pathattribute , protocolID and identifier
+ */
+ public void add(BgpLSNlri nlri, PathAttrNlriDetails details) {
+ if (nlri instanceof BgpNodeLSNlriVer4) {
+ BgpNodeLSIdentifier nodeLSIdentifier = ((BgpNodeLSNlriVer4) nlri).getLocalNodeDescriptors();
+ if (nodeTree.containsKey(nodeLSIdentifier)) {
+ nodeTree.replace(nodeLSIdentifier, details);
+ } else {
+ nodeTree.put(nodeLSIdentifier, details);
+ }
+ } else if (nlri instanceof BgpLinkLsNlriVer4) {
+ BgpLinkLSIdentifier linkLSIdentifier = ((BgpLinkLsNlriVer4) nlri).getLinkIdentifier();
+ if (linkTree.containsKey(linkLSIdentifier)) {
+ linkTree.replace(linkLSIdentifier, details);
+ } else {
+ linkTree.put(linkLSIdentifier, details);
+ }
+ } else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) {
+ BgpPrefixLSIdentifier prefixIdentifier = ((BgpPrefixIPv4LSNlriVer4) nlri).getPrefixIdentifier();
+ if (prefixTree.containsKey(prefixIdentifier)) {
+ prefixTree.replace(prefixIdentifier, details);
+ } else {
+ prefixTree.put(prefixIdentifier, details);
+ }
+ }
+ }
+
+ /**
+ * Update nlri identifier mapped with route distinguisher if it exists in tree otherwise add nlri infomation mapped
+ * to respective route distinguisher in tree.
+ *
+ * @param nlri NLRI info
+ * @param details has pathattribute , protocolID and identifier
+ * @param routeDistinguisher unique for for each vpn
+ */
+ public void addVpn(BgpLSNlri nlri, PathAttrNlriDetails details, RouteDistinguisher routeDistinguisher) {
+ add(nlri, details);
+ if (nlri instanceof BgpNodeLSNlriVer4) {
+ if (!vpnNodeTree.containsKey(routeDistinguisher)) {
+ vpnNodeTree.put(routeDistinguisher, nodeTree);
+ }
+ } else if (nlri instanceof BgpLinkLsNlriVer4) {
+ if (!vpnLinkTree.containsKey(routeDistinguisher)) {
+ vpnLinkTree.put(routeDistinguisher, linkTree);
+ }
+ } else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) {
+ if (!vpnPrefixTree.containsKey(routeDistinguisher)) {
+ vpnPrefixTree.put(routeDistinguisher, prefixTree);
+ }
+ }
+ }
+
+ /**
+ * Removes vpn nlri identifier mapped to route distinguisher if it exists in tree.
+ *
+ * @param nlri NLRI Info
+ * @param routeDistinguisher unique for for each vpn
+ */
+ public void removeVpn(BgpLSNlri nlri, RouteDistinguisher routeDistinguisher) {
+ if (nlri instanceof BgpNodeLSNlriVer4) {
+ if (vpnNodeTree.containsKey(routeDistinguisher)) {
+ BgpNodeLSIdentifier nodeLSIdentifier = ((BgpNodeLSNlriVer4) nlri).getLocalNodeDescriptors();
+ if (nodeTree.containsKey(nodeLSIdentifier)) {
+ nodeTree.remove(nodeLSIdentifier);
+ }
+ if ((vpnNodeTree.get(routeDistinguisher)).isEmpty()) {
+ vpnNodeTree.remove(routeDistinguisher);
+ }
+ }
+ } else if (nlri instanceof BgpLinkLsNlriVer4) {
+ if (vpnLinkTree.containsKey(routeDistinguisher)) {
+ BgpLinkLSIdentifier linkLSIdentifier = ((BgpLinkLsNlriVer4) nlri).getLinkIdentifier();
+ if (linkTree.containsKey(linkLSIdentifier)) {
+ linkTree.remove(linkLSIdentifier);
+ }
+ if ((vpnLinkTree.get(routeDistinguisher)).isEmpty()) {
+ vpnLinkTree.remove(routeDistinguisher);
+ }
+ }
+ } else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) {
+ if (vpnPrefixTree.containsKey(routeDistinguisher)) {
+ BgpPrefixLSIdentifier prefixIdentifier = ((BgpPrefixIPv4LSNlriVer4) nlri).getPrefixIdentifier();
+ if (prefixTree.containsKey(prefixIdentifier)) {
+ prefixTree.remove(prefixIdentifier);
+ }
+ if ((vpnPrefixTree.get(routeDistinguisher)).isEmpty()) {
+ vpnPrefixTree.remove(routeDistinguisher);
+ }
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues().add("nodeTree", nodeTree)
+ .add("linkTree", linkTree)
+ .add("prefixTree", prefixTree)
+ .add("vpnNodeTree", vpnNodeTree)
+ .add("vpnLinkTree", vpnLinkTree)
+ .add("vpnPrefixTree", vpnPrefixTree)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/ctl/src/test/java/org/onosproject/bgp/BgpControllerImplTest.java b/framework/src/onos/bgp/ctl/src/test/java/org/onosproject/bgp/BgpControllerImplTest.java
new file mode 100755
index 00000000..36b1d6fc
--- /dev/null
+++ b/framework/src/onos/bgp/ctl/src/test/java/org/onosproject/bgp/BgpControllerImplTest.java
@@ -0,0 +1,300 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgp;
+
+import com.google.common.net.InetAddresses;
+import org.jboss.netty.bootstrap.ClientBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.Channels;
+import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import org.onlab.junit.TestUtils;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.util.LinkedList;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.onosproject.bgp.controller.BgpCfg;
+import org.onosproject.bgp.controller.impl.BgpControllerImpl;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv;
+import org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv;
+
+/**
+ * Test case for BGPControllerImpl.
+ */
+public class BgpControllerImplTest {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpControllerImplTest.class);
+
+ private static final String IP_LOOPBACK_ID1 = "127.0.0.1";
+
+ private static final int MESSAGE_TIMEOUT_MS = 3000;
+ public byte version;
+ public short asNumber;
+ public short holdTime;
+ public int bgpId = InetAddresses.coerceToInteger(InetAddresses.forString(IP_LOOPBACK_ID1));
+ public boolean isLargeAsCapabilitySet = false;
+ public LinkedList<BgpValueType> capabilityTlv = new LinkedList<>();
+
+ @Before
+ public void setUp() throws Exception {
+ peer1 = new BgpPeerTest(version, asNumber,
+ holdTime, bgpId, isLargeAsCapabilitySet,
+ capabilityTlv);
+
+ bgpControllerImpl = new BgpControllerImpl();
+
+ // NOTE: We use port 0 to bind on any available port
+ bgpControllerImpl.controller().setBgpPortNum();
+ bgpControllerImpl.activate();
+
+ Channel serverChannel = TestUtils.getField(bgpControllerImpl.controller(),
+ "serverChannel");
+ SocketAddress socketAddress = serverChannel.getLocalAddress();
+ InetSocketAddress inetSocketAddress =
+ (InetSocketAddress) socketAddress;
+ InetAddress connectToAddress = InetAddresses.forString("127.0.0.1");
+ connectToSocket = new InetSocketAddress(connectToAddress,
+ inetSocketAddress.getPort());
+
+ bgpControllerImpl.getConfig().setRouterId("1.1.1.1");
+ bgpControllerImpl.getConfig().setAsNumber(200);
+ bgpControllerImpl.getConfig().setHoldTime((short) 120);
+ bgpControllerImpl.getConfig().setState(BgpCfg.State.IP_AS_CONFIGURED);
+
+ bgpControllerImpl.getConfig().addPeer("127.0.0.1", 200);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ bgpControllerImpl.deactivate();
+ bgpControllerImpl = null;
+ }
+
+ private BgpControllerImpl bgpControllerImpl;
+
+ BgpPeerTest peer1;
+
+ // The socket that the remote peers should connect to
+ private InetSocketAddress connectToSocket;
+
+ @Test
+ public void bgpOpenMessageTest1() throws InterruptedException {
+ peer1.peerChannelHandler.asNumber = 200;
+ peer1.peerChannelHandler.version = 4;
+ peer1.peerChannelHandler.holdTime = 120;
+ peer1.connect(connectToSocket);
+ boolean result;
+ result = peer1.peerFrameDecoder.receivedOpenMessageLatch.await(
+ MESSAGE_TIMEOUT_MS,
+ TimeUnit.MILLISECONDS);
+ assertThat(result, is(true));
+ result = peer1.peerFrameDecoder.receivedKeepaliveMessageLatch.await(
+ MESSAGE_TIMEOUT_MS,
+ TimeUnit.MILLISECONDS);
+ assertThat(result, is(true));
+ }
+
+ @Test
+ public void bgpOpenMessageTest2() throws InterruptedException {
+ // Open message with as number which is not configured at peer
+ peer1.peerChannelHandler.asNumber = 500;
+ peer1.peerChannelHandler.version = 4;
+ peer1.peerChannelHandler.holdTime = 120;
+ peer1.connect(connectToSocket);
+
+ boolean result;
+ result = peer1.peerFrameDecoder.receivedNotificationMessageLatch.await(
+ MESSAGE_TIMEOUT_MS,
+ TimeUnit.MILLISECONDS);
+ assertThat(result, is(true));
+ }
+
+ @Test
+ public void bgpOpenMessageTest3() throws InterruptedException {
+ // Open message with invalid hold time value
+ peer1.peerChannelHandler.asNumber = 200;
+ peer1.peerChannelHandler.version = 4;
+ peer1.peerChannelHandler.holdTime = 1;
+ peer1.connect(connectToSocket);
+
+ boolean result;
+ result = peer1.peerFrameDecoder.receivedNotificationMessageLatch.await(
+ MESSAGE_TIMEOUT_MS,
+ TimeUnit.MILLISECONDS);
+ assertThat(result, is(true));
+ }
+
+ @Test
+ public void bgpOpenMessageTest4() throws InterruptedException {
+ // Open message with invalid as number
+ peer1.peerChannelHandler.asNumber = 200;
+ peer1.peerChannelHandler.version = 4;
+ peer1.peerChannelHandler.holdTime = 120;
+ peer1.peerChannelHandler.isLargeAsCapabilitySet = true;
+ BgpValueType tempTlv = new FourOctetAsNumCapabilityTlv(766545);
+ peer1.peerChannelHandler.capabilityTlv.add(tempTlv);
+ peer1.connect(connectToSocket);
+
+ boolean result;
+ result = peer1.peerFrameDecoder.receivedNotificationMessageLatch.await(
+ MESSAGE_TIMEOUT_MS,
+ TimeUnit.MILLISECONDS);
+ assertThat(result, is(true));
+ }
+
+ @Test
+ public void bgpOpenMessageTest5() throws InterruptedException {
+ // Open message with LS capability
+ short afi = 16388;
+ byte res = 0;
+ byte safi = 71;
+ peer1.peerChannelHandler.asNumber = 200;
+ peer1.peerChannelHandler.version = 4;
+ peer1.peerChannelHandler.holdTime = 120;
+ bgpControllerImpl.getConfig().setLsCapability(true);
+ BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
+ peer1.peerChannelHandler.capabilityTlv.add(tempTlv1);
+ peer1.connect(connectToSocket);
+
+ boolean result;
+ result = peer1.peerFrameDecoder.receivedOpenMessageLatch.await(
+ MESSAGE_TIMEOUT_MS,
+ TimeUnit.MILLISECONDS);
+ assertThat(result, is(true));
+ result = peer1.peerFrameDecoder.receivedKeepaliveMessageLatch.await(
+ MESSAGE_TIMEOUT_MS,
+ TimeUnit.MILLISECONDS);
+ assertThat(result, is(true));
+ }
+
+ @Test
+ public void bgpOpenMessageTest6() throws InterruptedException {
+ // Open message with as4 capability
+ peer1.peerChannelHandler.asNumber = 200;
+ peer1.peerChannelHandler.version = 4;
+ peer1.peerChannelHandler.holdTime = 120;
+ peer1.peerChannelHandler.isLargeAsCapabilitySet = true;
+ bgpControllerImpl.getConfig().setLargeASCapability(true);
+ BgpValueType tempTlv = new FourOctetAsNumCapabilityTlv(200);
+ peer1.peerChannelHandler.capabilityTlv.add(tempTlv);
+ peer1.connect(connectToSocket);
+
+ boolean result;
+ result = peer1.peerFrameDecoder.receivedOpenMessageLatch.await(
+ MESSAGE_TIMEOUT_MS,
+ TimeUnit.MILLISECONDS);
+ assertThat(result, is(true));
+ result = peer1.peerFrameDecoder.receivedKeepaliveMessageLatch.await(
+ MESSAGE_TIMEOUT_MS,
+ TimeUnit.MILLISECONDS);
+ assertThat(result, is(true));
+
+ result = peer1.peerFrameDecoder.receivedKeepaliveMessageLatch.await(
+ MESSAGE_TIMEOUT_MS,
+ TimeUnit.MILLISECONDS);
+ assertThat(result, is(true));
+ }
+
+ @Test
+ public void bgpOpenMessageTest7() throws InterruptedException {
+ // Open message with both LS capability and as4 capability
+ short afi = 16388;
+ byte res = 0;
+ byte safi = 71;
+ peer1.peerChannelHandler.asNumber = 200;
+ peer1.peerChannelHandler.version = 4;
+ peer1.peerChannelHandler.holdTime = 120;
+
+ peer1.peerChannelHandler.isLargeAsCapabilitySet = true;
+ bgpControllerImpl.getConfig().setLargeASCapability(true);
+ BgpValueType tempTlv = new FourOctetAsNumCapabilityTlv(200);
+ peer1.peerChannelHandler.capabilityTlv.add(tempTlv);
+
+ bgpControllerImpl.getConfig().setLsCapability(true);
+ BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
+ peer1.peerChannelHandler.capabilityTlv.add(tempTlv1);
+ peer1.connect(connectToSocket);
+
+ boolean result;
+ result = peer1.peerFrameDecoder.receivedOpenMessageLatch.await(
+ MESSAGE_TIMEOUT_MS,
+ TimeUnit.MILLISECONDS);
+ assertThat(result, is(true));
+ }
+
+ /**
+ * A class to capture the state for a BGP peer.
+ */
+ private final class BgpPeerTest {
+ private ClientBootstrap peerBootstrap;
+ private BgpPeerFrameDecoderTest peerFrameDecoder =
+ new BgpPeerFrameDecoderTest();
+ private BgpPeerChannelHandlerTest peerChannelHandler;
+
+ private BgpPeerTest(byte version, short asNumber,
+ short holdTime, int bgpId, boolean isLargeAsCapabilitySet,
+ LinkedList<BgpValueType> capabilityTlv) {
+ peerChannelHandler = new BgpPeerChannelHandlerTest(version,
+ asNumber, holdTime, bgpId, isLargeAsCapabilitySet, capabilityTlv);
+ }
+
+ /**
+ * Starts the BGP peer.
+ *
+ * @param connectToSocket the socket to connect to
+ */
+ private void connect(InetSocketAddress connectToSocket)
+ throws InterruptedException {
+
+ ChannelFactory channelFactory =
+ new NioClientSocketChannelFactory(
+ Executors.newCachedThreadPool(),
+ Executors.newCachedThreadPool());
+ ChannelPipelineFactory pipelineFactory = () -> {
+ ChannelPipeline pipeline = Channels.pipeline();
+ pipeline.addLast("BgpPeerFrameDecoderTest",
+ peerFrameDecoder);
+ pipeline.addLast("BgpPeerChannelHandlerTest",
+ peerChannelHandler);
+ return pipeline;
+ };
+
+ peerBootstrap = new ClientBootstrap(channelFactory);
+ peerBootstrap.setOption("child.keepAlive", true);
+ peerBootstrap.setOption("child.tcpNoDelay", true);
+ peerBootstrap.setPipelineFactory(pipelineFactory);
+ peerBootstrap.connect(connectToSocket);
+ }
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/ctl/src/test/java/org/onosproject/bgp/BgpPeerChannelHandlerTest.java b/framework/src/onos/bgp/ctl/src/test/java/org/onosproject/bgp/BgpPeerChannelHandlerTest.java
new file mode 100755
index 00000000..26ed36d8
--- /dev/null
+++ b/framework/src/onos/bgp/ctl/src/test/java/org/onosproject/bgp/BgpPeerChannelHandlerTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgp;
+
+import java.util.LinkedList;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelStateEvent;
+import org.jboss.netty.channel.SimpleChannelHandler;
+import org.onosproject.bgpio.protocol.ver4.BgpKeepaliveMsgVer4;
+import org.onosproject.bgpio.protocol.ver4.BgpOpenMsgVer4;
+import org.onosproject.bgpio.types.BgpHeader;
+import org.onosproject.bgpio.types.BgpValueType;
+
+public class BgpPeerChannelHandlerTest extends SimpleChannelHandler {
+ public static final int OPEN_MSG_MINIMUM_LENGTH = 29;
+ public static final byte[] MARKER = new byte[] {(byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff};
+ public static final BgpHeader DEFAULT_OPEN_HEADER = new BgpHeader(MARKER,
+ (short) OPEN_MSG_MINIMUM_LENGTH, (byte) 0X01);
+ LinkedList<BgpValueType> capabilityTlv = new LinkedList<>();
+ public byte version;
+ public short asNumber;
+ public short holdTime;
+ public int bgpId;
+ public boolean isLargeAsCapabilitySet;
+
+ final BgpOpenMsgVer4 openMessage = new BgpOpenMsgVer4();
+ ChannelHandlerContext savedCtx;
+
+ /**
+ * Constructor to initialize all variables of BGP Open message.
+ *
+ * @param version BGP version in open message
+ * @param asNumber AS number in open message
+ * @param holdTime hold time in open message
+ * @param bgpId BGP identifier in open message
+ * @param capabilityTlv capabilities in open message
+ */
+ public BgpPeerChannelHandlerTest(byte version,
+ short asNumber,
+ short holdTime,
+ int bgpId,
+ boolean isLargeAsCapabilitySet,
+ LinkedList<BgpValueType> capabilityTlv) {
+ this.version = version;
+ this.asNumber = asNumber;
+ this.holdTime = holdTime;
+ this.bgpId = bgpId;
+ this.isLargeAsCapabilitySet = isLargeAsCapabilitySet;
+ this.capabilityTlv = capabilityTlv;
+ }
+
+ /**
+ * closes the channel.
+ */
+ void closeChannel() {
+ savedCtx.getChannel().close();
+ }
+
+ @Override
+ public void channelConnected(ChannelHandlerContext ctx,
+ ChannelStateEvent channelEvent) throws InterruptedException {
+ this.savedCtx = ctx;
+
+ BgpOpenMsgVer4 openMsg = new BgpOpenMsgVer4(DEFAULT_OPEN_HEADER,
+ this.version,
+ this.asNumber,
+ this.holdTime,
+ this.bgpId,
+ this.capabilityTlv);
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ openMsg.writeTo(buffer);
+ ctx.getChannel().write(buffer);
+
+ TimeUnit.MILLISECONDS.sleep(100);
+
+ BgpKeepaliveMsgVer4 keepaliveMsg = new BgpKeepaliveMsgVer4();
+ ChannelBuffer buffer1 = ChannelBuffers.dynamicBuffer();
+ keepaliveMsg.writeTo(buffer1);
+ ctx.getChannel().write(buffer1);
+ }
+
+ @Override
+ public void channelDisconnected(ChannelHandlerContext ctx,
+ ChannelStateEvent channelEvent) {
+ //Do Nothing
+ }
+}
diff --git a/framework/src/onos/bgp/ctl/src/test/java/org/onosproject/bgp/BgpPeerFrameDecoderTest.java b/framework/src/onos/bgp/ctl/src/test/java/org/onosproject/bgp/BgpPeerFrameDecoderTest.java
new file mode 100755
index 00000000..7767053f
--- /dev/null
+++ b/framework/src/onos/bgp/ctl/src/test/java/org/onosproject/bgp/BgpPeerFrameDecoderTest.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgp;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.handler.codec.frame.FrameDecoder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * Class to decode the message received.
+ */
+public class BgpPeerFrameDecoderTest extends FrameDecoder {
+ static final byte OPEN_MSG_TYPE = 0x1;
+ static final byte KEEPALIVE_MSG_TYPE = 0x4;
+ static final byte UPDATE_MSG_TYPE = 0x2;
+ static final byte NOTIFICATION_MSG_TYPE = 0x3;
+ static final int MINIMUM_COMMON_HEADER_LENGTH = 19;
+ static final int MINIMUM_OPEN_MSG_LENGTH = 29;
+ static final int MINIMUM_HEADER_MARKER_LENGTH = 16;
+ static final int HEADER_AND_MSG_LEN = 18;
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpPeerFrameDecoderTest.class);
+ final CountDownLatch receivedOpenMessageLatch = new CountDownLatch(1);
+ final CountDownLatch receivedKeepaliveMessageLatch = new CountDownLatch(1);
+ final CountDownLatch receivedNotificationMessageLatch = new CountDownLatch(1);
+
+ @Override
+ protected Object decode(ChannelHandlerContext ctx,
+ Channel channel,
+ ChannelBuffer cb) throws Exception {
+
+ if (cb.readableBytes() < MINIMUM_COMMON_HEADER_LENGTH) {
+ log.debug("Error: Packet length is less then minimum length");
+ return null;
+ }
+
+ byte[] marker = new byte[MINIMUM_HEADER_MARKER_LENGTH];
+ cb.readBytes(marker);
+ for (int i = 0; i < marker.length; i++) {
+ if (marker[i] != (byte) 0xff) {
+ log.debug("Error: Marker must be set all ones");
+ ctx.getChannel().close();
+ return null;
+ }
+ }
+
+ short length = cb.readShort();
+ if (length < MINIMUM_COMMON_HEADER_LENGTH) {
+ log.debug("Error: Bad message length");
+ ctx.getChannel().close();
+ return null;
+ }
+
+ if (length != (cb.readableBytes() + HEADER_AND_MSG_LEN)) {
+ log.debug("Error: Bad message length");
+ ctx.getChannel().close();
+ return null;
+ }
+
+ byte type = cb.readByte();
+ int len = length - MINIMUM_COMMON_HEADER_LENGTH;
+
+ ChannelBuffer message = cb.readBytes(len);
+
+ switch (type) {
+ case OPEN_MSG_TYPE:
+ processBgpOpen(ctx, message);
+ break;
+ case UPDATE_MSG_TYPE:
+ break;
+ case NOTIFICATION_MSG_TYPE:
+ processBgpNotification(ctx, message);
+ break;
+ case KEEPALIVE_MSG_TYPE:
+ processBgpKeepalive(ctx, message);
+ break;
+ default:
+ ctx.getChannel().close();
+ return null;
+ }
+
+ return null;
+ }
+
+ /**
+ * Processes BGP open message.
+ *
+ * @param ctx Channel handler context
+ * @param message open message
+ */
+ private void processBgpOpen(ChannelHandlerContext ctx,
+ ChannelBuffer message) {
+ int minLength =
+ MINIMUM_OPEN_MSG_LENGTH - MINIMUM_COMMON_HEADER_LENGTH;
+ if (message.readableBytes() < minLength) {
+ log.debug("Error: Bad message length");
+ ctx.getChannel().close();
+ return;
+ }
+
+ message.readByte(); // read version
+ message.readShort(); // read AS number
+ message.readShort(); // read Hold timer
+ message.readInt(); // read BGP Identifier
+ // Optional Parameters
+ int optParamLen = message.readUnsignedByte();
+ if (message.readableBytes() < optParamLen) {
+ log.debug("Error: Bad message length");
+ ctx.getChannel().close();
+ return;
+ }
+ message.readBytes(optParamLen);
+
+ // Open message received
+ receivedOpenMessageLatch.countDown();
+ }
+
+ /**
+ * Processes BGP keepalive message.
+ *
+ * @param ctx Channel handler context
+ * @param message keepalive message
+ */
+ private void processBgpKeepalive(ChannelHandlerContext ctx,
+ ChannelBuffer message) {
+
+ // Keepalive message received
+ receivedKeepaliveMessageLatch.countDown();
+ }
+
+ /**
+ * Processes BGP notification message.
+ *
+ * @param ctx Channel handler context
+ * @param message notification message
+ */
+ private void processBgpNotification(ChannelHandlerContext ctx,
+ ChannelBuffer message) {
+ byte[] data;
+ message.readByte(); //read error code
+ message.readByte(); // read error sub code
+ if (message.readableBytes() > 0) {
+ data = new byte[message.readableBytes()];
+ message.readBytes(data, 0, message.readableBytes());
+ }
+
+ // Notification message received
+ receivedNotificationMessageLatch.countDown();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/bgp/ctl/src/test/java/org/onosproject/controller/impl/BgpSelectionAlgoTest.java b/framework/src/onos/bgp/ctl/src/test/java/org/onosproject/controller/impl/BgpSelectionAlgoTest.java
new file mode 100644
index 00000000..7c0fa417
--- /dev/null
+++ b/framework/src/onos/bgp/ctl/src/test/java/org/onosproject/controller/impl/BgpSelectionAlgoTest.java
@@ -0,0 +1,595 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.controller.impl;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+import java.util.LinkedList;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpAddress.Version;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType;
+import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails;
+import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib;
+import org.onosproject.bgpio.types.AsPath;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.types.LocalPref;
+import org.onosproject.bgpio.types.Med;
+import org.onosproject.bgpio.types.Origin;
+import org.onosproject.bgp.controller.impl.BgpSelectionAlgo;
+
+/**
+ * Test cases for BGP Selection Algorithm.
+ */
+public class BgpSelectionAlgoTest {
+
+ /**
+ * firstPathAttribute and secondPathAttribute has same AS count and firstPathAttribute
+ * has shortest Origin value than secondPathAttribute.
+ */
+ @Test
+ public void selectionAlgoTest1() throws BgpParseException {
+ byte[] peerIp = new byte[] {0x0a, 0x0a, 0x0a, 0x0a };
+ LinkedList<BgpValueType> pathAttributes1 = new LinkedList<>();
+ BgpValueType pathAttribute1;
+ //origin with IGP
+ byte[] origin = new byte[] {0x40, 0x01, 0x01, 0x00 };
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(origin);
+ pathAttribute1 = Origin.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+ //AsPath with AS_SEQ with one AS
+ byte[] asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
+ (byte) 0xea };
+ buffer.writeBytes(asPath);
+ pathAttribute1 = AsPath.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+
+ IpAddress ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ int bgpId = 168427777;
+ short locRIBASNum = 100;
+ boolean isIbgp = false;
+ PathAttrNlriDetails attrList1 = new PathAttrNlriDetails();
+ attrList1.setIdentifier(0);
+ attrList1.setPathAttribute(pathAttributes1);
+ attrList1.setProtocolID(ProtocolType.ISIS_LEVEL_ONE);
+ PathAttrNlriDetailsLocalRib list1 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList1);
+
+ peerIp = new byte[] {0x0b, 0x0b, 0x0b, 0x0b };
+ LinkedList<BgpValueType> pathAttributes2 = new LinkedList<>();
+ BgpValueType pathAttribute2;
+ //origin with INCOMPLETE
+ origin = new byte[] {0x40, 0x01, 0x01, 0x02 };
+ buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(origin);
+ pathAttribute2 = Origin.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+ //AsPath with AS_SEQ with one AS
+ asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
+ (byte) 0xe9 };
+ buffer.writeBytes(asPath);
+ pathAttribute2 = AsPath.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+
+ ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ bgpId = 536936448;
+ locRIBASNum = 200;
+ isIbgp = true;
+ PathAttrNlriDetails attrList2 = new PathAttrNlriDetails();
+ attrList2.setIdentifier(0);
+ attrList2.setPathAttribute(pathAttributes2);
+ attrList2.setProtocolID(ProtocolType.OSPF_V2);
+ PathAttrNlriDetailsLocalRib list2 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList2);
+ BgpSelectionAlgo algo = new BgpSelectionAlgo();
+ int result = algo.compare(list1, list2);
+ assertThat(result, is(1));
+ }
+
+ /**
+ * firstPathAttribute has 1 AS count and secondPathAttribute has 2 AS count
+ * and firstPathAttribute has shortest Origin value than secondPathAttribute.
+ */
+ @Test
+ public void selectionAlgoTest2() throws BgpParseException {
+
+ byte[] peerIp = new byte[] {0x0a, 0x0a, 0x0a, 0x0a };
+ LinkedList<BgpValueType> pathAttributes1 = new LinkedList<>();
+ BgpValueType pathAttribute1;
+ byte[] origin = new byte[] {0x40, 0x01, 0x01, 0x00 };
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(origin);
+ pathAttribute1 = Origin.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+ byte[] asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
+ (byte) 0xe9 };
+ buffer.writeBytes(asPath);
+ pathAttribute1 = AsPath.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+
+ IpAddress ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ int bgpId = 168427777;
+ short locRIBASNum = 100;
+ boolean isIbgp = false;
+ PathAttrNlriDetails attrList1 = new PathAttrNlriDetails();
+ attrList1.setIdentifier(0);
+ attrList1.setPathAttribute(pathAttributes1);
+ attrList1.setProtocolID(ProtocolType.ISIS_LEVEL_ONE);
+ PathAttrNlriDetailsLocalRib list1 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList1);
+
+ peerIp = new byte[] {0x0b, 0x0b, 0x0b, 0x0b };
+ LinkedList<BgpValueType> pathAttributes2 = new LinkedList<>();
+ BgpValueType pathAttribute2;
+ origin = new byte[] {0x40, 0x01, 0x01, 0x02 };
+ buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(origin);
+ pathAttribute2 = Origin.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+ asPath = new byte[] {0x40, 0x02, 0x08, 0x02, 0x01, (byte) 0xfd,
+ (byte) 0xea, 0x02, 0x01, (byte) 0xfd, (byte) 0xea };
+ buffer.writeBytes(asPath);
+ pathAttribute2 = AsPath.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+
+ ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ bgpId = 536936448;
+ locRIBASNum = 200;
+ isIbgp = true;
+ PathAttrNlriDetails attrList2 = new PathAttrNlriDetails();
+ attrList2.setIdentifier(0);
+ attrList2.setPathAttribute(pathAttributes2);
+ attrList2.setProtocolID(ProtocolType.OSPF_V2);
+ PathAttrNlriDetailsLocalRib list2 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList2);
+ BgpSelectionAlgo algo = new BgpSelectionAlgo();
+ int result = algo.compare(list1, list2);
+ assertThat(result, is(-1));
+ }
+
+ /**
+ * firstPathAttribute and secondPathAttribute has same AS value
+ * and firstPathAttribute has shortest Origin value than secondPathAttribute.
+ */
+ @Test
+ public void selectionAlgoTest3() throws BgpParseException {
+
+ byte[] peerIp = new byte[] {0x0a, 0x0a, 0x0a, 0x0a };
+ LinkedList<BgpValueType> pathAttributes1 = new LinkedList<>();
+ BgpValueType pathAttribute1;
+ byte[] origin = new byte[] {0x40, 0x01, 0x01, 0x00 };
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(origin);
+ pathAttribute1 = Origin.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+ byte[] asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
+ (byte) 0xe9 };
+ buffer.writeBytes(asPath);
+ pathAttribute1 = AsPath.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+
+ IpAddress ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ int bgpId = 168427777;
+ short locRIBASNum = 100;
+ boolean isIbgp = false;
+ PathAttrNlriDetails attrList1 = new PathAttrNlriDetails();
+ attrList1.setIdentifier(0);
+ attrList1.setPathAttribute(pathAttributes1);
+ attrList1.setProtocolID(ProtocolType.ISIS_LEVEL_ONE);
+ PathAttrNlriDetailsLocalRib list1 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList1);
+
+ peerIp = new byte[] {0x0b, 0x0b, 0x0b, 0x0b };
+ LinkedList<BgpValueType> pathAttributes2 = new LinkedList<>();
+ BgpValueType pathAttribute2;
+ origin = new byte[] {0x40, 0x01, 0x01, 0x02 };
+ buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(origin);
+ pathAttribute2 = Origin.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+ asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
+ (byte) 0xe9 };
+ buffer.writeBytes(asPath);
+ pathAttribute2 = AsPath.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+
+ ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ bgpId = 536936448;
+ locRIBASNum = 200;
+ isIbgp = true;
+ PathAttrNlriDetails attrList2 = new PathAttrNlriDetails();
+ attrList2.setIdentifier(0);
+ attrList2.setPathAttribute(pathAttributes2);
+ attrList2.setProtocolID(ProtocolType.OSPF_V2);
+ PathAttrNlriDetailsLocalRib list2 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList2);
+ BgpSelectionAlgo algo = new BgpSelectionAlgo();
+ int result = algo.compare(list1, list2);
+ assertThat(result, is(1));
+ }
+
+ /**
+ * firstPathAttribute has lowest med than secondPathAttribute.
+ */
+ @Test
+ public void selectionAlgoTest4() throws BgpParseException {
+
+ byte[] peerIp = new byte[] {0x0a, 0x0a, 0x0a, 0x0a };
+ LinkedList<BgpValueType> pathAttributes1 = new LinkedList<>();
+ BgpValueType pathAttribute1;
+ byte[] origin = new byte[] {0x40, 0x01, 0x01, 0x00 };
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(origin);
+ pathAttribute1 = Origin.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+ byte[] med = new byte[] {(byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00,
+ 0x00 };
+ buffer.writeBytes(med);
+ pathAttribute1 = Med.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+ byte[] asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
+ (byte) 0xe9 };
+ buffer.writeBytes(asPath);
+ pathAttribute1 = AsPath.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+
+ IpAddress ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ int bgpId = 168427777;
+ short locRIBASNum = 100;
+ boolean isIbgp = false;
+ PathAttrNlriDetails attrList1 = new PathAttrNlriDetails();
+ attrList1.setIdentifier(0);
+ attrList1.setPathAttribute(pathAttributes1);
+ attrList1.setProtocolID(ProtocolType.ISIS_LEVEL_ONE);
+ PathAttrNlriDetailsLocalRib list1 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList1);
+
+ peerIp = new byte[] {0x0b, 0x0b, 0x0b, 0x0b };
+ LinkedList<BgpValueType> pathAttributes2 = new LinkedList<>();
+ BgpValueType pathAttribute2;
+ origin = new byte[] {0x40, 0x01, 0x01, 0x02 };
+ buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(origin);
+ pathAttribute2 = Origin.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+ med = new byte[] {(byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x01 };
+ buffer.writeBytes(med);
+ pathAttribute2 = Med.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+ asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
+ (byte) 0xe9 };
+ buffer.writeBytes(asPath);
+ pathAttribute2 = AsPath.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+
+ ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ bgpId = 536936448;
+ locRIBASNum = 200;
+ isIbgp = true;
+ PathAttrNlriDetails attrList2 = new PathAttrNlriDetails();
+ attrList2.setIdentifier(0);
+ attrList2.setPathAttribute(pathAttributes2);
+ attrList2.setProtocolID(ProtocolType.OSPF_V2);
+ PathAttrNlriDetailsLocalRib list2 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList2);
+ BgpSelectionAlgo algo = new BgpSelectionAlgo();
+ int result = algo.compare(list1, list2);
+ assertThat(result, is(1));
+ }
+
+ /**
+ * secondPathAttribute has higher local preference than firstPathAttribute.
+ */
+ @Test
+ public void selectionAlgoTest5() throws BgpParseException {
+
+ byte[] peerIp = new byte[] {0x0a, 0x0a, 0x0a, 0x0a };
+ LinkedList<BgpValueType> pathAttributes1 = new LinkedList<>();
+ BgpValueType pathAttribute1;
+ byte[] locPref = new byte[] {(byte) 0x00, 0x05, 0x04, 0x00, 0x00,
+ 0x00, 0x01 };
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(locPref);
+ pathAttribute1 = LocalPref.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+
+ IpAddress ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ int bgpId = 168427777;
+ short locRIBASNum = 100;
+ boolean isIbgp = false;
+ PathAttrNlriDetails attrList1 = new PathAttrNlriDetails();
+ attrList1.setIdentifier(0);
+ attrList1.setPathAttribute(pathAttributes1);
+ attrList1.setProtocolID(ProtocolType.ISIS_LEVEL_ONE);
+ PathAttrNlriDetailsLocalRib list1 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList1);
+
+ peerIp = new byte[] {0x0b, 0x0b, 0x0b, 0x0b };
+ LinkedList<BgpValueType> pathAttributes2 = new LinkedList<>();
+ BgpValueType pathAttribute2;
+ locPref = new byte[] {(byte) 0x00, 0x05, 0x04, 0x00, 0x00, 0x00, 0x0a };
+ buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(locPref);
+ pathAttribute2 = LocalPref.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+
+ ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ bgpId = 536936448;
+ locRIBASNum = 200;
+ isIbgp = true;
+ PathAttrNlriDetails attrList2 = new PathAttrNlriDetails();
+ attrList2.setIdentifier(0);
+ attrList2.setPathAttribute(pathAttributes2);
+ attrList2.setProtocolID(ProtocolType.OSPF_V2);
+ PathAttrNlriDetailsLocalRib list2 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList2);
+ BgpSelectionAlgo algo = new BgpSelectionAlgo();
+ int result = algo.compare(list1, list2);
+ assertThat(result, is(-1));
+ }
+
+ /**
+ * secondPathAttribute is EBGP than firstPathAttribute is IBGP.
+ */
+ @Test
+ public void selectionAlgoTest6() throws BgpParseException {
+
+ byte[] peerIp = new byte[] {0x0a, 0x0a, 0x0a, 0x0a };
+ LinkedList<BgpValueType> pathAttributes1 = new LinkedList<>();
+ BgpValueType pathAttribute1;
+ byte[] origin = new byte[] {0x40, 0x01, 0x01, 0x00 };
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(origin);
+ pathAttribute1 = Origin.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+ byte[] asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
+ (byte) 0xe9 };
+ buffer.writeBytes(asPath);
+ pathAttribute1 = AsPath.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+
+ IpAddress ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ int bgpId = 168427777;
+ short locRIBASNum = 100;
+ boolean isIbgp = true;
+ PathAttrNlriDetails attrList1 = new PathAttrNlriDetails();
+ attrList1.setIdentifier(0);
+ attrList1.setPathAttribute(pathAttributes1);
+ attrList1.setProtocolID(ProtocolType.ISIS_LEVEL_ONE);
+ PathAttrNlriDetailsLocalRib list1 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList1);
+
+ peerIp = new byte[] {0x0b, 0x0b, 0x0b, 0x0b };
+ LinkedList<BgpValueType> pathAttributes2 = new LinkedList<>();
+ BgpValueType pathAttribute2;
+ origin = new byte[] {0x40, 0x01, 0x01, 0x00 };
+ buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(origin);
+ pathAttribute2 = Origin.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+ asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
+ (byte) 0xe9 };
+ buffer.writeBytes(asPath);
+ pathAttribute2 = AsPath.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+
+ ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ bgpId = 536936448;
+ locRIBASNum = 200;
+ isIbgp = false;
+ PathAttrNlriDetails attrList2 = new PathAttrNlriDetails();
+ attrList2.setIdentifier(0);
+ attrList2.setPathAttribute(pathAttributes2);
+ attrList2.setProtocolID(ProtocolType.OSPF_V2);
+ PathAttrNlriDetailsLocalRib list2 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, false, attrList2);
+ BgpSelectionAlgo algo = new BgpSelectionAlgo();
+ int result = algo.compare(list1, list2);
+ assertThat(result, is(-1));
+ }
+
+ /**
+ * firstPathAttribute has lower BGPID than secondPathAttribute.
+ */
+ @Test
+ public void selectionAlgoTest7() throws BgpParseException {
+
+ byte[] peerIp = new byte[] {0x0a, 0x0a, 0x0a, 0x0a };
+ LinkedList<BgpValueType> pathAttributes1 = new LinkedList<>();
+ BgpValueType pathAttribute1;
+ byte[] origin = new byte[] {0x40, 0x01, 0x01, 0x00 };
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(origin);
+ pathAttribute1 = Origin.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+ byte[] asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
+ (byte) 0xe9 };
+ buffer.writeBytes(asPath);
+ pathAttribute1 = AsPath.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+
+ IpAddress ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ //A0A0A00
+ Integer bgpId = 168430080;
+ short locRIBASNum = 100;
+ boolean isIbgp = false;
+ PathAttrNlriDetails attrList1 = new PathAttrNlriDetails();
+ attrList1.setIdentifier(0);
+ attrList1.setPathAttribute(pathAttributes1);
+ attrList1.setProtocolID(ProtocolType.ISIS_LEVEL_ONE);
+ PathAttrNlriDetailsLocalRib list1 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList1);
+
+ peerIp = new byte[] {0x0b, 0x0b, 0x0b, 0x0b };
+ LinkedList<BgpValueType> pathAttributes2 = new LinkedList<>();
+ BgpValueType pathAttribute2;
+ origin = new byte[] {0x40, 0x01, 0x01, 0x00 };
+ buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(origin);
+ pathAttribute2 = Origin.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+ asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
+ (byte) 0xe9 };
+ buffer.writeBytes(asPath);
+ pathAttribute2 = AsPath.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+
+ ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ //B0A0A00
+ bgpId = 185207296;
+ locRIBASNum = 200;
+ isIbgp = false;
+ PathAttrNlriDetails attrList2 = new PathAttrNlriDetails();
+ attrList2.setIdentifier(0);
+ attrList2.setPathAttribute(pathAttributes2);
+ attrList2.setProtocolID(ProtocolType.OSPF_V2);
+ PathAttrNlriDetailsLocalRib list2 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList2);
+ BgpSelectionAlgo algo = new BgpSelectionAlgo();
+ int result = algo.compare(list1, list2);
+ assertThat(result, is(1));
+ }
+
+ /**
+ * secondPathAttribute has lowest peer address than firstPathAttribute.
+ */
+ @Test
+ public void selectionAlgoTest8() throws BgpParseException {
+
+ byte[] peerIp = new byte[] {0x0b, 0x0b, 0x0b, 0x0b };
+ LinkedList<BgpValueType> pathAttributes1 = new LinkedList<>();
+ BgpValueType pathAttribute1;
+ byte[] origin = new byte[] {0x40, 0x01, 0x01, 0x00 };
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(origin);
+ pathAttribute1 = Origin.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+ byte[] asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
+ (byte) 0xe9 };
+ buffer.writeBytes(asPath);
+ pathAttribute1 = AsPath.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+
+ IpAddress ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ //A0A0A00
+ Integer bgpId = 168430080;
+ short locRIBASNum = 100;
+ boolean isIbgp = false;
+ PathAttrNlriDetails attrList1 = new PathAttrNlriDetails();
+ attrList1.setIdentifier(0);
+ attrList1.setPathAttribute(pathAttributes1);
+ attrList1.setProtocolID(ProtocolType.ISIS_LEVEL_ONE);
+ PathAttrNlriDetailsLocalRib list1 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList1);
+
+ peerIp = new byte[] {0x0a, 0x0a, 0x0a, 0x0a };
+ LinkedList<BgpValueType> pathAttributes2 = new LinkedList<>();
+ BgpValueType pathAttribute2;
+ origin = new byte[] {0x40, 0x01, 0x01, 0x00 };
+ buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(origin);
+ pathAttribute2 = Origin.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+ asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
+ (byte) 0xe9 };
+ buffer.writeBytes(asPath);
+ pathAttribute2 = AsPath.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+
+ ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ //A0A0A00
+ bgpId = 168430080;
+ locRIBASNum = 200;
+ isIbgp = false;
+ PathAttrNlriDetails attrList2 = new PathAttrNlriDetails();
+ attrList2.setIdentifier(0);
+ attrList2.setPathAttribute(pathAttributes2);
+ attrList2.setProtocolID(ProtocolType.OSPF_V2);
+ PathAttrNlriDetailsLocalRib list2 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList2);
+ BgpSelectionAlgo algo = new BgpSelectionAlgo();
+ int result = algo.compare(list1, list2);
+ assertThat(result, is(-1));
+ }
+
+ /**
+ * firstPathAttribute and secondPathAttribute are same.
+ */
+ @Test
+ public void selectionAlgoTest9() throws BgpParseException {
+
+ byte[] peerIp = new byte[] {0x0a, 0x0a, 0x0a, 0x0a };
+ LinkedList<BgpValueType> pathAttributes1 = new LinkedList<>();
+ BgpValueType pathAttribute1;
+ byte[] origin = new byte[] {0x40, 0x01, 0x01, 0x00 };
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(origin);
+ pathAttribute1 = Origin.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+ byte[] asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
+ (byte) 0xe9 };
+ buffer.writeBytes(asPath);
+ pathAttribute1 = AsPath.read(buffer);
+ pathAttributes1.add(pathAttribute1);
+
+ IpAddress ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ //A0A0A00
+ Integer bgpId = 168430080;
+ short locRIBASNum = 100;
+ boolean isIbgp = false;
+ PathAttrNlriDetails attrList1 = new PathAttrNlriDetails();
+ attrList1.setIdentifier(0);
+ attrList1.setPathAttribute(pathAttributes1);
+ attrList1.setProtocolID(ProtocolType.ISIS_LEVEL_ONE);
+ PathAttrNlriDetailsLocalRib list1 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList1);
+
+ peerIp = new byte[] {0x0a, 0x0a, 0x0a, 0x0a };
+ LinkedList<BgpValueType> pathAttributes2 = new LinkedList<>();
+ BgpValueType pathAttribute2;
+ origin = new byte[] {0x40, 0x01, 0x01, 0x00 };
+ buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(origin);
+ pathAttribute2 = Origin.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+ asPath = new byte[] {0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd,
+ (byte) 0xe9 };
+ buffer.writeBytes(asPath);
+ pathAttribute2 = AsPath.read(buffer);
+ pathAttributes2.add(pathAttribute2);
+
+ ipAddress = IpAddress.valueOf(Version.INET, peerIp);
+ //A0A0A00
+ bgpId = 168430080;
+ locRIBASNum = 200;
+ isIbgp = false;
+ PathAttrNlriDetails attrList2 = new PathAttrNlriDetails();
+ attrList2.setIdentifier(0);
+ attrList2.setPathAttribute(pathAttributes2);
+ attrList2.setProtocolID(ProtocolType.OSPF_V2);
+ PathAttrNlriDetailsLocalRib list2 = new PathAttrNlriDetailsLocalRib(
+ ipAddress, bgpId, locRIBASNum, isIbgp, attrList2);
+ BgpSelectionAlgo algo = new BgpSelectionAlgo();
+ int result = algo.compare(list1, list2);
+ assertThat(result, is(0));
+ }
+}