def mon_pkt_callback(pkt):
    if not Ether in pkt:
        return
    tup = {
        "valid": 1,
        "port": 0,
        "vport": 0,
        "dmac": "0x" + pkt[Ether].dst.replace(":", ""),
        "smac": "0x" + pkt[Ether].src.replace(":", ""),
        "typ": pkt[Ether].type,
        "vid": 0,
        "pcp": 0,
        "sip": 0,
        "dip": 0,
        "prot": 0,
        "tos": 0,
        "tsp": 0,
        "tdp": 0
    }
    if UDP in pkt:
        tup["tsp"] = pkt[UDP].sport
        tup["tdp"] = pkt[UDP].dport
    if TCP in pkt:
        tup["tsp"] = pkt[TCP].sport
        tup["tdp"] = pkt[TCP].dport
    if IP in pkt:
        tup["tos"] = pkt[IP].tos
        tup["sip"] = dottedQuadToNum(pkt[IP].src)
        tup["dip"] = dottedQuadToNum(pkt[IP].dst)
        tup["prot"] = pkt[IP].proto
    if ICMP in pkt:
        tup["tsp"] = pkt[ICMP].type
        tup["tdp"] = pkt[ICMP].code

    action = "0x00FF"
    if tup["smac"] in learnedMACs:
        tup["port"] = learnedMACs[tup["smac"]]
    if tup["dmac"] in learnedMACs:
        action = tuple_funs.th(1 << learnedMACs[tup["dmac"]])

    commands = tuple_funs.gen_wr_commands(action,
                                          tuple_funs.create_tuple(tup),
                                          cam_size=2048,
                                          cmd=WRAXI)
    lock.acquire()
    print "Installing Flow... Action: " + str(action) + "\t Tuple: " + str(tup)
    for line in commands:
        subprocess.check_output(line.split())
    lock.release()
def mon_pkt_callback(pkt):
    if not Ether in pkt:
        return
    tup = { "valid":1,
            "port":0,
            "vport":0,
            "dmac":"0x"+pkt[Ether].dst.replace(":",""),
            "smac":"0x"+pkt[Ether].src.replace(":",""),
            "typ":pkt[Ether].type,
            "vid":0,
            "pcp":0,
            "sip":0,
            "dip":0,
            "prot":0,
            "tos":0,
            "tsp":0,
            "tdp":0}
    if UDP in pkt:
        tup["tsp"]=pkt[UDP].sport
        tup["tdp"]=pkt[UDP].dport
    if TCP in pkt:
        tup["tsp"]=pkt[TCP].sport
        tup["tdp"]=pkt[TCP].dport
    if IP in pkt:
        tup["tos"]=pkt[IP].tos
        tup["sip"]=dottedQuadToNum(pkt[IP].src)
        tup["dip"]=dottedQuadToNum(pkt[IP].dst)
        tup["prot"]=pkt[IP].proto
    if ICMP in pkt:
        tup["tsp"]=pkt[ICMP].type
        tup["tdp"]=pkt[ICMP].code
        
    action = "0x00FF"
    if tup["smac"] in learnedMACs:
        tup["port"] = learnedMACs[tup["smac"]]
    if tup["dmac"] in learnedMACs:
        action = tuple_funs.th(1<<learnedMACs[tup["dmac"]])
        
    commands = tuple_funs.gen_wr_commands(action,tuple_funs.create_tuple(tup),cam_size=2048,cmd=WRAXI)
    lock.acquire()
    print "Installing Flow... Action: "+str(action) + "\t Tuple: " + str(tup)
    for line in commands:
        subprocess.check_output(line.split())
    lock.release()
Beispiel #3
0
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this project. If not, see <http://www.gnu.org/licenses/>.
 
 Parameter for this script is NetFPGA-10G interface.
"""

from tuple_calculator import tuple_funs
import subprocess
import sys
WRAXI = "../../../../../../contrib-projects/upb_openflowswitch/sw/wraxi"
RDAXI = "../../../../../../contrib-projects/upb_openflowswitch/sw/rdaxi"
dev = sys.argv[1]
num_entries = int(
    tuple_funs.td(
        subprocess.check_output("sudo " + RDAXI + " " + dev + " 0xB0000008",
                                shell=True).strip().split("=")[1]))
print "Deleting CAM Contents. This might take a while..."
sys.stdout.write("   0/" + str(num_entries))
for i in range(0, num_entries):
    cmds = tuple_funs.gen_wr_commands(0, 0, dev=dev, cmd=WRAXI, hashh=i)
    sys.stdout.write("\b\b\b\b\b" + ("\b" * len(str(num_entries))) +
                     str(i + 1).rjust(4) + "/" + str(num_entries))
    sys.stdout.flush()
    for cmd in cmds:
        subprocess.check_output(cmd.split())
print ""
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this project. If not, see <http://www.gnu.org/licenses/>.
 
 Parameter for this script is NetFPGA-10G interface.
"""

from tuple_calculator import tuple_funs
import subprocess
import sys

WRAXI = "../../../../../../contrib-projects/upb_openflowswitch/sw/wraxi"
RDAXI = "../../../../../../contrib-projects/upb_openflowswitch/sw/rdaxi"
dev = sys.argv[1]
num_entries = int(
    tuple_funs.td(
        subprocess.check_output("sudo " + RDAXI + " " + dev + " 0xB0000008", shell=True).strip().split("=")[1]
    )
)
print "Deleting CAM Contents. This might take a while..."
sys.stdout.write("   0/" + str(num_entries))
for i in range(0, num_entries):
    cmds = tuple_funs.gen_wr_commands(0, 0, dev=dev, cmd=WRAXI, hashh=i)
    sys.stdout.write("\b\b\b\b\b" + ("\b" * len(str(num_entries))) + str(i + 1).rjust(4) + "/" + str(num_entries))
    sys.stdout.flush()
    for cmd in cmds:
        subprocess.check_output(cmd.split())
print ""