How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask Steve Your Own Question
Steve
Steve, Consultant
Category: Programming
Satisfied Customers: 274
Experience:  Steve is a consultant in the areas of computer software and programming, information management and networking.
47680681
Type Your Programming Question Here...
Steve is online now
A new question is answered every 9 seconds

Im trying to simulate a router that uses the longest-prefix

Customer Question

HI.
Im trying to simulate a router that uses the longest-prefix match by creating a program in python and it's giving me hard time.
I have to create two .txt files.
One file should have something like this:
128 128 I0
160 224 I1
96 248 I2
The meaning of entries in a row is subnet address, netmask, and port name.
Another .txt file with address destinations like this:
161
175
103
etc
so the program reads in the two files and then the destination is routed to the correct port name.
Using command prompt the output would be:
I1
I8
I2
NO MATCH
etc
Submitted: 1 year ago.
Category: Programming
Expert:  Michael Hannigan replied 1 year ago.

Hello. My name is***** will assist you with your question.

I don't see subnet addresses in your first text file. Or even address destinations in the 2nd file. It looks like what you're looking for is the first file to have an IP address like 192.168.1.10/128 8080 e0

That would represent the IP address, subnet mask, the port number, and the interface name. It doesn't appear enough information in your first file to route based on the 2nd file. And then in the 2nd file I would think that what you're looking for is IP addresses and subnet masks.

Mike

Customer: replied 1 year ago.
Hi Mike...
In this particular program I have to implement a simple router( implement a
router's decision-making, given an incoming packet's IP address, as to which next hop to
forward it to, using the longest-prefix match algorithm.)
To make things simple, assume IP addresses are 8 bits
instead of 32 bits, so that each IP address is just a number between 0 and 255.The program will read in a routing table (table.txt) and a file
of destination IP addresses (dests.txt). The routing table file should contain one
tab-separated entry on each line, e.g:128 128 I0
160 224 I1
96 248 I2
64 224 I3
200 252 I4
20 252 I5
192 240 I6
144 240 I7
168 248 I8The meaning of the entries in a row is: subnet address [tab] netmask [tab] port name.
The port name is ***** ***** plain strain (with no spaces).The destination file should contain one IP address on each line, e.g.:161
175
103
5
201
199
204
203
23I believe that a given destination IP d matches a subnet with address
a and netmask m (i.e., this is a potential place the router will
consider for routing the packet) if this (Python) expression evaluates to true:d & m == a & m (bitwise operator AND)Using command prompt, the output of the program based on the destination IP addresses in the second file would be:I1
I8
I2
NO MATCH
I4
I6
I6
I4
I5
Customer: replied 1 year ago.
I'm just resending the information that should be contained in the table.txt128 128 I0
160 224 I1
96 248 I2
64 224 I3
200 252 I4
20 252 I5
192 240 I6
144 240 I7
168 248 I8
Customer: replied 1 year ago.
Sorry but the information in the table.txt is being sent in the wrong way( there are not spaces between the columns)
128 ---128 ---I0
160----224--- I1
96----248--- I2
64--- 224--- I3
200--- 252--- I4
20----252----I5
192--- 240--- I6
144--- 240--- I7
168 ---248 ---I8
Expert:  Steve replied 1 year ago.

Hi, my name is ***** ***** I can help you out if you still need help. But I don't see the program or text files attached to this message. Did you provide them a different way?

Related Programming Questions