Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for GRE #1445

Merged
merged 8 commits into from
Sep 2, 2019
Merged

API for GRE #1445

merged 8 commits into from
Sep 2, 2019

Conversation

rewenset
Copy link
Contributor

@rewenset rewenset commented Aug 23, 2019

This PR implements GRE tunnel interface from #1387

@rewenset rewenset added the 🚧 WIP do not merge! work in progress! label Aug 23, 2019
@@ -22,6 +22,7 @@ message Interface {
IPSEC_TUNNEL = 8;
VMXNET3_INTERFACE = 9;
BOND_INTERFACE = 10;
GRE = 11;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be GRE_TUNNEL to match with other tunnel types.

Type tunnel_type = 1;
string src_addr = 2;
string dst_addr = 3;
uint32 outerFibID = 4;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instance uint32
IsIPv6 uint8
TunnelType uint8
SrcAddress string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using type net.IP here, will allow you to get rid of IsIPv6.

Copy link
Contributor Author

@rewenset rewenset Aug 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this will help. As I understand, you are saying about checking IsIPv6 in dump function:

if greDetails.IsIPv6 == 1 { ...

But in greDetails addresses comes as []byte and, for example, ip 10.10.10.10 will be presented as [10 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0], on the other hand ip 2019::8:23 will be presented as [32 25 0 0 0 0 0 0 0 0 0 0 0 8 0 35].

If I do not check IsIPv6 and not slice this slice if it's IPv4, then String() method on such net.IP in a case with 10.10.10.10 will return a0a:a0a:: and this is definitely not what I've expected to see.

One thing is actually redundant is calling To4() and To16(), because slice was already trimmed to proper size.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant was to use the net.IP values parsed in dump:

srcAddr = net.IP(greDetails.SrcAddress).To16().String()
dstAddr = net.IP(greDetails.DstAddress).To16().String()

And store as net.IP here:

SrcAddress: srcAddr,
DstAddress: dstAddr,

And the caller who calls dump can simply use the addresses directly without parsing them from string again. You can easily check if net.IP is IPv4 or IPv6:

	ip4 := net.ParseIP("10.0.1.1")
	fmt.Println(ip4)
	fmt.Printf("is IPv6: %v\n\n", ip4.To4() == nil) // prints false
	
	ip6 := net.ParseIP("fe80::200:5aee:feaa:20a2")
	fmt.Println(ip6)
	fmt.Printf("is IPv6: %v\n", ip6.To4() == nil) // prints true

https://play.golang.org/p/8WQKPMVmHJz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see now. Yes, it would be better to keep IP addresses as net.IP

t.Run(test.name, func(t *testing.T) {
ifIdx, err := h.AddGreTunnel(fmt.Sprintf("test%d", i), test.greLink)

if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this will handle test case where we expect some non-nil error, but it gets nil.

@rewenset
Copy link
Contributor Author

Manual tests with localclient:

VPP was not restarted during this tests

Definition of ERSPAN GRE tunnel in code

var (
	greInterface = &vpp_interfaces.Interface{
		Name:    "myGreInterface",
		Type:    vpp_interfaces.Interface_GRE_TUNNEL,
		Enabled: true,
		Link: &vpp_interfaces.Interface_Gre{
			Gre: &vpp_interfaces.GreLink{
				TunnelType: vpp_interfaces.GreLink_ERSPAN,
				SrcAddr:    "10.10.10.10",
				DstAddr:    "20.20.20.20",
			},
		},
	}
)

Create ERSPAN

+======================================================================================================================+
| #0 - NB Transaction                                                                                       FullResync |
+======================================================================================================================+
  * transaction arguments:
      - seqNum: 0
      - type: NB Transaction, Full Resync
      - values:
          - key: config/vpp/v2/interfaces/myGreInterface
            val: { name:"myGreInterface" type:GRE_TUNNEL enabled:true gre:<tunnel_type:ERSPAN src_addr:"10.10.10.10" dst_addr:"20.20.20.20" >  }

o----------------------------------------------------------------------------------------------------------------------o
  * executed operations (2019-08-29 10:43:20.272 +0300 EEST -> 2019-08-29 10:43:20.282 +0300 EEST, dur: 10ms):
      1. CREATE:
          - key: config/vpp/v2/interfaces/myGreInterface
          - value: { name:"myGreInterface" type:GRE_TUNNEL enabled:true gre:<tunnel_type:ERSPAN src_addr:"10.10.10.10" dst_addr:"20.20.20.20" >  }
x----------------------------------------------------------------------------------------------------------------------x
| #0 - NB Transaction                                                                                      took 10.1ms |
x----------------------------------------------------------------------------------------------------------------------x

+======================================================================================================================+
| #1 - SB Notification                                                                                                 |
+======================================================================================================================+
  * transaction arguments:
      - seqNum: 1
      - type: SB Notification
      - values:
          - key: vpp/interface/myGreInterface/link-state/UP
            val: <EMPTY>

INFO[0002] Transaction #0 successful! (took 10.4ms)      loc="orchestrator/dispatcher.go(179)" logger=dispatcher
o----------------------------------------------------------------------------------------------------------------------o
  * executed operations (2019-08-29 10:43:20.282 +0300 EEST -> 2019-08-29 10:43:20.282 +0300 EEST, dur: 0s):
      1. CREATE [OBTAINED]:
          - key: vpp/interface/myGreInterface/link-state/UP
          - value: <EMPTY>
x----------------------------------------------------------------------------------------------------------------------x
| #1 - SB Notification                                                                                      took 100µs |
x----------------------------------------------------------------------------------------------------------------------x

INFO[0002] Transaction 1 successful!                     loc="kvscheduler/txn_process.go(401)" logger=kvscheduler

Restart Agent (without restarting VPP)

+======================================================================================================================+
| #0 - NB Transaction                                                                                       FullResync |
+======================================================================================================================+
  * transaction arguments:
      - seqNum: 0
      - type: NB Transaction, Full Resync
      - values:
          - key: config/vpp/v2/interfaces/myGreInterface
            val: { name:"myGreInterface" type:GRE_TUNNEL enabled:true gre:<tunnel_type:ERSPAN src_addr:"10.10.10.10" dst_addr:"20.20.20.20" >  }

o----------------------------------------------------------------------------------------------------------------------o
  * executed operations:
      <NONE>
x----------------------------------------------------------------------------------------------------------------------x
| #0 - NB Transaction                                                                                       took 9.9ms |
x----------------------------------------------------------------------------------------------------------------------x

Disable interface

+======================================================================================================================+
| #1 - NB Transaction                                                                                       FullResync |
+======================================================================================================================+
  * transaction arguments:
      - seqNum: 1
      - type: NB Transaction, Full Resync
      - values:
          - key: config/vpp/v2/interfaces/myGreInterface
            val: { name:"myGreInterface" type:GRE_TUNNEL gre:<tunnel_type:ERSPAN src_addr:"10.10.10.10" dst_addr:"20.20.20.20" >  }

o----------------------------------------------------------------------------------------------------------------------o
  * executed operations (2019-08-29 10:53:58.354 +0300 EEST -> 2019-08-29 10:53:58.364 +0300 EEST, dur: 10ms):
      1. UPDATE:
          - key: config/vpp/v2/interfaces/myGreInterface
          - prev-value: { name:"myGreInterface" type:GRE_TUNNEL enabled:true phys_address:"d0:0b:ee:d0:00:00" gre:<tunnel_type:ERSPAN src_addr:"10.10.10.10" dst_addr:"20.20.20.20" >  }
          - new-value: { name:"myGreInterface" type:GRE_TUNNEL gre:<tunnel_type:ERSPAN src_addr:"10.10.10.10" dst_addr:"20.20.20.20" >  }
x----------------------------------------------------------------------------------------------------------------------x
| #1 - NB Transaction                                                                                       took 9.9ms |
x----------------------------------------------------------------------------------------------------------------------x

+======================================================================================================================+
| #2 - SB Notification                                                                                                 |
+======================================================================================================================+
  * transaction arguments:
      - seqNum: 2
      - type: SB Notification
      - values:
          - key: vpp/interface/myGreInterface/link-state/DOWN
            val: <EMPTY>
          - key: vpp/interface/myGreInterface/link-state/UP
            val: <NIL>

o----------------------------------------------------------------------------------------------------------------------o
  * executed operations (2019-08-29 10:53:58.365 +0300 EEST -> 2019-08-29 10:53:58.365 +0300 EEST, dur: 0s):
      1. DELETE [WAS-OBTAINED]:
          - key: vpp/interface/myGreInterface/link-state/UP
          - value: <EMPTY>
      2. CREATE [OBTAINED]:
          - key: vpp/interface/myGreInterface/link-state/DOWN
          - value: <EMPTY>
x----------------------------------------------------------------------------------------------------------------------x
| #2 - SB Notification                                                                                      took 200µs |
x----------------------------------------------------------------------------------------------------------------------x

Change "Source" for GRE tunnel

+======================================================================================================================+
| #3 - NB Transaction                                                                                       FullResync |
+======================================================================================================================+
  * transaction arguments:
      - seqNum: 3
      - type: NB Transaction, Full Resync
      - values:
          - key: config/vpp/v2/interfaces/myGreInterface
            val: { name:"myGreInterface" type:GRE_TUNNEL gre:<tunnel_type:ERSPAN src_addr:"30.30.30.30" dst_addr:"20.20.20.20" >  }

o----------------------------------------------------------------------------------------------------------------------o
  * executed operations (2019-08-29 10:54:03.365 +0300 EEST -> 2019-08-29 10:54:03.371 +0300 EEST, dur: 5ms):
      1. DELETE [RECREATE]:
          - key: config/vpp/v2/interfaces/myGreInterface
          - value: { name:"myGreInterface" type:GRE_TUNNEL phys_address:"d0:0b:ee:d0:00:00" gre:<tunnel_type:ERSPAN src_addr:"10.10.10.10" dst_addr:"20.20.20.20" >  }
      2. CREATE [RECREATE]:
          - key: config/vpp/v2/interfaces/myGreInterface
          - value: { name:"myGreInterface" type:GRE_TUNNEL gre:<tunnel_type:ERSPAN src_addr:"30.30.30.30" dst_addr:"20.20.20.20" >  }
x----------------------------------------------------------------------------------------------------------------------x
| #3 - NB Transaction                                                                                       took 5.5ms |
x----------------------------------------------------------------------------------------------------------------------x

+======================================================================================================================+
| #4 - SB Notification                                                                                                 |
+======================================================================================================================+
  * transaction arguments:
      - seqNum: 4
      - type: SB Notification
      - values:
          - key: vpp/interface/myGreInterface/link-state/DOWN
            val: <NIL>

INFO[0012] Transaction #3 successful! (took 5.6ms)       loc="orchestrator/dispatcher.go(179)" logger=dispatcher
o----------------------------------------------------------------------------------------------------------------------o
  * executed operations (2019-08-29 10:54:03.371 +0300 EEST -> 2019-08-29 10:54:03.371 +0300 EEST, dur: 0s):
      1. DELETE [WAS-OBTAINED]:
          - key: vpp/interface/myGreInterface/link-state/DOWN
          - value: <EMPTY>
x----------------------------------------------------------------------------------------------------------------------x
| #4 - SB Notification                                                                                      took 100µs |
x----------------------------------------------------------------------------------------------------------------------x

INFO[0012] Transaction 4 successful!                     loc="kvscheduler/txn_process.go(401)" logger=kvscheduler

Enable interface

+======================================================================================================================+
| #5 - NB Transaction                                                                                       FullResync |
+======================================================================================================================+
  * transaction arguments:
      - seqNum: 5
      - type: NB Transaction, Full Resync
      - values:
          - key: config/vpp/v2/interfaces/myGreInterface
            val: { name:"myGreInterface" type:GRE_TUNNEL enabled:true gre:<tunnel_type:ERSPAN src_addr:"30.30.30.30" dst_addr:"20.20.20.20" >  }

o----------------------------------------------------------------------------------------------------------------------o
  * executed operations (2019-08-29 11:04:06.203 +0300 EEST -> 2019-08-29 11:04:06.212 +0300 EEST, dur: 9ms):
      1. UPDATE:
          - key: config/vpp/v2/interfaces/myGreInterface
          - prev-value: { name:"myGreInterface" type:GRE_TUNNEL phys_address:"d0:0b:ee:d0:00:00" gre:<tunnel_type:ERSPAN src_addr:"30.30.30.30" dst_addr:"20.20.20.20" >  }
          - new-value: { name:"myGreInterface" type:GRE_TUNNEL enabled:true gre:<tunnel_type:ERSPAN src_addr:"30.30.30.30" dst_addr:"20.20.20.20" >  }
x----------------------------------------------------------------------------------------------------------------------x
| #5 - NB Transaction                                                                                       took 8.5ms |
x----------------------------------------------------------------------------------------------------------------------x

+======================================================================================================================+
| #6 - SB Notification                                                                                                 |
+======================================================================================================================+
  * transaction arguments:
      - seqNum: 6
      - type: SB Notification
      - values:
          - key: vpp/interface/myGreInterface/link-state/DOWN
            val: <NIL>
          - key: vpp/interface/myGreInterface/link-state/UP
            val: <EMPTY>

INFO[0017] Transaction #5 successful! (took 8.8ms)       loc="orchestrator/dispatcher.go(179)" logger=dispatcher
o----------------------------------------------------------------------------------------------------------------------o
  * executed operations (2019-08-29 11:04:06.212 +0300 EEST -> 2019-08-29 11:04:06.212 +0300 EEST, dur: 0s):
      1. DELETE [WAS-OBTAINED]:
          - key: vpp/interface/myGreInterface/link-state/DOWN
          - value: <EMPTY>
      2. CREATE [OBTAINED]:
          - key: vpp/interface/myGreInterface/link-state/UP
          - value: <EMPTY>
x----------------------------------------------------------------------------------------------------------------------x
| #6 - SB Notification                                                                                      took 100µs |
x----------------------------------------------------------------------------------------------------------------------x

INFO[0017] Transaction 6 successful!                     loc="kvscheduler/txn_process.go(401)" logger=kvscheduler

Stop Agent, change source address and start Agent again

+======================================================================================================================+
| #0 - NB Transaction                                                                                       FullResync |
+======================================================================================================================+
  * transaction arguments:
      - seqNum: 0
      - type: NB Transaction, Full Resync
      - values:
          - key: config/vpp/v2/interfaces/myGreInterface
            val: { name:"myGreInterface" type:GRE_TUNNEL enabled:true gre:<tunnel_type:ERSPAN src_addr:"10.10.10.10" dst_addr:"20.20.20.20" >  }

o----------------------------------------------------------------------------------------------------------------------o
  * executed operations (2019-08-29 11:08:29.609 +0300 EEST -> 2019-08-29 11:08:29.622 +0300 EEST, dur: 13ms):
      1. DELETE [RECREATE DISCOVERED]:
          - key: config/vpp/v2/interfaces/myGreInterface
          - value: { name:"myGreInterface" type:GRE_TUNNEL enabled:true phys_address:"d0:0b:ee:d0:00:00" gre:<tunnel_type:ERSPAN src_addr:"30.30.30.30" dst_addr:"20.20.20.20" >  } 
      2. CREATE [RECREATE]:
          - key: config/vpp/v2/interfaces/myGreInterface
          - value: { name:"myGreInterface" type:GRE_TUNNEL enabled:true gre:<tunnel_type:ERSPAN src_addr:"10.10.10.10" dst_addr:"20.20.20.20" >  } 
x----------------------------------------------------------------------------------------------------------------------x
| #0 - NB Transaction                                                                                      took 12.6ms |
x----------------------------------------------------------------------------------------------------------------------x

INFO[0002] Transaction #0 successful! (took 13.1ms)      loc="orchestrator/dispatcher.go(179)" logger=dispatcher

Stop Agent, add one more GRE tunnel in code, start Agent

+======================================================================================================================+
| #0 - NB Transaction                                                                                       FullResync |
+======================================================================================================================+
  * transaction arguments:
      - seqNum: 0
      - type: NB Transaction, Full Resync
      - values:
          - key: config/vpp/v2/interfaces/myGreInterface
            val: { name:"myGreInterface" type:GRE_TUNNEL enabled:true gre:<tunnel_type:ERSPAN src_addr:"10.10.10.10" dst_addr:"20.20.20.20" >  }
          - key: config/vpp/v2/interfaces/myGreNextGen
            val: { name:"myGreNextGen" type:GRE_TUNNEL enabled:true gre:<tunnel_type:ERSPAN src_addr:"10.10.10.10" dst_addr:"30.30.30.30" >  }

o----------------------------------------------------------------------------------------------------------------------o
  * executed operations (2019-08-29 11:20:33.578 +0300 EEST -> 2019-08-29 11:20:33.582 +0300 EEST, dur: 4ms):
      1. CREATE:
          - key: config/vpp/v2/interfaces/myGreNextGen
          - value: { name:"myGreNextGen" type:GRE_TUNNEL enabled:true gre:<tunnel_type:ERSPAN src_addr:"10.10.10.10" dst_addr:"30.30.30.30" >  }
x----------------------------------------------------------------------------------------------------------------------x
| #0 - NB Transaction                                                                                       took 3.7ms |
x----------------------------------------------------------------------------------------------------------------------x

+======================================================================================================================+
| #1 - SB Notification                                                                                                 |
+======================================================================================================================+
  * transaction arguments:
      - seqNum: 1
      - type: SB Notification
      - values:
          - key: vpp/interface/myGreNextGen/link-state/UP
            val: <EMPTY>

INFO[0002] Transaction #0 successful! (took 3.8ms)       loc="orchestrator/dispatcher.go(179)" logger=dispatcher
o----------------------------------------------------------------------------------------------------------------------o
  * executed operations (2019-08-29 11:20:33.582 +0300 EEST -> 2019-08-29 11:20:33.582 +0300 EEST, dur: 0s):
      1. CREATE [OBTAINED]:
          - key: vpp/interface/myGreNextGen/link-state/UP
          - value: <EMPTY>
x----------------------------------------------------------------------------------------------------------------------x
| #1 - SB Notification                                                                                      took 100µs |
x----------------------------------------------------------------------------------------------------------------------x

INFO[0002] Transaction 1 successful!                     loc="kvscheduler/txn_process.go(401)" logger=kvscheduler

Output from vppctl after all of this

    _______    _        _   _____  ___ 
 __/ __/ _ \  (_)__    | | / / _ \/ _ \
 _/ _// // / / / _ \   | |/ / ___/ ___/
 /_/ /____(_)_/\___/   |___/_/  /_/    

vpp# sh ver
vpp v19.04-6~g6f05f724f built by [...]
vpp# sh int
              Name               Idx    State  MTU (L3/IP4/IP6/MPLS)     Counter          Count     
gre0                              1      up          9000/0/0/0     
gre1                              2      up          9000/0/0/0     
local0                            0     down          0/0/0/0       
vpp# sh gre tun
[0] instance 0 src 10.10.10.10 dst 20.20.20.20 fib-idx 0 sw-if-idx 1 payload ERSPAN session 0 l2-adj-idx 0 
[1] instance 1 src 10.10.10.10 dst 30.30.30.30 fib-idx 0 sw-if-idx 2 payload ERSPAN session 0 l2-adj-idx 1 
vpp# 

Copy link
Collaborator

@milanlenco milanlenco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! Also thanks for the summary of manual tests. Soon we will have a framework to write end-to-end tests as Go UTs (just like we have integration tests for vppcalls), so it will be possible to automate all of that.

@rewenset rewenset changed the title WIP: API for GRE API for GRE Aug 30, 2019
@rewenset rewenset removed the 🚧 WIP do not merge! work in progress! label Aug 30, 2019
@ondrej-fabry ondrej-fabry merged commit 3814f0f into ligato:dev Sep 2, 2019
VladoLavor pushed a commit to VladoLavor/vpp-agent that referenced this pull request Oct 4, 2019
* Add GRE VPP calls. Add GRE type and link to inteface message

* add basic validation and support of create and delete operations for GRE

* Rename things. Store addresses as net.IP

* add GRE to interfaces dump

* Add UNKNOWN to types of GRE tunnel

* Support vpp1901 and vpp1908

* Test also removing of GRE tunnel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants