2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.pcep.api;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertThat;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.matchers.JUnitMatchers.containsString;
16 import java.util.ArrayList;
17 import java.util.List;
19 import org.junit.Test;
20 import org.opendaylight.protocol.concepts.IPv4;
21 import org.opendaylight.protocol.concepts.IPv4Address;
22 import org.opendaylight.protocol.concepts.IPv4Prefix;
23 import org.opendaylight.protocol.concepts.SharedRiskLinkGroup;
24 import org.opendaylight.protocol.concepts.TEMetric;
25 import org.opendaylight.protocol.pcep.PCEPErrors;
26 import org.opendaylight.protocol.pcep.PCEPOFCodes;
27 import org.opendaylight.protocol.pcep.PCEPObject;
28 import org.opendaylight.protocol.pcep.PCEPTlv;
29 import org.opendaylight.protocol.pcep.concepts.UnnumberedInterfaceIdentifier;
30 import org.opendaylight.protocol.pcep.message.PCEPOpenMessage;
31 import org.opendaylight.protocol.pcep.object.CompositeErrorObject;
32 import org.opendaylight.protocol.pcep.object.CompositeNotifyObject;
33 import org.opendaylight.protocol.pcep.object.CompositePathObject;
34 import org.opendaylight.protocol.pcep.object.CompositeReplySvecObject;
35 import org.opendaylight.protocol.pcep.object.CompositeRequestObject;
36 import org.opendaylight.protocol.pcep.object.CompositeRequestSvecObject;
37 import org.opendaylight.protocol.pcep.object.CompositeResponseObject;
38 import org.opendaylight.protocol.pcep.object.CompositeRptPathObject;
39 import org.opendaylight.protocol.pcep.object.CompositeStateReportObject;
40 import org.opendaylight.protocol.pcep.object.CompositeUpdPathObject;
41 import org.opendaylight.protocol.pcep.object.CompositeUpdateRequestObject;
42 import org.opendaylight.protocol.pcep.object.PCEPClassTypeObject;
43 import org.opendaylight.protocol.pcep.object.PCEPEndPoints;
44 import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject;
45 import org.opendaylight.protocol.pcep.object.PCEPErrorObject;
46 import org.opendaylight.protocol.pcep.object.PCEPExcludeRouteObject;
47 import org.opendaylight.protocol.pcep.object.PCEPExistingPathBandwidthObject;
48 import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject;
49 import org.opendaylight.protocol.pcep.object.PCEPGlobalConstraintsObject;
50 import org.opendaylight.protocol.pcep.object.PCEPIncludeRouteObject;
51 import org.opendaylight.protocol.pcep.object.PCEPLoadBalancingObject;
52 import org.opendaylight.protocol.pcep.object.PCEPLspObject;
53 import org.opendaylight.protocol.pcep.object.PCEPLspaObject;
54 import org.opendaylight.protocol.pcep.object.PCEPMetricObject;
55 import org.opendaylight.protocol.pcep.object.PCEPNoPathObject;
56 import org.opendaylight.protocol.pcep.object.PCEPNotificationObject;
57 import org.opendaylight.protocol.pcep.object.PCEPObjectiveFunctionObject;
58 import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
59 import org.opendaylight.protocol.pcep.object.PCEPP2MPEndPointsObject;
60 import org.opendaylight.protocol.pcep.object.PCEPReportedRouteObject;
61 import org.opendaylight.protocol.pcep.object.PCEPRequestParameterObject;
62 import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject;
63 import org.opendaylight.protocol.pcep.object.PCEPSvecObject;
64 import org.opendaylight.protocol.pcep.subobject.EROAsNumberSubobject;
65 import org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject;
66 import org.opendaylight.protocol.pcep.subobject.EROUnnumberedInterfaceSubobject;
67 import org.opendaylight.protocol.pcep.subobject.ExcludeRouteSubobject;
68 import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject;
69 import org.opendaylight.protocol.pcep.subobject.RROAsNumberSubobject;
70 import org.opendaylight.protocol.pcep.subobject.RROIPAddressSubobject;
71 import org.opendaylight.protocol.pcep.subobject.RROUnnumberedInterfaceSubobject;
72 import org.opendaylight.protocol.pcep.subobject.ReportedRouteSubobject;
73 import org.opendaylight.protocol.pcep.subobject.XROAsNumberSubobject;
74 import org.opendaylight.protocol.pcep.subobject.XROIPPrefixSubobject;
75 import org.opendaylight.protocol.pcep.subobject.XROSRLGSubobject;
76 import org.opendaylight.protocol.pcep.subobject.XROSubobjectAttribute;
77 import org.opendaylight.protocol.pcep.subobject.XROUnnumberedInterfaceSubobject;
78 import org.opendaylight.protocol.pcep.tlv.OrderTlv;
79 import org.opendaylight.protocol.util.ByteArray;
80 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Bandwidth;
83 import com.google.common.collect.Lists;
88 public class ObjectsTest {
90 private final AsNumber as = new AsNumber((long) 2555);
93 public void compositeErrorObjectTest() {
95 final List<PCEPErrorObject> errorObjects = new ArrayList<PCEPErrorObject>() {
96 private static final long serialVersionUID = 1L;
99 this.add(new PCEPErrorObject(PCEPErrors.ATTEMPT_2ND_SESSION));
103 final List<PCEPRequestParameterObject> errorParams = new ArrayList<PCEPRequestParameterObject>() {
104 private static final long serialVersionUID = 1L;
107 this.add(new PCEPRequestParameterObject(true, true, true, true, true, false, false, false, (short) 1, 1, true, true));
110 final CompositeErrorObject m = new CompositeErrorObject(errorParams, errorObjects);
111 final CompositeErrorObject m2 = new CompositeErrorObject(errorParams, errorObjects);
112 final CompositeErrorObject m3 = new CompositeErrorObject(errorObjects);
115 assertEquals(m.toString(), m2.toString());
116 assertEquals(m.hashCode(), m2.hashCode());
117 assertEquals(m.getCompositeAsList(), m2.getCompositeAsList());
118 assertEquals(m.getErrors(), m2.getErrors());
119 assertEquals(m.getRequestParameters(), m2.getRequestParameters());
120 assertEquals(m, CompositeErrorObject.getCompositeFromList(m.getCompositeAsList()));
121 assertFalse(m.equals(null));
122 assertFalse(m.equals(m3));
123 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
124 assertTrue(m.equals(m));
128 public void compositeNotifyObjectTest() {
130 final List<PCEPNotificationObject> notifications = new ArrayList<PCEPNotificationObject>() {
131 private static final long serialVersionUID = 1L;
134 this.add(new PCEPNotificationObject((short) 2, (short) 3));
138 final List<PCEPRequestParameterObject> reqParams = new ArrayList<PCEPRequestParameterObject>() {
139 private static final long serialVersionUID = 1L;
142 this.add(new PCEPRequestParameterObject(true, true, true, true, true, false, false, false, (short) 1, 1, true, true));
145 final CompositeNotifyObject m = new CompositeNotifyObject(reqParams, notifications);
146 final CompositeNotifyObject m2 = new CompositeNotifyObject(reqParams, notifications);
147 final CompositeNotifyObject m3 = new CompositeNotifyObject(notifications);
150 assertEquals(m.toString(), m2.toString());
151 assertEquals(m.hashCode(), m2.hashCode());
152 assertEquals(m.getCompositeAsList(), m2.getCompositeAsList());
153 assertEquals(m.getNotificationObjects(), m2.getNotificationObjects());
154 assertEquals(m.getRequestParameters(), m2.getRequestParameters());
155 assertEquals(m, CompositeNotifyObject.getCompositeFromList(m.getCompositeAsList()));
156 assertFalse(m.equals(null));
157 assertFalse(m.equals(m3));
158 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
159 assertTrue(m.equals(m));
163 public void compositePathObjectTest() {
165 final List<ExplicitRouteSubobject> subobjects = new ArrayList<ExplicitRouteSubobject>() {
166 private static final long serialVersionUID = 1L;
169 this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false));
173 final CompositePathObject m = new CompositePathObject(new PCEPExplicitRouteObject(subobjects, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList<PCEPMetricObject>() {
174 private static final long serialVersionUID = 1L;
177 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
179 }, new PCEPIncludeRouteObject(subobjects, true, true));
180 final CompositePathObject m2 = new CompositePathObject(new PCEPExplicitRouteObject(subobjects, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList<PCEPMetricObject>() {
181 private static final long serialVersionUID = 1L;
184 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
186 }, new PCEPIncludeRouteObject(subobjects, true, true));
187 final CompositePathObject m3 = new CompositePathObject(new PCEPExplicitRouteObject(subobjects, false));
190 assertEquals(m.toString(), m2.toString());
191 // assertEquals(m.hashCode(), m2.hashCode());
192 // assertEquals(m.getCompositeAsList(), m2.getCompositeAsList());
193 // assertEquals(m.getBandwidth(), m2.getBandwidth());
194 assertEquals(m.getExcludedRoute(), m2.getExcludedRoute());
195 assertEquals(m.getIncludeRoute(), m2.getIncludeRoute());
196 assertEquals(m.getLspa(), m2.getLspa());
197 assertEquals(m.getMetrics(), m2.getMetrics());
198 assertEquals(m, CompositePathObject.getCompositeFromList(m.getCompositeAsList()));
199 assertFalse(m.equals(null));
200 assertFalse(m.equals(m3));
201 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
202 assertTrue(m.equals(m));
206 public void compositeRptPathObjectTest() {
208 final List<ExplicitRouteSubobject> eroSubobjects = new ArrayList<ExplicitRouteSubobject>() {
209 private static final long serialVersionUID = 1L;
212 this.add(new EROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), new UnnumberedInterfaceIdentifier(2), true));
213 this.add(new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 12, (byte) 122,
214 (byte) 125, (byte) 2 }), 22), false));
218 final List<ReportedRouteSubobject> rroSubobjects = new ArrayList<ReportedRouteSubobject>() {
219 private static final long serialVersionUID = 1L;
222 this.add(new RROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), new UnnumberedInterfaceIdentifier(2)));
223 this.add(new RROIPAddressSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(new byte[] { (byte) 12, (byte) 122,
224 (byte) 125, (byte) 2 }), 22), true, false));
228 final CompositeRptPathObject m = new CompositeRptPathObject(new PCEPExplicitRouteObject(eroSubobjects, false), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new PCEPReportedRouteObject(rroSubobjects, false), new ArrayList<PCEPMetricObject>() {
229 private static final long serialVersionUID = 1L;
232 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
235 final CompositeRptPathObject m2 = new CompositeRptPathObject(new PCEPExplicitRouteObject(eroSubobjects, false), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new PCEPReportedRouteObject(rroSubobjects, false), new ArrayList<PCEPMetricObject>() {
236 private static final long serialVersionUID = 1L;
239 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
242 final CompositePathObject m3 = new CompositePathObject(new PCEPExplicitRouteObject(eroSubobjects, false));
244 // assertEquals(m, m2);
245 // assertEquals(m.toString(), m2.toString());
246 // assertEquals(m.hashCode(), m2.hashCode());
247 // assertEquals(m.getCompositeAsList(), m2.getCompositeAsList());
248 // assertEquals(m.getBandwidth(), m2.getBandwidth());
249 assertEquals(m.getExcludedRoute(), m2.getExcludedRoute());
250 assertEquals(m.getLspa(), m2.getLspa());
251 assertEquals(m.getMetrics(), m2.getMetrics());
252 assertEquals(m, CompositeRptPathObject.getCompositeFromList(m.getCompositeAsList()));
253 assertFalse(m.equals(null));
254 assertFalse(m.equals(m3));
255 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
256 assertTrue(m.equals(m));
260 public void compositeUpdPathObjectTest() {
262 final List<ExplicitRouteSubobject> subobjects = new ArrayList<ExplicitRouteSubobject>() {
263 private static final long serialVersionUID = 1L;
266 this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false));
270 final CompositeUpdPathObject m = new CompositeUpdPathObject(new PCEPExplicitRouteObject(subobjects, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList<PCEPMetricObject>() {
271 private static final long serialVersionUID = 1L;
274 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
277 final CompositeUpdPathObject m2 = new CompositeUpdPathObject(new PCEPExplicitRouteObject(subobjects, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList<PCEPMetricObject>() {
278 private static final long serialVersionUID = 1L;
281 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
284 final CompositeUpdPathObject m3 = new CompositeUpdPathObject(new PCEPExplicitRouteObject(subobjects, false));
287 // assertEquals(m, m2);
288 // assertEquals(m.toString(), m2.toString());
289 // assertEquals(m.hashCode(), m2.hashCode());
290 // assertEquals(m.getCompositeAsList(), m2.getCompositeAsList());
291 // assertEquals(m.getBandwidth(), m2.getBandwidth());
292 assertEquals(m.getExcludedRoute(), m2.getExcludedRoute());
293 assertEquals(m.getLspa(), m2.getLspa());
294 assertEquals(m.getMetrics(), m2.getMetrics());
295 assertEquals(m, CompositeUpdPathObject.getCompositeFromList(m.getCompositeAsList()));
296 assertFalse(m.equals(null));
297 assertFalse(m.equals(m3));
298 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
299 assertTrue(m.equals(m));
303 public void compositeRequestedObjectTest() {
305 final List<ExplicitRouteSubobject> eroSubobjects = new ArrayList<ExplicitRouteSubobject>() {
306 private static final long serialVersionUID = 1L;
309 this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false));
313 final List<ReportedRouteSubobject> rroSubobjects = new ArrayList<ReportedRouteSubobject>() {
314 private static final long serialVersionUID = 1L;
317 this.add(new RROAsNumberSubobject(ObjectsTest.this.as));
321 final CompositeRequestObject m = new CompositeRequestObject(new PCEPRequestParameterObject(true, true, true, true, true, true, false, false, false, (short) 1, 1, new ArrayList<PCEPTlv>() {
322 private static final long serialVersionUID = 1L;
324 this.add(new OrderTlv(1L, 2L));
326 }, true, true), new PCEPEndPointsObject<IPv4Address>(new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), new IPv4Address(new byte[] {
327 (byte) 127, (byte) 0, (byte) 0, (byte) 1 })), new PCEPClassTypeObject((short) 2), new PCEPLspObject((short) 1, true, true, true, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList<PCEPMetricObject>() {
328 private static final long serialVersionUID = 1L;
331 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
333 }, new PCEPReportedRouteObject(rroSubobjects, true), new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new PCEPIncludeRouteObject(eroSubobjects, true, true), new PCEPLoadBalancingObject(2, new Bandwidth(ByteArray.floatToBytes((float) 0.2)), true));
334 final CompositeRequestObject m2 = new CompositeRequestObject(new PCEPRequestParameterObject(true, true, true, true, true, true, false, false, false, (short) 1, 1, new ArrayList<PCEPTlv>() {
335 private static final long serialVersionUID = 1L;
337 this.add(new OrderTlv(1L, 2L));
339 }, true, true), new PCEPEndPointsObject<IPv4Address>(new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), new IPv4Address(new byte[] {
340 (byte) 127, (byte) 0, (byte) 0, (byte) 1 })), new PCEPClassTypeObject((short) 2), new PCEPLspObject((short) 1, true, true, true, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList<PCEPMetricObject>() {
341 private static final long serialVersionUID = 1L;
344 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
346 }, new PCEPReportedRouteObject(rroSubobjects, true), new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new PCEPIncludeRouteObject(eroSubobjects, true, true), new PCEPLoadBalancingObject(2, new Bandwidth(ByteArray.floatToBytes((float) 0.2)), true));
347 final CompositeRequestObject m3 = new CompositeRequestObject(new PCEPRequestParameterObject(true, true, true, true, true, true, false, false, false, (short) 1, 1, new ArrayList<PCEPTlv>() {
348 private static final long serialVersionUID = 1L;
350 this.add(new OrderTlv(1L, 2L));
352 }, true, true), new PCEPEndPointsObject<IPv4Address>(new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }), new IPv4Address(new byte[] {
353 (byte) 127, (byte) 0, (byte) 0, (byte) 1 })));
356 // assertEquals(m, m2);
357 // assertEquals(m.toString(), m2.toString());
358 // assertEquals(m.hashCode(), m2.hashCode());
359 // assertEquals(m.getCompositeAsList(), m2.getCompositeAsList());
360 // assertEquals(m.getBandwidth(), m2.getBandwidth());
361 assertEquals(m.getLspa(), m2.getLspa());
362 assertEquals(m.getMetrics(), m2.getMetrics());
363 assertEquals(m.getClassType(), m2.getClassType());
364 assertEquals(m.getEndPoints(), m2.getEndPoints());
365 assertEquals(m.getIncludeRoute(), m2.getIncludeRoute());
366 assertEquals(m.getLsp(), m2.getLsp());
367 // assertEquals(m.getRroBandwidth(), m2.getRroBandwidth());
368 assertEquals(m, CompositeRequestObject.getCompositeFromList(m.getCompositeAsList()));
369 assertFalse(m.equals(null));
370 assertFalse(m.equals(m3));
371 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
372 assertTrue(m.equals(m));
376 public void compositeResponseObjectTest() {
378 final List<ExplicitRouteSubobject> subobjects = new ArrayList<ExplicitRouteSubobject>() {
379 private static final long serialVersionUID = 1L;
382 this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false));
386 final List<CompositePathObject> paths = new ArrayList<CompositePathObject>() {
387 private static final long serialVersionUID = 1L;
390 this.add(new CompositePathObject(new PCEPExplicitRouteObject(subobjects, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList<PCEPMetricObject>() {
391 private static final long serialVersionUID = 1L;
394 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
396 }, new PCEPIncludeRouteObject(subobjects, true, true)));
400 final CompositeResponseObject m = new CompositeResponseObject(new PCEPRequestParameterObject(true, true, true, true, true, false, false, false, (short) 1, 1, true, true), new PCEPNoPathObject((short) 2, true, false), new PCEPLspObject((short) 1, true, true, true, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList<PCEPMetricObject>() {
401 private static final long serialVersionUID = 1L;
404 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
406 }, new PCEPIncludeRouteObject(subobjects, true, true), paths);
407 final CompositeResponseObject m2 = new CompositeResponseObject(new PCEPRequestParameterObject(true, true, true, true, true, false, false, false, (short) 1, 1, true, true), new PCEPNoPathObject((short) 2, true, false), new PCEPLspObject((short) 1, true, true, true, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList<PCEPMetricObject>() {
408 private static final long serialVersionUID = 1L;
411 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
413 }, new PCEPIncludeRouteObject(subobjects, true, true), paths);
414 final CompositeResponseObject m3 = new CompositeResponseObject(new PCEPRequestParameterObject(true, true, true, true, true, false, false, false, (short) 1, 1, true, true));
417 // assertEquals(m, m2);
418 // assertEquals(m.toString(), m2.toString());
419 // assertEquals(m.hashCode(), m2.hashCode());
420 // assertEquals(m.getCompositeAsList(), m2.getCompositeAsList());
421 // assertEquals(m.getBandwidth(), m2.getBandwidth());
422 assertEquals(m.getLspa(), m2.getLspa());
423 assertEquals(m.getMetrics(), m2.getMetrics());
424 assertEquals(m.getIncludeRoute(), m2.getIncludeRoute());
425 assertEquals(m.getLsp(), m2.getLsp());
426 assertEquals(m.getPaths(), m2.getPaths());
427 assertEquals(m.getRequestParameter(), m2.getRequestParameter());
428 assertEquals(m, CompositeResponseObject.getCompositeFromList(m.getCompositeAsList()));
429 assertFalse(m.equals(null));
430 assertFalse(m.equals(m3));
431 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
432 assertTrue(m.equals(m));
436 public void compositeStateReportObjectTest() {
438 final List<ExplicitRouteSubobject> eroSubobjects = new ArrayList<ExplicitRouteSubobject>() {
439 private static final long serialVersionUID = 1L;
442 this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false));
446 final List<ReportedRouteSubobject> rroSubobjects = new ArrayList<ReportedRouteSubobject>() {
447 private static final long serialVersionUID = 1L;
450 this.add(new RROAsNumberSubobject(ObjectsTest.this.as));
454 final List<CompositeRptPathObject> paths = new ArrayList<CompositeRptPathObject>() {
455 private static final long serialVersionUID = 1L;
458 this.add(new CompositeRptPathObject(new PCEPExplicitRouteObject(eroSubobjects, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new PCEPReportedRouteObject(rroSubobjects, true), new ArrayList<PCEPMetricObject>() {
459 private static final long serialVersionUID = 1L;
462 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
468 final CompositeStateReportObject m = new CompositeStateReportObject(new PCEPLspObject((short) 1, true, true, true, true), paths);
469 final CompositeStateReportObject m2 = new CompositeStateReportObject(new PCEPLspObject((short) 1, true, true, true, true), paths);
470 final CompositeStateReportObject m3 = new CompositeStateReportObject(new PCEPLspObject((short) 1, true, true, true, true));
473 assertEquals(m.toString(), m2.toString());
474 assertEquals(m.hashCode(), m2.hashCode());
475 assertEquals(m.getCompositeAsList(), m2.getCompositeAsList());
476 assertEquals(m.getLsp(), m2.getLsp());
477 assertEquals(m.getPaths(), m2.getPaths());
478 assertEquals(m, CompositeStateReportObject.getCompositeFromList(m.getCompositeAsList()));
479 assertFalse(m.equals(null));
480 assertFalse(m.equals(m3));
481 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
482 assertTrue(m.equals(m));
486 public void compositeUpdateRequestObjectTest() {
488 final List<ExplicitRouteSubobject> subobjects = new ArrayList<ExplicitRouteSubobject>() {
489 private static final long serialVersionUID = 1L;
492 this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false));
496 final List<CompositeUpdPathObject> paths = new ArrayList<CompositeUpdPathObject>() {
497 private static final long serialVersionUID = 1L;
500 this.add(new CompositeUpdPathObject(new PCEPExplicitRouteObject(subobjects, true), new PCEPLspaObject(2, 2, 2, (short) 2, (short) 2, true, true, true, true), new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes((float) 0.222)), true, true), new ArrayList<PCEPMetricObject>() {
501 private static final long serialVersionUID = 1L;
504 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
510 final CompositeUpdateRequestObject m = new CompositeUpdateRequestObject(new PCEPLspObject((short) 1, true, true, true, true), paths);
511 final CompositeUpdateRequestObject m2 = new CompositeUpdateRequestObject(new PCEPLspObject((short) 1, true, true, true, true), paths);
512 final CompositeUpdateRequestObject m3 = new CompositeUpdateRequestObject(new PCEPLspObject((short) 1, true, true, true, true));
515 assertEquals(m.toString(), m2.toString());
516 assertEquals(m.hashCode(), m2.hashCode());
517 assertEquals(m.getCompositeAsList(), m2.getCompositeAsList());
518 assertEquals(m.getLsp(), m2.getLsp());
519 assertEquals(m.getPaths(), m2.getPaths());
520 assertEquals(m, CompositeUpdateRequestObject.getCompositeFromList(m.getCompositeAsList()));
521 assertFalse(m.equals(null));
522 assertFalse(m.equals(m3));
523 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
524 assertTrue(m.equals(m));
528 public void compositeRequestSVECObjectTest() {
530 final List<ExcludeRouteSubobject> subobjects = new ArrayList<ExcludeRouteSubobject>() {
531 private static final long serialVersionUID = 1L;
534 this.add(new XROAsNumberSubobject(ObjectsTest.this.as, false));
538 final List<Long> requestIds = new ArrayList<Long>() {
539 private static final long serialVersionUID = 1L;
542 this.add(0x12345678L);
546 final CompositeRequestSvecObject m = new CompositeRequestSvecObject(new PCEPSvecObject(true, true, true, false, false, requestIds, true), new PCEPObjectiveFunctionObject(PCEPOFCodes.MBC, true, false), new PCEPGlobalConstraintsObject((short) 2, (short) 2, (short) 2, (short) 2, true, false), new PCEPExcludeRouteObject(subobjects, true, true, false), new ArrayList<PCEPMetricObject>() {
547 private static final long serialVersionUID = 1L;
550 this.add(new PCEPMetricObject(true, true, new TEMetric(0x123456), true, false));
553 final CompositeRequestSvecObject m2 = new CompositeRequestSvecObject(new PCEPSvecObject(true, true, true, false, false, requestIds, true), new PCEPObjectiveFunctionObject(PCEPOFCodes.MBC, true, false), new PCEPGlobalConstraintsObject((short) 2, (short) 2, (short) 2, (short) 2, true, false), new PCEPExcludeRouteObject(subobjects, true, true, false), new ArrayList<PCEPMetricObject>() {
554 private static final long serialVersionUID = 1L;
557 this.add(new PCEPMetricObject(true, true, new TEMetric(0x123456), true, false));
560 final CompositeRequestSvecObject m3 = new CompositeRequestSvecObject(new PCEPSvecObject(true, true, true, false, false, requestIds, true));
563 assertEquals(m.toString(), m2.toString());
564 assertEquals(m.hashCode(), m2.hashCode());
565 assertEquals(m.getCompositeAsList(), m2.getCompositeAsList());
566 assertEquals(m.getExcludeRoute(), m2.getExcludeRoute());
567 assertEquals(m.getGlobalConstraints(), m2.getGlobalConstraints());
568 assertEquals(m.getObjectiveFunction(), m2.getObjectiveFunction());
569 assertEquals(m.getSvec(), m2.getSvec());
570 assertEquals(m, CompositeRequestSvecObject.getCompositeFromList(m.getCompositeAsList()));
571 assertFalse(m.equals(null));
572 assertFalse(m.equals(m3));
573 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
574 assertTrue(m.equals(m));
578 public void compositeRplySVECObjectTest() {
580 final List<Long> requestIds = new ArrayList<Long>() {
581 private static final long serialVersionUID = 1L;
584 this.add(0x12345678L);
588 final CompositeReplySvecObject m = new CompositeReplySvecObject(new PCEPSvecObject(true, true, true, false, false, requestIds, true), new PCEPObjectiveFunctionObject(PCEPOFCodes.MBC, true, false), new ArrayList<PCEPMetricObject>() {
589 private static final long serialVersionUID = 1L;
592 this.add(new PCEPMetricObject(true, true, new TEMetric(0x123456), true, false));
595 final CompositeReplySvecObject m2 = new CompositeReplySvecObject(new PCEPSvecObject(true, true, true, false, false, requestIds, true), new PCEPObjectiveFunctionObject(PCEPOFCodes.MBC, true, false), new ArrayList<PCEPMetricObject>() {
596 private static final long serialVersionUID = 1L;
599 this.add(new PCEPMetricObject(true, true, new TEMetric(0x123456), true, false));
602 final CompositeReplySvecObject m3 = new CompositeReplySvecObject(new PCEPSvecObject(true, true, true, false, false, requestIds, true));
605 assertEquals(m.toString(), m2.toString());
606 assertEquals(m.hashCode(), m2.hashCode());
607 assertEquals(m.getCompositeAsList(), m2.getCompositeAsList());
608 assertEquals(m.getObjectiveFunction(), m2.getObjectiveFunction());
609 assertEquals(m.getSvec(), m2.getSvec());
610 assertEquals(m, CompositeReplySvecObject.getCompositeFromList(m.getCompositeAsList()));
611 assertFalse(m.equals(null));
612 assertFalse(m.equals(m3));
613 assertFalse(m.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
614 assertTrue(m.equals(m));
618 public void subobjectsTest() {
619 final EROAsNumberSubobject xas = new EROAsNumberSubobject(this.as, false);
620 final EROUnnumberedInterfaceSubobject uis = new EROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { (byte) 127, (byte) 0,
621 (byte) 0, (byte) 2 }), new UnnumberedInterfaceIdentifier(2), true);
622 final EROIPPrefixSubobject<IPv4Prefix> ips = new EROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(new byte[] {
623 (byte) 12, (byte) 122, (byte) 125, (byte) 2 }), 22), false);
625 assertEquals(xas.getASNumber().getValue().longValue(), 2555);
626 assertEquals(xas.isLoose(), false);
627 assertFalse(xas.equals(null));
628 assertFalse(xas.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
629 assertTrue(xas.equals(xas));
631 assertEquals(uis.getInterfaceID().getInterfaceId(), 2);
632 assertEquals(uis.getRouterID(), new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }));
633 assertEquals(uis.isLoose(), true);
634 assertFalse(uis.equals(null));
635 assertFalse(uis.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
636 assertTrue(uis.equals(uis));
638 assertEquals(ips.getPrefix(), new IPv4Prefix(new IPv4Address(new byte[] { (byte) 12, (byte) 122, (byte) 125, (byte) 2 }), 22));
639 assertEquals(ips.isLoose(), false);
640 assertFalse(ips.equals(null));
641 assertFalse(ips.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
642 assertTrue(ips.equals(ips));
646 public void xroSubobjectsTest() {
647 final XROAsNumberSubobject xas = new XROAsNumberSubobject(this.as, false);
648 final XROUnnumberedInterfaceSubobject uis = new XROUnnumberedInterfaceSubobject(new IPv4Address(new byte[] { (byte) 127, (byte) 0,
649 (byte) 0, (byte) 2 }), new UnnumberedInterfaceIdentifier(2), true, XROSubobjectAttribute.SRLG);
650 final XROIPPrefixSubobject<IPv4Prefix> ips = new XROIPPrefixSubobject<IPv4Prefix>(new IPv4Prefix(new IPv4Address(new byte[] {
651 (byte) 12, (byte) 122, (byte) 125, (byte) 2 }), 22), false, XROSubobjectAttribute.SRLG);
652 final XROSRLGSubobject srlg = new XROSRLGSubobject(new SharedRiskLinkGroup(0x1234L), true);
654 assertEquals(xas.getASNumber().getValue().longValue(), 2555);
655 assertEquals(xas.isMandatory(), false);
656 assertFalse(xas.equals(null));
657 assertFalse(xas.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
658 assertTrue(xas.equals(xas));
661 // assertEquals(xas.toString(), "XROAsNumberSubobject [asnumber=AsNumber [_value=2555], mandatory=false]");
663 assertEquals(uis.getInterfaceID().getInterfaceId(), 2);
664 assertEquals(uis.getRouterID(), new IPv4Address(new byte[] { (byte) 127, (byte) 0, (byte) 0, (byte) 2 }));
665 assertEquals(uis.isMandatory(), true);
666 assertFalse(uis.equals(null));
667 assertFalse(uis.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
668 assertTrue(uis.equals(uis));
669 assertEquals(uis.getAttribute(), XROSubobjectAttribute.SRLG);
672 "XROUnnumberedInterfaceSubobject [attribute=SRLG, interfaceID=UnnumberedInterfaceIdentifier [interfaceId=2], routerID=127.0.0.2, mandatory=true]");
674 assertEquals(ips.getPrefix(), new IPv4Prefix(new IPv4Address(new byte[] { (byte) 12, (byte) 122, (byte) 125, (byte) 2 }), 22));
675 assertEquals(ips.isMandatory(), false);
676 assertFalse(ips.equals(null));
677 assertFalse(ips.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
678 assertTrue(ips.equals(ips));
679 assertEquals(ips.getAttribute(), XROSubobjectAttribute.SRLG);
680 assertEquals(ips.toString(), "XROIPPrefixSubobject [attribute=SRLG, prefix=12.122.124.0/22, mandatory=false]");
682 assertEquals(srlg.getSrlgId().getValue(), 0x1234L);
683 assertEquals(srlg.getAttribute(), XROSubobjectAttribute.SRLG);
684 assertFalse(srlg.equals(null));
685 assertFalse(srlg.equals(new PCEPOpenMessage(new PCEPOpenObject(10, 10, 1))));
686 assertTrue(srlg.equals(srlg));
687 assertEquals(srlg.toString(), "XROSRLGSubobject [attribute=SRLG, srlgId=4660, mandatory=true]");
691 public void testToString() {
692 final List<PCEPObject> objects = Lists.newArrayList();
693 objects.add(new PCEPExistingPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(22)), true, false));
694 objects.add(new PCEPRequestedPathBandwidthObject(new Bandwidth(ByteArray.floatToBytes(22)), true, false));
695 objects.add(new PCEPEndPointsObject<IPv4Address>(IPv4.FAMILY.addressForBytes(new byte[] { 1, 1, 1, 1 }), IPv4.FAMILY.addressForBytes(new byte[] {
697 objects.add(new PCEPP2MPEndPointsObject<IPv4Address>(0, IPv4.FAMILY.addressForBytes(new byte[] { 1, 1, 1, 1 }), Lists.newArrayList(IPv4.FAMILY.addressForBytes(new byte[] {
698 1, 1, 1, 1 })), true, false));
700 for (final PCEPObject o : objects) {
701 assertThat(o.toString(), containsString("processed=true"));
702 assertThat(o.toString(), containsString("ignored=false"));
704 // if (o instanceof PCEPBandwidthObject)
705 // assertThat(o.toString(), containsString("bandwidth=Bandwidth [_value=22.0]"));
706 if (o instanceof PCEPEndPoints)
707 assertThat(o.toString(), containsString("sourceAddress=1.1.1.1"));
708 if (o instanceof PCEPP2MPEndPointsObject)
709 assertThat(o.toString(), containsString("destinationAddresses=[1.1.1.1]"));