summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-11-03 22:26:51 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-11-04 01:00:12 +0900
commit3efe2cefa791fcf815e4214d1a10a13119ece495 (patch)
treeee7a2ea1ec9646201b2e7993ca4f8912efef69bb
parent19adcea6a0a703f81bcf37246a308cad0351ed92 (diff)
packet: add NewPathAttributer* functions
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--packet/bgp.go148
1 files changed, 148 insertions, 0 deletions
diff --git a/packet/bgp.go b/packet/bgp.go
index 49cec3a3..49aa625d 100644
--- a/packet/bgp.go
+++ b/packet/bgp.go
@@ -1070,6 +1070,16 @@ type PathAttributeOrigin struct {
PathAttribute
}
+func NewPathAttributeOrigin(value uint8) *PathAttributeOrigin {
+ return &PathAttributeOrigin{
+ PathAttribute: PathAttribute{
+ Flags: BGP_ATTR_FLAG_TRANSITIVE,
+ Type: BGP_ATTR_TYPE_ORIGIN,
+ Value: []byte{byte(value)},
+ },
+ }
+}
+
type AsPathParam struct {
Type uint8
Num uint8
@@ -1161,6 +1171,16 @@ func (p *PathAttributeAsPath) Serialize() ([]byte, error) {
return p.PathAttribute.Serialize()
}
+func NewPathAttributeAsPath(value []AsPathParam) *PathAttributeAsPath {
+ return &PathAttributeAsPath{
+ PathAttribute: PathAttribute{
+ Flags: BGP_ATTR_FLAG_TRANSITIVE,
+ Type: BGP_ATTR_TYPE_AS_PATH,
+ },
+ Value: value,
+ }
+}
+
type PathAttributeNextHop struct {
PathAttribute
Value net.IP
@@ -1177,6 +1197,16 @@ func (p *PathAttributeNextHop) Serialize() ([]byte, error) {
return p.PathAttribute.Serialize()
}
+func NewPathAttributeNextHop(value string) *PathAttributeNextHop {
+ return &PathAttributeNextHop{
+ PathAttribute: PathAttribute{
+ Flags: BGP_ATTR_FLAG_TRANSITIVE,
+ Type: BGP_ATTR_TYPE_NEXT_HOP,
+ },
+ Value: net.ParseIP(value).To4(),
+ }
+}
+
type PathAttributeMultiExitDisc struct {
PathAttribute
Value uint32
@@ -1195,6 +1225,16 @@ func (p *PathAttributeMultiExitDisc) Serialize() ([]byte, error) {
return p.PathAttribute.Serialize()
}
+func NewPathAttributeMultiExitDisc(value uint32) *PathAttributeMultiExitDisc {
+ return &PathAttributeMultiExitDisc{
+ PathAttribute: PathAttribute{
+ Flags: BGP_ATTR_FLAG_OPTIONAL,
+ Type: BGP_ATTR_TYPE_MULTI_EXIT_DISC,
+ },
+ Value: value,
+ }
+}
+
type PathAttributeLocalPref struct {
PathAttribute
Value uint32
@@ -1213,10 +1253,29 @@ func (p *PathAttributeLocalPref) Serialize() ([]byte, error) {
return p.PathAttribute.Serialize()
}
+func NewPathAttributeLocalPref(value uint32) *PathAttributeLocalPref {
+ return &PathAttributeLocalPref{
+ PathAttribute: PathAttribute{
+ Flags: BGP_ATTR_FLAG_TRANSITIVE,
+ Type: BGP_ATTR_TYPE_LOCAL_PREF,
+ },
+ Value: value,
+ }
+}
+
type PathAttributeAtomicAggregate struct {
PathAttribute
}
+func NewPathAttributeAtomicAggregate() *PathAttributeAtomicAggregate {
+ return &PathAttributeAtomicAggregate{
+ PathAttribute: PathAttribute{
+ Flags: BGP_ATTR_FLAG_TRANSITIVE,
+ Type: BGP_ATTR_TYPE_ATOMIC_AGGREGATE,
+ },
+ }
+}
+
type PathAttributeAggregatorParam struct {
AS uint32
Address net.IP
@@ -1247,6 +1306,19 @@ func (p *PathAttributeAggregator) Serialize() ([]byte, error) {
return p.PathAttribute.Serialize()
}
+func NewPathAttributeAggregator(as uint16, address string) *PathAttributeAggregator {
+ return &PathAttributeAggregator{
+ PathAttribute: PathAttribute{
+ Flags: BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE,
+ Type: BGP_ATTR_TYPE_AGGREGATOR,
+ },
+ Value: PathAttributeAggregatorParam{
+ AS: uint32(as),
+ Address: net.ParseIP(address).To4(),
+ },
+ }
+}
+
type PathAttributeCommunities struct {
PathAttribute
Value []uint32
@@ -1271,6 +1343,13 @@ func (p *PathAttributeCommunities) Serialize() ([]byte, error) {
return p.PathAttribute.Serialize()
}
+func NewPathAttributeCommunities(value []uint32) *PathAttributeCommunities {
+ return &PathAttributeCommunities{
+ PathAttribute{BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE, BGP_ATTR_TYPE_COMMUNITIES, 0, nil},
+ value,
+ }
+}
+
type PathAttributeOriginatorId struct {
PathAttribute
Value net.IP
@@ -1289,6 +1368,13 @@ func (p *PathAttributeOriginatorId) Serialize() ([]byte, error) {
return p.PathAttribute.Serialize()
}
+func NewPathAttributeOriginatorId(value string) *PathAttributeOriginatorId {
+ return &PathAttributeOriginatorId{
+ PathAttribute{BGP_ATTR_FLAG_OPTIONAL, BGP_ATTR_TYPE_ORIGINATOR_ID, 0, nil},
+ net.ParseIP(value).To4(),
+ }
+}
+
type PathAttributeClusterList struct {
PathAttribute
Value []net.IP
@@ -1313,6 +1399,17 @@ func (p *PathAttributeClusterList) Serialize() ([]byte, error) {
return p.PathAttribute.Serialize()
}
+func NewPathAttributeClusterList(value []string) *PathAttributeClusterList {
+ l := make([]net.IP, len(value))
+ for i, v := range value {
+ l[i] = net.ParseIP(v).To4()
+ }
+ return &PathAttributeClusterList{
+ PathAttribute{BGP_ATTR_FLAG_OPTIONAL, BGP_ATTR_TYPE_CLUSTER_LIST, 0, nil},
+ l,
+ }
+}
+
type PathAttributeMpReachNLRI struct {
PathAttribute
Nexthop net.IP
@@ -1379,6 +1476,17 @@ func (p *PathAttributeMpReachNLRI) Serialize() ([]byte, error) {
return p.PathAttribute.Serialize()
}
+func NewPathAttributeMpReachNLRI(nexthop string, nlri []AddrPrefixInterface) *PathAttributeMpReachNLRI {
+ return &PathAttributeMpReachNLRI{
+ PathAttribute: PathAttribute{
+ Flags: BGP_ATTR_FLAG_OPTIONAL,
+ Type: BGP_ATTR_TYPE_MP_REACH_NLRI,
+ },
+ Nexthop: net.ParseIP(nexthop),
+ Value: nlri,
+ }
+}
+
type PathAttributeMpUnreachNLRI struct {
PathAttribute
Value []AddrPrefixInterface
@@ -1417,6 +1525,13 @@ func (p *PathAttributeMpUnreachNLRI) Serialize() ([]byte, error) {
return p.PathAttribute.Serialize()
}
+func NewPathAttributeMpUnreachNLRI(nlri []AddrPrefixInterface) *PathAttributeMpUnreachNLRI {
+ return &PathAttributeMpUnreachNLRI{
+ PathAttribute{BGP_ATTR_FLAG_OPTIONAL, BGP_ATTR_TYPE_MP_UNREACH_NLRI, 0, nil},
+ nlri,
+ }
+}
+
type ExtendedCommunityInterface interface {
Serialize() ([]byte, error)
}
@@ -1538,6 +1653,16 @@ func (p *PathAttributeExtendedCommunities) DecodeFromBytes(data []byte) error {
return nil
}
+func NewPathAttributeExtendedCommunities(value []ExtendedCommunityInterface) *PathAttributeExtendedCommunities {
+ return &PathAttributeExtendedCommunities{
+ PathAttribute: PathAttribute{
+ Flags: BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE,
+ Type: BGP_ATTR_TYPE_EXTENDED_COMMUNITIES,
+ },
+ Value: value,
+ }
+}
+
type PathAttributeAs4Path struct {
PathAttribute
Value []AsPathParam
@@ -1550,6 +1675,16 @@ func (p *PathAttributeAs4Path) DecodeFromBytes(data []byte) error {
return nil
}
+func NewPathAttributeAs4Path(value []AsPathParam) *PathAttributeAs4Path {
+ return &PathAttributeAs4Path{
+ PathAttribute: PathAttribute{
+ Flags: BGP_ATTR_FLAG_TRANSITIVE,
+ Type: BGP_ATTR_TYPE_AS4_PATH,
+ },
+ Value: value,
+ }
+}
+
type PathAttributeAs4Aggregator struct {
PathAttribute
Value PathAttributeAggregatorParam
@@ -1571,6 +1706,19 @@ func (p *PathAttributeAs4Aggregator) Serialize() ([]byte, error) {
return p.PathAttribute.Serialize()
}
+func NewPathAttributeAs4Aggregator(as uint32, address string) *PathAttributeAs4Aggregator {
+ return &PathAttributeAs4Aggregator{
+ PathAttribute: PathAttribute{
+ Flags: BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE,
+ Type: BGP_ATTR_TYPE_AS4_AGGREGATOR,
+ },
+ Value: PathAttributeAggregatorParam{
+ AS: as,
+ Address: net.ParseIP(address),
+ },
+ }
+}
+
type PathAttributeUnknown struct {
PathAttribute
}