Skip to content

Commit

Permalink
#126 - fixing science_gateway application, and fixing manifest file c…
Browse files Browse the repository at this point in the history
…onfiguration error.
  • Loading branch information
Sean Donovan committed Dec 3, 2019
1 parent 98f8fe4 commit ba1685f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 26 deletions.
2 changes: 1 addition & 1 deletion configuration/awave-deployment/awave.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"model":"DP2400 3.x.x",
"portinfo": [
{
"portnumber": 1,
"portnumber": 2,
"speed": 80000000000,
"destination": "mia-app-186-106"
},
Expand Down
75 changes: 50 additions & 25 deletions docker/sci_gw_demo/science_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import subprocess
from datetime import datetime, timedelta
from time import sleep

import json

# HTTP status codes:
HTTP_GOOD = 200
Expand All @@ -26,17 +26,19 @@

port = 9999

TUNNEL = True
#TUNNEL = False
# List of endpoints
endpoints = {'atl-dtn':{'ctrlip':'10.100.1.21','port':9999,
'dataip':'10.201.2.21',
'switch':'atl-switch', 'switchport':4, 'vlan':201},
'dataip':'10.201.2.21', 'switch':'soxswitch-216-3',
'switchport':4, 'vlan':201},
'mia-dtn':{'ctrlip':'10.100.1.27','port':9999,
'dataip':'10.201.2.28',
'switch':'mia-switch', 'switchport':10, 'vlan':124}}
'dataip':'10.201.2.28', 'switch':'miaswitch-206-198',
'switchport':10, 'vlan':124}}

global sdx_ip, sdx_port, sdx_user, sdx_pw, login_cookie, tunnel_policy
sdx_ip = '10.100.1.21'
sdx_port = 5555
sdx_port = 5000
sdx_user = 'sdonovan'
sdx_pw = '1234'
login_cookie = None
Expand All @@ -55,16 +57,19 @@ def create_tunnel(srcswitch, dstswitch, srcport, dstport,
login_to_sdx_controller()

# Calculate start and end times
starttime = datetime.now()
endtime = starttime + time

# Issue POST command
endpoint = "http://%s:%s/api/v1/policies/type/l2tunnel" % (sdx_ip, sdx_port)
#starttime = datetime.now() - time
#endtime = starttime + time
# Hardwiring these, so that this will always be installable
starttime = datetime(1999, 01, 01)
endtime = datetime(2030, 01, 01)

# Issue POST command
endpoint = "http://%s:%s/api/v1/policies/type/L2Tunnel" % (sdx_ip, sdx_port)
l2tunnel = '{"L2Tunnel":{"starttime":"%s","endtime":"%s","srcswitch":"%s","dstswitch":"%s","srcport":%s,"dstport":%s,"srcvlan":%s,"dstvlan":%s,"bandwidth":10000000}}' % (
starttime.strftime(rfc3339format), endtime.strftime(rfc3339format),
srcswitch, dstswitch, srcport, dstport, srcvlan, dstvlan)

output = subprocess.check_call(['curl', '-X', 'POST',
output = subprocess.check_output(['curl', '-X', 'POST',
'-H',
'Content-type: application/json',
'-H', "Accept: application/json",
Expand All @@ -73,22 +78,29 @@ def create_tunnel(srcswitch, dstswitch, srcport, dstport,
'-b', login_cookie])

# Get policy number
output = json.loads(output)
print("OUTPUT: %s" % output)
output = json.loads(output.decode('utf-8'))
installed_policynum = int(output['policy']['href'].split('/')[-1])

# Set tunnel_policy
tunnel_policy = installed_policynum

sleep(3)

def delete_tunnel():
global sdx_ip, sdx_port, tunnel_policy, login_cookie

if login_cookie == None:
login_to_sdx_controller()

# Issue DELETE command
endpoint = "http://%s:%s/api/vl/policies/number/%s" % (
print("Deleting policy #%s" % tunnel_policy)

endpoint = "http://%s:%s/api/v1/policies/number/%s" % (
sdx_ip, sdx_port, tunnel_policy)

print("Deleting policy endpoint %s" % endpoint)

output = subprocess.check_call(['curl', '-X', 'DELETE',
'-H', 'Accept: application/json',
endpoint,
Expand All @@ -99,6 +111,8 @@ def delete_tunnel():
def login_to_sdx_controller():
global sdx_ip, sdx_port, sdx_user, sdx_pw, login_cookie

print("Logging into SDX Controller: %s:%s - %s:%s" % (
sdx_ip, sdx_port, sdx_user, sdx_pw))
# if there's a saved login, return
if login_cookie != None:
return
Expand Down Expand Up @@ -131,12 +145,16 @@ def get_ep_dict_from_num(endpoints, num):
a += 1

def get_dir(ctrlip, dataip, srcport):
print("Getting directory info for %s:%s:%s" % (
ctrlip, dataip, srcport))
endpoint = 'http://%s:%s/dtn/transfer/%s' % (ctrlip, srcport, dataip)
print(" %s"% endpoint)
output = subprocess.check_output(['curl', '-X', 'GET', endpoint])
return output.decode('utf-8')


def parse_files(filestr):
print("Parsing files")
# Split the filestr into a list of files
# Based on https://stackoverflow.com/questions/1894269/convert-string-representation-of-list-to-list
ls = filestr.strip('[]').replace('[','').replace(']','').replace('"', '').replace("'", '').replace(' ', '').split(',')
Expand All @@ -151,11 +169,14 @@ def print_files(files):


def transfer_file(srcdataip, dstctrlip, dstport, filename):
print("Trying to transfer file %s from %s to %s:%s" % (
filename, srcdataip, dstctrlip, dstport))
timeout = 1000

# Execute file transfer
endpoint = 'http://%s:%s/dtn/transfer/%s/%s' % (
dstctrlip, dstport, srcdataip, filename)
print(" %s" % endpoint)
output = subprocess.check_output(['curl', '-X', 'POST', endpoint])
output = output.decode('utf-8')
print("Transferring file: %s" % output)
Expand Down Expand Up @@ -194,29 +215,33 @@ def transfer_file(srcdataip, dstctrlip, dstport, filename):
#print("srcdict - %s" % srcdict)
#print("dstdict - %s" % dstdict)

create_tunnel(srcdict['switch'], dstdict['switch'],
srcdict['switchport'], dstdict['switchport'],
srcdict['vlan'], dstdict['vlan'],
timedelta(0,1))
if TUNNEL:
create_tunnel(srcdict['switch'], dstdict['switch'],
srcdict['switchport'], dstdict['switchport'],
srcdict['vlan'], dstdict['vlan'],
timedelta(100,))

# Get and display files available on src
rawfiles = get_dir(srcdict['ctrlip'], dstdict['dataip'], srcdict['port'])
rawfiles = get_dir(dstdict['ctrlip'], srcdict['dataip'], dstdict['port'])
fileslist = parse_files(rawfiles)
print_files(fileslist)
delete_tunnel()
if TUNNEL:
delete_tunnel()

# Let user choose file to transfer
filenumber = input("Choose a file: ")
filename = fileslist[int(filenumber)]

# Reestablish path between src and dest
create_tunnel(srcdict['switch'], dstdict['switch'],
srcdict['switchport'], dstdict['switchport'],
srcdict['vlan'], dstdict['vlan'],
timedelta(1,0)) # 1 day, excessive, but we'll delete it, don't worry
if TUNNEL:
create_tunnel(srcdict['switch'], dstdict['switch'],
srcdict['switchport'], dstdict['switchport'],
srcdict['vlan'], dstdict['vlan'],
timedelta(100,0)) # 1 day, excessive, but we'll delete it, don't worry

# Make transfer call
transfer_file(srcdict['dataip'], dstdict['ctrlip'], dstdict['port'], filename)

# Clean up
delete_tunnel()
if TUNNEL:
delete_tunnel()

0 comments on commit ba1685f

Please sign in to comment.