Skip to content

Commit

Permalink
localnet, multi-homing: introduce localnet alias
Browse files Browse the repository at this point in the history
Having a different parameter to use as the network_name option of the
localnet logical switch port allows the admin to create multiple
physical network attachment without having to reconfigure the physical
OVN bridge mappings.

This improves the admin's UX (less operations) and solution scalability
(since a single mapping can be re-used) and thus the size of the
ovn-bridge-mappings string can be kept low.

Signed-off-by: Miguel Duarte Barroso <[email protected]>
  • Loading branch information
maiqueb committed Oct 12, 2024
1 parent 689e95a commit 0a5265a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
2 changes: 2 additions & 0 deletions go-controller/pkg/cni/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type NetConf struct {
// restart.
AllowPersistentIPs bool `json:"allowPersistentIPs,omitempty"`

PhysicalNetworkName string `json:"physicalNetworkName,omitempty"`

// PciAddrs in case of using sriov or Auxiliry device name in case of SF
DeviceID string `json:"deviceID,omitempty"`
// LogFile to log all the messages from cni shim binary to
Expand Down
14 changes: 11 additions & 3 deletions go-controller/pkg/ovn/secondary_localnet_network_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,7 @@ func (oc *SecondaryLocalnetNetworkController) Init() error {
Name: oc.GetNetworkScopedName(types.OVNLocalnetPort),
Addresses: []string{"unknown"},
Type: "localnet",
Options: map[string]string{
"network_name": oc.GetNetworkName(),
},
Options: oc.localnetPortNetworkNameOptions(),
}
intVlanID := int(oc.Vlan())
if intVlanID != 0 {
Expand Down Expand Up @@ -346,3 +344,13 @@ func (oc *SecondaryLocalnetNetworkController) newRetryFramework(
resourceHandler,
)
}

func (oc *SecondaryLocalnetNetworkController) localnetPortNetworkNameOptions() map[string]string {
localnetLSPOptions := map[string]string{
"network_name": oc.GetNetworkName(),
}
if oc.PhysicalNetworkName() != "" {
localnetLSPOptions["network_name"] = oc.PhysicalNetworkName()
}
return localnetLSPOptions
}
53 changes: 33 additions & 20 deletions go-controller/pkg/util/multi_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type BasicNetInfo interface {
JoinSubnets() []*net.IPNet
Vlan() uint
AllowsPersistentIPs() bool
PhysicalNetworkName() string

// utility methods
Equals(BasicNetInfo) bool
Expand Down Expand Up @@ -265,6 +266,10 @@ func (nInfo *DefaultNetInfo) AllowsPersistentIPs() bool {
return false
}

func (nInfo *DefaultNetInfo) PhysicalNetworkName() string {
return ""
}

// SecondaryNetInfo holds the network name information for secondary network if non-nil
type secondaryNetInfo struct {
netName string
Expand All @@ -285,6 +290,8 @@ type secondaryNetInfo struct {
// to be plumbed for this network
sync.Mutex
nadNames sets.Set[string]

physicalNetworkName string
}

// GetNetworkName returns the network name
Expand Down Expand Up @@ -434,6 +441,10 @@ func (nInfo *secondaryNetInfo) AllowsPersistentIPs() bool {
return nInfo.allowPersistentIPs
}

func (nInfo *secondaryNetInfo) PhysicalNetworkName() string {
return nInfo.physicalNetworkName
}

// IPMode returns the ipv4/ipv6 mode
func (nInfo *secondaryNetInfo) IPMode() (bool, bool) {
return nInfo.ipv4mode, nInfo.ipv6mode
Expand Down Expand Up @@ -519,18 +530,19 @@ func (nInfo *secondaryNetInfo) copy() *secondaryNetInfo {

// everything is immutable except the NADs
c := &secondaryNetInfo{
netName: nInfo.netName,
primaryNetwork: nInfo.primaryNetwork,
topology: nInfo.topology,
mtu: nInfo.mtu,
vlan: nInfo.vlan,
allowPersistentIPs: nInfo.allowPersistentIPs,
ipv4mode: nInfo.ipv4mode,
ipv6mode: nInfo.ipv6mode,
subnets: nInfo.subnets,
excludeSubnets: nInfo.excludeSubnets,
joinSubnets: nInfo.joinSubnets,
nadNames: nInfo.nadNames.Clone(),
netName: nInfo.netName,
primaryNetwork: nInfo.primaryNetwork,
topology: nInfo.topology,
mtu: nInfo.mtu,
vlan: nInfo.vlan,
allowPersistentIPs: nInfo.allowPersistentIPs,
ipv4mode: nInfo.ipv4mode,
ipv6mode: nInfo.ipv6mode,
subnets: nInfo.subnets,
excludeSubnets: nInfo.excludeSubnets,
joinSubnets: nInfo.joinSubnets,
nadNames: nInfo.nadNames.Clone(),
physicalNetworkName: nInfo.physicalNetworkName,
}

return c
Expand Down Expand Up @@ -589,14 +601,15 @@ func newLocalnetNetConfInfo(netconf *ovncnitypes.NetConf) (NetInfo, error) {
}

ni := &secondaryNetInfo{
netName: netconf.Name,
topology: types.LocalnetTopology,
subnets: subnets,
excludeSubnets: excludes,
mtu: netconf.MTU,
vlan: uint(netconf.VLANID),
allowPersistentIPs: netconf.AllowPersistentIPs,
nadNames: sets.Set[string]{},
netName: netconf.Name,
topology: types.LocalnetTopology,
subnets: subnets,
excludeSubnets: excludes,
mtu: netconf.MTU,
vlan: uint(netconf.VLANID),
allowPersistentIPs: netconf.AllowPersistentIPs,
nadNames: sets.Set[string]{},
physicalNetworkName: netconf.PhysicalNetworkName,
}
ni.ipv4mode, ni.ipv6mode = getIPMode(subnets)
return ni, nil
Expand Down

0 comments on commit 0a5265a

Please sign in to comment.