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
83eeee8f
Commit
83eeee8f
authored
Jun 14, 2020
by
Elf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加获取卫星topo和卫星IPlist的接口
parent
a5debe6d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
260 additions
and
6 deletions
+260
-6
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/controller/DockerController.java
...va/top/ninwoo/edgecenter/controller/DockerController.java
+57
-0
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/controller/IndexController.java
...ava/top/ninwoo/edgecenter/controller/IndexController.java
+1
-0
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/LogicTopoService.java
.../java/top/ninwoo/edgecenter/service/LogicTopoService.java
+7
-0
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/impl/LogicTopoServiceImpl.java
.../ninwoo/edgecenter/service/impl/LogicTopoServiceImpl.java
+38
-0
bishe-test/src/test/java/top/ninwoo/BisheTests.java
bishe-test/src/test/java/top/ninwoo/BisheTests.java
+156
-5
bishe-weixingsim/src/main/java/top/ninwoo/weixingsim/service/impl/ToponetImpl.java
.../java/top/ninwoo/weixingsim/service/impl/ToponetImpl.java
+1
-1
No files found.
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/controller/DockerController.java
0 → 100644
View file @
83eeee8f
package
top.ninwoo.edgecenter.controller
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
top.ninwoo.edgecenter.service.ClusterService
;
import
top.ninwoo.edgecenter.service.IpService
;
import
top.ninwoo.edgecenter.service.LogicTopoService
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
@RestController
@RequestMapping
(
"/dockerData"
)
public
class
DockerController
{
@Autowired
private
IpService
ipService
;
@Autowired
ClusterService
clusterService
;
@Autowired
private
LogicTopoService
logicTopoService
;
//要将过去的删除掉
@GetMapping
(
"/getIPlist"
)
public
List
<
String
>
getIPlist
()
{
System
.
out
.
println
(
"已返回IPlist"
);
return
logicTopoService
.
getIPlist
();
}
//需下发逻辑拓扑后才能获得,todo
@GetMapping
(
"/getTopo"
)
public
int
[][]
getTopo
()
{
System
.
out
.
println
(
"已返回topo"
);
return
logicTopoService
.
getTopo
(
11111
l
);
}
@GetMapping
(
"/getIPbyName"
)
public
String
getIPbyname
(
@RequestParam
(
name
=
"appname"
)
String
appname
)
{
//System.out.println("接受到消息了");
//System.out.println(appname);
//这里可能以后要加个传入的集群ID
Set
<
String
>
cid1
=
clusterService
.
getContainerIdsByClusterId
(
11111
l
,
appname
);
//System.out.println(cid1);
String
appID1
=
((
String
)
cid1
.
toArray
()[
0
]);
//System.out.println(appID1);
String
appIP1
=
ipService
.
getContainerIp
(
appID1
).
split
(
"/"
)[
0
];
System
.
out
.
println
(
appIP1
);
return
appIP1
;
}
}
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/controller/IndexController.java
View file @
83eeee8f
...
...
@@ -152,6 +152,7 @@ public class IndexController {
// 创建网络
// 使用topo创建工具
topologyService
.
createTopo
(
clusterConfig
.
getId
(),
clusterConfig
.
getTopology
());
logicTopoService
.
saveIPlist
(
clusterConfig
.
getId
(),
clusterConfig
.
getTopology
().
getAppNames
());
return
resMap
;
}
...
...
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/LogicTopoService.java
View file @
83eeee8f
...
...
@@ -13,4 +13,11 @@ public interface LogicTopoService {
String
modifyLogicTopology
(
long
clusterId
,
NetworkTopology
logictopo
);
//得到逻辑拓扑
NetworkTopology
getLogictopo
(
NetworkTopology
oritopo
);
//储存IPlist
void
saveIPlist
(
long
clusterId
,
String
[]
appnames
);
//返回topo到docker容器端
int
[][]
getTopo
(
long
clusterId
);
//返回IPlist到docker容器端
List
<
String
>
getIPlist
();
}
bishe-edge-center/src/main/java/top/ninwoo/edgecenter/service/impl/LogicTopoServiceImpl.java
View file @
83eeee8f
...
...
@@ -11,6 +11,8 @@ import top.ninwoo.edgecenter.service.IpService;
import
top.ninwoo.edgecenter.service.LogicTopoService
;
import
top.ninwoo.utils.service.IptablesService
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
@@ -19,6 +21,8 @@ public class LogicTopoServiceImpl implements LogicTopoService {
private
final
static
Logger
LOG
=
LoggerFactory
.
getLogger
(
TopologyServiceImpl
.
class
);
// 用于存储集群的拓扑
private
ConcurrentHashMap
<
Long
,
NetworkTopology
>
clustersTopo
=
new
ConcurrentHashMap
<>();
//根据appnames来存储IP
private
List
<
String
>
IPlist
=
new
ArrayList
<
String
>();
@Value
(
"${bs.sdn-controller.host}"
)
private
String
host
;
...
...
@@ -60,6 +64,8 @@ public class LogicTopoServiceImpl implements LogicTopoService {
}
}
}
clustersTopo
.
put
(
clusterId
,
logictopo
);
}
...
...
@@ -182,4 +188,36 @@ public class LogicTopoServiceImpl implements LogicTopoService {
iptablesService
.
dropTraffic
(
appID1
,
appIP2
,
appIP1
);
iptablesService
.
dropTraffic
(
appID2
,
appIP1
,
appIP2
);
}
@Override
public
void
saveIPlist
(
long
clusterId
,
String
[]
appnames
){
//获取appnames
//todo 这里用dowhile似乎更快些
int
flag
=
0
;
for
(
int
i
=
0
;
i
<
appnames
.
length
-
1
;
i
++)
{
if
(
appnames
[
i
].
startsWith
(
"br:"
))
{
break
;
}
flag
++;
}
for
(
int
k
=
0
;
k
<
flag
;
k
++){
Set
<
String
>
cid
=
clusterService
.
getContainerIdsByClusterId
(
clusterId
,
appnames
[
k
]);
String
appID
=
((
String
)
cid
.
toArray
()[
0
]);
String
appIP
=
ipService
.
getContainerIp
(
appID
).
split
(
"/"
)[
0
];
IPlist
.
add
(
appIP
);
}
System
.
out
.
println
(
"已储存IPlist"
);
}
@Override
public
int
[][]
getTopo
(
long
clusterId
)
{
return
clustersTopo
.
get
(
clusterId
).
getTopology
();
}
@Override
public
List
<
String
>
getIPlist
()
{
return
IPlist
;
}
}
bishe-test/src/test/java/top/ninwoo/BisheTests.java
View file @
83eeee8f
...
...
@@ -140,7 +140,7 @@ public class BisheTests {
DockerContainer
container
=
new
DockerContainer
();
container
.
setName
(
"D1"
);
container
.
setCommand
(
"sh"
);
container
.
setImage
(
"
joliu/networktest
"
);
container
.
setImage
(
"
test2
"
);
containerDescription
.
setDockerContainer
(
container
);
List
<
ContainerDescription
>
cds
=
new
ArrayList
<>();
...
...
@@ -152,7 +152,7 @@ public class BisheTests {
DockerContainer
disContainer
=
new
DockerContainer
();
disContainer
.
setName
(
"D2"
);
disContainer
.
setCommand
(
"sh"
);
disContainer
.
setImage
(
"
joliu/networktest
"
);
disContainer
.
setImage
(
"
test2
"
);
dis
.
setDockerContainer
(
disContainer
);
cds
.
add
(
dis
);
...
...
@@ -162,15 +162,15 @@ public class BisheTests {
DockerContainer
disContainer2
=
new
DockerContainer
();
disContainer2
.
setName
(
"D3"
);
disContainer2
.
setCommand
(
"sh"
);
disContainer2
.
setImage
(
"
joliu/networktest
"
);
disContainer2
.
setImage
(
"
test2
"
);
dis2
.
setDockerContainer
(
disContainer2
);
cds
.
add
(
dis2
);
String
[]
appnames
=
new
String
[]{
"D1"
,
"D2"
,
"D3"
,
"br:ovs"
};
int
[][]
topology
=
new
int
[][]{
{
0
,
0
,
0
,
0
},
{
0
,
0
,
0
,
0
},
{
0
,
0
,
0
,
0
},
{
1
,
0
,
0
,
0
},
{
0
,
1
,
0
,
0
},
{
1
,
1
,
1
,
0
}};
clusterConfig
.
setDockers
(
cds
);
...
...
@@ -188,6 +188,7 @@ public class BisheTests {
//下发逻辑拓扑
clusterService
.
sendLogicTopoToEdgeNode
(
clusterConfigs
);
/*
//改变逻辑拓扑
int[][] newtopology = new int[][]{
{0, 0, 0, 0 },
...
...
@@ -199,6 +200,8 @@ public class BisheTests {
//下发修改后的逻辑拓扑
clusterService.adjustLogicTopoToEdgeNode(clusterConfigs);
*/
}
// 测试初始化设置
...
...
@@ -315,6 +318,154 @@ public class BisheTests {
//下发修改后逻辑拓扑
clusterService
.
adjustLogicTopoToEdgeNode
(
clusterConfigs
);
}
}
//测试历史功能,需要提前定义好输出文本地址
@Test
public
void
test4
()
throws
IllegalAccessException
,
InterruptedException
{
ArrayList
<
SeparatedClusterConfig
>
clusterConfigs
=
new
ArrayList
<>();
SeparatedClusterConfig
separatedClusterConfig
=
new
SeparatedClusterConfig
();
List
<
ContainerDescription
>
cds
=
new
ArrayList
<>();
// TODO: 这个ID应该是从借口获取的
separatedClusterConfig
.
setEdgeNodeId
(
"192.168.190.135:8081"
);
ClusterConfig
clusterConfig
=
new
ClusterConfig
();
clusterConfig
.
setId
(
11111
l
);
clusterConfig
.
setOwner
(
"joliu"
);
//从文本中获取卫星的数据
WeixingImpl
wx
=
new
WeixingImpl
();
ToponetImpl
tp
=
new
ToponetImpl
();
SimData
sd
=
new
SimData
();
tp
.
delHistory
();
File
file
=
new
File
(
"C:\\WorkSpace\\test\\topusim_1.txt"
);
List
<
WeiXingData
>
wxData
=
wx
.
iniTopo
(
file
);
int
[][]
toponet
=
tp
.
getTopology
(
wxData
,
sd
);
//创建容器
for
(
int
k
=
0
;
k
<
wxData
.
size
();
k
++)
{
ContainerDescription
containerDescription
=
new
ContainerDescription
();
containerDescription
.
setMode
(
"normal"
);
containerDescription
.
setReplicas
(
1
);
DockerContainer
container
=
new
DockerContainer
();
container
.
setName
(
wxData
.
get
(
k
).
getName
());
container
.
setCommand
(
"sh"
);
container
.
setImage
(
"joliu/networktest"
);
containerDescription
.
setDockerContainer
(
container
);
cds
.
add
(
containerDescription
);
}
clusterConfig
.
setDockers
(
cds
);
NetworkTopology
topo
=
new
NetworkTopology
();
topo
.
setAppNames
(
tp
.
getAppNames
(
wxData
));
// 这个参数好像没啥用
topo
.
setTopologyId
(
11
);
topo
.
setTopology
(
toponet
);
clusterConfig
.
setTopology
(
topo
);
separatedClusterConfig
.
setClusterConfig
(
clusterConfig
);
clusterConfigs
.
add
(
separatedClusterConfig
);
clusterService
.
sendClusterConfigToEdgeNode
(
clusterConfigs
);
//下发逻辑拓扑
clusterService
.
sendLogicTopoToEdgeNode
(
clusterConfigs
);
for
(
int
i
=
1
;
;
i
++)
{
Thread
.
sleep
(
2000
);
int
time
=
i
*
sd
.
getJiange
();
List
<
WeiXingData
>
changetp
=
wx
.
changeTopo
(
wxData
,
time
);
topo
.
setTopology
(
tp
.
getTopology
(
changetp
,
sd
));
tp
.
history
(
topo
.
getAppNames
(),
topo
.
getTopology
());
//下发修改后逻辑拓扑
clusterService
.
adjustLogicTopoToEdgeNode
(
clusterConfigs
);
}
}
//测试容器运行程序
@Test
public
void
test5
()
{
ArrayList
<
SeparatedClusterConfig
>
clusterConfigs
=
new
ArrayList
<>();
SeparatedClusterConfig
separatedClusterConfig
=
new
SeparatedClusterConfig
();
//需修改为下发的IP地址
separatedClusterConfig
.
setEdgeNodeId
(
"192.168.190.135: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
(
"D1"
);
container
.
setCommand
(
"-e PARAMS=\"--name="
+
container
.
getName
()+
"\""
);
container
.
setImage
(
"joliu/networktest"
);
containerDescription
.
setDockerContainer
(
container
);
List
<
ContainerDescription
>
cds
=
new
ArrayList
<>();
cds
.
add
(
containerDescription
);
ContainerDescription
dis
=
new
ContainerDescription
();
dis
.
setMode
(
"normal"
);
dis
.
setReplicas
(
1
);
DockerContainer
disContainer
=
new
DockerContainer
();
disContainer
.
setName
(
"D2"
);
disContainer
.
setCommand
(
"-e PARAMS=\"--name="
+
disContainer
.
getName
()+
"\""
);
disContainer
.
setImage
(
"joliu/networktest"
);
dis
.
setDockerContainer
(
disContainer
);
cds
.
add
(
dis
);
ContainerDescription
dis2
=
new
ContainerDescription
();
dis2
.
setMode
(
"normal"
);
dis2
.
setReplicas
(
1
);
DockerContainer
disContainer2
=
new
DockerContainer
();
disContainer2
.
setName
(
"D3"
);
disContainer2
.
setCommand
(
"-e PARAMS=\"--name="
+
disContainer2
.
getName
()+
"\""
);
disContainer2
.
setImage
(
"joliu/networktest"
);
dis2
.
setDockerContainer
(
disContainer2
);
cds
.
add
(
dis2
);
String
[]
appnames
=
new
String
[]{
"D1"
,
"D2"
,
"D3"
,
"br:ovs"
};
int
[][]
topology
=
new
int
[][]{
{
0
,
0
,
0
,
0
},
{
1
,
0
,
0
,
0
},
{
0
,
1
,
0
,
0
},
{
1
,
1
,
1
,
0
}};
clusterConfig
.
setDockers
(
cds
);
NetworkTopology
topo
=
new
NetworkTopology
();
topo
.
setAppNames
(
appnames
);
// 这个参数好像没啥用
topo
.
setTopologyId
(
11
);
topo
.
setTopology
(
topology
);
clusterConfig
.
setTopology
(
topo
);
separatedClusterConfig
.
setClusterConfig
(
clusterConfig
);
clusterConfigs
.
add
(
separatedClusterConfig
);
clusterService
.
sendClusterConfigToEdgeNode
(
clusterConfigs
);
//下发逻辑拓扑
clusterService
.
sendLogicTopoToEdgeNode
(
clusterConfigs
);
/*
//改变逻辑拓扑
int[][] newtopology = new int[][]{
{0, 0, 0, 0 },
{1, 0, 0, 0 },
{1, 1, 0, 0 },
{1, 1, 1, 0 }};
topo.setTopology(newtopology);
//下发修改后的逻辑拓扑
clusterService.adjustLogicTopoToEdgeNode(clusterConfigs);
*/
}
}
bishe-weixingsim/src/main/java/top/ninwoo/weixingsim/service/impl/ToponetImpl.java
View file @
83eeee8f
...
...
@@ -80,7 +80,7 @@ public class ToponetImpl implements Toponet {
bw
.
write
(
str
+
"开始的拓扑结构"
+
"\n"
);
//todo 需要设计排版
int
num
=
appNames
.
length
/
2
;
int
num
=
appNames
.
length
;
int
[][]
logic
=
new
int
[
num
][
num
];
for
(
int
i
=
0
;
i
<
num
;
i
++){
for
(
int
m
=
0
;
m
<
num
;
m
++){
...
...
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