blob: 4d3c9ba8e273d7b5c2d3aac2bfef1b124b0e5fb3 [file] [log] [blame]
Toshio Koide2c67a2d2014-08-27 11:30:56 -07001package net.onrc.onos.api.flowmanager;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertNotNull;
5
6import java.util.Arrays;
7import java.util.List;
8
9import net.onrc.onos.core.matchaction.action.Action;
10import net.onrc.onos.core.matchaction.action.OutputAction;
11import net.onrc.onos.core.util.PortNumber;
12import net.onrc.onos.core.util.SwitchPort;
13import net.onrc.onos.core.util.serializers.KryoFactory;
14
15import org.junit.After;
16import org.junit.Before;
17import org.junit.Test;
18
19public class OpticalPathFlowTest {
20
21 @Before
22 public void setUp() throws Exception {
23 }
24
25 @After
26 public void tearDown() throws Exception {
27 }
28
29 /**
30 * Tests if the object can be serialized and deserialized properly with
31 * Kryo.
32 */
33 @Test
34 public void testKryo() {
35 final FlowId id = new FlowId(1);
36 final PortNumber ingressPort = PortNumber.uint32(12345);
37 final Path path = new Path(Arrays.asList(
38 new FlowLink(new SwitchPort(1, (short) 1), new SwitchPort(2, (short) 2)),
39 new FlowLink(new SwitchPort(2, (short) 1), new SwitchPort(3, (short) 2))
40 ));
41 final List<Action> egressActions =
42 Arrays.asList((Action) new OutputAction(PortNumber.uint32(54321)));
43 final int lambda = 100;
44
45 final OpticalPathFlow originalFlow =
46 new OpticalPathFlow(id, ingressPort, path, egressActions, lambda);
47
48 assertNotNull(originalFlow);
49 byte[] buf = KryoFactory.serialize(originalFlow);
50
51 final OpticalPathFlow obtainedFlow = KryoFactory.deserialize(buf);
52
53 assertEquals(id, obtainedFlow.getId());
54 assertEquals(ingressPort, obtainedFlow.getIngressPortNumber());
55 assertEquals(path, obtainedFlow.getPath());
56 assertEquals(egressActions, obtainedFlow.getEgressActions());
57 assertEquals(lambda, obtainedFlow.getLambda());
58 }
59}