Skip to content

Commit

Permalink
added kernel to vxlan to kernel test
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Avramenko <avramenkomihail15@gmail.com>
  • Loading branch information
Mixaster995 committed Aug 11, 2021
1 parent c06c5d8 commit 15fbbdd
Show file tree
Hide file tree
Showing 4 changed files with 338 additions and 1,392 deletions.
56 changes: 56 additions & 0 deletions internal/tests/copyfile/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2020 Doc.ai and/or its affiliates.
//
// 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 copyfile provides the necessary mechanisms to request and inject a kernel interface.
package copyfile

import (
"context"
"github.com/golang/protobuf/ptypes/empty"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"net/url"
)

type copyFileServer struct{
name string
}

// NewServer - creates a NetworkServiceServer that requests a kernel interface and populates the netns inode
func NewServer(name string) networkservice.NetworkServiceServer {
return &copyFileServer{
name: name,
}
}

func (m *copyFileServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
if mechanism := kernel.ToMechanism(request.GetConnection().GetMechanism()); mechanism != nil {
//nsHandle, err := mechutils.ToNSHandle(mechanism)
//fd, err := syscall.Open("/run/netns/" + m.name, unix.O_RDONLY|unix.O_CLOEXEC, 0)
//if err != nil {
// return nil, err
//}
//filename := fmt.Sprintf("/proc/%d/fd/%d", os.Getpid(), fd)
mechanism.SetNetNSURL((&url.URL{Scheme: "file", Path: "/run/netns/" + m.name}).String())
}
return next.Server(ctx).Request(ctx, request)
}

func (m *copyFileServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) {
return next.Server(ctx).Close(ctx, conn)
}

170 changes: 170 additions & 0 deletions internal/tests/suite_kernel_vxlan_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package tests

import (
"context"
"fmt"
"git.fd.io/govpp.git/api"
"github.com/edwarnicke/vpphelper"
"github.com/google/uuid"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/cls"
"github.com/networkservicemesh/cmd-forwarder-vpp/internal/tests/copyfile"
"github.com/networkservicemesh/cmd-forwarder-vpp/internal/tests/ns"
"github.com/networkservicemesh/sdk-kernel/pkg/kernel/networkservice/connectioncontextkernel"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/connectioncontext"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/connectioncontext/mtu"

"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/kernel"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/memif"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/vxlan"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/wireguard"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/pinhole"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/stats"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/tag"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/up"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/xconnect"
"github.com/networkservicemesh/sdk/pkg/networkservice/chains/endpoint"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/authorize"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms"
kernelmechanism "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/kernel"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanismtranslation"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/refresh"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/serialize"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/updatepath"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/ipam/point2pointipam"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
"github.com/networkservicemesh/sdk/pkg/tools/token"
"github.com/thanhpk/randstr"
"github.com/vishvananda/netns"
"net"
)

type kernelToVxlanVerifiableEndpoint struct {
ctx context.Context
vppConn api.Connection
endpointNSHandle netns.NsHandle
endpoint.Endpoint
}

func newKernelToVxlanVerifiableEndpoint(ctx context.Context,
prefix1, prefix2 *net.IPNet,
tokenGenerator token.GeneratorFunc,
vppConn vpphelper.Connection) verifiableEndpoint {

rootNSHandle, err := netns.Get()
if err != nil {
panic(fmt.Sprintf("unable to get root netNs: %+v", err))
}
endpointNSName := fmt.Sprintf("endpoint-%s", randstr.Hex(4))
endpointNSHandle, err := netns.NewNamed(endpointNSName)
if err != nil {
panic(fmt.Sprintf("unable create netNs %s: %+v", endpointNSName, err))
}
go func(endpointNsName string) {
<-ctx.Done()
_ = netns.DeleteNamed(endpointNsName)
}(endpointNSName)

rv := &kernelToVxlanVerifiableEndpoint{
ctx: ctx,
vppConn: vppConn,
endpointNSHandle: endpointNSHandle,
}
name := "vxlanVerifiableEndpoint"
rv.Endpoint = endpoint.NewServer(ctx,
tokenGenerator,
endpoint.WithName(name),
endpoint.WithAuthorizeServer(authorize.NewServer()),
endpoint.WithAdditionalFunctionality(
metadata.NewServer(),
connectioncontext.NewServer(vppConn),
up.NewServer(ctx, vppConn),
xconnect.NewServer(vppConn),
connectioncontextkernel.NewServer(),
tag.NewServer(ctx, vppConn),
mtu.NewServer(vppConn),
pinhole.NewServer(vppConn),
mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{
vxlan.MECHANISM: vxlan.NewServer(vppConn, net.ParseIP(serverIP)),
}),
adapters.NewClientToServer(clientChain(ctx, vppConn, net.ParseIP(serverIP))),
updatepath.NewServer("ep-" + uuid.New().String()),
//metadata.NewServer(),
point2pointipam.NewServer(prefix1),
point2pointipam.NewServer(prefix2),
mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{
kernel.MECHANISM: chain.NewNetworkServiceServer(
kernelmechanism.NewServer(),
),
}),
ns.NewServer(endpointNSHandle),
copyfile.NewServer(endpointNSName),
ns.NewServer(rootNSHandle),
),
)

return rv
}

func clientChain(ctx context.Context, vppConn vpphelper.Connection, tunnelIP net.IP) networkservice.NetworkServiceClient{
return chain.NewNetworkServiceClient(
[]networkservice.NetworkServiceClient{
mechanismtranslation.NewClient(),
updatepath.NewClient("client-" + uuid.New().String()),
serialize.NewClient(),
refresh.NewClient(ctx),
metadata.NewClient(),
mechanismtranslation.NewClient(),
connectioncontextkernel.NewClient(),
stats.NewClient(ctx),
up.NewClient(ctx, vppConn),
mtu.NewClient(vppConn),
tag.NewClient(ctx, vppConn),
// mechanisms
memif.NewClient(vppConn),
kernel.NewClient(vppConn),
vxlan.NewClient(vppConn, tunnelIP),
wireguard.NewClient(vppConn, tunnelIP),
pinhole.NewClient(vppConn),
}...)
}

func (v *kernelToVxlanVerifiableEndpoint) VerifyConnection(conn *networkservice.Connection) error {
//namingConn := conn.Clone()
//namingConn.Id = conn.GetPath().GetPathSegments()[len(conn.GetPath().GetPathSegments())-1].GetId()
//namingConn.Mechanism = &networkservice.Mechanism{
// Cls: cls.LOCAL,
// Type: kernel.MECHANISM,
// Parameters: map[string]string{
// krnl.InterfaceNameKey : "ns-",
// },
//}
////rootNSHandle, err := netns.Get()
////if err != nil {
//// panic(fmt.Sprintf("unable to get root netNs: %+v", err))
////}
//if err := checkKernelInterface(namingConn, conn.GetContext().GetIpContext().GetDstIPNets(), v.endpointNSHandle); err != nil {
// return err
//}
namingConn := conn.Clone()
namingConn.Id = conn.GetPath().GetPathSegments()[len(conn.GetPath().GetPathSegments())-1].GetId()
namingConn.Mechanism = &networkservice.Mechanism{
Cls: cls.LOCAL,
Type: kernel.MECHANISM,
}
if err := checkKernelInterface(namingConn, conn.GetContext().GetIpContext().GetDstIPNets(), v.endpointNSHandle); err != nil {
return err
}
for _, ip := range conn.GetContext().GetIpContext().GetSrcIPNets() {
if err := pingKernel(ip, v.endpointNSHandle); err != nil {
return err
}
}
return nil
}

func (v *kernelToVxlanVerifiableEndpoint) VerifyClose(conn *networkservice.Connection) error {
return checkNoKernelInterface(conn, v.endpointNSHandle)
}
123 changes: 112 additions & 11 deletions internal/tests/suite_performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import (
"time"
)

const N = 5
const N = 8
const M = 1

type clientInfo struct {
Expand All @@ -62,7 +62,7 @@ var errTable = map[string][]string{}

func (f *ForwarderTestSuite) TestKernelToKernelPerformance() {
//time.Sleep(time.Hour)
//f.T().Skip()
f.T().Skip()
//create endpoint
epCtx, epCancel := context.WithCancel(f.ctx)

Expand Down Expand Up @@ -100,11 +100,7 @@ func (f *ForwarderTestSuite) TestKernelToKernelPerformance() {
testRequest := &networkservice.NetworkServiceRequest{
Connection: &networkservice.Connection{
NetworkService: networkserviceName,
Payload: payload.Ethernet,
//Mechanism: &networkservice.Mechanism{
// Type: wireguard.MECHANISM,
// Cls: cls.REMOTE,
//},
Payload: payload.IP,
},
}

Expand Down Expand Up @@ -143,14 +139,14 @@ func (f *ForwarderTestSuite) TestKernelToKernelPerformance() {
wg := sync.WaitGroup{}
for k, v := range clInfo.clientWithConn {
cl, ok := k.(*kernelVerifiableClient)
e, ok2 := ep.(*kernelVerifiableEndpoint)
_, ok2 := ep.(*kernelVerifiableEndpoint)
if !ok || !ok2 {
continue
}
wg.Add(1)
conn := v
go func() {
_ = iperfMeasure(conn, cl, e)
_ = iperfMeasure(conn, cl)
wg.Done()
}()
}
Expand All @@ -169,7 +165,113 @@ func (f *ForwarderTestSuite) TestKernelToKernelPerformance() {
err = <-serverErrCh
}

func iperfMeasure(conn *networkservice.Connection, k *kernelVerifiableClient, ep *kernelVerifiableEndpoint) error {
func (f *ForwarderTestSuite) TestKernelToVxlanToKernelPerformance() {
//time.Sleep(time.Hour)
//f.T().Skip()
//create endpoint
epCtx, epCancel := context.WithCancel(f.ctx)

serverCreds := credentials.NewTLS(tlsconfig.MTLSServerConfig(f.x509source, f.x509bundle, tlsconfig.AuthorizeAny()))
serverCreds = grpcfd.TransportCredentials(serverCreds)
server := grpc.NewServer(grpc.Creds(serverCreds))

_, prefix1, err := net.ParseCIDR("10.0.0.0/24")
f.Require().NoError(err)
_, prefix2, err := net.ParseCIDR("fc00::/7")
f.Require().NoError(err)

ep := newKernelToVxlanVerifiableEndpoint(epCtx,
prefix1,
prefix2,
spiffejwt.TokenGeneratorFunc(f.x509source, f.config.MaxTokenLifetime),
f.vppServerConn,
)

networkservice.RegisterNetworkServiceServer(server, ep)
networkservice.RegisterMonitorConnectionServer(server, ep)
registry.RegisterNetworkServiceEndpointRegistryServer(server, f.registryServer)
serverErrCh := f.ListenAndServe(epCtx, server)

clInfo := &clientInfo{
clientWithConn: map[verifiableClient]*networkservice.Connection{},
}
for i := 0; i < N; i++ {
f.T().Run(fmt.Sprintf("Kernel%v", i+1), func(t *testing.T) {
ctx, cancel := context.WithTimeout(f.ctx, contextTimeout * 100)
clInfo.cancels = append(clInfo.cancels, cancel)

ctx = log.WithLog(ctx, logruslogger.New(ctx))
networkserviceName := "ns"
// Create testRequest
testRequest := &networkservice.NetworkServiceRequest{
Connection: &networkservice.Connection{
NetworkService: networkserviceName,
Payload: payload.Ethernet,
},
}

client := newKernelVerifiableClient(ctx, f.sutCC)
conn, err := client.Request(ctx, testRequest)
assert.NoError(t, err)
assert.NotNil(t, conn)

clInfo.clientWithConn[client] = conn
//if conn != nil {
// latencyTable[conn.Id] = []string{}
//}

if err == nil {
assert.NoError(t, client.VerifyConnection(conn))
assert.NoError(t, ep.VerifyConnection(conn))
}
})
}

for _, v := range clInfo.clientWithConn {
e, ok2 := ep.(*kernelToVxlanVerifiableEndpoint)
if !ok2 {
continue
}
v2 := v
for _, ip := range v2.GetContext().GetIpContext().GetDstIPNets() {
ip2 := ip
log.FromContext(f.ctx).Infof(ip2.IP.String())
go func() {
_ = iperf.StartServer(ip2, e.endpointNSHandle)
}()
time.Sleep(time.Second * 10)
}
}
wg := sync.WaitGroup{}
for k, v := range clInfo.clientWithConn {
cl, ok := k.(*kernelVerifiableClient)
_, ok2 := ep.(*kernelToVxlanVerifiableEndpoint)
if !ok || !ok2 {
continue
}
wg.Add(1)
conn := v
go func() {
_ = iperfMeasure(conn, cl)
wg.Done()
}()
}
wg.Wait()

_ = iperf.WriteFile("kernelToWireguardTo", "kernel", N, M)

for _, c := range clInfo.cancels {
c()
}

//writeFile("kernel", "kernel", N, M)

epCancel()

err = <-serverErrCh
}

func iperfMeasure(conn *networkservice.Connection, k *kernelVerifiableClient) error {
for _, ip := range conn.GetContext().GetIpContext().GetDstIPNets() {
var err error
for i := 0; i < 20; i++ {
Expand Down Expand Up @@ -363,7 +465,6 @@ func (f *ForwarderTestSuite) TestMemifToMemifPerformance() {
})
}

time.Sleep(time.Hour)
//for _, v := range clInfo.clientWithConn {
// e, ok2 := ep.(*kernelVerifiableEndpoint)
// if !ok2 {
Expand Down
Loading

0 comments on commit 15fbbdd

Please sign in to comment.