Test for role delivery
Change-Id: I202e7606b03bcb89effd57d07003c563de0b7b06
Showing
2 changed files
with
285 additions
and
1 deletions
... | @@ -51,7 +51,7 @@ public interface DeviceProviderService extends ProviderService<DeviceProvider> { | ... | @@ -51,7 +51,7 @@ public interface DeviceProviderService extends ProviderService<DeviceProvider> { |
51 | * mastership role on the device. | 51 | * mastership role on the device. |
52 | * | 52 | * |
53 | * @param deviceId identity of the device | 53 | * @param deviceId identity of the device |
54 | - * @param role mastership role being asserted | 54 | + * @param role mastership role that was asserted but failed |
55 | */ | 55 | */ |
56 | void unableToAssertRole(DeviceId deviceId, MastershipRole role); | 56 | void unableToAssertRole(DeviceId deviceId, MastershipRole role); |
57 | 57 | ... | ... |
1 | +package org.onlab.onos.openflow.controller.impl; | ||
2 | + | ||
3 | +import java.io.IOException; | ||
4 | +import java.util.List; | ||
5 | + | ||
6 | +import org.jboss.netty.channel.Channel; | ||
7 | +import org.junit.After; | ||
8 | +import org.junit.Before; | ||
9 | +import org.junit.Test; | ||
10 | +import org.onlab.onos.openflow.controller.RoleState; | ||
11 | +import org.onlab.onos.openflow.controller.driver.OpenFlowAgent; | ||
12 | +import org.onlab.onos.openflow.controller.driver.OpenFlowSwitchDriver; | ||
13 | +import org.onlab.onos.openflow.controller.driver.RoleHandler; | ||
14 | +import org.onlab.onos.openflow.controller.driver.RoleRecvStatus; | ||
15 | +import org.onlab.onos.openflow.controller.driver.RoleReplyInfo; | ||
16 | +import org.onlab.onos.openflow.controller.driver.SwitchStateException; | ||
17 | +import org.projectfloodlight.openflow.protocol.OFDescStatsReply; | ||
18 | +import org.projectfloodlight.openflow.protocol.OFErrorMsg; | ||
19 | +import org.projectfloodlight.openflow.protocol.OFFactories; | ||
20 | +import org.projectfloodlight.openflow.protocol.OFFactory; | ||
21 | +import org.projectfloodlight.openflow.protocol.OFFeaturesReply; | ||
22 | +import org.projectfloodlight.openflow.protocol.OFMessage; | ||
23 | +import org.projectfloodlight.openflow.protocol.OFPortDesc; | ||
24 | +import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; | ||
25 | +import org.projectfloodlight.openflow.protocol.OFVersion; | ||
26 | +import org.projectfloodlight.openflow.types.U64; | ||
27 | + | ||
28 | +import static org.junit.Assert.assertEquals; | ||
29 | +import static org.onlab.onos.openflow.controller.RoleState.*; | ||
30 | +import static org.onlab.onos.openflow.controller.driver.RoleRecvStatus.*; | ||
31 | + | ||
32 | +public class RoleManagerTest { | ||
33 | + | ||
34 | + private static final U64 GID = U64.of(10L); | ||
35 | + private static final long XID = 1L; | ||
36 | + | ||
37 | + private OpenFlowSwitchDriver sw; | ||
38 | + private RoleManager manager; | ||
39 | + | ||
40 | + @Before | ||
41 | + public void setUp() { | ||
42 | + sw = new TestSwitchDriver(); | ||
43 | + manager = new RoleManager(sw); | ||
44 | + } | ||
45 | + | ||
46 | + @After | ||
47 | + public void tearDown() { | ||
48 | + manager = null; | ||
49 | + sw = null; | ||
50 | + } | ||
51 | + | ||
52 | + @Test | ||
53 | + public void deliverRoleReply() { | ||
54 | + RoleRecvStatus status; | ||
55 | + | ||
56 | + RoleReplyInfo asserted = new RoleReplyInfo(MASTER, GID, XID); | ||
57 | + RoleReplyInfo unasserted = new RoleReplyInfo(SLAVE, GID, XID); | ||
58 | + | ||
59 | + try { | ||
60 | + //call without sendRoleReq() for requestPending = false | ||
61 | + //first, sw.role == null | ||
62 | + status = manager.deliverRoleReply(asserted); | ||
63 | + assertEquals("expectation wrong", OTHER_EXPECTATION, status); | ||
64 | + | ||
65 | + sw.setRole(MASTER); | ||
66 | + assertEquals("expectation wrong", OTHER_EXPECTATION, status); | ||
67 | + sw.setRole(SLAVE); | ||
68 | + | ||
69 | + //match to pendingRole = MASTER, requestPending = true | ||
70 | + manager.sendRoleRequest(MASTER, MATCHED_CURRENT_ROLE); | ||
71 | + status = manager.deliverRoleReply(asserted); | ||
72 | + assertEquals("expectation wrong", MATCHED_CURRENT_ROLE, status); | ||
73 | + | ||
74 | + //requestPending never gets reset -- this might be a bug. | ||
75 | + status = manager.deliverRoleReply(unasserted); | ||
76 | + assertEquals("expectation wrong", OTHER_EXPECTATION, status); | ||
77 | + assertEquals("pending role mismatch", MASTER, ((TestSwitchDriver) sw).failed); | ||
78 | + | ||
79 | + } catch (IOException | SwitchStateException e) { | ||
80 | + assertEquals("unexpected error thrown", | ||
81 | + SwitchStateException.class, e.getClass()); | ||
82 | + } | ||
83 | + } | ||
84 | + | ||
85 | + private class TestSwitchDriver implements OpenFlowSwitchDriver { | ||
86 | + | ||
87 | + RoleState failed = null; | ||
88 | + RoleState current = null; | ||
89 | + | ||
90 | + @Override | ||
91 | + public void sendMsg(OFMessage msg) { | ||
92 | + } | ||
93 | + | ||
94 | + @Override | ||
95 | + public void sendMsg(List<OFMessage> msgs) { | ||
96 | + } | ||
97 | + | ||
98 | + @Override | ||
99 | + public void handleMessage(OFMessage fromSwitch) { | ||
100 | + } | ||
101 | + | ||
102 | + @Override | ||
103 | + public void setRole(RoleState role) { | ||
104 | + current = role; | ||
105 | + } | ||
106 | + | ||
107 | + @Override | ||
108 | + public RoleState getRole() { | ||
109 | + return current; | ||
110 | + } | ||
111 | + | ||
112 | + @Override | ||
113 | + public List<OFPortDesc> getPorts() { | ||
114 | + return null; | ||
115 | + } | ||
116 | + | ||
117 | + @Override | ||
118 | + public OFFactory factory() { | ||
119 | + // return what-ever triggers requestPending = true | ||
120 | + return OFFactories.getFactory(OFVersion.OF_10); | ||
121 | + } | ||
122 | + | ||
123 | + @Override | ||
124 | + public String getStringId() { | ||
125 | + return "100"; | ||
126 | + } | ||
127 | + | ||
128 | + @Override | ||
129 | + public long getId() { | ||
130 | + return 0; | ||
131 | + } | ||
132 | + | ||
133 | + @Override | ||
134 | + public String manfacturerDescription() { | ||
135 | + return null; | ||
136 | + } | ||
137 | + | ||
138 | + @Override | ||
139 | + public String datapathDescription() { | ||
140 | + return null; | ||
141 | + } | ||
142 | + | ||
143 | + @Override | ||
144 | + public String hardwareDescription() { | ||
145 | + return null; | ||
146 | + } | ||
147 | + | ||
148 | + @Override | ||
149 | + public String softwareDescription() { | ||
150 | + return null; | ||
151 | + } | ||
152 | + | ||
153 | + @Override | ||
154 | + public String serialNumber() { | ||
155 | + return null; | ||
156 | + } | ||
157 | + | ||
158 | + @Override | ||
159 | + public void disconnectSwitch() { | ||
160 | + } | ||
161 | + | ||
162 | + @Override | ||
163 | + public void returnRoleAssertFailure(RoleState role) { | ||
164 | + failed = role; | ||
165 | + } | ||
166 | + | ||
167 | + @Override | ||
168 | + public void setAgent(OpenFlowAgent agent) { | ||
169 | + } | ||
170 | + | ||
171 | + @Override | ||
172 | + public void setRoleHandler(RoleHandler roleHandler) { | ||
173 | + } | ||
174 | + | ||
175 | + @Override | ||
176 | + public void reassertRole() { | ||
177 | + } | ||
178 | + | ||
179 | + @Override | ||
180 | + public boolean handleRoleError(OFErrorMsg error) { | ||
181 | + return false; | ||
182 | + } | ||
183 | + | ||
184 | + @Override | ||
185 | + public void handleNiciraRole(OFMessage m) throws SwitchStateException { | ||
186 | + } | ||
187 | + | ||
188 | + @Override | ||
189 | + public void handleRole(OFMessage m) throws SwitchStateException { | ||
190 | + } | ||
191 | + | ||
192 | + @Override | ||
193 | + public void startDriverHandshake() { | ||
194 | + } | ||
195 | + | ||
196 | + @Override | ||
197 | + public boolean isDriverHandshakeComplete() { | ||
198 | + return false; | ||
199 | + } | ||
200 | + | ||
201 | + @Override | ||
202 | + public void processDriverHandshakeMessage(OFMessage m) { | ||
203 | + } | ||
204 | + | ||
205 | + @Override | ||
206 | + public boolean connectSwitch() { | ||
207 | + return false; | ||
208 | + } | ||
209 | + | ||
210 | + @Override | ||
211 | + public boolean activateMasterSwitch() { | ||
212 | + return false; | ||
213 | + } | ||
214 | + | ||
215 | + @Override | ||
216 | + public boolean activateEqualSwitch() { | ||
217 | + return false; | ||
218 | + } | ||
219 | + | ||
220 | + @Override | ||
221 | + public void transitionToEqualSwitch() { | ||
222 | + } | ||
223 | + | ||
224 | + @Override | ||
225 | + public void transitionToMasterSwitch() { | ||
226 | + } | ||
227 | + | ||
228 | + @Override | ||
229 | + public void removeConnectedSwitch() { | ||
230 | + } | ||
231 | + | ||
232 | + @Override | ||
233 | + public void setPortDescReply(OFPortDescStatsReply portDescReply) { | ||
234 | + } | ||
235 | + | ||
236 | + @Override | ||
237 | + public void setFeaturesReply(OFFeaturesReply featuresReply) { | ||
238 | + } | ||
239 | + | ||
240 | + @Override | ||
241 | + public void setSwitchDescription(OFDescStatsReply desc) { | ||
242 | + } | ||
243 | + | ||
244 | + @Override | ||
245 | + public int getNextTransactionId() { | ||
246 | + return (int) XID; | ||
247 | + } | ||
248 | + | ||
249 | + @Override | ||
250 | + public Boolean supportNxRole() { | ||
251 | + return true; | ||
252 | + } | ||
253 | + | ||
254 | + @Override | ||
255 | + public void setOFVersion(OFVersion ofV) { | ||
256 | + } | ||
257 | + | ||
258 | + @Override | ||
259 | + public void setTableFull(boolean full) { | ||
260 | + } | ||
261 | + | ||
262 | + @Override | ||
263 | + public void setChannel(Channel channel) { | ||
264 | + } | ||
265 | + | ||
266 | + @Override | ||
267 | + public void setConnected(boolean connected) { | ||
268 | + } | ||
269 | + | ||
270 | + @Override | ||
271 | + public boolean isConnected() { | ||
272 | + return false; | ||
273 | + } | ||
274 | + | ||
275 | + @Override | ||
276 | + public void write(OFMessage msg) { | ||
277 | + } | ||
278 | + | ||
279 | + @Override | ||
280 | + public void write(List<OFMessage> msgs) { | ||
281 | + } | ||
282 | + | ||
283 | + } | ||
284 | +} |
-
Please register or login to post a comment