Merge "Randomize port to allow concurrent execution"
[bgpcep.git] / pcep / api / src / test / java / org / opendaylight / protocol / pcep / api / ObjectsTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.api;
9
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;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
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;
82
83 import com.google.common.collect.Lists;
84
85 /**
86  *
87  */
88 public class ObjectsTest {
89
90         private final AsNumber as = new AsNumber((long) 2555);
91
92         @Test
93         public void compositeErrorObjectTest() {
94
95                 final List<PCEPErrorObject> errorObjects = new ArrayList<PCEPErrorObject>() {
96                         private static final long serialVersionUID = 1L;
97
98                         {
99                                 this.add(new PCEPErrorObject(PCEPErrors.ATTEMPT_2ND_SESSION));
100                         }
101                 };
102
103                 final List<PCEPRequestParameterObject> errorParams = new ArrayList<PCEPRequestParameterObject>() {
104                         private static final long serialVersionUID = 1L;
105
106                         {
107                                 this.add(new PCEPRequestParameterObject(true, true, true, true, true, false, false, false, (short) 1, 1, true, true));
108                         }
109                 };
110                 final CompositeErrorObject m = new CompositeErrorObject(errorParams, errorObjects);
111                 final CompositeErrorObject m2 = new CompositeErrorObject(errorParams, errorObjects);
112                 final CompositeErrorObject m3 = new CompositeErrorObject(errorObjects);
113
114                 assertEquals(m, m2);
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));
125         }
126
127         @Test
128         public void compositeNotifyObjectTest() {
129
130                 final List<PCEPNotificationObject> notifications = new ArrayList<PCEPNotificationObject>() {
131                         private static final long serialVersionUID = 1L;
132
133                         {
134                                 this.add(new PCEPNotificationObject((short) 2, (short) 3));
135                         }
136                 };
137
138                 final List<PCEPRequestParameterObject> reqParams = new ArrayList<PCEPRequestParameterObject>() {
139                         private static final long serialVersionUID = 1L;
140
141                         {
142                                 this.add(new PCEPRequestParameterObject(true, true, true, true, true, false, false, false, (short) 1, 1, true, true));
143                         }
144                 };
145                 final CompositeNotifyObject m = new CompositeNotifyObject(reqParams, notifications);
146                 final CompositeNotifyObject m2 = new CompositeNotifyObject(reqParams, notifications);
147                 final CompositeNotifyObject m3 = new CompositeNotifyObject(notifications);
148
149                 assertEquals(m, m2);
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));
160         }
161
162         @Test
163         public void compositePathObjectTest() {
164
165                 final List<ExplicitRouteSubobject> subobjects = new ArrayList<ExplicitRouteSubobject>() {
166                         private static final long serialVersionUID = 1L;
167
168                         {
169                                 this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false));
170                         }
171                 };
172
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;
175
176                         {
177                                 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
178                         }
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;
182
183                         {
184                                 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
185                         }
186                 }, new PCEPIncludeRouteObject(subobjects, true, true));
187                 final CompositePathObject m3 = new CompositePathObject(new PCEPExplicitRouteObject(subobjects, false));
188
189                 // FIXME BUG-89
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));
203         }
204
205         @Test
206         public void compositeRptPathObjectTest() {
207
208                 final List<ExplicitRouteSubobject> eroSubobjects = new ArrayList<ExplicitRouteSubobject>() {
209                         private static final long serialVersionUID = 1L;
210
211                         {
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));
215                         }
216                 };
217
218                 final List<ReportedRouteSubobject> rroSubobjects = new ArrayList<ReportedRouteSubobject>() {
219                         private static final long serialVersionUID = 1L;
220
221                         {
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));
225                         }
226                 };
227
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;
230
231                         {
232                                 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
233                         }
234                 });
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;
237
238                         {
239                                 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
240                         }
241                 });
242                 final CompositePathObject m3 = new CompositePathObject(new PCEPExplicitRouteObject(eroSubobjects, false));
243                 // FIXME BUG-89
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));
257         }
258
259         @Test
260         public void compositeUpdPathObjectTest() {
261
262                 final List<ExplicitRouteSubobject> subobjects = new ArrayList<ExplicitRouteSubobject>() {
263                         private static final long serialVersionUID = 1L;
264
265                         {
266                                 this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false));
267                         }
268                 };
269
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;
272
273                         {
274                                 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
275                         }
276                 });
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;
279
280                         {
281                                 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
282                         }
283                 });
284                 final CompositeUpdPathObject m3 = new CompositeUpdPathObject(new PCEPExplicitRouteObject(subobjects, false));
285
286                 // FIXME BUG-89
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));
300         }
301
302         @Test
303         public void compositeRequestedObjectTest() {
304
305                 final List<ExplicitRouteSubobject> eroSubobjects = new ArrayList<ExplicitRouteSubobject>() {
306                         private static final long serialVersionUID = 1L;
307
308                         {
309                                 this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false));
310                         }
311                 };
312
313                 final List<ReportedRouteSubobject> rroSubobjects = new ArrayList<ReportedRouteSubobject>() {
314                         private static final long serialVersionUID = 1L;
315
316                         {
317                                 this.add(new RROAsNumberSubobject(ObjectsTest.this.as));
318                         }
319                 };
320
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;
323                         {
324                                 this.add(new OrderTlv(1L, 2L));
325                         }
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;
329
330                         {
331                                 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
332                         }
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;
336                         {
337                                 this.add(new OrderTlv(1L, 2L));
338                         }
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;
342
343                         {
344                                 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
345                         }
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;
349                         {
350                                 this.add(new OrderTlv(1L, 2L));
351                         }
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 })));
354
355                 // FIXME BUG-89
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));
373         }
374
375         @Test
376         public void compositeResponseObjectTest() {
377
378                 final List<ExplicitRouteSubobject> subobjects = new ArrayList<ExplicitRouteSubobject>() {
379                         private static final long serialVersionUID = 1L;
380
381                         {
382                                 this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false));
383                         }
384                 };
385
386                 final List<CompositePathObject> paths = new ArrayList<CompositePathObject>() {
387                         private static final long serialVersionUID = 1L;
388
389                         {
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;
392
393                                         {
394                                                 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
395                                         }
396                                 }, new PCEPIncludeRouteObject(subobjects, true, true)));
397                         }
398                 };
399
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;
402
403                         {
404                                 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
405                         }
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;
409
410                         {
411                                 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
412                         }
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));
415
416                 // FIXME BUG-89
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));
433         }
434
435         @Test
436         public void compositeStateReportObjectTest() {
437
438                 final List<ExplicitRouteSubobject> eroSubobjects = new ArrayList<ExplicitRouteSubobject>() {
439                         private static final long serialVersionUID = 1L;
440
441                         {
442                                 this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false));
443                         }
444                 };
445
446                 final List<ReportedRouteSubobject> rroSubobjects = new ArrayList<ReportedRouteSubobject>() {
447                         private static final long serialVersionUID = 1L;
448
449                         {
450                                 this.add(new RROAsNumberSubobject(ObjectsTest.this.as));
451                         }
452                 };
453
454                 final List<CompositeRptPathObject> paths = new ArrayList<CompositeRptPathObject>() {
455                         private static final long serialVersionUID = 1L;
456
457                         {
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;
460
461                                         {
462                                                 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
463                                         }
464                                 }));
465                         }
466                 };
467
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));
471
472                 assertEquals(m, m2);
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));
483         }
484
485         @Test
486         public void compositeUpdateRequestObjectTest() {
487
488                 final List<ExplicitRouteSubobject> subobjects = new ArrayList<ExplicitRouteSubobject>() {
489                         private static final long serialVersionUID = 1L;
490
491                         {
492                                 this.add(new EROAsNumberSubobject(ObjectsTest.this.as, false));
493                         }
494                 };
495
496                 final List<CompositeUpdPathObject> paths = new ArrayList<CompositeUpdPathObject>() {
497                         private static final long serialVersionUID = 1L;
498
499                         {
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;
502
503                                         {
504                                                 this.add(new PCEPMetricObject(true, true, new TEMetric(255), true, false));
505                                         }
506                                 }));
507                         }
508                 };
509
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));
513
514                 assertEquals(m, m2);
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));
525         }
526
527         @Test
528         public void compositeRequestSVECObjectTest() {
529
530                 final List<ExcludeRouteSubobject> subobjects = new ArrayList<ExcludeRouteSubobject>() {
531                         private static final long serialVersionUID = 1L;
532
533                         {
534                                 this.add(new XROAsNumberSubobject(ObjectsTest.this.as, false));
535                         }
536                 };
537
538                 final List<Long> requestIds = new ArrayList<Long>() {
539                         private static final long serialVersionUID = 1L;
540
541                         {
542                                 this.add(0x12345678L);
543                         }
544                 };
545
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;
548
549                         {
550                                 this.add(new PCEPMetricObject(true, true, new TEMetric(0x123456), true, false));
551                         }
552                 });
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;
555
556                         {
557                                 this.add(new PCEPMetricObject(true, true, new TEMetric(0x123456), true, false));
558                         }
559                 });
560                 final CompositeRequestSvecObject m3 = new CompositeRequestSvecObject(new PCEPSvecObject(true, true, true, false, false, requestIds, true));
561
562                 assertEquals(m, m2);
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));
575         }
576
577         @Test
578         public void compositeRplySVECObjectTest() {
579
580                 final List<Long> requestIds = new ArrayList<Long>() {
581                         private static final long serialVersionUID = 1L;
582
583                         {
584                                 this.add(0x12345678L);
585                         }
586                 };
587
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;
590
591                         {
592                                 this.add(new PCEPMetricObject(true, true, new TEMetric(0x123456), true, false));
593                         }
594                 });
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;
597
598                         {
599                                 this.add(new PCEPMetricObject(true, true, new TEMetric(0x123456), true, false));
600                         }
601                 });
602                 final CompositeReplySvecObject m3 = new CompositeReplySvecObject(new PCEPSvecObject(true, true, true, false, false, requestIds, true));
603
604                 assertEquals(m, m2);
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));
615         }
616
617         @Test
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);
624
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));
630
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));
637
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));
643         }
644
645         @Test
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);
653
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));
659
660                 // FIXME BUG-89
661                 // assertEquals(xas.toString(), "XROAsNumberSubobject [asnumber=AsNumber [_value=2555], mandatory=false]");
662
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);
670                 assertEquals(
671                                 uis.toString(),
672                                 "XROUnnumberedInterfaceSubobject [attribute=SRLG, interfaceID=UnnumberedInterfaceIdentifier [interfaceId=2], routerID=127.0.0.2, mandatory=true]");
673
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]");
681
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]");
688         }
689
690         @Test
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[] {
696                                 1, 1, 1, 2 })));
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));
699
700                 for (final PCEPObject o : objects) {
701                         assertThat(o.toString(), containsString("processed=true"));
702                         assertThat(o.toString(), containsString("ignored=false"));
703                         // FIXME BUG-89
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]"));
710                 }
711         }
712
713 }