2 * Copyright (c) 2015 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.impl.translator;
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Mockito.when;
14 import java.math.BigInteger;
15 import java.util.Collections;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.runners.MockitoJUnitRunner;
21 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
22 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
23 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
24 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
25 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10Builder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
42 * Test of {@link AggregatedFlowStatisticsTranslator}.
44 @RunWith(MockitoJUnitRunner.class)
45 public class FlowRemovedTranslatorTest {
47 private FlowRemovedTranslator translator;
49 private FlowRemovedV10Translator translatorV10;
52 private DeviceContext deviceContext;
55 private DeviceState deviceState;
58 private DeviceInfo deviceInfo;
61 private GetFeaturesOutput features;
64 private FlowWildcardsV10 flowWildcards;
68 final KeyedInstanceIdentifier<Node, NodeKey> nodeId = InstanceIdentifier.create(Nodes.class)
69 .child(Node.class, new NodeKey(new NodeId("dummyNodeId")));
71 final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
72 translator = new FlowRemovedTranslator(convertorManager);
73 translatorV10 = new FlowRemovedV10Translator(convertorManager);
75 when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeId);
79 public void testTranslate() {
80 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved flowRemovedMessage =
82 final FlowRemoved flowRemoved = translator.translate(flowRemovedMessage, deviceInfo, null);
84 assertEquals(flowRemovedMessage.getCookie(), flowRemoved.getCookie().getValue());
85 assertEquals(flowRemovedMessage.getPriority(), flowRemoved.getPriority());
86 assertEquals((long)flowRemovedMessage.getTableId().getValue(), (long)flowRemoved.getTableId());
90 public void testTranslateV10() {
91 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved flowRemovedMessage =
93 final FlowRemoved flowRemoved = translatorV10.translate(flowRemovedMessage, deviceInfo, null);
95 assertEquals(flowRemovedMessage.getCookie(), flowRemoved.getCookie().getValue());
96 assertEquals(flowRemovedMessage.getPriority(), flowRemoved.getPriority());
97 assertEquals((short)0, flowRemoved.getTableId().shortValue());
100 private org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved
101 buildMessage(boolean isV10) {
102 FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder()
103 .setCookie(BigInteger.ONE)
104 .setReason(FlowRemovedReason.OFPRRGROUPDELETE)
108 builder.setMatchV10(new MatchV10Builder().setWildcards(flowWildcards).build());
110 builder.setMatch(new MatchBuilder().setMatchEntry(Collections.emptyList()).build())
111 .setTableId(new TableId(42L));
114 return builder.build();