Skip to content
Snippets Groups Projects
Commit 5abaac44 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

delete confligting files

parents f08fc969 0fb29710
No related branches found
No related tags found
1 merge request!2Packet/ospfv3
Pipeline #53059 failed
Showing
with 322 additions and 499 deletions
#!/bin/sh
for i in examples/*; do
echo "building $i"
go install github.com/bio-routing/bio-rd/$i
done
#!/bin/bash
result="$(gofmt -e -s -l . 2>&1 | grep -v '^vendor/' )"
if [ -n "$result" ]; then
echo "Go code is not formatted, run 'gofmt -e -s -w .'" >&2
echo "$result"
exit 1
else
echo "Go code is formatted well"
fi
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
jobs:
build:
docker:
- image: circleci/golang:1.13
steps:
- checkout
- run: go test -v -cover -coverprofile=coverage.txt ./...
- run: bash <(curl -s https://codecov.io/bash)
- run: .circleci/build-examples
- run: .circleci/check-gofmt
*.raw filter=lfs diff=lfs merge=lfs -text
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**Steps to Reproduce**
Give us clear and precise steps how to reproduce the bug.
**Expected behavior**
A clear and concise description of what you expected to happen.
**Configuration used**
Please show us your config, what settings did u used?
**Additional context**
Add any other context about the problem here.
variables:
SECURE_ANALYZERS_PREFIX: registry.gitlab.com/gitlab-org/security-products/analyzers
stages:
- test
test:cover:
image: golang:1.15
stage: test
script:
- go test -v -cover ./...
include:
# - local: '/build/ci/.code-quality-ci.yml'
- local: '/build/ci/.security-and-compliance-ci.yml'
...@@ -13,20 +13,34 @@ A re-implementation of BGP, IS-IS and OSPF in go. We value respect and robustnes ...@@ -13,20 +13,34 @@ A re-implementation of BGP, IS-IS and OSPF in go. We value respect and robustnes
#### BGP #### BGP
cd examples/bgp/ && go build ```
cd examples/bgp/ && go build
```
#### BMP #### BMP
cd examples/bmp/ && go build ```
cd examples/bmp/ && go build
```
#### Device #### Device
cd examples/device && go build ```
cd examples/device && go build
```
### Run Tests ### Run Tests
go test -v -cover ./... ```
go test -v -cover ./...
```
### Update modules ### Update modules
go mod tidy ```
go mod tidy
```
## Benchmarks
The benchmarks can be found in the [bio-rd-benchmarks](/bio-routing/bio-rd-benchmarks) repository.
\ No newline at end of file
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
package main
import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
"runtime/pprof"
"time"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
log "github.com/sirupsen/logrus"
)
var (
nRuns = flag.Int("runs", 1, "# runs")
)
type task struct {
num int
raw *bytes.Buffer
msg *packet.BGPMessage
}
func main() {
flag.Parse()
updates := make([][]*bytes.Buffer, *nRuns)
for i := 0; i < *nRuns; i++ {
updates[i] = make([]*bytes.Buffer, 0)
}
raw, err := ioutil.ReadFile("AS8881.raw")
if err != nil {
log.Errorf("Unable to open PCAP file: %v", err)
os.Exit(1)
}
msgs := extractBGPMessages(raw)
for _, msg := range msgs {
for i := 0; i < *nRuns; i++ {
updates[i] = append(updates[i], bytes.NewBuffer(msg))
}
}
c := len(updates[0])
fmt.Printf("Decoding %d BGP messages\n", c)
buf := bytes.NewBuffer(nil)
err = pprof.StartCPUProfile(buf)
if err != nil {
panic(err)
}
dco := &packet.DecodeOptions{
Use32BitASN: true,
}
start := time.Now().UnixNano()
nlriCount := 0
for j := 0; j < *nRuns; j++ {
for i := 0; i < c; i++ {
msg, err := packet.Decode(updates[j][i], dco)
if err != nil {
fmt.Printf("Unable to decode msg %d: %v\n", i, err)
continue
}
if msg.Header.Type == 2 {
n := msg.Body.(*packet.BGPUpdate).NLRI
for {
if n == nil {
break
}
nlriCount++
n = n.Next
}
}
}
}
fmt.Printf("NLRIs: %d\n", nlriCount)
end := time.Now().UnixNano()
d := end - start
pprof.StopCPUProfile()
fmt.Printf("decoding updates took %d ms\n", d/1000000)
ioutil.WriteFile("profile.pprof", buf.Bytes(), 0644)
x := bytes.NewBuffer(nil)
pprof.WriteHeapProfile(x)
ioutil.WriteFile("heap.pprof", x.Bytes(), 0644)
}
func hexDump(input []byte) string {
s := ""
for _, x := range input {
s += fmt.Sprintf("%x ", x)
}
return s
}
func extractBGPMessages(input []byte) [][]byte {
fmt.Printf("Extracting BGP messages from %d bytes\n", len(input))
ret := make([][]byte, 0)
//fmt.Printf("Data: %v\n", input[0:24])
l := len(input)
i := 0
for {
if i+17 > l {
break
}
for j := 0; j < 16; j++ {
if input[i+j] != 255 {
panic(fmt.Sprintf("Invalid BGP marker: (%d+%d=%d): %s", i, j, i+j, hexDump(input[i:i+16])))
}
}
msgLen := uint16(input[i+16])*256 + uint16(input[i+17])
ret = append(ret, input[i:i+int(msgLen)])
if msgLen == 0 {
panic(msgLen)
}
i += int(msgLen)
}
fmt.Printf("Done\n")
return ret
}
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"runtime/pprof"
"time"
"net/http"
_ "net/http/pprof"
bnet "github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/protocols/bgp/server"
"github.com/bio-routing/bio-rd/routingtable"
"github.com/bio-routing/bio-rd/routingtable/filter"
"github.com/bio-routing/bio-rd/routingtable/vrf"
btesting "github.com/bio-routing/bio-rd/testing"
"github.com/sirupsen/logrus"
)
/*
*
* This benchmark measure the time to learn 750k BGP prefixes
*
*/
func main() {
go http.ListenAndServe("localhost:1337", nil)
b := server.NewBGPServer(100, nil)
v, err := vrf.New("master", 0)
if err != nil {
log.Fatal(err)
}
iEnd := 100
jEnd := 100
kEnd := 75
ch := make(chan struct{})
fmt.Printf("Learning %d routes\n", kEnd*iEnd*jEnd)
v.IPv4UnicastRIB().SetCountTarget(uint64(kEnd*iEnd*jEnd), ch)
err = b.Start()
if err != nil {
logrus.Fatalf("Unable to start BGP server: %v", err)
}
con := btesting.NewMockConnBidi(&btesting.MockAddr{
Addr: "169.254.200.0:1234",
Proto: "TCP",
}, &btesting.MockAddr{
Addr: "172.17.0.3:179",
Proto: "TCP",
})
openMSG := []byte{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // Marker
0, 29, // Length
1, // Type = Open
4, // Version
0, 200, //ASN,
0, 15, // Holdtime
10, 20, 30, 40, // BGP Identifier
0, // Opt Parm Len
}
con.WriteB(openMSG)
keepAlive := []byte{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // Marker
0, 19, // Length
4, // Type = Keepalive
}
con.WriteB(keepAlive)
c := 0
for i := 0; i < iEnd; i++ {
for j := 0; j < jEnd; j++ {
for k := 1; k <= kEnd; k++ {
update := []byte{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // Marker
0, 80, // Length
2, // Type = Update
0, 0, // Withdraw length
0, 53, // Total Path Attribute Length
255, // Attribute flags
1, // Attribute Type code (ORIGIN)
0, 1, // Length
2, // INCOMPLETE
0, // Attribute flags
2, // Attribute Type code (AS Path)
12, // Length
2, // Type = AS_SEQUENCE
2, // Path Segment Length
59, 65, // AS15169
12, 248, // AS3320
1, // Type = AS_SET
2, // Path Segment Length
59, 65, // AS15169
12, 248, // AS3320
0, // Attribute flags
3, // Attribute Type code (Next Hop)
4, // Length
10, 11, 12, 13, // Next Hop
0, // Attribute flags
4, // Attribute Type code (MED)
4, // Length
0, 0, 1, 0, // MED 256
0, // Attribute flags
5, // Attribute Type code (Local Pref)
4, // Length
0, 0, 1, 0, // Local Pref 256
0, // Attribute flags
6, // Attribute Type code (Atomic Aggregate)
0, // Length
0, // Attribute flags
7, // Attribute Type code (Atomic Aggregate)
6, // Length
1, 2, // ASN
10, 11, 12, 13, // Address
24, uint8(k), uint8(i), uint8(j), // Prefix
}
con.WriteB(update)
c++
}
}
}
fmt.Printf("Added routes: %d\n", c)
buf := bytes.NewBuffer(nil)
err = pprof.StartCPUProfile(buf)
if err != nil {
panic(err)
}
peerCfg := server.PeerConfig{
AdminEnabled: true,
LocalAS: 65200,
PeerAS: 200,
PeerAddress: bnet.IPv4FromOctets(172, 17, 0, 3).Ptr(),
LocalAddress: bnet.IPv4FromOctets(169, 254, 200, 0).Ptr(),
ReconnectInterval: time.Second * 15,
HoldTime: time.Second * 90,
KeepAlive: time.Second * 30,
Passive: true,
RouterID: b.RouterID(),
IPv4: &server.AddressFamilyConfig{
ImportFilterChain: filter.NewAcceptAllFilterChain(),
ExportFilterChain: filter.NewAcceptAllFilterChain(),
AddPathSend: routingtable.ClientOptions{
MaxPaths: 10,
},
},
RouteServerClient: true,
VRF: v,
}
b.AddPeer(peerCfg)
start := time.Now().UnixNano()
b.ConnectMockPeer(peerCfg, con)
<-ch
end := time.Now().UnixNano()
d := end - start
pprof.StopCPUProfile()
fmt.Printf("Learning routes took %d ms\n", d/1000000)
ioutil.WriteFile("profile.pprof", buf.Bytes(), 0644)
x := bytes.NewBuffer(nil)
pprof.WriteHeapProfile(x)
ioutil.WriteFile("heap.pprof", x.Bytes(), 0644)
}
package main
import (
"bytes"
"fmt"
"io/ioutil"
"runtime/pprof"
"time"
bnet "github.com/bio-routing/bio-rd/net"
)
func main() {
for i := 0; i < 255; i++ {
for j := 0; j < 255; j++ {
for k := 0; k < 11; k++ {
addr := bnet.IPv4FromOctets(10, uint8(i), uint8(j), uint8(k))
addr.Dedup()
}
}
}
buf := bytes.NewBuffer(nil)
err := pprof.StartCPUProfile(buf)
if err != nil {
panic(err)
}
start := time.Now().UnixNano()
for x := 0; x < 1; x++ {
for i := 0; i < 255; i++ {
for j := 0; j < 255; j++ {
for k := 0; k < 11; k++ {
addr := bnet.IPv4FromOctets(10, uint8(i), uint8(j), uint8(k))
addr.Dedup()
}
}
}
}
end := time.Now().UnixNano()
d := end - start
pprof.StopCPUProfile()
fmt.Printf("Looking up IP-Addresses took %d ms\n", d/1000000)
ioutil.WriteFile("profile.pprof", buf.Bytes(), 0644)
x := bytes.NewBuffer(nil)
pprof.WriteHeapProfile(x)
ioutil.WriteFile("heap.pprof", x.Bytes(), 0644)
}
package main
import (
"bytes"
"fmt"
"io/ioutil"
"runtime/pprof"
"time"
bnet "github.com/bio-routing/bio-rd/net"
)
func main() {
pfxs := make([]*bnet.Prefix, 0)
for i := 0; i < 255; i++ {
for j := 0; j < 255; j++ {
for k := 0; k < 11; k++ {
addr := bnet.IPv4FromOctets(uint8(k)+1, uint8(i), uint8(j), 0)
pfxs = append(pfxs, bnet.NewPfx(addr, 24).Dedup())
}
}
}
buf := bytes.NewBuffer(nil)
err := pprof.StartCPUProfile(buf)
if err != nil {
panic(err)
}
start := time.Now().UnixNano()
for i := range pfxs {
pfxs[i].Dedup()
}
end := time.Now().UnixNano()
d := end - start
pprof.StopCPUProfile()
fmt.Printf("Looking up Prefixes took %d ms\n", d/1000000)
ioutil.WriteFile("profile.pprof", buf.Bytes(), 0644)
x := bytes.NewBuffer(nil)
pprof.WriteHeapProfile(x)
ioutil.WriteFile("heap.pprof", x.Bytes(), 0644)
}
code-quality-master:
stage: test
allow_failure: true
tags:
- baremetal
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script:
# writes golangci-lint output to gl-code-quality-report.json
- /home/gitlab-runner/go/bin/golangci-lint run --config build/ci/.golangci-config/.golangci-master.yml --out-format code-climate | tee gl-code-quality-report.json
artifacts:
reports:
codequality: gl-code-quality-report.json
paths:
- gl-code-quality-report.json
code-quality:
stage: test
allow_failure: true
tags:
- baremetal
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != $CI_DEFAULT_BRANCH
script:
# writes golangci-lint output to gl-code-quality-report.json
- /home/gitlab-runner/go/bin/golangci-lint run --config build/ci/.golangci-config/.golangci.yml --out-format code-climate | tee gl-code-quality-report.json
artifacts:
reports:
codequality: gl-code-quality-report.json
paths:
- gl-code-quality-report.json
run:
timeout: 5m
issues-exit-code: 1
output:
format: code-climate
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
path-prefix: ""
linters-settings:
gocyclo:
min-complexity: 15
golint:
min-confidence: 0.8
linters:
disable-all: true
enable:
- gofmt
- golint
- gocyclo
- govet
issues:
exclude-use-default: false
run:
timeout: 5m
issues-exit-code: 1
output:
format: code-climate
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
path-prefix: ""
linters-settings:
gocyclo:
min-complexity: 15
golint:
min-confidence: 0.8
linters:
disable-all: true
enable:
- gofmt
- golint
- gocyclo
- govet
golangci-lint run\
--config .ci/.golangci-master.yml\
--out-format code-climate |\
jq -r '.[] | "\(.location.path):\(.location.lines.begin) \(.description)"'
sast:
variables:
SAST_ANALYZER_IMAGE_TAG: '2'
SAST_EXCLUDED_PATHS: spec, test, tests, tmp
SEARCH_MAX_DEPTH: '4'
include:
- template: Security/SAST.gitlab-ci.yml
- template: Dependency-Scanning.gitlab-ci.yml
- template: Security/License-Scanning.gitlab-ci.yml
package config
import (
"fmt"
"io/ioutil"
"net"
"github.com/bio-routing/bio-rd/routingtable/vrf"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
)
// RISMirrorConfig is the config of RISMirror instance
type RISMirrorConfig struct {
RIBConfigs []*RIBConfig `yaml:"ribs"`
}
// RIBConfig is a RIB configuration
type RIBConfig struct {
Router string `yaml:"router"`
router net.IP
VRFs []string `yaml:"vrfs"`
vrfs []uint64
IPVersions []uint8 `yaml:"IPVersions"`
SrcRISInstances []string `yaml:"source_ris_instances"`
}
// GetRouter gets a routers IP address
func (rc *RIBConfig) GetRouter() net.IP {
return rc.router
}
// GetVRFs gets a routers VRFs
func (rc *RIBConfig) GetVRFs() []uint64 {
return rc.vrfs
}
// LoadConfig loads a RISMirror config
func LoadConfig(filepath string) (*RISMirrorConfig, error) {
f, err := ioutil.ReadFile(filepath)
if err != nil {
return nil, errors.Wrap(err, "Unable to read config file")
}
cfg := &RISMirrorConfig{}
err = yaml.Unmarshal(f, cfg)
if err != nil {
return nil, errors.Wrap(err, "Unmarshal failed")
}
for _, rc := range cfg.RIBConfigs {
err := rc.loadRouter()
if err != nil {
return nil, errors.Wrap(err, "Unable to load router config")
}
err = rc.loadVRFs()
if err != nil {
return nil, errors.Wrap(err, "Unable to load VRFs")
}
}
return cfg, nil
}
func (r *RIBConfig) loadRouter() error {
addr := net.ParseIP(r.Router)
if addr == nil {
return fmt.Errorf("Unable to parse routers IP: %q", r.Router)
}
r.router = addr
return nil
}
func (r *RIBConfig) loadVRFs() error {
for _, vrfHuman := range r.VRFs {
vrfRD, err := vrf.ParseHumanReadableRouteDistinguisher(vrfHuman)
if err != nil {
return errors.Wrap(err, "Unable to parse VRF identifier")
}
r.vrfs = append(r.vrfs, vrfRD)
}
return nil
}
// GetRISInstances returns a list of all RIS instances in the config
func (rismc *RISMirrorConfig) GetRISInstances() []string {
instances := make(map[string]struct{})
for _, r := range rismc.RIBConfigs {
for _, s := range r.SrcRISInstances {
instances[s] = struct{}{}
}
}
ret := make([]string, 0)
for instance := range instances {
ret = append(ret, instance)
}
return ret
}
package main
import (
"flag"
"os"
"time"
"github.com/bio-routing/bio-rd/cmd/ris-mirror/config"
"github.com/bio-routing/bio-rd/cmd/ris-mirror/rismirror"
pb "github.com/bio-routing/bio-rd/cmd/ris/api"
"github.com/bio-routing/bio-rd/cmd/ris/risserver"
prom_grpc_cm "github.com/bio-routing/bio-rd/metrics/grpc/clientmanager/adapter/prom"
prom_ris_mirror "github.com/bio-routing/bio-rd/metrics/ris-mirror/adapter/prom"
"github.com/bio-routing/bio-rd/util/grpc/clientmanager"
"github.com/bio-routing/bio-rd/util/servicewrapper"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
)
var (
grpcPort = flag.Uint("grpc_port", 4321, "gRPC server port")
httpPort = flag.Uint("http_port", 4320, "HTTP server port")
grpcKeepaliveMinTime = flag.Uint("grpc_keepalive_min_time", 1, "Minimum time (seconds) for a client to wait between GRPC keepalive pings")
risTimeout = flag.Uint("ris_timeout", 5, "RIS timeout in seconds")
configFilePath = flag.String("config.file", "ris_mirror.yml", "Configuration file")
)
func main() {
flag.Parse()
cfg, err := config.LoadConfig(*configFilePath)
if err != nil {
log.WithError(err).Fatal("Failed to load config")
}
grpcClientManager := clientmanager.New()
for _, instance := range cfg.GetRISInstances() {
err := grpcClientManager.AddIfNotExists(instance, grpc.WithInsecure(), grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: time.Second * 10,
Timeout: time.Second * time.Duration(*risTimeout),
PermitWithoutStream: true,
}))
if err != nil {
log.WithError(err).Fatal("GRPC clientmanager add failed")
}
}
m := rismirror.New()
prometheus.MustRegister(prom_ris_mirror.NewCollector(m))
prometheus.MustRegister(prom_grpc_cm.NewCollector(grpcClientManager))
for _, rcfg := range cfg.RIBConfigs {
for _, vrdRD := range rcfg.GetVRFs() {
srcs := make([]*grpc.ClientConn, 0)
for _, srcInstance := range rcfg.SrcRISInstances {
srcs = append(srcs, grpcClientManager.Get(srcInstance))
}
m.AddTarget(rcfg.Router, rcfg.GetRouter(), vrdRD, srcs)
}
}
s := risserver.NewServer(m)
unaryInterceptors := []grpc.UnaryServerInterceptor{}
streamInterceptors := []grpc.StreamServerInterceptor{}
srv, err := servicewrapper.New(
uint16(*grpcPort),
servicewrapper.HTTP(uint16(*httpPort)),
unaryInterceptors,
streamInterceptors,
keepalive.EnforcementPolicy{
MinTime: time.Duration(*grpcKeepaliveMinTime) * time.Second,
PermitWithoutStream: true,
},
)
if err != nil {
log.Errorf("failed to listen: %v", err)
os.Exit(1)
}
pb.RegisterRoutingInformationServiceServer(srv.GRPC(), s)
if err := srv.Serve(); err != nil {
log.Fatalf("failed to start server: %v", err)
}
}
ribs:
- router: 10.200.0.1
vrfs: [51324:65201]
source_ris_instances: ["ncs01.lej01.srv.exaring.net:4321", "ncs02.lej01.srv.exaring.net:4321"]
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment