2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.openflow.md.core.sal;
11 import com.google.common.base.Optional;
12 import com.google.common.util.concurrent.CheckedFuture;
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.MoreExecutors;
15 import java.math.BigInteger;
16 import java.util.ArrayList;
17 import java.util.List;
18 import java.util.concurrent.ExecutionException;
19 import java.util.concurrent.Executors;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.mockito.Matchers;
24 import org.mockito.Mock;
25 import org.mockito.Mockito;
26 import org.mockito.runners.MockitoJUnitRunner;
27 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
28 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
29 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
30 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
31 import org.opendaylight.openflowplugin.api.OFConstants;
32 import org.opendaylight.openflowplugin.api.openflow.md.core.ConnectionConductor;
33 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
34 import org.opendaylight.openflowplugin.api.openflow.md.core.session.IMessageDispatchService;
35 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
36 import org.opendaylight.openflowplugin.api.openflow.statistics.MessageSpy;
37 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
38 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowHashIdMapping;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInputBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlowBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInputBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInputBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutputBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInputBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInputBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutputBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInputBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutputBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.PortBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.PortKey;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.queue.rev130925.QueueId;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInputBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInputBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutputBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroupBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInputBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutputBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInputBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutputBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInputBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutputBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInputBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutputBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInputBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInputBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInputBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutputBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeterBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInputBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutputBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInputBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutputBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInputBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutputBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInputBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutputBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInputBuilder;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutputBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.port.update.UpdatedPortBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInputBuilder;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutputBuilder;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInputBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutputBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInputBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutputBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortInputBuilder;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutputBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortInputBuilder;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutputBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTable;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableConfig;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfieldBuilder;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesKey;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.TablePropertiesBuilder;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeatureProperties;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeaturePropertiesBuilder;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeaturePropertiesKey;
152 import org.opendaylight.yangtools.yang.binding.DataContainer;
153 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
154 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
155 import org.opendaylight.yangtools.yang.common.RpcResult;
156 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
157 import org.opendaylight.openflowplugin.openflow.md.core.role.OfEntityManager;
158 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
161 * simple NPE smoke test
163 @RunWith(MockitoJUnitRunner.class)
164 public class ModelDrivenSwitchImplTest {
166 private ModelDrivenSwitchImpl mdSwitchOF10;
167 private ModelDrivenSwitchImpl mdSwitchOF13;
170 private SessionContext context;
172 private ConnectionConductor conductor;
174 private IMessageDispatchService messageDispatchService;
176 private GetFeaturesOutput features;
178 private MessageSpy<DataContainer> messageSpy;
180 private DataBroker dataBroker;
182 private ReadWriteTransaction rwTx;
184 private EntityOwnershipService entityOwnershipService;
187 * @throws java.lang.Exception
190 public void setUp() throws Exception {
191 Mockito.when(context.getPrimaryConductor()).thenReturn(conductor);
192 Mockito.when(context.getMessageDispatchService()).thenReturn(messageDispatchService);
193 Mockito.when(conductor.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_0)
194 .thenReturn(OFConstants.OFP_VERSION_1_3);
195 Mockito.when(context.getFeatures()).thenReturn(features);
196 Mockito.when(features.getDatapathId()).thenReturn(BigInteger.valueOf(1));
199 OFSessionUtil.getSessionManager().setRpcPool(MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10)));
200 OFSessionUtil.getSessionManager().setMessageSpy(messageSpy);
201 OFSessionUtil.getSessionManager().setDataBroker(dataBroker);
203 CheckedFuture<Optional<FlowHashIdMapping>, ReadFailedException> dummyReadFuture
204 = Futures.<Optional<FlowHashIdMapping>,ReadFailedException>immediateCheckedFuture(Optional.<FlowHashIdMapping>absent());
205 Mockito.when(rwTx.read(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<FlowHashIdMapping>>any())).thenReturn(dummyReadFuture);
206 Mockito.when(dataBroker.newReadWriteTransaction()).thenReturn(rwTx);
209 OpenflowPortsUtil.init();
211 mdSwitchOF10 = new ModelDrivenSwitchImpl(null, null, context);
212 mdSwitchOF13 = new ModelDrivenSwitchImpl(null, null, context);
217 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#addFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput)}
219 * @throws ExecutionException
220 * @throws InterruptedException
223 public void testAddFlow() throws InterruptedException, ExecutionException {
224 UpdateFlowOutputBuilder updateFlowOutput = new UpdateFlowOutputBuilder();
225 updateFlowOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
226 RpcResult<UpdateFlowOutput> result = RpcResultBuilder.success(updateFlowOutput.build()).build();
228 messageDispatchService.flowMod(Matchers.any(FlowModInput.class),
229 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
231 AddFlowInputBuilder input = new AddFlowInputBuilder();
232 input.setMatch(createMatch());
234 Mockito.when(features.getVersion()).thenReturn((short)1);
235 mdSwitchOF10.addFlow(input.build()).get();
236 Mockito.when(features.getVersion()).thenReturn((short)4);
237 mdSwitchOF13.addFlow(input.build()).get();
238 Mockito.verify(messageDispatchService, Mockito.times(2)).flowMod(
239 Matchers.any(FlowModInput.class),
240 Matchers.any(SwitchConnectionDistinguisher.class));
245 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#removeFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput)}
247 * @throws ExecutionException
248 * @throws InterruptedException
251 public void testRemoveFlow() throws InterruptedException, ExecutionException {
252 UpdateFlowOutputBuilder updateFlowOutput = new UpdateFlowOutputBuilder();
253 updateFlowOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
254 RpcResult<UpdateFlowOutput> result = RpcResultBuilder.success(updateFlowOutput.build()).build();
256 messageDispatchService.flowMod(Matchers.any(FlowModInput.class),
257 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
259 RemoveFlowInputBuilder input = new RemoveFlowInputBuilder();
260 input.setMatch(createMatch());
262 Mockito.when(features.getVersion()).thenReturn((short)1);
263 mdSwitchOF10.removeFlow(input.build()).get();
264 Mockito.when(features.getVersion()).thenReturn((short)4);
265 mdSwitchOF13.removeFlow(input.build()).get();
266 Mockito.verify(messageDispatchService, Mockito.times(2)).flowMod(
267 Matchers.any(FlowModInput.class),
268 Matchers.any(SwitchConnectionDistinguisher.class));
274 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#updateFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput)}
276 * @throws ExecutionException
277 * @throws InterruptedException
280 public void testUpdateFlow() throws InterruptedException, ExecutionException {
281 UpdateFlowOutputBuilder updateFlowOutput = new UpdateFlowOutputBuilder();
282 updateFlowOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
283 RpcResult<UpdateFlowOutput> result = RpcResultBuilder.success(updateFlowOutput.build()).build();
285 messageDispatchService.flowMod(Matchers.any(FlowModInput.class),
286 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
288 UpdateFlowInputBuilder input = new UpdateFlowInputBuilder();
289 UpdatedFlowBuilder updatedFlow = new UpdatedFlowBuilder();
290 updatedFlow.setBarrier(false);
291 updatedFlow.setMatch(createMatch());
292 updatedFlow.setPriority(65);
293 updatedFlow.setFlags(new FlowModFlags(true, false, true, false, true));
294 input.setUpdatedFlow(updatedFlow.build());
295 OriginalFlowBuilder originalFlowBuilder = new OriginalFlowBuilder();
296 originalFlowBuilder.setMatch(createMatch());
297 originalFlowBuilder.setPriority(65);
298 originalFlowBuilder.setFlags(new FlowModFlags(true, false, true, false, true));
299 input.setOriginalFlow(originalFlowBuilder.build());
300 KeyedInstanceIdentifier<Flow, FlowKey> dummyIdentifier = InstanceIdentifier.create(Nodes.class)
301 .child(Node.class, new NodeKey(new NodeId("openflow:1")))
302 .augmentation(FlowCapableNode.class)
303 .child(Table.class, new TableKey((short)0))
304 .child(Flow.class, new FlowKey(new FlowId("1")));
305 input.setFlowRef(new FlowRef(dummyIdentifier));
307 Mockito.when(features.getVersion()).thenReturn((short)1);
308 mdSwitchOF10.updateFlow(input.build()).get();
309 Mockito.when(features.getVersion()).thenReturn((short)4);
310 mdSwitchOF13.updateFlow(input.build()).get();
311 Mockito.verify(messageDispatchService, Mockito.times(2)).flowMod(
312 Matchers.any(FlowModInput.class),
313 Matchers.any(SwitchConnectionDistinguisher.class));
318 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
319 * addGroup(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.
322 * @throws ExecutionException
323 * @throws InterruptedException
326 public void testAddGroup() throws InterruptedException, ExecutionException {
327 UpdateGroupOutputBuilder updateGroupOutput = new UpdateGroupOutputBuilder();
328 updateGroupOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
329 RpcResult<UpdateGroupOutput> result = RpcResultBuilder.success(updateGroupOutput.build()).build();
331 messageDispatchService.groupMod(Matchers.any(GroupModInput.class),
332 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
334 AddGroupInputBuilder input = new AddGroupInputBuilder();
335 input.setGroupType(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes.GroupFf);
336 input.setGroupId(new GroupId(789L));
338 mdSwitchOF10.addGroup(input.build()).get();
339 mdSwitchOF13.addGroup(input.build()).get();
340 Mockito.verify(messageDispatchService, Mockito.times(2)).groupMod(
341 Matchers.any(GroupModInput.class),
342 Matchers.any(SwitchConnectionDistinguisher.class));
347 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
348 * updateGroup(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.
351 * @throws ExecutionException
352 * @throws InterruptedException
355 public void testUpdateGroup() throws InterruptedException, ExecutionException {
356 UpdateGroupOutputBuilder updateGroupOutput = new UpdateGroupOutputBuilder();
357 updateGroupOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
358 RpcResult<UpdateGroupOutput> result = RpcResultBuilder.success(updateGroupOutput.build()).build();
360 messageDispatchService.groupMod(Matchers.any(GroupModInput.class),
361 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
363 UpdateGroupInputBuilder input = new UpdateGroupInputBuilder();
364 UpdatedGroupBuilder updatedGroupBuilder = new UpdatedGroupBuilder();
365 updatedGroupBuilder.setGroupId(new GroupId(789L));
366 updatedGroupBuilder.setGroupType(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes.GroupFf);
367 input.setUpdatedGroup(updatedGroupBuilder.build());
369 mdSwitchOF10.updateGroup(input.build()).get();
370 mdSwitchOF13.updateGroup(input.build()).get();
371 Mockito.verify(messageDispatchService, Mockito.times(2)).groupMod(
372 Matchers.any(GroupModInput.class),
373 Matchers.any(SwitchConnectionDistinguisher.class));
378 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
379 * removeGroup(org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.
382 * @throws ExecutionException
383 * @throws InterruptedException
386 public void testRemoveGroup() throws InterruptedException, ExecutionException {
387 UpdateGroupOutputBuilder updateGroupOutput = new UpdateGroupOutputBuilder();
388 updateGroupOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
389 RpcResult<UpdateGroupOutput> result = RpcResultBuilder.success(updateGroupOutput.build()).build();
391 messageDispatchService.groupMod(Matchers.any(GroupModInput.class),
392 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
394 RemoveGroupInputBuilder input = new RemoveGroupInputBuilder();
395 input.setGroupId(new GroupId(789L));
396 input.setGroupType(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes.GroupFf);
398 mdSwitchOF10.removeGroup(input.build()).get();
399 mdSwitchOF13.removeGroup(input.build()).get();
400 Mockito.verify(messageDispatchService, Mockito.times(2)).groupMod(
401 Matchers.any(GroupModInput.class),
402 Matchers.any(SwitchConnectionDistinguisher.class));
407 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
408 * addMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.
411 * @throws ExecutionException
412 * @throws InterruptedException
415 public void testAddMeter() throws InterruptedException, ExecutionException {
416 UpdateMeterOutputBuilder updateMeterOutput = new UpdateMeterOutputBuilder();
417 updateMeterOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
418 RpcResult<UpdateMeterOutput> result = RpcResultBuilder.success(updateMeterOutput.build()).build();
420 messageDispatchService.meterMod(Matchers.any(MeterModInput.class),
421 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
423 AddMeterInputBuilder input = new AddMeterInputBuilder();
424 input.setMeterId(new MeterId(78L));
426 mdSwitchOF10.addMeter(input.build()).get();
427 mdSwitchOF13.addMeter(input.build()).get();
428 Mockito.verify(messageDispatchService, Mockito.times(2)).meterMod(
429 Matchers.any(MeterModInput.class),
430 Matchers.any(SwitchConnectionDistinguisher.class));
435 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
436 * updateMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.
439 * @throws ExecutionException
440 * @throws InterruptedException
443 public void testUpdtateMeter() throws InterruptedException, ExecutionException {
444 UpdateMeterOutputBuilder updateMeterOutput = new UpdateMeterOutputBuilder();
445 updateMeterOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
446 RpcResult<UpdateMeterOutput> result = RpcResultBuilder.success(updateMeterOutput.build()).build();
448 messageDispatchService.meterMod(Matchers.any(MeterModInput.class),
449 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
451 UpdateMeterInputBuilder input = new UpdateMeterInputBuilder();
452 UpdatedMeterBuilder updatedMeterBuilder = new UpdatedMeterBuilder();
453 updatedMeterBuilder.setMeterId(new MeterId(89L));
454 updatedMeterBuilder.setBarrier(false);
455 input.setUpdatedMeter(updatedMeterBuilder.build());
457 mdSwitchOF10.updateMeter(input.build()).get();
458 mdSwitchOF13.updateMeter(input.build()).get();
459 Mockito.verify(messageDispatchService, Mockito.times(2)).meterMod(
460 Matchers.any(MeterModInput.class),
461 Matchers.any(SwitchConnectionDistinguisher.class));
466 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
467 * removeMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.
470 * @throws ExecutionException
471 * @throws InterruptedException
474 public void testRemoveMeter() throws InterruptedException, ExecutionException {
475 UpdateMeterOutputBuilder updateMeterOutput = new UpdateMeterOutputBuilder();
476 updateMeterOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
477 RpcResult<UpdateMeterOutput> result = RpcResultBuilder.success(updateMeterOutput.build()).build();
479 messageDispatchService.meterMod(Matchers.any(MeterModInput.class),
480 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
482 RemoveMeterInputBuilder input = new RemoveMeterInputBuilder();
483 input.setMeterId(new MeterId(89L));
485 mdSwitchOF10.removeMeter(input.build()).get();
486 mdSwitchOF13.removeMeter(input.build()).get();
487 Mockito.verify(messageDispatchService, Mockito.times(2)).meterMod(
488 Matchers.any(MeterModInput.class),
489 Matchers.any(SwitchConnectionDistinguisher.class));
494 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
495 * getAllGroupStatistics(org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.
496 * GetAllGroupStatisticsInput)}
498 * @throws ExecutionException
499 * @throws InterruptedException
502 public void testGetAllGroupStatistics() throws InterruptedException, ExecutionException {
503 GetAllGroupStatisticsOutputBuilder getAllGroupStatistcsOutput = new GetAllGroupStatisticsOutputBuilder();
504 getAllGroupStatistcsOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
505 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
507 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
508 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
510 GetAllGroupStatisticsInputBuilder input = new GetAllGroupStatisticsInputBuilder();
512 mdSwitchOF10.getAllGroupStatistics(input.build()).get();
513 mdSwitchOF13.getAllGroupStatistics(input.build()).get();
514 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
515 Matchers.any(MultipartRequestInput.class),
516 Matchers.any(SwitchConnectionDistinguisher.class));
521 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
522 * getGroupDescription(org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.
523 * GetGroupDescriptionInput)}
525 * @throws ExecutionException
526 * @throws InterruptedException
529 public void testGetGroupDescription() throws InterruptedException, ExecutionException {
530 GetGroupDescriptionOutputBuilder getGroupDescOutput = new GetGroupDescriptionOutputBuilder();
531 getGroupDescOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
532 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
534 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
535 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
537 GetGroupDescriptionInputBuilder input = new GetGroupDescriptionInputBuilder();
539 mdSwitchOF10.getGroupDescription(input.build()).get();
540 mdSwitchOF13.getGroupDescription(input.build()).get();
541 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
542 Matchers.any(MultipartRequestInput.class),
543 Matchers.any(SwitchConnectionDistinguisher.class));
548 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
549 * getGroupFeatures(org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.
550 * GetGroupFeaturesInput)}
552 * @throws ExecutionException
553 * @throws InterruptedException
556 public void testGetGroupFeatures() throws InterruptedException, ExecutionException {
557 GetGroupFeaturesOutputBuilder getGroupFeaturesOutput = new GetGroupFeaturesOutputBuilder();
558 getGroupFeaturesOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
559 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
561 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
562 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
564 GetGroupFeaturesInputBuilder input = new GetGroupFeaturesInputBuilder();
566 mdSwitchOF10.getGroupFeatures(input.build()).get();
567 mdSwitchOF13.getGroupFeatures(input.build()).get();
568 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
569 Matchers.any(MultipartRequestInput.class),
570 Matchers.any(SwitchConnectionDistinguisher.class));
575 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
576 * getGroupStatistics(org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.
577 * GetGroupStatisticsInput)}
579 * @throws ExecutionException
580 * @throws InterruptedException
582 //TODO GetGroupStatistics why NPE?
584 public void testGetGroupStatistics() throws InterruptedException, ExecutionException {
585 GetGroupStatisticsOutputBuilder getGroupStatsOutput = new GetGroupStatisticsOutputBuilder();
586 getGroupStatsOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
587 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
589 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
590 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
592 GetGroupStatisticsInputBuilder input = new GetGroupStatisticsInputBuilder();
593 input.setGroupId(new GroupId(42L));
595 mdSwitchOF10.getGroupStatistics(input.build()).get();
596 mdSwitchOF13.getGroupStatistics(input.build()).get();
597 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
598 Matchers.any(MultipartRequestInput.class),
599 Matchers.any(SwitchConnectionDistinguisher.class));
604 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
605 * getAllMeterConfigStatistics(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.
606 * GetAllMeterConfigStatisticsInput)}
608 * @throws ExecutionException
609 * @throws InterruptedException
612 public void testGetAllMeterConfigStatistics() throws InterruptedException, ExecutionException {
613 GetAllMeterConfigStatisticsOutputBuilder getAllMeterConfigStatsOutput =
614 new GetAllMeterConfigStatisticsOutputBuilder();
615 getAllMeterConfigStatsOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
616 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
618 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
619 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
621 GetAllMeterConfigStatisticsInputBuilder input = new GetAllMeterConfigStatisticsInputBuilder();
623 mdSwitchOF10.getAllMeterConfigStatistics(input.build()).get();
624 mdSwitchOF13.getAllMeterConfigStatistics(input.build()).get();
625 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
626 Matchers.any(MultipartRequestInput.class),
627 Matchers.any(SwitchConnectionDistinguisher.class));
632 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
633 * getAllMeterStatistics(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.
634 * GetAllMeterStatisticsInput)}
636 * @throws ExecutionException
637 * @throws InterruptedException
640 public void testGetAllMeterStatistics() throws InterruptedException, ExecutionException {
641 GetAllMeterStatisticsOutputBuilder getAllMeterStatisticsOutput =
642 new GetAllMeterStatisticsOutputBuilder();
643 getAllMeterStatisticsOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
644 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
646 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
647 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
649 GetAllMeterStatisticsInputBuilder input = new GetAllMeterStatisticsInputBuilder();
651 mdSwitchOF10.getAllMeterStatistics(input.build()).get();
652 mdSwitchOF13.getAllMeterStatistics(input.build()).get();
653 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
654 Matchers.any(MultipartRequestInput.class),
655 Matchers.any(SwitchConnectionDistinguisher.class));
660 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
661 * getMeterFeatures(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.
662 * GetMeterFeaturesInput)}
664 * @throws ExecutionException
665 * @throws InterruptedException
668 public void testGetMeterFeatures() throws InterruptedException, ExecutionException {
669 GetMeterFeaturesOutputBuilder getMeterFeaturesOutput =
670 new GetMeterFeaturesOutputBuilder();
671 getMeterFeaturesOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
672 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
674 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
675 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
677 GetMeterFeaturesInputBuilder input = new GetMeterFeaturesInputBuilder();
679 mdSwitchOF10.getMeterFeatures(input.build()).get();
680 mdSwitchOF13.getMeterFeatures(input.build()).get();
681 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
682 Matchers.any(MultipartRequestInput.class),
683 Matchers.any(SwitchConnectionDistinguisher.class));
688 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
689 * getMeterStatistics(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.
690 * GetMeterStatisticsInput)}
692 * @throws ExecutionException
693 * @throws InterruptedException
696 public void testGetMeterStatistics() throws InterruptedException, ExecutionException {
697 GetMeterStatisticsOutputBuilder getMeterStatsOutput = new GetMeterStatisticsOutputBuilder();
698 getMeterStatsOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
699 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
701 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
702 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
704 GetMeterStatisticsInputBuilder input = new GetMeterStatisticsInputBuilder();
705 input.setMeterId(new MeterId(42L));
707 mdSwitchOF10.getMeterStatistics(input.build()).get();
708 mdSwitchOF13.getMeterStatistics(input.build()).get();
709 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
710 Matchers.any(MultipartRequestInput.class),
711 Matchers.any(SwitchConnectionDistinguisher.class));
716 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
717 * getAllNodeConnectorsStatistics(org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.
718 * GetAllNodeConnectorsStatisticsInput)}
720 * @throws ExecutionException
721 * @throws InterruptedException
724 public void testGetAllNodeConnectorsStatistics() throws InterruptedException, ExecutionException {
725 GetAllNodeConnectorsStatisticsOutputBuilder getAllNodeConnectorsStatsOutput =
726 new GetAllNodeConnectorsStatisticsOutputBuilder();
727 getAllNodeConnectorsStatsOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
728 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();;
730 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
731 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
733 GetAllNodeConnectorsStatisticsInputBuilder input = new GetAllNodeConnectorsStatisticsInputBuilder();
735 mdSwitchOF10.getAllNodeConnectorsStatistics(input.build()).get();
736 mdSwitchOF13.getAllNodeConnectorsStatistics(input.build()).get();
737 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
738 Matchers.any(MultipartRequestInput.class),
739 Matchers.any(SwitchConnectionDistinguisher.class));
744 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
745 * getNodeConnectorStatistics(org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.
746 * GetNodeConnectorStatisticsInput)}
748 * @throws ExecutionException
749 * @throws InterruptedException
752 public void testGetNodeConnectorStatistics() throws InterruptedException, ExecutionException {
753 GetNodeConnectorStatisticsOutputBuilder getNodeConnectorStatsOutput =
754 new GetNodeConnectorStatisticsOutputBuilder();
755 getNodeConnectorStatsOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
756 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
758 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
759 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
761 GetNodeConnectorStatisticsInputBuilder input = new GetNodeConnectorStatisticsInputBuilder();
762 input.setNodeConnectorId(new NodeConnectorId("openflow:12:8"));
764 Mockito.when(features.getVersion()).thenReturn((short)1);
765 mdSwitchOF10.getNodeConnectorStatistics(input.build()).get();
766 Mockito.when(features.getVersion()).thenReturn((short)4);
767 mdSwitchOF13.getNodeConnectorStatistics(input.build()).get();
768 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
769 Matchers.any(MultipartRequestInput.class),
770 Matchers.any(SwitchConnectionDistinguisher.class));
775 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
776 * updatePort(org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.
779 * @throws ExecutionException
780 * @throws InterruptedException
783 public void testUpdatePort() throws InterruptedException, ExecutionException {
784 UpdatePortOutputBuilder updatePortOutput = new UpdatePortOutputBuilder();
785 updatePortOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
786 RpcResult<UpdatePortOutput> result = RpcResultBuilder.success(updatePortOutput.build()).build();
788 messageDispatchService.portMod(Matchers.any(PortModInput.class),
789 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
791 UpdatePortInputBuilder input = new UpdatePortInputBuilder();
793 PortBuilder portBuilder = new PortBuilder();
794 List<Port> ports = new ArrayList<Port>();
795 ports.add(createPort());
796 portBuilder.setPort(ports);
797 UpdatedPortBuilder updatedPortBuilder = new UpdatedPortBuilder();
798 updatedPortBuilder.setPort(portBuilder.build());
799 input.setUpdatedPort(updatedPortBuilder.build());
801 mdSwitchOF10.updatePort(input.build()).get();
802 mdSwitchOF13.updatePort(input.build()).get();
803 Mockito.verify(messageDispatchService, Mockito.times(2)).portMod(
804 Matchers.any(PortModInput.class),
805 Matchers.any(SwitchConnectionDistinguisher.class));
808 private static Port createPort() {
809 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.PortBuilder port =
810 new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.PortBuilder();
812 port.setPortName("TestingPort01");
813 port.setMask(new PortConfig(true, true, true, true));
814 port.setConfiguration(new PortConfig(true, true, true, true));
815 port.setAdvertisedFeatures(new PortFeatures(true, true, true, true,
816 false, false, false, false,
817 true, true, true, true,
818 false, false, false, false));
819 port.setPortNumber(new PortNumberUni(42L));
820 port.setHardwareAddress(new MacAddress("01:23:45:67:89:ab"));
821 port.setBarrier(true);
822 port.setContainerName("TestContainer");
823 port.setPortModOrder(25L);
824 port.setKey(new PortKey(25L));
830 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
831 * updateTable(org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.
834 * @throws ExecutionException
835 * @throws InterruptedException
838 public void testUpdateTable() throws InterruptedException, ExecutionException {
839 UpdateTableOutputBuilder updateTableOutput = new UpdateTableOutputBuilder();
840 updateTableOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
841 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
843 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
844 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
846 UpdateTableInputBuilder input = new UpdateTableInputBuilder();
847 input.setUpdatedTable(createUpdateTable());
849 mdSwitchOF10.updateTable(input.build()).get();
850 mdSwitchOF13.updateTable(input.build()).get();
851 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
852 Matchers.any(MultipartRequestInput.class),
853 Matchers.any(SwitchConnectionDistinguisher.class));
856 private static UpdatedTable createUpdateTable() {
857 UpdatedTableBuilder updatedTableBuilder = new UpdatedTableBuilder();
858 TableFeaturesBuilder tableFeaturesBuilder = new TableFeaturesBuilder();
859 tableFeaturesBuilder.setConfig(new TableConfig(true));
860 tableFeaturesBuilder.setKey(new TableFeaturesKey((short) 42));
861 tableFeaturesBuilder.setMaxEntries(42L);
862 tableFeaturesBuilder.setMetadataMatch(BigInteger.valueOf(42424242));
863 tableFeaturesBuilder.setMetadataWrite(BigInteger.valueOf(42424242));
864 tableFeaturesBuilder.setName("testTableFeatures");
865 tableFeaturesBuilder.setTableId((short) 41);
867 TablePropertiesBuilder tablePropertiesBuilder = new TablePropertiesBuilder();
868 TableFeaturePropertiesBuilder tableFeaturePropertiesBuilder = new TableFeaturePropertiesBuilder();
869 tableFeaturePropertiesBuilder.setKey(new TableFeaturePropertiesKey(45));
870 tableFeaturePropertiesBuilder.setOrder(44);
871 tableFeaturePropertiesBuilder.setTableFeaturePropType(new ApplySetfieldBuilder().build());
872 List<TableFeatureProperties> tableFeatureProperties = new ArrayList<TableFeatureProperties>();
873 tableFeatureProperties.add(tableFeaturePropertiesBuilder.build());
874 tablePropertiesBuilder.setTableFeatureProperties(tableFeatureProperties);
876 tableFeaturesBuilder.setTableProperties(tablePropertiesBuilder.build());
877 List<TableFeatures> tableFeatures = new ArrayList<TableFeatures>();
878 tableFeatures.add(tableFeaturesBuilder.build());
879 updatedTableBuilder.setTableFeatures(tableFeatures);
880 return updatedTableBuilder.build();
885 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
886 * getAllFlowStatisticsFromFlowTable(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.
887 * GetAllFlowStatisticsFromFlowTableInput)}
889 * @throws ExecutionException
890 * @throws InterruptedException
893 public void testGetAllFlowStatisticsFromFlowTable() throws InterruptedException, ExecutionException {
894 GetAllFlowStatisticsFromFlowTableOutputBuilder allFlowStatisticsFromFlowTableOutput =
895 new GetAllFlowStatisticsFromFlowTableOutputBuilder();
896 allFlowStatisticsFromFlowTableOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
897 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
899 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
900 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
902 GetAllFlowStatisticsFromFlowTableInputBuilder input = new GetAllFlowStatisticsFromFlowTableInputBuilder();
903 input.setTableId(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId((short) 42));
905 mdSwitchOF10.getAllFlowStatisticsFromFlowTable(input.build()).get();
906 mdSwitchOF13.getAllFlowStatisticsFromFlowTable(input.build()).get();
907 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
908 Matchers.any(MultipartRequestInput.class),
909 Matchers.any(SwitchConnectionDistinguisher.class));
914 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
915 * getAllFlowStatisticsFromFlowTable(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.
916 * GetAllFlowStatisticsFromFlowTableInput)}
918 * @throws ExecutionException
919 * @throws InterruptedException
922 public void testGetAllFlowsStatisticsFromAllFlowTables() throws InterruptedException, ExecutionException {
923 GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder allFlowStatisticsFromAllFlowTablesOutput =
924 new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder();
925 allFlowStatisticsFromAllFlowTablesOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
926 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
928 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
929 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
931 GetAllFlowsStatisticsFromAllFlowTablesInputBuilder input =
932 new GetAllFlowsStatisticsFromAllFlowTablesInputBuilder();
934 mdSwitchOF10.getAllFlowsStatisticsFromAllFlowTables(input.build()).get();
935 mdSwitchOF13.getAllFlowsStatisticsFromAllFlowTables(input.build()).get();
936 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
937 Matchers.any(MultipartRequestInput.class),
938 Matchers.any(SwitchConnectionDistinguisher.class));
943 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
944 * getAllFlowStatisticsFromFlowTable(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.
945 * GetAllFlowStatisticsFromFlowTableInput)}
947 * @throws ExecutionException
948 * @throws InterruptedException
951 public void testGetFlowStatisticsFromFlowTables() throws InterruptedException, ExecutionException {
952 GetFlowStatisticsFromFlowTableOutputBuilder flowStatisticsFromFlowTablesOutput =
953 new GetFlowStatisticsFromFlowTableOutputBuilder();
954 flowStatisticsFromFlowTablesOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
955 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
957 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
958 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
960 GetFlowStatisticsFromFlowTableInputBuilder input =
961 new GetFlowStatisticsFromFlowTableInputBuilder();
962 input.setMatch(createMatch());
964 mdSwitchOF10.getFlowStatisticsFromFlowTable(input.build()).get();
965 mdSwitchOF13.getFlowStatisticsFromFlowTable(input.build()).get();
966 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
967 Matchers.any(MultipartRequestInput.class),
968 Matchers.any(SwitchConnectionDistinguisher.class));
971 private static Match createMatch() {
972 MatchBuilder matchBuilder = new MatchBuilder();
973 EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder();
974 EthernetDestinationBuilder ethernetDestinationBuilder = new EthernetDestinationBuilder();
975 ethernetDestinationBuilder.setAddress(new MacAddress("01:23:45:67:89:ab"));
976 ethernetDestinationBuilder.setMask(new MacAddress("01:23:45:67:89:ab"));
977 ethernetMatchBuilder.setEthernetDestination(ethernetDestinationBuilder.build());
978 EthernetSourceBuilder ethernetSourceBuilder = new EthernetSourceBuilder();
979 ethernetSourceBuilder.setAddress(new MacAddress("01:23:45:67:89:ab"));
980 ethernetSourceBuilder.setMask(new MacAddress("01:23:45:67:89:ab"));
981 ethernetMatchBuilder.setEthernetSource(ethernetSourceBuilder.build());
982 ethernetMatchBuilder.setEthernetType(new EthernetTypeBuilder().setType(new EtherType(42L)).build());
983 matchBuilder.setEthernetMatch(ethernetMatchBuilder.build());
984 return matchBuilder.build();
989 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
990 * getAggregateFlowStatisticsFromFlowTableForAllFlows(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.
991 * GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput)}
993 * @throws ExecutionException
994 * @throws InterruptedException
997 public void testGetAggregateFlowStatisticsFromFlowTableForAllFlows() throws InterruptedException,
999 GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder aggregateFlowStatisticsOutput =
1000 new GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutputBuilder();
1001 aggregateFlowStatisticsOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
1002 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
1004 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
1005 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
1007 GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder input =
1008 new GetAggregateFlowStatisticsFromFlowTableForAllFlowsInputBuilder();
1009 input.setTableId(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId((short) 42));
1011 mdSwitchOF10.getAggregateFlowStatisticsFromFlowTableForAllFlows(input.build()).get();
1012 mdSwitchOF13.getAggregateFlowStatisticsFromFlowTableForAllFlows(input.build()).get();
1013 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
1014 Matchers.any(MultipartRequestInput.class),
1015 Matchers.any(SwitchConnectionDistinguisher.class));
1020 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
1021 * getAggregateFlowStatisticsFromFlowTableForGivenMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.
1022 * GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput)}
1024 * @throws ExecutionException
1025 * @throws InterruptedException
1028 public void testGetAggregateFlowStatisticsFromFlowTableForGivenMatch() throws InterruptedException,
1029 ExecutionException {
1030 GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder aggregateFlowStatisticsForMatchOutput =
1031 new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
1032 aggregateFlowStatisticsForMatchOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
1033 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
1035 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
1036 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
1038 GetAggregateFlowStatisticsFromFlowTableForGivenMatchInputBuilder input =
1039 new GetAggregateFlowStatisticsFromFlowTableForGivenMatchInputBuilder();
1040 input.setMatch(createMatch());
1041 input.setCookie(new FlowCookie(BigInteger.valueOf(123456)));
1042 input.setCookieMask(new FlowCookie(BigInteger.valueOf(123456)));
1043 input.setOutGroup(44L);
1044 input.setOutPort(BigInteger.valueOf(12563));
1046 mdSwitchOF10.getAggregateFlowStatisticsFromFlowTableForGivenMatch(input.build()).get();
1047 mdSwitchOF13.getAggregateFlowStatisticsFromFlowTableForGivenMatch(input.build()).get();
1048 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
1049 Matchers.any(MultipartRequestInput.class),
1050 Matchers.any(SwitchConnectionDistinguisher.class));
1055 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
1056 * getFlowTablesStatistics(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.
1057 * GetFlowTablesStatisticsInput)}
1059 * @throws ExecutionException
1060 * @throws InterruptedException
1063 public void testGetFlowTablesStatistics() throws InterruptedException, ExecutionException {
1064 GetFlowTablesStatisticsOutputBuilder flowTableStatisticsOutput =
1065 new GetFlowTablesStatisticsOutputBuilder();
1066 flowTableStatisticsOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
1067 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
1069 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
1070 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
1072 GetFlowTablesStatisticsInputBuilder input = new GetFlowTablesStatisticsInputBuilder();
1074 mdSwitchOF10.getFlowTablesStatistics(input.build()).get();
1075 mdSwitchOF13.getFlowTablesStatistics(input.build()).get();
1076 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
1077 Matchers.any(MultipartRequestInput.class),
1078 Matchers.any(SwitchConnectionDistinguisher.class));
1083 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
1084 * getAllQueuesStatisticsFromAllPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.
1085 * GetAllQueuesStatisticsFromAllPortsInput)}
1087 * @throws ExecutionException
1088 * @throws InterruptedException
1091 public void testGetAllQueuesStatisticsFromAllPorts() throws InterruptedException, ExecutionException {
1092 GetAllQueuesStatisticsFromAllPortsOutputBuilder allQueuesStatisticsAllPortsOutput =
1093 new GetAllQueuesStatisticsFromAllPortsOutputBuilder();
1094 allQueuesStatisticsAllPortsOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
1095 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
1097 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
1098 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
1100 GetAllQueuesStatisticsFromAllPortsInputBuilder input =
1101 new GetAllQueuesStatisticsFromAllPortsInputBuilder();
1103 mdSwitchOF10.getAllQueuesStatisticsFromAllPorts(input.build()).get();
1104 mdSwitchOF13.getAllQueuesStatisticsFromAllPorts(input.build()).get();
1105 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
1106 Matchers.any(MultipartRequestInput.class),
1107 Matchers.any(SwitchConnectionDistinguisher.class));
1112 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
1113 * getAllQueuesStatisticsFromGivenPort(org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.
1114 * GetAllQueuesStatisticsFromGivenPortInput)}
1116 * @throws ExecutionException
1117 * @throws InterruptedException
1120 public void testGetAllQueuesStatisticsFromGivenPort() throws InterruptedException, ExecutionException {
1121 GetAllQueuesStatisticsFromGivenPortOutputBuilder allQueuesStatisticsGivenPortsOutput =
1122 new GetAllQueuesStatisticsFromGivenPortOutputBuilder();
1123 allQueuesStatisticsGivenPortsOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
1124 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
1126 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
1127 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
1129 GetAllQueuesStatisticsFromGivenPortInputBuilder input =
1130 new GetAllQueuesStatisticsFromGivenPortInputBuilder();
1131 input.setNodeConnectorId(new NodeConnectorId("openflow:12:8"));
1133 Mockito.when(features.getVersion()).thenReturn((short)1);
1134 mdSwitchOF10.getAllQueuesStatisticsFromGivenPort(input.build()).get();
1135 Mockito.when(features.getVersion()).thenReturn((short)4);
1136 mdSwitchOF13.getAllQueuesStatisticsFromGivenPort(input.build()).get();
1137 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
1138 Matchers.any(MultipartRequestInput.class),
1139 Matchers.any(SwitchConnectionDistinguisher.class));
1144 * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.ModelDrivenSwitchImpl#
1145 * getQueueStatisticsFromGivenPort(org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.
1146 * GetQueueStatisticsFromGivenPortInput)}
1148 * @throws ExecutionException
1149 * @throws InterruptedException
1152 public void testGetQueueStatisticsFromGivenPort() throws InterruptedException, ExecutionException {
1153 GetQueueStatisticsFromGivenPortOutputBuilder queuesStatisticsGivenPortOutput =
1154 new GetQueueStatisticsFromGivenPortOutputBuilder();
1155 queuesStatisticsGivenPortOutput.setTransactionId(new TransactionId(BigInteger.valueOf(42)));
1156 RpcResult<Void> result = RpcResultBuilder.success((Void)null).build();
1158 messageDispatchService.multipartRequest(Matchers.any(MultipartRequestInput.class),
1159 Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
1161 GetQueueStatisticsFromGivenPortInputBuilder input =
1162 new GetQueueStatisticsFromGivenPortInputBuilder();
1163 input.setNodeConnectorId(new NodeConnectorId("openflow:12:8"));
1164 input.setQueueId(new QueueId(55L));
1166 Mockito.when(features.getVersion()).thenReturn((short)1);
1167 mdSwitchOF10.getQueueStatisticsFromGivenPort(input.build()).get();
1168 Mockito.when(features.getVersion()).thenReturn((short)4);
1169 mdSwitchOF13.getQueueStatisticsFromGivenPort(input.build()).get();
1170 Mockito.verify(messageDispatchService, Mockito.times(2)).multipartRequest(
1171 Matchers.any(MultipartRequestInput.class),
1172 Matchers.any(SwitchConnectionDistinguisher.class));