本文整理汇总了Golang中github.com/osrg/gobgp/packet/bgp.NewPathAttributeNextHop函数的典型用法代码示例。如果您正苦于以下问题:Golang NewPathAttributeNextHop函数的具体用法?Golang NewPathAttributeNextHop怎么用?Golang NewPathAttributeNextHop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewPathAttributeNextHop函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestMrtRib
func TestMrtRib(t *testing.T) {
aspath1 := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(2, []uint16{1000}),
bgp.NewAsPathParam(1, []uint16{1001, 1002}),
bgp.NewAsPathParam(2, []uint16{1003, 1004}),
}
p := []bgp.PathAttributeInterface{
bgp.NewPathAttributeOrigin(3),
bgp.NewPathAttributeAsPath(aspath1),
bgp.NewPathAttributeNextHop("129.1.1.2"),
bgp.NewPathAttributeMultiExitDisc(1 << 20),
bgp.NewPathAttributeLocalPref(1 << 22),
}
e1 := NewRibEntry(1, uint32(time.Now().Unix()), p)
e2 := NewRibEntry(2, uint32(time.Now().Unix()), p)
e3 := NewRibEntry(3, uint32(time.Now().Unix()), p)
r1 := NewRib(1, bgp.NewIPAddrPrefix(24, "192.168.0.0"), []*RibEntry{e1, e2, e3})
b1, err := r1.Serialize()
if err != nil {
t.Fatal(err)
}
r2 := &Rib{
RouteFamily: bgp.RF_IPv4_UC,
}
err = r2.DecodeFromBytes(b1)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, reflect.DeepEqual(r1, r2), true)
}
开发者ID:mfeed,项目名称:gobgp,代码行数:33,代码来源:mrt_test.go
示例2: ToLocal
func (p *Path) ToLocal() *Path {
nlri := p.GetNlri()
f := p.GetRouteFamily()
switch f {
case bgp.RF_IPv4_VPN:
n := nlri.(*bgp.LabeledVPNIPAddrPrefix)
_, c, _ := net.ParseCIDR(n.IPPrefix())
ones, _ := c.Mask.Size()
nlri = bgp.NewIPAddrPrefix(uint8(ones), c.IP.String())
case bgp.RF_IPv6_VPN:
n := nlri.(*bgp.LabeledVPNIPv6AddrPrefix)
_, c, _ := net.ParseCIDR(n.IPPrefix())
ones, _ := c.Mask.Size()
nlri = bgp.NewIPAddrPrefix(uint8(ones), c.IP.String())
default:
return p
}
path := NewPath(p.OriginInfo().source, nlri, p.IsWithdraw, p.GetPathAttrs(), p.OriginInfo().timestamp, false)
path.delPathAttr(bgp.BGP_ATTR_TYPE_EXTENDED_COMMUNITIES)
if f == bgp.RF_IPv4_VPN {
nh := path.GetNexthop()
path.delPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
path.setPathAttr(bgp.NewPathAttributeNextHop(nh.String()))
}
return path
}
开发者ID:osrg,项目名称:gobgp,代码行数:26,代码来源:path.go
示例3: TestMrtRibEntry
func TestMrtRibEntry(t *testing.T) {
aspath1 := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(2, []uint16{1000}),
bgp.NewAsPathParam(1, []uint16{1001, 1002}),
bgp.NewAsPathParam(2, []uint16{1003, 1004}),
}
p := []bgp.PathAttributeInterface{
bgp.NewPathAttributeOrigin(3),
bgp.NewPathAttributeAsPath(aspath1),
bgp.NewPathAttributeNextHop("129.1.1.2"),
bgp.NewPathAttributeMultiExitDisc(1 << 20),
bgp.NewPathAttributeLocalPref(1 << 22),
}
e1 := NewRibEntry(1, uint32(time.Now().Unix()), p)
b1, err := e1.Serialize()
if err != nil {
t.Fatal(err)
}
e2 := &RibEntry{}
rest, err := e2.DecodeFromBytes(b1)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(rest), 0)
assert.Equal(t, reflect.DeepEqual(e1, e2), true)
}
开发者ID:mfeed,项目名称:gobgp,代码行数:29,代码来源:mrt_test.go
示例4: TestASPathLen
func TestASPathLen(t *testing.T) {
assert := assert.New(t)
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint16{65001, 65002, 65003, 65004, 65004, 65004, 65004, 65004, 65005}),
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002, 65003, 65004, 65005}),
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100, 65101, 65102}),
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100, 65101})}
aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("192.168.50.1")
med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{
origin,
aspath,
nexthop,
med,
}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
update := bgpmsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(update)
peer := PathCreatePeer()
p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(), false)
assert.Equal(10, p.GetAsPathLen())
}
开发者ID:mfeed,项目名称:gobgp,代码行数:27,代码来源:path_test.go
示例5: TestPathPrependAsnToExistingSeqAttr
func TestPathPrependAsnToExistingSeqAttr(t *testing.T) {
assert := assert.New(t)
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint16{65001, 65002, 65003, 65004, 65005}),
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, []uint16{65001, 65002, 65003, 65004, 65005}),
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ, []uint16{65100, 65101, 65102}),
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, []uint16{65100, 65101})}
aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("192.168.50.1")
pathAttributes := []bgp.PathAttributeInterface{
origin,
aspath,
nexthop,
}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
update := bgpmsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(update)
peer := PathCreatePeer()
p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(), false)
p.PrependAsn(65000, 1)
assert.Equal([]uint32{65000, 65001, 65002, 65003, 65004, 65005, 0, 0, 0}, p.GetAsSeqList())
fmt.Printf("asns: %v", p.GetAsSeqList())
}
开发者ID:mfeed,项目名称:gobgp,代码行数:28,代码来源:path_test.go
示例6: TestTimeTieBreaker
func TestTimeTieBreaker(t *testing.T) {
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(2, []uint32{65001})}
aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := bgp.NewIPAddrPrefix(24, "10.10.0.0")
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, []*bgp.IPAddrPrefix{nlri})
peer1 := &PeerInfo{AS: 2, LocalAS: 1, Address: net.IP{1, 1, 1, 1}, ID: net.IP{1, 1, 1, 1}}
path1 := ProcessMessage(updateMsg, peer1, time.Now())[0]
peer2 := &PeerInfo{AS: 2, LocalAS: 1, Address: net.IP{2, 2, 2, 2}, ID: net.IP{2, 2, 2, 2}} // weaker router-id
path2 := ProcessMessage(updateMsg, peer2, time.Now().Add(-1*time.Hour))[0] // older than path1
d := NewDestination(nlri)
d.AddNewPath(path1)
d.AddNewPath(path2)
d.Calculate(nil)
assert.Equal(t, len(d.knownPathList), 2)
assert.Equal(t, true, d.GetBestPath("").GetSource().ID.Equal(net.IP{2, 2, 2, 2})) // path from peer2 win
// this option disables tie breaking by age
SelectionOptions.ExternalCompareRouterId = true
d = NewDestination(nlri)
d.AddNewPath(path1)
d.AddNewPath(path2)
d.Calculate(nil)
assert.Equal(t, len(d.knownPathList), 2)
assert.Equal(t, true, d.GetBestPath("").GetSource().ID.Equal(net.IP{1, 1, 1, 1})) // path from peer1 win
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:35,代码来源:destination_test.go
示例7: AddLocalProtoRoute
//AddLocalProtoRoute is used to add local endpoint to the protocol RIB
func (self *OfnetBgp) AddLocalProtoRoute(pathInfo []*OfnetProtoRouteInfo) error {
if self.routerIP == "" {
//ignoring populating to the bgp rib because
//Bgp is not configured.
return nil
}
log.Infof("Received AddLocalProtoRoute to add local endpoint to protocol RIB: %+v", pathInfo)
// add routes
attrs := []bgp.PathAttributeInterface{
bgp.NewPathAttributeOrigin(1),
bgp.NewPathAttributeNextHop(pathInfo[0].nextHopIP),
bgp.NewPathAttributeAsPath([]bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint32{self.myBgpAs})}),
}
paths := []*table.Path{}
for _, path := range pathInfo {
paths = append(paths, table.NewPath(nil, bgp.NewIPAddrPrefix(32, path.localEpIP), false, attrs, time.Now(), false))
}
_, err := self.bgpServer.AddPath("", paths)
if err != nil {
return err
}
return nil
}
开发者ID:jojimt,项目名称:netplugin,代码行数:28,代码来源:ofnetBgp.go
示例8: TestGetPathAttrs
func TestGetPathAttrs(t *testing.T) {
paths := PathCreatePath(PathCreatePeer())
path0 := paths[0]
path1 := path0.Clone(false)
path1.delPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
path2 := path1.Clone(false)
path2.setPathAttr(bgp.NewPathAttributeNextHop("192.168.50.1"))
assert.NotNil(t, path2.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP))
}
开发者ID:mfeed,项目名称:gobgp,代码行数:9,代码来源:path_test.go
示例9: TestImplicitWithdrawCalculate
func TestImplicitWithdrawCalculate(t *testing.T) {
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(2, []uint32{65001})}
aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := bgp.NewIPAddrPrefix(24, "10.10.0.101")
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, []*bgp.IPAddrPrefix{nlri})
peer1 := &PeerInfo{AS: 1, Address: net.IP{1, 1, 1, 1}}
path1 := ProcessMessage(updateMsg, peer1, time.Now())[0]
path1.Filter("1", POLICY_DIRECTION_IMPORT)
// suppose peer2 has import policy to prepend as-path
action := &AsPathPrependAction{
asn: 100,
repeat: 1,
}
path2 := action.Apply(path1.Clone(false), nil)
path1.Filter("2", POLICY_DIRECTION_IMPORT)
path2.Filter("1", POLICY_DIRECTION_IMPORT)
path2.Filter("3", POLICY_DIRECTION_IMPORT)
d := NewDestination(nlri)
d.AddNewPath(path1)
d.AddNewPath(path2)
d.Calculate(nil)
assert.Equal(t, len(d.GetKnownPathList("1")), 0) // peer "1" is the originator
assert.Equal(t, len(d.GetKnownPathList("2")), 1)
assert.Equal(t, d.GetKnownPathList("2")[0].GetAsString(), "100 65001") // peer "2" has modified path {100, 65001}
assert.Equal(t, len(d.GetKnownPathList("3")), 1)
assert.Equal(t, d.GetKnownPathList("3")[0].GetAsString(), "65001") // peer "3" has original path {65001}
assert.Equal(t, len(d.knownPathList), 2)
// say, we removed peer2's import policy and
// peer1 advertised new path with the same prefix
aspathParam = []bgp.AsPathParamInterface{bgp.NewAs4PathParam(2, []uint32{65001, 65002})}
aspath = bgp.NewPathAttributeAsPath(aspathParam)
pathAttributes = []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
updateMsg = bgp.NewBGPUpdateMessage(nil, pathAttributes, []*bgp.IPAddrPrefix{nlri})
path3 := ProcessMessage(updateMsg, peer1, time.Now())[0]
path3.Filter("1", POLICY_DIRECTION_IMPORT)
d.AddNewPath(path3)
d.Calculate(nil)
assert.Equal(t, len(d.GetKnownPathList("1")), 0) // peer "1" is the originator
assert.Equal(t, len(d.GetKnownPathList("2")), 1)
assert.Equal(t, d.GetKnownPathList("2")[0].GetAsString(), "65001 65002") // peer "2" has new original path {65001, 65002}
assert.Equal(t, len(d.GetKnownPathList("3")), 1)
assert.Equal(t, d.GetKnownPathList("3")[0].GetAsString(), "65001 65002") // peer "3" has new original path {65001, 65002}
assert.Equal(t, len(d.knownPathList), 1)
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:56,代码来源:destination_test.go
示例10: DelPath
func (bs *BgpService) DelPath(route string) error {
attrs := []bgp.PathAttributeInterface{
bgp.NewPathAttributeNextHop("0.0.0.0"),
}
if err := bs.bgp.DeletePath([]byte{}, bgp.RF_IPv4_UC, "", []*table.Path{table.NewPath(nil, bgp.NewIPAddrPrefix(32, route), true, attrs, time.Now(), false)}); err != nil {
return fmt.Errorf("[bgp] Error deleting bgp path. %v", err)
}
return nil
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:11,代码来源:bgp.go
示例11: createPathFromIPRouteMessage
func createPathFromIPRouteMessage(m *zebra.Message) *table.Path {
header := m.Header
body := m.Body.(*zebra.IPRouteBody)
family := bgp.RF_IPv6_UC
if header.Command == zebra.IPV4_ROUTE_ADD || header.Command == zebra.IPV4_ROUTE_DELETE {
family = bgp.RF_IPv4_UC
}
var nlri bgp.AddrPrefixInterface
pattr := make([]bgp.PathAttributeInterface, 0)
var mpnlri *bgp.PathAttributeMpReachNLRI
var isWithdraw bool = header.Command == zebra.IPV4_ROUTE_DELETE || header.Command == zebra.IPV6_ROUTE_DELETE
origin := bgp.NewPathAttributeOrigin(bgp.BGP_ORIGIN_ATTR_TYPE_IGP)
pattr = append(pattr, origin)
log.WithFields(log.Fields{
"Topic": "Zebra",
"RouteType": body.Type.String(),
"Flag": body.Flags.String(),
"Message": body.Message,
"Prefix": body.Prefix,
"PrefixLength": body.PrefixLength,
"Nexthop": body.Nexthops,
"IfIndex": body.Ifindexs,
"Metric": body.Metric,
"Distance": body.Distance,
"api": header.Command.String(),
}).Debugf("create path from ip route message.")
switch family {
case bgp.RF_IPv4_UC:
nlri = bgp.NewIPAddrPrefix(body.PrefixLength, body.Prefix.String())
nexthop := bgp.NewPathAttributeNextHop(body.Nexthops[0].String())
pattr = append(pattr, nexthop)
case bgp.RF_IPv6_UC:
nlri = bgp.NewIPv6AddrPrefix(body.PrefixLength, body.Prefix.String())
mpnlri = bgp.NewPathAttributeMpReachNLRI(body.Nexthops[0].String(), []bgp.AddrPrefixInterface{nlri})
pattr = append(pattr, mpnlri)
default:
log.WithFields(log.Fields{
"Topic": "Zebra",
}).Errorf("unsupport address family: %s", family)
return nil
}
med := bgp.NewPathAttributeMultiExitDisc(body.Metric)
pattr = append(pattr, med)
path := table.NewPath(nil, nlri, isWithdraw, pattr, time.Now(), false)
path.SetIsFromExternal(true)
return path
}
开发者ID:osrg,项目名称:gobgp,代码行数:54,代码来源:zclient.go
示例12: TestCalculate2
func TestCalculate2(t *testing.T) {
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(2, []uint32{65001})}
aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{origin, aspath, nexthop, med}
nlri := bgp.NewIPAddrPrefix(24, "10.10.0.0")
// peer1 sends normal update message 10.10.0.0/24
update1 := bgp.NewBGPUpdateMessage(nil, pathAttributes, []*bgp.IPAddrPrefix{nlri})
peer1 := &PeerInfo{AS: 1, Address: net.IP{1, 1, 1, 1}}
path1 := ProcessMessage(update1, peer1, time.Now())[0]
d := NewDestination(nlri)
d.AddNewPath(path1)
d.Calculate(nil)
// suppose peer2 sends grammaatically correct but semantically flawed update message
// which has a withdrawal nlri not advertised before
update2 := bgp.NewBGPUpdateMessage([]*bgp.IPAddrPrefix{nlri}, pathAttributes, nil)
peer2 := &PeerInfo{AS: 2, Address: net.IP{2, 2, 2, 2}}
path2 := ProcessMessage(update2, peer2, time.Now())[0]
assert.Equal(t, path2.IsWithdraw, true)
d.AddWithdraw(path2)
d.Calculate(nil)
// we have a path from peer1 here
assert.Equal(t, len(d.knownPathList), 1)
// after that, new update with the same nlri comes from peer2
update3 := bgp.NewBGPUpdateMessage(nil, pathAttributes, []*bgp.IPAddrPrefix{nlri})
path3 := ProcessMessage(update3, peer2, time.Now())[0]
assert.Equal(t, path3.IsWithdraw, false)
d.AddNewPath(path3)
d.Calculate(nil)
// this time, we have paths from peer1 and peer2
assert.Equal(t, len(d.knownPathList), 2)
// now peer3 sends normal update message 10.10.0.0/24
peer3 := &PeerInfo{AS: 3, Address: net.IP{3, 3, 3, 3}}
update4 := bgp.NewBGPUpdateMessage(nil, pathAttributes, []*bgp.IPAddrPrefix{nlri})
path4 := ProcessMessage(update4, peer3, time.Now())[0]
d.AddNewPath(path4)
d.Calculate(nil)
// we must have paths from peer1, peer2 and peer3
assert.Equal(t, len(d.knownPathList), 3)
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:54,代码来源:destination_test.go
示例13: SetNexthop
func (path *Path) SetNexthop(nexthop net.IP) {
attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
if attr != nil {
path.setPathAttr(bgp.NewPathAttributeNextHop(nexthop.String()))
}
attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
if attr != nil {
oldNlri := attr.(*bgp.PathAttributeMpReachNLRI)
path.setPathAttr(bgp.NewPathAttributeMpReachNLRI(nexthop.String(), oldNlri.Value))
}
}
开发者ID:mfeed,项目名称:gobgp,代码行数:11,代码来源:path.go
示例14: AddPath
func (bs *BgpService) AddPath(route string) error {
attrs := []bgp.PathAttributeInterface{
bgp.NewPathAttributeOrigin(0),
bgp.NewPathAttributeNextHop("0.0.0.0"),
}
if _, err := bs.bgp.AddPath("", []*table.Path{table.NewPath(nil, bgp.NewIPAddrPrefix(32, route), false, attrs, time.Now(), false)}); err != nil {
return fmt.Errorf("[bgp] Error adding bgp path. %v", err)
}
return nil
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:12,代码来源:bgp.go
示例15: createPathFromIPRouteMessage
func createPathFromIPRouteMessage(m *zebra.Message, peerInfo *table.PeerInfo) *table.Path {
header := m.Header
body := m.Body.(*zebra.IPRouteBody)
isV4 := header.Command == zebra.IPV4_ROUTE_ADD || header.Command == zebra.IPV4_ROUTE_DELETE
var nlri bgp.AddrPrefixInterface
pattr := make([]bgp.PathAttributeInterface, 0)
var mpnlri *bgp.PathAttributeMpReachNLRI
var isWithdraw bool = header.Command == zebra.IPV4_ROUTE_DELETE || header.Command == zebra.IPV6_ROUTE_DELETE
origin := bgp.NewPathAttributeOrigin(bgp.BGP_ORIGIN_ATTR_TYPE_IGP)
pattr = append(pattr, origin)
log.WithFields(log.Fields{
"Topic": "Zebra",
"RouteType": body.Type.String(),
"Flag": body.Flags.String(),
"Message": body.Message,
"Prefix": body.Prefix,
"PrefixLength": body.PrefixLength,
"Nexthop": body.Nexthops,
"IfIndex": body.Ifindexs,
"Metric": body.Metric,
"Distance": body.Distance,
"api": header.Command.String(),
}).Debugf("create path from ip route message.")
if isV4 {
nlri = bgp.NewIPAddrPrefix(body.PrefixLength, body.Prefix.String())
nexthop := bgp.NewPathAttributeNextHop(body.Nexthops[0].String())
pattr = append(pattr, nexthop)
} else {
nlri = bgp.NewIPv6AddrPrefix(body.PrefixLength, body.Prefix.String())
mpnlri = bgp.NewPathAttributeMpReachNLRI(body.Nexthops[0].String(), []bgp.AddrPrefixInterface{nlri})
pattr = append(pattr, mpnlri)
}
med := bgp.NewPathAttributeMultiExitDisc(body.Metric)
pattr = append(pattr, med)
p := table.NewPath(peerInfo, nlri, isWithdraw, pattr, time.Now(), false)
p.SetIsFromExternal(true)
return p
}
开发者ID:mfeed,项目名称:gobgp,代码行数:45,代码来源:zclient.go
示例16: updateMsgP2
func updateMsgP2() *bgp.BGPMessage {
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65100})}
aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("192.168.100.1")
med := bgp.NewPathAttributeMultiExitDisc(100)
pathAttributes := []bgp.PathAttributeInterface{
origin,
aspath,
nexthop,
med,
}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "20.20.20.0")}
return bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
}
开发者ID:mfeed,项目名称:gobgp,代码行数:18,代码来源:path_test.go
示例17: DeleteLocalProtoRoute
//DeleteLocalProtoRoute withdraws local endpoints from protocol RIB
func (self *OfnetBgp) DeleteLocalProtoRoute(pathInfo []*OfnetProtoRouteInfo) error {
log.Infof("Received DeleteLocalProtoRoute to withdraw local endpoint to protocol RIB: %v", pathInfo)
attrs := []bgp.PathAttributeInterface{
bgp.NewPathAttributeOrigin(1),
bgp.NewPathAttributeNextHop(pathInfo[0].nextHopIP),
bgp.NewPathAttributeAsPath([]bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, []uint32{self.myBgpAs})}),
}
paths := []*table.Path{}
for _, path := range pathInfo {
paths = append(paths, table.NewPath(nil, bgp.NewIPAddrPrefix(32, path.localEpIP), true, attrs, time.Now(), false))
}
if err := self.bgpServer.DeletePath(nil, bgp.RF_IPv4_UC, "", paths); err != nil {
return err
}
return nil
}
开发者ID:jojimt,项目名称:netplugin,代码行数:20,代码来源:ofnetBgp.go
示例18: updateMsgD1
func updateMsgD1() *bgp.BGPMessage {
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65000})}
aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("192.168.50.1")
med := bgp.NewPathAttributeMultiExitDisc(0)
pathAttributes := []bgp.PathAttributeInterface{
origin,
aspath,
nexthop,
med,
}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
updateMsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
UpdatePathAttrs4ByteAs(updateMsg.Body.(*bgp.BGPUpdate))
return updateMsg
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:20,代码来源:destination_test.go
示例19: DeleteLocalProtoRoute
//DeleteLocalProtoRoute withdraws local endpoints from protocol RIB
func (self *OfnetBgp) DeleteLocalProtoRoute(pathInfo *OfnetProtoRouteInfo) error {
log.Infof("Received DeleteLocalProtoRoute to withdraw local endpoint to protocol RIB: %v", pathInfo)
path := &api.Path{
Pattrs: make([][]byte, 0),
}
//form appropraite path attributes for path to be withdrawn
nlri := bgp.NewIPAddrPrefix(32, pathInfo.localEpIP)
path.Nlri, _ = nlri.Serialize()
origin, _ := bgp.NewPathAttributeOrigin(bgp.BGP_ORIGIN_ATTR_TYPE_EGP).Serialize()
path.Pattrs = append(path.Pattrs, origin)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(2, []uint32{self.myBgpAs})}
aspath, _ := bgp.NewPathAttributeAsPath(aspathParam).Serialize()
path.Pattrs = append(path.Pattrs, aspath)
n, _ := bgp.NewPathAttributeNextHop(pathInfo.nextHopIP).Serialize()
path.Pattrs = append(path.Pattrs, n)
path.IsWithdraw = true
//paths := []*api.Path{path}
arg := &api.DeletePathRequest{
Resource: api.Resource_GLOBAL,
Path: path,
}
//send arguement stream
client := api.NewGobgpApiClient(self.cc)
if client == nil {
log.Errorf("Gobgpapi stream invalid")
return nil
}
_, err := client.DeletePath(context.Background(), arg)
if err != nil {
log.Errorf("Fail to enforce Modpathi: %v", err)
return err
}
return nil
}
开发者ID:karamsivia,项目名称:netplugin,代码行数:42,代码来源:ofnetBgp.go
示例20: TestPathPrependAsnToNewAsPathAttr
func TestPathPrependAsnToNewAsPathAttr(t *testing.T) {
assert := assert.New(t)
origin := bgp.NewPathAttributeOrigin(0)
nexthop := bgp.NewPathAttributeNextHop("192.168.50.1")
pathAttributes := []bgp.PathAttributeInterface{
origin,
nexthop,
}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "10.10.10.0")}
bgpmsg := bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri)
update := bgpmsg.Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(update)
peer := PathCreatePeer()
p := NewPath(peer[0], update.NLRI[0], false, update.PathAttributes, time.Now(), false)
asn := uint32(65000)
p.PrependAsn(asn, 1)
assert.Equal([]uint32{asn}, p.GetAsSeqList())
}
开发者ID:mfeed,项目名称:gobgp,代码行数:21,代码来源:path_test.go
注:本文中的github.com/osrg/gobgp/packet/bgp.NewPathAttributeNextHop函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论