This repository has been archived by the owner on Oct 29, 2021. It is now read-only.
/
composite.go
107 lines (88 loc) · 3.08 KB
/
composite.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2019 VMware, Inc.
// 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 main
import (
"context"
"github.com/networkservicemesh/networkservicemesh/sdk/endpoint"
"github.com/golang/protobuf/ptypes/empty"
"github.com/ligato/vpp-agent/api/configurator"
"github.com/ligato/vpp-agent/api/models/vpp"
l2 "github.com/ligato/vpp-agent/api/models/vpp/l2"
"github.com/networkservicemesh/networkservicemesh/controlplane/api/connection"
"github.com/networkservicemesh/networkservicemesh/controlplane/api/networkservice"
"github.com/networkservicemesh/networkservicemesh/sdk/common"
"github.com/sirupsen/logrus"
)
type vppAgentBridgeComposite struct {
workspace string
bridgeDomain *l2.BridgeDomain
}
func (vbc *vppAgentBridgeComposite) Request(ctx context.Context,
request *networkservice.NetworkServiceRequest) (*connection.Connection, error) {
err := vbc.insertVPPAgentInterface(request.GetConnection(), true, vbc.workspace)
if err != nil {
logrus.Error(err)
return nil, err
}
if endpoint.Next(ctx) != nil {
return endpoint.Next(ctx).Request(ctx, request)
}
return request.GetConnection(), nil
}
func (vbc *vppAgentBridgeComposite) CreateBridgeDomain() {
dataChange := &configurator.Config{
VppConfig: &vpp.ConfigData{
BridgeDomains: []*l2.BridgeDomain{vbc.bridgeDomain},
},
}
_ = sendDataChangeToVppAgent(dataChange)
}
func (vbc *vppAgentBridgeComposite) Close(ctx context.Context, conn *connection.Connection) (*empty.Empty, error) {
// remove from connections
err := vbc.insertVPPAgentInterface(conn, false, vbc.workspace)
if err != nil {
logrus.Error(err)
return &empty.Empty{}, err
}
if endpoint.Next(ctx) != nil {
if _, err := endpoint.Next(ctx).Close(ctx, conn); err != nil {
return &empty.Empty{}, nil
}
}
return &empty.Empty{}, nil
}
// Name returns the composite name
func (vbc *vppAgentBridgeComposite) Name() string {
return "VPP Agent Bridge"
}
// vppAgentBridgeComposite creates a new VPP Agent composite
func newVppAgentBridgeComposite(configuration *common.NSConfiguration) *vppAgentBridgeComposite {
bridgeDomain := &l2.BridgeDomain{
Name: "brd",
Flood: true,
UnknownUnicastFlood: true,
Forward: true,
Learn: true,
MacAge: 120,
Interfaces: make([]*l2.BridgeDomain_Interface, 0),
}
newVppAgentBridgeComposite := &vppAgentBridgeComposite{
workspace: configuration.Workspace,
bridgeDomain: bridgeDomain,
}
_ = resetVppAgent()
newVppAgentBridgeComposite.CreateBridgeDomain()
return newVppAgentBridgeComposite
}