Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert the following python code into java code # print header for forwarding database(FDB) def printHeader(outFile: str): outFile.write(------------------------------------------------- ) outFile.write(| Indx | Host | Port

Convert the following python code into java code

# print header for forwarding database(FDB) def printHeader(outFile: str): outFile.write("------------------------------------------------- ") outFile.write("| Indx | Host | Port | ") outFile.write("------------------------------------------------- ")

# print forwarding database(FDB) def printFDB(outFile: str, fdb: dict): index = 1 printHeader(outFile) for port, src_mac in fdb.items(): ..................outFile.write("|{0}|{1}|{2}| ".format(index, src_mac, port)) ..................index += 1 outFile.write(" ")

# number of ports in the bridge number_of_ports = int(input("Number of ports in the bridge: ")) if number_of_ports > 8: ...............print("Number of ports should be less than 9") ...............exit()

fileName = input("Enter input file name: ")

fdb = {} # empty dictionary to store MAC and its incoming port number

with open("fdb.txt", 'w') as outFile:

.............with open("inp.txt", 'r') as file: ...........................frames = file.readlines() # The variable "frames" is a list containing all lines in the file ...........................for frame in frames: .................................frame = frame.strip(' ') .................................try: ........................................src, dest, port = frame.split(" ") .........................................if int(port) > number_of_ports: ..............................................continue .................................except ValueError: .....................................continue

.................................if fdb.get(port) is None: .......................................fdb[port] = src .......................................outFile.write("Action: add to FDB (index {0}); forward to all out ports: ".format(len(fdb))) .................................else: .......................................index = list(fdb.keys()).index(port) .......................................outFile.write("Action: found at index {0}(no update); forward to port: ".format( index + 1))

.................................printFDB(outFile, fdb)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago