Re: [ovs-dev] [PATCH v1] tests: Added NSH related unit test cases for datapath

2018-04-17 Thread Ben Pfaff
On Mon, Apr 16, 2018 at 02:58:34PM -0700, Gregory Rose wrote:
> On 4/11/2018 11:13 AM, Ashish Varma wrote:
> >Sure, no problem.
> >
> >Thanks,
> >Ashish
> >
> >On Tue, Apr 10, 2018 at 5:00 PM, Gregory Rose  >> wrote:
> >
> >On 4/6/2018 7:35 AM, Gregory Rose wrote:
> >
> >
> >
> >On 4/4/2018 10:23 AM, Ben Pfaff wrote:
> >
> >On Thu, Mar 29, 2018 at 04:46:09PM -0700, Ashish Varma wrote:
> >
> >Added test cases for encap, decap, replace and
> >forwarding of NSH packets.
> >Also added a python script 'sendpkt.py' to send hex
> >ethernet frames.
> >
> >Signed-off-by: Ashish Varma  >>
> >
> >Ashish, do you have a suggestion who should review this? 
> >Greg, are you
> >the right person?
> >
> >I can have a look at them now that I'm back but need to get
> >caught up with some other issues first.
> >
> >
> >Ashish,
> >
> >I continue to be otherwise occupied so I'm sorry for the delay in
> >reviewing your patch.  It is still on my radar!
> >
> >Thanks,
> >
> >- Greg
> >
> 
> Looks good - tests out alright to me:
> 
> set /bin/bash '../tests/system-kmod-testsuite' -C tests 
> AUTOTEST_PATH='utilities:vswitchd:ovsdb:vtep:tests::/usr:ovn/controller-vtep:ovn/northd:ovn/utilities:ovn/controller'
> -k nsh -j1; \
> "$@" || (test X'' = Xyes && "$@" --recheck)
> ## -- ##
> ## openvswitch 2.9.90 test suite. ##
> ## -- ##
> 
> nsh-datapath
> 
>  91: nsh - encap header  ok
>  92: nsh - decap header  ok
>  93: nsh - replace header    ok
>  94: nsh - forward   ok
> 
> ## - ##
> ## Test results. ##
> ## - ##
> 
> All 4 tests were successful.
> 
> And the script code looks fine to me as well.
> 
> Tested-by: Greg Rose 
> Reviewed-by: Greg Rose 

Thanks Greg and Ashish.

I folded in the following to make the build-time Python checking OK with
it (also fixed a spelling error "eode" => "code"), added Greg's tags,
and applied this to master.

Thanks again!

Ben

--8<--cut here-->8--

diff --git a/tests/sendpkt.py b/tests/sendpkt.py
index 6d16d0f45e9e..50a4795ebf34 100755
--- a/tests/sendpkt.py
+++ b/tests/sendpkt.py
@@ -26,7 +26,6 @@
 
 
 import socket
-import struct
 import sys
 from optparse import OptionParser
 
@@ -72,23 +71,23 @@ pkt = "".join(map(chr, hex_list))
 try:
 sockfd = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)
 except socket.error as msg:
-print 'unable to create socket! error eode: ' + str(msg[0]) + ' : '\
-+ msg[1]
+print('unable to create socket! error code: ' + str(msg[0]) + ' : '
++ msg[1])
 sys.exit(2)
 
 try:
 sockfd.bind((args[0], 0))
 except socket.error as msg:
-print 'unable to bind socket! error eode: ' + str(msg[0]) + ' : '\
-+ msg[1]
+print('unable to bind socket! error code: ' + str(msg[0]) + ' : '
++ msg[1])
 sys.exit(2)
 
 try:
 sockfd.send(pkt)
 except socket.error as msg:
-print 'unable to send packet! error eode: ' + str(msg[0]) + ' : '\
-+ msg[1]
+print('unable to send packet! error code: ' + str(msg[0]) + ' : '
++ msg[1])
 sys.exit(2)
 
-print 'send success!'
+print('send success!')
 sys.exit(0)
___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


Re: [ovs-dev] [PATCH v1] tests: Added NSH related unit test cases for datapath

2018-04-16 Thread Gregory Rose

On 4/11/2018 11:13 AM, Ashish Varma wrote:

Sure, no problem.

Thanks,
Ashish

On Tue, Apr 10, 2018 at 5:00 PM, Gregory Rose > wrote:


On 4/6/2018 7:35 AM, Gregory Rose wrote:



On 4/4/2018 10:23 AM, Ben Pfaff wrote:

On Thu, Mar 29, 2018 at 04:46:09PM -0700, Ashish Varma wrote:

Added test cases for encap, decap, replace and
forwarding of NSH packets.
Also added a python script 'sendpkt.py' to send hex
ethernet frames.

Signed-off-by: Ashish Varma mailto:ashishvarma@gmail.com>>

Ashish, do you have a suggestion who should review this? 
Greg, are you
the right person?

I can have a look at them now that I'm back but need to get
caught up with some other issues first.


Ashish,

I continue to be otherwise occupied so I'm sorry for the delay in
reviewing your patch.  It is still on my radar!

Thanks,

- Greg



Looks good - tests out alright to me:

set /bin/bash '../tests/system-kmod-testsuite' -C tests 
AUTOTEST_PATH='utilities:vswitchd:ovsdb:vtep:tests::/usr:ovn/controller-vtep:ovn/northd:ovn/utilities:ovn/controller' 
-k nsh -j1; \

"$@" || (test X'' = Xyes && "$@" --recheck)
## -- ##
## openvswitch 2.9.90 test suite. ##
## -- ##

nsh-datapath

 91: nsh - encap header  ok
 92: nsh - decap header  ok
 93: nsh - replace header    ok
 94: nsh - forward   ok

## - ##
## Test results. ##
## - ##

All 4 tests were successful.

And the script code looks fine to me as well.

Tested-by: Greg Rose 
Reviewed-by: Greg Rose 

___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


Re: [ovs-dev] [PATCH v1] tests: Added NSH related unit test cases for datapath

2018-04-11 Thread Ashish Varma
Sure, no problem.

Thanks,
Ashish

On Tue, Apr 10, 2018 at 5:00 PM, Gregory Rose  wrote:

> On 4/6/2018 7:35 AM, Gregory Rose wrote:
>
>>
>>
>> On 4/4/2018 10:23 AM, Ben Pfaff wrote:
>>
>>> On Thu, Mar 29, 2018 at 04:46:09PM -0700, Ashish Varma wrote:
>>>
 Added test cases for encap, decap, replace and forwarding of NSH
 packets.
 Also added a python script 'sendpkt.py' to send hex ethernet frames.

 Signed-off-by: Ashish Varma 

>>> Ashish, do you have a suggestion who should review this?  Greg, are you
>>> the right person?
>>>
>> I can have a look at them now that I'm back but need to get caught up
>> with some other issues first.
>>
>
> Ashish,
>
> I continue to be otherwise occupied so I'm sorry for the delay in
> reviewing your patch.  It is still on my radar!
>
> Thanks,
>
> - Greg
>
>
>> Thanks,
>>
>> - Greg
>>
>
>
___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


Re: [ovs-dev] [PATCH v1] tests: Added NSH related unit test cases for datapath

2018-04-10 Thread Gregory Rose

On 4/6/2018 7:35 AM, Gregory Rose wrote:



On 4/4/2018 10:23 AM, Ben Pfaff wrote:

On Thu, Mar 29, 2018 at 04:46:09PM -0700, Ashish Varma wrote:
Added test cases for encap, decap, replace and forwarding of NSH 
packets.

Also added a python script 'sendpkt.py' to send hex ethernet frames.

Signed-off-by: Ashish Varma 

Ashish, do you have a suggestion who should review this?  Greg, are you
the right person?
I can have a look at them now that I'm back but need to get caught up 
with some other issues first.


Ashish,

I continue to be otherwise occupied so I'm sorry for the delay in 
reviewing your patch.  It is still on my radar!


Thanks,

- Greg



Thanks,

- Greg


___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


Re: [ovs-dev] [PATCH v1] tests: Added NSH related unit test cases for datapath

2018-04-06 Thread Gregory Rose



On 4/4/2018 10:23 AM, Ben Pfaff wrote:

On Thu, Mar 29, 2018 at 04:46:09PM -0700, Ashish Varma wrote:

Added test cases for encap, decap, replace and forwarding of NSH packets.
Also added a python script 'sendpkt.py' to send hex ethernet frames.

Signed-off-by: Ashish Varma 

Ashish, do you have a suggestion who should review this?  Greg, are you
the right person?
I can have a look at them now that I'm back but need to get caught up 
with some other issues first.


Thanks,

- Greg
___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


Re: [ovs-dev] [PATCH v1] tests: Added NSH related unit test cases for datapath

2018-04-04 Thread Ben Pfaff
On Thu, Mar 29, 2018 at 04:46:09PM -0700, Ashish Varma wrote:
> Added test cases for encap, decap, replace and forwarding of NSH packets.
> Also added a python script 'sendpkt.py' to send hex ethernet frames.
> 
> Signed-off-by: Ashish Varma 

Ashish, do you have a suggestion who should review this?  Greg, are you
the right person?
___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


[ovs-dev] [PATCH v1] tests: Added NSH related unit test cases for datapath

2018-03-29 Thread Ashish Varma
Added test cases for encap, decap, replace and forwarding of NSH packets.
Also added a python script 'sendpkt.py' to send hex ethernet frames.

Signed-off-by: Ashish Varma 
---
 tests/automake.mk   |   4 +-
 tests/sendpkt.py|  94 
 tests/system-traffic.at | 163 
 3 files changed, 260 insertions(+), 1 deletion(-)
 create mode 100755 tests/sendpkt.py

diff --git a/tests/automake.mk b/tests/automake.mk
index 780d3b8..0796123 100644
--- a/tests/automake.mk
+++ b/tests/automake.mk
@@ -400,7 +400,9 @@ CHECK_PYFILES = \
tests/test-unix-socket.py \
tests/test-unixctl.py \
tests/test-vlog.py \
-   tests/uuidfilt.py
+   tests/uuidfilt.py \
+   tests/sendpkt.py
+
 EXTRA_DIST += $(CHECK_PYFILES)
 PYCOV_CLEAN_FILES += $(CHECK_PYFILES:.py=.py,cover) .coverage
 
diff --git a/tests/sendpkt.py b/tests/sendpkt.py
new file mode 100755
index 000..6d16d0f
--- /dev/null
+++ b/tests/sendpkt.py
@@ -0,0 +1,94 @@
+#! /usr/bin/env python
+
+# Copyright (c) 2018 VMware, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# This program can be used send L2-L7 protocol messages using the hex bytes
+# of the packet, to test simple protocol scenarios. (e.g. generate simple
+# nsh packets to test nsh match fields/actions)
+#
+# Currently, the script supports sending the packets starting from the
+# Ethernet header. As a part of future enchancement, raw ip packet support
+# can also be added, and that's why there is "-t"/"--type" option
+#
+
+
+import socket
+import struct
+import sys
+from optparse import OptionParser
+
+
+usage = "usage: %prog [OPTIONS] OUT-INTERFACE HEX-BYTES \n \
+ bytes in HEX-BYTES must be separated by space(s)"
+parser = OptionParser(usage=usage)
+parser.add_option("-t", "--type", type="string", dest="packet_type",
+  help="packet type ('eth' is the default PACKET_TYPE)",
+  default="eth")
+
+(options, args) = parser.parse_args()
+
+# validate the arguments
+if len(args) < 2:
+parser.print_help()
+sys.exit(1)
+
+# validate the "-t" or "--type" option
+if options.packet_type != "eth":
+parser.error('invalid argument to "-t"/"--type". Allowed value is "eth".')
+
+# store the hex bytes with 0x appended at the beginning
+# if not present in the user input and validate the hex bytes
+hex_list = []
+for a in args[1:]:
+if a[:2] != "0x":
+hex_byte = "0x" + a
+else:
+hex_byte = a
+try:
+temp = int(hex_byte, 0)
+except:
+parser.error("invalid hex byte " + a)
+
+if temp > 0xff:
+parser.error("hex byte " + a + " cannot be greater than 0xff!")
+
+hex_list.append(temp)
+
+pkt = "".join(map(chr, hex_list))
+
+try:
+sockfd = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)
+except socket.error as msg:
+print 'unable to create socket! error eode: ' + str(msg[0]) + ' : '\
++ msg[1]
+sys.exit(2)
+
+try:
+sockfd.bind((args[0], 0))
+except socket.error as msg:
+print 'unable to bind socket! error eode: ' + str(msg[0]) + ' : '\
++ msg[1]
+sys.exit(2)
+
+try:
+sockfd.send(pkt)
+except socket.error as msg:
+print 'unable to send packet! error eode: ' + str(msg[0]) + ' : '\
++ msg[1]
+sys.exit(2)
+
+print 'send success!'
+sys.exit(0)
diff --git a/tests/system-traffic.at b/tests/system-traffic.at
index 2afadec..58db095 100644
--- a/tests/system-traffic.at
+++ b/tests/system-traffic.at
@@ -4478,3 +4478,166 @@ NS_CHECK_EXEC([at_ns0], [ping -s 1600 -q -c 3 -i 0.3 -w 
2 10.2.2.2 | FORMAT_PING
 
 OVS_TRAFFIC_VSWITCHD_STOP
 AT_CLEANUP
+
+
+AT_BANNER([nsh-datapath])
+
+AT_SETUP([nsh - encap header])
+OVS_TRAFFIC_VSWITCHD_START()
+
+ADD_NAMESPACES(at_ns0, at_ns1)
+
+ADD_VETH(p0, at_ns0, br0, "0.0.0.0")
+ADD_VETH(p1, at_ns1, br0, "0.0.0.0")
+
+dnl The flow will encap a nsh header to the TCP syn packet
+dnl eth/ip/tcp --> OVS --> eth/nsh/eth/ip/tcp
+AT_CHECK([ovs-ofctl -Oopenflow13 add-flow br0 
"table=0,priority=100,in_port=ovs-p0,ip,actions=encap(nsh(md_type=1)),set_field:0x1234->nsh_spi,set_field:0x11223344->nsh_c1,encap(ethernet),set_field:f2:ff:00:00:00:02->dl_dst,set_field:f2:ff:00:00:00:01->dl_src,ovs-p1"])
+
+rm ovs-p1.pcap
+tcpdump -U -i ovs-p1 -w ovs-p1.pcap