import hpsdnclient as hp
import sys
import socket

#get IP of eth0
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 1))

#configuration
controller = s.getsockname()[0]
auth = hp.XAuthToken(user='******', password='******', server=controller)
api = hp.Api(controller=controller, auth=auth)

# flow template (first flow in the first datapath)
id = api.get_datapaths()[0].dpid
flow_temp = api.get_flows(id)[0]
flow_temp.byte_count = '0'
flow_temp.match.eth_type = "ipv4"
flow_temp.match.eth_dst = ""
flow_temp.match.eth_src = ""
flow_temp.priority = "65535"


def insert_flow(ipsrc, ipdst, inPort, outPort, dpid):
    flow = flow_temp
    flow.actions.output = outPort
    flow.match.ipv4_src = ipsrc
    flow.match.ipv4_dst = ipdst
    flow.match.in_port = inPort
    api.add_flows(dpid, flow)
Exemplo n.º 2
0
  sys.exit()

x = len(pid_list) # Keep track of how many items we need to process


  

# Check to see if anything was chozen. If x is zero goto Nothing Selected page and exit



j = 0

#Create authorization Token for the SDN controller

auth = hp.XAuthToken(user=user,password=passw,server=server)
api=hp.Api(controller=server,auth=auth)


#--------------------------------------------------------------------------
# dpid factory: Break up dpis and match to vendor to determin MAC address
#---------------------------------------------------------------------------

print "Content-type:text/html\r\n\r\n"
print "<!DOCTYPE html>"
print "<html>"
print "<head>"
print "<title> Wookieware.com</title>"
print "<link rel=\"stylesheet\" type\"text/css\" href=\"../../css/corex.css\"/>"
print "<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js\"></script>"
print "</head>"
Exemplo n.º 3
0
#              Get the field VARS from the calling HTML form
#-------------------------------------------------------------------------
form = cgi.FieldStorage()
null = form.getvalue('null')
dest_ip = form.getvalue('dest_ip')
toe_ip = form.getvalue('toe_ip')
src_dpid = form.getvalue('src_dpid')
src_port = form.getvalue('src_port')
src_mac = form.getvalue('src_mac')
a_port = form.getvalue('a_port')
server = form.getvalue('server')
user = form.getvalue('user')
passw = form.getvalue('passw')

#Create authorization Token
auth = flare.XAuthToken(user=user, password=passw, controller=server)
my_flare = flare.Api(controller=server, auth=auth)

#----------------------------------------------------------------------------------------------------
#          Get the output port for the conversation
#----------------------------------------------------------------------------------------------------
flows = my_flare.get_flows(src_dpid)

for f in flows:
    if (f.match.eth_src == src_mac):
        out_port = f.actions.output

if (int(out_port) == int(a_port)):
    print "Content-type:text/html\r\n\r\n"
    print "<html>"
    print "<head>"