def createMatch(self,request):
     #loop over dictionary, use switch statement
     match = of.ofp_match()
     for attribute,value in request.openflow.items():
         if attribute=="IngressPort":
             match.in_port=value
         elif attribute=="EthernetSource":
             match.dl_src=value
         elif attribute=="EthernetDestination":
             match.dl_dst=value
         elif attribute=="EthernetType":
             match.dl_type=value
         elif attribute=="VLANpriority":
             match.dl_vlan_pop=value
         elif attribute=="IPSourceAddress":
             match.nw_src=value
         elif attribute=="IPDestinationAddress":
             match.nw_dst=value
         elif attribute=="IPprotocol":
             match.nw_proto
         elif attribute=="IPToS":
             match.nw_tos=value
         elif attribute=="sourcePort":
             match.tp_src=value
         elif attribute=="destinationPort":
             match.tp_dst=value
         elif attribute=="VLANID":
             match.dl_vlan=value
     return match
    def block(self, ip):
        match = of.ofp_match()
        match.nw_src = IPAddr(ip)

        print self.colours["GREEN"] + "blocking ", ip + self.colours["END"]
        msg2 = of.ofp_flow_mod(command=of.OFPFC_ADD, actions=[], match=match)
        for connection in core.openflow.connections:
            connection.send(msg2)
    def block(self, ip):
        match = of.ofp_match()
        match.nw_src = IPAddr(ip)

        print self.colours["GREEN"] + "blocking ", ip + self.colours["END"]
        msg2 = of.ofp_flow_mod(command=of.OFPFC_ADD, actions=[], match=match)
        for connection in core.openflow.connections:
            connection.send(msg2)
 def unblock(self, ip):
     msg = of.ofp_packet_out()
     action = of.ofp_action_output(port=of.OFPP_CONTROLLER)
     msg.actions.append(action)
     match = of.ofp_match()
     match.nw_src = IPAddr(ip)
     #match.nw_dst = IPAddr(ip[1])
     msg.command = of.OFPFC_DELETE
     msg.match = match
     print self.colours["WHITE"] + "unblocking ", ip + self.colours["END"]
     for connection in core.openflow.connections:
         connection.send(msg)
 def unblock(self, ip):
     msg = of.ofp_packet_out()
     action = of.ofp_action_output(port=of.OFPP_CONTROLLER)
     msg.actions.append(action)
     match = of.ofp_match()
     match.nw_src = IPAddr(ip)
     # match.nw_dst = IPAddr(ip[1])
     msg.command = of.OFPFC_DELETE
     msg.match = match
     print self.colours["WHITE"] + "unblocking ", ip + self.colours["END"]
     for connection in core.openflow.connections:
         connection.send(msg)
 def measureLatency(self,switchOne, switchTwo):  
     self.TimeTotal = 0 #time between controller, s1, s2
     time.sleep(5)
     s1 = None
     s2 = None
     """go through the list of connected switches, mapping between s1 and the dpid trim the input
     
     for core.connections print strpid"""
     for switch in core.openflow.connections:
         #print "Switch " + str(switch.dpid)
         if switchOne.strip() == str(switch.dpid):
             s1 = switch
         if switchTwo.strip() == str(switch.dpid):
             s2 = switch
             
     print switchOne+" is "+str(s1)
     print switchTwo+" is "+str(s2)
     
     measureSwitchOne = LatencyMeasurment(s1)
     measureSwitchTwo = LatencyMeasurment(s2)
     print "Round trip time to switch one: "+str(measureSwitchOne.roundTripTime)
     print "Round trip time to switch two: "+str(measureSwitchTwo.roundTripTime)
     self.timeS1 = measureSwitchOne.roundTripTime
     self.timeS2 = measureSwitchTwo.roundTripTime
     
     
     
     """send flow mod to switch, put timestamp in ethernet packet, and choose the right port that goes to s2"""
     
     match = of.ofp_match()
     match.dl_type= 0001
     self.sendLatencyFlowMod(s1)
     time.sleep(1)
     self.sendLatencyEthernetPacket(2,s1) #get port number from mac address
     
     
     
     " to get the port, use mac table?"