Exemple #1
0
func (t *Table) deletePathsByVrf(vrf *Vrf) []*Path {
	pathList := make([]*Path, 0)
	for _, dest := range t.destinations {
		for _, p := range dest.knownPathList {
			var rd bgp.RouteDistinguisherInterface
			nlri := p.GetNlri()
			switch nlri.(type) {
			case *bgp.LabeledVPNIPAddrPrefix:
				rd = nlri.(*bgp.LabeledVPNIPAddrPrefix).RD
			case *bgp.LabeledVPNIPv6AddrPrefix:
				rd = nlri.(*bgp.LabeledVPNIPv6AddrPrefix).RD
			case *bgp.EVPNNLRI:
				rd = nlri.(*bgp.EVPNNLRI).RD()
			default:
				return pathList
			}
			if p.IsLocal() && vrf.Rd.String() == rd.String() {
				p.IsWithdraw = true
				pathList = append(pathList, p)
				break
			}
		}
	}
	return pathList
}
Exemple #2
0
func (cli *GoBGPClient) AddVRF(name string, id int, rd bgp.RouteDistinguisherInterface, im, ex []bgp.ExtendedCommunityInterface) error {
	buf, err := rd.Serialize()
	if err != nil {
		return err
	}

	f := func(comms []bgp.ExtendedCommunityInterface) ([][]byte, error) {
		var bufs [][]byte
		for _, c := range comms {
			buf, err := c.Serialize()
			if err != nil {
				return nil, err
			}
			bufs = append(bufs, buf)
		}
		return bufs, err
	}

	importRT, err := f(im)
	if err != nil {
		return err
	}
	exportRT, err := f(ex)
	if err != nil {
		return err
	}

	arg := &api.AddVrfRequest{
		Vrf: &api.Vrf{
			Name:     name,
			Rd:       buf,
			Id:       uint32(id),
			ImportRt: importRT,
			ExportRt: exportRT,
		},
	}
	_, err = cli.cli.AddVrf(context.Background(), arg)
	return err
}