Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-WIC-Cnf
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3
Issues
3
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
CommunityXG
OpenXG-WIC-Cnf
Commits
ce5d2893
Commit
ce5d2893
authored
Jul 03, 2020
by
Hu Jintao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加路径计算代码模块
parent
d86722e1
Changes
24
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
2605 additions
and
1 deletion
+2605
-1
apps/cnf-path-computing/business-api/pom.xml
apps/cnf-path-computing/business-api/pom.xml
+17
-0
apps/cnf-path-computing/business-api/src/main/java/com/pitong/business/item/DataPackage.java
...i/src/main/java/com/pitong/business/item/DataPackage.java
+79
-0
apps/cnf-path-computing/business-api/src/main/java/com/pitong/business/item/Picture.java
...s-api/src/main/java/com/pitong/business/item/Picture.java
+19
-0
apps/cnf-path-computing/businessInCloud/pom.xml
apps/cnf-path-computing/businessInCloud/pom.xml
+55
-0
apps/cnf-path-computing/businessInCloud/src/main/java/top/ninwoo/test/BisheTestMain.java
...sInCloud/src/main/java/top/ninwoo/test/BisheTestMain.java
+195
-0
apps/cnf-path-computing/businessInCloud/src/main/java/top/ninwoo/test/doMap/DoMap.java
...essInCloud/src/main/java/top/ninwoo/test/doMap/DoMap.java
+506
-0
apps/cnf-path-computing/businessInCloud/src/main/java/top/ninwoo/test/doMap/InterSlotDijstraV2.java
...c/main/java/top/ninwoo/test/doMap/InterSlotDijstraV2.java
+156
-0
apps/cnf-path-computing/businessInCloud/src/main/java/top/ninwoo/test/doMap/RandomArray.java
...loud/src/main/java/top/ninwoo/test/doMap/RandomArray.java
+33
-0
apps/cnf-path-computing/businessInCloud/src/main/java/top/ninwoo/test/doMap/path.java
...nessInCloud/src/main/java/top/ninwoo/test/doMap/path.java
+27
-0
apps/cnf-path-computing/businessInCloud/src/main/resources/application.properties
...businessInCloud/src/main/resources/application.properties
+8
-0
apps/cnf-path-computing/businessInDocker/pom.xml
apps/cnf-path-computing/businessInDocker/pom.xml
+54
-0
apps/cnf-path-computing/businessInDocker/src/main/java/com/pitong/business/Application.java
...Docker/src/main/java/com/pitong/business/Application.java
+83
-0
apps/cnf-path-computing/businessInDocker/src/main/java/com/pitong/business/service/IPService.java
.../src/main/java/com/pitong/business/service/IPService.java
+25
-0
apps/cnf-path-computing/businessInDocker/src/main/java/com/pitong/business/service/ServerService.java
.../main/java/com/pitong/business/service/ServerService.java
+573
-0
apps/cnf-path-computing/businessInDocker/src/main/java/com/pitong/business/service/parameters.java
...src/main/java/com/pitong/business/service/parameters.java
+19
-0
apps/cnf-path-computing/businessInDocker/src/main/resources/application.yaml
...ting/businessInDocker/src/main/resources/application.yaml
+11
-0
apps/cnf-path-computing/sateDeploy/pom.xml
apps/cnf-path-computing/sateDeploy/pom.xml
+49
-0
apps/cnf-path-computing/sateDeploy/src/main/java/top/ninwoo/test/BisheTestMain.java
...teDeploy/src/main/java/top/ninwoo/test/BisheTestMain.java
+11
-0
apps/cnf-path-computing/sateDeploy/src/main/resources/application.properties
...ting/sateDeploy/src/main/resources/application.properties
+2
-0
apps/cnf-path-computing/sateDeploy/src/test/java/top/ninwoo/BisheMultiNodeTests.java
...eDeploy/src/test/java/top/ninwoo/BisheMultiNodeTests.java
+161
-0
apps/cnf-path-computing/sateDeploy/src/test/java/top/ninwoo/BisheTests.java
...uting/sateDeploy/src/test/java/top/ninwoo/BisheTests.java
+516
-0
cnf-cloud-center/src/main/java/top/ninwoo/cloudcenter/register/CloudRegisterCenter.java
.../top/ninwoo/cloudcenter/register/CloudRegisterCenter.java
+1
-0
cnf-edge-center/src/main/resources/application.yaml
cnf-edge-center/src/main/resources/application.yaml
+1
-1
pom.xml
pom.xml
+4
-0
No files found.
apps/cnf-path-computing/business-api/pom.xml
0 → 100644
View file @
ce5d2893
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
cnf
</artifactId>
<groupId>
top.ninwoo
</groupId>
<version>
1.0-SNAPSHOT
</version>
<relativePath>
../../../pom.xml
</relativePath>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
business-api
</artifactId>
</project>
\ No newline at end of file
apps/cnf-path-computing/business-api/src/main/java/com/pitong/business/item/DataPackage.java
0 → 100644
View file @
ce5d2893
package
com.pitong.business.item
;
import
java.io.Serializable
;
import
java.util.List
;
public
class
DataPackage
implements
Serializable
{
private
int
number
;
private
List
<
Integer
>
sequence
;
private
Picture
picture
;
private
String
loc
;
private
double
eta
;
private
Long
currentime
;
private
Long
fun1time
;
private
List
<
Double
>
compCapacity
;
public
List
<
Double
>
getCompCapacity
()
{
return
compCapacity
;
}
public
void
setCompCapacity
(
List
<
Double
>
compCapacity
)
{
this
.
compCapacity
=
compCapacity
;
}
public
void
setFun1time
(
Long
fun1time
)
{
this
.
fun1time
=
fun1time
;
}
public
Long
getFun1time
()
{
return
fun1time
;
}
public
void
setCurrentime
(
Long
currentime
)
{
this
.
currentime
=
currentime
;
}
public
Long
getCurrentime
()
{
return
currentime
;
}
public
int
getNumber
()
{
return
number
;
}
public
void
setNumber
(
int
number
)
{
this
.
number
=
number
;
}
public
List
<
Integer
>
getSequence
()
{
return
sequence
;
}
public
void
setSequence
(
List
<
Integer
>
sequence
)
{
this
.
sequence
=
sequence
;
}
public
Picture
getPicture
()
{
return
picture
;
}
public
void
setPicture
(
Picture
picture
)
{
this
.
picture
=
picture
;
}
public
String
getLoc
()
{
return
loc
;
}
public
void
setLoc
(
String
loc
)
{
this
.
loc
=
loc
;
}
public
double
getEta
()
{
return
eta
;
}
public
void
setEta
(
double
eta
)
{
this
.
eta
=
eta
;
}
}
apps/cnf-path-computing/business-api/src/main/java/com/pitong/business/item/Picture.java
0 → 100644
View file @
ce5d2893
package
com.pitong.business.item
;
import
java.io.Serializable
;
public
class
Picture
implements
Serializable
{
private
byte
[]
data
;
public
byte
[]
getData
()
{
return
data
;
}
public
void
setData
(
byte
[]
data
)
{
int
length
=
data
.
length
;
this
.
data
=
new
byte
[
length
];
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
this
.
data
[
i
]
=
data
[
i
];
}
}
}
apps/cnf-path-computing/businessInCloud/pom.xml
0 → 100644
View file @
ce5d2893
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
cnf
</artifactId>
<groupId>
top.ninwoo
</groupId>
<version>
1.0-SNAPSHOT
</version>
<relativePath>
../../../pom.xml
</relativePath>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
businessInCloud
</artifactId>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
top.ninwoo
</groupId>
<artifactId>
cnf-client-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
top.ninwoo
</groupId>
<artifactId>
business-api
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<version>
${springboot.version}
</version>
<executions>
<execution>
<goals>
<goal>
repackage
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
apps/cnf-path-computing/businessInCloud/src/main/java/top/ninwoo/test/BisheTestMain.java
0 → 100644
View file @
ce5d2893
package
top.ninwoo.test
;
import
com.pitong.business.item.DataPackage
;
import
com.pitong.business.item.Picture
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.ApplicationArguments
;
import
org.springframework.boot.ApplicationRunner
;
import
org.springframework.boot.Banner
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
top.ninwoo.test.doMap.DoMap
;
import
top.ninwoo.test.doMap.path
;
import
java.io.*
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Random
;
@SpringBootApplication
@path
public
class
BisheTestMain
implements
ApplicationRunner
{
@Value
(
"${eta}"
)
private
double
ETA
;
@Value
(
"${targetIp}"
)
private
String
targetIp
;
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
BisheTestMain
.
class
)
.
web
(
WebApplicationType
.
NONE
)
// .REACTIVE, .SERVLET
.
bannerMode
(
Banner
.
Mode
.
OFF
)
.
run
(
args
);
}
@Override
public
void
run
(
ApplicationArguments
args
)
throws
Exception
{
//解析注解
Class
<
BisheTestMain
>
bisheTestMainClass
=
BisheTestMain
.
class
;
path
annotation
=
bisheTestMainClass
.
getAnnotation
(
path
.
class
);
String
rmCmd
=
annotation
.
rmCmd
();
String
saveCmd1
=
annotation
.
saveCmd1
();
String
saveCmd2
=
annotation
.
saveCmd2
();
String
saveCmd3
=
annotation
.
saveCmd3
();
String
saveCmd4
=
annotation
.
saveCmd4
();
String
saveCmd5
=
annotation
.
saveCmd5
();
String
savePath
=
annotation
.
savePath
();
System
.
out
.
println
(
"========================================"
);
System
.
out
.
println
(
"exec start timestamp: "
+
System
.
currentTimeMillis
());
System
.
out
.
println
();
// DoMap doMap = new DoMap();
List
<
Integer
>
sequence
=
Arrays
.
asList
(
1
,
3
,
7
,
8
,
12
,
17
,
20
);
System
.
out
.
println
(
"optimal mapping scheme"
+
sequence
);
String
loc
=
null
;
String
file_path
=
"passport.jpg"
;
int
number
=
1
;
double
eta
=
ETA
;
Long
currentime
=
System
.
currentTimeMillis
();
Long
fun1time
=
Long
.
valueOf
(
0
);
List
<
Double
>
compCapacity
=
Arrays
.
asList
(
1.112341341313
,
0.5196272109574349
,
0.675827555541419
,
0.7637869915859579
,
0.7998320296858645
,
0.638652700648973
,
0.6396760676518485
,
0.5615337810185533
,
0.6356797503522186
,
0.8266103444996542
,
0.6924037701405794
,
0.9371892689614395
,
0.6949256728585527
,
0.6212614126622614
,
0.6318393608430264
,
0.7494680794385384
,
0.9983949989039682
,
0.5610722256465777
,
0.6415780028672076
,
0.9371892689
);
//取值范围0.2到1,首尾固定为1M/s
DataPackage
dataPackage
=
combine
(
number
,
sequence
,
loc
,
file_path
,
eta
,
currentime
,
fun1time
,
compCapacity
);
send
(
dataPackage
,
targetIp
,
2020
);
for
(
int
i
=
0
;
i
<
sequence
.
size
();
i
++){
ServerSocket
serverSocket
=
new
ServerSocket
(
8900
);
//获取数据流
Socket
accept
=
serverSocket
.
accept
();
InputStream
inputStream
=
accept
.
getInputStream
();
//读取数据流
ObjectInputStream
objectInputStream
=
new
ObjectInputStream
(
new
BufferedInputStream
(
inputStream
));
Object
object
=
null
;
try
{
object
=
objectInputStream
.
readObject
();
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
List
<
String
>
strings
=
(
List
)
object
;
//输出数据流
for
(
String
s:
strings
)
{
System
.
out
.
println
(
s
);
}
serverSocket
.
close
();
accept
.
close
();
System
.
out
.
println
();
}
//生成保存目录
File
dirpath
=
new
File
(
savePath
);
if
(!
dirpath
.
exists
()){
creatParent
(
dirpath
);
dirpath
.
mkdir
();
}
try
{
// 起作用的代码其实就下面这一行, 参数是linux中要执行的代码
Runtime
.
getRuntime
().
exec
(
rmCmd
).
waitFor
();
Runtime
.
getRuntime
().
exec
(
saveCmd1
).
waitFor
();
//jthudocker
Runtime
.
getRuntime
().
exec
(
saveCmd2
).
waitFor
();
//jthudocker
Runtime
.
getRuntime
().
exec
(
saveCmd3
).
waitFor
();
//jthudocker
for
(
int
i
=
1
;
i
<
sequence
.
size
();
i
++){
Runtime
.
getRuntime
().
exec
(
"docker cp sate"
+
sequence
.
get
(
i
)+
saveCmd4
+
sequence
.
get
(
i
)+
".jpg"
).
waitFor
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
saveCmd5
);
System
.
out
.
println
(
"========================================"
);
// System.out.print("File size :");
// System.out.println(dataPackage.getPicture().getData().length / 1000+"k");
}
private
void
creatParent
(
File
dirpath
)
{
File
file
=
new
File
(
dirpath
.
getParent
());
if
(!
file
.
exists
())
{
creatParent
(
file
);
file
.
mkdir
();
}
}
private
static
DataPackage
combine
(
int
number
,
List
<
Integer
>
sequence
,
String
loc
,
String
file_path
,
double
eta
,
Long
Currentime
,
Long
fun1time
,
List
<
Double
>
compCapacity
)
{
DataPackage
dataPackage
=
new
DataPackage
();
dataPackage
.
setNumber
(
number
);
dataPackage
.
setPicture
(
loadPicture
(
file_path
));
dataPackage
.
setSequence
(
sequence
);
dataPackage
.
setEta
(
eta
);
dataPackage
.
setCurrentime
(
Currentime
);
dataPackage
.
setFun1time
(
fun1time
);
dataPackage
.
setCompCapacity
(
compCapacity
);
return
dataPackage
;
}
private
static
Picture
loadPicture
(
String
pic_url
)
{
try
{
File
f
=
new
File
(
pic_url
);
InputStream
is
=
new
FileInputStream
(
f
);
byte
[]
b
=
new
byte
[(
int
)
f
.
length
()];
is
.
read
(
b
);
is
.
close
();
Picture
picture
=
new
Picture
();
picture
.
setData
(
b
);
return
picture
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
private
static
void
send
(
DataPackage
dataPackage
,
String
ip
,
int
port
)
{
Socket
socket
=
null
;
try
{
socket
=
new
Socket
(
ip
,
port
);
ObjectOutputStream
objectOutputStream
=
new
ObjectOutputStream
(
socket
.
getOutputStream
());
objectOutputStream
.
writeObject
(
dataPackage
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
if
(
socket
!=
null
)
{
socket
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
/**
* 得到0.5到1的随机数
* @return
*/
public
static
Double
getRangeDate
(){
Double
max
=
1.0
;
Double
min
=
0.5
;
Random
random
=
new
Random
();
return
random
.
nextDouble
()%(
max
-
min
)
+
min
;
}
}
apps/cnf-path-computing/businessInCloud/src/main/java/top/ninwoo/test/doMap/DoMap.java
0 → 100644
View file @
ce5d2893
This diff is collapsed.
Click to expand it.
apps/cnf-path-computing/businessInCloud/src/main/java/top/ninwoo/test/doMap/InterSlotDijstraV2.java
0 → 100644
View file @
ce5d2893
package
top.ninwoo.test.doMap
;
import
java.util.Arrays
;
public
class
InterSlotDijstraV2
{
public
static
void
main
(
String
[]
args
)
{
double
[][]
edgeWeight
=
new
double
[][]
{
{
0
,
96
,
157
,
100
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
},
{
371
,
0
,
163
,
MAXWEIGHT
,
100
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
},
{
84
,
395
,
0
,
MAXWEIGHT
,
MAXWEIGHT
,
100
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
0
,
8
,
1
,
100
,
MAXWEIGHT
,
MAXWEIGHT
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
5
,
0
,
1
,
MAXWEIGHT
,
100
,
MAXWEIGHT
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
5
,
5
,
0
,
MAXWEIGHT
,
MAXWEIGHT
,
100
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
0
,
46
,
83
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
25
,
0
,
55
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
35
,
18
,
0
}};
int
num
=
3
;
double
slot
=
100
;
double
testLatency
=
0
;
InterSlotDijstraV2
di
=
new
InterSlotDijstraV2
(
num
,
slot
);
di
.
dijstra
(
edgeWeight
,
testLatency
);
}
/* //最短路矩阵
double [][] pathWeight;
//*/
//设备数目
int
num
;
//时隙值
double
slot
;
//最大权值
static
final
int
MAXWEIGHT
=
10000
*
1000
;
public
InterSlotDijstraV2
(
int
num
,
double
slot
)
{
// TODO Auto-generated constructor stub
this
.
num
=
num
;
this
.
slot
=
slot
;
}
//最短路径算法
public
pathRecord
dijstra
(
double
[][]
edgeWeight
,
double
testLatency
)
{
pathRecord
pathRecord
=
new
pathRecord
();
//存放上一条路径
pathRecord
.
lastHop
=
new
int
[
edgeWeight
.
length
][
edgeWeight
.
length
];
//存放最短路径
pathRecord
.
pathWeight
=
new
double
[
edgeWeight
.
length
][
edgeWeight
.
length
];
for
(
int
i
=
0
;
i
<
edgeWeight
.
length
;
i
++)
{
singlePointDijstra
(
edgeWeight
,
i
,
testLatency
,
pathRecord
.
lastHop
[
i
],
pathRecord
.
pathWeight
[
i
]);
/* for(int j = 0; j < edgeWeight.length; j++) {
pathWeight[i][j] = singleRowWeight[j];
// System.out.print(pathWeight[i][j]+""+'\t');
}*/
// System.out.println('\n');
}
System
.
out
.
println
(
Arrays
.
deepToString
(
pathRecord
.
pathWeight
));
System
.
out
.
println
(
Arrays
.
deepToString
(
pathRecord
.
lastHop
));
// System.out.println(Arrays.deepToString(pathWeight));
return
pathRecord
;
}
//单点最短路算法
private
double
[]
singlePointDijstra
(
double
[][]
edgeWeight
,
int
point
,
double
testLatency
,
int
[]
lastHopi
,
double
[]
pathWeighti
)
{
/* //存放最短路径
double [] singleRowWeight = new double [edgeWeight.length];*/
//存放已求得最短路径节点
boolean
[]
isVisited
=
new
boolean
[
edgeWeight
.
length
];
//初始化
for
(
int
j
=
0
;
j
<
edgeWeight
.
length
;
j
++)
{
if
(
edgeWeight
[
point
][
j
]!=
MAXWEIGHT
&&
edgeWeight
[
point
][
j
]!=
slot
)
{
if
((
edgeWeight
[
point
][
j
]+
testLatency
)
<=
slot
)
{
pathWeighti
[
j
]
=
edgeWeight
[
point
][
j
]
+
testLatency
;
}
else
{
pathWeighti
[
j
]
=
MAXWEIGHT
;
}
}
else
{
pathWeighti
[
j
]
=
edgeWeight
[
point
][
j
];
}
}
isVisited
[
point
]
=
true
;
//遍历所有节点
for
(
int
j
=
0
;
j
<
edgeWeight
[
point
].
length
;
j
++)
{
//遍历下一节点
int
index
=
MAXWEIGHT
;
index
=
nextPoint
(
pathWeighti
,
index
,
isVisited
,
edgeWeight
);
if
(
index
==
MAXWEIGHT
)
{
break
;}
isVisited
[
index
]
=
true
;
//更新以下一节点中转的全局最短路
pathWeighti
=
updateSRW
(
edgeWeight
,
pathWeighti
,
point
,
index
,
isVisited
,
lastHopi
);
}
return
pathWeighti
;
}
//遍历下一节点
private
int
nextPoint
(
double
[]
singleRowWeight
,
int
index
,
boolean
[]
isVisited
,
double
[][]
edgeWeight
)
{
double
min
=
0
;
for
(
int
j
=
0
;
j
<
edgeWeight
.
length
;
j
++)
{
if
(
isVisited
[
j
]
==
false
)
{
if
(
singleRowWeight
[
j
]
!=
0
&&
min
==
0
&&
singleRowWeight
[
j
]
!=
MAXWEIGHT
)
{
min
=
singleRowWeight
[
j
];
index
=
j
;
}
if
(
singleRowWeight
[
j
]
<
min
)
{
min
=
singleRowWeight
[
j
];
index
=
j
;
}
}
}
return
index
;
}
//更新以下一节点中转的全局最短路
private
double
[]
updateSRW
(
double
[][]
edgeWeight
,
double
[]
singleRowWeight
,
int
point
,
int
index
,
boolean
[]
isVisited
,
int
[]
lastHopi
)
{
double
temp
=
singleRowWeight
[
index
];
for
(
int
k
=
0
;
k
<
edgeWeight
.
length
;
k
++)
{
if
(
isVisited
[
k
]
==
false
)
{
if
((
index
+
num
)
==
k
)
{
if
(
(
k
/
num
-
point
/
num
)*
slot
<
singleRowWeight
[
k
])
{
singleRowWeight
[
k
]
=
(
k
/
num
-
point
/
num
)*
slot
;
lastHopi
[
k
]
=
index
;
}
}
else
{
if
((
temp
+
edgeWeight
[
index
][
k
])<=
(
k
/
num
-
point
/
num
+
1
)*
slot
&&
(
temp
+
edgeWeight
[
index
][
k
])
<
singleRowWeight
[
k
])
{
singleRowWeight
[
k
]
=
temp
+
edgeWeight
[
index
][
k
];
lastHopi
[
k
]
=
index
;
}
}
}
}
return
singleRowWeight
;
}
class
pathRecord
{
//最短路矩阵
double
[][]
pathWeight
;
//上一跳矩阵
int
[][]
lastHop
;
public
pathRecord
()
{
}
}
}
apps/cnf-path-computing/businessInCloud/src/main/java/top/ninwoo/test/doMap/RandomArray.java
0 → 100644
View file @
ce5d2893
package
top.ninwoo.test.doMap
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
RandomArray
{
public
static
void
main
(
String
[]
args
)
{
int
[]
arr
=
gennerateArray
(
10
,
100
);
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
System
.
out
.
println
(
arr
[
i
]);
}
List
comCapacity
=
gennerateArray
(
20
,
100.0
);
System
.
out
.
println
(
comCapacity
);
}
public
static
int
[]
gennerateArray
(
int
len
,
int
max
){
int
[]
arr
=
new
int
[
len
];
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++){
arr
[
i
]=(
int
)(
Math
.
random
()*
max
);
}
return
arr
;
}
public
static
ArrayList
<
Double
>
gennerateArray
(
int
len
,
double
max
){
ArrayList
<
Double
>
objects
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
len
;
i
++){
objects
.
add
(
Math
.
random
()/
2.0
+
0.5
);
}
return
objects
;
}
}
apps/cnf-path-computing/businessInCloud/src/main/java/top/ninwoo/test/doMap/path.java
0 → 100644
View file @
ce5d2893
package
top.ninwoo.test.doMap
;
import
java.io.File
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
path
{
String
savePath
()
default
"/home/ninwoo/dynamic_sate/picResult"
;
String
rmCmd
()
default
"rm /home/ninwoo/dynamic_sate/picResult/*.jpg"
;
String
saveCmd1
()
default
"docker cp sate1_0:/pic/in.jpg /home/ninwoo/dynamic_sate/picResult/source.jpg"
;
String
saveCmd2
()
default
"docker cp sate1_0:/pic/out1.jpg /home/ninwoo/dynamic_sate/picResult/task_1.1.jpg"
;
String
saveCmd3
()
default
"docker cp sate1_0:/pic/out2.jpg /home/ninwoo/dynamic_sate/picResult/task_1.2.jpg"
;
String
saveCmd4
()
default
"_0:/pic/out.jpg /home/ninwoo/dynamic_sate/picResult/task_"
;
String
saveCmd5
()
default
"save pictrues to dynamic_sate/picResult directory finish"
;
}
apps/cnf-path-computing/businessInCloud/src/main/resources/application.properties
0 → 100644
View file @
ce5d2893
bishe.app.app-name
=
joliu
bishe.app.cloud-url
=
192.168.47.130:9091
# bishe.app.cloud-url=192.168.31.198:9090
eta
=
0.7
targetIp
=
172.17.0.2
#targetIp=192.168.47.1
#eta=${eta}
#
targetIp
=
${targetIp}
\ No newline at end of file
apps/cnf-path-computing/businessInDocker/pom.xml
0 → 100644
View file @
ce5d2893
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
cnf
</artifactId>
<groupId>
top.ninwoo
</groupId>
<version>
1.0-SNAPSHOT
</version>
<relativePath>
../../../pom.xml
</relativePath>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
businessInDocker
</artifactId>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
top.ninwoo
</groupId>
<artifactId>
cnf-client-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
top.ninwoo
</groupId>
<artifactId>
business-api
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<version>
${springboot.version}
</version>
<executions>
<execution>
<goals>
<goal>
repackage
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
apps/cnf-path-computing/businessInDocker/src/main/java/com/pitong/business/Application.java
0 → 100644
View file @
ce5d2893
package
com.pitong.business
;
import
com.pitong.business.item.DataPackage
;
import
com.pitong.business.item.Picture
;
import
com.pitong.business.service.ServerService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.*
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
java.io.BufferedInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.ObjectInputStream
;
import
java.lang.reflect.Method
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.util.List
;
@SpringBootApplication
public
class
Application
implements
ApplicationRunner
{
@Autowired
private
ServerService
serverService
;
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
Application
.
class
)
.
web
(
WebApplicationType
.
NONE
)
// .REACTIVE, .SERVLET
.
bannerMode
(
Banner
.
Mode
.
OFF
)
.
run
(
args
);
}
@Override
public
void
run
(
ApplicationArguments
args
)
throws
Exception
{
ServerSocket
serverSocket
=
null
;
InputStream
inputStream
=
null
;
ObjectInputStream
objectInputStream
=
null
;
Long
startime
=
System
.
currentTimeMillis
();
try
{
serverSocket
=
new
ServerSocket
(
2020
);
while
(
true
)
{
Socket
client
=
serverSocket
.
accept
();
inputStream
=
client
.
getInputStream
();
objectInputStream
=
new
ObjectInputStream
(
new
BufferedInputStream
(
inputStream
));
Object
object
=
objectInputStream
.
readObject
();
DataPackage
dataPackage
=
(
DataPackage
)
object
;
int
number
=
dataPackage
.
getNumber
();
List
<
Integer
>
sequence
=
dataPackage
.
getSequence
();
Picture
picture
=
dataPackage
.
getPicture
();
String
loc
=
dataPackage
.
getLoc
();
double
eta
=
dataPackage
.
getEta
();
Long
Currentime
=
dataPackage
.
getCurrentime
();
Long
fun1time
=
dataPackage
.
getFun1time
();
List
<
Double
>
compCapacity
=
dataPackage
.
getCompCapacity
();
System
.
out
.
println
(
"====================="
);
String
methodName
=
"func"
+
number
;
Method
method
=
serverService
.
getClass
().
getMethod
(
methodName
,
Class
.
forName
(
"java.util.List"
),
Picture
.
class
,
Class
.
forName
(
"java.lang.String"
),
Class
.
forName
(
"java.lang.Double"
),
Class
.
forName
(
"java.lang.Long"
),
Class
.
forName
(
"java.lang.Long"
),
Class
.
forName
(
"java.lang.Long"
),
Class
.
forName
(
"java.util.List"
));
method
.
invoke
(
serverService
,
sequence
,
picture
,
loc
,
eta
,
Currentime
,
startime
,
fun1time
,
compCapacity
);
}
}
catch
(
IOException
|
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
if
(
objectInputStream
!=
null
)
{
objectInputStream
.
close
();
}
if
(
inputStream
!=
null
)
{
inputStream
.
close
();
}
if
(
serverSocket
!=
null
)
{
serverSocket
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
apps/cnf-path-computing/businessInDocker/src/main/java/com/pitong/business/service/IPService.java
0 → 100644
View file @
ce5d2893
package
com.pitong.business.service
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
top.ninwoo.bishe.starter.service.NetworkService
;
import
java.util.List
;
@Service
public
class
IPService
{
@Autowired
private
NetworkService
networkService
;
public
String
getIpByAppName
(
String
appName
)
{
List
<
String
>
ipList
=
networkService
.
getIpListByAppName
(
11111
l
,
appName
);
if
(!
ipList
.
isEmpty
()){
String
ip_tmp
=
ipList
.
get
(
0
);
String
[]
split_list
=
ip_tmp
.
split
(
"/"
);
return
split_list
[
0
];
}
return
null
;
}
}
apps/cnf-path-computing/businessInDocker/src/main/java/com/pitong/business/service/ServerService.java
0 → 100644
View file @
ce5d2893
This diff is collapsed.
Click to expand it.
apps/cnf-path-computing/businessInDocker/src/main/java/com/pitong/business/service/parameters.java
0 → 100644
View file @
ce5d2893
package
com.pitong.business.service
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
parameters
{
double
coe
()
default
0.7
;
long
slot
()
default
1000L
*
20
;
String
cldUrl
()
default
"192.168.47.130"
;
int
cldPort
()
default
8900
;
}
apps/cnf-path-computing/businessInDocker/src/main/resources/application.yaml
0 → 100644
View file @
ce5d2893
bishe
:
app
:
app-name
:
joliu
cloud-url
:
192.168.47.130:9091
# cloud-url: 192.168.31.198:9090
slot
:
20000
# 1000L*20
coe
:
0.7
cldUrl
:
192.168.47.130
cldPort
:
8900
apps/cnf-path-computing/sateDeploy/pom.xml
0 → 100644
View file @
ce5d2893
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
cnf
</artifactId>
<groupId>
top.ninwoo
</groupId>
<version>
1.0-SNAPSHOT
</version>
<relativePath>
../../../pom.xml
</relativePath>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
sateDeploy
</artifactId>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
top.ninwoo
</groupId>
<artifactId>
cnf-client-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<version>
${springboot.version}
</version>
<executions>
<execution>
<goals>
<goal>
repackage
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
apps/cnf-path-computing/sateDeploy/src/main/java/top/ninwoo/test/BisheTestMain.java
0 → 100644
View file @
ce5d2893
package
top.ninwoo.test
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
BisheTestMain
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
BisheTestMain
.
class
,
args
);
}
}
apps/cnf-path-computing/sateDeploy/src/main/resources/application.properties
0 → 100644
View file @
ce5d2893
bishe.app.app-name
=
joliu
bishe.app.cloud-url
=
cloud.cnf.org:9091
\ No newline at end of file
apps/cnf-path-computing/sateDeploy/src/test/java/top/ninwoo/BisheMultiNodeTests.java
0 → 100644
View file @
ce5d2893
package
top.ninwoo
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
top.ninwoo.bishe.starter.entity.ContainerMonitor
;
import
top.ninwoo.bishe.starter.service.ClusterService
;
import
top.ninwoo.bishe.starter.service.NetworkService
;
import
top.ninwoo.common.entity.*
;
import
top.ninwoo.test.BisheTestMain
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
BisheTestMain
.
class
)
public
class
BisheMultiNodeTests
{
@Autowired
private
ClusterService
clusterService
;
@Resource
private
NetworkService
networkService
;
@Test
public
void
testSendSeparateConfig
()
{
ArrayList
<
SeparatedClusterConfig
>
clusterConfigs
=
new
ArrayList
<>();
SeparatedClusterConfig
separatedClusterConfig
=
new
SeparatedClusterConfig
();
// TODO: 这个ID应该是从借口获取的
separatedClusterConfig
.
setEdgeNodeId
(
"192.168.31.154:8081"
);
ClusterConfig
clusterConfig
=
new
ClusterConfig
();
clusterConfig
.
setId
(
11111
l
);
clusterConfig
.
setOwner
(
"joliu"
);
ContainerDescription
containerDescription
=
new
ContainerDescription
();
containerDescription
.
setMode
(
"normal"
);
containerDescription
.
setReplicas
(
1
);
DockerContainer
container
=
new
DockerContainer
();
container
.
setName
(
"APP1"
);
container
.
setCommand
(
"sh"
);
container
.
setImage
(
"joliu/networktest"
);
containerDescription
.
setDockerContainer
(
container
);
List
<
ContainerDescription
>
cds
=
new
ArrayList
<>();
cds
.
add
(
containerDescription
);
ContainerDescription
containerDescription1
=
new
ContainerDescription
();
containerDescription1
.
setMode
(
"normal"
);
containerDescription1
.
setReplicas
(
1
);
DockerContainer
container1
=
new
DockerContainer
();
container1
.
setName
(
"APP2"
);
container1
.
setCommand
(
"sh"
);
container1
.
setImage
(
"joliu/networktest"
);
containerDescription1
.
setDockerContainer
(
container1
);
cds
.
add
(
containerDescription1
);
clusterConfig
.
setDockers
(
cds
);
NetworkTopology
topo
=
new
NetworkTopology
();
topo
.
setAppNames
(
new
String
[]{
"APP1"
,
"APP2"
,
"br:ovs1"
,
"br:remote:ovs2:192.168.31.16"
});
// 这个参数好像没啥用
topo
.
setTopologyId
(
11
);
topo
.
setTopology
(
new
int
[][]{{
0
,
0
,
0
,
0
},{
0
,
0
,
0
,
0
},{
1
,
1
,
0
,
0
},{
0
,
0
,
1
,
0
}});
clusterConfig
.
setTopology
(
topo
);
separatedClusterConfig
.
setClusterConfig
(
clusterConfig
);
clusterConfigs
.
add
(
separatedClusterConfig
);
// 构建第二个节点
SeparatedClusterConfig
separatedClusterConfig1
=
new
SeparatedClusterConfig
();
// TODO: 这个ID应该是从借口获取的
separatedClusterConfig1
.
setEdgeNodeId
(
"192.168.31.16:8081"
);
ClusterConfig
clusterConfig1
=
new
ClusterConfig
();
clusterConfig1
.
setId
(
11111
l
);
clusterConfig1
.
setOwner
(
"joliu"
);
ContainerDescription
containerDescription11
=
new
ContainerDescription
();
containerDescription11
.
setMode
(
"normal"
);
containerDescription11
.
setReplicas
(
1
);
DockerContainer
container11
=
new
DockerContainer
();
container11
.
setName
(
"APP3"
);
container11
.
setCommand
(
"sh"
);
container11
.
setImage
(
"joliu/networktest"
);
containerDescription11
.
setDockerContainer
(
container11
);
List
<
ContainerDescription
>
cds1
=
new
ArrayList
<>();
cds1
.
add
(
containerDescription11
);
ContainerDescription
containerDescription12
=
new
ContainerDescription
();
containerDescription12
.
setMode
(
"normal"
);
containerDescription12
.
setReplicas
(
1
);
DockerContainer
container12
=
new
DockerContainer
();
container12
.
setName
(
"APP4"
);
container12
.
setCommand
(
"sh"
);
container12
.
setImage
(
"joliu/networktest"
);
containerDescription12
.
setDockerContainer
(
container12
);
cds1
.
add
(
containerDescription12
);
clusterConfig1
.
setDockers
(
cds1
);
NetworkTopology
topo1
=
new
NetworkTopology
();
topo1
.
setAppNames
(
new
String
[]{
"APP3"
,
"APP4"
,
"br:ovs2"
,
"br:remote:ovs1:192.168.31.154"
});
// 这个参数好像没啥用
topo1
.
setTopologyId
(
11
);
topo1
.
setTopology
(
new
int
[][]{{
0
,
0
,
0
,
0
},{
0
,
0
,
0
,
0
},{
1
,
1
,
0
,
0
},{
0
,
0
,
1
,
0
}});
clusterConfig1
.
setTopology
(
topo1
);
separatedClusterConfig1
.
setClusterConfig
(
clusterConfig1
);
clusterConfigs
.
add
(
separatedClusterConfig1
);
clusterService
.
sendClusterConfigToEdgeNode
(
clusterConfigs
);
}
@Test
public
void
removeClusterFromEdgeNodeTest
()
{
clusterService
.
removeClusterFromEdgeNode
(
11111L
);
}
@Test
public
void
getLogicalNetworkTopologyTest
()
{
NetworkTopology
logicalNetworkTopology
=
networkService
.
getLogicalNetworkTopology
(
11111L
);
System
.
out
.
println
(
logicalNetworkTopology
);
}
@Test
public
void
getIpListByAppNameTest
()
{
List
<
String
>
ipList
=
networkService
.
getIpListByAppName
(
11111L
,
"APP3"
);
System
.
out
.
println
(
ipList
);
}
@Test
public
void
enableNetworkMonitorTest
()
throws
InterruptedException
{
String
res
=
networkService
.
enableNetworkMonitor
(
11111L
,
"Run"
);
System
.
out
.
println
(
res
);
}
@Test
public
void
cancelNetworkMonitorTest
()
{
String
run
=
networkService
.
cancelNetworkMonitor
(
11111L
,
"Run"
);
System
.
out
.
println
(
run
);
}
@Test
public
void
getNetworkMonitorTest
()
throws
InterruptedException
{
List
<
ContainerMonitor
>
run
=
networkService
.
getContainerMonitors
(
11111L
,
"Run"
);
int
i
=
0
;
while
(
i
<
10
)
{
run
.
forEach
(
c
->
{
System
.
out
.
println
(
c
.
getContainerInfo
());
});
Thread
.
sleep
(
500
);
i
++;
}
}
@Test
public
void
getAllEdgeNodeIdsTest
()
{
List
<
String
>
allEdgeNodeIds
=
clusterService
.
getAllEdgeNodeIds
();
System
.
out
.
println
(
allEdgeNodeIds
);
}
}
apps/cnf-path-computing/sateDeploy/src/test/java/top/ninwoo/BisheTests.java
0 → 100644
View file @
ce5d2893
This diff is collapsed.
Click to expand it.
cnf-cloud-center/src/main/java/top/ninwoo/cloudcenter/register/CloudRegisterCenter.java
View file @
ce5d2893
...
...
@@ -102,6 +102,7 @@ public class CloudRegisterCenter implements Register {
LOG
.
info
(
"新的节点{}已接入"
,
event
.
getData
().
getPath
());
String
newNode
=
event
.
getData
().
getPath
();
String
newNodeIp
=
new
String
(
event
.
getData
().
getData
());
LOG
.
info
(
"新的节点信息{}"
,
newNodeIp
);
// 通过newNodeIp获取边缘服务器的信息
// 注册信息到中心节点上
// 这里通过网络进行请求,其实也是在做一次测试,查看远程服务器是否符合版本要求,网络是否顺畅
...
...
cnf-edge-center/src/main/resources/application.yaml
View file @
ce5d2893
...
...
@@ -24,7 +24,7 @@ bs:
name
:
my-bs-cloud-center
edgenode
:
name
:
random
ip-prefix
:
192.168
.31
ip-prefix
:
192.168
ipservice
:
ip
:
ipservice.cnf.org:23333
sdn-controller
:
...
...
pom.xml
View file @
ce5d2893
...
...
@@ -20,6 +20,10 @@
<module>
apps/cnf-weixingsim
</module>
<module>
apps/cnf-case-dis
</module>
<module>
apps/cnf-app-demo
</module>
<module>
apps/cnf-path-computing/businessInDocker
</module>
<module>
apps/cnf-path-computing/businessInCloud
</module>
<module>
apps/cnf-path-computing/sateDeploy
</module>
<module>
apps/cnf-path-computing/business-api
</module>
</modules>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment