Skip to content
Snippets Groups Projects
Commit 862519ec authored by Daniel Czerwonk's avatar Daniel Czerwonk
Browse files

copy paths, first path modification actions

parent aa2bc7a8
No related branches found
No related tags found
No related merge requests found
...@@ -154,6 +154,14 @@ func (b *BGPPath) Print() string { ...@@ -154,6 +154,14 @@ func (b *BGPPath) Print() string {
return ret return ret
} }
func (b *BGPPath) Prepend(asn uint32, times uint16) {
for i := 0; uint16(i) < times; i++ {
b.ASPath = fmt.Sprintf("%d %s", asn, b.ASPath)
}
b.ASPathLen = b.ASPathLen + uint16(times)
}
func uint32To4Byte(addr uint32) [4]byte { func uint32To4Byte(addr uint32) [4]byte {
slice := convert.Uint32Byte(addr) slice := convert.Uint32Byte(addr)
ret := [4]byte{ ret := [4]byte{
...@@ -164,3 +172,12 @@ func uint32To4Byte(addr uint32) [4]byte { ...@@ -164,3 +172,12 @@ func uint32To4Byte(addr uint32) [4]byte {
} }
return ret return ret
} }
func (p *BGPPath) Copy() *BGPPath {
if p == nil {
return nil
}
cp := *p
return &cp
}
...@@ -100,3 +100,15 @@ func (p *Path) Print() string { ...@@ -100,3 +100,15 @@ func (p *Path) Print() string {
return ret return ret
} }
func (p *Path) Copy() *Path {
if p == nil {
return nil
}
cp := *p
cp.BGPPath = cp.BGPPath.Copy()
cp.StaticPath = cp.StaticPath.Copy()
return &cp
}
...@@ -23,3 +23,12 @@ func (s *StaticPath) Compare(t *StaticPath) int8 { ...@@ -23,3 +23,12 @@ func (s *StaticPath) Compare(t *StaticPath) int8 {
func (s *StaticPath) ECMP(t *StaticPath) bool { func (s *StaticPath) ECMP(t *StaticPath) bool {
return true return true
} }
func (s *StaticPath) Copy() *StaticPath {
if s == nil {
return nil
}
cp := *s
return &cp
}
package actions
import (
"github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route"
)
type ASPathPrependAction struct {
asn uint32
times uint16
}
func NewASPathPrependAction(asn uint32, times uint16) *ASPathPrependAction {
return &ASPathPrependAction{
asn: asn,
times: times,
}
}
func (a *ASPathPrependAction) Do(p net.Prefix, pa *route.Path) (modPath *route.Path, reject bool) {
if pa.BGPPath == nil {
return pa, false
}
modified := pa.Copy()
modified.BGPPath.Prepend(a.asn, a.times)
return modified, false
}
package actions
import (
"github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route"
)
type FilterAction interface {
Do(p net.Prefix, pa *route.Path) (modPath *route.Path, reject bool)
}
...@@ -3,20 +3,19 @@ package actions ...@@ -3,20 +3,19 @@ package actions
import ( import (
"github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable/filter"
) )
type setLocalPrefAction struct { type SetLocalPrefAction struct {
pref uint32 pref uint32
} }
func NewSetLocalPrefAction(pref uint32) filter.FilterAction { func NewSetLocalPrefAction(pref uint32) *SetLocalPrefAction {
return &setLocalPrefAction{ return &SetLocalPrefAction{
pref: pref, pref: pref,
} }
} }
func (a *setLocalPrefAction) Do(p net.Prefix, pa *route.Path) (modPath *route.Path, reject bool) { func (a *SetLocalPrefAction) Do(p net.Prefix, pa *route.Path) (modPath *route.Path, reject bool) {
if pa.BGPPath == nil { if pa.BGPPath == nil {
return pa, false return pa, false
} }
... ...
......
...@@ -3,26 +3,25 @@ package actions ...@@ -3,26 +3,25 @@ package actions
import ( import (
"github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable/filter"
) )
type setNextHopAction struct { type SetNextHopAction struct {
addr uint32 addr uint32
} }
func NewSetNextHopAction(addr uint32) filter.FilterAction { func NewSetNextHopAction(addr uint32) *SetNextHopAction {
return &setNextHopAction{ return &SetNextHopAction{
addr: addr, addr: addr,
} }
} }
func (a *setNextHopAction) Do(p net.Prefix, pa *route.Path) (modPath *route.Path, reject bool) { func (a *SetNextHopAction) Do(p net.Prefix, pa *route.Path) (modPath *route.Path, reject bool) {
if pa.BGPPath == nil { if pa.BGPPath == nil {
return pa, false return pa, false
} }
modified := *pa modified := pa.Copy()
modified.BGPPath.NextHop = a.addr modified.BGPPath.NextHop = a.addr
return &modified, false return modified, false
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment