Skip to content

Add SwitchId and Suggestions to NetworkAdapter configuration#51

Closed
Vigilans wants to merge 2 commits into
M2Team:mainfrom
Vigilans:vigilans/switch-id
Closed

Add SwitchId and Suggestions to NetworkAdapter configuration#51
Vigilans wants to merge 2 commits into
M2Team:mainfrom
Vigilans:vigilans/switch-id

Conversation

@Vigilans

@Vigilans Vigilans commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add SwitchId property to NetworkAdapterConfiguration, allowing each network adapter to connect to a different HCN network (e.g. Default Switch, Docker nat, WSL, or a custom network)
  • Add Suggestions property with SwitchName, SwitchType, SwitchSubnet, and IPAddress fields, used as creation parameters when the specified network does not exist
    • IPAddress is written to IPConfigurations when creating the endpoint. Currently ICS DHCP overrides this value, but it is included for potential use with other network types (e.g. NAT with static allocation) and for future testing
  • Skip failed network adapters at startup instead of aborting with HCS_E_INVALID_JSON
    • When ComputeNetworkCreateEndpoint fails (e.g. invalid SwitchId, network creation rejected), the exception was caught but the adapter remained Connected = true with an empty MacAddress. MakeHcsNetworkAdapterConfiguration then wrote an empty MacAddress into the HCS JSON, causing HcsCreateComputeSystem to fail with HCS_E_INVALID_JSON (0xC037010D). The fix sets Connected = false on failure so the adapter is skipped in HCS JSON generation

Test plan

  • VM with multiple adapters bound to different HCN networks (NanaBox, Default Switch, nat, custom)
  • Adapter with SwitchId pointing to non-existent network → auto-created with Suggestions
  • Adapter with invalid SwitchId → gracefully skipped, VM starts with remaining adapters
  • Empty SwitchId → defaults to NanaBox ICS network, SwitchId filled after startup

Example

NanaBox Configuration:

    "NetworkAdapters": [
      { // NanaBox Switch, fixed subnet
        "Connected": true,
        "EndpointId": "03aaff5b-111d-4074-a4c8-53044df40856",
        "MacAddress": "00-15-5D-F2-F4-1B",
        "Suggestions": {
          "IPAddress": "172.22.78.65/24",
          "SwitchSubnet": "172.22.78.0/24"
        },
        "SwitchId": "85c8668e-36fe-447f-aae0-ba159a0142a7"
      },
      { // Bridged Switch
        "Connected": true,
        "EndpointId": "e122336a-76fb-4bfa-9025-fe76aac42b8f",
        "MacAddress": "00-15-5D-CE-FC-72",
        "SwitchId": "B232AF89-B4BF-4850-A6D5-5313C4FB1240"
      },
      { // Default Switch
        "Connected": true,
        "EndpointId": "e3ab45a8-c3b2-4d06-a790-34b0317d4504",
        "MacAddress": "00-15-5D-4F-D0-72",
        "SwitchId": "c08cb7b8-9b3c-408e-8e30-5e16a3aeb444"
      },
      { // Docker default nat Switch
        "Connected": true,
        "EndpointId": "55664846-9503-4088-8a11-8b936d816314",
        "MacAddress": "00-15-5D-0F-3B-E7",
        "SwitchId": "5F4717D6-4A97-4A05-9B7E-22084DBEFF03"
      },
      { // In-place creating Switch
        "Connected": true,
        "EndpointId": "d8286a56-b838-4a5f-817a-8f84b81ef2c3",
        "MacAddress": "00-15-5D-72-49-E1",
        "Suggestions": {
          "SwitchName": "Test HCN",
          "SwitchSubnet": "10.99.0.0/24"
        },
        "SwitchId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      }
    ]

Windows Screenshot:
image

Vigilans added 2 commits April 9, 2026 17:30
* Each network adapter can specify different virtual switch to attach now

Signed-off-by: Vigilans <vigilans@foxmail.com>
When creating a new HCN network via SwitchId, the Suggestions object
provides optional parameters: SwitchName, SwitchType, SwitchSubnet for
network creation, and IPAddress for endpoint IPConfigurations. These are
ignored if the network already exists.
@Vigilans Vigilans force-pushed the vigilans/switch-id branch from e351e7b to 80e8fd4 Compare April 9, 2026 09:30
MouriNaruto added a commit that referenced this pull request Apr 9, 2026
…network adapter. (#51) (Contributed by Vigilans.)

Co-authored-by: Vigilans <vigilans@foxmail.com>
@MouriNaruto

Copy link
Copy Markdown
Member

Have manually merged.

74c6f50

Kenji Mouri

@MouriNaruto MouriNaruto closed this Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants