Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions src/netKnow/Class/IP.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package netKnow.Class;

public class IP {
public class IP implements Comparable <IP>{
private int [] ipArray;
private int [] maskArray;
private String fullIPAdress [];
Expand All @@ -15,6 +15,8 @@ public IP(String [] fullIPAdress){
ipArray = new int[4];
maskArray = new int[4];
this.fullIPAdress = fullIPAdress;
convertStringToIPAdress(fullIPAdress);
convertStringToMask();
}

private void convertStringToIPAdress(String [] fullIPAdress){
Expand All @@ -23,16 +25,14 @@ private void convertStringToIPAdress(String [] fullIPAdress){
}
}

private void convertStringToMask(String mask){
private void convertStringToMask(){
int n = Integer.parseInt(fullIPAdress[4]);
for(int i = 0; i < n; i++){
maskArray[i/8] |= (128 >> (i%8));
}
}

public void computeData(){
convertStringToIPAdress(fullIPAdress);
convertStringToMask(fullIPAdress[4]);
network = computeNetwork();
broadcast = computeBroadcast();
numberOfHosts = Integer.toString(numberOfHosts());
Expand Down Expand Up @@ -77,6 +77,22 @@ private String maxHost()
return (tmp1[0] + "." + tmp1[1] + "." + tmp1[2] + "." + tmp2);
}

public int compareTo(IP ip){
if(this.ipArray[0] == ip.ipArray[0] && this.ipArray[1] == ip.ipArray[1] && this.ipArray[2] == ip.ipArray[2]
&& this.ipArray[3] == ip.ipArray[3]){
return 0;
}
else if((this.ipArray[0] > ip.ipArray[0]) || (this.ipArray[0] == ip.ipArray[0] && this.ipArray[1] > ip.ipArray[1]) ||
(this.ipArray[0] == ip.ipArray[0] && this.ipArray[1] == ip.ipArray[1] && this.ipArray[2] > ip.ipArray[2]) ||
(this.ipArray[0] == ip.ipArray[0] && this.ipArray[1] == ip.ipArray[1] && this.ipArray[2] == ip.ipArray[2]
&& this.ipArray[3] > ip.ipArray[3])){
return 1;
}
else{
return -1;
}
}

public String getNetwork() {
return network;
}
Expand All @@ -96,4 +112,17 @@ public String getMinHost() {
public String getNumberOfHosts() {
return numberOfHosts;
}

public String getIP(){
return (ipArray[0]+ "." + ipArray[1]+ "." + ipArray[2]+ "." + ipArray[3] + "/" + fullIPAdress[4]);
}

public int[] getIPAsInt(){ return ipArray; }

public int getMaskAsInt(){return Integer.parseInt(fullIPAdress[4]);}

public void setMask(int k){
fullIPAdress[4] = Integer.toString(k);
convertStringToMask();
};
}
52 changes: 52 additions & 0 deletions src/netKnow/Code/NetworkAggregation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package netKnow.Code;

import netKnow.Class.IP;

import java.util.Arrays;


/**
* Created by Kuba on 16.05.2017.
*/
public class NetworkAggregation {
private IP[] IPArray;

public NetworkAggregation(IP[] Array) {
this.IPArray = Array;
}

public IP[] aggregateNetwork() {
int [][] tmp = new int[IPArray.length][4];
IP [] result = new IP[IPArray.length];
for (int i = 0; i < IPArray.length; i++) {
tmp[i] = IPArray[i].getIPAsInt();
}
Arrays.sort(IPArray);
int k = 0;
for(int i = 0; i < IPArray.length; i++){
int [] tmp2 = tmp[i];
int [] tmp3 = IPArray[i].getIPAsInt();
int j = IPArray[i].getMaskAsInt() - 1;
int mask = j+1;
String [] tmpString1 = {Integer.toString(tmp3[0]), Integer.toString(tmp3[1]), Integer.toString(tmp3[2]),
Integer.toString(tmp3[3]), Integer.toString(mask)};
result[k] = new IP(tmpString1);
while(j > 0) {
tmp2[j / 8] |= 128 >> j % 8;
String[] tmpString = {Integer.toString(tmp2[0]), Integer.toString(tmp2[1]), Integer.toString(tmp2[2]),
Integer.toString(tmp2[3]), Integer.toString(j)};
IP newIP = new IP(tmpString);
int key = Arrays.binarySearch(IPArray, newIP);
if (key > 0 && key < IPArray.length && IPArray[key].compareTo(newIP) == 0) {
i = key;
mask = j;
}
if(i < IPArray.length - 1)
result[k].setMask(mask);
j--;
}
k++;
}
return result;
}
}
8 changes: 5 additions & 3 deletions src/netKnow/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import javafx.stage.Stage;
import netKnow.scene.LoginScene;
import netKnow.scene.RoutingScene;
import netKnow.Class.IP;
import netKnow.Code.NetworkAggregation;


public class Main extends Application {
Expand All @@ -18,10 +20,10 @@ public void start(Stage primaryStage) throws Exception{
window.setTitle("netKnow - aplication that will change your life");
Scene scene = new Scene(new VBox(), 1000, 800);
window.setScene(scene);
//new LoginScene(scene);
new RoutingScene(scene);
new LoginScene(scene);
//new RoutingScene(scene);
window.show();
//window.setFullScreen(true);
//window.setFullScreen(true);*/
}


Expand Down