{{ message }}
Repository navigation
Support IGD v2 port mappings #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+197
−4
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Support IGD v2 port mappings
Handle newer gateways and routers that describe ports differently. Fixes #366 Signed-off-by: Giovanni Menzano <giovanni.menzano@gmail.com>
- Loading branch information
commit 38fd3d8755af246869efa3f56802aec8858bd34a
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
bundles/org.jupnp.support/src/test/java/org/jupnp/support/igd/PortMappingListenerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }); | ||
|
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); | ||
| } | ||
| } | ||
107 changes: 107 additions & 0 deletions
107
...g.jupnp.support/src/test/java/org/jupnp/support/igd/callback/PortMappingCallbackTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| * 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.callback; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
|
|
||
| import java.net.URI; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.jupnp.model.action.ActionInvocation; | ||
| import org.jupnp.model.message.UpnpResponse; | ||
| import org.jupnp.model.meta.Action; | ||
| import org.jupnp.model.meta.ActionArgument; | ||
| import org.jupnp.model.meta.RemoteService; | ||
| import org.jupnp.model.meta.StateVariable; | ||
| import org.jupnp.model.meta.StateVariableTypeDetails; | ||
| import org.jupnp.model.types.Datatype; | ||
| import org.jupnp.model.types.UDAServiceId; | ||
| import org.jupnp.model.types.UDAServiceType; | ||
| import org.jupnp.model.types.UnsignedIntegerFourBytes; | ||
| import org.jupnp.support.model.PortMapping; | ||
|
|
||
| class PortMappingCallbackTest { | ||
|
|
||
| @Test | ||
| void addUsesPortDatatypeAdvertisedByTheService() throws Exception { | ||
| final PortMappingAdd callback = new PortMappingAdd(portMappingService(Datatype.Builtin.UI4.getDatatype(), true), | ||
| mapping()) { | ||
| @Override | ||
| public void success(final ActionInvocation invocation) { | ||
| } | ||
|
|
||
| @Override | ||
| public void failure(final ActionInvocation invocation, final UpnpResponse operation, | ||
| final String defaultMsg) { | ||
| } | ||
| }; | ||
| final ActionInvocation<?> invocation = callback.getActionInvocation(); | ||
|
|
||
| assertInstanceOf(UnsignedIntegerFourBytes.class, invocation.getInput("NewExternalPort").getValue()); | ||
| assertInstanceOf(UnsignedIntegerFourBytes.class, invocation.getInput("NewInternalPort").getValue()); | ||
| } | ||
|
|
||
| @Test | ||
| void deleteUsesPortDatatypeAdvertisedByTheService() throws Exception { | ||
| final PortMappingDelete callback = new PortMappingDelete( | ||
| portMappingService(Datatype.Builtin.UI4.getDatatype(), false), mapping()) { | ||
| @Override | ||
| public void success(final ActionInvocation invocation) { | ||
| } | ||
|
|
||
| @Override | ||
| public void failure(final ActionInvocation invocation, final UpnpResponse operation, | ||
| final String defaultMsg) { | ||
| } | ||
| }; | ||
| final ActionInvocation<?> invocation = callback.getActionInvocation(); | ||
|
|
||
| assertInstanceOf(UnsignedIntegerFourBytes.class, invocation.getInput("NewExternalPort").getValue()); | ||
| } | ||
|
|
||
| private PortMapping mapping() { | ||
| return new PortMapping(36743, "192.168.1.99", PortMapping.Protocol.TCP, "jUPnP test"); | ||
| } | ||
|
|
||
| private RemoteService portMappingService(final Datatype<?> portDatatype, final boolean add) throws Exception { | ||
| final StateVariable[] variables = new StateVariable[] { variable("ExternalPort", portDatatype), | ||
| variable("InternalPort", portDatatype), variable("Protocol", Datatype.Builtin.STRING.getDatatype()), | ||
| variable("InternalClient", Datatype.Builtin.STRING.getDatatype()), | ||
| variable("LeaseDuration", Datatype.Builtin.UI4.getDatatype()), | ||
| variable("Enabled", Datatype.Builtin.BOOLEAN.getDatatype()), | ||
| variable("Description", Datatype.Builtin.STRING.getDatatype()) }; | ||
| final Action action = add | ||
| ? new Action("AddPortMapping", | ||
| new ActionArgument[] { input("NewExternalPort", "ExternalPort"), | ||
| input("NewProtocol", "Protocol"), input("NewInternalClient", "InternalClient"), | ||
| input("NewInternalPort", "InternalPort"), input("NewLeaseDuration", "LeaseDuration"), | ||
| input("NewEnabled", "Enabled"), input("NewPortMappingDescription", "Description") }) | ||
| : new Action("DeletePortMapping", new ActionArgument[] { input("NewExternalPort", "ExternalPort"), | ||
| input("NewProtocol", "Protocol") }); | ||
|
|
||
| return new RemoteService(new UDAServiceType("WANIPConnection", 1), new UDAServiceId("WANIPConnection"), | ||
| URI.create("service.xml"), URI.create("control"), URI.create("events"), new Action[] { action }, | ||
| variables); | ||
| } | ||
|
|
||
| private StateVariable variable(final String name, final Datatype<?> datatype) { | ||
| return new StateVariable(name, new StateVariableTypeDetails(datatype)); | ||
| } | ||
|
|
||
| private ActionArgument input(final String name, final String stateVariable) { | ||
| return new ActionArgument(name, stateVariable, ActionArgument.Direction.IN); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
You can’t perform that action at this time.

Uh oh!
There was an error while loading. Please reload this page.