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 1 commit
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 @@ -38,10 +38,10 @@ protected PortMappingAdd(Service<?, ?> service, ControlPoint controlPoint, PortM

this.portMapping = portMapping;

getActionInvocation().setInput("NewExternalPort", portMapping.getExternalPort());
getActionInvocation().setInput("NewExternalPort", portMapping.getExternalPort().toString());
getActionInvocation().setInput("NewProtocol", portMapping.getProtocol());
getActionInvocation().setInput("NewInternalClient", portMapping.getInternalClient());
getActionInvocation().setInput("NewInternalPort", portMapping.getInternalPort());
getActionInvocation().setInput("NewInternalPort", portMapping.getInternalPort().toString());
Comment thread
wborn marked this conversation as resolved.
Outdated
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 @@ -38,7 +38,7 @@ protected PortMappingDelete(Service<?, ?> service, ControlPoint controlPoint, Po

this.portMapping = portMapping;

getActionInvocation().setInput("NewExternalPort", portMapping.getExternalPort());
getActionInvocation().setInput("NewExternalPort", portMapping.getExternalPort().toString());
Comment thread
wborn marked this conversation as resolved.
Outdated
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,60 @@
/*
* 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", 1),
new UDAServiceId("WANIPConnection"), URI.create("service.xml"), URI.create("control"),
URI.create("events"));
final RemoteDevice connectionDevice = new RemoteDevice(identity("connection"),
new UDADeviceType("WANConnectionDevice", 1), new DeviceDetails("WAN connection"),
new RemoteService[] { connectionService });
final RemoteDevice gateway = new RemoteDevice(identity("gateway"),
new UDADeviceType("InternetGatewayDevice", 2), new DeviceDetails("Internet gateway"),
new RemoteService[0], new RemoteDevice[] { connectionDevice });
Comment thread
wborn marked this conversation as resolved.
Outdated

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