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.util.Collections;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.Mock;
19 import org.mockito.junit.MockitoJUnitRunner;
20 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
21 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
22 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
23 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
24 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10Builder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
38 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
39 import org.opendaylight.yangtools.yang.common.Uint16;
40 import org.opendaylight.yangtools.yang.common.Uint32;
41 import org.opendaylight.yangtools.yang.common.Uint64;
44 * Test of {@link AggregatedFlowStatisticsTranslator}.
46 @RunWith(MockitoJUnitRunner.class)
47 public class FlowRemovedTranslatorTest {
49 private FlowRemovedTranslator translator;
51 private FlowRemovedV10Translator translatorV10;
54 private DeviceContext deviceContext;
57 private DeviceState deviceState;
60 private DeviceInfo deviceInfo;
63 private GetFeaturesOutput features;
66 private FlowWildcardsV10 flowWildcards;
70 final KeyedInstanceIdentifier<Node, NodeKey> nodeId = InstanceIdentifier.create(Nodes.class)
71 .child(Node.class, new NodeKey(new NodeId("dummyNodeId")));
73 final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
74 translator = new FlowRemovedTranslator(convertorManager);
75 translatorV10 = new FlowRemovedV10Translator(convertorManager);
77 when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeId);
81 public void testTranslate() {
82 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved flowRemovedMessage =
84 final FlowRemoved flowRemoved = translator.translate(flowRemovedMessage, deviceInfo, null);
86 assertEquals(flowRemovedMessage.getCookie(), flowRemoved.getCookie().getValue());
87 assertEquals(flowRemovedMessage.getPriority(), flowRemoved.getPriority());
88 assertEquals(flowRemovedMessage.getTableId().getValue().toJava(), flowRemoved.getTableId().toJava());
92 public void testTranslateV10() {
93 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved flowRemovedMessage =
95 final FlowRemoved flowRemoved = translatorV10.translate(flowRemovedMessage, deviceInfo, null);
97 assertEquals(flowRemovedMessage.getCookie(), flowRemoved.getCookie().getValue());
98 assertEquals(flowRemovedMessage.getPriority(), flowRemoved.getPriority());
99 assertEquals((short)0, flowRemoved.getTableId().shortValue());
102 private org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved
103 buildMessage(final boolean isV10) {
104 FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder()
105 .setCookie(Uint64.ONE)
106 .setReason(FlowRemovedReason.OFPRRGROUPDELETE)
107 .setPriority(Uint16.ONE);
110 builder.setMatchV10(new MatchV10Builder().setWildcards(flowWildcards).build());
112 builder.setMatch(new MatchBuilder().setMatchEntry(Collections.emptyList()).build())
113 .setTableId(new TableId(Uint32.valueOf(42)));
116 return builder.build();