-
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.
Signed-off-by: Ed Warnicke <hagbard@gmail.com>
- Loading branch information
1 parent
fe5a6c8
commit 54ae665
Showing
22 changed files
with
1,190 additions
and
21 deletions.
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
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,82 @@ | ||
// Copyright (c) 2020 Cisco 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 vxlan | ||
|
||
import ( | ||
"context" | ||
"net" | ||
|
||
"git.fd.io/govpp.git/api" | ||
"github.com/golang/protobuf/ptypes/empty" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain" | ||
|
||
"github.com/networkservicemesh/api/pkg/api/networkservice" | ||
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/cls" | ||
|
||
"google.golang.org/grpc" | ||
|
||
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/vxlan/vni" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" | ||
) | ||
|
||
type vxlanClient struct { | ||
vppConn api.Connection | ||
} | ||
|
||
// NewClient - returns a new client for the vxlan remote mechanism | ||
func NewClient(vppConn api.Connection, tunnelIP net.IP) networkservice.NetworkServiceClient { | ||
return chain.NewNetworkServiceClient( | ||
&vxlanClient{ | ||
vppConn: vppConn, | ||
}, | ||
vni.NewClient(tunnelIP), | ||
) | ||
} | ||
|
||
func (v *vxlanClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) { | ||
mechanism := &networkservice.Mechanism{ | ||
Cls: cls.REMOTE, | ||
Type: MECHANISM, | ||
Parameters: make(map[string]string), | ||
} | ||
request.MechanismPreferences = append(request.MechanismPreferences, mechanism) | ||
conn, err := next.Client(ctx).Request(ctx, request, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := addDel(ctx, conn, v.vppConn, true, metadata.IsClient(v)); err != nil { | ||
_, _ = v.Close(ctx, conn, opts...) | ||
return nil, err | ||
} | ||
return conn, nil | ||
} | ||
|
||
func (v *vxlanClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) { | ||
rv, err := next.Client(ctx).Close(ctx, conn, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if err := addDel(ctx, conn, v.vppConn, false, metadata.IsClient(v)); err != nil { | ||
return nil, err | ||
} | ||
return rv, 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,78 @@ | ||
// Copyright (c) 2020 Cisco 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 vxlan | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"git.fd.io/govpp.git/api" | ||
"github.com/edwarnicke/govpp/binapi/vxlan" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/networkservicemesh/api/pkg/api/networkservice" | ||
vxlanMech "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/vxlan" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/core/trace" | ||
|
||
"github.com/networkservicemesh/sdk-vpp/pkg/tools/ifindex" | ||
"github.com/networkservicemesh/sdk-vpp/pkg/tools/types" | ||
) | ||
|
||
func addDel(ctx context.Context, conn *networkservice.Connection, vppConn api.Connection, isAdd, isClient bool) error { | ||
if mechanism := vxlanMech.ToMechanism(conn.GetMechanism()); mechanism != nil { | ||
_, ok := ifindex.Load(ctx, isClient) | ||
if isAdd && ok { | ||
return nil | ||
} | ||
if !isAdd && !ok { | ||
return nil | ||
} | ||
if mechanism.SrcIP() == nil { | ||
return errors.Errorf("no vxlan SrcIP not provided") | ||
} | ||
if mechanism.DstIP() == nil { | ||
return errors.Errorf("no vxlan DstIP not provided") | ||
} | ||
|
||
now := time.Now() | ||
vxlanAddDelTunnel := &vxlan.VxlanAddDelTunnel{ | ||
IsAdd: isAdd, | ||
Instance: ^uint32(0), | ||
SrcAddress: types.ToVppAddress(mechanism.SrcIP()), | ||
DstAddress: types.ToVppAddress(mechanism.DstIP()), | ||
DecapNextIndex: ^uint32(0), | ||
Vni: mechanism.VNI(), | ||
} | ||
if !isClient { | ||
vxlanAddDelTunnel.SrcAddress = types.ToVppAddress(mechanism.DstIP()) | ||
vxlanAddDelTunnel.DstAddress = types.ToVppAddress(mechanism.SrcIP()) | ||
} | ||
rsp, err := vxlan.NewServiceClient(vppConn).VxlanAddDelTunnel(ctx, vxlanAddDelTunnel) | ||
if err != nil { | ||
return errors.WithStack(err) | ||
} | ||
trace.Log(ctx). | ||
WithField("swIfIndex", rsp.SwIfIndex). | ||
WithField("SrcAddress", vxlanAddDelTunnel.SrcAddress). | ||
WithField("DstAddress", vxlanAddDelTunnel.DstAddress). | ||
WithField("Vni", vxlanAddDelTunnel.Vni). | ||
WithField("duration", time.Since(now)). | ||
WithField("vppapi", "VxlanAddDelTunnel").Debug("completed") | ||
ifindex.Store(ctx, isClient, rsp.SwIfIndex) | ||
} | ||
return 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,26 @@ | ||
// Copyright (c) 2020 Cisco 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 vxlan | ||
|
||
import ( | ||
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/vxlan" | ||
) | ||
|
||
const ( | ||
// MECHANISM string | ||
MECHANISM = vxlan.MECHANISM | ||
) |
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) 2020 Cisco 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 vxlan provides networkservice.NetworkService{Client,Server} chain elements for the vxlan mechanism | ||
package vxlan |
Oops, something went wrong.