本文整理汇总了Golang中github.com/osrg/gobgp/packet/bgp.NewAsPathParam函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAsPathParam函数的具体用法?Golang NewAsPathParam怎么用?Golang NewAsPathParam使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewAsPathParam函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestAsPathAs4Trans3
// before:
// as-path : 65000, 4000, {10, 20, 30}, 23456, 23456, 40001
// as4-path : 3000, 400000, 300000, 40001
// expected result:
// as-path : 65000, 4000, 3000, 400000, 300000, 40001
func TestAsPathAs4Trans3(t *testing.T) {
as1 := []uint16{65000, 4000}
param1 := bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as1)
as2 := []uint16{10, 20, 30}
param2 := bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SET, as2)
as3 := []uint16{bgp.AS_TRANS, bgp.AS_TRANS, 40001}
param3 := bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as3)
params := []bgp.AsPathParamInterface{param1, param2, param3}
aspath := bgp.NewPathAttributeAsPath(params)
as4 := []uint32{3000, 400000, 300000, 40001}
param4s := []*bgp.As4PathParam{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as4)}
as4path := bgp.NewPathAttributeAs4Path(param4s)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath, as4path}, nil).Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(msg)
assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.As4PathParam).AS), 6)
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.As4PathParam).AS[0], uint32(65000))
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.As4PathParam).AS[1], uint32(4000))
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.As4PathParam).AS[2], uint32(3000))
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.As4PathParam).AS[3], uint32(400000))
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.As4PathParam).AS[4], uint32(300000))
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.As4PathParam).AS[5], uint32(40001))
}
开发者ID:mfeed,项目名称:gobgp,代码行数:30,代码来源:message_test.go
示例2: 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
示例3: 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
示例4: 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
示例5: 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
示例6: TestPathPrependAsnToFullPathAttr
func TestPathPrependAsnToFullPathAttr(t *testing.T) {
assert := assert.New(t)
origin := bgp.NewPathAttributeOrigin(0)
asns := make([]uint16, 255)
for i, _ := range asns {
asns[i] = 65000 + uint16(i)
}
aspathParam := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, asns),
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)
expected := []uint32{65000, 65000}
for _, v := range asns {
expected = append(expected, uint32(v))
}
p.PrependAsn(65000, 2)
assert.Equal(append(expected, []uint32{0, 0, 0}...), p.GetAsSeqList())
fmt.Printf("asns: %v", p.GetAsSeqList())
}
开发者ID:mfeed,项目名称:gobgp,代码行数:38,代码来源:path_test.go
示例7: UpdatePathAttrs2ByteAs
func UpdatePathAttrs2ByteAs(msg *bgp.BGPUpdate) error {
ps := msg.PathAttributes
msg.PathAttributes = make([]bgp.PathAttributeInterface, len(ps))
copy(msg.PathAttributes, ps)
var asAttr *bgp.PathAttributeAsPath
idx := 0
for i, attr := range msg.PathAttributes {
if a, ok := attr.(*bgp.PathAttributeAsPath); ok {
asAttr = a
idx = i
break
}
}
if asAttr == nil {
return nil
}
as4Params := make([]*bgp.As4PathParam, 0, len(asAttr.Value))
as2Params := make([]bgp.AsPathParamInterface, 0, len(asAttr.Value))
mkAs4 := false
for _, param := range asAttr.Value {
as4Param := param.(*bgp.As4PathParam)
as2Path := make([]uint16, 0, len(as4Param.AS))
for _, as := range as4Param.AS {
if as > (1<<16)-1 {
mkAs4 = true
as2Path = append(as2Path, bgp.AS_TRANS)
} else {
as2Path = append(as2Path, uint16(as))
}
}
as2Params = append(as2Params, bgp.NewAsPathParam(as4Param.Type, as2Path))
// RFC 6793 4.2.2 Generating Updates
//
// Whenever the AS path information contains the AS_CONFED_SEQUENCE or
// AS_CONFED_SET path segment, the NEW BGP speaker MUST exclude such
// path segments from the AS4_PATH attribute being constructed.
if as4Param.Type != bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ && as4Param.Type != bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET {
as4Params = append(as4Params, as4Param)
}
}
msg.PathAttributes[idx] = bgp.NewPathAttributeAsPath(as2Params)
if mkAs4 {
msg.PathAttributes = append(msg.PathAttributes, bgp.NewPathAttributeAs4Path(as4Params))
}
return nil
}
开发者ID:ramrunner,项目名称:gobgp,代码行数:49,代码来源:message.go
示例8: TestAsPathAs4TransInvalid3
// before:
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : nil
// expected result:
// as-path : 65000, 4000, 23456, 23456, 40001
func TestAsPathAs4TransInvalid3(t *testing.T) {
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as)}
aspath := bgp.NewPathAttributeAsPath(params)
msg := bgp.NewBGPUpdateMessage(nil, []bgp.PathAttributeInterface{aspath}, nil).Body.(*bgp.BGPUpdate)
UpdatePathAttrs4ByteAs(msg)
assert.Equal(t, len(msg.PathAttributes), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value), 1)
assert.Equal(t, len(msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.As4PathParam).AS), 5)
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.As4PathParam).AS[0], uint32(65000))
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.As4PathParam).AS[1], uint32(4000))
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.As4PathParam).AS[2], uint32(bgp.AS_TRANS))
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.As4PathParam).AS[3], uint32(bgp.AS_TRANS))
assert.Equal(t, msg.PathAttributes[0].(*bgp.PathAttributeAsPath).Value[0].(*bgp.As4PathParam).AS[4], uint32(40001))
}
开发者ID:mfeed,项目名称:gobgp,代码行数:21,代码来源:message_test.go
示例9: 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
示例10: 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
示例11: updateMsgD3
func updateMsgD3() *bgp.BGPMessage {
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65100})}
aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("192.168.150.1")
med := bgp.NewPathAttributeMultiExitDisc(100)
pathAttributes := []bgp.PathAttributeInterface{
origin,
aspath,
nexthop,
med,
}
nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "30.30.30.0")}
w1 := bgp.NewIPAddrPrefix(23, "40.40.40.0")
withdrawnRoutes := []*bgp.IPAddrPrefix{w1}
updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri)
UpdatePathAttrs4ByteAs(updateMsg.Body.(*bgp.BGPUpdate))
return updateMsg
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:21,代码来源:destination_test.go
注:本文中的github.com/osrg/gobgp/packet/bgp.NewAsPathParam函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论