blob: 1b400df6063c28767b0a9b73da02e7b175a9fb8b [file] [log] [blame]
Jonathan Hartaa380972014-04-03 10:24:46 -07001package net.onrc.onos.core.intent;
Toshio Koidec406e792014-02-14 16:52:42 -08002
Toshio Koided9fa2a82014-02-19 17:35:18 -08003import static org.junit.Assert.assertEquals;
Ray Milkey269ffb92014-04-03 14:43:30 -07004
Jonathan Hart472062d2014-04-03 10:56:48 -07005import net.onrc.onos.core.topology.LinkEvent;
6import net.onrc.onos.core.topology.Path;
Jonathan Hart23701d12014-04-03 10:45:48 -07007import net.onrc.onos.core.util.serializers.KryoFactory;
Toshio Koidec406e792014-02-14 16:52:42 -08008
9import org.junit.After;
10import org.junit.Before;
11import org.junit.Test;
12
13import com.esotericsoftware.kryo.Kryo;
14import com.esotericsoftware.kryo.io.Input;
15import com.esotericsoftware.kryo.io.Output;
16
Toshio Koide066506e2014-02-20 19:52:09 -080017/**
18 * @author Toshio Koide (t-koide@onlab.us)
19 */
Toshio Koidec406e792014-02-14 16:52:42 -080020public class PathIntentTest {
Ray Milkey269ffb92014-04-03 14:43:30 -070021 @Before
22 public void setUp() throws Exception {
23 }
Toshio Koidec406e792014-02-14 16:52:42 -080024
Ray Milkey269ffb92014-04-03 14:43:30 -070025 @After
26 public void tearDown() throws Exception {
27 }
Toshio Koidec406e792014-02-14 16:52:42 -080028
Ray Milkey269ffb92014-04-03 14:43:30 -070029 @Test
30 public void testCreateFirstId() {
31 String id = PathIntent.createFirstId("100");
32 assertEquals("100___0", id);
33 }
Toshio Koidea10c0372014-02-20 17:28:10 -080034
Ray Milkey269ffb92014-04-03 14:43:30 -070035 @Test
36 public void testCreateNextId() {
37 String id = PathIntent.createNextId("100___999");
38 assertEquals("100___1000", id);
39 }
Toshio Koidea10c0372014-02-20 17:28:10 -080040
Ray Milkey269ffb92014-04-03 14:43:30 -070041 @Test
42 public void test() {
43 KryoFactory factory = new KryoFactory();
44 Kryo kryo = factory.newKryo();
45 Output output = new Output(1024);
Toshio Koidec406e792014-02-14 16:52:42 -080046
Ray Milkey269ffb92014-04-03 14:43:30 -070047 ConstrainedShortestPathIntent cspIntent1 =
48 new ConstrainedShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L, 1000.0);
Toshio Koidec406e792014-02-14 16:52:42 -080049
Ray Milkey269ffb92014-04-03 14:43:30 -070050 Path path = new Path();
51 path.add(new LinkEvent(1L, 1L, 2L, 2L));
52 path.add(new LinkEvent(2L, 1L, 3L, 2L));
53 path.add(new LinkEvent(3L, 1L, 4L, 2L));
Toshio Koidec406e792014-02-14 16:52:42 -080054
Ray Milkey269ffb92014-04-03 14:43:30 -070055 PathIntent pathIntent1 = new PathIntent("11", path, 123.45, cspIntent1);
Toshio Koidec406e792014-02-14 16:52:42 -080056
Ray Milkey269ffb92014-04-03 14:43:30 -070057 kryo.writeObject(output, pathIntent1);
58 output.close();
Toshio Koidec406e792014-02-14 16:52:42 -080059
Ray Milkey269ffb92014-04-03 14:43:30 -070060 Input input = new Input(output.toBytes());
Toshio Koidec406e792014-02-14 16:52:42 -080061
Ray Milkey269ffb92014-04-03 14:43:30 -070062 // create pathIntent from bytes
Toshio Koidec406e792014-02-14 16:52:42 -080063
Ray Milkey269ffb92014-04-03 14:43:30 -070064 PathIntent pathIntent2 =
65 kryo.readObject(input, PathIntent.class);
66 input.close();
Toshio Koidec406e792014-02-14 16:52:42 -080067
Ray Milkey269ffb92014-04-03 14:43:30 -070068 // check
Toshio Koided9fa2a82014-02-19 17:35:18 -080069
Ray Milkey269ffb92014-04-03 14:43:30 -070070 assertEquals("11", pathIntent2.getId());
71 Path path2 = pathIntent2.getPath();
Toshio Koidec406e792014-02-14 16:52:42 -080072
Ray Milkey269ffb92014-04-03 14:43:30 -070073 assertEquals(Long.valueOf(1L), path2.get(0).getSrc().getDpid());
74 assertEquals(Long.valueOf(1L), path2.get(0).getSrc().getNumber());
75 assertEquals(Long.valueOf(2L), path2.get(0).getDst().getDpid());
76 assertEquals(Long.valueOf(2L), path2.get(0).getDst().getNumber());
Toshio Koidec406e792014-02-14 16:52:42 -080077
Ray Milkey269ffb92014-04-03 14:43:30 -070078 assertEquals(Long.valueOf(2L), path2.get(1).getSrc().getDpid());
79 assertEquals(Long.valueOf(1L), path2.get(1).getSrc().getNumber());
80 assertEquals(Long.valueOf(3L), path2.get(1).getDst().getDpid());
81 assertEquals(Long.valueOf(2L), path2.get(1).getDst().getNumber());
Toshio Koidec406e792014-02-14 16:52:42 -080082
Ray Milkey269ffb92014-04-03 14:43:30 -070083 assertEquals(Long.valueOf(3L), path2.get(2).getSrc().getDpid());
84 assertEquals(Long.valueOf(1L), path2.get(2).getSrc().getNumber());
85 assertEquals(Long.valueOf(4L), path2.get(2).getDst().getDpid());
86 assertEquals(Long.valueOf(2L), path2.get(2).getDst().getNumber());
Toshio Koidec406e792014-02-14 16:52:42 -080087
Ray Milkey269ffb92014-04-03 14:43:30 -070088 assertEquals(123.45, pathIntent2.getBandwidth(), 0.0);
Toshio Koidec406e792014-02-14 16:52:42 -080089
Ray Milkey269ffb92014-04-03 14:43:30 -070090 ConstrainedShortestPathIntent cspIntent2 =
91 (ConstrainedShortestPathIntent) pathIntent2.getParentIntent();
Toshio Koided9fa2a82014-02-19 17:35:18 -080092
Ray Milkey269ffb92014-04-03 14:43:30 -070093 assertEquals("1", cspIntent2.getId());
94 assertEquals(2L, cspIntent2.getSrcSwitchDpid());
95 assertEquals(3L, cspIntent2.getSrcPortNumber());
96 assertEquals(4L, cspIntent2.getSrcMac());
97 assertEquals(5L, cspIntent2.getDstSwitchDpid());
98 assertEquals(6L, cspIntent2.getDstPortNumber());
99 assertEquals(7L, cspIntent2.getDstMac());
100 assertEquals(1000.0, cspIntent2.getBandwidth(), 0.0);
101 }
Toshio Koidec406e792014-02-14 16:52:42 -0800102}