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.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotSame;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
16 import java.net.InetAddress;
17 import java.net.UnknownHostException;
19 import org.junit.Test;
21 import org.opendaylight.protocol.concepts.IPv4Address;
22 import org.opendaylight.protocol.concepts.IPv6Address;
23 import org.opendaylight.protocol.pcep.concepts.AbstractExtendedTunnelIdentifier;
24 import org.opendaylight.protocol.pcep.concepts.AggregateBandwidthConsumptionMetric;
25 import org.opendaylight.protocol.pcep.concepts.CumulativeIGPCostMetric;
26 import org.opendaylight.protocol.pcep.concepts.CumulativeTECostMetric;
27 import org.opendaylight.protocol.pcep.concepts.IPv4ExtendedTunnelIdentifier;
28 import org.opendaylight.protocol.pcep.concepts.IPv6ExtendedTunnelIdentifier;
29 import org.opendaylight.protocol.pcep.concepts.LSPIdentifier;
30 import org.opendaylight.protocol.pcep.concepts.LSPSymbolicName;
31 import org.opendaylight.protocol.pcep.concepts.MostLoadedLinkLoadMetric;
32 import org.opendaylight.protocol.pcep.concepts.TunnelIdentifier;
33 import org.opendaylight.protocol.pcep.concepts.UnnumberedInterfaceIdentifier;
35 public class ConceptsTest {
38 public void testConcepts() throws UnknownHostException {
39 final AbstractExtendedTunnelIdentifier<IPv4Address> t1 = new AbstractExtendedTunnelIdentifier<IPv4Address>(new IPv4Address(
40 InetAddress.getByName("127.0.0.1"))) {
41 private static final long serialVersionUID = 445350555352830607L;
44 final AbstractExtendedTunnelIdentifier<IPv4Address> t2 = new AbstractExtendedTunnelIdentifier<IPv4Address>(new IPv4Address(
45 InetAddress.getByName("127.0.0.2"))) {
46 private static final long serialVersionUID = 572633522583009640L;
49 final AbstractExtendedTunnelIdentifier<IPv4Address> t3 = new AbstractExtendedTunnelIdentifier<IPv4Address>(new IPv4Address(
50 InetAddress.getByName("127.0.0.1"))) {
51 private static final long serialVersionUID = 445350555352830607L;
54 assertNotSame(t1, t2);
55 assertEquals(-1, t1.compareTo(t2));
56 assertEquals(t1.hashCode(), t3.hashCode());
57 assertEquals(t1.toString(), t3.toString());
59 final IPv4ExtendedTunnelIdentifier v4 = new IPv4ExtendedTunnelIdentifier(new IPv4Address(InetAddress.getByName("127.0.0.1")));
60 final IPv6ExtendedTunnelIdentifier v6 = new IPv6ExtendedTunnelIdentifier(new IPv6Address(InetAddress.getByName("2001:db8:85a3::8a2e:370:7333")));
61 assertTrue(v4 instanceof AbstractExtendedTunnelIdentifier);
62 assertTrue(v6 instanceof AbstractExtendedTunnelIdentifier);
64 final LSPIdentifier id1 = new LSPIdentifier(new byte[] { 1, 2 });
65 final LSPIdentifier id2 = new LSPIdentifier(new byte[] { 1, 3 });
66 final LSPIdentifier id3 = new LSPIdentifier(new byte[] { 1, 3 });
68 assertNotSame(id1, id2);
69 assertNotSame(id1.getLspId(), id2.getLspId());
70 assertEquals(id3.toString(), id2.toString());
72 final LSPSymbolicName n1 = new LSPSymbolicName(new byte[] { 5 });
73 final LSPSymbolicName n2 = new LSPSymbolicName(new byte[] { 6, 3 });
74 final LSPSymbolicName n3 = new LSPSymbolicName(new byte[] { 5 });
75 assertNotSame(n1.getSymbolicName(), n2.getSymbolicName());
77 assertEquals(n1.toString(), n3.toString());
79 final TunnelIdentifier ti1 = new TunnelIdentifier(new byte[] { 2, 4 });
80 final TunnelIdentifier ti2 = new TunnelIdentifier(new byte[] { 2, 4 });
81 assertArrayEquals(ti1.getBytes(), ti2.getBytes());
82 assertEquals(ti1, ti2);
83 assertEquals(ti1.toString(), ti2.toString());
85 final UnnumberedInterfaceIdentifier u1 = new UnnumberedInterfaceIdentifier(3000);
86 final UnnumberedInterfaceIdentifier u2 = new UnnumberedInterfaceIdentifier(4000);
87 final UnnumberedInterfaceIdentifier u3 = new UnnumberedInterfaceIdentifier(3000);
89 assertEquals(-1, u1.compareTo(u2));
91 assertEquals(u1.hashCode(), u3.hashCode());
92 assertEquals(u1.getInterfaceId(), u3.getInterfaceId());
93 assertEquals(u1.toString(), u3.toString());
95 final CumulativeIGPCostMetric cigp1 = new CumulativeIGPCostMetric(3000);
96 final CumulativeIGPCostMetric cigp2 = new CumulativeIGPCostMetric(4000);
97 final CumulativeIGPCostMetric cigp3 = new CumulativeIGPCostMetric(3000);
99 new CumulativeIGPCostMetric(-1);
100 fail("Expected exception but no thrown.");
101 } catch (final IllegalArgumentException e) {
104 assertEquals(-1, cigp1.compareTo(cigp2));
105 assertEquals(cigp1, cigp3);
106 assertEquals(cigp1.hashCode(), cigp3.hashCode());
107 assertEquals(cigp1.getValue(), cigp3.getValue());
108 assertEquals(cigp1.toString(), cigp3.toString());
110 final CumulativeTECostMetric cte1 = new CumulativeTECostMetric(3000);
111 final CumulativeTECostMetric cte2 = new CumulativeTECostMetric(4000);
112 final CumulativeTECostMetric cte3 = new CumulativeTECostMetric(3000);
114 assertEquals(-1, cte1.compareTo(cte2));
115 assertEquals(cte1, cte3);
116 assertEquals(cte1.hashCode(), cte3.hashCode());
117 assertEquals(cte1.getValue(), cte3.getValue());
118 assertEquals(cte1.toString(), cte3.toString());
120 new CumulativeTECostMetric(-1);
121 fail("Expected exception but no thrown.");
122 } catch (final IllegalArgumentException e) {
125 final AggregateBandwidthConsumptionMetric agg1 = new AggregateBandwidthConsumptionMetric(3000);
126 final AggregateBandwidthConsumptionMetric agg2 = new AggregateBandwidthConsumptionMetric(4000);
127 final AggregateBandwidthConsumptionMetric agg3 = new AggregateBandwidthConsumptionMetric(3000);
129 assertEquals(-1, agg1.compareTo(agg2));
130 assertEquals(agg1, agg3);
131 assertEquals(agg1.hashCode(), agg3.hashCode());
132 assertEquals(agg1.getValue(), agg3.getValue());
133 assertEquals(agg1.toString(), agg3.toString());
135 new AggregateBandwidthConsumptionMetric(-1);
136 fail("Expected exception but no thrown.");
137 } catch (final IllegalArgumentException e) {
140 final MostLoadedLinkLoadMetric mlm1 = new MostLoadedLinkLoadMetric(3000);
141 final MostLoadedLinkLoadMetric mlm2 = new MostLoadedLinkLoadMetric(4000);
142 final MostLoadedLinkLoadMetric mlm3 = new MostLoadedLinkLoadMetric(3000);
144 assertEquals(-1, mlm1.compareTo(mlm2));
145 assertEquals(mlm1, mlm3);
146 assertEquals(mlm1.hashCode(), mlm3.hashCode());
147 assertEquals(mlm1.getValue(), mlm3.getValue());
148 assertEquals(mlm1.toString(), mlm3.toString());
150 new MostLoadedLinkLoadMetric(-1);
151 fail("Expected exception but no thrown.");
152 } catch (final IllegalArgumentException e) {