Yotam Harchol | a11f38b | 2013-09-26 15:38:17 -0700 | [diff] [blame] | 1 | package org.projectfloodlight.openflow.types; |
| 2 | |
| 3 | import static org.junit.Assert.assertArrayEquals; |
| 4 | import junit.framework.TestCase; |
| 5 | |
| 6 | import org.junit.Test; |
| 7 | |
| 8 | public class OFPortMapTest extends TestCase { |
| 9 | |
| 10 | @Test |
| 11 | public void testOFPortMap() { |
| 12 | Boolean[] on = new Boolean[128]; |
| 13 | for (int i = 0; i < 128; i++) { |
| 14 | on[i] = false; |
| 15 | } |
| 16 | |
| 17 | OFPortMap.Builder builder = new OFPortMap.Builder(); |
| 18 | |
| 19 | for (int i = 0; i < 128; i += 3) { |
| 20 | OFPort p = OFPort.of(i); |
| 21 | builder.set(p); |
| 22 | on[p.getPortNumber()] = true; |
| 23 | } |
| 24 | |
| 25 | // Test that all ports that were added are actually on, and all other ports are off |
| 26 | OFPortMap portmap = builder.build(); |
Yotam Harchol | 595c644 | 2013-09-27 16:29:08 -0700 | [diff] [blame] | 27 | //System.out.println(portmap); |
Yotam Harchol | a11f38b | 2013-09-26 15:38:17 -0700 | [diff] [blame] | 28 | Boolean[] actual = new Boolean[128]; |
| 29 | for (int i = 0; i < 128; i++) { |
| 30 | actual[i] = false; |
| 31 | } |
| 32 | for (int i = 0; i < 128; i++) { |
| 33 | actual[i] = portmap.isOn(OFPort.of(i)); |
| 34 | } |
| 35 | assertArrayEquals(on, actual); |
| 36 | |
| 37 | // Turn some ports off |
| 38 | for (int i = 0; i < 128; i += 7) { |
| 39 | on[i] = false; |
| 40 | builder.unset(OFPort.of(i)); |
| 41 | } |
| 42 | |
| 43 | // Test again |
| 44 | portmap = builder.build(); |
| 45 | actual = new Boolean[128]; |
| 46 | for (int i = 0; i < 128; i++) { |
| 47 | actual[i] = false; |
| 48 | } |
| 49 | for (int i = 0; i < 128; i++) { |
| 50 | actual[i] = portmap.isOn(OFPort.of(i)); |
| 51 | } |
| 52 | assertArrayEquals(on, actual); |
| 53 | } |
| 54 | } |