Skip to content

Commit

Permalink
VRF: move from cloud APIs to evpngw APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
  • Loading branch information
glimchb committed Jul 13, 2023
1 parent 5b18e77 commit 522e181
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 128 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ Run `docker-compose up -d`
## Manual gRPC example

```bash
docker-compose exec opi-evpn-bridge grpcurl -plaintext -d '{"vpc" : {"spec" : {"v4_route_table_name_ref" : "1234"} }, "vpc_id" : "testvpc", "parent" : "todo" }' localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.CreateVpc
docker-compose exec opi-evpn-bridge grpcurl -plaintext -d '{"subnet" : {"spec" : {"vpc_name_ref": "//network.opiproject.org/vpcs/blue", "virtual_router_mac": "qrvMAAAB", "v4_prefix": {"addr": 336860161, "len": 24} } }, "subnet_id" : "testbridge", "parent" : "todo" }' localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.CreateSubnet
docker-compose exec opi-evpn-bridge grpcurl -plaintext -d '{"vrf" : {"spec" : {"vni" : 1234, "loopback_ip_prefix" : {} }}, "vrf_id" : "testvrf" }' localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.CreateVrf"
docker-compose exec opi-evpn-bridge grpcurl -plaintext -d '{"subnet" : {"spec" : {"vpc_name_ref": "//network.opiproject.org/vrfs/blue", "virtual_router_mac": "qrvMAAAB", "v4_prefix": {"addr": 336860161, "len": 24} } }, "subnet_id" : "testbridge", "parent" : "todo" }' localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.CreateSubnet
docker-compose exec opi-evpn-bridge grpcurl -plaintext -d '{"interface" : {"spec" : {"ifid": 11, "l3_if_spec": {"vpc_name_ref": "//network.opiproject.org/subnets/testbridge", mac_address: "qrvMAAAB"}} }, "interface_id" : "testinterface", "parent" : "todo" }' localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.CreateInterface
docker-compose exec opi-evpn-bridge grpcurl -plaintext -d '{"tunnel" : {"spec" : {"vpc_name_ref": "//network.opiproject.org/subnets/testbridge", "local_ip": {"af": "IP_AF_INET", "v4_addr": 336860161}, "encap": {"type": "ENCAP_TYPE_VXLAN", "value": {"vnid": 100}} } }, "tunnel_id" : "testvxlan", "parent" : "todo" }' localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.CreateTunnel
docker-compose exec opi-evpn-bridge grpcurl -plaintext -d '{"name": "//network.opiproject.org/interfaces/testinterface"}' localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.GetInterface
docker-compose exec opi-evpn-bridge grpcurl -plaintext -d '{"name": "//network.opiproject.org/subnets/testbridge"}' localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.GetSubnet
docker-compose exec opi-evpn-bridge grpcurl -plaintext -d '{"name": "//network.opiproject.org/tunnels/testvxlan"}' localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.GetTunnel
docker-compose exec opi-evpn-bridge grpcurl -plaintext -d '{"name": "//network.opiproject.org/vpcs/testvpc"}' localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.GetVpc
docker-compose exec opi-evpn-bridge grpcurl -plaintext -d '{"name": "//network.opiproject.org/vrfs/testvrf"}' localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.GetVrf
docker-compose exec opi-evpn-bridge grpcurl -plaintext -d '{"name": "//network.opiproject.org/interfaces/testinterface"}' localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.DeleteInterface
docker-compose exec opi-evpn-bridge grpcurl -plaintext -d '{"name": "//network.opiproject.org/subnets/testbridge"}' localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.DeleteSubnet
docker-compose exec opi-evpn-bridge grpcurl -plaintext -d '{"name" : "//network.opiproject.org/tunnels/testvxlan"}' localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.DeleteTunnel
docker-compose exec opi-evpn-bridge grpcurl -plaintext -d '{"name" : "//network.opiproject.org/vpcs/testvpc"}' localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.DeleteVpc
docker-compose exec opi-evpn-bridge grpcurl -plaintext -d '{"name" : "//network.opiproject.org/vrfs/testvrf"}' localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.DeleteVrf
```
## Architecture Diagram
Expand Down
2 changes: 2 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"net"

pb "github.com/opiproject/opi-api/network/cloud/v1alpha1/gen/go"
pe "github.com/opiproject/opi-api/network/evpn-gw/v1alpha1/gen/go"
"github.com/opiproject/opi-evpn-bridge/pkg/evpn"

"google.golang.org/grpc"
Expand All @@ -33,6 +34,7 @@ func main() {

// TODO: replace cloud -> evpn
pb.RegisterCloudInfraServiceServer(s, opi)
pe.RegisterVrfServiceServer(s, opi)

reflection.Register(s)

Expand Down
35 changes: 19 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -270,27 +270,30 @@ services:
/entrypoint.sh ls localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.CreateInterface -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.CreateSubnet -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.CreateTunnel -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.CreateVpc -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.GetInterface -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.GetSubnet -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.GetTunnel -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.GetVpc -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.DeleteInterface -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.DeleteSubnet -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.DeleteTunnel -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.cloud.v1alpha1.CloudInfraService.DeleteVpc -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.evpn_gw.v1alpha1.VrfService -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.evpn_gw.v1alpha1.VrfService.CreateVrf -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.evpn_gw.v1alpha1.VrfService.ListVrf -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.evpn_gw.v1alpha1.VrfService.GetVrf -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.evpn_gw.v1alpha1.VrfService.DeleteVrf -l && \
/entrypoint.sh ls localhost:50151 opi_api.network.evpn_gw.v1alpha1.VrfService.UpdateVrf -l && \
echo create && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateVpc "{\"vpc\" : {\"spec\" : {\"v4_route_table_name_ref\" : \"1000\"} }, \"vpc_id\" : \"blue\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateVpc "{\"vpc\" : {\"spec\" : {\"v4_route_table_name_ref\" : \"1001\"} }, \"vpc_id\" : \"green\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateVpc "{\"vpc\" : {\"spec\" : {\"v4_route_table_name_ref\" : \"1002\"} }, \"vpc_id\" : \"yellow\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateSubnet "{\"subnet\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/vpcs/blue\", \"virtual_router_mac\": \"qrvMAAAB\" } }, \"subnet_id\" : \"br100\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateSubnet "{\"subnet\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/vpcs/green\", \"virtual_router_mac\": \"qrvMAAAC\" } }, \"subnet_id\" : \"br101\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateSubnet "{\"subnet\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/vpcs/yellow\", \"virtual_router_mac\": \"qrvMAAAD\" } }, \"subnet_id\" : \"br102\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateVrf "{\"vrf\" : {\"spec\" : {\"vni\" : 1000, \"loopback_ip_prefix\": {} }}, \"vrf_id\" : \"blue\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateVrf "{\"vrf\" : {\"spec\" : {\"vni\" : 1001, \"loopback_ip_prefix\": {} }}, \"vrf_id\" : \"green\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateVrf "{\"vrf\" : {\"spec\" : {\"vni\" : 1002, \"loopback_ip_prefix\": {} }}, \"vrf_id\" : \"yellow\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateSubnet "{\"subnet\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/vrfs/blue\", \"virtual_router_mac\": \"qrvMAAAB\" } }, \"subnet_id\" : \"br100\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateSubnet "{\"subnet\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/vrfs/green\", \"virtual_router_mac\": \"qrvMAAAC\" } }, \"subnet_id\" : \"br101\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateSubnet "{\"subnet\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/vrfs/yellow\", \"virtual_router_mac\": \"qrvMAAAD\" } }, \"subnet_id\" : \"br102\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateSubnet "{\"subnet\" : {\"spec\" : { \"virtual_router_mac\": \"qrvMAAAR\" } }, \"subnet_id\" : \"br10\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateSubnet "{\"subnet\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/vpcs/blue\", \"virtual_router_mac\": \"qrvMAAAh\", \"v4_prefix\": {\"addr\": 336860161, \"len\": 24} } }, \"subnet_id\" : \"br20\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateSubnet "{\"subnet\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/vpcs/blue\", \"virtual_router_mac\": \"qrvMAAAx\", \"v4_prefix\": {\"addr\": 505290241, \"len\": 24} } }, \"subnet_id\" : \"br30\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateSubnet "{\"subnet\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/vpcs/green\", \"virtual_router_mac\": \"qrvMAABB\", \"v4_prefix\": {\"addr\": 673720321, \"len\": 24} } }, \"subnet_id\" : \"br40\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateSubnet "{\"subnet\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/vpcs/yellow\", \"virtual_router_mac\": \"qrvMAABC\", \"v4_prefix\": {\"addr\": 842150401, \"len\": 24} } }, \"subnet_id\" : \"br50\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateSubnet "{\"subnet\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/vrfs/blue\", \"virtual_router_mac\": \"qrvMAAAh\", \"v4_prefix\": {\"addr\": 336860161, \"len\": 24} } }, \"subnet_id\" : \"br20\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateSubnet "{\"subnet\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/vrfs/blue\", \"virtual_router_mac\": \"qrvMAAAx\", \"v4_prefix\": {\"addr\": 505290241, \"len\": 24} } }, \"subnet_id\" : \"br30\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateSubnet "{\"subnet\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/vrfs/green\", \"virtual_router_mac\": \"qrvMAABB\", \"v4_prefix\": {\"addr\": 673720321, \"len\": 24} } }, \"subnet_id\" : \"br40\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateSubnet "{\"subnet\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/vrfs/yellow\", \"virtual_router_mac\": \"qrvMAABC\", \"v4_prefix\": {\"addr\": 842150401, \"len\": 24} } }, \"subnet_id\" : \"br50\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateTunnel "{\"tunnel\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/subnets/br100\", \"local_ip\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 167772162}, \"encap\": {\"type\": \"ENCAP_TYPE_VXLAN\", \"value\": {\"vnid\": 100}} } }, \"tunnel_id\" : \"vni100\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateTunnel "{\"tunnel\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/subnets/br101\", \"local_ip\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 167772162}, \"encap\": {\"type\": \"ENCAP_TYPE_VXLAN\", \"value\": {\"vnid\": 101}} } }, \"tunnel_id\" : \"vni101\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateTunnel "{\"tunnel\" : {\"spec\" : {\"vpc_name_ref\" : \"//network.opiproject.org/subnets/br102\", \"local_ip\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 167772162}, \"encap\": {\"type\": \"ENCAP_TYPE_VXLAN\", \"value\": {\"vnid\": 102}} } }, \"tunnel_id\" : \"vni102\", \"parent\" : \"todo\" }" && \
Expand All @@ -304,9 +307,9 @@ services:
/entrypoint.sh call --json_input --json_output localhost:50151 CreateInterface "{\"interface\" : {\"spec\" : {\"ifid\": 40, \"l3_if_spec\": {\"vpc_name_ref\" : \"//network.opiproject.org/subnets/br40\"}} }, \"interface_id\" : \"eth3\", \"parent\" : \"todo\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 CreateInterface "{\"interface\" : {\"spec\" : {\"ifid\": 50, \"l3_if_spec\": {\"vpc_name_ref\" : \"//network.opiproject.org/subnets/br50\"}} }, \"interface_id\" : \"eth4\", \"parent\" : \"todo\" }" && \
echo get && \
/entrypoint.sh call --json_input --json_output localhost:50151 GetVpc "{\"name\" : \"//network.opiproject.org/vpcs/blue\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 GetVpc "{\"name\" : \"//network.opiproject.org/vpcs/green\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 GetVpc "{\"name\" : \"//network.opiproject.org/vpcs/yellow\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 GetVrf "{\"name\" : \"//network.opiproject.org/vrfs/blue\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 GetVrf "{\"name\" : \"//network.opiproject.org/vrfs/green\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 GetVrf "{\"name\" : \"//network.opiproject.org/vrfs/yellow\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 GetSubnet "{\"name\" : \"//network.opiproject.org/subnets/br100\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 GetSubnet "{\"name\" : \"//network.opiproject.org/subnets/br101\" }" && \
/entrypoint.sh call --json_input --json_output localhost:50151 GetSubnet "{\"name\" : \"//network.opiproject.org/subnets/br102\" }" && \
Expand Down
6 changes: 4 additions & 2 deletions pkg/evpn/evpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ import (
"fmt"

pb "github.com/opiproject/opi-api/network/cloud/v1alpha1/gen/go"
pe "github.com/opiproject/opi-api/network/evpn-gw/v1alpha1/gen/go"
)

// Server represents the Server object
type Server struct {
pb.UnimplementedCloudInfraServiceServer
pe.UnimplementedVrfServiceServer
Subnets map[string]*pb.Subnet
Interfaces map[string]*pb.Interface
Tunnels map[string]*pb.Tunnel
Vpcs map[string]*pb.Vpc
Vrfs map[string]*pe.Vrf
}

// NewServer creates initialized instance of EVPN server
Expand All @@ -26,7 +28,7 @@ func NewServer() *Server {
Subnets: make(map[string]*pb.Subnet),
Interfaces: make(map[string]*pb.Interface),
Tunnels: make(map[string]*pb.Tunnel),
Vpcs: make(map[string]*pb.Vpc),
Vrfs: make(map[string]*pe.Vrf),
}
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/evpn/evpn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ import (
"google.golang.org/grpc/test/bufconn"

pb "github.com/opiproject/opi-api/network/cloud/v1alpha1/gen/go"
pe "github.com/opiproject/opi-api/network/evpn-gw/v1alpha1/gen/go"
)

// TODO: move test infrastructure code to a separate (test/server) package to avoid duplication

func dialer(opi *Server) func(context.Context, string) (net.Conn, error) {
listener := bufconn.Listen(1024 * 1024)
server := grpc.NewServer()

// TODO: replace cloud -> evpn
pb.RegisterCloudInfraServiceServer(server, opi)
pe.RegisterVrfServiceServer(server, opi)

go func() {
if err := server.Serve(listener); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/evpn/svi_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func (s *Server) CreateSubnet(_ context.Context, in *pb.CreateSubnetRequest) (*p
log.Printf("error: %v", err)
return nil, err
}
// now get VRF/VPC to plug this bridge into
vpc, ok := s.Vpcs[in.Subnet.Spec.VpcNameRef]
// now get VRF to plug this bridge into
vpc, ok := s.Vrfs[in.Subnet.Spec.VpcNameRef]
if !ok {
err := status.Errorf(codes.NotFound, "unable to find key %s", in.Subnet.Spec.VpcNameRef)
log.Printf("error: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/evpn/svi_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
testSubnetName = resourceIDToFullName("subnets", testSubnetID)
testSubnet = pb.Subnet{
Spec: &pb.SubnetSpec{
VpcNameRef: testVpcName,
VpcNameRef: testVrfName,
VirtualRouterMac: []byte("qrvMAAAB"),
V4Prefix: &pc.IPv4Prefix{
Addr: 336860161,
Expand Down Expand Up @@ -205,7 +205,7 @@ func Test_DeleteSubnet(t *testing.T) {

func Test_UpdateSubnet(t *testing.T) {
spec := &pb.SubnetSpec{
VpcNameRef: testVpcName,
VpcNameRef: testVrfName,
VirtualRouterMac: []byte("qrvMAAAB"),
V4Prefix: &pc.IPv4Prefix{
Addr: 336860161,
Expand Down
Loading

0 comments on commit 522e181

Please sign in to comment.