Unverified Commit 07f12c2d authored by 张祖建's avatar 张祖建 Committed by GitHub
Browse files

update Go to version 1.19 (#1892)

parent e5878ff9
Showing with 101 additions and 1895 deletions
+101 -1895
......@@ -19,7 +19,7 @@ concurrency:
cancel-in-progress: true
env:
GO_VERSION: '1.18'
GO_VERSION: '1.19'
jobs:
build:
......
......@@ -20,8 +20,8 @@ concurrency:
cancel-in-progress: true
env:
GO_VERSION: '1.18'
GOSEC_VERSION: '2.12.0'
GO_VERSION: '1.19'
GOSEC_VERSION: '2.13.1'
jobs:
build-ovs-and-ovn:
......
......@@ -20,9 +20,9 @@ concurrency:
cancel-in-progress: true
env:
GO_VERSION: '1.18'
GOSEC_VERSION: '2.12.0'
KIND_VERSION: v0.14.0
GO_VERSION: '1.19'
GOSEC_VERSION: '2.13.1'
KIND_VERSION: v0.15.0
jobs:
build-kube-ovn:
......@@ -1500,7 +1500,7 @@ jobs:
run: |
sudo pip3 install j2cli
sudo pip3 install "j2cli[yaml]"
sudo PATH=~/.local/bin:$PATH k8s_version=v1.23.6 make kind-init
sudo PATH=~/.local/bin:$PATH k8s_version=v1.23.10 make kind-init
- name: Install Kube-OVN
uses: nick-invision/retry@v2
......
......@@ -13,7 +13,7 @@ concurrency:
cancel-in-progress: true
env:
GO_VERSION: '1.18'
GO_VERSION: '1.19'
jobs:
golangci:
......
GO_VERSION = 1.18
GO_VERSION = 1.19
SHELL=/bin/bash
REGISTRY = kubeovn
......
......@@ -4,7 +4,7 @@
##### Prerequisites:
1. Kube-OVN is developed by [Go](https://golang.org/) 1.18 and uses [Go Modules](https://github.com/golang/go/wiki/Modules) to manage dependency. Make sure `GO111MODULE="on"`.
1. Kube-OVN is developed by [Go](https://golang.org/) 1.19 and uses [Go Modules](https://github.com/golang/go/wiki/Modules) to manage dependency. Make sure `GO111MODULE="on"`.
2. We also use [gosec](https://github.com/securego/gosec) to inspect source code for security problems.
......
module github.com/kubeovn/kube-ovn
go 1.18
go 1.19
require (
github.com/Mellanox/sriovnet v1.1.0
......@@ -16,31 +16,31 @@ require (
github.com/coreos/go-iptables v0.6.0
github.com/emicklei/go-restful/v3 v3.9.0
github.com/go-logr/stdr v1.2.2
github.com/golang/protobuf v1.5.2
github.com/greenpau/ovsdb v1.0.2
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.3.0
github.com/mdlayher/arp v0.0.0-20220512170110-6706a2966875
github.com/moby/sys/mountinfo v0.6.0
github.com/moby/sys/mountinfo v0.6.2
github.com/neverlee/keymutex v0.0.0-20171121013845-f593aa834bf9
github.com/oilbeater/go-ping v0.0.0-20200413021620-332b7197c5b5
github.com/onsi/ginkgo/v2 v2.1.5
github.com/onsi/gomega v1.20.1
github.com/osrg/gobgp v0.0.0-20190401195721-805d02fdfbc5
github.com/ovn-org/libovsdb v0.0.0-20220826133223-e4d2d8648be7
github.com/onsi/ginkgo/v2 v2.1.6
github.com/onsi/gomega v1.20.2
github.com/osrg/gobgp/v3 v3.6.0
github.com/ovn-org/libovsdb v0.0.0-20220901025242-999ca1972a3a
github.com/parnurzeal/gorequest v0.2.16
github.com/prometheus/client_golang v1.13.0
github.com/sirupsen/logrus v1.9.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.0
github.com/vishvananda/netlink v1.2.1-beta.2
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261
golang.org/x/sys v0.0.0-20220907062415-87db552b00fd
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9
google.golang.org/grpc v1.49.0
google.golang.org/protobuf v1.28.1
gopkg.in/k8snetworkplumbingwg/multus-cni.v3 v3.9.1
k8s.io/api v0.24.4
k8s.io/apimachinery v0.24.4
k8s.io/client-go v12.0.0+incompatible
k8s.io/klog/v2 v2.70.1
k8s.io/klog/v2 v2.80.0
k8s.io/kubernetes v1.24.4
k8s.io/sample-controller v0.24.4
kubevirt.io/client-go v0.56.0
......@@ -48,7 +48,6 @@ require (
)
require (
github.com/armon/go-radix v1.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/cenkalti/hub v1.0.1 // indirect
......@@ -76,6 +75,7 @@ require (
github.com/golang/glog v1.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
......@@ -88,6 +88,7 @@ require (
github.com/josharian/native v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/juju/errors v1.0.0 // indirect
github.com/k-sone/critbitgo v1.4.0 // indirect
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/kelseyhightower/envconfig v1.4.0 // indirect
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 // indirect
......@@ -107,7 +108,7 @@ require (
github.com/openshift/custom-resource-status v1.1.2 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/projectcalico/go-json v0.0.0-20161128004156-6219dc7339ba // indirect
......@@ -117,25 +118,23 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.12.0 // indirect
github.com/subosito/gotenv v1.4.0 // indirect
github.com/spf13/viper v1.13.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/net v0.0.0-20220822230855-b0a4917ee28c // indirect
golang.org/x/net v0.0.0-20220906165146-f3363e06e74c // indirect
golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094 // indirect
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde // indirect
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
golang.org/x/text v0.3.7 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/genproto v0.0.0-20220902135211-223410557253 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
......@@ -144,7 +143,7 @@ require (
k8s.io/component-base v0.24.4 // indirect
k8s.io/component-helpers v0.24.4 // indirect
k8s.io/kube-openapi v0.0.0-20220803164354-a70c9af30aea // indirect
k8s.io/kube-proxy v0.0.0 // indirect
k8s.io/kube-proxy v0.24.4 // indirect
k8s.io/utils v0.0.0-20220823124924-e9cbc92d1a73 // indirect
kubevirt.io/api v0.56.0 // indirect
kubevirt.io/containerized-data-importer-api v1.54.0 // indirect
......@@ -159,7 +158,7 @@ replace (
github.com/alauda/felix => github.com/kubeovn/felix v0.0.0-20220325073257-c8a0f705d139
github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2
github.com/greenpau/ovsdb => github.com/alauda/ovsdb v0.0.0-20210113100339-040cf3e76c28
github.com/openshift/api => github.com/openshift/api v0.0.0-20210428205234-a8389931bee7
github.com/openshift/api => github.com/openshift/api v0.0.0-20210105115604-44119421ec6b
github.com/openshift/client-go => github.com/openshift/client-go v0.0.0-20210112165513-ebc401615f47
github.com/openshift/library-go => github.com/mhenriks/library-go v0.0.0-20210511195009-51ba86622560
gopkg.in/k8snetworkplumbingwg/multus-cni.v3 => github.com/k8snetworkplumbingwg/multus-cni v0.0.0-20220818150730-3d9cec4ec9d5
......
This diff is collapsed.
......@@ -37,14 +37,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
// of clientsets, like in:
//
// import (
// "k8s.io/client-go/kubernetes"
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
// )
// import (
// "k8s.io/client-go/kubernetes"
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
// )
//
// kclientset, _ := kubernetes.NewForConfig(c)
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
// kclientset, _ := kubernetes.NewForConfig(c)
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
//
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
// correctly.
......
......@@ -37,14 +37,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
// of clientsets, like in:
//
// import (
// "k8s.io/client-go/kubernetes"
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
// )
// import (
// "k8s.io/client-go/kubernetes"
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
// )
//
// kclientset, _ := kubernetes.NewForConfig(c)
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
// kclientset, _ := kubernetes.NewForConfig(c)
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
//
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
// correctly.
......
......@@ -7,10 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/kubeovn/kube-ovn/versions"
"io"
"io/ioutil"
"k8s.io/apimachinery/pkg/util/yaml"
"net/http"
"os"
"reflect"
......@@ -19,16 +16,19 @@ import (
"text/template"
"time"
kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
"github.com/kubeovn/kube-ovn/pkg/util"
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/tools/cache"
"k8s.io/klog/v2"
kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
"github.com/kubeovn/kube-ovn/pkg/util"
"github.com/kubeovn/kube-ovn/versions"
)
var (
......@@ -657,12 +657,12 @@ func getCoreDnsTemplateFile(url string) error {
return fmt.Errorf("access errors, return code:%d", resp.StatusCode)
}
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
err = ioutil.WriteFile(CorednsTemplateDep, data, 0644)
err = os.WriteFile(CorednsTemplateDep, data, 0644)
if err != nil {
return err
}
......
......@@ -80,7 +80,7 @@ func (c *Controller) setExGateway() error {
return nil
}
//Generally, the MTU of the interface is set to 1400. But in special cases, a special pod (docker indocker) will introduce the docker0 interface to the pod. The MTU of docker0 is 1500.
//The network application in pod will calculate the TCP MSS according to the MTU of docker0, and then initiate communication with others. After the other party sends a response, the kernel protocol stack of Linux host will send ICMP unreachable message to the other party, indicating that IP fragmentation is needed, which is not supported by the other party, resulting in communication failure.
// Generally, the MTU of the interface is set to 1400. But in special cases, a special pod (docker indocker) will introduce the docker0 interface to the pod. The MTU of docker0 is 1500.
// The network application in pod will calculate the TCP MSS according to the MTU of docker0, and then initiate communication with others. After the other party sends a response, the kernel protocol stack of Linux host will send ICMP unreachable message to the other party, indicating that IP fragmentation is needed, which is not supported by the other party, resulting in communication failure.
func (c *Controller) appendMssRule() {
}
......@@ -4,9 +4,9 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"io"
"os"
exec "os/exec"
"os/exec"
"reflect"
"strings"
"syscall"
......@@ -219,7 +219,7 @@ func checkNorthdActive() bool {
klog.Errorf("failed to open %s err = %v", OvnNorthdPid, err)
return false
}
fileByte, err := ioutil.ReadAll(file)
fileByte, err := io.ReadAll(file)
if err != nil {
klog.Errorf("failed to read %s err = %v", OvnNorthdPid, err)
return false
......
package ovs
import (
"context"
"fmt"
"github.com/ovn-org/libovsdb/client"
"github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb"
)
func (c OvnClient) GetLogicalSwitch(name string, ignoreNotFound bool) (*ovnnb.LogicalSwitch, error) {
ls := &ovnnb.LogicalSwitch{Name: name}
if err := c.ovnNbClient.Get(context.TODO(), ls); err != nil {
if ignoreNotFound && err == client.ErrNotFound {
return nil, nil
}
return nil, fmt.Errorf("failed to get logical switch %s: %v", name, err)
}
return ls, nil
}
func (c OvnClient) LogicalSwitchExists(name string) (bool, error) {
ls, err := c.GetLogicalSwitch(name, true)
return ls != nil, err
}
......@@ -5,12 +5,8 @@ import (
"fmt"
"github.com/ovn-org/libovsdb/client"
"github.com/ovn-org/libovsdb/model"
"github.com/ovn-org/libovsdb/ovsdb"
"k8s.io/klog/v2"
ovsclient "github.com/kubeovn/kube-ovn/pkg/ovsdb/client"
"github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb"
"github.com/kubeovn/kube-ovn/pkg/util"
)
......@@ -70,54 +66,3 @@ func (c OvnClient) LogicalSwitchPortExists(name string) (bool, error) {
lsp, err := c.GetLogicalSwitchPort(name, true)
return lsp != nil, err
}
func (c OvnClient) AddSwitchRouterPort(ls, lr string) error {
klog.Infof("add %s to %s", ls, lr)
lsTolr := fmt.Sprintf("%s-%s", ls, lr)
lrTols := fmt.Sprintf("%s-%s", lr, ls)
logicalSwitch, err := c.GetLogicalSwitch(ls, false)
if err != nil {
return err
}
var ops []ovsdb.Operation
lsp := &ovnnb.LogicalSwitchPort{
UUID: ovsclient.NamedUUID(),
Name: lsTolr,
Type: "router",
Addresses: []string{"router"},
Options: map[string]string{"router-port": lrTols},
ExternalIDs: map[string]string{"vendor": util.CniTypeName},
}
// ensure there is no port in the same name, before we create it in the transaction
waitOp := ConstructWaitForNameNotExistsOperation(lsTolr, "Logical_Switch_Port")
ops = append(ops, waitOp)
createOps, err := c.ovnNbClient.Create(lsp)
if err != nil {
return err
}
ops = append(ops, createOps...)
mutationOps, err := c.ovnNbClient.
Where(logicalSwitch).
Mutate(logicalSwitch,
model.Mutation{
Field: &logicalSwitch.Ports,
Mutator: ovsdb.MutateOperationInsert,
Value: []string{lsp.UUID},
},
)
if err != nil {
return err
}
ops = append(ops, mutationOps...)
if err := Transact(c.ovnNbClient, "lsp-add", ops, c.ovnNbClient.Timeout); err != nil {
return fmt.Errorf("failed to create logical switch port %s: %v", lsTolr, err)
}
return nil
}
This diff is collapsed.
// Copyright (C) 2018 Nippon Telegraph and Telephone Corporation.
//
// 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.
//nolint:staticcheck
package apiutil
import (
"fmt"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
api "github.com/osrg/gobgp/api"
"github.com/osrg/gobgp/pkg/packet/bgp"
)
func NewMultiProtocolCapability(a *bgp.CapMultiProtocol) *api.MultiProtocolCapability {
afi, safi := bgp.RouteFamilyToAfiSafi(a.CapValue)
return &api.MultiProtocolCapability{
Family: ToApiFamily(afi, safi),
}
}
func NewRouteRefreshCapability(a *bgp.CapRouteRefresh) *api.RouteRefreshCapability {
return &api.RouteRefreshCapability{}
}
func NewCarryingLabelInfoCapability(a *bgp.CapCarryingLabelInfo) *api.CarryingLabelInfoCapability {
return &api.CarryingLabelInfoCapability{}
}
func NewExtendedNexthopCapability(a *bgp.CapExtendedNexthop) *api.ExtendedNexthopCapability {
tuples := make([]*api.ExtendedNexthopCapabilityTuple, 0, len(a.Tuples))
for _, t := range a.Tuples {
tuples = append(tuples, &api.ExtendedNexthopCapabilityTuple{
NlriFamily: ToApiFamily(t.NLRIAFI, uint8(t.NLRISAFI)),
NexthopFamily: ToApiFamily(t.NexthopAFI, bgp.SAFI_UNICAST),
})
}
return &api.ExtendedNexthopCapability{
Tuples: tuples,
}
}
func NewGracefulRestartCapability(a *bgp.CapGracefulRestart) *api.GracefulRestartCapability {
tuples := make([]*api.GracefulRestartCapabilityTuple, 0, len(a.Tuples))
for _, t := range a.Tuples {
tuples = append(tuples, &api.GracefulRestartCapabilityTuple{
Family: ToApiFamily(t.AFI, t.SAFI),
Flags: uint32(t.Flags),
})
}
return &api.GracefulRestartCapability{
Flags: uint32(a.Flags),
Time: uint32(a.Time),
Tuples: tuples,
}
}
func NewFourOctetASNumberCapability(a *bgp.CapFourOctetASNumber) *api.FourOctetASNumberCapability {
return &api.FourOctetASNumberCapability{
As: a.CapValue,
}
}
func NewAddPathCapability(a *bgp.CapAddPath) *api.AddPathCapability {
tuples := make([]*api.AddPathCapabilityTuple, 0, len(a.Tuples))
for _, t := range a.Tuples {
afi, safi := bgp.RouteFamilyToAfiSafi(t.RouteFamily)
tuples = append(tuples, &api.AddPathCapabilityTuple{
Family: ToApiFamily(afi, safi),
Mode: api.AddPathMode(t.Mode),
})
}
return &api.AddPathCapability{
Tuples: tuples,
}
}
func NewEnhancedRouteRefreshCapability(a *bgp.CapEnhancedRouteRefresh) *api.EnhancedRouteRefreshCapability {
return &api.EnhancedRouteRefreshCapability{}
}
func NewLongLivedGracefulRestartCapability(a *bgp.CapLongLivedGracefulRestart) *api.LongLivedGracefulRestartCapability {
tuples := make([]*api.LongLivedGracefulRestartCapabilityTuple, 0, len(a.Tuples))
for _, t := range a.Tuples {
tuples = append(tuples, &api.LongLivedGracefulRestartCapabilityTuple{
Family: ToApiFamily(t.AFI, uint8(t.SAFI)),
Flags: uint32(t.Flags),
Time: t.RestartTime,
})
}
return &api.LongLivedGracefulRestartCapability{
Tuples: tuples,
}
}
func NewRouteRefreshCiscoCapability(a *bgp.CapRouteRefreshCisco) *api.RouteRefreshCiscoCapability {
return &api.RouteRefreshCiscoCapability{}
}
func NewUnknownCapability(a *bgp.CapUnknown) *api.UnknownCapability {
return &api.UnknownCapability{
Code: uint32(a.CapCode),
Value: a.CapValue,
}
}
func MarshalCapability(value bgp.ParameterCapabilityInterface) (*any.Any, error) {
var m proto.Message
switch n := value.(type) {
case *bgp.CapMultiProtocol:
m = NewMultiProtocolCapability(n)
case *bgp.CapRouteRefresh:
m = NewRouteRefreshCapability(n)
case *bgp.CapCarryingLabelInfo:
m = NewCarryingLabelInfoCapability(n)
case *bgp.CapExtendedNexthop:
m = NewExtendedNexthopCapability(n)
case *bgp.CapGracefulRestart:
m = NewGracefulRestartCapability(n)
case *bgp.CapFourOctetASNumber:
m = NewFourOctetASNumberCapability(n)
case *bgp.CapAddPath:
m = NewAddPathCapability(n)
case *bgp.CapEnhancedRouteRefresh:
m = NewEnhancedRouteRefreshCapability(n)
case *bgp.CapLongLivedGracefulRestart:
m = NewLongLivedGracefulRestartCapability(n)
case *bgp.CapRouteRefreshCisco:
m = NewRouteRefreshCiscoCapability(n)
case *bgp.CapUnknown:
m = NewUnknownCapability(n)
default:
return nil, fmt.Errorf("invalid capability type to marshal: %+v", value)
}
return ptypes.MarshalAny(m)
}
func MarshalCapabilities(values []bgp.ParameterCapabilityInterface) ([]*any.Any, error) {
caps := make([]*any.Any, 0, len(values))
for _, value := range values {
a, err := MarshalCapability(value)
if err != nil {
return nil, err
}
caps = append(caps, a)
}
return caps, nil
}
func unmarshalCapability(a *any.Any) (bgp.ParameterCapabilityInterface, error) {
var value ptypes.DynamicAny
if err := ptypes.UnmarshalAny(a, &value); err != nil {
return nil, fmt.Errorf("failed to unmarshal capability: %s", err)
}
switch a := value.Message.(type) {
case *api.MultiProtocolCapability:
return bgp.NewCapMultiProtocol(ToRouteFamily(a.Family)), nil
case *api.RouteRefreshCapability:
return bgp.NewCapRouteRefresh(), nil
case *api.CarryingLabelInfoCapability:
return bgp.NewCapCarryingLabelInfo(), nil
case *api.ExtendedNexthopCapability:
tuples := make([]*bgp.CapExtendedNexthopTuple, 0, len(a.Tuples))
for _, t := range a.Tuples {
var nhAfi uint16
switch t.NexthopFamily.Afi {
case api.Family_AFI_IP:
nhAfi = bgp.AFI_IP
case api.Family_AFI_IP6:
nhAfi = bgp.AFI_IP6
default:
return nil, fmt.Errorf("invalid address family for nexthop afi in extended nexthop capability: %s", t.NexthopFamily)
}
tuples = append(tuples, bgp.NewCapExtendedNexthopTuple(ToRouteFamily(t.NlriFamily), nhAfi))
}
return bgp.NewCapExtendedNexthop(tuples), nil
case *api.GracefulRestartCapability:
tuples := make([]*bgp.CapGracefulRestartTuple, 0, len(a.Tuples))
for _, t := range a.Tuples {
var forward bool
if t.Flags&0x80 > 0 {
forward = true
}
tuples = append(tuples, bgp.NewCapGracefulRestartTuple(ToRouteFamily(t.Family), forward))
}
var restarting bool
if a.Flags&0x08 > 0 {
restarting = true
}
var notification bool
if a.Flags&0x04 > 0 {
notification = true
}
return bgp.NewCapGracefulRestart(restarting, notification, uint16(a.Time), tuples), nil
case *api.FourOctetASNumberCapability:
return bgp.NewCapFourOctetASNumber(a.As), nil
case *api.AddPathCapability:
tuples := make([]*bgp.CapAddPathTuple, 0, len(a.Tuples))
for _, t := range a.Tuples {
tuples = append(tuples, bgp.NewCapAddPathTuple(ToRouteFamily(t.Family), bgp.BGPAddPathMode(t.Mode)))
}
return bgp.NewCapAddPath(tuples), nil
case *api.EnhancedRouteRefreshCapability:
return bgp.NewCapEnhancedRouteRefresh(), nil
case *api.LongLivedGracefulRestartCapability:
tuples := make([]*bgp.CapLongLivedGracefulRestartTuple, 0, len(a.Tuples))
for _, t := range a.Tuples {
var forward bool
if t.Flags&0x80 > 0 {
forward = true
}
tuples = append(tuples, bgp.NewCapLongLivedGracefulRestartTuple(ToRouteFamily(t.Family), forward, t.Time))
}
return bgp.NewCapLongLivedGracefulRestart(tuples), nil
case *api.RouteRefreshCiscoCapability:
return bgp.NewCapRouteRefreshCisco(), nil
case *api.UnknownCapability:
return bgp.NewCapUnknown(bgp.BGPCapabilityCode(a.Code), a.Value), nil
}
return nil, fmt.Errorf("invalid capability type to unmarshal: %s", a.TypeUrl)
}
func UnmarshalCapabilities(values []*any.Any) ([]bgp.ParameterCapabilityInterface, error) {
caps := make([]bgp.ParameterCapabilityInterface, 0, len(values))
for _, value := range values {
c, err := unmarshalCapability(value)
if err != nil {
return nil, err
}
caps = append(caps, c)
}
return caps, nil
}
// Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
//
// 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.
//nolint:staticcheck
package apiutil
import (
"encoding/json"
"net"
"time"
"github.com/golang/protobuf/ptypes"
api "github.com/osrg/gobgp/api"
"github.com/osrg/gobgp/pkg/packet/bgp"
)
// workaround. This for the json format compatibility. Once we update senario tests, we can remove this.
type Path struct {
Nlri bgp.AddrPrefixInterface `json:"nlri"`
Age int64 `json:"age"`
Best bool `json:"best"`
Attrs []bgp.PathAttributeInterface `json:"attrs"`
Stale bool `json:"stale"`
Withdrawal bool `json:"withdrawal,omitempty"`
SourceID net.IP `json:"source-id,omitempty"`
NeighborIP net.IP `json:"neighbor-ip,omitempty"`
}
type Destination struct {
Paths []*Path
}
func (d *Destination) MarshalJSON() ([]byte, error) {
return json.Marshal(d.Paths)
}
func NewDestination(dst *api.Destination) *Destination {
l := make([]*Path, 0, len(dst.Paths))
for _, p := range dst.Paths {
nlri, _ := GetNativeNlri(p)
attrs, _ := GetNativePathAttributes(p)
t, _ := ptypes.Timestamp(p.Age)
l = append(l, &Path{
Nlri: nlri,
Age: t.Unix(),
Best: p.Best,
Attrs: attrs,
Stale: p.Stale,
Withdrawal: p.IsWithdraw,
SourceID: net.ParseIP(p.SourceId),
NeighborIP: net.ParseIP(p.NeighborIp),
})
}
return &Destination{Paths: l}
}
func NewPath(nlri bgp.AddrPrefixInterface, isWithdraw bool, attrs []bgp.PathAttributeInterface, age time.Time) *api.Path {
t, _ := ptypes.TimestampProto(age)
return &api.Path{
Nlri: MarshalNLRI(nlri),
Pattrs: MarshalPathAttributes(attrs),
Age: t,
IsWithdraw: isWithdraw,
Family: ToApiFamily(nlri.AFI(), nlri.SAFI()),
Identifier: nlri.PathIdentifier(),
}
}
func getNLRI(family bgp.RouteFamily, buf []byte) (bgp.AddrPrefixInterface, error) {
afi, safi := bgp.RouteFamilyToAfiSafi(family)
nlri, err := bgp.NewPrefixFromRouteFamily(afi, safi)
if err != nil {
return nil, err
}
if err := nlri.DecodeFromBytes(buf); err != nil {
return nil, err
}
return nlri, nil
}
func GetNativeNlri(p *api.Path) (bgp.AddrPrefixInterface, error) {
if len(p.NlriBinary) > 0 {
return getNLRI(ToRouteFamily(p.Family), p.NlriBinary)
}
return UnmarshalNLRI(ToRouteFamily(p.Family), p.Nlri)
}
func GetNativePathAttributes(p *api.Path) ([]bgp.PathAttributeInterface, error) {
pattrsLen := len(p.PattrsBinary)
if pattrsLen > 0 {
pattrs := make([]bgp.PathAttributeInterface, 0, pattrsLen)
for _, attr := range p.PattrsBinary {
a, err := bgp.GetPathAttribute(attr)
if err != nil {
return nil, err
}
err = a.DecodeFromBytes(attr)
if err != nil {
return nil, err
}
pattrs = append(pattrs, a)
}
return pattrs, nil
}
return UnmarshalPathAttributes(p.Pattrs)
}
func ToRouteFamily(f *api.Family) bgp.RouteFamily {
return bgp.AfiSafiToRouteFamily(uint16(f.Afi), uint8(f.Safi))
}
func ToApiFamily(afi uint16, safi uint8) *api.Family {
return &api.Family{
Afi: api.Family_Afi(afi),
Safi: api.Family_Safi(safi),
}
}
......@@ -5,12 +5,12 @@ import (
"errors"
"flag"
"fmt"
"github.com/osrg/gobgp/pkg/packet/bgp"
"os"
"time"
api "github.com/osrg/gobgp/api"
gobgp "github.com/osrg/gobgp/pkg/server"
api "github.com/osrg/gobgp/v3/api"
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
gobgp "github.com/osrg/gobgp/v3/pkg/server"
"github.com/spf13/pflag"
"google.golang.org/grpc"
"k8s.io/client-go/kubernetes"
......@@ -198,7 +198,7 @@ func (config *Configuration) initBgpServer() error {
}
if err := s.StartBgp(context.Background(), &api.StartBgpRequest{
Global: &api.Global{
As: config.ClusterAs,
Asn: config.ClusterAs,
RouterId: config.RouterId,
ListenPort: listenPort,
UseMultiplePaths: true,
......@@ -211,7 +211,7 @@ func (config *Configuration) initBgpServer() error {
Timers: &api.Timers{Config: &api.TimersConfig{HoldTime: uint64(config.HoldTime)}},
Conf: &api.PeerConf{
NeighborAddress: config.NeighborAddress,
PeerAs: config.NeighborAs,
PeerAsn: config.NeighborAs,
},
Transport: &api.Transport{
PassiveMode: config.PassiveMode,
......
......@@ -4,20 +4,19 @@ package speaker
import (
"context"
"fmt"
"github.com/vishvananda/netlink"
"net"
"strconv"
"strings"
"github.com/golang/protobuf/ptypes"
anypb "github.com/golang/protobuf/ptypes/any"
bgpapi "github.com/osrg/gobgp/api"
"github.com/osrg/gobgp/pkg/packet/bgp"
bgpapi "github.com/osrg/gobgp/v3/api"
bgpapiutil "github.com/osrg/gobgp/v3/pkg/apiutil"
"github.com/osrg/gobgp/v3/pkg/packet/bgp"
"github.com/vishvananda/netlink"
"google.golang.org/protobuf/types/known/anypb"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/klog/v2"
bgpapiutil "github.com/kubeovn/kube-ovn/pkg/speaker/bgpapiutil"
"github.com/kubeovn/kube-ovn/pkg/util"
)
......@@ -180,14 +179,14 @@ func (c *Controller) getNlriAndAttrs(route string) (*anypb.Any, []*anypb.Any, er
if err != nil {
return nil, nil, err
}
nlri, _ := ptypes.MarshalAny(&bgpapi.IPAddressPrefix{
nlri, _ := anypb.New(&bgpapi.IPAddressPrefix{
Prefix: prefix,
PrefixLen: prefixLen,
})
a1, _ := ptypes.MarshalAny(&bgpapi.OriginAttribute{
a1, _ := anypb.New(&bgpapi.OriginAttribute{
Origin: 0,
})
a2, _ := ptypes.MarshalAny(&bgpapi.NextHopAttribute{
a2, _ := anypb.New(&bgpapi.NextHopAttribute{
NextHop: getNextHopAttribute(c.config.NeighborAddress, c.config.RouterId),
})
attrs := []*anypb.Any{a1, a2}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment