本文整理汇总了Golang中github.com/osrg/gobgp/table.Path.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Path.String方法的具体用法?Golang Path.String怎么用?Golang Path.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/osrg/gobgp/table.Path
的用法示例。
在下文中一共展示了Path.String方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: modRib
//modrib receives route updates from BGP server and adds the endpoint
func (self *OfnetBgp) modRib(path *table.Path) error {
var nlri bgp.AddrPrefixInterface
var nextHop string
var macAddrStr string
var portNo uint32
nlri = path.GetNlri()
nextHop = path.GetNexthop().String()
if nextHop == "0.0.0.0" {
return nil
}
if nlri == nil {
return fmt.Errorf("no nlri")
}
endpointIPNet, _ := netlink.ParseIPNet(nlri.String())
log.Infof("Bgp Rib Received endpoint update for path %s", path.String())
//check if bgp published a route local to the host
epid := self.agent.getEndpointIdByIpVrf(endpointIPNet.IP.Mask(endpointIPNet.Mask), "default")
//Check if the route is local
if nextHop == self.routerIP {
log.Debugf("This is a local route skipping endpoint create! ")
return nil
} else if ep := self.agent.getEndpointByID(epid); ep != nil {
if ep.EndpointType != "external" {
log.Debugf("Endpoint was learnt via internal protocol. skipping update! ")
return nil
}
}
nhEpid := self.agent.getEndpointIdByIpVrf(net.ParseIP(nextHop), "default")
if ep := self.agent.getEndpointByID(nhEpid); ep == nil {
//the nexthop is not the directly connected eBgp peer
macAddrStr = ""
portNo = 0
} else {
macAddrStr = ep.MacAddrStr
portNo = ep.PortNo
}
ipmask := net.ParseIP("255.255.255.255").Mask(endpointIPNet.Mask)
if path.IsWithdraw != true {
epreg := &OfnetEndpoint{
EndpointID: epid,
EndpointType: "external",
IpAddr: endpointIPNet.IP,
IpMask: ipmask,
Vrf: "default", // FIXME set VRF correctly
MacAddrStr: macAddrStr,
Vlan: 1,
OriginatorIp: self.agent.localIp,
PortNo: portNo,
Timestamp: time.Now(),
}
// Install the endpoint in datapath
// First, add the endpoint to local routing table
self.agent.endpointDb.Set(epreg.EndpointID, epreg)
err := self.agent.datapath.AddEndpoint(epreg)
if err != nil {
log.Errorf("Error adding endpoint: {%+v}. Err: %v", epreg, err)
return err
}
} else {
log.Info("Received route withdraw from BGP for ", endpointIPNet)
endpoint := self.agent.getEndpointByIpVrf(endpointIPNet.IP, "default")
if endpoint != nil {
self.agent.datapath.RemoveEndpoint(endpoint)
self.agent.endpointDb.Remove(endpoint.EndpointID)
}
}
return nil
}