Commit 945046d1 authored by wutu's avatar wutu

fix-bug

parent 7b3043a1
server:
port: 9090
port: 9091
zookeeper:
url: 192.168.1.5:2181
url: 192.168.0.108:2181
bs:
cloudcenter:
name: my-bs-cloud-center
ipservice:
url: 192.168.1.5:23333
\ No newline at end of file
url: 192.168.0.108:23333
\ No newline at end of file
......@@ -3,6 +3,7 @@ package top.ninwoo.edgecenter.service.impl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import top.ninwoo.common.entity.ClusterConfig;
import top.ninwoo.common.entity.NetworkTopology;
......@@ -28,6 +29,11 @@ public class TopologyServiceImpl implements TopologyService {
// 用于存储集群的拓扑
private ConcurrentHashMap<Long, NetworkTopology> clustersTopo = new ConcurrentHashMap<>();
@Value("${bs.sdn-controller.host}")
private String host;
@Value("${bs.sdn-controller.port}")
private int port;
@Autowired
OVSService ovsService;
......@@ -89,6 +95,8 @@ public class TopologyServiceImpl implements TopologyService {
if(!appName1.contains("remote") && !ovsService.isBridge(appName1.substring(3))) {
LOG.info("创建虚拟交换机:{}", appName1.substring(3));
ovsService.addBridge(appName1.substring(3));
// todo 设置controller
ovsService.setController(appName1.substring(3), host, port);
}
//LOG.info("Ovs Bridge[" + appName1 + "] is normal!");
}
......@@ -99,6 +107,7 @@ public class TopologyServiceImpl implements TopologyService {
if(!appName2.contains("remote") && !ovsService.isBridge(appName2.substring(3))) {
LOG.info("创建虚拟交换机:{}", appName2.substring(3));
ovsService.addBridge(appName2.substring(3));
ovsService.setController(appName2.substring(3), host, port);
}
}
......
......@@ -21,6 +21,9 @@ bs:
name: random
ip-prefix: 192
ipservice:
ip: 192.168.1.5:23333
ip: 192.168.0.108:23333
sdn-controller:
host: 192.168.61.131
port: 6653
zookeeper:
url: 192.168.1.5:2181
\ No newline at end of file
url: 192.168.0.108:2181
bishe.app.app-name=joliu
bishe.app.cloud-url=192.168.31.154:9090
\ No newline at end of file
bishe.app.cloud-url=127.0.0.1:9091
\ No newline at end of file
......@@ -25,12 +25,98 @@ public class BisheMultiNodeTests {
@Resource
private NetworkService networkService;
@Test
public void testNetworkChange() {
ArrayList<SeparatedClusterConfig> clusterConfigs = new ArrayList<>();
SeparatedClusterConfig separatedClusterConfig = new SeparatedClusterConfig();
separatedClusterConfig.setEdgeNodeId("192.168.61.130:8081");
ClusterConfig clusterConfig = new ClusterConfig();
clusterConfig.setId(11111l);
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);
clusterConfig.setDockers(cds);
NetworkTopology topo = new NetworkTopology();
topo.setAppNames(new String[]{"APP1", "br:ovs1", "br:ovs2", "br:remote:ovs3:192.168.61.131"});
// 这个参数好像没啥用
topo.setTopologyId(11);
topo.setTopology(new int[][]{
{0,0,0,0},
{1,0,0,0},
{0,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.61.131:8081");
ClusterConfig clusterConfig1 = new ClusterConfig();
clusterConfig1.setId(11111l);
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[]{"APP2", "br:ovs3", "br:ovs4","br:ovs5","br:ovs6","br:ovs7","br:ovs8","br:remote:ovs2:192.168.61.130"});
// 这个参数好像没啥用
topo1.setTopologyId(11);
topo1.setTopology(new int[][]{{0,0,0,0,0,0,0,0}
,{0,0,0,0,0,0,0,0}
,{0,1,0,0,0,0,0,0}
,{0,0,1,0,0,0,0,0}
,{0,0,1,1,0,0,0,0}
,{0,0,0,0,1,0,0,0}
,{1,0,0,0,0,1,0,0}
,{0,1,0,0,0,0,0,0}});
clusterConfig1.setTopology(topo1);
separatedClusterConfig1.setClusterConfig(clusterConfig1);
clusterConfigs.add(separatedClusterConfig1);
clusterService.sendClusterConfigToEdgeNode(clusterConfigs);
}
@Test
public void testSendSeparateConfig() {
ArrayList<SeparatedClusterConfig> clusterConfigs = new ArrayList<>();
SeparatedClusterConfig separatedClusterConfig = new SeparatedClusterConfig();
// TODO: 这个ID应该是从借口获取的
separatedClusterConfig.setEdgeNodeId("192.168.31.16:8081");
separatedClusterConfig.setEdgeNodeId("192.168.61.130:8081");
ClusterConfig clusterConfig = new ClusterConfig();
clusterConfig.setId(11111l);
clusterConfig.setOwner("joliu");
......@@ -59,7 +145,7 @@ public class BisheMultiNodeTests {
clusterConfig.setDockers(cds);
NetworkTopology topo = new NetworkTopology();
topo.setAppNames(new String[]{"APP1", "APP2", "br:ovs1", "br:remote:ovs2:192.168.31.220"});
topo.setAppNames(new String[]{"APP1", "APP2", "br:ovs1", "br:remote:ovs2:192.168.61.131"});
// 这个参数好像没啥用
topo.setTopologyId(11);
topo.setTopology(new int[][]{{0,0,0,0},{0,0,0,0},{1,1,0,0},{0,0,1,0}});
......@@ -70,7 +156,7 @@ public class BisheMultiNodeTests {
// 构建第二个节点
SeparatedClusterConfig separatedClusterConfig1 = new SeparatedClusterConfig();
// TODO: 这个ID应该是从借口获取的
separatedClusterConfig1.setEdgeNodeId("192.168.31.220:8081");
separatedClusterConfig1.setEdgeNodeId("192.168.61.131:8081");
ClusterConfig clusterConfig1 = new ClusterConfig();
clusterConfig1.setId(11111l);
clusterConfig1.setOwner("joliu");
......@@ -99,7 +185,7 @@ public class BisheMultiNodeTests {
clusterConfig1.setDockers(cds1);
NetworkTopology topo1 = new NetworkTopology();
topo1.setAppNames(new String[]{"APP3", "APP4", "br:ovs2", "br:remote:ovs1:192.168.31.16"});
topo1.setAppNames(new String[]{"APP3", "APP4", "br:ovs2", "br:remote:ovs1:192.168.61.130"});
// 这个参数好像没啥用
topo1.setTopologyId(11);
topo1.setTopology(new int[][]{{0,0,0,0},{0,0,0,0},{1,1,0,0},{0,0,1,0}});
......
......@@ -23,4 +23,6 @@ public interface OVSService {
boolean delVxlan(String bridgeName);
boolean delBridgePort(String bridgeName, String portName);
void setController(String bridgeName, String host, int port);
}
......@@ -152,6 +152,11 @@ public class OVSServiceImpl implements OVSService, InitializingBean {
}
}
@Override
public void setController(String bridgeName, String host, int port) {
ovsUtils.setController(bridgeName, host, port);
}
/**
* 连接两个虚拟交换机
* @param br1
......
......@@ -12,6 +12,8 @@ import top.ninwoo.utils.util.Utils;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @Author joliu
......@@ -21,7 +23,7 @@ import java.util.List;
@Utils
public class OvsUtilsImpl implements OvsUtils {
private final Logger LOG = LoggerFactory.getLogger(OvsUtilsImpl.class);
private final AtomicInteger atomicInteger = new AtomicInteger(0);
@Autowired
LinuxCtlUtils linuxCtlUtils;
......@@ -272,9 +274,11 @@ public class OvsUtilsImpl implements OvsUtils {
@Override
public boolean setVxlan(String bridgeName, String remoteIp) {
// TODO: bug
int id = atomicInteger.getAndIncrement();
String cmd = "echo 'Vudo3423' | sudo -S ovs-vsctl add-port " + bridgeName
+ " vxlan0 -- set interface vxlan0 type=vxlan options:remote_ip=" + remoteIp;
LOG.info("设置VXLAN[bridgeName:{},remoteIP:{}]", bridgeName, remoteIp);
+ " vxlan" + id + " -- set interface vxlan" + id + " type=vxlan options:remote_ip=" + remoteIp;
System.out.println(cmd);
LOG.info("设置VXLAN[bridgeName:{},remoteIP:{},{}]", bridgeName, remoteIp,cmd);
String res = linuxCtlUtils.runCmd(cmd);
if(!"".equals(res)) {
LOG.warn("setVxlan:" + "[" + bridgeName + "]:" + res);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment