diff --git a/src/netKnow/Class/routing/CiscoConfigurationCodeGenerator.java b/src/netKnow/Class/routing/CiscoConfigurationCodeGenerator.java new file mode 100644 index 0000000..7b54c35 --- /dev/null +++ b/src/netKnow/Class/routing/CiscoConfigurationCodeGenerator.java @@ -0,0 +1,132 @@ +package netKnow.Class.routing; + +import java.util.List; + +/** + * Created by MQ on 2017-06-06. + */ +public class CiscoConfigurationCodeGenerator { + List routersList; + List nodes; + + public CiscoConfigurationCodeGenerator(List routersList, List nodes){ + this.routersList = routersList; + this.nodes = nodes; + } + + public String getConfiguration(){ + String out = ""; + for(int i=0; i 0){ + NodeLinkData data = connectedToInterfaceNode.nodeLinks.get(i).nodeLinkData; + for(int j=0; j mLinkIds = new ArrayList(); + public List nodeLinks = new ArrayList<>(); + public List nodePCLink = new ArrayList<>(); + public List pcList = new ArrayList<>(); private EventHandler mContextDragOver; private EventHandler mContextDragDropped; @@ -51,6 +54,7 @@ public class DraggableNode extends AnchorPane{ private DragIconType mType = null; private Point2D mDragOffset = new Point2D(0.0, 0.0); public DraggableNodeData draggableNodeData; + public RIPInfo ripInfo; public DraggableNode() { self = this; @@ -70,6 +74,11 @@ public DraggableNode() { setId(UUID.randomUUID().toString()); } + public DraggableNode(String id){ + self = this; + setId(id); + } + public void setTitleBar(String titleBarText) { titleBar.setText(titleBarText); } @@ -278,10 +287,6 @@ public void setType(DragIconType type) { case switchIco: nodeBody.getStyleClass().add("icon-switch"); break; - case labelIco: - nodeBody.getStyleClass().add("icon-label"); - break; - default: break; } diff --git a/src/netKnow/Class/routing/DraggableNodeData.java b/src/netKnow/Class/routing/DraggableNodeData.java index db2c07f..91dd8cb 100644 --- a/src/netKnow/Class/routing/DraggableNodeData.java +++ b/src/netKnow/Class/routing/DraggableNodeData.java @@ -7,10 +7,17 @@ public class DraggableNodeData { private String name; private String host; + private String ip; - public DraggableNodeData(String name, String host){ + public DraggableNodeData(String name, String x){ this.name = name; - this.host = host; + if(x.length() > 3){ + this.ip = x; + System.out.println("IP: " + this.ip); + }else{ + this.host = x; + System.out.println("host: " + this.host); + } } public String getName(){ @@ -20,4 +27,23 @@ public String getName(){ public String getHost(){ return host; } + + public String getIp() { + return ip; + } + + public String getIpWithoutMask(){ + String [] pp = ip.split("/"); + return pp[0]; + } + + public String getMask(){ + System.out.println("MY IP IS: " + ip); + String [] pp = ip.split("/"); + int cidrMask = Integer.parseInt(pp[1]); + long bits = 0; + bits = 0xffffffff ^ (1 << 32 - cidrMask) - 1; + String mask = String.format("%d.%d.%d.%d", (bits & 0x0000000000ff000000L) >> 24, (bits & 0x0000000000ff0000) >> 16, (bits & 0x0000000000ff00) >> 8, bits & 0xff); + return mask; + } } diff --git a/src/netKnow/Class/routing/JuniperConfigurationCodeGenerator.java b/src/netKnow/Class/routing/JuniperConfigurationCodeGenerator.java new file mode 100644 index 0000000..b788562 --- /dev/null +++ b/src/netKnow/Class/routing/JuniperConfigurationCodeGenerator.java @@ -0,0 +1,134 @@ +package netKnow.Class.routing; + +import java.util.List; + +/** + * Created by MQ on 2017-06-06. + */ +public class JuniperConfigurationCodeGenerator { + + List routersList; + List nodes; + + public JuniperConfigurationCodeGenerator(List routersList, List nodes){ + this.routersList = routersList; + this.nodes = nodes; + } + + public String getConfiguration(){ + String out = ""; + for(int i=0; i 0){ + NodeLinkData data = connectedToInterfaceNode.nodeLinks.get(i).nodeLinkData; + for(int j=0; j> 24, (bits & 0x0000000000ff0000) >> 16, (bits & 0x0000000000ff00) >> 8, bits & 0xff); + return mask; + } } diff --git a/src/netKnow/Class/routing/RIPInfo.java b/src/netKnow/Class/routing/RIPInfo.java new file mode 100644 index 0000000..5f50e59 --- /dev/null +++ b/src/netKnow/Class/routing/RIPInfo.java @@ -0,0 +1,72 @@ +package netKnow.Class.routing; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by MQ on 2017-06-05. + */ +public class RIPInfo { + + private DraggableNode routerFrom; + private List ripWayList; + private DraggableNode[] prev; + private List orderedRouters; + + public RIPInfo(DraggableNode[] prev, List orderedRouters){ + routerFrom = orderedRouters.get(0); + this.prev = prev; + this.orderedRouters = orderedRouters; + ripWayList = new ArrayList<>(); + fillWayList(); + showWayList(); + } + + public void showWayList(){ + System.out.println("Way for: " + routerFrom.titleBar.getText()); + for(int i=0; i way; + + public RIPWay(DraggableNode dest){ + destination = dest; + way = new ArrayList<>(); + } + + public void addToEnd(DraggableNode x){ + way.add(x); + } + + public void addToStart(DraggableNode x){ + way.add(0, x); + } + + public DraggableNode getDestination() { + return destination; + } + + public void setDestination(DraggableNode destination) { + this.destination = destination; + } + + public List getWay() { + return way; + } +} diff --git a/src/netKnow/DatabaseConnection.java b/src/netKnow/DatabaseConnection.java index 6cc169e..9d134b9 100644 --- a/src/netKnow/DatabaseConnection.java +++ b/src/netKnow/DatabaseConnection.java @@ -14,8 +14,8 @@ public class DatabaseConnection { public static Connection getConenction(){ try { - connection = DriverManager.getConnection(DBURL, DBUSER, DBPASS); - //connection = DriverManager.getConnection(DBURL2, DBUSER2, DBPASS); + //connection = DriverManager.getConnection(DBURL, DBUSER, DBPASS); + connection = DriverManager.getConnection(DBURL2, DBUSER2, DBPASS); if(connection != null){ System.out.println("Connected to the datebase :D"); return connection; diff --git a/src/netKnow/Main.java b/src/netKnow/Main.java index 017a14b..f20c12e 100644 --- a/src/netKnow/Main.java +++ b/src/netKnow/Main.java @@ -6,6 +6,7 @@ import javafx.scene.layout.VBox; import javafx.stage.Stage; import netKnow.scene.LoginScene; +import netKnow.scene.MainOptionsScene; import netKnow.scene.RoutingScene; import netKnow.Class.IP; import netKnow.Code.NetworkAggregation; diff --git a/src/netKnow/controller/CodeGeneratorController.java b/src/netKnow/controller/CodeGeneratorController.java new file mode 100644 index 0000000..3a862c0 --- /dev/null +++ b/src/netKnow/controller/CodeGeneratorController.java @@ -0,0 +1,49 @@ +package netKnow.controller; + +/** + * Created by MQ on 2017-06-06. + */ +import javafx.fxml.FXML; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.TextArea; +import javafx.scene.layout.GridPane; +import netKnow.Class.routing.CiscoConfigurationCodeGenerator; +import netKnow.Class.routing.DraggableNode; +import netKnow.Class.routing.JuniperConfigurationCodeGenerator; +import netKnow.scene.MainOptionsScene; + +import java.util.List; + +public class CodeGeneratorController { + + private Scene scene; + @FXML + private TextArea textAreaField; + @FXML + private GridPane buttons; + @FXML + private Button menuButton; + @FXML + private Button jakisButton; + List routersList; + List nodeList; + String code; + String typeOfDevice; + + + @FXML + void initialize(){ + menuButton.setOnAction(e-> new MainOptionsScene(scene)); + } + + public void setScene(Scene scene){ + this.scene = scene; + } + + public void setDevicesLists(String code, List routersList, List nodeList){ + this.routersList = routersList; + this.nodeList = nodeList; + textAreaField.setText(code); + } +} diff --git a/src/netKnow/controller/RoutingController.java b/src/netKnow/controller/RoutingController.java index c530753..a6781bb 100644 --- a/src/netKnow/controller/RoutingController.java +++ b/src/netKnow/controller/RoutingController.java @@ -57,26 +57,39 @@ private void initialize() { goBackButton.setOnAction(e -> new MainOptionsScene(scene)); routingTypeButton.setOnAction(e -> { + // sciaganie nodow do listy nodow List nodes = new ArrayList<>(); for(int i=0; i { - System.out.println("drag dropped"); - DragContainer container = (DragContainer) event.getDragboard().getContent(DragContainer.AddNode); container.addData("scene_coords", new Point2D(event.getSceneX(), event.getSceneY())); @@ -239,6 +250,7 @@ private void buildDragHandlers() { link.bindEnds(source, target); NodeLinkData ipAddress = NodeLinkPopUp.display(); + if(ipAddress != null){ link.infoLabel.setText(ipAddress.getAddress()); link.relocateLabelCoords(right_pane); @@ -256,4 +268,5 @@ private void buildDragHandlers() { public void setScene(Scene scene){ this.scene = scene; } + } diff --git a/src/netKnow/controller/RoutingTypeController.java b/src/netKnow/controller/RoutingTypeController.java index fcb79ba..a140b0b 100644 --- a/src/netKnow/controller/RoutingTypeController.java +++ b/src/netKnow/controller/RoutingTypeController.java @@ -1,12 +1,20 @@ package netKnow.controller; +import com.sun.org.apache.xpath.internal.SourceTree; import javafx.collections.FXCollections; import javafx.fxml.FXML; +import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.ChoiceBox; import javafx.scene.control.ComboBox; +import javafx.scene.layout.AnchorPane; +import netKnow.Class.routing.*; +import netKnow.scene.CodeGeneratorScene; + +import java.util.ArrayList; +import java.util.List; /** * Created by MQ on 2017-05-19. @@ -18,36 +26,174 @@ public class RoutingTypeController { @FXML private ComboBox typeOfDeviceChoiceBox; @FXML - private ComboBox typeOfRoutingChoiceBox; - @FXML private Button generateCodeButton; @FXML private Button simulationButton; + private List nodeList; + private List routersList; @FXML void initialize(){ generateCodeButton.setOnAction(e ->{ - System.out.println("Tu bedzie generowanie kodu!"); + String typeOfConnection = typeOfDeviceChoiceBox.getValue(); + new CodeGeneratorScene(scene, typeOfConnection, routersList, nodeList); + //new CodeGeneratorScene(scene); + //JuniperConfigurationCodeGenerator juniper = new JuniperConfigurationCodeGenerator(routersList, nodeList); + //String out = juniper.getConfiguration(); + //System.out.println(out); + //System.out.println("Tu bedzie generowanie kodu!"); }); simulationButton.setOnAction(e -> { + for(int i=0; i nodeList){ + this.nodeList = nodeList; + setRoutersList(); + setNodePCLink(); + setPCConnectedToRouters(); + } + + private void setRoutersList(){ + routersList = new ArrayList<>(); + for(int i=0; i(); + System.out.println("Aktualny size to: "+routersList.size()); + routersList.add(new DraggableNode("R1")); // 0 + routersList.add(new DraggableNode("R2")); // 1 + routersList.add(new DraggableNode("R3")); // 2 + routersList.add(new DraggableNode("R4")); // 3 + routersList.add(new DraggableNode("R5")); // 4 + routersList.get(0).nodeLinks.add(new NodeLink("r1-connect1", "R1", "R2")); + routersList.get(0).nodeLinks.add(new NodeLink("r1-connect2", "R1", "R3")); + routersList.get(0).nodeLinks.add(new NodeLink("r1-connect3", "R1", "R4")); + routersList.get(1).nodeLinks.add(new NodeLink("r2-connect1", "R2", "R1")); + routersList.get(1).nodeLinks.add(new NodeLink("r2-connect2", "R2", "R4")); + routersList.get(2).nodeLinks.add(new NodeLink("r3-connect1", "R3", "R1")); + routersList.get(2).nodeLinks.add(new NodeLink("r3-connect2", "R3", "R4")); + routersList.get(3).nodeLinks.add(new NodeLink("r4-connect1", "R4", "R1")); + routersList.get(3).nodeLinks.add(new NodeLink("r4-connect2", "R4", "R2")); + routersList.get(3).nodeLinks.add(new NodeLink("r4-connect3", "R4", "R3")); + routersList.get(3).nodeLinks.add(new NodeLink("r4-connect4", "R4", "R5")); + routersList.get(4).nodeLinks.add(new NodeLink("r5-connect1", "R5", "R4")); + + } + private DraggableNode[] countRIPPaths(int v){ + //setMyOwnRoutersAndLinkers(); + + int [] distance = new int[routersList.size()]; + DraggableNode [] previous = new DraggableNode[routersList.size()]; + + for(int i=0; i distance[l] + 1){ + distance[index] = distance[l] + 1; + previous[index] = routersList.get(l); + } + } + } + } + + /*for(int i=0; i + + + + + + + +
+ +
+ + + + + + + + + + + +