Toshio Koide | 2c67a2d | 2014-08-27 11:30:56 -0700 | [diff] [blame] | 1 | package net.onrc.onos.api.flowmanager; |
| 2 | |
| 3 | import static org.junit.Assert.assertEquals; |
| 4 | import static org.junit.Assert.assertNotNull; |
| 5 | |
| 6 | import java.util.Arrays; |
| 7 | import java.util.List; |
| 8 | |
| 9 | import net.onrc.onos.core.matchaction.action.Action; |
| 10 | import net.onrc.onos.core.matchaction.action.OutputAction; |
| 11 | import net.onrc.onos.core.util.PortNumber; |
| 12 | import net.onrc.onos.core.util.SwitchPort; |
| 13 | import net.onrc.onos.core.util.serializers.KryoFactory; |
| 14 | |
| 15 | import org.junit.After; |
| 16 | import org.junit.Before; |
| 17 | import org.junit.Test; |
| 18 | |
| 19 | public 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 | } |