Upgrade to Pro — share decks privately, control downloads, hide ads and more …

17MBのフルルートルータ

 17MBのフルルートルータ

nnao45

June 08, 2018
Tweet

More Decks by nnao45

Other Decks in Technology

Transcript

  1. ‣໊લɿԣࢁ ঘ໻ɹ(ฏ੒3೥ 11݄13೔ੜ·Ε) ‣ॴଐɿCyber AgentגࣜձࣾɹΞυςΫຊ෦ɹ5݄1೔ೖࣾ ‣ݱ৬ɿαʔόαΠυͷίʔσΟϯάɺύϒϦοΫΫϥ΢υपΓͷΠϯϑϥ୲౰ɻ ‣લ৬ɿ๭Ϋϥ΢υϕϯμʹͯɺόοΫϘʔϯωοτϫʔΫ։ൃɺӡ༻ɻ ‣લʑ৬ɿ๭ΩϟϦΞʹͯɺPBB,EVPN,MPLS,VXLANपΓͷݚڀ։ൃɻ ‣঎ࡐɿฐࣾͷαʔόαΠυΛ΍Β͍ͤͯͨͩ͘༧ఆɻ ‣ٕज़ɿBGPɺEVPNɺGoݴޠɺScalaɺ

    kubernetesɺrancher ‣Githubɿ https://github.com/nnao45ʢશ෦GoͰ͢সʣ ‣ओͳίϯτϦϏϡʔτɿosrg/gobgpɺfuture-architect/vulsɺskycoin/skycoin….etc ‣ओͳࣗ࡞ιϑτɿpexpo…λʔϛφϧͰExping(ʮgo pingʯͱݕࡧ͢Δͱग़·͢) jgob…gobgpΛREST HTTP APIԽ͢ΔϑϨʔϜϫʔΫ @nnao45 https://nathany.com/go-testing-toolbox/
  2. CI/CDͷલʹͦ΋ͦ΋ςετॻ͚΍ɻ ੈ͸·͞ʹେίϯςφʔ࣌୅www ͸Φϫίϯ Ansible͸όʔδϣϯ2.6ͰmerakiϞδϡʔϧʹରԠɻ ͜Ε͔Β͸ػցֶ ↑ϋΠϋΠࣗԋԵ VimVimVimVimVimVimVimVimVimVimVimVimVimVimVimVim kubernetes࠷ߴ gVisorͱ͔͕ࠓ͸ྲྀߦΓΒ͠ EmacsEmacsEmacsEmacsEmacsEmacsEmacsEmacsEmac

    ͦΕGitlabͰ΍Ε͹ʁ ࣮ࡍֶशϞσϧ͑͋͞Ε͹ޙ͸Ϧιʔε͔ͩ keynoteͰΞχϝֆͬͯҾ͖·͔͢ ίϯςφʹ͢ΔඞཁͶʔͩΖw C++ͷ࣍͸Rustɻҟ࿦͸ ͳ Μ ͔ ஌ Β Μ ϒϩοΫνΣʔϯ͸ ͚ Ͳ प Γ ͷ ք ۾ ͸SREͱͯ͠ؤுΓ·͢ ͸ ੌ ͍ ͳ ͊ ·ͨόζϫʔυ͔Αɻ vimrcॻ͍ͯҰ೔ऴΘͬͨɻ ΩζφΞΠٕͬͯज़
  3. • اۀͱͯ͠࢖͏৔߹ɺ৭ʑ΍Δ࣌ʹ৭ʑɾɾɾɻ • σʔλϓϨʔϯपΓͰ੍໿͕େ͖͍ɻ • τϨʔχϯά༻్ʹݶఆ͞ΕΔʢͱࢥ͍ͬͯΔʣɻ • ࠓͷ୅දతͳNWٕज़͸ރΕ͖ͬͯΔ͠ɺຊ൪؀ڥͰCLIૢ࡞͢ΔͳΒखࠒͳϧʔλͰ͍͍ɻ • OSΛLinuxͰબͿͱ͍͏͚ͩͰΞυόϯςʔδΛಘΕΔػձ͸ͦ͏େ͖͘͸ͳ͍ɻ

    • σʔλϓϨʔϯͲ͏͢Δ໰୊ɻ • ѻ͏ͷʹඞཁͳεΩϧηοτ͕Ψν੎޲͚͗͢Δɻ • ͲͪΒ͔ͱ͍͏ͱ૊ΈࠐΈΤϯδχΞ޲͚ͱ͑͞ࢥ͑Δɻ • ͦ͜·ͰΨνͰ΍Δͷ͸ཁ݅͸தʑͳ͍͔΋ʢۚ༥ܥͷΫϥ΢υNWͰ͸Ձ஋ߴ͍ͱࢥ͏ʣɻ .FSBLJƋŮƥ%ǭȂ✣ȉƒ$16⥦৘ƃźaໃটƑťƮ࠯ℿƃƋනũb OFUOTƋ❣ƶƊaƋƉƥŭൗὐƎƍƆƉŧơżč睬ȼ睬Ď ŶƯƥἠದ০ႨƋŮaƄƪƆƋźƂὨି⃷⃾ƊƒਅŲ൐ƲƯơżƫƐb ※શͯݸਓతͳҙݟͳͷͰɺ ܰ͘ฉ͖ྲྀ͍ͯͩ͘͠͞ =Ǫȉdzȉǧȉdzȉ̇
  4. • اۀͱͯ͠࢖͏৔߹ɺ৭ʑ΍Δ࣌ʹ৭ʑɾɾɾɻ • σʔλϓϨʔϯपΓͰ੍໿͕େ͖͍ɻ • τϨʔχϯά༻్ʹݶఆ͞ΕΔʢͱࢥ͍ͬͯΔʣɻ • ࠓͷ୅දతͳNWٕज़͸ރΕ͖ͬͯΔ͠ɺຊ൪؀ڥͰCLIૢ࡞͢ΔͳΒखࠒͳϧʔλͰ͍͍ɻ • OSΛLinuxͰબͿͱ͍͏͚ͩͰΞυόϯςʔδΛಘΕΔػձ͸ͦ͏େ͖͘͸ͳ͍ɻ

    • σʔλϓϨʔϯͲ͏͢Δ໰୊ɻ • ѻ͏ͷʹඞཁͳεΩϧηοτ͕Ψν੎޲͚͗͢Δɻ • ͲͪΒ͔ͱ͍͏ͱ૊ΈࠐΈΤϯδχΞ޲͚ͱ͑͞ࢥ͑Δɻ • ͦ͜·ͰΨνͰ΍Δͷ͸ཁ݅͸தʑͳ͍͔΋ʢۚ༥ܥͷΫϥ΢υNWͰ͸Ձ஋ߴ͍ͱࢥ͏ʣɻ .FSBLJƋŮƥ%ǭȂ✣ȉƒ$16⥦৘ƃźaໃটƑťƮ࠯ℿƃƋනũb OFUOTƋ❣ƶƊaƋƉƥŭൗὐƒƍƆƉŧơżč睬ȼ睬Ď ŶƯƥἠದ০ႨƋŮaƄƪƆƋźƂὨି⃷⃾ƊƒਅŲ൐ƲƯơżƫƐb ※શͯݸਓతͳҙݟͳͷͰɺ ܰ͘ฉ͖ྲྀ͍ͯͩ͘͠͞ =Ǫȉdzȉǧȉdzȉ̇ ࠓ೔ͷൃදͰ͸ɺ ͜ΕΒͱ͸ผͷΞϓϩʔνͰ /8Λ΋ͬͱ༡΂ΔΑ͏ʹ͠·͢ ࠇຐज़ʹ๋͛Δ୅ঈ͸ίʔυɾɾɾʁ w w w
  5. FROM golang:latest WORKDIR /go/src/github.com/alexellis/href-counter/ RUN go get -d -v golang.org/x/net/html

    COPY app.go . RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . FROM alpine:latest RUN apk --no-cache add ca-certificates WORKDIR /root/ COPY --from=0 /go/src/github.com/alexellis/href-counter/app . CMD ["./app"] Dockerfile https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
  6. bin ϑϧϧʔτ RIB toml busybody bin ϑϧϧʔτ RIB toml ࣮ߦϑΝΠϧͷϏϧυ

    ߏ੒ઃఆͷϑΝΠϧ MIBϑΝΠϧͷDL golang:alpine root@v-lab:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> 8596549588c1 42 hours ago 949MB nnao45/full-routaas latest e916b7ff399a 42 hours ago 102MB ※RIBϑΝΠϧ͕ 85MB͋ΔͷͰɺ ίϯςφຊମ͸ 102 - 85 =17MB
  7. FROM golang:alpine AS builder MAINTAINER nnao45 <[email protected]> RUN apk update

    && \ apk upgrade && \ apk add git make ADD . $GOPATH/src/app WORKDIR $GOPATH/src/app RUN make dep-install RUN make dep RUN make RUN mkdir /app && \ cp -a $GOPATH/src/app/full-routaas /app && \ cp -a $GOPATH/src/app/config.tml /app && \ cp -a $GOPATH/src/app/rib* /app FROM busybox WORKDIR /root/ COPY --from=builder app . CMD ["./full-routaas"] Dockerfile https://system-admins.ru/vnedrenie-docker/
  8. https://www.analyticsvidhya.com/blog/2017/11/reproducible-data-science-docker-for-data-science/ #show bgp ipv4 unicast summary Wed Apr 22 16:13:33.503

    JST BGP router identifier XX.XX.XX.XX, local AS number XXXXX BGP generic scan interval 60 secs Non-stop routing is enabled BGP table state: Active Table ID: 0xe0000000 RD version: 205 BGP main routing table version 205 BGP NSR Initial initsync version 51 (Reached) BGP NSR/ISSU Sync-Group versions 0/0 BGP scan interval 60 secs BGP is operating in STANDALONE mode. Process RcvTblVer bRIB/RIB LabelVer ImportVer SendTblVer StandbyVer Speaker 205 205 205 205 205 0 Neighbor Spk AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down St/PfxRcd XX.XX.XX.XX 0 XXXXX 2573601 58 112 0 0 00:01:26 696234 # time docker push ϩʔΧϧNWͷ΄͛΄͛:5000/nnao45/full-routaas The push refers to repository [XX.XX.XX.XX:5000/nnao45/full-routaas] 095a50fd17f7: Pushed 0314be9edf00: Pushed latest: digest: sha256:6080de0f02b50874926472ab2fca62d4d9746866 ca9dd4263991d569b264c952 size: 739 real 0m3.598s user 0m0.080s sys 0m0.020s 1෼26ඵͰ70ສܦ࿏ऑ޿ใʂʂ ϓϥΠϕʔτϨϙδτϦʹ docker pushɺΘ͔ͣ4ඵʂʂ
  9. LDFLAGS := -ldflags="-s -w -X \"main.version=$(VERSION)\" -extldflags \"-static\"" $(TARGET): $(SRCS)

    CGO_ENABLED=0 GOOS=linux go build -a -tags netgo -installsuffix netgo $(LDFLAGS) -o $(NAME) Go 1.4Ҏ߱͸σϑΥϧτͰͷϏϧυ࣌ʹɺ netύοέʔδ͕dynamic linkԽʂ ὎static linkԽͰෳ਺؀ڥͰಈ͘ΞϓϦʹ͠Α͏ɻ ὎MakefileͰ؅ཧ͕΍͸Γศརɻ ὎ϥΠϒϥϦଆͰ࢖ͬͯΔ࣌͸LDϑϥά΋ཱͯ·͠ΐ͏ˑ ζ*’Ϫ')ζ Makefile https://www.analyticsvidhya.com/blog/2017/11/reproducible-data-science-docker-for-data-science/
  10. Կ͔͠ΒͷΠϯλʔϑΣΠε Network Library Hard Ware Docker Engine ࣮ߦΠϝʔδͷখܕԽ=ϙʔλϏϦςΟ APIΛίʔυͰૢ࡞=ػೳ΍௨৴Λॎʹ੍ݶ ίϯςφʹΑΔΠϝʔδ؅ཧ

    =֤ػೳͷΠϛϡʔλϒϧԽ MSBʹΑΔ։ൃͱ࣮ߦ؀ڥͷ෼཭ =αʔϏεͷϚΠΫϩԽʹΑΓɺ ΦϖϨʔγϣϯϛεͷݮগ API(ૢ࡞͍ͨ͠ػೳ͚ͩίʔσΟϯά) Go Runtime Grpc Server
  11. func bgpdServer() { s := gobgp.NewBgpServer() go s.Serve() g :=

    api.NewGrpcServer(s, ":50051") go g.Serve() global := &config.Global{ Config: config.GlobalConfig{ As: 65000, RouterId: 10.0.0.1, Port: -1, // gobgp won't listen on tcp:179 }, } if err := s.Start(global); err != nil { log.Fatal(err) } //gobgpdαʔϏεΛΰϧʔνϯͰىಈɻ //grpcαʔϏεΛgobgpdαʔϏεʹ ϑοΫͤͨ͞ঢ়ଶͰΰϧʔνϯͰىಈʢΦϓγϣϯʣɻ ͜ΕͰ࣮͸gobgpίϚϯυ͕ซ༻Ͱ͖Δɻ //gobgpdͷάϩʔόϧίϯϑΟάΛઃఆɻ Ͳͷ৔߹΋ɺlocal-asͱrouter-idͱbgpͷϙʔτ͘Β͍͠ ͔ઃఆ͠ͳ͍ͱ͜ΖͩͱࢥΘΕ·͢ɻ https://gist.github.com/nnao45/942c4e9465387f5fda9227da00495e86
  12. n := &config.Neighbor{ Config: config.NeighborConfig{ NeighborAddress: 10.0.0.2, PeerAs: 65000, PeerType:

    config.PEER_TYPE_INTERNAL, }, EbgpMultihop: config.EbgpMultihop{ Config: config.EbgpMultihopConfig{ Enabled: true, MultihopTtl: 255, }, }, AfiSafis: []config.AfiSafi{ { Config: config.AfiSafiConfig{ AfiSafiName: "ipv4-unicast", Enabled: true, }, }, ApplyPolicy: config.ApplyPolicy{ Config: config.ApplyPolicyConfig{ ImportPolicyList: []string{"pd1"}, DefaultImportPolicy: config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE, }, }, } if err := s.AddNeighbor(n); err != nil { log.Error(err) } } //gobgpdͷωΠόʔίϯϑΟάΛઃఆɻ ΠϝʔδΛҎԼʹॻ͍ͯΈͨɻ Config.Neghborܕ NeighborConfigܕ EbgpMultihopܕ AfiSafiܕ AfiSafiConfigܕ ApplyPolicyܕ AfiPolicyConfigܕ
  13. AddPath() Client DeletePath() GetRib() GetNeighbor() timeout := grpc.WithTimeout(time.Second) conn, rpcErr

    := grpc.Dial("localhost:50051", timeout, grpc.WithBlock(), grpc.WithInsecure()) if rpcErr != nil { log.Fatal("GoBGP is probably not running on the local server ... Please start gobgpd process !\n") log.Fatal(rpcErr) return } client := api.NewGobgpApiClient(conn) //࠶ͼgRPCɻ ͜͜ͷίʔυ͸gobgpͷ֤APIΛͨͨ͘ҝʹɺ gRPCΫϥΠΞϯτΛ৽͘͠ఆ͓͖ٛͯ͠·͢ɻ gRPCͷ֤ଐੑΛ٧ΊࠐΜͩม਺clientΛ࢖͍·Θ͠·͢ɻ TCPͳͷͰGC͸ߟྀͯ͠λΠϜΞ΢τ΋ඞਢͰ͢ɻ
  14. args := []string{"10.45.0.0/24"} path, err := cmd.ParsePath(bgp.RF_IPv4_UC, args) if err

    != nil { fmt.Println(err) os.Exit(1) } for _, p := range []*table.Path{path} { arg := &api.AddPathRequest{ Resource: api.Resource_GLOBAL, VrfId: "", Path: api.ToPathApi(p), } r, err := client.AddPath(context.Background(), arg) if err != nil { fmt.Println(err) os.Exit(1) } var b []byte var u uuid.UUID b = r.Uuid u, err = uuid.FromBytes(b) if err != nil { fmt.Println(err) os.Exit(1) } fmt.Println("Added a route's UUID is, ", u.String()) } CLI string CLI PARSE API //CLIΛύʔε͢ΔAPIΛܦ༝ͨ͠ޙɺ ಘͨPathܕͷม਺ΛgRPCʹแΜͰɺ GoBGPଆʹ౉͢Πϝʔδ //CLIΛύʔε͢ΔAPIΛܦ༝͠ͳ͍ͱܕͱ͔໘౗ gobgpd service grpc service gobgp ops API //ࠨ͸AddPathؔ਺ʹಥͬࠐΜ͍Δɻ VRFͷࢦఆͳΜ͔΋͜͜Ͱ΍Δɻ //ͪͳΈʹGoBGP͸ܦ࿏ͷ؅ཧΛUUIDͰ΍ΕΔɻ (DeletePath()͸UUIDࢦఆ͚ͩͰ̤̠)
  15. r, err := client.GetRib(context.Background(), &api.GetRibRequest{ Table: &api.Table{ Type: api.Resource_GLOBAL, Family:

    uint32(bgp.RF_IPv4_UC), Name: "", }, } if err != nil { fmt.Println(err) os.Exit(1) } t, err := r.Table.ToNativeTable() if err != nil { fmt.Println(err) os.Exit(1) } for _, d := range t.GetSortedDestinations() { var ps []*table.Path ps = d.GetAllKnownPathList() for _, s := range ps { fmt.Println("Show a route's UUID is, ",s.UUID().String()) } } //ࠨ͸GetRibؔ਺ʹಥͬࠐΜ͍Δɻ //CࣾͰݴ͑͹ʮshow ip routeʯͬͯॴ //͜ͷCode͡Ό͋·Γҙຯ͸ແ͍͕ɺ ѼઌͰιʔτͯ͘͠ΕΔؔ਺Λୟ͘ྫɻ //͜͜Ͱಘͨܦ࿏ͷUUIDͱAddPathؔ਺ͰಘͨUUID Λಥ͖߹Θͤ͹ਖ਼ৗʹಈ࡞͍ͯ͠ΔࣄΛ֬ೝͰ͖Δɻ for { //ී௨͸ɺίϯϑΟάͱgRPCΫϥΠΞϯτͷ४උ͕ग़དྷͨΒޙ͸forͷແݶϧʔϓͰೖྗΛ଴ͪड͚ΔɻGoͩͱɺνϟϯωϧͰଞ ͷgoroutine͔Β৘ใΛड͚औΕ͹͍͍ͱࢥ͏ɻ }
  16. ✓ ϧʔςΟϯάςʔϒϧΛͲ͏͢Δͷ͔ߟ͓͑ͯ͘ɻ ➡ ϝϞϦ্Ͱ͋Δ͚ͩͳͷͰɺ࠶ىಈͰফ͑·͢ʢ)8ͱಉ͡ʣɻ ➡ ΋͠ܦ࿏ΛӬٱอ؅͢Δඞཁ͕͋ͬͨ৔߹͸ɺผ్%#Ͱอ؅͢ΔίʔυΛॻ͖·͠ΐ͏ɻ ✓ ΞυϨεͱ͔ͷίϯϑΟάϨʔγϣϯΛNBJO ౳ʹϋʔυίʔυ͸ྲྀੴʹɾɾɾɻ ➡

    UPNM IUUQTHJUIVCDPN#VSOU4VTIJUPNM ͱ͔࢖ͬͯϓϨʔϯςΩετ͔ΒಡΈग़ͦ͏ɻ ✓ σόοΫΛߟ͍͑ͯ͘ ➡ ̣̬ΤϯδχΞతʹ͸ϧʔςΟϯάςʔϒϧͱϩάͩΖ͏͕ɺʮ(Pݴޠʯͱͯ͠ͷσόοΫ΋ඞਢɻ ➡ ΍ΔͳΒɺ಺෦ެ։"1*ͱͯ͠SVOUJNF3FBE.FN4UBUT ͷ֤छϞδϡʔϧͱSVOUJNF/VN(PSPVUJOF ͸෷͍ग़͠ ͓͍ͯͯάϥϑͰ΋ॻ͚͹Α͍ɻ ✓ '*#ʹ൓өͱ͔ͦ͏͍͏̙ϓϨʔϯपΓ͸ଞͷιϑτ΢ΣΞͱ࿈ܞͤ͞ͳ͍ͱμϝͰ͢ɻ ➡ ࠓճͷΑ͏ͳ࢖͍ํͰ͸$ϓϨʔϯ୯ಠͷίϯτϩʔϥతͳ࢖͍ํ͕޲͍͍ͯΔؾ͕͠·͢ɻ