BUG-2218: Keep existing link augmentations during discovery process
[controller.git] / opendaylight / routing / dijkstra_implementation / src / test / java / org / opendaylight / controller / routing / dijkstra_implementation / MaxThruputTest.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
9 package org.opendaylight.controller.routing.dijkstra_implementation;
10
11 import org.junit.Test;
12
13 import org.opendaylight.controller.sal.core.ConstructionException;
14 import org.opendaylight.controller.sal.core.Edge;
15 import org.opendaylight.controller.sal.core.Node;
16 import org.opendaylight.controller.sal.core.NodeConnector;
17 import org.opendaylight.controller.sal.core.Path;
18 import org.opendaylight.controller.sal.topology.TopoEdgeUpdate;
19 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
20 import org.opendaylight.controller.sal.utils.NodeCreator;
21
22 import java.util.LinkedList;
23 import java.util.List;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import org.junit.Assert;
29 import org.opendaylight.controller.routing.dijkstra_implementation.internal.DijkstraImplementation;
30
31 import org.opendaylight.controller.sal.core.UpdateType;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 public class MaxThruputTest {
36     protected static final Logger logger = LoggerFactory
37             .getLogger(MaxThruputTest.class);
38     Map<Edge, Number> LinkCostMap = new HashMap<Edge, Number>();
39
40     @Test
41     public void testMaxThruPut() {
42         DijkstraImplementation imp = new DijkstraImplementation();
43         imp.init();
44         Node node1 = NodeCreator.createOFNode((long) 1);
45         Node node2 = NodeCreator.createOFNode((long) 2);
46         Node node3 = NodeCreator.createOFNode((long) 3);
47         Node node4 = NodeCreator.createOFNode((long) 4);
48         Node node5 = NodeCreator.createOFNode((long) 5);
49         Node node6 = NodeCreator.createOFNode((long) 6);
50         NodeConnector nc11 = NodeConnectorCreator.createOFNodeConnector(
51                 (short) 1, node1);
52         NodeConnector nc21 = NodeConnectorCreator.createOFNodeConnector(
53                 (short) 1, node2);
54         NodeConnector nc31 = NodeConnectorCreator.createOFNodeConnector(
55                 (short) 1, node3);
56         NodeConnector nc41 = NodeConnectorCreator.createOFNodeConnector(
57                 (short) 1, node4);
58         NodeConnector nc51 = NodeConnectorCreator.createOFNodeConnector(
59                 (short) 1, node5);
60         NodeConnector nc61 = NodeConnectorCreator.createOFNodeConnector(
61                 (short) 1, node6);
62         NodeConnector nc12 = NodeConnectorCreator.createOFNodeConnector(
63                 (short) 2, node1);
64         NodeConnector nc22 = NodeConnectorCreator.createOFNodeConnector(
65                 (short) 2, node2);
66         NodeConnector nc32 = NodeConnectorCreator.createOFNodeConnector(
67                 (short) 2, node3);
68         NodeConnector nc42 = NodeConnectorCreator.createOFNodeConnector(
69                 (short) 2, node4);
70         NodeConnector nc52 = NodeConnectorCreator.createOFNodeConnector(
71                 (short) 2, node5);
72         NodeConnector nc62 = NodeConnectorCreator.createOFNodeConnector(
73                 (short) 2, node6);
74
75         Edge edge1 = null;
76         try {
77             edge1 = new Edge(nc11, nc21);
78         } catch (ConstructionException e) {
79             logger.error("", e);
80         }
81         LinkCostMap.put(edge1, 10);
82         Edge edge2 = null;
83         try {
84             edge2 = new Edge(nc21, nc11);
85         } catch (ConstructionException e) {
86             logger.error("", e);
87         }
88         LinkCostMap.put(edge2, 10);
89
90         Edge edge3 = null;
91         try {
92             edge3 = new Edge(nc22, nc31);
93         } catch (ConstructionException e) {
94             logger.error("", e);
95         }
96         LinkCostMap.put(edge3, 30);
97         Edge edge4 = null;
98         try {
99             edge4 = new Edge(nc31, nc22);
100         } catch (ConstructionException e) {
101             logger.error("", e);
102         }
103         LinkCostMap.put(edge4, 30);
104
105         Edge edge5 = null;
106         try {
107             edge5 = new Edge(nc32, nc41);
108         } catch (ConstructionException e) {
109             logger.error("", e);
110         }
111         LinkCostMap.put(edge5, 10);
112         Edge edge6 = null;
113         try {
114             edge6 = new Edge(nc41, nc32);
115         } catch (ConstructionException e) {
116             logger.error("", e);
117         }
118         LinkCostMap.put(edge6, 10);
119
120         Edge edge7 = null;
121         try {
122             edge7 = new Edge(nc12, nc51);
123         } catch (ConstructionException e) {
124             logger.error("", e);
125         }
126         LinkCostMap.put(edge7, 20);
127         Edge edge8 = null;
128         try {
129             edge8 = new Edge(nc51, nc12);
130         } catch (ConstructionException e) {
131             logger.error("", e);
132         }
133         LinkCostMap.put(edge8, 20);
134
135         Edge edge9 = null;
136         try {
137             edge9 = new Edge(nc52, nc61);
138         } catch (ConstructionException e) {
139             logger.error("", e);
140         }
141         LinkCostMap.put(edge9, 20);
142         Edge edge10 = null;
143         try {
144             edge10 = new Edge(nc61, nc52);
145         } catch (ConstructionException e) {
146             logger.error("", e);
147         }
148         LinkCostMap.put(edge10, 20);
149
150         Edge edge11 = null;
151         try {
152             edge11 = new Edge(nc62, nc42);
153         } catch (ConstructionException e) {
154             logger.error("", e);
155         }
156         LinkCostMap.put(edge11, 20);
157         Edge edge12 = null;
158         try {
159             edge12 = new Edge(nc42, nc62);
160         } catch (ConstructionException e) {
161             logger.error("", e);
162         }
163         LinkCostMap.put(edge12, 20);
164
165         List<TopoEdgeUpdate> topoedgeupdateList = new ArrayList<TopoEdgeUpdate>();
166         TopoEdgeUpdate teu1 = new TopoEdgeUpdate(edge1, null, UpdateType.ADDED);
167         topoedgeupdateList.add(teu1);
168         TopoEdgeUpdate teu2 = new TopoEdgeUpdate(edge2, null, UpdateType.ADDED);
169         topoedgeupdateList.add(teu2);
170         TopoEdgeUpdate teu3 = new TopoEdgeUpdate(edge3, null, UpdateType.ADDED);
171         topoedgeupdateList.add(teu3);
172         TopoEdgeUpdate teu4 = new TopoEdgeUpdate(edge4, null, UpdateType.ADDED);
173         topoedgeupdateList.add(teu4);
174         TopoEdgeUpdate teu5 = new TopoEdgeUpdate(edge5, null, UpdateType.ADDED);
175         topoedgeupdateList.add(teu5);
176         TopoEdgeUpdate teu6 = new TopoEdgeUpdate(edge6, null, UpdateType.ADDED);
177         topoedgeupdateList.add(teu6);
178         TopoEdgeUpdate teu7 = new TopoEdgeUpdate(edge7, null, UpdateType.ADDED);
179         topoedgeupdateList.add(teu7);
180         TopoEdgeUpdate teu8 = new TopoEdgeUpdate(edge8, null, UpdateType.ADDED);
181         topoedgeupdateList.add(teu8);
182         TopoEdgeUpdate teu9 = new TopoEdgeUpdate(edge9, null, UpdateType.ADDED);
183         topoedgeupdateList.add(teu9);
184         TopoEdgeUpdate teu10 = new TopoEdgeUpdate(edge10, null,
185                 UpdateType.ADDED);
186         topoedgeupdateList.add(teu10);
187         TopoEdgeUpdate teu11 = new TopoEdgeUpdate(edge11, null,
188                 UpdateType.ADDED);
189         topoedgeupdateList.add(teu11);
190         TopoEdgeUpdate teu12 = new TopoEdgeUpdate(edge12, null,
191                 UpdateType.ADDED);
192         topoedgeupdateList.add(teu12);
193
194         imp.edgeUpdate(topoedgeupdateList);
195
196         imp.initMaxThroughput(LinkCostMap);
197
198         Path res = imp.getMaxThroughputRoute(node1, node3);
199         System.out.println("Max Thruput Path between n1-n3: " + res);
200
201         List<Edge> expectedPath = (List<Edge>) new LinkedList<Edge>();
202         expectedPath.add(0, edge7);
203         expectedPath.add(1, edge9);
204         expectedPath.add(2, edge11);
205         expectedPath.add(3, edge6);
206
207         Path expectedRes = null;
208         try {
209             expectedRes = new Path(expectedPath);
210         } catch (ConstructionException e) {
211             logger.error("", e);
212         }
213         if (!res.equals(expectedRes)) {
214             System.out.println("Actual Res is " + res);
215             System.out.println("Expected Res is " + expectedRes);
216         }
217         Assert.assertTrue(res.equals(expectedRes));
218
219         res = imp.getRoute(node1, node3);
220         System.out.println("Shortest Path between n1-n3: " + res);
221         expectedPath.clear();
222         expectedPath.add(0, edge1);
223         expectedPath.add(1, edge3);
224
225         expectedRes = null;
226         try {
227             expectedRes = new Path(expectedPath);
228         } catch (ConstructionException e) {
229             logger.error("", e);
230         }
231         if (!res.equals(expectedRes)) {
232             System.out.println("Actual Res is " + res);
233             System.out.println("Expected Res is " + expectedRes);
234         }
235         Assert.assertTrue(res.equals(expectedRes));
236     }
237 }