summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-11-03 23:00:33 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-11-04 01:00:15 +0900
commit2e3c100371a644f1a7a43a540e85c7ba28b935c7 (patch)
treef166018b28c00cfbb6c9bf2e5366547582264dd1
parent3efe2cefa791fcf815e4214d1a10a13119ece495 (diff)
packet add NewBGP*Message functions
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--packet/bgp.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/packet/bgp.go b/packet/bgp.go
index 49aa625d..f781170e 100644
--- a/packet/bgp.go
+++ b/packet/bgp.go
@@ -375,6 +375,13 @@ func (msg *BGPOpen) Serialize() ([]byte, error) {
return buf, nil
}
+func NewBGPOpenMessage(myas uint16, holdtime uint16, id string, optparams []OptionParameterInterface) *BGPMessage {
+ return &BGPMessage{
+ Header: BGPHeader{Type: BGP_MSG_OPEN},
+ Body: &BGPOpen{4, myas, holdtime, net.ParseIP(id).To4(), 0, optparams},
+ }
+}
+
type AddrPrefixInterface interface {
DecodeFromBytes([]byte) error
Serialize() ([]byte, error)
@@ -1834,6 +1841,13 @@ func (msg *BGPUpdate) Serialize() ([]byte, error) {
return buf, nil
}
+func NewBGPUpdateMessage(withdrawnRoutes []WithdrawnRoute, pathattrs []PathAttributeInterface, nlri []NLRInfo) *BGPMessage {
+ return &BGPMessage{
+ Header: BGPHeader{Type: BGP_MSG_UPDATE},
+ Body: &BGPUpdate{0, withdrawnRoutes, 0, pathattrs, nlri},
+ }
+}
+
type BGPNotification struct {
ErrorCode uint8
ErrorSubcode uint8
@@ -1860,6 +1874,13 @@ func (msg *BGPNotification) Serialize() ([]byte, error) {
return buf, nil
}
+func NewBGPNotificationMessage(errcode uint8, errsubcode uint8, data []byte) *BGPMessage {
+ return &BGPMessage{
+ Header: BGPHeader{Type: BGP_MSG_NOTIFICATION},
+ Body: &BGPNotification{errcode, errsubcode, data},
+ }
+}
+
type BGPKeepAlive struct {
}
@@ -1871,6 +1892,13 @@ func (msg *BGPKeepAlive) Serialize() ([]byte, error) {
return nil, nil
}
+func NewBGPKeepAliveMessage() *BGPMessage {
+ return &BGPMessage{
+ Header: BGPHeader{Len: 19, Type: BGP_MSG_KEEPALIVE},
+ Body: &BGPKeepAlive{},
+ }
+}
+
type BGPRouteRefresh struct {
AFI uint16
Demarcation uint8
@@ -1895,6 +1923,13 @@ func (msg *BGPRouteRefresh) Serialize() ([]byte, error) {
return buf, nil
}
+func NewBGPRouteRefreshMessage(afi uint16, demarcation uint8, safi uint8) *BGPMessage {
+ return &BGPMessage{
+ Header: BGPHeader{Type: BGP_MSG_ROUTE_REFRESH},
+ Body: &BGPRouteRefresh{afi, demarcation, safi},
+ }
+}
+
type BGPBody interface {
DecodeFromBytes([]byte) error
Serialize() ([]byte, error)