This repository has been archived by the owner on Mar 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split DpmService into multiple files according to resource type
- Loading branch information
1 parent
f45e561
commit 3b20ef1
Showing
9 changed files
with
757 additions
and
531 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...ta_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/ovs/DhcpService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Copyright 2019 The Alcor Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.futurewei.alcor.dataplane.service.ovs; | ||
|
||
import com.futurewei.alcor.dataplane.entity.UnicastGoalState; | ||
import com.futurewei.alcor.schema.DHCP; | ||
import com.futurewei.alcor.schema.Port; | ||
import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class DhcpService extends ResourceService { | ||
public void buildDhcpStates(NetworkConfiguration networkConfig, UnicastGoalState unicastGoalState) throws Exception { | ||
List<Port.PortState> portStates = unicastGoalState.getGoalStateBuilder().getPortStatesList(); | ||
if (portStates == null || portStates.size() == 0) { | ||
return; | ||
} | ||
|
||
for (Port.PortState portState: portStates) { | ||
String macAddress = portState.getConfiguration().getMacAddress(); | ||
List<Port.PortConfiguration.FixedIp> fixedIps = portState.getConfiguration().getFixedIpsList(); | ||
for (Port.PortConfiguration.FixedIp fixedIp: fixedIps) { | ||
DHCP.DHCPConfiguration.Builder dhcpConfigBuilder = DHCP.DHCPConfiguration.newBuilder(); | ||
dhcpConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); | ||
dhcpConfigBuilder.setMacAddress(macAddress); | ||
dhcpConfigBuilder.setIpv4Address(fixedIp.getIpAddress()); | ||
//TODO: support ipv6 | ||
//dhcpConfigBuilder.setIpv6Address(); | ||
//dhcpConfigBuilder.setPortHostName(); | ||
//dhcpConfigBuilder.setExtraDhcpOptions(); | ||
//dhcpConfigBuilder.setDnsEntryList(); | ||
|
||
DHCP.DHCPState.Builder dhcpStateBuilder = DHCP.DHCPState.newBuilder(); | ||
dhcpStateBuilder.setOperationType(networkConfig.getOpType()); | ||
dhcpStateBuilder.setConfiguration(dhcpConfigBuilder.build()); | ||
unicastGoalState.getGoalStateBuilder().addDhcpStates(dhcpStateBuilder.build()); | ||
} | ||
} | ||
} | ||
} |
556 changes: 25 additions & 531 deletions
556
...plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/ovs/DpmServiceImpl.java
Large diffs are not rendered by default.
Oops, something went wrong.
131 changes: 131 additions & 0 deletions
131
...lane_manager/src/main/java/com/futurewei/alcor/dataplane/service/ovs/NeighborService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
Copyright 2019 The Alcor Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.futurewei.alcor.dataplane.service.ovs; | ||
|
||
import com.futurewei.alcor.dataplane.entity.MulticastGoalState; | ||
import com.futurewei.alcor.dataplane.entity.UnicastGoalState; | ||
import com.futurewei.alcor.dataplane.exception.NeighborInfoNotFound; | ||
import com.futurewei.alcor.dataplane.exception.PortFixedIpNotFound; | ||
import com.futurewei.alcor.schema.Common; | ||
import com.futurewei.alcor.schema.Neighbor; | ||
import com.futurewei.alcor.schema.Port; | ||
import com.futurewei.alcor.web.entity.dataplane.NeighborEntry; | ||
import com.futurewei.alcor.web.entity.dataplane.NeighborInfo; | ||
import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.*; | ||
|
||
@Service | ||
public class NeighborService extends ResourceService { | ||
public Neighbor.NeighborState buildNeighborState(NeighborEntry neighborEntry, NeighborInfo neighborInfo, Common.OperationType operationType) { | ||
Neighbor.NeighborConfiguration.Builder neighborConfigBuilder = Neighbor.NeighborConfiguration.newBuilder(); | ||
neighborConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); | ||
//neighborConfigBuilder.setId(); // TODO: We are going to need this per latest ACA change | ||
neighborConfigBuilder.setVpcId(neighborInfo.getVpcId()); | ||
//neighborConfigBuilder.setName(); | ||
neighborConfigBuilder.setMacAddress(neighborInfo.getPortMac()); | ||
neighborConfigBuilder.setHostIpAddress(neighborInfo.getHostIp()); | ||
Neighbor.NeighborType neighborType = Neighbor.NeighborType.valueOf(neighborEntry.getNeighborType().getType()); | ||
|
||
//TODO:setNeighborHostDvrMac | ||
//neighborConfigBuilder.setNeighborHostDvrMac(); | ||
Neighbor.NeighborConfiguration.FixedIp.Builder fixedIpBuilder = Neighbor.NeighborConfiguration.FixedIp.newBuilder(); | ||
fixedIpBuilder.setSubnetId(neighborInfo.getSubnetId()); | ||
fixedIpBuilder.setIpAddress(neighborInfo.getPortIp()); | ||
fixedIpBuilder.setNeighborType(neighborType); | ||
neighborConfigBuilder.addFixedIps(fixedIpBuilder.build()); | ||
//TODO:setAllowAddressPairs | ||
//neighborConfigBuilder.setAllowAddressPairs(); | ||
|
||
Neighbor.NeighborState.Builder neighborStateBuilder = Neighbor.NeighborState.newBuilder(); | ||
neighborStateBuilder.setOperationType(operationType); | ||
neighborStateBuilder.setConfiguration(neighborConfigBuilder.build()); | ||
|
||
return neighborStateBuilder.build(); | ||
} | ||
|
||
public void buildNeighborStates(NetworkConfiguration networkConfig, String hostIp, | ||
UnicastGoalState unicastGoalState, | ||
MulticastGoalState multicastGoalState) throws Exception { | ||
Map<String, NeighborInfo> neighborInfos = networkConfig.getNeighborInfos(); | ||
if (neighborInfos == null || neighborInfos.size() == 0) { | ||
return; | ||
} | ||
|
||
Map<String, List<NeighborEntry>> neighborTable = networkConfig.getNeighborTable(); | ||
if (neighborTable == null || neighborTable.size() == 0) { | ||
return; | ||
} | ||
|
||
List<Port.PortState> portStates = unicastGoalState.getGoalStateBuilder().getPortStatesList(); | ||
if (portStates == null || portStates.size() == 0) { | ||
return; | ||
} | ||
|
||
List<NeighborEntry> multicastNeighborEntries = new ArrayList<>(); | ||
for (Port.PortState portState: portStates) { | ||
List<Port.PortConfiguration.FixedIp> fixedIps = portState.getConfiguration().getFixedIpsList(); | ||
if (fixedIps == null) { | ||
throw new PortFixedIpNotFound(); | ||
} | ||
|
||
for (Port.PortConfiguration.FixedIp fixedIp: fixedIps) { | ||
List<NeighborEntry> neighborEntries = neighborTable.get(fixedIp.getIpAddress()); | ||
if (neighborEntries == null) { | ||
throw new NeighborInfoNotFound(); | ||
} | ||
|
||
for (NeighborEntry neighborEntry: neighborEntries) { | ||
NeighborInfo neighborInfo = neighborInfos.get(neighborEntry.getNeighborIp()); | ||
if (neighborInfo == null) { | ||
throw new NeighborInfoNotFound(); | ||
} | ||
|
||
if (hostIp.equals(neighborInfo.getHostIp())) { | ||
continue; | ||
} | ||
|
||
unicastGoalState.getGoalStateBuilder().addNeighborStates(buildNeighborState( | ||
neighborEntry, neighborInfo, networkConfig.getOpType())); | ||
} | ||
|
||
multicastNeighborEntries.addAll(neighborEntries); | ||
} | ||
} | ||
|
||
Set<NeighborInfo> neighborInfoSet = new HashSet<>(); | ||
for (NeighborEntry neighborEntry: multicastNeighborEntries) { | ||
String localIp = neighborEntry.getLocalIp(); | ||
String neighborIp = neighborEntry.getNeighborIp(); | ||
NeighborInfo neighborInfo1 = neighborInfos.get(localIp); | ||
NeighborInfo neighborInfo2 = neighborInfos.get(neighborIp); | ||
if (neighborInfo1 == null || neighborInfo2 == null) { | ||
throw new NeighborInfoNotFound(); | ||
} | ||
|
||
if (!multicastGoalState.getHostIps().contains(neighborInfo2.getHostIp())) { | ||
multicastGoalState.getHostIps().add(neighborInfo2.getHostIp()); | ||
} | ||
|
||
if (!neighborInfoSet.contains(neighborInfo1)) { | ||
multicastGoalState.getGoalStateBuilder().addNeighborStates(buildNeighborState( | ||
neighborEntry, neighborInfo1, networkConfig.getOpType())); | ||
neighborInfoSet.add(neighborInfo1); | ||
} | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...ta_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/ovs/PortService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
Copyright 2019 The Alcor Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.futurewei.alcor.dataplane.service.ovs; | ||
|
||
import com.futurewei.alcor.dataplane.entity.UnicastGoalState; | ||
import com.futurewei.alcor.schema.Common; | ||
import com.futurewei.alcor.schema.Port; | ||
import com.futurewei.alcor.web.entity.dataplane.InternalPortEntity; | ||
import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class PortService extends ResourceService { | ||
public void buildPortState(NetworkConfiguration networkConfig, List<InternalPortEntity> portEntities, | ||
UnicastGoalState unicastGoalState) { | ||
for (InternalPortEntity portEntity: portEntities) { | ||
Port.PortConfiguration.Builder portConfigBuilder = Port.PortConfiguration.newBuilder(); | ||
portConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); | ||
portConfigBuilder.setId(portEntity.getId()); | ||
portConfigBuilder.setUpdateType(Common.UpdateType.FULL); | ||
portConfigBuilder.setVpcId(portEntity.getVpcId()); | ||
|
||
if (portEntity.getName() != null) { | ||
portConfigBuilder.setName(portEntity.getName()); | ||
} | ||
|
||
portConfigBuilder.setMacAddress(portEntity.getMacAddress()); | ||
portConfigBuilder.setAdminStateUp(portEntity.isAdminStateUp()); | ||
|
||
Port.PortConfiguration.HostInfo.Builder hostInfoBuilder = Port.PortConfiguration.HostInfo.newBuilder(); | ||
hostInfoBuilder.setIpAddress(portEntity.getBindingHostIP()); | ||
//TODO: Do we need mac address? | ||
//hostInfoBuilder.setMacAddress() | ||
portConfigBuilder.setHostInfo(hostInfoBuilder.build()); | ||
if (portEntity.getFixedIps() != null) { | ||
portEntity.getFixedIps().forEach(fixedIp -> { | ||
Port.PortConfiguration.FixedIp.Builder fixedIpBuilder = Port.PortConfiguration.FixedIp.newBuilder(); | ||
fixedIpBuilder.setSubnetId(fixedIp.getSubnetId()); | ||
fixedIpBuilder.setIpAddress(fixedIp.getIpAddress()); | ||
portConfigBuilder.addFixedIps(fixedIpBuilder.build()); | ||
}); | ||
} | ||
|
||
if (portEntity.getAllowedAddressPairs() != null) { | ||
portEntity.getAllowedAddressPairs().forEach(pair -> { | ||
Port.PortConfiguration.AllowAddressPair.Builder allowAddressPairBuilder = Port.PortConfiguration.AllowAddressPair.newBuilder(); | ||
allowAddressPairBuilder.setIpAddress(pair.getIpAddress()); | ||
allowAddressPairBuilder.setMacAddress(pair.getMacAddress()); | ||
portConfigBuilder.addAllowAddressPairs(allowAddressPairBuilder.build()); | ||
}); | ||
} | ||
|
||
if (portEntity.getSecurityGroups() != null) { | ||
portEntity.getSecurityGroups().forEach(securityGroupId-> { | ||
Port.PortConfiguration.SecurityGroupId.Builder securityGroupIdBuilder = Port.PortConfiguration.SecurityGroupId.newBuilder(); | ||
securityGroupIdBuilder.setId(securityGroupId); | ||
portConfigBuilder.addSecurityGroupIds(securityGroupIdBuilder.build()); | ||
}); | ||
} | ||
|
||
//PortState | ||
Port.PortState.Builder portStateBuilder = Port.PortState.newBuilder(); | ||
portStateBuilder.setOperationType(networkConfig.getOpType()); | ||
portStateBuilder.setConfiguration(portConfigBuilder.build()); | ||
unicastGoalState.getGoalStateBuilder().addPortStates(portStateBuilder.build()); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...lane_manager/src/main/java/com/futurewei/alcor/dataplane/service/ovs/ResourceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright 2019 The Alcor Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.futurewei.alcor.dataplane.service.ovs; | ||
|
||
import com.futurewei.alcor.schema.Common.OperationType; | ||
|
||
public class ResourceService { | ||
protected static final int FORMAT_REVISION_NUMBER = 1; | ||
|
||
protected OperationType getOperationType(com.futurewei.alcor.common.enumClass.OperationType operationType) { | ||
switch (operationType) { | ||
case CREATE: | ||
return OperationType.CREATE; | ||
case UPDATE: | ||
return OperationType.UPDATE; | ||
case INFO: | ||
return OperationType.INFO; | ||
case DELETE: | ||
return OperationType.DELETE; | ||
default: | ||
return OperationType.UNRECOGNIZED; | ||
} | ||
} | ||
} |
Oops, something went wrong.