Support IGD v2 port mappings by GiovanniMenzano · Pull Request #367 · jupnp/jupnp · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.jupnp.support.igd.callback;

import java.util.Objects;

import org.jupnp.controlpoint.ActionCallback;
import org.jupnp.controlpoint.ControlPoint;
import org.jupnp.model.action.ActionInvocation;
Expand All @@ -38,10 +40,10 @@ protected PortMappingAdd(Service<?, ?> service, ControlPoint controlPoint, PortM

this.portMapping = portMapping;

getActionInvocation().setInput("NewExternalPort", portMapping.getExternalPort());
getActionInvocation().setInput("NewExternalPort", Objects.toString(portMapping.getExternalPort(), null));
getActionInvocation().setInput("NewProtocol", portMapping.getProtocol());
getActionInvocation().setInput("NewInternalClient", portMapping.getInternalClient());
getActionInvocation().setInput("NewInternalPort", portMapping.getInternalPort());
getActionInvocation().setInput("NewInternalPort", Objects.toString(portMapping.getInternalPort(), null));
getActionInvocation().setInput("NewLeaseDuration", portMapping.getLeaseDurationSeconds());
getActionInvocation().setInput("NewEnabled", portMapping.isEnabled());
if (portMapping.hasRemoteHost()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.jupnp.support.igd.callback;

import java.util.Objects;

import org.jupnp.controlpoint.ActionCallback;
import org.jupnp.controlpoint.ControlPoint;
import org.jupnp.model.action.ActionInvocation;
Expand All @@ -38,7 +40,7 @@ protected PortMappingDelete(Service<?, ?> service, ControlPoint controlPoint, Po

this.portMapping = portMapping;

getActionInvocation().setInput("NewExternalPort", portMapping.getExternalPort());
getActionInvocation().setInput("NewExternalPort", Objects.toString(portMapping.getExternalPort(), null));
getActionInvocation().setInput("NewProtocol", portMapping.getProtocol());
if (portMapping.hasRemoteHost()) {
getActionInvocation().setInput("NewRemoteHost", portMapping.getRemoteHost());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2011-2026 4th Line GmbH, Switzerland and others
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License Version 1 or later
* ("CDDL") (collectively, the "License"). You may not use this file
* except in compliance with the License. See LICENSE.txt for more
* information.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* SPDX-License-Identifier: CDDL-1.0
*/
package org.jupnp.support.igd;

import static org.junit.jupiter.api.Assertions.assertSame;

import java.net.InetAddress;
import java.net.URI;
import java.net.URL;

import org.junit.jupiter.api.Test;
import org.jupnp.model.meta.DeviceDetails;
import org.jupnp.model.meta.RemoteDevice;
import org.jupnp.model.meta.RemoteDeviceIdentity;
import org.jupnp.model.meta.RemoteService;
import org.jupnp.model.meta.Service;
import org.jupnp.model.types.UDADeviceType;
import org.jupnp.model.types.UDAServiceId;
import org.jupnp.model.types.UDAServiceType;
import org.jupnp.model.types.UDN;
import org.jupnp.support.model.PortMapping;

class PortMappingListenerTest {

@Test
void discoversVersionTwoInternetGatewayDevice() throws Exception {
final RemoteService connectionService = new RemoteService(new UDAServiceType("WANIPConnection", 2),
new UDAServiceId("WANIPConnection"), URI.create("service.xml"), URI.create("control"),
URI.create("events"));
final RemoteDevice connectionDevice = new RemoteDevice(identity("connection"),
new UDADeviceType("WANConnectionDevice", 2), new DeviceDetails("WAN connection"),
new RemoteService[] { connectionService });
final RemoteDevice wanDevice = new RemoteDevice(identity("wan"), new UDADeviceType("WANDevice", 2),
new DeviceDetails("WAN device"), new RemoteService[0], new RemoteDevice[] { connectionDevice });
final RemoteDevice gateway = new RemoteDevice(identity("gateway"),
new UDADeviceType("InternetGatewayDevice", 2), new DeviceDetails("Internet gateway"),
new RemoteService[0], new RemoteDevice[] { wanDevice });

final Service<?, ?> discovered = new PortMappingListener(new PortMapping()).discoverConnectionService(gateway);

assertSame(connectionService, discovered);
}

private RemoteDeviceIdentity identity(final String name) throws Exception {
final URL descriptorUrl = new URL("http://127.0.0.1/" + name + ".xml");
final InetAddress localAddress = InetAddress.getLoopbackAddress();
return new RemoteDeviceIdentity(new UDN("uuid:" + name), 1800, descriptorUrl, null, localAddress);
}
}
Loading