Committed by
Gerrit Code Review
BGP device id string.
Change-Id: Ie108dd2dce9b854ab3f0e42550cfaf23a9395ad6
Showing
2 changed files
with
92 additions
and
19 deletions
... | @@ -17,15 +17,27 @@ import static com.google.common.base.Preconditions.checkArgument; | ... | @@ -17,15 +17,27 @@ import static com.google.common.base.Preconditions.checkArgument; |
17 | 17 | ||
18 | import java.net.URI; | 18 | import java.net.URI; |
19 | import java.net.URISyntaxException; | 19 | import java.net.URISyntaxException; |
20 | +import java.util.List; | ||
21 | +import java.util.ListIterator; | ||
20 | 22 | ||
21 | import org.onosproject.bgpio.exceptions.BgpParseException; | 23 | import org.onosproject.bgpio.exceptions.BgpParseException; |
22 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; | 24 | import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; |
25 | +import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier; | ||
23 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; | 26 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; |
27 | +import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors; | ||
28 | +import org.onosproject.bgpio.types.AreaIDTlv; | ||
29 | +import org.onosproject.bgpio.types.AutonomousSystemTlv; | ||
30 | +import org.onosproject.bgpio.types.BgpLSIdentifierTlv; | ||
31 | +import org.onosproject.bgpio.types.BgpValueType; | ||
32 | +import org.onosproject.bgpio.types.IsIsNonPseudonode; | ||
33 | +import org.onosproject.bgpio.types.IsIsPseudonode; | ||
34 | +import org.onosproject.bgpio.types.OspfNonPseudonode; | ||
35 | +import org.onosproject.bgpio.types.OspfPseudonode; | ||
24 | import org.slf4j.Logger; | 36 | import org.slf4j.Logger; |
25 | import org.slf4j.LoggerFactory; | 37 | import org.slf4j.LoggerFactory; |
26 | 38 | ||
27 | /** | 39 | /** |
28 | - * The class representing a network bgp device id. This class is immutable. | 40 | + * The class representing a network bgp device id. |
29 | */ | 41 | */ |
30 | public final class BgpDpid { | 42 | public final class BgpDpid { |
31 | private static final Logger log = LoggerFactory.getLogger(BgpDpid.class); | 43 | private static final Logger log = LoggerFactory.getLogger(BgpDpid.class); |
... | @@ -43,15 +55,22 @@ public final class BgpDpid { | ... | @@ -43,15 +55,22 @@ public final class BgpDpid { |
43 | * @param nodeDescriptorType node descriptor type, local/remote | 55 | * @param nodeDescriptorType node descriptor type, local/remote |
44 | */ | 56 | */ |
45 | public BgpDpid(final BgpLinkLsNlriVer4 linkNlri, int nodeDescriptorType) { | 57 | public BgpDpid(final BgpLinkLsNlriVer4 linkNlri, int nodeDescriptorType) { |
46 | - this.stringBuilder = new StringBuilder("bgpls://"); | 58 | + this.stringBuilder = new StringBuilder(""); |
47 | 59 | ||
48 | if (linkNlri.getRouteDistinguisher() != null) { | 60 | if (linkNlri.getRouteDistinguisher() != null) { |
49 | - this.stringBuilder.append(linkNlri.getRouteDistinguisher().getRouteDistinguisher()).append(':'); | 61 | + this.stringBuilder.append("RD=").append(linkNlri.getRouteDistinguisher() |
62 | + .getRouteDistinguisher()).append(":"); | ||
50 | } | 63 | } |
51 | 64 | ||
52 | try { | 65 | try { |
53 | - this.stringBuilder.append(linkNlri.getProtocolId()).append(':').append(linkNlri.getIdentifier()) | 66 | + if ((linkNlri.getProtocolId() == BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_ONE) |
54 | - .append('/'); | 67 | + || (linkNlri.getProtocolId() == BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO)) { |
68 | + this.stringBuilder.append("PROTO=").append("ISIS").append(":ID=") | ||
69 | + .append(linkNlri.getIdentifier()); | ||
70 | + } else { | ||
71 | + this.stringBuilder.append("PROTO=").append(linkNlri.getProtocolId()).append(":ID=") | ||
72 | + .append(linkNlri.getIdentifier()); | ||
73 | + } | ||
55 | 74 | ||
56 | if (nodeDescriptorType == NODE_DESCRIPTOR_LOCAL) { | 75 | if (nodeDescriptorType == NODE_DESCRIPTOR_LOCAL) { |
57 | add(linkNlri.localNodeDescriptors()); | 76 | add(linkNlri.localNodeDescriptors()); |
... | @@ -64,23 +83,43 @@ public final class BgpDpid { | ... | @@ -64,23 +83,43 @@ public final class BgpDpid { |
64 | 83 | ||
65 | } | 84 | } |
66 | 85 | ||
86 | + /* | ||
87 | + * Get iso node ID in specified string format. | ||
88 | + */ | ||
89 | + private String isoNodeIdString(byte[] isoNodeId) { | ||
90 | + if (isoNodeId != null) { | ||
91 | + int p1 = (int) isoNodeId[0] << 8 | (int) isoNodeId[1]; | ||
92 | + int p2 = (int) isoNodeId[2] << 8 | (int) isoNodeId[3]; | ||
93 | + int p3 = (int) isoNodeId[4] << 8 | (int) isoNodeId[5]; | ||
94 | + | ||
95 | + return String.format("%1$d.%2$d.%3$d", p1, p2, p3); | ||
96 | + } | ||
97 | + return null; | ||
98 | + } | ||
99 | + | ||
67 | /** | 100 | /** |
68 | * Initialize bgp id to generate URI. | 101 | * Initialize bgp id to generate URI. |
69 | * | 102 | * |
70 | * @param nodeNlri node Nlri. | 103 | * @param nodeNlri node Nlri. |
71 | */ | 104 | */ |
72 | public BgpDpid(final BgpNodeLSNlriVer4 nodeNlri) { | 105 | public BgpDpid(final BgpNodeLSNlriVer4 nodeNlri) { |
73 | - this.stringBuilder = new StringBuilder("bgpls://"); | 106 | + this.stringBuilder = new StringBuilder(""); |
74 | 107 | ||
75 | if (nodeNlri.getRouteDistinguisher() != null) { | 108 | if (nodeNlri.getRouteDistinguisher() != null) { |
76 | - this.stringBuilder.append(nodeNlri.getRouteDistinguisher().getRouteDistinguisher()).append(':'); | 109 | + this.stringBuilder.append("RD=").append(nodeNlri.getRouteDistinguisher() |
110 | + .getRouteDistinguisher()).append(":"); | ||
77 | } | 111 | } |
78 | 112 | ||
79 | try { | 113 | try { |
80 | - | 114 | + if ((nodeNlri.getProtocolId() == BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_ONE) |
81 | - this.stringBuilder.append(nodeNlri.getProtocolId()).append(':').append(nodeNlri.getIdentifier()) | 115 | + || (nodeNlri.getProtocolId() == BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO)) { |
82 | - .append('/'); | 116 | + |
83 | - | 117 | + this.stringBuilder.append("PROTO=").append("ISIS").append(":ID=") |
118 | + .append(nodeNlri.getIdentifier()); | ||
119 | + } else { | ||
120 | + this.stringBuilder.append("PROTO=").append(nodeNlri.getProtocolId()).append(":ID=") | ||
121 | + .append(nodeNlri.getIdentifier()); | ||
122 | + } | ||
84 | add(nodeNlri.getLocalNodeDescriptors()); | 123 | add(nodeNlri.getLocalNodeDescriptors()); |
85 | 124 | ||
86 | } catch (BgpParseException e) { | 125 | } catch (BgpParseException e) { |
... | @@ -89,8 +128,45 @@ public final class BgpDpid { | ... | @@ -89,8 +128,45 @@ public final class BgpDpid { |
89 | } | 128 | } |
90 | 129 | ||
91 | BgpDpid add(final Object value) { | 130 | BgpDpid add(final Object value) { |
92 | - if (value != null) { | 131 | + NodeDescriptors nodeDescriptors = null; |
93 | - this.stringBuilder.append('&').append('=').append(value.toString()); | 132 | + if (value instanceof BgpNodeLSIdentifier) { |
133 | + BgpNodeLSIdentifier nodeLsIdentifier = (BgpNodeLSIdentifier) value; | ||
134 | + nodeDescriptors = nodeLsIdentifier.getNodedescriptors(); | ||
135 | + } else if (value instanceof NodeDescriptors) { | ||
136 | + nodeDescriptors = (NodeDescriptors) value; | ||
137 | + } | ||
138 | + | ||
139 | + if (nodeDescriptors != null) { | ||
140 | + List<BgpValueType> subTlvs = nodeDescriptors.getSubTlvs(); | ||
141 | + ListIterator<BgpValueType> listIterator = subTlvs.listIterator(); | ||
142 | + while (listIterator.hasNext()) { | ||
143 | + BgpValueType tlv = listIterator.next(); | ||
144 | + if (tlv.getType() == AutonomousSystemTlv.TYPE) { | ||
145 | + AutonomousSystemTlv autonomousSystem = (AutonomousSystemTlv) tlv; | ||
146 | + this.stringBuilder.append(":AS=").append(autonomousSystem.getAsNum()); | ||
147 | + } else if (tlv.getType() == BgpLSIdentifierTlv.TYPE) { | ||
148 | + BgpLSIdentifierTlv lsIdentifierTlv = (BgpLSIdentifierTlv) tlv; | ||
149 | + this.stringBuilder.append(":LSID=").append(lsIdentifierTlv.getBgpLsIdentifier()); | ||
150 | + } else if (tlv.getType() == AreaIDTlv.TYPE) { | ||
151 | + AreaIDTlv areaIdTlv = (AreaIDTlv) tlv; | ||
152 | + this.stringBuilder.append(":AREA=").append(areaIdTlv.getAreaID()); | ||
153 | + } else if (tlv.getType() == NodeDescriptors.IGP_ROUTERID_TYPE) { | ||
154 | + if (tlv instanceof IsIsNonPseudonode) { | ||
155 | + IsIsNonPseudonode isisNonPseudonode = (IsIsNonPseudonode) tlv; | ||
156 | + this.stringBuilder.append(":ISOID=").append(isoNodeIdString(isisNonPseudonode.getIsoNodeId())); | ||
157 | + } else if (tlv instanceof IsIsPseudonode) { | ||
158 | + IsIsPseudonode isisPseudonode = (IsIsPseudonode) tlv; | ||
159 | + this.stringBuilder.append(":ISOID=").append(isoNodeIdString(isisPseudonode.getIsoNodeId())); | ||
160 | + this.stringBuilder.append(":PSN=").append(isisPseudonode.getPsnIdentifier()); | ||
161 | + } else if (tlv instanceof OspfNonPseudonode) { | ||
162 | + OspfNonPseudonode ospfNonPseudonode = (OspfNonPseudonode) tlv; | ||
163 | + this.stringBuilder.append(":RID=").append(ospfNonPseudonode.getrouterID()); | ||
164 | + } else if (tlv instanceof OspfPseudonode) { | ||
165 | + OspfPseudonode ospfPseudonode = (OspfPseudonode) tlv; | ||
166 | + this.stringBuilder.append(":RID=").append(ospfPseudonode.getrouterID()); | ||
167 | + } | ||
168 | + } | ||
169 | + } | ||
94 | } | 170 | } |
95 | return this; | 171 | return this; |
96 | } | 172 | } | ... | ... |
... | @@ -56,14 +56,11 @@ import org.onosproject.net.provider.ProviderId; | ... | @@ -56,14 +56,11 @@ import org.onosproject.net.provider.ProviderId; |
56 | public class BgpTopologyProviderTest { | 56 | public class BgpTopologyProviderTest { |
57 | 57 | ||
58 | private static final DeviceId DID1 = DeviceId | 58 | private static final DeviceId DID1 = DeviceId |
59 | - .deviceId("bgp:bgpls://0:direct:0/&=bgpnodelsidentifier%7bnodedescriptors=nodedescriptors%7bdestype=512," | 59 | + .deviceId("bgp:rd=0:proto=direct:id=0:as=100"); |
60 | - + "%20deslength=4,%20subtlvs=[autonomoussystemtlv%7btype=512,%20length=4,%20asnum=100%7d]%7d%7d"); | ||
61 | private static final DeviceId DID2 = DeviceId | 60 | private static final DeviceId DID2 = DeviceId |
62 | - .deviceId("bgp:bgpls://0:direct:0/&=bgpnodelsidentifier%7bnodedescriptors=nodedescriptors%7bdestype=512," | 61 | + .deviceId("bgp:rd=0:proto=direct:id=0:as=10"); |
63 | - + "%20deslength=4,%20subtlvs=[autonomoussystemtlv%7btype=512,%20length=4,%20asnum=10%7d]%7d%7d"); | ||
64 | private static final DeviceId DID3 = DeviceId | 62 | private static final DeviceId DID3 = DeviceId |
65 | - .deviceId("bgp:bgpls://direct:0/&=nodedescriptors%7bdestype=512,%20deslength=4," | 63 | + .deviceId("bgp:rd=0:proto=direct:id=0:as=100"); |
66 | - + "%20subtlvs=[autonomoussystemtlv%7btype=512,%20length=4,%20asnum=100%7d]%7d"); | ||
67 | private final BgpTopologyProvider provider = new BgpTopologyProvider(); | 64 | private final BgpTopologyProvider provider = new BgpTopologyProvider(); |
68 | private final TestDeviceRegistry nodeRegistry = new TestDeviceRegistry(); | 65 | private final TestDeviceRegistry nodeRegistry = new TestDeviceRegistry(); |
69 | private final TestController controller = new TestController(); | 66 | private final TestController controller = new TestController(); | ... | ... |
-
Please register or login to post a comment