2 * Copyright (c) 2014 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.translator;
11 import static org.mockito.Mockito.when;
13 import java.math.BigInteger;
14 import java.util.ArrayList;
15 import java.util.List;
16 import junit.framework.TestCase;
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.OFConstants;
22 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
23 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionTypeV10;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPortBuilder;
34 import org.opendaylight.yangtools.yang.binding.Augmentation;
35 import org.opendaylight.yangtools.yang.binding.DataContainer;
36 import org.opendaylight.yangtools.yang.binding.DataObject;
38 @RunWith(MockitoJUnitRunner.class)
39 public class FeaturesV10ToNodeConnectorUpdatedTranslatorTest extends TestCase {
41 private static final FeaturesV10ToNodeConnectorUpdatedTranslator FEATURES_V_10_TO_NODE_CONNECTOR_UPDATED_TRANSLATOR = new FeaturesV10ToNodeConnectorUpdatedTranslator();
42 private static final PortFeatures PORT_FEATURES = new PortFeatures(true, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false);
45 SwitchConnectionDistinguisher switchConnectionDistinguisher;
46 private static final PortConfig PORT_CONFIG = new PortConfig(true, false, false, false);
48 SessionContext sessionContext;
50 GetFeaturesOutput featuresOutput;
54 * Test method for basic functionality of {@link FeaturesV10ToNodeConnectorUpdatedTranslator#translate(org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher, org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader)}
56 public void testTranslate() throws Exception {
58 when(sessionContext.getFeatures()).thenReturn(featuresOutput);
59 when(featuresOutput.getDatapathId()).thenReturn(BigInteger.valueOf(42));
60 List<DataObject> data = FEATURES_V_10_TO_NODE_CONNECTOR_UPDATED_TRANSLATOR.translate(switchConnectionDistinguisher, sessionContext, new MockOfHeader());
62 assertEquals(10, data.size());
65 private final class MockOfHeader implements OfHeader, GetFeaturesOutput {
68 public Short getVersion() {
69 return OFConstants.OFP_VERSION_1_3;
73 public Long getXid() {
78 public Class<? extends DataContainer> getImplementedInterface() {
79 return GetFeaturesOutput.class;
83 public <E extends Augmentation<GetFeaturesOutput>> E getAugmentation(final Class<E> eClass) {
88 public BigInteger getDatapathId() {
93 public Long getBuffers() {
98 public Short getTables() {
103 public Short getAuxiliaryId() {
108 public Capabilities getCapabilities() {
113 public Long getReserved() {
118 public CapabilitiesV10 getCapabilitiesV10() {
123 public ActionTypeV10 getActionsV10() {
128 public List<PhyPort> getPhyPort() {
129 List<PhyPort> phyPorts = new ArrayList<>();
130 for (int i = 0; i < 10; i++) {
131 PhyPortBuilder phyPortBuilder = new PhyPortBuilder();
132 phyPortBuilder.setAdvertisedFeatures(PORT_FEATURES);
133 phyPortBuilder.setConfig(PORT_CONFIG);
134 phyPortBuilder.setCurrentFeatures(PORT_FEATURES);
135 phyPortBuilder.setPeerFeatures(PORT_FEATURES);
136 phyPortBuilder.setState(PortState.getDefaultInstance("live"));
137 phyPortBuilder.setSupportedFeatures(PORT_FEATURES);
138 phyPortBuilder.setPortNo(new Long(42));
139 phyPorts.add(phyPortBuilder.build());