blob: 43ce79fc5126520724db69cd690ef381c8bf3dd5 [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;
Jonathan Hart472062d2014-04-03 10:56:48 -07004import net.onrc.onos.core.topology.LinkEvent;
Jonathan Hart23701d12014-04-03 10:45:48 -07005import net.onrc.onos.core.util.serializers.KryoFactory;
Toshio Koidec406e792014-02-14 16:52:42 -08006
7import org.junit.After;
8import org.junit.Before;
9import org.junit.Test;
10
11import com.esotericsoftware.kryo.Kryo;
12import com.esotericsoftware.kryo.io.Input;
13import com.esotericsoftware.kryo.io.Output;
14
Toshio Koide066506e2014-02-20 19:52:09 -080015/**
Yuta HIGUCHId4acc802014-06-19 22:30:31 -070016 * Unit tests for PathIntent.
Toshio Koide066506e2014-02-20 19:52:09 -080017 */
Toshio Koidec406e792014-02-14 16:52:42 -080018public class PathIntentTest {
Ray Milkey269ffb92014-04-03 14:43:30 -070019 @Before
20 public void setUp() throws Exception {
21 }
Toshio Koidec406e792014-02-14 16:52:42 -080022
Ray Milkey269ffb92014-04-03 14:43:30 -070023 @After
24 public void tearDown() throws Exception {
25 }
Toshio Koidec406e792014-02-14 16:52:42 -080026
Ray Milkey269ffb92014-04-03 14:43:30 -070027 @Test
28 public void testCreateFirstId() {
29 String id = PathIntent.createFirstId("100");
30 assertEquals("100___0", id);
31 }
Toshio Koidea10c0372014-02-20 17:28:10 -080032
Ray Milkey269ffb92014-04-03 14:43:30 -070033 @Test
34 public void testCreateNextId() {
35 String id = PathIntent.createNextId("100___999");
36 assertEquals("100___1000", id);
37 }
Toshio Koidea10c0372014-02-20 17:28:10 -080038
Ray Milkey269ffb92014-04-03 14:43:30 -070039 @Test
40 public void test() {
41 KryoFactory factory = new KryoFactory();
42 Kryo kryo = factory.newKryo();
43 Output output = new Output(1024);
Toshio Koidec406e792014-02-14 16:52:42 -080044
Ray Milkey269ffb92014-04-03 14:43:30 -070045 ConstrainedShortestPathIntent cspIntent1 =
46 new ConstrainedShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L, 1000.0);
Toshio Koidec406e792014-02-14 16:52:42 -080047
Ray Milkey269ffb92014-04-03 14:43:30 -070048 Path path = new Path();
49 path.add(new LinkEvent(1L, 1L, 2L, 2L));
50 path.add(new LinkEvent(2L, 1L, 3L, 2L));
51 path.add(new LinkEvent(3L, 1L, 4L, 2L));
Toshio Koidec406e792014-02-14 16:52:42 -080052
Ray Milkey269ffb92014-04-03 14:43:30 -070053 PathIntent pathIntent1 = new PathIntent("11", path, 123.45, cspIntent1);
Toshio Koidec406e792014-02-14 16:52:42 -080054
Ray Milkey269ffb92014-04-03 14:43:30 -070055 kryo.writeObject(output, pathIntent1);
56 output.close();
Toshio Koidec406e792014-02-14 16:52:42 -080057
Ray Milkey269ffb92014-04-03 14:43:30 -070058 Input input = new Input(output.toBytes());
Toshio Koidec406e792014-02-14 16:52:42 -080059
Ray Milkey269ffb92014-04-03 14:43:30 -070060 // create pathIntent from bytes
Toshio Koidec406e792014-02-14 16:52:42 -080061
Ray Milkey269ffb92014-04-03 14:43:30 -070062 PathIntent pathIntent2 =
63 kryo.readObject(input, PathIntent.class);
64 input.close();
Toshio Koidec406e792014-02-14 16:52:42 -080065
Ray Milkey269ffb92014-04-03 14:43:30 -070066 // check
Toshio Koided9fa2a82014-02-19 17:35:18 -080067
Ray Milkey269ffb92014-04-03 14:43:30 -070068 assertEquals("11", pathIntent2.getId());
69 Path path2 = pathIntent2.getPath();
Toshio Koidec406e792014-02-14 16:52:42 -080070
Ray Milkey269ffb92014-04-03 14:43:30 -070071 assertEquals(Long.valueOf(1L), path2.get(0).getSrc().getDpid());
72 assertEquals(Long.valueOf(1L), path2.get(0).getSrc().getNumber());
73 assertEquals(Long.valueOf(2L), path2.get(0).getDst().getDpid());
74 assertEquals(Long.valueOf(2L), path2.get(0).getDst().getNumber());
Toshio Koidec406e792014-02-14 16:52:42 -080075
Ray Milkey269ffb92014-04-03 14:43:30 -070076 assertEquals(Long.valueOf(2L), path2.get(1).getSrc().getDpid());
77 assertEquals(Long.valueOf(1L), path2.get(1).getSrc().getNumber());
78 assertEquals(Long.valueOf(3L), path2.get(1).getDst().getDpid());
79 assertEquals(Long.valueOf(2L), path2.get(1).getDst().getNumber());
Toshio Koidec406e792014-02-14 16:52:42 -080080
Ray Milkey269ffb92014-04-03 14:43:30 -070081 assertEquals(Long.valueOf(3L), path2.get(2).getSrc().getDpid());
82 assertEquals(Long.valueOf(1L), path2.get(2).getSrc().getNumber());
83 assertEquals(Long.valueOf(4L), path2.get(2).getDst().getDpid());
84 assertEquals(Long.valueOf(2L), path2.get(2).getDst().getNumber());
Toshio Koidec406e792014-02-14 16:52:42 -080085
Ray Milkey269ffb92014-04-03 14:43:30 -070086 assertEquals(123.45, pathIntent2.getBandwidth(), 0.0);
Toshio Koidec406e792014-02-14 16:52:42 -080087
Ray Milkey269ffb92014-04-03 14:43:30 -070088 ConstrainedShortestPathIntent cspIntent2 =
89 (ConstrainedShortestPathIntent) pathIntent2.getParentIntent();
Toshio Koided9fa2a82014-02-19 17:35:18 -080090
Ray Milkey269ffb92014-04-03 14:43:30 -070091 assertEquals("1", cspIntent2.getId());
92 assertEquals(2L, cspIntent2.getSrcSwitchDpid());
93 assertEquals(3L, cspIntent2.getSrcPortNumber());
94 assertEquals(4L, cspIntent2.getSrcMac());
95 assertEquals(5L, cspIntent2.getDstSwitchDpid());
96 assertEquals(6L, cspIntent2.getDstPortNumber());
97 assertEquals(7L, cspIntent2.getDstMac());
98 assertEquals(1000.0, cspIntent2.getBandwidth(), 0.0);
99 }
Toshio Koidec406e792014-02-14 16:52:42 -0800100}