Procházet zdrojové kódy

fix : enable newNode's source & destination address

master
우인혜 před 6 roky
rodič
revize
668f290e6e

+ 19
- 0
.vscode/tasks.json Zobrazit soubor

@@ -0,0 +1,19 @@
1
+{
2
+    // See https://go.microsoft.com/fwlink/?LinkId=733558
3
+    // for the documentation about the tasks.json format
4
+    "version": "2.0.0",
5
+    "tasks": [
6
+        {
7
+            "label": "verify",
8
+            "type": "shell",
9
+            "command": "mvn -B verify",
10
+            "group": "build"
11
+        },
12
+        {
13
+            "label": "test",
14
+            "type": "shell",
15
+            "command": "mvn -B test",
16
+            "group": "test"
17
+        }
18
+    ]
19
+}

+ 20
- 10
src/main/java/com/mycompany/app/App.java Zobrazit soubor

@@ -16,12 +16,11 @@ public class App {
16 16
         File file = new File("2016_05_05_05.txt"); // Create file variable
17 17
 
18 18
         Vector<String> IP = new Vector<String>(10); // inbound ip
19
-        Vector<Node> networkNode = new Vector<Node>();  //  Node vector 정의
19
+        Vector<Node> networkNode = new Vector<Node>();  //  Store Node
20 20
 
21 21
         try {
22 22
             // Insert file in BufferedReader
23 23
             BufferedReader reader = new BufferedReader(new FileReader(file));
24
-            // 파일을 한줄씩 읽어 넣기 위한 변수 line
25 24
             String line = null;
26 25
 
27 26
             // Read and Insert 1 line and Excute if not null
@@ -36,11 +35,10 @@ public class App {
36 35
                     jsonObject = (JSONObject) jsonParser.parse(line);
37 36
 
38 37
                 } catch (ParseException e) {
39
-                    // TODO Auto-generated catch block
40 38
                     e.printStackTrace();
41 39
                 }
42 40
 
43
-                //  packet 하나씩 받아서 처리
41
+                //  Handling Packet one and one
44 42
                 try {
45 43
                     Packet newPacket = packet.getClass().newInstance();
46 44
                     newPacket.eip = jsonObject.get("eip");
@@ -65,29 +63,32 @@ public class App {
65 63
                         newDest.setDestIp(newPacket.nip);
66 64
                         newDest.setDestPort(newPacket.nport);
67 65
                         newNode.ip = newSource.getSourceIp();
68
-                        //  Insert source & destination address
69
-                        newNode.source.add(newSource);
70
-                        newNode.destination.add(newDest);
66
+                        //  Insert source & destination address -> need edit
67
+                        (newNode.source).addElement(newSource);
68
+                        (newNode.destination).addElement(newDest);
71 69
                         //  sum packet & byte
72 70
                         newNode.sumPkt(newPacket.out_pkt);
73 71
                         newNode.sumByte(newPacket.out_byte);
74 72
                         //  Insert newNode
75 73
                         networkNode.add(newNode);
76 74
                     } catch (InstantiationException e) {
75
+                        e.printStackTrace();
77 76
 
78 77
                     } catch (IllegalAccessException e) {
78
+                        e.printStackTrace();
79 79
 
80 80
                     }
81 81
                 }
82
-                else {
82
+                else if(IP.contains(newPacket.eip)){
83
+                    //  Find Node
84
+                    Node searchNode = findNode(networkNode, newPacket.eip);
85
+
83 86
 
84 87
                 }
85 88
 
86 89
                 } catch (InstantiationException e1) {
87
-                    // TODO Auto-generated catch block
88 90
                     e1.printStackTrace();
89 91
                 } catch (IllegalAccessException e1) {
90
-                    // TODO Auto-generated catch block
91 92
                     e1.printStackTrace();
92 93
                 }
93 94
             }
@@ -98,4 +99,13 @@ public class App {
98 99
             e.printStackTrace();
99 100
         }
100 101
     }
102
+    public static Node findNode(Vector<Node> nodeVector, Object obj){
103
+        for(int i = 0; i < nodeVector.size(); i++){
104
+            if(nodeVector.elementAt(i).ip.equals((String)obj)){
105
+                Node sNode = nodeVector.elementAt(i);
106
+                return sNode;
107
+            }
108
+        }
109
+        return null;
110
+    }
101 111
 }

+ 4
- 4
src/main/java/com/mycompany/app/Eips.java Zobrazit soubor

@@ -1,17 +1,17 @@
1 1
 package com.mycompany.app;
2 2
 class Eips{
3
-    String ip;
4
-    int port;
3
+    String ip = null;
4
+    long port = 0;
5 5
     String getSourceIp(){
6 6
         return ip;
7 7
     }
8
-    int getSourcePort(){
8
+    long getSourcePort(){
9 9
         return port;
10 10
     }
11 11
     void setSourceIp(Object obj){
12 12
         ip = (String)obj;
13 13
     }
14 14
     void setSourcePort(Object obj){
15
-        port = (int)obj;
15
+        port = (long)obj;
16 16
     }
17 17
 }

+ 4
- 4
src/main/java/com/mycompany/app/Nips.java Zobrazit soubor

@@ -1,17 +1,17 @@
1 1
 package com.mycompany.app;
2 2
 class Nips{
3
-    String ip;
4
-    int port;
3
+    String ip=null;
4
+    long port=0;
5 5
     String getDestIp(){
6 6
         return ip;
7 7
     }
8
-    int getDestPort(){
8
+    long getDestPort(){
9 9
         return port;
10 10
     }
11 11
     void setDestIp(Object obj){
12 12
         ip = (String)obj;
13 13
     }
14 14
     void setDestPort(Object obj){
15
-        port = (int)obj;
15
+        port = (long)obj;
16 16
     }
17 17
 }

+ 34
- 7
src/main/java/com/mycompany/app/Node.java Zobrazit soubor

@@ -3,9 +3,9 @@ package com.mycompany.app;
3 3
 import java.util.Vector;
4 4
 
5 5
 class Node {
6
-    Vector<Eips> source;
7
-    Vector<Nips> destination; 
8
-    String ip; //  ip
6
+    Vector<Eips> source = new Vector<Eips>();
7
+    Vector<Nips> destination = new Vector<Nips>(); 
8
+    String ip=null; //  ip
9 9
 
10 10
     double vulnerability = 1/30;   //  inbound value
11 11
     double aggression;      //  outbound value
@@ -16,10 +16,37 @@ class Node {
16 16
 
17 17
     Integer total_port_counts;
18 18
 
19
-    long sumPkt(Object obj){
20
-        return total_pkt + (long)obj;
19
+    void sumPkt(Object obj){
20
+        total_pkt +=(long)obj;
21 21
     }
22
-    long sumByte(Object obj){
23
-        return total_bytes + (long)obj;
22
+    void sumByte(Object obj){
23
+        total_bytes += (long)obj;
24 24
     }
25
+    long getTotal_pkt(){
26
+        return total_pkt;
27
+    }
28
+    long getTotal_bytes(){
29
+        return total_bytes;
30
+    }
31
+    double getVulnerability(){
32
+        return vulnerability;
33
+    }
34
+    double getAggression(){
35
+        return aggression;
36
+    }
37
+    double getCo_efficient(){
38
+        return co_efficient;
39
+    }
40
+    /*
41
+    void setVulnerability(){
42
+
43
+    }
44
+    void setAggression(){
45
+
46
+    }
47
+    void setCo_efficient(){
48
+
49
+    }
50
+    */
51
+
25 52
 }

binární
target/classes/com/mycompany/app/App.class Zobrazit soubor


binární
target/classes/com/mycompany/app/Eips.class Zobrazit soubor


binární
target/classes/com/mycompany/app/Nips.class Zobrazit soubor


binární
target/classes/com/mycompany/app/Node.class Zobrazit soubor


Načítá se…
Zrušit
Uložit