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.Before;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.MockitoAnnotations;
21 import org.mockito.runners.MockitoJUnitRunner;
22 import org.opendaylight.openflowplugin.api.OFConstants;
23 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
24 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
25 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionTypeV10;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPortBuilder;
36 import org.opendaylight.yangtools.yang.binding.Augmentation;
37 import org.opendaylight.yangtools.yang.binding.DataContainer;
38 import org.opendaylight.yangtools.yang.binding.DataObject;
40 @RunWith(MockitoJUnitRunner.class)
41 public class FeaturesV10ToNodeConnectorUpdatedTranslatorTest extends TestCase {
43 private static final FeaturesV10ToNodeConnectorUpdatedTranslator FEATURES_V_10_TO_NODE_CONNECTOR_UPDATED_TRANSLATOR = new FeaturesV10ToNodeConnectorUpdatedTranslator();
44 private static final PortFeatures PORT_FEATURES = new PortFeatures(true, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false);
46 @MockitoAnnotations.Mock
47 SwitchConnectionDistinguisher switchConnectionDistinguisher;
48 private static final PortConfig PORT_CONFIG = new PortConfig(true, false, false, false);
49 @MockitoAnnotations.Mock
50 SessionContext sessionContext;
51 @MockitoAnnotations.Mock
52 GetFeaturesOutput featuresOutput;
56 OpenflowPortsUtil.init();
61 * 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)}
63 public void testTranslate() throws Exception {
65 when(sessionContext.getFeatures()).thenReturn(featuresOutput);
66 when(featuresOutput.getDatapathId()).thenReturn(BigInteger.valueOf(42));
67 List<DataObject> data = FEATURES_V_10_TO_NODE_CONNECTOR_UPDATED_TRANSLATOR.translate(switchConnectionDistinguisher, sessionContext, new MockOfHeader());
69 assertEquals(10, data.size());
72 private final class MockOfHeader implements OfHeader, GetFeaturesOutput {
75 public Short getVersion() {
76 return OFConstants.OFP_VERSION_1_3;
80 public Long getXid() {
85 public Class<? extends DataContainer> getImplementedInterface() {
86 return GetFeaturesOutput.class;
90 public <E extends Augmentation<GetFeaturesOutput>> E getAugmentation(Class<E> eClass) {
95 public BigInteger getDatapathId() {
100 public Long getBuffers() {
105 public Short getTables() {
110 public Short getAuxiliaryId() {
115 public Capabilities getCapabilities() {
120 public Long getReserved() {
125 public CapabilitiesV10 getCapabilitiesV10() {
130 public ActionTypeV10 getActionsV10() {
135 public List<PhyPort> getPhyPort() {
136 List<PhyPort> phyPorts = new ArrayList();
137 for (int i = 0; i < 10; i++) {
138 PhyPortBuilder phyPortBuilder = new PhyPortBuilder();
139 phyPortBuilder.setAdvertisedFeatures(PORT_FEATURES);
140 phyPortBuilder.setConfig(PORT_CONFIG);
141 phyPortBuilder.setCurrentFeatures(PORT_FEATURES);
142 phyPortBuilder.setPeerFeatures(PORT_FEATURES);
143 phyPortBuilder.setState(PortState.getDefaultInstance("live"));
144 phyPortBuilder.setSupportedFeatures(PORT_FEATURES);
145 phyPortBuilder.setPortNo(new Long(42));
146 phyPorts.add(phyPortBuilder.build());