def stopShell(): shell_lock.acquire() try: te = sh.TableEntry('control_out_port.ipv4_check_checksum')( action='DoMirror') sh.TableEntry('control_out_port.ipv4_check_checksum').read( lambda t: t.delete()) sh.teardown() print("disconnected") finally: shell_lock.release()
print("deleting entries from any previous run") tables = sh.P4Objects(context.P4Type.table) count = 0 for table in tables: for te in sh.TableEntry(table.name).read(): count += 1 te.delete() print("Deleted %d entries" % count) print("installing entries") for i, entry in enumerate(entries): print("installing %d" % i) try: te = sh.TableEntry(entry["table"])(action=entry["action"]) for key, val in entry["keys"].items(): te.match[key] = val for arg,val in entry["args"].items(): te.action[arg] = val priority = entry.get("priority", None) if priority != None: te.priority = priority te.insert() except Exception: print("ENTRY FAILED:\n", json.dumps(entry, indent=2), "\nEND FAILURE") raise Exception sh.teardown() print("Successful teardown!")
def tearDown(self): sh.teardown() super().tearDown()