blob: 530f66bf2d85ef0c6843a9bd4d08205c38f14a2a [file] [log] [blame]
Sovietaced13f88022014-12-02 06:38:34 -05001package org.projectfloodlight.protocol;
2
3import java.util.Arrays;
4import java.util.HashSet;
5
6import org.junit.Test;
7import org.projectfloodlight.openflow.protocol.OFFactories;
8import org.projectfloodlight.openflow.protocol.OFFactory;
9import org.projectfloodlight.openflow.protocol.OFPortConfig;
10import org.projectfloodlight.openflow.protocol.OFPortDesc;
11import org.projectfloodlight.openflow.protocol.OFPortState;
12import org.projectfloodlight.openflow.protocol.OFVersion;
13
14import static org.hamcrest.Matchers.is;
15
16import static org.junit.Assert.assertThat;
17
Sovietacedd1196ab2014-12-02 06:45:42 -050018/**
19 * Tests auxiliary OFPortDesc methods for all versions of OpenFlow
20 *
kjwon157bc85402015-02-12 15:07:42 +090021 * @author Jason Parraga {@literal <}jason.parraga@bigswitch.com{@literal >}
Sovietacedd1196ab2014-12-02 06:45:42 -050022 */
Sovietaced13f88022014-12-02 06:38:34 -050023public class OFPortDescTest {
24
Sovietaced13f88022014-12-02 06:38:34 -050025 @Test
26 public void testIsEnabled() {
Sovietacedd1196ab2014-12-02 06:45:42 -050027 testIsEnabledForFactory(OFFactories.getFactory(OFVersion.OF_10));
28 testIsEnabledForFactory(OFFactories.getFactory(OFVersion.OF_11));
29 testIsEnabledForFactory(OFFactories.getFactory(OFVersion.OF_12));
30 testIsEnabledForFactory(OFFactories.getFactory(OFVersion.OF_13));
31 testIsEnabledForFactory(OFFactories.getFactory(OFVersion.OF_14));
32 }
33
34 public void testIsEnabledForFactory(OFFactory factory) {
Sovietaced13f88022014-12-02 06:38:34 -050035 // Default
36 OFPortDesc desc = factory.buildPortDesc()
37 .build();
38 assertThat(desc.isEnabled(), is(true));
39
40 // Partially disabled
41 desc = factory.buildPortDesc()
42 .setConfig(new HashSet<OFPortConfig>(Arrays.asList(OFPortConfig.PORT_DOWN)))
43 .build();
44 assertThat(desc.isEnabled(), is(false));
45
46 // Fully disabled
47 desc = factory.buildPortDesc()
48 .setConfig(new HashSet<OFPortConfig>(Arrays.asList(OFPortConfig.PORT_DOWN)))
49 .setState(new HashSet<OFPortState>(Arrays.asList(OFPortState.LINK_DOWN)))
50 .build();
51 assertThat(desc.isEnabled(), is(false));
52 }
53}