Initial code drop
[bgpcep.git] / bgp / util / src / test / java / org / opendaylight / protocol / bgp / util / PrefixTest.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.bgp.util;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotSame;
12
13 import java.util.Collections;
14
15 import org.junit.Test;
16 import org.opendaylight.protocol.bgp.concepts.ASPath;
17 import org.opendaylight.protocol.bgp.concepts.BGPOrigin;
18 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
19 import org.opendaylight.protocol.bgp.concepts.Community;
20 import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
21 import org.opendaylight.protocol.bgp.util.BGPIPv4PrefixImpl;
22 import org.opendaylight.protocol.bgp.util.BGPIPv6PrefixImpl;
23
24 import org.opendaylight.protocol.concepts.ASNumber;
25 import org.opendaylight.protocol.concepts.IPv4;
26 import org.opendaylight.protocol.concepts.IPv6;
27 import org.opendaylight.protocol.bgp.linkstate.NodeIdentifier;
28 import org.opendaylight.protocol.bgp.linkstate.OSPFRouterIdentifier;
29 import org.opendaylight.protocol.bgp.linkstate.RouteTag;
30 import org.opendaylight.protocol.bgp.linkstate.NetworkObjectState;
31 import org.opendaylight.protocol.bgp.linkstate.NetworkPrefixState;
32 import org.opendaylight.protocol.bgp.linkstate.IPv4PrefixIdentifier;
33 import org.opendaylight.protocol.bgp.linkstate.IPv6PrefixIdentifier;
34 import com.google.common.collect.Lists;
35 import com.google.common.collect.Sets;
36
37 public class PrefixTest {
38         final BaseBGPObjectState base = new BaseBGPObjectState(BGPOrigin.EGP, null);
39         final NetworkObjectState state = new NetworkObjectState(new ASPath(Lists.newArrayList(new ASNumber(10L))), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
40         final NetworkPrefixState prefixState = new NetworkPrefixState(this.state, Sets.<RouteTag> newTreeSet(), null);
41
42         final BGPIPv4PrefixImpl r4 = new BGPIPv4PrefixImpl(this.base, new IPv4PrefixIdentifier(new NodeIdentifier(null, null, null, new OSPFRouterIdentifier(new byte[] {
43                         1, 2, 3, 4 })), IPv4.FAMILY.prefixForString("172.168.4.5/16")), this.prefixState);
44         final BGPIPv6PrefixImpl r6 = new BGPIPv6PrefixImpl(this.base, new IPv6PrefixIdentifier(new NodeIdentifier(null, null, null, new OSPFRouterIdentifier(new byte[] {
45                         1, 2, 3, 4 })), IPv6.FAMILY.prefixForString("2001::4/32")), this.prefixState);
46
47         @Test
48         public void testIPv4Prefix() {
49                 final BGPIPv4PrefixImpl r2 = new BGPIPv4PrefixImpl(this.base, new IPv4PrefixIdentifier(new NodeIdentifier(null, null, null, new OSPFRouterIdentifier(new byte[] {
50                                 1, 2, 3, 4 })), IPv4.FAMILY.prefixForString("172.168.4.5/16")), this.prefixState);
51
52                 assertEquals(this.r4, r2);
53                 assertEquals(this.r4.hashCode(), r2.hashCode());
54                 assertNotSame(this.r4, this.r6);
55         }
56
57         @Test
58         public void testIPv6Route() {
59                 final BGPIPv6PrefixImpl r2 = new BGPIPv6PrefixImpl(this.base, new IPv6PrefixIdentifier(new NodeIdentifier(null, null, null, new OSPFRouterIdentifier(new byte[] {
60                                 1, 2, 3, 4 })), IPv6.FAMILY.prefixForString("2001::4/32")), this.prefixState);
61
62                 assertEquals(this.r6.currentState(), r2.currentState());
63                 assertEquals(this.r6.toString(), r2.toString());
64                 assertEquals(this.r6.getPrefixIdentifier(), r2.getPrefixIdentifier());
65         }
66 }