本文整理汇总了Golang中github.com/att/tegu/gizmos.Host.To_json方法的典型用法代码示例。如果您正苦于以下问题:Golang Host.To_json方法的具体用法?Golang Host.To_json怎么用?Golang Host.To_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/att/tegu/gizmos.Host
的用法示例。
在下文中一共展示了Host.To_json方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: find_paths
//.........这里部分代码省略.........
if plidx >= len(path_list) {
net_sheep.Baa(0, "CRI: find-path: internal error -- path size > num of links. [TGUNET006]")
return
}
ssw, _ = h1.Get_switch_port(swidx) // get next switch that lists h1 as attached; we'll work 'out' from it toward h2
if ssw == nil { // no more source switches which h1 thinks it's attached to
pcount = plidx
if pcount <= 0 || swidx == 0 {
net_sheep.Baa(1, "find-path: early exit? no switch/port returned for h1 (%s) at index %d captrip=%v", *h1nm, swidx, lcap_trip)
}
path_list = path_list[0:pcount] // slice it down to size
cap_trip = lcap_trip // set with overall state
return
}
fence := n.get_fence(usr)
if ssw.Has_host(h1nm) && ssw.Has_host(h2nm) { // if both hosts are on the same switch, there's no path if they both have the same port (both external to our view)
p1 := h1.Get_port(ssw)
p2 := h2.Get_port(ssw)
if p1 < 0 || p1 != p2 { // when ports differ we'll create/find the vlink between them (in Tegu-lite port == -128 is legit and will dup)
m1 := h1.Get_mac()
m2 := h2.Get_mac()
lnk = n.find_vlink(*(ssw.Get_id()), p1, p2, m1, m2)
has_room := true // always room if relaxed mode, so start this way
if n.relaxed {
has_room = ssw.Has_capacity_out(commence, conclude, inc_cap, fence.Name, fence.Get_limit_max()) // ensure cap on all outbound links from switch
}
if has_room { // room for the reservation
lnk.Add_lbp(*h1nm)
net_sheep.Baa(1, "path[%d]: found target on same switch, different ports: %s %d, %d", plidx, ssw.To_str(), h1.Get_port(ssw), h2.Get_port(ssw))
path = gizmos.Mk_path(h1, h2) // empty path
path.Set_bandwidth(inc_cap)
path.Set_extip(extip, ext_flag)
path.Add_switch(ssw)
path.Add_link(lnk)
path_list[plidx] = path
plidx++
} else {
lcap_trip = true
net_sheep.Baa(1, "path[%d]: hosts on same switch, virtual link cannot support bandwidth increase of %d", plidx, inc_cap)
}
} else { // debugging only
net_sheep.Baa(2, "find-path: path[%d]: found target (%s) on same switch with same port: %s %d, %d", plidx, *h2nm, ssw.To_str(), p1, p2)
net_sheep.Baa(2, "find-path: host1-json= %s", h1.To_json())
net_sheep.Baa(2, "find-path: host2-json= %s", h2.To_json())
}
} else { // usual case, two named hosts and hosts are on different switches
net_sheep.Baa(1, "path[%d]: searching for path starting from switch: %s", plidx, ssw.To_str())
for sname := range n.switches { // initialise the network for the walk
n.switches[sname].Cost = 2147483647 // this should be large enough and allows cost to be int32
n.switches[sname].Prev = nil
n.switches[sname].Flags &= ^tegu.SWFL_VISITED
}
if n.relaxed {
if !ssw.Has_capacity_out(commence, conclude, inc_cap, fence.Name, fence.Get_limit_max()) { // we do enforce capacity on ingress switch
err = fmt.Errorf("ingress switch cannot support additional bandwidth (%d) or user max reached (%d)", inc_cap, fence.Get_limit_max())
net_sheep.Baa(1, "%s", err)
lcap_trip = true
} else {
dsw, _ := h2.Get_switch_port(swidx) // need the switch associated with the second host (dest switch)
path, err = n.find_relaxed_path(ssw, h1, dsw, h2)
}
if err != nil {
net_sheep.Baa(1, "find_paths: find_relaxed failed: %s", err)
}
} else {
if find_all { // find all possible paths not just shortest
path, err = n.find_all_paths(ssw, h1, h2, usr, commence, conclude, inc_cap, fence.Get_limit_max()) // find a 'scramble' path
if err != nil {
net_sheep.Baa(1, "find_paths: find_all failed: %s", err)
}
} else {
path, cap_trip = n.find_shortest_path(ssw, h1, h2, usr, commence, conclude, inc_cap, fence.Get_limit_max())
if cap_trip {
lcap_trip = true
}
}
}
if path != nil {
path.Set_extip(extip, ext_flag)
path_list[plidx] = path
plidx++
}
}
swidx++
}
pcount = plidx // shouldn't get here, but safety first
cap_trip = lcap_trip
return
}