Last active
June 19, 2019 11:20
-
-
Save flavio-fernandes/ddd5a2c591092c5ee0a88ae950e376c6 to your computer and use it in GitHub Desktop.
simple ovsdb echo example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
# Playing with ovsdb json rpc | |
# https://tools.ietf.org/html/rfc7047#section-4.1.11 | |
# https://keepingitclassless.net/2013/10/introduction-to-open-vswitch/ | |
# https://keepingitclassless.net/2013/10/ovsdb-echo-in-python/ | |
import socket | |
import json | |
import time | |
def pingOVS(s, pingId): | |
#Send JSON to socket | |
print("Sending echo request =====>") | |
s.send(json.dumps({'method':'echo','id':str(pingId),'params':["hi"]})) | |
#Wait for response and print to console | |
result = json.loads(s.recv(1024)) | |
print("<========" + str(result)) | |
time.sleep(2) | |
#Create socket | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
#Establish TCP session via IP address and port specified | |
s.connect(("127.0.0.1", 6641)) | |
for pingId in range(3): | |
pingOVS(s, pingId) | |
#Exit | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment