本文整理汇总了Golang中github.com/araobp/nlan/agent/context.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: addVpls
func addVpls(sVid string, sVni string, ip string, brInt string, con *context.Context) {
cmd, cmdp := con.GetCmd()
intBr := "int_br" + sVni
cmdp("ovs-vsctl", "add-port", brInt, intBr, "tag="+sVid, "--", "set", "interface", intBr, "type=internal")
cmd("ip", "link", "set", "dev", intBr, "up")
cmd("ip", "addr", "add", "dev", intBr, ip)
}
开发者ID:araobp,项目名称:nlan,代码行数:7,代码来源:l2vpn.go
示例2: AddNodes
func AddNodes(nodes *nlan.Nodes, con *context.Context) (string, string) {
cmd, cmdp := con.GetCmd()
brTun := nodes.Ptn
brInt := nodes.L2Sw
patchTun := "patch-tun_" + brTun
patchInt := "patch-int_" + brInt
log.Printf("Adding bridges: %s and %s\n", brTun, brInt)
// Adds br-int and br-tun and connects them to each other
cmdp("ovs-vsctl", "add-br", brInt)
cmdp("ovs-vsctl", "add-br", brTun)
cmd("ovs-ofctl", "del-flows", brTun)
cmdp("ovs-vsctl", "add-port", brInt, patchInt, "--", "set", "interface", patchInt, "type=patch", "options:peer="+patchTun)
cmdp("ovs-vsctl", "add-port", brTun, patchTun, "--", "set", "interface", patchTun, "type=patch", "options:peer="+patchInt)
cmdp("ovs-vsctl", "set-fail-mode", brTun, "secure")
// Obtains ofport for 'patch-tun' port
patchTunNum := strconv.Itoa(util.GetOfport(patchTun))
log.Printf("patchTunNum(ofport): %s\n", patchTunNum)
// Adds flow entries onto br-tun
cmd("ovs-ofctl", "add-flow", brTun, "table=0,priority=1,in_port="+patchTunNum+",actions=resubmit(,1)")
cmd("ovs-ofctl", "add-flow", brTun, "table=0,priority=0,actions=drop")
cmd("ovs-ofctl", "add-flow", brTun, "table=1,priority=0,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00,actions=resubmit(,19)")
cmd("ovs-ofctl", "add-flow", brTun, "table=1,priority=0,dl_dst=00:00:00:00:00:00/01:00:00:00:00:00,actions=resubmit(,20)")
cmd("ovs-ofctl", "add-flow", brTun, "table=2,priority=0,actions=drop")
cmd("ovs-ofctl", "add-flow", brTun, "table=3,priority=0,actions=drop")
cmd("ovs-ofctl", "add-flow", brTun, "table=10,priority=1,actions=learn(table=20,hard_timeout=300,priority=1,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:0->NXM_OF_VLAN_TCI[],load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[],output:NXM_OF_IN_PORT[]),output:"+patchTunNum)
cmd("ovs-ofctl", "add-flow", brTun, "table=19,priority=0,actions=resubmit(,21)")
cmd("ovs-ofctl", "add-flow", brTun, "table=20,priority=0,actions=resubmit(,21)")
cmd("ovs-ofctl", "add-flow", brTun, "table=21,priority=0,actions=drop")
return brTun, brInt
}
开发者ID:araobp,项目名称:nlan,代码行数:30,代码来源:nodes.go
示例3: addVhosts
func addVhosts(addr ipAddress, vhosts uint32, con *context.Context) {
cmd, _ := con.GetCmd()
br := "br_" + addr.abcd
br_ip := addr.abcd
cmd("brctl", "addbr", br)
cmd("ip", "addr", "add", "dev", br, addr.network)
cmd("ip", "link", "set", "dev", br, "up")
for i := 1; i <= int(vhosts); i++ {
d, _ := strconv.Atoi(addr.d)
id := strconv.Itoa(d + i)
ip := addr.abc + "." + id
ns := ip
cmd("ip", "netns", "add", ns)
cmd("ip", "link", "add", ns, "type", "veth", "peer", "name", "temp")
cmd("ip", "link", "set", "dev", "temp", "netns", ns)
cmd("ip", "netns", "exec", ns, "ip", "link", "set", "dev", "temp", "name", "eth0")
cmd("brctl", "addif", br, ns)
cmd("ip", "link", "set", "dev", ns, "promisc", "on")
cmd("ip", "link", "set", "dev", ns, "up")
cmd("ip", "netns", "exec", ns, "ip", "link", "set", "dev", "eth0", "up")
cmd("ip", "netns", "exec", ns, "ip", "addr", "add", "dev", "eth0", ip+"/"+addr.mask)
cmd("ip", "netns", "exec", ns, "ip", "route", "add", "default", "via", br_ip, "dev", "eth0")
}
}
开发者ID:araobp,项目名称:nlan,代码行数:25,代码来源:vhosts.go
示例4: Crud
func Crud(crud int, in map[string]*nlan.Interface, con *context.Context) {
// TODO: CRUD operatoins
cmd, _ := con.GetCmd()
for dev, params := range in { // map key is not used.
log.Println(dev)
cmd("ip", "tunnel", "add", dev, "mode", params.Mode, "local", params.Local, "remote", params.Remote)
cmd("ip", "addr", "add", params.Address, "dev", dev)
cmd("ip", "link", "set", "dev", dev, "up")
}
}
开发者ID:araobp,项目名称:nlan,代码行数:10,代码来源:interfaces.go
示例5: addRouter
func addRouter(loopback string, embedded bool, s *gobgp.BgpServer, ospf []*nlan.Ospf, bgp map[string]*nlan.Attrs, con *context.Context) {
cmd, cmdp := con.GetCmd()
// Loopback address
cmd("ip", "addr", "add", "dev", "lo", loopback)
// Allow receiving packets from non-best-path interfaces
cmd("sysctl", "-w", "net.ipv4.conf.all.rp_filter=2")
// Allow routing packets with local addresses
cmd("sysctl", "-w", "net.ipv4.conf.all.accept_local=1")
var script [][]string
if ospf != nil {
script = append(script, []string{"router", "ospf"})
script = append(script, []string{"redistribute", "connected"})
for _, o := range ospf {
area := o.Area
networks := o.Networks
log.Print("OSPF Networks: %v", networks)
routerOspfNetworks(&script, area, networks)
}
script = append(script, []string{"exit"})
}
if bgp != nil {
for as, neighs := range bgp {
if embedded {
routerId := strings.Split(loopback, "/")[0]
asInt, _ := strconv.ParseInt(as, 10, 64)
gobgpReqModGlobalConfig(s, routerId, asInt, con)
} else {
script = append(script, []string{"router", "bgp", as})
script = append(script, []string{"redistribute", "connected"})
}
if neighs != nil {
if embedded {
gobgpReqModNeighbor(s, neighs, con)
} else {
routerBgpNeighbors(&script, neighs)
}
}
}
script = append(script, []string{"exit"})
}
if len(script) > 0 && !embedded {
batch := util.VtyshBatch(script)
cmdp("vtysh", batch...)
}
}
开发者ID:araobp,项目名称:nlan,代码行数:49,代码来源:router.go
示例6: addFlowEntries
func addFlowEntries(sVid string, sVni string, peers *[]string, brTun string, con *context.Context) {
cmd, _ := con.GetCmd()
_ = "int_br" + sVni
cmd("ovs-ofctl", "add-flow", brTun, "table=2,priority=1,tun_id="+sVni+",actions=mod_vlan_vid:"+sVid+",resubmit(,10)")
// Broadcast tree for each vni
l := util.GetVxlanPorts(peers)
var buff bytes.Buffer
for e := l.Front(); e != nil; e = e.Next() {
v := e.Value
outPort := strconv.Itoa(v.(int))
buff.Write([]byte(",output:"))
buff.Write([]byte(outPort))
}
outputPorts := buff.String()
cmd("ovs-ofctl", "add-flow", brTun, "table=21,priority=1,dl_vlan="+sVid+",actions=strip_vlan,set_tunnel:"+sVni+outputPorts)
}
开发者ID:araobp,项目名称:nlan,代码行数:16,代码来源:l2vpn.go
示例7: Crud
func Crud(crud int, in *nlan.Router, con *context.Context) {
loopback := in.Loopback
embedded := in.EmbeddedBgp // quagga-bgpd(false) or gobgp(true)
ospf := in.GetOspf()
bgp := in.GetBgp()
cmd, _ := con.GetCmd()
log.Print("Router called...")
var s *gobgp.BgpServer
var g *gobgp.Server
if embedded {
cmd("/etc/init.d/quagga", "stop")
s = gobgp.NewBgpServer()
go s.Serve()
g = gobgp.NewGrpcServer(50051, s.GrpcReqCh)
go g.Serve()
}
var crudRouter func(string, bool, *gobgp.BgpServer, []*nlan.Ospf, map[string]*nlan.Attrs, *context.Context)
switch crud {
case env.ADD:
crudRouter = addRouter
case env.UPDATE:
crudRouter = updateRouter
case env.DELETE:
crudRouter = deleteRouter
default:
log.Fatal("CRUD unidentified")
}
log.Printf("Loopback: %s", loopback)
crudRouter(loopback, embedded, s, ospf, bgp, con)
log.Print("crudRouter() completed")
}
开发者ID:araobp,项目名称:nlan,代码行数:36,代码来源:router.go
注:本文中的github.com/araobp/nlan/agent/context.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论