Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This needs to be done in Java class Router { private RoutingTableEntry[] routingTable; private int numEntries; private int maxEntries; public Router() { Scanner keyboard =

This needs to be done in Java

image text in transcribed

class Router { private RoutingTableEntry[] routingTable; private int numEntries; private int maxEntries;

public Router() { Scanner keyboard = new Scanner(System.in); System.out.print("Enter number of entries maximum for array: "); while (!keyboard.hasNextInt()) { System.out.println ("Invalid...must enter an integer...reenter: "); keyboard.next(); } maxEntries = keyboard.nextInt(); if (maxEntries

} public void processPacket(Packet inPacket) {

boolean found = false; String port = null; for (int i = 0; i

if (addToTable) { if (numEntries >= maxEntries) System.out.println("Table is full.........cannot add " + inPacket.getDestNetwork()); else { routingTable[numEntries] = new RoutingTableEntry(); routingTable[numEntries++].addEntry(inPacket.getDestNetwork(), inPacket.getPacketData()); } } }

public void displayTable() { System.out.println(" Routing table... "); for (int i = 0; i

public RoutingTableEntry() { }

public void addEntry(IPAddress dest, String PC) { destination.initialize(dest); portCode = PC; }

public String toString() { String out = new String(); out += destination.toString() + " Port: " + portCode; return out; }

public String searchForPort(IPAddress dest) { if (destination.isEqual(dest)) return portCode; else return null; } }

class IPAddress { private int[] address = new int[4]; // each of four octets private int subnet; // number of network bits

public IPAddress() { for (int i = 0; i

public boolean initialize(int[] add, int sub) { for (int i = 0; i

public boolean initialize(IPAddress newOne) { for (int i = 0; i

public boolean readAddress(Scanner inFile) { try { for (int i = 0; i

public boolean readKeyboard() { Scanner keyboard = new Scanner(System.in); System.out.print("Enter four numbers for the four octets: "); for (int i = 0; i

public boolean isValid() { if (address[0] 255 || address[1] 255 || address[2] 255 || address[3] 255 || subnet > 32 || subnet 127) return false; else if (subnet 191) return false; else if (subnet 223) return false; else return true; }

public String toString() { String out = new String(); for (int i = 0; i

public IPAddress getNetwork() { IPAddress networkIP = new IPAddress(); int maxOctetsToCopy = 0; // figure out how much is network...how much is host I could also do // NaxOctetsToCopy = subnet / 8; if (subnet == 24) maxOctetsToCopy = 3; if (subnet == 16) maxOctetsToCopy = 2; if (subnet == 8) maxOctetsToCopy = 1; // copy Network address

for (int i = 0; i

public boolean isEqual(IPAddress rhs) { boolean result = true; IPAddress rhsNetwork; rhsNetwork = rhs.getNetwork(); IPAddress lhsNetwork; lhsNetwork = getNetwork(); for (int i = 0; i rhs.address[i]) return true; } return false; } }

Problem Description: In this assignment, you will modify a solution to Assignment 1. You may use your solution, or my posted one. You wil make the RoutingTable data structure more efficient in two ways a) Change the routingTable declaration in Router class to be an object of ArrayList. Note -this means you will delete the numEntries and maxEntries data methods in the Router class as you will no longer need them b) Change the insert into the routing table so that the addresses are in numeric order from smallest to largest in the most efficient way possible. Once the routing table is ordered, modify your search to also make it as efficient as possible (Note - do NOT use Generic Collection methods yet) NOTE: you will need to be able to compare two IPAddress objects and also two RoutingTableEntry objects and so you will need to add a method in each of these classes to do this. The isEqual method in IPAddress is a model for this process. Sample Output for this file: p 192 168 12 24 192 168 1 4 24 e0 d 192 168 1 2 24 192 168 1 4 24 123456778123 p 192 168 4 6 24 192 168 3 2 24 e1 p 192 168 4 6 24 192 168 3 2 24 e1 d 192 168 4 1 24 192 168 3 2 24 aaaaaa p 192 168 3 8 24 11 0428s0 d 192 168 33 24 192 168 3 224 bbbbb d 192 168 55 16 192 168 32 24 abcde

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

Step: 3

blur-text-image

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

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students also viewed these Databases questions

Question

What is involved in the administration of a labor agreement?

Answered: 1 week ago