Question
TWO JAVA PACKAGES YOU NEED TO USE AND OUTPUT CODE BELOW As network packets are received by the NIDS, each network packet is assigned a
TWO JAVA PACKAGES YOU NEED TO USE AND OUTPUT CODE BELOW
As network packets are received by the NIDS, each network packet is assigned a priority, which in this project is an integer. The priority of a packet denotes its level of urgency in processing. More specifically, packets with a higher priority need to be analyzed by the NIDS first, and hence need to be permitted to travel to their destination as soon as possible if they are found to be non-malicious. Those packets that have a lower priority may wait a little longer. For example, packets that carry the audio and video traffic of a Google meet session have higher priorities than packets that carry out a time synchronization with a remote server on the Internet. The NIDS inserts all packets in a priority queue. The NIDS then processes those packets one at a time, giving precedence to those packets that have higher priorities.
For the sake of keeping this project in scope, only the priority of each packet is inserted in the priority queue instead of the entire headers and data of the packet. The code that comes with this project consists of two classes, namely IDSWorkerClass.java and PrioritizedNetworkTraffic.java. IDSWorkerClass contains code that is used by the NIDS to operate on the priority queue. PrioritizedNetworkTraffic is the class that implements the actual priority queue and its operations, and hence is the class that students are required to implement in this project.
Students can verify the correctness of their PrioritizedNetworkTraffic class by comparing their output with the following output:
IDS analysis of prioritized network traffic is running...
-------------------------------------------------------------
Displaying priority queue data...
Index: 0 Packet Priority: -1
Index: 1 Packet Priority: -1
Index: 2 Packet Priority: -1
Index: 3 Packet Priority: -1
Index: 4 Packet Priority: -1
Index: 5 Packet Priority: -1
Index: 6 Packet Priority: -1
Index: 7 Packet Priority: -1
Current Head: -1; Current Tail: 0
-------------------------------------------------------------
At Enqueue: inserted 4 in index 0
-------------------------------------------------------------
Displaying priority queue data...
Index: 0 Packet Priority: 4
Index: 1 Packet Priority: -1
Index: 2 Packet Priority: -1
Index: 3 Packet Priority: -1
Index: 4 Packet Priority: -1
Index: 5 Packet Priority: -1
Index: 6 Packet Priority: -1
Index: 7 Packet Priority: -1
Current Head: 0; Current Tail: 1
-------------------------------------------------------------
At Enqueue: inserted 9 in index 1
-------------------------------------------------------------
Displaying priority queue data...
Index: 0 Packet Priority: 4
Index: 1 Packet Priority: 9
Index: 2 Packet Priority: -1
Index: 3 Packet Priority: -1
Index: 4 Packet Priority: -1
Index: 5 Packet Priority: -1
Index: 6 Packet Priority: -1
Index: 7 Packet Priority: -1
Current Head: 1; Current Tail: 2
-------------------------------------------------------------
At Enqueue: inserted 15 in index 2
-------------------------------------------------------------
Displaying priority queue data... Index: 0 Packet Priority: 4 Index: 1 Packet Priority: 9 Index: 2 Packet Priority: 15 Index: 3 Packet Priority: -1 Index: 4 Packet Priority: -1 Index: 5 Packet Priority: -1 Index: 6 Packet Priority: -1 Index: 7 Packet Priority: -1
Current Head: 2; Current Tail: 3 ------------------------------------------------------------- At Enqueue: inserted 1 in index 3 ------------------------------------------------------------- Displaying priority queue data... Index: 0 Packet Priority: 4 Index: 1 Packet Priority: 9 Index: 2 Packet Priority: 15 Index: 3 Packet Priority: 1 Index: 4 Packet Priority: -1 Index: 5 Packet Priority: -1 Index: 6 Packet Priority: -1 Index: 7 Packet Priority: -1
Current Head: 2; Current Tail: 4 ------------------------------------------------------------- At Enqueue: inserted 4 in index 4 ------------------------------------------------------------- Displaying priority queue data... Index: 0 Packet Priority: 4 Index: 1 Packet Priority: 9 Index: 2 Packet Priority: 15 Index: 3 Packet Priority: 1 Index: 4 Packet Priority: 4 Index: 5 Packet Priority: -1 Index: 6 Packet Priority: -1 Index: 7 Packet Priority: -1
Current Head: 2; Current Tail: 5 ------------------------------------------------------------- At Enqueue: inserted 10 in index 5 ------------------------------------------------------------- Displaying priority queue data... Index: 0 Packet Priority: 4 Index: 1 Packet Priority: 9 Index: 2 Packet Priority: 15 Index: 3 Packet Priority: 1 Index: 4 Packet Priority: 4 Index: 5 Packet Priority: 10 Index: 6 Packet Priority: -1 Index: 7 Packet Priority: -1
Current Head: 2; Current Tail: 6 ------------------------------------------------------------- At Enqueue: inserted 5 in index 6 ------------------------------------------------------------- Displaying priority queue data... Index: 0 Packet Priority: 4 Index: 1 Packet Priority: 9 Index: 2 Packet Priority: 15 Index: 3 Packet Priority: 1 Index: 4 Packet Priority: 4 Index: 5 Packet Priority: 10 Index: 6 Packet Priority: 5 Index: 7 Packet Priority: -1
Current Head: 2; Current Tail: 7 ------------------------------------------------------------- At Enqueue: inserted 3 in index 7 ------------------------------------------------------------- Displaying priority queue data... Index: 0 Packet Priority: 4 Index: 1 Packet Priority: 9 Index: 2 Packet Priority: 15 Index: 3 Packet Priority: 1 Index: 4 Packet Priority: 4 Index: 5 Packet Priority: 10 Index: 6 Packet Priority: 5 Index: 7 Packet Priority: 3
Current Head: 2; Current Tail: 3 ------------------------------------------------------------- At Dequeue: removed 15 from index 2 ------------------------------------------------------------- Displaying priority queue data... Index: 0 Packet Priority: 4 Index: 1 Packet Priority: 9 Index: 2 Packet Priority: -1 Index: 3 Packet Priority: 1 Index: 4 Packet Priority: 4 Index: 5 Packet Priority: 10 Index: 6 Packet Priority: 5 Index: 7 Packet Priority: 3
Current Head: 5; Current Tail: 2 ------------------------------------------------------------- At Enqueue: inserted 17 in index 2 ------------------------------------------------------------- Displaying priority queue data... Index: 0 Packet Priority: 4 Index: 1 Packet Priority: 9 Index: 2 Packet Priority: 17 Index: 3 Packet Priority: 1 Index: 4 Packet Priority: 4 Index: 5 Packet Priority: 10 Index: 6 Packet Priority: 5 Index: 7 Packet Priority: 3
Current Head: 2; Current Tail: 3 -------------------------------------------------------------
CODE: (fill in where it says "implement me"
import textbook.PrioritizedNetworkTraffic;
public class IDSWorkerClass {
public static void main(String[] args) {
int arraySize = 8;
int Max = 0;
System.out.println("IDS analysis of prioritized network traffic is running... ");
PrioritizedNetworkTraffic ptraffic = new PrioritizedNetworkTraffic(arraySize);
ptraffic.DisplayPriorityQueue();
ptraffic.Enqueue(4);
ptraffic.DisplayPriorityQueue();
ptraffic.Enqueue(9);
ptraffic.DisplayPriorityQueue();
ptraffic.Enqueue(15);
ptraffic.DisplayPriorityQueue();
ptraffic.Enqueue(1);
ptraffic.DisplayPriorityQueue();
ptraffic.Enqueue(4);
ptraffic.DisplayPriorityQueue();
ptraffic.Enqueue(10);
ptraffic.DisplayPriorityQueue();
ptraffic.Enqueue(5);
ptraffic.DisplayPriorityQueue();
ptraffic.Enqueue(3);
ptraffic.DisplayPriorityQueue();
ptraffic.Dequeue();
ptraffic.DisplayPriorityQueue();
ptraffic.Enqueue(17);
ptraffic.DisplayPriorityQueue();
}
}
package textbook;
public class PrioritizedNetworkTraffic {
private int[] Q;
private int head = -1;
private int tail = 0;
private int length;
// Precondition: Priority queue Q is defined but not created.
// Postcondition: Priority queue Q is created, and its size is set to "queueSize".
// All values of Q are initialized to -1.
// length is set to "queueSize".
public PrioritizedNetworkTraffic(int queueSize)
{
// Implement me.
}
// Precondition: Priority queue Q is existent.
// "tail" is already set to the index of Q where a new packet may be inserted.
// "head" is already set to the index of Q where the packet with the highest priority is stored.
// Postcondition: A new packet with priority "newElement" is inserted in the priority queue Q.
// "head" is set to the index of Q where the packet with the highest priority is stored.
// "tail" is set to the next index of Q that is available for storage of a new element.
// If Q is full, "tail" is to the index of Q where the packet with the lowest priority is stored.
public void Enqueue(int newElement)
{
// Implement me.
}
// Precondition: Priority queue Q is existent.
// "head" is already set to the index of Q where the packet with the highest priority is stored.
// If Q is empty, "head" is -1.
// "tail" is already set to the index of Q where a new packet may be inserted.
// Postcondition: The packet with index equal to "head" is removed from Q and is returned to the caller.
// -1 is inserted in its place, namely in the cell of Q where the removed packet was previously stored.
// "head" is set to the index of Q where the packet with the highest priority is stored.
// "tail" is set to the next index of Q that is available for storage of a new element.
// If Q is empty, "head" is set to -1 and "tail" is set to 0.
public int Dequeue()
{
// Implement me.
}
// Precondition: Priority queue Q is existent.
// "startIndex" and "endIndex" are indices of Q that define the beginning and the end, respectively, of the subarray of Q that needs to be searched.
// "startIndex" and "endIndex" may refer to the entire Q.
// Postcondition: The index of Q, where the packet with the highest priority is stored, is found and is returned to the caller.
public int LocateNextHead(int startIndex, int endIndex)
{
// Implement me.
}
// Precondition: Priority queue Q is existent.
// "startIndex" and "endIndex" are indices of Q that define the beginning and the end, respectively, of the subarray of Q that needs to be searched.
// "startIndex" and "endIndex" may refer to the entire Q.
// Postcondition: The index of Q, where the packet with the lowest priority is stored, is found and is returned to the caller.
public int LocateNextTail(int startIndex, int endIndex)
{
// Implement me.
}
// Precondition: Priority queue Q is existent.
// Postcondition: The index and priority of each packet in Q are displayed on the monitor.
public void DisplayPriorityQueue()
{
// Implement me.
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started