diff --git a/docker-compose.yml b/docker-compose.yml index b972e1a5..f68b9859 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -250,11 +250,11 @@ services: /entrypoint.sh call --json_input --json_output localhost:50151 CreateVrf "{\"vrf_id\" : \"blue\", \"vrf\" : {\"spec\" : { \"loopback_ip_prefix\": {\"addr\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 167772418}, \"len\": 32}, \"vtep_ip_prefix\": {\"addr\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 167772162}, \"len\": 32} }} }" && \ /entrypoint.sh call --json_input --json_output localhost:50151 CreateVrf "{\"vrf_id\" : \"green\", \"vrf\" : {\"spec\" : {\"vni\" : 100, \"loopback_ip_prefix\": {\"addr\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 167772674}, \"len\": 32}, \"vtep_ip_prefix\": {\"addr\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 167772162}, \"len\": 32} }} }" && \ /entrypoint.sh call --json_input --json_output localhost:50151 CreateVrf "{\"vrf_id\" : \"yellow\", \"vrf\" : {\"spec\" : {\"vni\" : 101, \"loopback_ip_prefix\": {\"addr\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 167772930}, \"len\": 32}, \"vtep_ip_prefix\": {\"addr\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 167772162}, \"len\": 32} }} }" && \ - /entrypoint.sh call --json_input --json_output localhost:50151 CreateLogicalBridge "{\"logical_bridge_id\" : \"vlan10\", \"logical_bridge\" : {\"spec\" : {\"vni\" : 10, \"vlan_id\": 10 }} }" && \ - /entrypoint.sh call --json_input --json_output localhost:50151 CreateLogicalBridge "{\"logical_bridge_id\" : \"vlan20\", \"logical_bridge\" : {\"spec\" : {\"vni\" : 20, \"vlan_id\": 20 }} }" && \ - /entrypoint.sh call --json_input --json_output localhost:50151 CreateLogicalBridge "{\"logical_bridge_id\" : \"vlan30\", \"logical_bridge\" : {\"spec\" : {\"vni\" : 30, \"vlan_id\": 30 }} }" && \ - /entrypoint.sh call --json_input --json_output localhost:50151 CreateLogicalBridge "{\"logical_bridge_id\" : \"vlan40\", \"logical_bridge\" : {\"spec\" : {\"vni\" : 40, \"vlan_id\": 40 }} }" && \ - /entrypoint.sh call --json_input --json_output localhost:50151 CreateLogicalBridge "{\"logical_bridge_id\" : \"vlan50\", \"logical_bridge\" : {\"spec\" : { \"vlan_id\": 50 }} }" && \ + /entrypoint.sh call --json_input --json_output localhost:50151 CreateLogicalBridge "{\"logical_bridge_id\" : \"vlan10\", \"logical_bridge\" : {\"spec\" : {\"vni\" : 10, \"vlan_id\": 10, \"vtep_ip_prefix\": {\"addr\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 167772162}, \"len\": 24} }} }" && \ + /entrypoint.sh call --json_input --json_output localhost:50151 CreateLogicalBridge "{\"logical_bridge_id\" : \"vlan20\", \"logical_bridge\" : {\"spec\" : {\"vni\" : 20, \"vlan_id\": 20, \"vtep_ip_prefix\": {\"addr\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 167772162}, \"len\": 24} }} }" && \ + /entrypoint.sh call --json_input --json_output localhost:50151 CreateLogicalBridge "{\"logical_bridge_id\" : \"vlan30\", \"logical_bridge\" : {\"spec\" : {\"vni\" : 30, \"vlan_id\": 30, \"vtep_ip_prefix\": {\"addr\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 167772162}, \"len\": 24} }} }" && \ + /entrypoint.sh call --json_input --json_output localhost:50151 CreateLogicalBridge "{\"logical_bridge_id\" : \"vlan40\", \"logical_bridge\" : {\"spec\" : {\"vni\" : 40, \"vlan_id\": 40, \"vtep_ip_prefix\": {\"addr\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 167772162}, \"len\": 24} }} }" && \ + /entrypoint.sh call --json_input --json_output localhost:50151 CreateLogicalBridge "{\"logical_bridge_id\" : \"vlan50\", \"logical_bridge\" : {\"spec\" : { \"vlan_id\": 50, \"vtep_ip_prefix\": {\"addr\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 167772162}, \"len\": 24} }} }" && \ /entrypoint.sh call --json_input --json_output localhost:50151 CreateSvi "{\"svi_id\" : \"blue-vlan20\", \"svi\" : {\"spec\" : {\"vrf\": \"//network.opiproject.org/vrfs/blue\", \"logical_bridge\": \"//network.opiproject.org/bridges/vlan20\", \"mac_address\" : \"qrvMAAAh\", \"gw_ip_prefix\": [{\"addr\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 336860161}, \"len\": 24}] }} }" && \ /entrypoint.sh call --json_input --json_output localhost:50151 CreateSvi "{\"svi_id\" : \"blue-vlan30\", \"svi\" : {\"spec\" : {\"vrf\": \"//network.opiproject.org/vrfs/blue\", \"logical_bridge\": \"//network.opiproject.org/bridges/vlan30\", \"mac_address\" : \"qrvMAAAx\", \"gw_ip_prefix\": [{\"addr\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 505290241}, \"len\": 24}] }} }" && \ /entrypoint.sh call --json_input --json_output localhost:50151 CreateSvi "{\"svi_id\" : \"green-vlan40\", \"svi\" : {\"spec\" : {\"vrf\": \"//network.opiproject.org/vrfs/green\", \"logical_bridge\": \"//network.opiproject.org/bridges/vlan40\", \"mac_address\" : \"qrvMAABB\", \"gw_ip_prefix\": [{\"addr\": {\"af\": \"IP_AF_INET\", \"v4_addr\": 673720321}, \"len\": 24}] }} }" && \ diff --git a/go.mod b/go.mod index 474c51a8..a838da9f 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/opiproject/opi-evpn-bridge go 1.19 require ( - github.com/opiproject/opi-api v0.0.0-20230831141553-56e46f754823 + github.com/opiproject/opi-api v0.0.0-20230905130004-eac732ac240b github.com/stretchr/testify v1.8.4 github.com/vishvananda/netlink v1.2.1-beta.2 go.einride.tech/aip v0.62.0 @@ -19,10 +19,10 @@ require ( github.com/stretchr/objx v0.5.0 // indirect github.com/vishvananda/netns v0.0.4 // indirect golang.org/x/net v0.14.0 // indirect - golang.org/x/sys v0.11.0 // indirect - golang.org/x/text v0.12.0 // indirect - google.golang.org/genproto v0.0.0-20230807174057-1744710a1577 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20230807174057-1744710a1577 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 // indirect + golang.org/x/sys v0.12.0 // indirect + golang.org/x/text v0.13.0 // indirect + google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 4a2ed160..b5a7f873 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,8 @@ github.com/opiproject/opi-api v0.0.0-20230826011814-48b273e85a4f h1:LGBMsOd0tDVn github.com/opiproject/opi-api v0.0.0-20230826011814-48b273e85a4f/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY= github.com/opiproject/opi-api v0.0.0-20230831141553-56e46f754823 h1:MrJE4bh6zSYVkf78Wz+lzD8TsFnn/OFn7l0S0WFkJR8= github.com/opiproject/opi-api v0.0.0-20230831141553-56e46f754823/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY= +github.com/opiproject/opi-api v0.0.0-20230905130004-eac732ac240b h1:jAEYUnARydKpnJkB8WgDqk6Awiq0b+SZHgtq+McAdXI= +github.com/opiproject/opi-api v0.0.0-20230905130004-eac732ac240b/go.mod h1:92pv4ulvvPMuxCJ9ND3aYbmBfEMLx0VCjpkiR7ZTqPY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -37,15 +39,25 @@ golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/genproto v0.0.0-20230807174057-1744710a1577 h1:Tyk/35yqszRCvaragTn5NnkY6IiKk/XvHzEWepo71N0= google.golang.org/genproto v0.0.0-20230807174057-1744710a1577/go.mod h1:yZTlhN0tQnXo3h00fuXNCxJdLdIdnVFVBaRJ5LWBbw4= +google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d h1:VBu5YqKPv6XiJ199exd8Br+Aetz+o08F+PLMnwJQHAY= +google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d/go.mod h1:yZTlhN0tQnXo3h00fuXNCxJdLdIdnVFVBaRJ5LWBbw4= google.golang.org/genproto/googleapis/api v0.0.0-20230807174057-1744710a1577 h1:xv8KoglAClYGkprUSmDTKaILtzfD8XzG9NYVXMprjKo= google.golang.org/genproto/googleapis/api v0.0.0-20230807174057-1744710a1577/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk= +google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d h1:DoPTO70H+bcDXcd39vOqb2viZxgqeBeSGtZ55yZU4/Q= +google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk= google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 h1:wukfNtZmZUurLN/atp2hiIeTKn7QJWIQdHzqmsOnAOk= google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw= google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= diff --git a/pkg/evpn/bridge.go b/pkg/evpn/bridge.go index 17571376..96986377 100644 --- a/pkg/evpn/bridge.go +++ b/pkg/evpn/bridge.go @@ -68,8 +68,7 @@ func (s *Server) CreateLogicalBridge(_ context.Context, in *pb.CreateLogicalBrid } // Example: ip link add vxlan- type vxlan id local dstport 4789 nolearning proxy myip := make(net.IP, 4) - // TODO: remove hard-coded 167772162 == "10.0.0.2" - binary.BigEndian.PutUint32(myip, 167772162) + binary.BigEndian.PutUint32(myip, in.LogicalBridge.Spec.VtepIpPrefix.Addr.GetV4Addr()) vxlanName := fmt.Sprintf("vni%d", *in.LogicalBridge.Spec.Vni) vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: vxlanName}, VxlanId: int(*in.LogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip} log.Printf("Creating Vxlan %v", vxlan) diff --git a/pkg/evpn/bridge_test.go b/pkg/evpn/bridge_test.go index 3f2f2de1..7a3d8764 100644 --- a/pkg/evpn/bridge_test.go +++ b/pkg/evpn/bridge_test.go @@ -27,6 +27,7 @@ import ( "google.golang.org/protobuf/types/known/fieldmaskpb" pb "github.com/opiproject/opi-api/network/evpn-gw/v1alpha1/gen/go" + pc "github.com/opiproject/opi-api/network/opinetcommon/v1alpha1/gen/go" "github.com/opiproject/opi-evpn-bridge/pkg/utils/mocks" ) @@ -38,6 +39,15 @@ var ( Spec: &pb.LogicalBridgeSpec{ Vni: proto.Uint32(11), VlanId: 22, + VtepIpPrefix: &pc.IPPrefix{ + Addr: &pc.IPAddress{ + Af: pc.IpAf_IP_AF_INET, + V4OrV6: &pc.IPAddress_V4Addr{ + V4Addr: 167772162, + }, + }, + Len: 24, + }, }, } )