-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set the same MTU for the NSC internal interface as the base interface…
… has Closes: #514 Signed-off-by: Laszlo Kiraly <[email protected]>
- Loading branch information
Showing
7 changed files
with
265 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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,86 @@ | ||
// Copyright (c) 2022 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 mtu | ||
|
||
import ( | ||
"context" | ||
|
||
"git.fd.io/govpp.git/api" | ||
"google.golang.org/grpc" | ||
"google.golang.org/protobuf/types/known/emptypb" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" | ||
"github.com/networkservicemesh/sdk/pkg/tools/postpone" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/networkservicemesh/api/pkg/api/networkservice" | ||
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/vlan" | ||
|
||
"github.com/networkservicemesh/sdk-vpp/pkg/tools/ifindex" | ||
) | ||
|
||
type mtuClient struct { | ||
vppConn api.Connection | ||
mtu mtuMap | ||
} | ||
|
||
// NewClient - returns client chain element to manage vlan MTU | ||
func NewClient(vppConn api.Connection) networkservice.NetworkServiceClient { | ||
return &mtuClient{ | ||
vppConn: vppConn, | ||
} | ||
} | ||
|
||
func (m *mtuClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) { | ||
postponeCtxFunc := postpone.ContextWithValues(ctx) | ||
|
||
conn, err := next.Client(ctx).Request(ctx, request, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
swIfIndex, ok := ifindex.Load(ctx, metadata.IsClient(m)) | ||
if !ok { | ||
return conn, nil | ||
} | ||
if mechanism := vlan.ToMechanism(conn.GetMechanism()); mechanism != nil { | ||
localMtu, loaded := m.mtu.Load(swIfIndex) | ||
if !loaded { | ||
localMtu, err = getMTU(ctx, m.vppConn, swIfIndex) | ||
if err != nil { | ||
closeCtx, cancelClose := postponeCtxFunc() | ||
defer cancelClose() | ||
if _, closeErr := m.Close(closeCtx, conn); closeErr != nil { | ||
err = errors.Wrapf(err, "connection closed with error: %s", closeErr.Error()) | ||
} | ||
return nil, err | ||
} | ||
m.mtu.Store(swIfIndex, localMtu) | ||
} | ||
if conn.GetContext().GetMTU() > localMtu || conn.GetContext().GetMTU() == 0 { | ||
if conn.GetContext() == nil { | ||
conn.Context = &networkservice.ConnectionContext{} | ||
} | ||
conn.GetContext().MTU = localMtu | ||
} | ||
} | ||
return conn, nil | ||
} | ||
|
||
func (m *mtuClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*emptypb.Empty, error) { | ||
return next.Client(ctx).Close(ctx, conn, opts...) | ||
} |
This file contains 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,51 @@ | ||
// Copyright (c) 2022 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 mtu | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"git.fd.io/govpp.git/api" | ||
"github.com/pkg/errors" | ||
|
||
interfaces "github.com/edwarnicke/govpp/binapi/interface" | ||
"github.com/edwarnicke/govpp/binapi/interface_types" | ||
"github.com/networkservicemesh/sdk/pkg/tools/log" | ||
) | ||
|
||
func getMTU(ctx context.Context, vppConn api.Connection, swIfIndex interface_types.InterfaceIndex) (uint32, error) { | ||
now := time.Now() | ||
dc, err := interfaces.NewServiceClient(vppConn).SwInterfaceDump(ctx, &interfaces.SwInterfaceDump{ | ||
SwIfIndex: swIfIndex, | ||
}) | ||
if err != nil { | ||
return 0, errors.Wrapf(err, "error attempting to get interface dump client to determine MTU for swIfIndex %d", swIfIndex) | ||
} | ||
defer func() { _ = dc.Close() }() | ||
|
||
details, err := dc.Recv() | ||
if err != nil { | ||
return 0, errors.Wrapf(err, "error attempting to get interface details to determine MTU for swIfIndex %d", swIfIndex) | ||
} | ||
log.FromContext(ctx). | ||
WithField("swIfIndex", swIfIndex). | ||
WithField("details.LinkMtu", details.LinkMtu). | ||
WithField("duration", time.Since(now)). | ||
WithField("vppapi", "SwInterfaceDump").Debug("completed") | ||
return uint32(details.LinkMtu), nil | ||
} |
This file contains 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,18 @@ | ||
// Copyright (c) 2022 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 mtu computes the mtu for the vlan interface and adds it to context | ||
package mtu |
This file contains 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,26 @@ | ||
// Copyright (c) 2022 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 mtu | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
//go:generate go-syncmap -output mtu_map.gen.go -type mtuMap<github.com/edwarnicke/govpp/binapi/interface_types.InterfaceIndex,uint32> | ||
|
||
// mtuMap - sync.Map with key type interface_types.InterfaceIndex value of int index | ||
type mtuMap sync.Map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.