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 | |
Andreas Wundsam | 9667a16 | 2013-10-21 12:58:16 -0700 | [diff] [blame] | 8 | public class OFPortBitMapTest extends TestCase { |
Yotam Harchol | a11f38b | 2013-09-26 15:38:17 -0700 | [diff] [blame] | 9 | |
| 10 | @Test |
Andreas Wundsam | 9667a16 | 2013-10-21 12:58:16 -0700 | [diff] [blame] | 11 | public void testOFPortBitMap() { |
Andreas Wundsam | 28c9975 | 2013-10-22 16:51:25 -0700 | [diff] [blame] | 12 | Boolean[] on = new Boolean[127]; |
| 13 | for (int i = 0; i < 127; i++) { |
Yotam Harchol | a11f38b | 2013-09-26 15:38:17 -0700 | [diff] [blame] | 14 | on[i] = false; |
| 15 | } |
| 16 | |
Andreas Wundsam | 9667a16 | 2013-10-21 12:58:16 -0700 | [diff] [blame] | 17 | OFPortBitMap.Builder builder = new OFPortBitMap.Builder(); |
Yotam Harchol | a11f38b | 2013-09-26 15:38:17 -0700 | [diff] [blame] | 18 | |
Andreas Wundsam | 28c9975 | 2013-10-22 16:51:25 -0700 | [diff] [blame] | 19 | for (int i = 0; i < 127; i += 3) { |
Yotam Harchol | a11f38b | 2013-09-26 15:38:17 -0700 | [diff] [blame] | 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 |
Andreas Wundsam | 9667a16 | 2013-10-21 12:58:16 -0700 | [diff] [blame] | 26 | OFPortBitMap portmap = builder.build(); |
Yotam Harchol | 595c644 | 2013-09-27 16:29:08 -0700 | [diff] [blame] | 27 | //System.out.println(portmap); |
Andreas Wundsam | 28c9975 | 2013-10-22 16:51:25 -0700 | [diff] [blame] | 28 | Boolean[] actual = new Boolean[127]; |
| 29 | for (int i = 0; i < 127; i++) { |
Yotam Harchol | a11f38b | 2013-09-26 15:38:17 -0700 | [diff] [blame] | 30 | actual[i] = false; |
| 31 | } |
Andreas Wundsam | 28c9975 | 2013-10-22 16:51:25 -0700 | [diff] [blame] | 32 | for (int i = 0; i < 127; i++) { |
Yotam Harchol | a11f38b | 2013-09-26 15:38:17 -0700 | [diff] [blame] | 33 | actual[i] = portmap.isOn(OFPort.of(i)); |
| 34 | } |
| 35 | assertArrayEquals(on, actual); |
| 36 | |
| 37 | // Turn some ports off |
Andreas Wundsam | 28c9975 | 2013-10-22 16:51:25 -0700 | [diff] [blame] | 38 | for (int i = 0; i < 127; i += 7) { |
Yotam Harchol | a11f38b | 2013-09-26 15:38:17 -0700 | [diff] [blame] | 39 | on[i] = false; |
| 40 | builder.unset(OFPort.of(i)); |
| 41 | } |
| 42 | |
| 43 | // Test again |
| 44 | portmap = builder.build(); |
Andreas Wundsam | 28c9975 | 2013-10-22 16:51:25 -0700 | [diff] [blame] | 45 | actual = new Boolean[127]; |
| 46 | for (int i = 0; i < 127; i++) { |
Yotam Harchol | a11f38b | 2013-09-26 15:38:17 -0700 | [diff] [blame] | 47 | actual[i] = false; |
| 48 | } |
Andreas Wundsam | 28c9975 | 2013-10-22 16:51:25 -0700 | [diff] [blame] | 49 | for (int i = 0; i < 127; i++) { |
Yotam Harchol | a11f38b | 2013-09-26 15:38:17 -0700 | [diff] [blame] | 50 | actual[i] = portmap.isOn(OFPort.of(i)); |
| 51 | } |
| 52 | assertArrayEquals(on, actual); |
| 53 | } |
| 54 | } |