import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesReplyConvertor;
import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder;
* @param reply
* @return
*/
- public static FlowCapableNode nodeDescTranslator(@CheckForNull final MultipartReplyDesc reply) {
+ public static FlowCapableNode nodeDescTranslator(@CheckForNull final MultipartReplyDesc reply, final IpAddress ipAddress) {
Preconditions.checkArgument(reply != null);
final FlowCapableNodeBuilder flowCapAugBuilder = new FlowCapableNodeBuilder();
flowCapAugBuilder.setDescription(reply.getDpDesc());
flowCapAugBuilder.setTable(Collections.<Table>emptyList());
flowCapAugBuilder.setMeter(Collections.<Meter>emptyList());
flowCapAugBuilder.setGroup(Collections.<Group>emptyList());
+ if (ipAddress != null) {
+ flowCapAugBuilder.setIpAddress(ipAddress);
+ }
return flowCapAugBuilder.build();
}
import com.google.common.util.concurrent.ListenableFuture;
import io.netty.util.HashedWheelTimer;
import java.math.BigInteger;
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import org.opendaylight.openflowplugin.impl.device.listener.OpenflowProtocolListenerFullImpl;
import org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext;
import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
}
}
+ private static IpAddress getIpAddressOf(final DeviceContext deviceContext) {
+
+ InetSocketAddress remoteAddress = deviceContext.getPrimaryConnectionContext().getConnectionAdapter().getRemoteAddress();
+
+ if (remoteAddress == null) {
+ LOG.warn("IP address of the node {} cannot be obtained. No connection with switch.", deviceContext.getDeviceState().getNodeId());
+ return null;
+ }
+ LOG.info("IP address of switch is :"+remoteAddress);
+
+ final InetAddress address = remoteAddress.getAddress();
+ String hostAddress = address.getHostAddress();
+ if (address instanceof Inet4Address) {
+ return new IpAddress(new Ipv4Address(hostAddress));
+ }
+ if (address instanceof Inet6Address) {
+ return new IpAddress(new Ipv6Address(hostAddress));
+ }
+ LOG.info("Illegal IP address {} of switch:{} ", address, deviceContext.getDeviceState().getNodeId());
+ return null;
+
+ }
+
static void translateAndWriteReply(final MultipartType type, final DeviceContext dContext,
final InstanceIdentifier<Node> nodeII, final Collection<MultipartReply> result) {
try {
case OFPMPDESC:
Preconditions.checkArgument(body instanceof MultipartReplyDescCase);
final MultipartReplyDesc replyDesc = ((MultipartReplyDescCase) body).getMultipartReplyDesc();
- final FlowCapableNode fcNode = NodeStaticReplyTranslatorUtil.nodeDescTranslator(replyDesc);
+ final FlowCapableNode fcNode = NodeStaticReplyTranslatorUtil.nodeDescTranslator(replyDesc, getIpAddressOf(dContext));
final InstanceIdentifier<FlowCapableNode> fNodeII = nodeII.augmentation(FlowCapableNode.class);
dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, fNodeII, fcNode);
break;
private DeviceInitializationPhaseHandler deviceInitPhaseHandler;
@Mock
private TranslatorLibrary translatorLibrary;
+ @Mock
+ private ConnectionContext mockConnectionContext;
+ @Mock
+ private ConnectionAdapter mockedConnectionAdapter;
+ @Mock
+ private DeviceContextImpl mockedDeviceContext;
@Before
public void setUp() throws Exception {
OpenflowPortsUtil.init();
+
+ when(mockConnectionContext.getNodeId()).thenReturn(new NodeId("dummyNodeId"));
+ when(mockConnectionContext.getFeatures()).thenReturn(mockFeatures);
+ when(mockConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);
+ when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockConnectionContext);
+
+ final Capabilities capabilitiesV13 = Mockito.mock(Capabilities.class);
+ final CapabilitiesV10 capabilitiesV10 = Mockito.mock(CapabilitiesV10.class);
+ when(mockFeatures.getCapabilities()).thenReturn(capabilitiesV13);
+ when(mockFeatures.getCapabilitiesV10()).thenReturn(capabilitiesV10);
+ when(mockFeatures.getDatapathId()).thenReturn(BigInteger.valueOf(21L));
}
@Test
public void onDeviceContextLevelUp(boolean withException) {
DeviceManagerImpl deviceManager = prepareDeviceManager(withException);
- DeviceContextImpl mockedDeviceContext = mock(DeviceContextImpl.class);
if (withException) {
doThrow(new IllegalStateException("dummy")).when(mockedDeviceContext).initialSubmitTransaction();
DeviceState mockedDeviceState = mock(DeviceState.class);
}
protected ConnectionContext buildMockConnectionContext(short ofpVersion) {
- ConnectionContext mockConnectionContext = mock(ConnectionContext.class);
- when(mockConnectionContext.getNodeId()).thenReturn(new NodeId("dummyNodeId"));
-
- when(mockConnectionContext.getFeatures()).thenReturn(mockFeatures);
-
- ConnectionAdapter mockedConnectionAdapter = mock(ConnectionAdapter.class);
- when(mockConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);
when(mockFeatures.getVersion()).thenReturn(ofpVersion);
- final Capabilities capabilitiesV13 = Mockito.mock(Capabilities.class);
- final CapabilitiesV10 capabilitiesV10 = Mockito.mock(CapabilitiesV10.class);
- when(mockFeatures.getCapabilities()).thenReturn(capabilitiesV13);
- when(mockFeatures.getCapabilitiesV10()).thenReturn(capabilitiesV10);
- when(mockFeatures.getDatapathId()).thenReturn(BigInteger.valueOf(21L));
-
when(outboundQueueProvider.reserveEntry()).thenReturn(43L);
Mockito.doAnswer(new Answer<Void>() {
@Override
@Test
public void chainTableTrunkWriteOF10Test() {
- DeviceContext mockedDeviceContext = mock(DeviceContext.class);
DeviceState mockedDeviceState = mock(DeviceState.class);
GetFeaturesOutput mockedFeatures = mock(GetFeaturesOutput.class);
when(mockedFeatures.getTables()).thenReturn((short) 2);
when(mockedDeviceState.getFeatures()).thenReturn(mockedFeatures);
-
when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(DUMMY_NODE_II);
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
@Test
public void testTranslateAndWriteReplyTypeDesc() {
- DeviceContext mockedDeviceContext = mock(DeviceContext.class);
+ final ConnectionContext connectionContext = buildMockConnectionContext(OFConstants.OFP_VERSION_1_3);
+ Mockito.when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
+ DeviceState deviceState = Mockito.mock(DeviceState.class);
+ Mockito.when(mockedDeviceContext.getDeviceState()).thenReturn(deviceState);
+
Collection<MultipartReply> multipartReplyMessages = prepareDataforTypeDesc(mockedDeviceContext);
DeviceManagerImpl.translateAndWriteReply(MultipartType.OFPMPDESC, mockedDeviceContext, DUMMY_NODE_II, multipartReplyMessages);
@Test
public void translateAndWriteReplyTypeTableFeatures() {
- DeviceContext mockedDeviceContext = mock(DeviceContext.class);
-
TableFeaturesBuilder tableFeature = new TableFeaturesBuilder();
tableFeature.setTableId(DUMMY_TABLE_ID);
List<TableFeatures> tableFeatures = new ArrayList<>();
@Test
public void translateAndWriteReplyTypeMeterFeatures() {
- DeviceContext mockedDeviceContext = mock(DeviceContext.class);
DeviceState mockedDeviceState = mock(DeviceState.class);
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
@Test
public void translateAndWriteReplyTypeGroupFeatures() {
- DeviceContext mockedDeviceContext = mock(DeviceContext.class);
-
MultipartReplyGroupFeaturesBuilder multipartReplyGroupFeaturesBuilder = new MultipartReplyGroupFeaturesBuilder();
multipartReplyGroupFeaturesBuilder.setTypes(new GroupTypes(true, true, true, true));
multipartReplyGroupFeaturesBuilder.setCapabilities(new GroupCapabilities(true, true, true, true));
@Test
public void translateAndWriteReplyTypePortDesc() {
- DeviceContext mockedDeviceContext = mock(DeviceContext.class);
-
ConnectionContext mockedPrimaryConnectionContext = mock(ConnectionContext.class);
FeaturesReply mockedFeatures = mock(FeaturesReply.class);
when(mockedFeatures.getDatapathId()).thenReturn(new BigInteger(DUMMY_DATAPATH_ID));
@Test
public void createSuccessProcessingCallbackTest() {
- DeviceContext mockedDeviceContext = mock(DeviceContext.class);
DeviceState mockedDeviceState = mock(DeviceState.class);
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
+ final ConnectionContext connectionContext = buildMockConnectionContext(OFConstants.OFP_VERSION_1_3);
+
List<MultipartReply> multipartReplies = new ArrayList<>(prepareDataforTypeDesc(mockedDeviceContext));
RpcResult<List<MultipartReply>> result = RpcResultBuilder.<List<MultipartReply>>success(multipartReplies).build();
ListenableFuture<RpcResult<List<MultipartReply>>> mockedRequestContextFuture = Futures.immediateFuture(result);