def run(self, app, sonata_fields): self.logger.info('run') # compile app to p4 self.logger.info('init P4 application object') self.app = P4Application(app, sonata_fields) self.logger.info('generate p4 code and commands') p4_src = self.app.get_p4_code() write_to_file(self.P4_COMPILED, p4_src) p4_commands = self.app.get_commands() commands_string = "\n".join(p4_commands) # self.logger.info("Commands: " + commands_string) write_to_file(self.P4_COMMANDS, commands_string) # compile p4 to json self.logger.info('compile p4 code to json') # TODO: uncomment this line self.dataplane.compile_p4(self.P4_COMPILED, self.JSON_P4_COMPILED) # initialize dataplane and run the configuration self.logger.info( 'initialize the dataplane with the json configuration') # TODO: uncomment this line self.dataplane.initialize(self.JSON_P4_COMPILED, self.P4_COMMANDS) # start the emitter if self.em_conf: self.logger.info('start the emitter') em = Emitter(self.em_conf, self.app.get_header_formats()) em_thread = Thread(name='emitter', target=em.start) em_thread.setDaemon(True) em_thread.start()
def update(self, filter_update): self.logger.info('update') # Reset the data plane registers/tables before pushing the new delta config # self.dataplane.reset_switch_state() # Get the commands to add new filter flow rules commands = self.app.get_update_commands(filter_update) commands_string = "\n".join(commands) write_to_file(self.P4_DELTA_COMMANDS, commands_string) self.dataplane.send_commands(self.JSON_P4_COMPILED, self.P4_COMMANDS) self.dataplane.send_commands(self.JSON_P4_COMPILED, self.P4_DELTA_COMMANDS)
def delete_entries_from_table(number_of_entries, table_name, dataplane, JSON_P4_COMPILED, P4_DELTA_COMMANDS, logger): start = time.time() commands = [] for i in range(0, number_of_entries): CMD = "table_delete %s %s" % (table_name, i) commands.append(CMD) commands_string = "\n".join(commands) # print commands_string write_to_file(P4_DELTA_COMMANDS, commands_string) dataplane.send_commands(JSON_P4_COMPILED, P4_DELTA_COMMANDS) end = time.time() logger.info("delete|" + str(number_of_entries) + "|" + str(start) + "|" + str(end))
def add_entries_to_table(number_of_entries, table_name, p4_dataplane_obj, JSON_P4_COMPILED, P4_DELTA_COMMANDS, logger): start = time.time() commands = [] for i in range(0, number_of_entries): IP = "%d.%d.0.0" % (random.randint(0, 255), random.randint(0, 255)) CMD = "table_add %s _nop %s/16 =>" % (table_name, IP) commands.append(CMD) commands_string = "\n".join(commands) # print commands_string write_to_file(P4_DELTA_COMMANDS, commands_string) p4_dataplane_obj.send_commands(JSON_P4_COMPILED, P4_DELTA_COMMANDS) end = time.time() logger.info("update|" + str(number_of_entries) + "|" + str(start) + "|" + str(end))
CLI_PATH = BMV2_SWITCH_BASE + target_conf['cli_path'] THRIFTPORT = target_conf['thriftport'] P4_COMMANDS = COMPILED_SRCS + target_conf['p4_commands'] P4_DELTA_COMMANDS = COMPILED_SRCS + target_conf['p4_delta_commands'] # interfaces interfaces = { 'receiver': ['m-veth-1', 'out-veth-1'], 'sender': ['m-veth-2', 'out-veth-2'], 'original': ['m-veth-3', 'out-veth-3'] } p4_src, p4_commands, registers = get_sequential_code(NUMBER_OF_REGISTERS) write_to_file(P4_COMPILED, p4_src) commands_string = "\n".join(p4_commands) write_to_file(P4_COMMANDS, commands_string) dataplane = P4DataPlane(interfaces, SWITCH_PATH, CLI_PATH, THRIFTPORT, P4C_BM_SCRIPT) dataplane.compile_p4(P4_COMPILED, JSON_P4_COMPILED) dataplane.create_interfaces() cmd = dataplane.switch_path + " >/dev/null 2>&1" get_out(cmd) # initialize_the_switch(JSON_P4_COMPILED, SWITCH_PATH) Switch(JSON_P4_COMPILED, SWITCH_PATH).start() time.sleep(1)
THRIFTPORT = target_conf['thriftport'] P4_COMMANDS = COMPILED_SRCS + target_conf['p4_commands'] P4_DELTA_COMMANDS = COMPILED_SRCS + target_conf['p4_delta_commands'] # interfaces interfaces = { 'receiver': ['m-veth-1', 'out-veth-1'], 'sender': ['m-veth-2', 'out-veth-2'], 'original': ['m-veth-3', 'out-veth-3'] } p4_src, p4_commands, filter_table_name = get_sequential_code( NUMBER_OF_QUERIES, MAX_TABLE_ENTRIES) write_to_file(P4_COMPILED, p4_src) commands_string = "\n".join(p4_commands) write_to_file(P4_COMMANDS, commands_string) dataplane = P4DataPlane(interfaces, SWITCH_PATH, CLI_PATH, THRIFTPORT, P4C_BM_SCRIPT) dataplane.compile_p4(P4_COMPILED, JSON_P4_COMPILED) dataplane.create_interfaces() cmd = dataplane.switch_path + " >/dev/null 2>&1" get_out(cmd) # initialize_the_switch(JSON_P4_COMPILED, SWITCH_PATH) Switch(JSON_P4_COMPILED, SWITCH_PATH).start()