blob: 0bff4f40f008c17116f0f1737ccd6307704ed800 [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 Hartaa380972014-04-03 10:24:46 -07004import net.onrc.onos.core.intent.ConstrainedShortestPathIntent;
5import net.onrc.onos.core.intent.PathIntent;
Jonathan Hart472062d2014-04-03 10:56:48 -07006import net.onrc.onos.core.topology.LinkEvent;
7import net.onrc.onos.core.topology.Path;
Jonathan Hart23701d12014-04-03 10:45:48 -07008import net.onrc.onos.core.util.serializers.KryoFactory;
Toshio Koidec406e792014-02-14 16:52:42 -08009
10import org.junit.After;
11import org.junit.Before;
12import org.junit.Test;
13
14import com.esotericsoftware.kryo.Kryo;
15import com.esotericsoftware.kryo.io.Input;
16import com.esotericsoftware.kryo.io.Output;
17
Toshio Koide066506e2014-02-20 19:52:09 -080018/**
19 * @author Toshio Koide (t-koide@onlab.us)
20 */
Toshio Koidec406e792014-02-14 16:52:42 -080021public class PathIntentTest {
Toshio Koidec406e792014-02-14 16:52:42 -080022 @Before
23 public void setUp() throws Exception {
Toshio Koidec406e792014-02-14 16:52:42 -080024 }
25
26 @After
27 public void tearDown() throws Exception {
28 }
29
30 @Test
Toshio Koidea10c0372014-02-20 17:28:10 -080031 public void testCreateFirstId() {
32 String id = PathIntent.createFirstId("100");
Toshio Koide52a6bca2014-02-21 21:28:22 -080033 assertEquals("100___0", id);
Toshio Koidea10c0372014-02-20 17:28:10 -080034 }
35
36 @Test
37 public void testCreateNextId() {
Toshio Koide52a6bca2014-02-21 21:28:22 -080038 String id = PathIntent.createNextId("100___999");
39 assertEquals("100___1000", id);
Toshio Koidea10c0372014-02-20 17:28:10 -080040 }
41
42 @Test
Toshio Koidec406e792014-02-14 16:52:42 -080043 public void test() {
Toshio Koidebc116be2014-02-19 23:56:48 -080044 KryoFactory factory = new KryoFactory();
45 Kryo kryo = factory.newKryo();
Toshio Koidec406e792014-02-14 16:52:42 -080046 Output output = new Output(1024);
47
48 ConstrainedShortestPathIntent cspIntent1 =
49 new ConstrainedShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L, 1000.0);
50
51 Path path = new Path();
Toshio Koide5b4731d2014-02-22 15:58:52 -080052 path.add(new LinkEvent(1L, 1L, 2L, 2L));
53 path.add(new LinkEvent(2L, 1L, 3L, 2L));
54 path.add(new LinkEvent(3L, 1L, 4L, 2L));
Toshio Koidec406e792014-02-14 16:52:42 -080055
56 PathIntent pathIntent1 = new PathIntent("11", path, 123.45, cspIntent1);
57
58 kryo.writeObject(output, pathIntent1);
59 output.close();
60
61 Input input = new Input(output.toBytes());
62
63 // create pathIntent from bytes
64
65 PathIntent pathIntent2 =
66 kryo.readObject(input, PathIntent.class);
67 input.close();
68
69 // check
Toshio Koided9fa2a82014-02-19 17:35:18 -080070
Toshio Koidec406e792014-02-14 16:52:42 -080071 assertEquals("11", pathIntent2.getId());
Toshio Koided9fa2a82014-02-19 17:35:18 -080072 Path path2 = pathIntent2.getPath();
Toshio Koidec406e792014-02-14 16:52:42 -080073
Toshio Koided9fa2a82014-02-19 17:35:18 -080074 assertEquals(Long.valueOf(1L), path2.get(0).getSrc().getDpid());
75 assertEquals(Long.valueOf(1L), path2.get(0).getSrc().getNumber());
76 assertEquals(Long.valueOf(2L), path2.get(0).getDst().getDpid());
77 assertEquals(Long.valueOf(2L), path2.get(0).getDst().getNumber());
Toshio Koidec406e792014-02-14 16:52:42 -080078
Toshio Koided9fa2a82014-02-19 17:35:18 -080079 assertEquals(Long.valueOf(2L), path2.get(1).getSrc().getDpid());
80 assertEquals(Long.valueOf(1L), path2.get(1).getSrc().getNumber());
81 assertEquals(Long.valueOf(3L), path2.get(1).getDst().getDpid());
82 assertEquals(Long.valueOf(2L), path2.get(1).getDst().getNumber());
Toshio Koidec406e792014-02-14 16:52:42 -080083
Toshio Koided9fa2a82014-02-19 17:35:18 -080084 assertEquals(Long.valueOf(3L), path2.get(2).getSrc().getDpid());
85 assertEquals(Long.valueOf(1L), path2.get(2).getSrc().getNumber());
86 assertEquals(Long.valueOf(4L), path2.get(2).getDst().getDpid());
87 assertEquals(Long.valueOf(2L), path2.get(2).getDst().getNumber());
Toshio Koidec406e792014-02-14 16:52:42 -080088
89 assertEquals(123.45, pathIntent2.getBandwidth(), 0.0);
90
Toshio Koided9fa2a82014-02-19 17:35:18 -080091 ConstrainedShortestPathIntent cspIntent2 =
Toshio Koidec406e792014-02-14 16:52:42 -080092 (ConstrainedShortestPathIntent) pathIntent2.getParentIntent();
Toshio Koided9fa2a82014-02-19 17:35:18 -080093
Toshio Koidec406e792014-02-14 16:52:42 -080094 assertEquals("1", cspIntent2.getId());
95 assertEquals(2L, cspIntent2.getSrcSwitchDpid());
96 assertEquals(3L, cspIntent2.getSrcPortNumber());
97 assertEquals(4L, cspIntent2.getSrcMac());
98 assertEquals(5L, cspIntent2.getDstSwitchDpid());
99 assertEquals(6L, cspIntent2.getDstPortNumber());
100 assertEquals(7L, cspIntent2.getDstMac());
101 assertEquals(1000.0, cspIntent2.getBandwidth(), 0.0);
102 }
103}