github.com/osrg/gobgp/v3@v3.30.0/pkg/packet/bgp/helper.go (about) 1 // Copyright (C) 2016 Nippon Telegraph and Telephone Corporation. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 // implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 package bgp 17 18 func NewTestBGPOpenMessage() *BGPMessage { 19 p1 := NewOptionParameterCapability( 20 []ParameterCapabilityInterface{NewCapRouteRefresh()}) 21 p2 := NewOptionParameterCapability( 22 []ParameterCapabilityInterface{NewCapMultiProtocol(RF_IPv4_UC)}) 23 g := &CapGracefulRestartTuple{4, 2, 3} 24 p3 := NewOptionParameterCapability( 25 []ParameterCapabilityInterface{NewCapGracefulRestart(false, true, 100, 26 []*CapGracefulRestartTuple{g})}) 27 p4 := NewOptionParameterCapability( 28 []ParameterCapabilityInterface{NewCapFourOctetASNumber(100000)}) 29 p5 := NewOptionParameterCapability( 30 []ParameterCapabilityInterface{NewCapAddPath([]*CapAddPathTuple{NewCapAddPathTuple(RF_IPv4_UC, BGP_ADD_PATH_BOTH)})}) 31 return NewBGPOpenMessage(11033, 303, "100.4.10.3", 32 []OptionParameterInterface{p1, p2, p3, p4, p5}) 33 } 34 35 func NewTestBGPUpdateMessage() *BGPMessage { 36 w1 := NewIPAddrPrefix(23, "121.1.3.2") 37 w2 := NewIPAddrPrefix(17, "100.33.3.0") 38 w := []*IPAddrPrefix{w1, w2} 39 40 aspath1 := []AsPathParamInterface{ 41 NewAsPathParam(2, []uint16{1000}), 42 NewAsPathParam(1, []uint16{1001, 1002}), 43 NewAsPathParam(2, []uint16{1003, 1004}), 44 } 45 46 aspath2 := []AsPathParamInterface{ 47 NewAs4PathParam(2, []uint32{1000000}), 48 NewAs4PathParam(1, []uint32{1000001, 1002}), 49 NewAs4PathParam(2, []uint32{1003, 100004}), 50 } 51 52 aspath3 := []*As4PathParam{ 53 NewAs4PathParam(2, []uint32{1000000}), 54 NewAs4PathParam(1, []uint32{1000001, 1002}), 55 NewAs4PathParam(2, []uint32{1003, 100004}), 56 } 57 58 isTransitive := true 59 60 ecommunities := []ExtendedCommunityInterface{ 61 NewTwoOctetAsSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, 10003, 3<<20, isTransitive), 62 NewFourOctetAsSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, 1<<20, 300, isTransitive), 63 NewIPv4AddressSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, "192.2.1.2", 3000, isTransitive), 64 NewOpaqueExtended(false, []byte{1, 2, 3, 4, 5, 6, 7}), 65 NewValidationExtended(VALIDATION_STATE_INVALID), 66 NewUnknownExtended(99, []byte{0, 1, 2, 3, 4, 5, 6, 7}), 67 NewESILabelExtended(1000, true), 68 NewESImportRouteTarget("11:22:33:44:55:66"), 69 NewMacMobilityExtended(123, false), 70 } 71 72 prefixes1 := []AddrPrefixInterface{ 73 NewLabeledVPNIPAddrPrefix(24, "192.0.9.0", *NewMPLSLabelStack(1, 2, 3), 74 NewRouteDistinguisherTwoOctetAS(256, 10000)), 75 NewLabeledVPNIPAddrPrefix(24, "192.10.8.0", *NewMPLSLabelStack(5, 6, 7, 8), 76 NewRouteDistinguisherIPAddressAS("10.0.1.1", 10001)), 77 } 78 79 prefixes2 := []AddrPrefixInterface{NewIPv6AddrPrefix(128, 80 "fe80:1234:1234:5667:8967:af12:8912:1023")} 81 82 prefixes3 := []AddrPrefixInterface{NewLabeledVPNIPv6AddrPrefix(128, 83 "fe80:1234:1234:5667:8967:af12:1203:33a1", *NewMPLSLabelStack(5, 6), 84 NewRouteDistinguisherFourOctetAS(5, 6))} 85 86 prefixes4 := []AddrPrefixInterface{NewLabeledIPAddrPrefix(25, "192.168.0.0", 87 *NewMPLSLabelStack(5, 6, 7))} 88 89 prefixes5 := []AddrPrefixInterface{ 90 NewEVPNEthernetAutoDiscoveryRoute(NewRouteDistinguisherFourOctetAS(5, 6), EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 2, 2), 91 NewEVPNMacIPAdvertisementRoute(NewRouteDistinguisherFourOctetAS(5, 6), EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 3, "01:23:45:67:89:ab", "192.2.1.2", []uint32{3, 4}), 92 NewEVPNMulticastEthernetTagRoute(NewRouteDistinguisherFourOctetAS(5, 6), 3, "192.2.1.2"), 93 NewEVPNEthernetSegmentRoute(NewRouteDistinguisherFourOctetAS(5, 6), EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, "192.2.1.1"), 94 NewEVPNIPPrefixRoute(NewRouteDistinguisherFourOctetAS(5, 6), EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 5, 24, "192.2.1.0", "192.3.1.1", 5), 95 } 96 97 prefixes6 := []AddrPrefixInterface{NewVPLSNLRI(NewRouteDistinguisherFourOctetAS(5, 6), 101, 100, 10, 1000)} 98 99 p := []PathAttributeInterface{ 100 NewPathAttributeOrigin(3), 101 NewPathAttributeAsPath(aspath1), 102 NewPathAttributeAsPath(aspath2), 103 NewPathAttributeNextHop("129.1.1.2"), 104 NewPathAttributeMultiExitDisc(1 << 20), 105 NewPathAttributeLocalPref(1 << 22), 106 NewPathAttributeAtomicAggregate(), 107 NewPathAttributeAggregator(uint16(30002), "129.0.2.99"), 108 NewPathAttributeAggregator(uint32(30002), "129.0.2.99"), 109 NewPathAttributeAggregator(uint32(300020), "129.0.2.99"), 110 NewPathAttributeCommunities([]uint32{1, 3}), 111 NewPathAttributeOriginatorId("10.10.0.1"), 112 NewPathAttributeClusterList([]string{"10.10.0.2", "10.10.0.3"}), 113 NewPathAttributeExtendedCommunities(ecommunities), 114 NewPathAttributeAs4Path(aspath3), 115 NewPathAttributeAs4Aggregator(10000, "112.22.2.1"), 116 NewPathAttributeMpReachNLRI("112.22.2.0", prefixes1), 117 NewPathAttributeMpReachNLRI("1023::", prefixes2), 118 NewPathAttributeMpReachNLRI("fe80::", prefixes3), 119 NewPathAttributeMpReachNLRI("129.1.1.1", prefixes4), 120 NewPathAttributeMpReachNLRI("129.1.1.1", prefixes5), 121 NewPathAttributeMpReachNLRI("135.1.1.1", prefixes6), 122 NewPathAttributeMpUnreachNLRI(prefixes1), 123 //NewPathAttributeMpReachNLRI("112.22.2.0", []AddrPrefixInterface{}), 124 //NewPathAttributeMpUnreachNLRI([]AddrPrefixInterface{}), 125 NewPathAttributeUnknown(BGP_ATTR_FLAG_TRANSITIVE, 100, []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}), 126 } 127 n := []*IPAddrPrefix{NewIPAddrPrefix(24, "13.2.3.1")} 128 return NewBGPUpdateMessage(w, p, n) 129 }