Sovietaced | 13f8802 | 2014-12-02 06:38:34 -0500 | [diff] [blame] | 1 | package org.projectfloodlight.protocol; |
| 2 | |
Andreas Wundsam | 75c09dc | 2015-07-22 18:23:29 -0700 | [diff] [blame] | 3 | import static org.hamcrest.CoreMatchers.equalTo; |
| 4 | import static org.hamcrest.Matchers.is; |
| 5 | import static org.junit.Assert.assertThat; |
| 6 | |
Sovietaced | 13f8802 | 2014-12-02 06:38:34 -0500 | [diff] [blame] | 7 | import java.util.Arrays; |
| 8 | import java.util.HashSet; |
| 9 | |
Andreas Wundsam | 75c09dc | 2015-07-22 18:23:29 -0700 | [diff] [blame] | 10 | import org.hamcrest.Matchers; |
Sovietaced | 13f8802 | 2014-12-02 06:38:34 -0500 | [diff] [blame] | 11 | import org.junit.Test; |
| 12 | import org.projectfloodlight.openflow.protocol.OFFactories; |
| 13 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 14 | import org.projectfloodlight.openflow.protocol.OFPortConfig; |
| 15 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
Andreas Wundsam | 75c09dc | 2015-07-22 18:23:29 -0700 | [diff] [blame] | 16 | import org.projectfloodlight.openflow.protocol.OFPortDescProp; |
Sovietaced | 13f8802 | 2014-12-02 06:38:34 -0500 | [diff] [blame] | 17 | import org.projectfloodlight.openflow.protocol.OFPortState; |
| 18 | import org.projectfloodlight.openflow.protocol.OFVersion; |
Andreas Wundsam | 75c09dc | 2015-07-22 18:23:29 -0700 | [diff] [blame] | 19 | import org.projectfloodlight.openflow.types.U64; |
Sovietaced | 13f8802 | 2014-12-02 06:38:34 -0500 | [diff] [blame] | 20 | |
Andreas Wundsam | 75c09dc | 2015-07-22 18:23:29 -0700 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableList; |
Sovietaced | 13f8802 | 2014-12-02 06:38:34 -0500 | [diff] [blame] | 22 | |
Sovietaced | d1196ab | 2014-12-02 06:45:42 -0500 | [diff] [blame] | 23 | /** |
| 24 | * Tests auxiliary OFPortDesc methods for all versions of OpenFlow |
| 25 | * |
kjwon15 | 7bc8540 | 2015-02-12 15:07:42 +0900 | [diff] [blame] | 26 | * @author Jason Parraga {@literal <}jason.parraga@bigswitch.com{@literal >} |
Sovietaced | d1196ab | 2014-12-02 06:45:42 -0500 | [diff] [blame] | 27 | */ |
Sovietaced | 13f8802 | 2014-12-02 06:38:34 -0500 | [diff] [blame] | 28 | public class OFPortDescTest { |
| 29 | |
Sovietaced | 13f8802 | 2014-12-02 06:38:34 -0500 | [diff] [blame] | 30 | @Test |
| 31 | public void testIsEnabled() { |
Sovietaced | d1196ab | 2014-12-02 06:45:42 -0500 | [diff] [blame] | 32 | testIsEnabledForFactory(OFFactories.getFactory(OFVersion.OF_10)); |
| 33 | testIsEnabledForFactory(OFFactories.getFactory(OFVersion.OF_11)); |
| 34 | testIsEnabledForFactory(OFFactories.getFactory(OFVersion.OF_12)); |
| 35 | testIsEnabledForFactory(OFFactories.getFactory(OFVersion.OF_13)); |
| 36 | testIsEnabledForFactory(OFFactories.getFactory(OFVersion.OF_14)); |
| 37 | } |
| 38 | |
| 39 | public void testIsEnabledForFactory(OFFactory factory) { |
Sovietaced | 13f8802 | 2014-12-02 06:38:34 -0500 | [diff] [blame] | 40 | // Default |
| 41 | OFPortDesc desc = factory.buildPortDesc() |
| 42 | .build(); |
| 43 | assertThat(desc.isEnabled(), is(true)); |
| 44 | |
| 45 | // Partially disabled |
| 46 | desc = factory.buildPortDesc() |
| 47 | .setConfig(new HashSet<OFPortConfig>(Arrays.asList(OFPortConfig.PORT_DOWN))) |
| 48 | .build(); |
| 49 | assertThat(desc.isEnabled(), is(false)); |
| 50 | |
| 51 | // Fully disabled |
| 52 | desc = factory.buildPortDesc() |
| 53 | .setConfig(new HashSet<OFPortConfig>(Arrays.asList(OFPortConfig.PORT_DOWN))) |
| 54 | .setState(new HashSet<OFPortState>(Arrays.asList(OFPortState.LINK_DOWN))) |
| 55 | .build(); |
| 56 | assertThat(desc.isEnabled(), is(false)); |
| 57 | } |
Andreas Wundsam | 75c09dc | 2015-07-22 18:23:29 -0700 | [diff] [blame] | 58 | |
| 59 | @Test |
| 60 | public void testGenerationIdZeroIfUnset() { |
| 61 | for(OFVersion v: OFVersion.values()) { |
| 62 | OFFactory factory = OFFactories.getFactory(v); |
| 63 | assertThat("For version "+v, factory.buildPortDesc().build().getBsnGenerationId(), |
| 64 | Matchers.equalTo(U64.ZERO)); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | @Test |
| 69 | public void testGenerationIdSet() { |
| 70 | OFFactory factory = OFFactories.getFactory(OFVersion.OF_14); |
| 71 | OFPortDesc desc = factory.buildPortDesc() |
| 72 | .setProperties(ImmutableList.<OFPortDescProp>of( |
| 73 | factory.portDescPropBsnGenerationId(U64.of(1234)))) |
| 74 | .build(); |
| 75 | |
| 76 | assertThat(desc.getBsnGenerationId(), equalTo(U64.of(1234))); |
| 77 | } |
| 78 | |
Sovietaced | 13f8802 | 2014-12-02 06:38:34 -0500 | [diff] [blame] | 79 | } |