tony-liu | ea76b8e | 2016-11-27 15:26:09 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Foundation |
tony-liu | ea76b8e | 2016-11-27 15:26:09 +0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.tetunnel.api.tunnel; |
| 18 | |
| 19 | import com.google.common.collect.Lists; |
| 20 | import org.junit.Assert; |
| 21 | import org.junit.Test; |
| 22 | import org.onosproject.tetopology.management.api.TeTopologyKey; |
| 23 | import org.onosproject.tetopology.management.api.node.TeNodeKey; |
| 24 | import org.onosproject.tetopology.management.api.node.TtpKey; |
| 25 | import org.onosproject.tetunnel.api.lsp.TeLspKey; |
| 26 | import org.onosproject.tetunnel.api.tunnel.path.DefaultTePath; |
| 27 | import org.onosproject.tetunnel.api.tunnel.path.TePath; |
| 28 | |
| 29 | import java.util.List; |
| 30 | |
| 31 | /** |
| 32 | * Unit tests for default TE tunnel implementation. |
| 33 | */ |
| 34 | public class DefaultTeTunnelTest { |
| 35 | |
| 36 | /** |
| 37 | * Tests constructor of TeTunnelKey. |
| 38 | */ |
| 39 | @Test |
| 40 | public void testConstructorOfTeTunnelKey() { |
| 41 | final int providerId = 1; |
| 42 | final int clientId = 2; |
| 43 | final int topologyId = 3; |
| 44 | final int teTunnelId = 4; |
| 45 | |
| 46 | TeTunnelKey key = new TeTunnelKey(providerId, clientId, topologyId, |
| 47 | teTunnelId); |
| 48 | |
| 49 | Assert.assertEquals(key.teTunnelId(), teTunnelId); |
| 50 | Assert.assertEquals(key.teTopologyKey(), |
| 51 | new TeTopologyKey(providerId, clientId, |
| 52 | topologyId)); |
| 53 | Assert.assertTrue(key.equals( |
| 54 | new TeTunnelKey(providerId, clientId, topologyId, |
| 55 | teTunnelId))); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Tests constructor of TeLspKey. |
| 60 | */ |
| 61 | @Test |
| 62 | public void testConstructorOfTeLspKey() { |
| 63 | final int providerId = 1; |
| 64 | final int clientId = 2; |
| 65 | final int topologyId = 3; |
| 66 | final int teLspId = 4; |
| 67 | |
| 68 | TeLspKey key = new TeLspKey(providerId, clientId, topologyId, |
| 69 | teLspId); |
| 70 | |
| 71 | Assert.assertEquals(key.teLspId(), teLspId); |
| 72 | Assert.assertEquals(key.teTopologyKey(), |
| 73 | new TeTopologyKey(providerId, clientId, |
| 74 | topologyId)); |
| 75 | Assert.assertTrue(key.equals( |
| 76 | new TeLspKey(providerId, clientId, topologyId, |
| 77 | teLspId))); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Tests builder of the DefaultTeTunnel. |
| 82 | */ |
| 83 | @Test |
| 84 | public void testDefaultTeTunnelBuilder() { |
| 85 | final int providerId = 1; |
| 86 | final int clientId = 2; |
| 87 | final int topologyId = 3; |
| 88 | final int srcNodeId = 4; |
| 89 | final int srcTtpId = 5; |
| 90 | final int dstNodeId = 6; |
| 91 | final int dstTtpId = 7; |
| 92 | final int teTunnelId = 8; |
| 93 | final String teTunnelName = "Test TE tunnel"; |
| 94 | final List<TePath> paths = Lists.newArrayList( |
| 95 | new DefaultTePath(TePath.Type.DYNAMIC, null, null, null)); |
| 96 | final int segTunnelId1 = 1001; |
| 97 | final int segTunnelId2 = 1002; |
| 98 | final int segTunnelId3 = 1003; |
| 99 | |
| 100 | TeTunnel teTunnel = DefaultTeTunnel.builder() |
| 101 | .teTunnelKey( |
| 102 | new TeTunnelKey(providerId, clientId, topologyId, |
| 103 | teTunnelId)) |
| 104 | .srcNode(new TeNodeKey(providerId, clientId, topologyId, |
| 105 | srcNodeId)) |
| 106 | .srcTp(new TtpKey(providerId, clientId, topologyId, srcNodeId, |
| 107 | srcTtpId)) |
| 108 | .dstNode(new TeNodeKey(providerId, clientId, topologyId, |
| 109 | dstNodeId)) |
| 110 | .dstTp(new TtpKey(providerId, clientId, topologyId, dstNodeId, |
| 111 | dstTtpId)) |
| 112 | .name(teTunnelName) |
| 113 | .adminState(TeTunnel.State.UP) |
| 114 | .lspProtectionType(TeTunnel.LspProtectionType.LSP_PROT_REROUTE) |
| 115 | .type(TeTunnel.Type.P2P) |
| 116 | .primaryPaths(paths) |
| 117 | .build(); |
| 118 | |
| 119 | Assert.assertEquals(teTunnel.teTunnelKey().teTopologyKey(), |
| 120 | new TeTopologyKey(providerId, clientId, |
| 121 | topologyId)); |
| 122 | Assert.assertEquals(teTunnel.teTunnelKey().teTunnelId(), teTunnelId); |
| 123 | Assert.assertEquals(teTunnel.srcNode(), |
| 124 | new TeNodeKey(providerId, clientId, topologyId, |
| 125 | srcNodeId)); |
| 126 | Assert.assertEquals(teTunnel.dstNode(), |
| 127 | new TeNodeKey(providerId, clientId, topologyId, |
| 128 | dstNodeId)); |
| 129 | Assert.assertEquals(teTunnel.srcTp(), |
| 130 | new TtpKey(providerId, clientId, topologyId, |
| 131 | srcNodeId, srcTtpId)); |
| 132 | Assert.assertEquals(teTunnel.dstTp(), |
| 133 | new TtpKey(providerId, clientId, topologyId, |
| 134 | dstNodeId, dstTtpId)); |
| 135 | Assert.assertEquals(teTunnel.name(), teTunnelName); |
| 136 | Assert.assertEquals(teTunnel.adminStatus(), TeTunnel.State.UP); |
| 137 | Assert.assertEquals(teTunnel.lspProtectionType(), |
| 138 | TeTunnel.LspProtectionType.LSP_PROT_REROUTE); |
| 139 | Assert.assertEquals(teTunnel.type(), TeTunnel.Type.P2P); |
| 140 | Assert.assertEquals(teTunnel.primaryPaths().get(0).type(), |
| 141 | TePath.Type.DYNAMIC); |
| 142 | Assert.assertEquals(teTunnel.primaryPaths(), paths); |
| 143 | |
| 144 | TeTunnelKey segTunnel1 = new TeTunnelKey(providerId, clientId, |
| 145 | topologyId, segTunnelId1); |
| 146 | TeTunnelKey segTunnel2 = new TeTunnelKey(providerId, clientId, |
| 147 | topologyId, segTunnelId2); |
| 148 | TeTunnelKey segTunnel3 = new TeTunnelKey(providerId, clientId, |
| 149 | topologyId, segTunnelId3); |
| 150 | List<TeTunnelKey> segTunnels = Lists.newArrayList(segTunnel1, |
| 151 | segTunnel2, |
| 152 | segTunnel3); |
| 153 | teTunnel.segmentTunnels(segTunnels); |
| 154 | Assert.assertEquals(teTunnel.segmentTunnels(), segTunnels); |
| 155 | } |
| 156 | } |