Skip to content
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

Make vxlan port configurable #394

Merged
merged 1 commit into from
Oct 6, 2021
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
6 changes: 3 additions & 3 deletions pkg/networkservice/chains/xconnectns/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type xconnectNSServer struct {
}

// NewServer - returns an implementation of the xconnectns network service
func NewServer(ctx context.Context, name string, authzServer networkservice.NetworkServiceServer, tokenGenerator token.GeneratorFunc, clientURL *url.URL, vppConn Connection, tunnelIP net.IP, clientDialOptions ...grpc.DialOption) endpoint.Endpoint {
func NewServer(ctx context.Context, name string, authzServer networkservice.NetworkServiceServer, tokenGenerator token.GeneratorFunc, clientURL *url.URL, vppConn Connection, tunnelIP net.IP, tunnelPort uint16, clientDialOptions ...grpc.DialOption) endpoint.Endpoint {
denis-tingaikin marked this conversation as resolved.
Show resolved Hide resolved
rv := &xconnectNSServer{}
additionalFunctionality := []networkservice.NetworkServiceServer{
recvfd.NewServer(),
Expand All @@ -86,7 +86,7 @@ func NewServer(ctx context.Context, name string, authzServer networkservice.Netw
mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{
memif.MECHANISM: memif.NewServer(vppConn, memif.WithDirectMemif()),
kernel.MECHANISM: kernel.NewServer(vppConn),
vxlan.MECHANISM: vxlan.NewServer(vppConn, tunnelIP),
vxlan.MECHANISM: vxlan.NewServer(vppConn, tunnelIP, vxlan.WithVniPort(tunnelPort)),
wireguard.MECHANISM: wireguard.NewServer(vppConn, tunnelIP),
}),
pinhole.NewServer(vppConn),
Expand All @@ -104,7 +104,7 @@ func NewServer(ctx context.Context, name string, authzServer networkservice.Netw
// mechanisms
memif.NewClient(vppConn),
kernel.NewClient(vppConn),
vxlan.NewClient(vppConn, tunnelIP),
vxlan.NewClient(vppConn, tunnelIP, vxlan.WithVniPort(tunnelPort)),
wireguard.NewClient(vppConn, tunnelIP),
pinhole.NewClient(vppConn),
recvfd.NewClient(),
Expand Down
11 changes: 9 additions & 2 deletions pkg/networkservice/mechanisms/vxlan/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,20 @@ type vxlanClient struct {
}

// NewClient - returns a new client for the vxlan remote mechanism
func NewClient(vppConn api.Connection, tunnelIP net.IP) networkservice.NetworkServiceClient {
func NewClient(vppConn api.Connection, tunnelIP net.IP, options ...Option) networkservice.NetworkServiceClient {
opts := &vxlanOptions{
vxlanPort: vxlanDefaultPort,
}
for _, opt := range options {
opt(opts)
}

return chain.NewNetworkServiceClient(
&vxlanClient{
vppConn: vppConn,
},
mtu.NewClient(vppConn, tunnelIP),
vni.NewClient(tunnelIP),
vni.NewClient(tunnelIP, vni.WithTunnelPort(opts.vxlanPort)),
)
}

Expand Down
9 changes: 4 additions & 5 deletions pkg/networkservice/mechanisms/vxlan/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ func addDel(ctx context.Context, conn *networkservice.Connection, vppConn api.Co
if isClient {
port = mechanism.SrcPort()
}
if port != vxlanDefaultPort {
return errors.Errorf("vxlan only supports port %d not port %d", vxlanDefaultPort, port)
}
_, ok := ifindex.Load(ctx, isClient)
if isAdd && ok {
return nil
Expand Down Expand Up @@ -75,19 +72,21 @@ func addDel(ctx context.Context, conn *networkservice.Connection, vppConn api.Co
WithField("vppapi", "AddNodeNext").Debug("completed")

now = time.Now()
vxlanAddDelTunnel := &vxlan.VxlanAddDelTunnel{
vxlanAddDelTunnel := &vxlan.VxlanAddDelTunnelV2{
IsAdd: isAdd,
Instance: ^uint32(0),
SrcAddress: types.ToVppAddress(mechanism.SrcIP()),
DstAddress: types.ToVppAddress(mechanism.DstIP()),
DecapNextIndex: addNextNodeRsp.NextIndex,
Vni: mechanism.VNI(),
SrcPort: port,
DstPort: port,
}
if !isClient {
vxlanAddDelTunnel.SrcAddress = types.ToVppAddress(mechanism.DstIP())
vxlanAddDelTunnel.DstAddress = types.ToVppAddress(mechanism.SrcIP())
}
rsp, err := vxlan.NewServiceClient(vppConn).VxlanAddDelTunnel(ctx, vxlanAddDelTunnel)
rsp, err := vxlan.NewServiceClient(vppConn).VxlanAddDelTunnelV2(ctx, vxlanAddDelTunnel)
if err != nil {
return errors.WithStack(err)
}
Expand Down
35 changes: 35 additions & 0 deletions pkg/networkservice/mechanisms/vxlan/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2020-2021 Cisco and/or its affiliates.
//
// Copyright (c) 2021 Nordix Foundation.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package vxlan

// Option is an option pattern for vxlan server/client
type Option func(o *vxlanOptions)

// WithVniPort sets vni port
func WithVniPort(port uint16) Option {
return func(o *vxlanOptions) {
if port != 0 {
o.vxlanPort = port
}
}
}

type vxlanOptions struct {
vxlanPort uint16
}
11 changes: 9 additions & 2 deletions pkg/networkservice/mechanisms/vxlan/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,16 @@ type vxlanServer struct {
}

// NewServer - returns a new server for the vxlan remote mechanism
func NewServer(vppConn api.Connection, tunnelIP net.IP) networkservice.NetworkServiceServer {
func NewServer(vppConn api.Connection, tunnelIP net.IP, options ...Option) networkservice.NetworkServiceServer {
opts := &vxlanOptions{
vxlanPort: vxlanDefaultPort,
}
for _, opt := range options {
opt(opts)
}

return chain.NewNetworkServiceServer(
vni.NewServer(tunnelIP),
vni.NewServer(tunnelIP, vni.WithTunnelPort(opts.vxlanPort)),
mtu.NewServer(vppConn, tunnelIP),
&vxlanServer{
vppConn: vppConn,
Expand Down