blob: e2f3a6e2bd11553a8b49370d3835e81c7c6a8ce3 [file] [log] [blame]
Sovietaced13f88022014-12-02 06:38:34 -05001package org.projectfloodlight.protocol;
2
Andreas Wundsam75c09dc2015-07-22 18:23:29 -07003import static org.hamcrest.CoreMatchers.equalTo;
4import static org.hamcrest.Matchers.is;
5import static org.junit.Assert.assertThat;
6
Sovietaced13f88022014-12-02 06:38:34 -05007import java.util.Arrays;
8import java.util.HashSet;
9
Andreas Wundsam75c09dc2015-07-22 18:23:29 -070010import org.hamcrest.Matchers;
Sovietaced13f88022014-12-02 06:38:34 -050011import org.junit.Test;
12import org.projectfloodlight.openflow.protocol.OFFactories;
13import org.projectfloodlight.openflow.protocol.OFFactory;
14import org.projectfloodlight.openflow.protocol.OFPortConfig;
15import org.projectfloodlight.openflow.protocol.OFPortDesc;
Andreas Wundsam75c09dc2015-07-22 18:23:29 -070016import org.projectfloodlight.openflow.protocol.OFPortDescProp;
Sovietaced13f88022014-12-02 06:38:34 -050017import org.projectfloodlight.openflow.protocol.OFPortState;
18import org.projectfloodlight.openflow.protocol.OFVersion;
Andreas Wundsam75c09dc2015-07-22 18:23:29 -070019import org.projectfloodlight.openflow.types.U64;
Sovietaced13f88022014-12-02 06:38:34 -050020
Andreas Wundsam75c09dc2015-07-22 18:23:29 -070021import com.google.common.collect.ImmutableList;
Sovietaced13f88022014-12-02 06:38:34 -050022
Sovietacedd1196ab2014-12-02 06:45:42 -050023/**
24 * Tests auxiliary OFPortDesc methods for all versions of OpenFlow
25 *
kjwon157bc85402015-02-12 15:07:42 +090026 * @author Jason Parraga {@literal <}jason.parraga@bigswitch.com{@literal >}
Sovietacedd1196ab2014-12-02 06:45:42 -050027 */
Sovietaced13f88022014-12-02 06:38:34 -050028public class OFPortDescTest {
29
Sovietaced13f88022014-12-02 06:38:34 -050030 @Test
31 public void testIsEnabled() {
Sovietacedd1196ab2014-12-02 06:45:42 -050032 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) {
Sovietaced13f88022014-12-02 06:38:34 -050040 // 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 Wundsam75c09dc2015-07-22 18:23:29 -070058
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
Sovietaced13f88022014-12-02 06:38:34 -050079}