Open Kilda Java Documentation
ISwitchImplTest.java
Go to the documentation of this file.
1 package org.openkilda.simulator.classes;
2 
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertTrue;
6 
9 
10 import org.junit.After;
11 import org.junit.Before;
12 import org.junit.Rule;
13 import org.junit.Test;
14 import org.junit.rules.ExpectedException;
15 import org.projectfloodlight.openflow.types.DatapathId;
16 
17 import java.util.List;
18 
19 public class ISwitchImplTest {
20  private ISwitchImpl sw;
21  private SwitchId dpid = new SwitchId("00:00:00:00:00:01");
22  private int numOfPorts = 10;
23  private PortStateType portState = PortStateType.DOWN;
24 
25  @Rule
26  public ExpectedException thrown = ExpectedException.none();
27 
28 
29  @Before
30  public void setUp() throws Exception {
31  sw = new ISwitchImpl(dpid, numOfPorts, portState);
32  }
33 
34  @After
35  public void tearDown() throws Exception {
36  }
37 
38  @Test
39  public void testCreators() throws Exception {
40  ISwitchImpl sw1 = new ISwitchImpl();
41  assertEquals("00:00:00:00:00:00:00:00", sw1.getDpidAsString());
42  assertEquals(0, sw1.getMaxPorts());
43 
44  ISwitchImpl sw2 = new ISwitchImpl(dpid);
45  assertEquals(dpid.toString(), sw2.getDpidAsString());
46  assertEquals(DatapathId.of(dpid.toLong()), sw2.getDpid());
47  assertEquals(0, sw2.getMaxPorts());
48 
49  ISwitchImpl sw3 = new ISwitchImpl(dpid, numOfPorts, portState);
50  List<IPortImpl> ports = sw3.getPorts();
51  assertEquals(numOfPorts, ports.size());
52  for (IPortImpl port : ports) {
53  assertFalse(port.isActive());
54  }
55  }
56 
57  @Test
58  public void modState() throws Exception {
60  assertTrue(sw.isActive());
61 
63  assertFalse(sw.isActive());
64  }
65 
66  @Test
67  public void testActivateDeactivate() throws Exception {
68  sw.deactivate();
69  assertFalse(sw.isActive());
70 
71  sw.activate();
72  assertTrue(sw.isActive());
73  }
74 
75  @Test
76  public void testSetDpid() throws Exception {
77 
78  SwitchId newDpid = new SwitchId("01:02:03:04:05:06");
79  sw.setDpid(newDpid);
80  assertEquals(newDpid.toString(), sw.getDpidAsString());
81  assertEquals(DatapathId.of(newDpid.toString()), sw.getDpid());
82 
83  DatapathId dpid = sw.getDpid();
84  sw.setDpid(dpid);
85  assertEquals(dpid, sw.getDpid());
86  }
87 
88  @Test
89  public void addPort() throws Exception {
90  int portNum = sw.getPorts().size();
91  IPortImpl port = new IPortImpl(sw, PortStateType.UP, portNum);
92 
93  thrown.expect(SimulatorException.class);
94  thrown.expectMessage("Switch already has reached maxPorts");
95  sw.addPort(port);
96 
97  }
98 
99  @Test
100  public void getPort() throws Exception {
101  int numOfPorts = sw.getPorts().size();
102  assertEquals(1, sw.getPort(1).getNumber());
103 
104  thrown.expect(SimulatorException.class);
105  thrown.expectMessage(String.format("Port %d is not defined on %s", numOfPorts, sw.getDpidAsString()));
106  sw.getPort(numOfPorts);
107 
108  }
109 
110  @Test
111  public void getFlow() throws Exception {
112  }
113 
114  @Test
115  public void addFlow() throws Exception {
116  }
117 
118  @Test
119  public void modFlow() throws Exception {
120  }
121 
122  @Test
123  public void delFlow() throws Exception {
124  }
125 
126  @Test
127  public void getPortStats() throws Exception {
128  }
129 
130  @Test
131  public void getPortStats1() throws Exception {
132  }
133 
134 }