noxrepo / pox

The POX network software platform
https://noxrepo.github.io/pox-doc/html/
Apache License 2.0
619 stars 470 forks source link

issue with custom controller #290

Closed pavankumarjavvaji closed 11 months ago

pavankumarjavvaji commented 1 year ago

ERROR:packet:(dns) parsing questions: ord() expected string of length 1, but int found i am getting thiss error whill i am trying to ping i dont think there is error in code will you help me in it from pox.core import core import pox.openflow.libopenflow_01 as of

class BestNodeController(object): def init(self): self.node_details = {} # Store node details here core.openflow.addListeners(self) self.read_node_details() # Call a method to read node details

def _handle_ConnectionUp(self, event):
    best_node = self.find_best_node()  # Call a method to find the best node
    if best_node is not None:
        self.install_flow(event.connection, best_node)  # Install flow rules

def read_node_details(self):
    # Read and store node details from text files
    # Assume node files are named node1.txt, node2.txt, ...
    for node_id in range(1, 4):  # Adjust range based on the number of nodes
        filename = f'node{node_id}.txt'
        with open(filename, 'r') as f:
            details = f.read().strip()  # Read details from the file
            self.node_details[node_id] = details

def find_best_node(self):
    best_node = None
    best_score = float('-inf')  # Initialize with a low value

    for node_id, details in self.node_details.items():
        cpu_bandwidth, cpu_usage, num_vehicles, num_packets_dropped = map(int, details.split(','))

    # Define a simple score formula (you can customize this)
        score = cpu_bandwidth + (1 - cpu_usage) + num_vehicles - num_packets_dropped

        if score > best_score:
            best_node = node_id
            best_score = score

    return best_node

def _handle_ConnectionUp(self, event):
    best_node = self.find_best_node()  # Call a method to find the best node
    if best_node is not None:
        self.install_flow(event.connection, best_node)  # Install flow rules to send traffic to the best node

def install_flow(self, connection, best_node):
    out_port = self.node_details[best_node]  # Assuming node_details contains port information
    best_node = self.find_best_node()
    best_node_mac_address = self.node_details[best_node]['mac']
    some_destination_mac_address = best_node_mac_address

    msg = of.ofp_flow_mod()
    msg.match.dl_dst = some_destination_mac_address  # Set the appropriate destination MAC address
    msg.actions.append(of.ofp_action_output(port=out_port))
    connection.send(msg)

'''def install_flow(self, connection, out_port):
    msg = of.ofp_flow_mod()
    msg.actions.append(of.ofp_action_output(port=out_port))
    connection.send(msg)'''

def launch(): core.registerNew(BestNodeController)

MurphyMc commented 11 months ago

I think upgrading to POX halosaur will probably make that message go away (relevant docs). If you still get log messages from the packet subsystem, reopen the issue -- I have some improvements to the DNS code that haven't gotten pushed yet.

However, I am doubtful that this is actually your problem. From casual inspection, I think you must be running components besides BestNodeController which may conflict with it, and I think there are problems with BestNodeController. (For example, node_details doesn't look like it's a dictionary which will have a 'mac' key, and a flow mod that matches dl_dst probably also needs to match the IP protocol.)