Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ k8s_yaml('./config/samples/v1alpha1_prefixset.yaml')
k8s_resource(new_name='ccloud-prefixset', objects=['ccloud-prefixset:prefixset'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False, labels=['samples'])

k8s_yaml('./config/samples/v1alpha1_routingpolicy.yaml')
k8s_resource(new_name='bgp-import-policy', objects=['bgp-import-policy:routingpolicy', 'internal-networks:prefixset', 'partner-networks:prefixset', 'blocked-networks:prefixset'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False, labels=['samples'])
k8s_resource(new_name='bgp-import-policy', objects=['bgp-import-policy:routingpolicy', 'internal-networks:prefixset', 'partner-networks:prefixset', 'blocked-networks:prefixset', 'communityset-regular:communityset', 'communityset-extended:communityset'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False, labels=['samples'])

k8s_yaml('./config/samples/cisco/nx/v1alpha1_vpcdomain.yaml')
k8s_resource(new_name='vpcdomain', objects=['leaf1-vpcdomain:vpcdomain', 'leaf1-vrfvpckeepalive:vrf', 'eth1-30:interface', 'vpc-peer-link:interfaceconfig', 'eth1-31:interface','eth1-32:interface', 'po1:interface'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False, labels=['samples'])
Expand Down
24 changes: 24 additions & 0 deletions api/core/v1alpha1/routingpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,18 @@ type SetASPathReplace struct {
Replacement intstr.IntOrString `json:"replacement"`
}

// CommunityOperation defines whether communities are added to the route's existing
// set (Add) or replace it (Replace).
// +kubebuilder:validation:Enum=Add;Replace
type CommunityOperation string

const (
// CommunityOperationAdd appends the communities to the route's existing set.
CommunityOperationAdd CommunityOperation = "Add"
// CommunityOperationReplace overwrites the route's communities with the configured set.
CommunityOperationReplace CommunityOperation = "Replace"
)

// SetCommunityAction defines the action to set BGP standard communities.
type SetCommunityAction struct {
// Communities is the list of BGP standard communities to set.
Expand All @@ -205,6 +217,12 @@ type SetCommunityAction struct {
// +required
// +kubebuilder:validation:MinItems=1
Communities []string `json:"communities"`

// Operation controls whether attributes are added (Add) to the communities or
// if the communities attributes are replaced (Replace).
// +optional
// +kubebuilder:default=Replace
Operation CommunityOperation `json:"operation,omitempty"`
}

// SetExtCommunityAction defines the action to set BGP extended communities.
Expand All @@ -215,6 +233,12 @@ type SetExtCommunityAction struct {
// +required
// +kubebuilder:validation:MinItems=1
Communities []string `json:"communities"`

// Operation controls whether the communities are added to the route's existing
// communities (Add) or replace them (Replace).
// +optional
// +kubebuilder:default=Replace
Operation CommunityOperation `json:"operation,omitempty"`
}

// RoutingPolicyStatus defines the observed state of RoutingPolicy.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions config/samples/v1alpha1_routingpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ spec:
communities:
- "65137:100"
- "65137:200"
operation: Add
setExtCommunity:
communities:
- "65137:100"
operation: Replace
- sequence: 20
conditions:
matchPrefixSet:
Expand Down
22 changes: 22 additions & 0 deletions docs/api-reference/index.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/provider/cisco/nxos/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2890,12 +2890,12 @@ func (p *Provider) EnsureRoutingPolicy(ctx context.Context, req *provider.Ensure

if stmt.Actions.BgpActions != nil {
if stmt.Actions.BgpActions.SetCommunity != nil {
if err := e.SetCommunities(stmt.Actions.BgpActions.SetCommunity.Communities); err != nil {
if err := e.SetCommunities(stmt.Actions.BgpActions.SetCommunity.Communities, stmt.Actions.BgpActions.SetCommunity.Operation); err != nil {
return err
}
}
if stmt.Actions.BgpActions.SetExtCommunity != nil {
if err := e.SetExtCommunities(stmt.Actions.BgpActions.SetExtCommunity.Communities); err != nil {
if err := e.SetExtCommunities(stmt.Actions.BgpActions.SetExtCommunity.Communities, stmt.Actions.BgpActions.SetExtCommunity.Operation); err != nil {
return err
}
}
Expand Down
14 changes: 12 additions & 2 deletions internal/provider/cisco/nxos/routemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ type RouteMapEntry struct {
Action Action `json:"action"`
Order int32 `json:"order"`
SrttItems struct {
Additive AdminSt `json:"additive"`
ItemItems struct {
ItemList gnmiext.List[ExtCommItem, *ExtCommItem] `json:"Item-list,omitzero"`
} `json:"item-items,omitzero"`
} `json:"srtt-items,omitzero"`
SregcommItems struct {
Additive AdminSt `json:"additive"`
NoCommAttr AdminSt `json:"noCommAttr"`
ItemItems struct {
ItemList gnmiext.List[string, *CommItem] `json:"Item-list,omitzero"`
Expand Down Expand Up @@ -73,7 +75,7 @@ type RouteMapEntry struct {

func (e *RouteMapEntry) Key() int32 { return e.Order }

func (e *RouteMapEntry) SetCommunities(communities []string) error {
func (e *RouteMapEntry) SetCommunities(communities []string, operation v1alpha1.CommunityOperation) error {
for _, comm := range communities {
c, err := Community(comm)
if err != nil {
Expand All @@ -82,17 +84,25 @@ func (e *RouteMapEntry) SetCommunities(communities []string) error {
e.SregcommItems.NoCommAttr = AdminStDisabled
e.SregcommItems.ItemItems.ItemList.Set(&CommItem{Community: c})
}
e.SregcommItems.Additive = AdminStDisabled
if operation == v1alpha1.CommunityOperationAdd {
e.SregcommItems.Additive = AdminStEnabled
}
return nil
}

func (e *RouteMapEntry) SetExtCommunities(communities []string) error {
func (e *RouteMapEntry) SetExtCommunities(communities []string, operation v1alpha1.CommunityOperation) error {
for _, comm := range communities {
c, err := RouteTarget(comm)
if err != nil {
return err
}
e.SrttItems.ItemItems.ItemList.Set(&ExtCommItem{Community: c, Scope: RtExtComScopeTransitive})
}
e.SrttItems.Additive = AdminStDisabled
if operation == v1alpha1.CommunityOperationAdd {
e.SrttItems.Additive = AdminStEnabled
}
return nil
}

Expand Down
26 changes: 26 additions & 0 deletions internal/provider/cisco/nxos/routemap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ func init() {
e := &RouteMapEntry{}
e.Order = 10
e.Action = ActionPermit
e.SrttItems.Additive = AdminStDisabled
e.SrttItems.ItemItems.ItemList.Set(&ExtCommItem{Community: "route-target:as2-nn2:65137:107", Scope: RtExtComScopeTransitive})
e.SregcommItems.Additive = AdminStDisabled
e.SregcommItems.NoCommAttr = AdminStDisabled
e.SregcommItems.ItemItems.ItemList.Set(&CommItem{Community: "regular:as2-nn2:65137:107"})
e.MrtdstItems.RsrtDstAttItems.RsRtDstAttList.Set(&RsRtDstAtt{TDn: "/System/rpm-items/pfxlistv4-items/RuleV4-list[name='PL-CLOUD07']"})
Expand Down Expand Up @@ -141,4 +143,28 @@ func init() {
comboRM.Name = "RM-COMBINED-MATCH"
comboRM.EntItems.EntryList.Set(comboEntry)
Register("route_map_combined_match", comboRM)

commAdditiveEntry := &RouteMapEntry{}
commAdditiveEntry.Order = 10
commAdditiveEntry.Action = ActionPermit
if err := commAdditiveEntry.SetCommunities([]string{"65000:10", "65000:20"}, v1alpha1.CommunityOperationAdd); err != nil {
panic(err)
}

commAdditiveRM := &RouteMap{}
commAdditiveRM.Name = "RM-COMMUNITY-ADDITIVE"
commAdditiveRM.EntItems.EntryList.Set(commAdditiveEntry)
Register("route_map_community_additive", commAdditiveRM)

extCommAdditiveEntry := &RouteMapEntry{}
extCommAdditiveEntry.Order = 10
extCommAdditiveEntry.Action = ActionPermit
if err := extCommAdditiveEntry.SetExtCommunities([]string{"65000:10", "65000:20"}, v1alpha1.CommunityOperationAdd); err != nil {
panic(err)
}

extCommAdditiveRM := &RouteMap{}
extCommAdditiveRM.Name = "RM-EXTCOMMUNITY-ADDITIVE"
extCommAdditiveRM.EntItems.EntryList.Set(extCommAdditiveEntry)
Register("route_map_extcommunity_additive", extCommAdditiveRM)
}
2 changes: 2 additions & 0 deletions internal/provider/cisco/nxos/testdata/route_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"action": "permit",
"order": 10,
"srtt-items": {
"additive": "disabled",
"item-items": {
"Item-list": [
{
Expand All @@ -20,6 +21,7 @@
}
},
"sregcomm-items": {
"additive": "disabled",
"noCommAttr": "disabled",
"item-items": {
"Item-list": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"rpm-items": {
"rtmap-items": {
"Rule-list": [
{
"name": "RM-COMMUNITY-ADDITIVE",
"ent-items": {
"Entry-list": [
{
"action": "permit",
"order": 10,
"sregcomm-items": {
"additive": "enabled",
"noCommAttr": "disabled",
"item-items": {
"Item-list": [
{
"community": "regular:as2-nn2:65000:10"
},
{
"community": "regular:as2-nn2:65000:20"
}
]
}
}
}
]
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
route-map RM-COMMUNITY-ADDITIVE permit 10
set community 65000:10 65000:20 additive
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"rpm-items": {
"rtmap-items": {
"Rule-list": [
{
"name": "RM-EXTCOMMUNITY-ADDITIVE",
"ent-items": {
"Entry-list": [
{
"action": "permit",
"order": 10,
"srtt-items": {
"additive": "enabled",
"item-items": {
"Item-list": [
{
"community": "route-target:as2-nn2:65000:10",
"scope": "transitive"
},
{
"community": "route-target:as2-nn2:65000:20",
"scope": "transitive"
}
]
}
}
}
]
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
route-map RM-EXTCOMMUNITY-ADDITIVE permit 10
set extcommunity rt 65000:10 65000:20 additive
Loading
Loading