Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: ord() expected string of length 1, but int found Error in Pox Controller #251

Closed
0xabdi opened this issue Oct 12, 2020 · 23 comments

Comments

@0xabdi
Copy link

0xabdi commented Oct 12, 2020

  1. I ran pox using this command: /pox.py log.level openflow.of_01 forwarding.topo_proactive openflow.discovery
  2. Started mininet using a custom python script: sudo python3 proactive_p1.py

Up to this point, everything works fine until I ran this from the mininet prompt: h1 dhclient h1-eth0

The mininet prompt hangs for minutes and the following appears on the pox prompt:

INFO:core:POX 0.7.0 (gar) is up.
INFO:openflow.of_01:[00-00-00-00-00-01 2] connected
ERROR:core:Exception while handling OpenFlowNexus!PacketIn...
Traceback (most recent call last):
  File "/home/abdirahman/pox/pox/lib/revent/revent.py", line 242, in raiseEventNoErrors
    return self.raiseEvent(event, *args, **kw)
  File "/home/abdirahman/pox/pox/lib/revent/revent.py", line 295, in raiseEvent
    rv = event._invoke(handler, *args, **kw)
  File "/home/abdirahman/pox/pox/lib/revent/revent.py", line 168, in _invoke
    return handler(self, *args, **kw)
  File "/home/abdirahman/pox/pox/openflow/discovery.py", line 347, in _handle_openflow_PacketIn
    packet = event.parsed
  File "/home/abdirahman/pox/pox/openflow/__init__.py", line 193, in parsed
    return self.parse()
  File "/home/abdirahman/pox/pox/openflow/__init__.py", line 185, in parse
    self._parsed = ethernet(self.data)
  File "/home/abdirahman/pox/pox/lib/packet/ethernet.py", line 106, in __init__
    self.parse(raw)
  File "/home/abdirahman/pox/pox/lib/packet/ethernet.py", line 127, in parse
    self.next = ethernet.parse_next(self, self.type, raw, ethernet.MIN_LEN)
  File "/home/abdirahman/pox/pox/lib/packet/ethernet.py", line 134, in parse_next
    return parser(raw[offset:], prev)
  File "/home/abdirahman/pox/pox/lib/packet/ipv4.py", line 93, in __init__
    self.parse(raw)
  File "/home/abdirahman/pox/pox/lib/packet/ipv4.py", line 158, in parse
    self.next = udp(raw=raw[self.hl*4:length], prev=self)
  File "/home/abdirahman/pox/pox/lib/packet/udp.py", line 68, in __init__
    self.parse(raw)
  File "/home/abdirahman/pox/pox/lib/packet/udp.py", line 100, in parse
    self.next = dhcp(raw=raw[udp.MIN_LEN:],prev=self)
  File "/home/abdirahman/pox/pox/lib/packet/dhcp.py", line 142, in __init__
    self.parse(raw)
  File "/home/abdirahman/pox/pox/lib/packet/dhcp.py", line 215, in parse
    self.parseOptions()
  File "/home/abdirahman/pox/pox/lib/packet/dhcp.py", line 232, in parseOptions
    self.parseOptionSegment(self._raw_options)
  File "/home/abdirahman/pox/pox/lib/packet/dhcp.py", line 248, in parseOptionSegment
    opt = ord(barr[ofs])
TypeError: ord() expected string of length 1, but int found
@MurphyMc
Copy link
Collaborator

I think you can probably just remove the ord.

This looks like it had been missed until now in the Python 3 (#192) transition.

If removing the ord fixes it, we should push it.

@Jaisaiarun
Copy link

After removing ord()
"ERROR:packet:(dns) parsing questions: sequence item 0: expected str instance, bytes found"
this error is shown . what should be done?

@MurphyMc
Copy link
Collaborator

I don't have a lot of time to work on this right now. The basic issue is a Python2/Python3 conversion problem that didn't get caught yet. Here are some options:

  • Use the Python 2 version of POX. The fangtooth branch of my fork is the most up to date for Python 2.
  • Fix it yourself. For hints, you could look through other recent commits which are marked as Python 3 conversion stuff relating to str/bytes. If you do this, it'd be great if you'd make your fix available so it can be incorporated into POX.
  • Wait for me or someone else to fix it. You could facilitate this by:
    1. If there's a traceback instead of just the "sequence item 0" error message, post the full traceback.
    2. Posting a pcap capture that includes the DNS packet which causes the problem.

@Jaisaiarun
Copy link

I added b in join and it worked .
"def read_dns_name_from_index(cls, l, index):
retlist = []
next = cls._read_dns_name_from_index(l, index, retlist)
return (next + 1,b".".join(retlist))"

mattall added a commit to mattall/pox that referenced this issue May 19, 2021
Implemented the Jaisaiarun fix from issue noxrepo#251 (noxrepo#251).
@MurphyMc
Copy link
Collaborator

I'd forgotten about this issue, but have made a bunch of fixes to DNS (including the problem above) in this branch of my fork: https://github.com/MurphyMc/pox/tree/gar-wip3

... that stuff should probably eventually all get upstreamed.

@SalarJamal
Copy link

Hi dears
does this issue effect the result of measuring RTT and Throughput of network working under Pox controller? or it can be neglected?

@RiedelNicolas
Copy link

Hey, firendly reminder to put this fix on main.

@MohsenBs
Copy link

MohsenBs commented Nov 7, 2022

The problem still persists

@MohsenBs
Copy link

MohsenBs commented Nov 7, 2022

I added b in join and it worked . "def read_dns_name_from_index(cls, l, index): retlist = [] next = cls._read_dns_name_from_index(l, index, retlist) return (next + 1,b".".join(retlist))"

Can you share withus the code of DHCP after removing ord and DNS code

@aperezleiras
Copy link

I had to both add that "b" in read_dns_name_from_index and remove the ord's in _read_dns_name_from_index to get rid of the problem

@MohsenBs
Copy link

I had to both add that "b" in read_dns_name_from_index and remove the ord's in _read_dns_name_from_index to get rid of the problem

I don't have enough experience to edit, I tried and the error still appears

Can you send the code files after modification to make DHCP work?

@aperezleiras
Copy link

I had to both add that "b" in read_dns_name_from_index and remove the ord's in _read_dns_name_from_index to get rid of the problem

I don't have enough experience to edit, I tried and the error still appears

Can you send the code files after modification to make DHCP work?

I don't know about the DHCP problem, but it fixed the DNS problem for me, maybe you can do what I did to dns.py in dhcp.py, just replace pox/pox/lib/packet/dns.py with the dns.py in this zip
dns.zip

@MohsenBs
Copy link

I had to both add that "b" in read_dns_name_from_index and remove the ord's in _read_dns_name_from_index to get rid of the problem

I don't have enough experience to edit, I tried and the error still appears
Can you send the code files after modification to make DHCP work?

I don't know about the DHCP problem, but it fixed the DNS problem for me, maybe you can do what I did to dns.py in dhcp.py, just replace pox/pox/lib/packet/dns.py with the dns.py in this zip dns.zip

Thanks for the help, I appreciate it

But the problem persists, I think from the DHCP file


TypeError: ord() expected string of length 1, but int found
ERROR:core:Exception while handling Connection!PacketIn...
Traceback (most recent call last):
File "/home/mohsen/pox/pox/lib/revent/revent.py", line 242, in raiseEventNoErrors
return self.raiseEvent(event, *args, **kw)
File "/home/mohsen/pox/pox/lib/revent/revent.py", line 295, in raiseEvent
rv = event._invoke(handler, *args, **kw)
File "/home/mohsen/pox/pox/lib/revent/revent.py", line 168, in _invoke
return handler(self, args, **kw)
File "/home/mohsen/pox/pox/forwarding/topo_proactive.py", line 382, in _handle_PacketIn
packet = event.parsed
File "/home/mohsen/pox/pox/openflow/init.py", line 193, in parsed
return self.parse()
File "/home/mohsen/pox/pox/openflow/init.py", line 185, in parse
self._parsed = ethernet(self.data)
File "/home/mohsen/pox/pox/lib/packet/ethernet.py", line 106, in init
self.parse(raw)
File "/home/mohsen/pox/pox/lib/packet/ethernet.py", line 127, in parse
self.next = ethernet.parse_next(self, self.type, raw, ethernet.MIN_LEN)
File "/home/mohsen/pox/pox/lib/packet/ethernet.py", line 134, in parse_next
return parser(raw[offset:], prev)
File "/home/mohsen/pox/pox/lib/packet/ipv4.py", line 93, in init
self.parse(raw)
File "/home/mohsen/pox/pox/lib/packet/ipv4.py", line 158, in parse
self.next = udp(raw=raw[self.hl
4:length], prev=self)
File "/home/mohsen/pox/pox/lib/packet/udp.py", line 68, in init
self.parse(raw)
File "/home/mohsen/pox/pox/lib/packet/udp.py", line 100, in parse
self.next = dhcp(raw=raw[udp.MIN_LEN:],prev=self)
File "/home/mohsen/pox/pox/lib/packet/dhcp.py", line 142, in init
self.parse(raw)
File "/home/mohsen/pox/pox/lib/packet/dhcp.py", line 215, in parse
self.parseOptions()
File "/home/mohsen/pox/pox/lib/packet/dhcp.py", line 232, in parseOptions
self.parseOptionSegment(self._raw_options)
File "/home/mohsen/pox/pox/lib/packet/dhcp.py", line 248, in parseOptionSegment
opt = ord(barr[ofs])
TypeError: ord() expected string of length 1, but int found

@aperezleiras
Copy link

File "/home/mohsen/pox/pox/lib/packet/dhcp.py", line 248, in parseOptionSegment
opt = ord(barr[ofs])
TypeError: ord() expected string of length 1, but int found

Try editing that file, line 248, and just remove that ord call, so it says opt = barr[ofs], do the same with other "ord"s you see in that same function

@MurphyMc
Copy link
Collaborator

Just a note that you are using an old version of POX. I suspect this problem is fixed in the halosaur branch.

@MurphyMc
Copy link
Collaborator

The Selecting a Branch / Version section of the manual hasn't been updated for a while, but describes the POX versioning scheme and the procedure to select them.

@MohsenBs
Copy link

The Selecting a Branch / Version section of the manual hasn't been updated for a while, but describes the POX versioning scheme and the procedure to select them.

  • I appreciate the answer, I think it works now
  • after dhclient and dhclient -r commands the IP address is still the same on mininet hosts. How can change or renew with different IPs?

image

image

@MurphyMc
Copy link
Collaborator

File a new issue and include relevant information (such as the command line / configuration you are using).

@MohsenBs
Copy link

  • after dhclient and dhclient -r commands the IP address is still the same on mininet hosts. How can change or renew with different IPs?

#282 (comment)

@cloudlakecho
Copy link

@Jaisaiarun Thanks for sharing the tip.
Would you check the code line of return (next + 1,b".".join(retlist))"? The " isn't pair. The last " should by typo?

@cloudlakecho
Copy link

@aperezleiras I try to apply your tip of removing ord in the "_read_dns_name_from_index" function. I see two code lines with ord:
     chunk_size = ord(l[index])
     offset = ( (ord(l[index]) & 0x3) << 8 ) | ord(l[index + 1])

These lines should be like:
     chunk_size = l[index]
     offset = ( (l[index] & 0x3) << 8 ) | l[index + 1]?

My git branch: "gar-experimental"

@MurphyMc
Copy link
Collaborator

Why not just upgrade to the halosaur branch, where this was fixed almost two years ago?

@cloudlakecho
Copy link

@MurphyMc Thanks for your suggestion. I will switch the branch to "halosaur" and check the message during runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants