use of org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.Protocol in project netvirt by opendaylight.
the class NeutronvpnManager method dissociateNetworks.
/**
* It handles the invocations to the neutronvpn:dissociateNetworks RPC method.
*/
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public ListenableFuture<RpcResult<DissociateNetworksOutput>> dissociateNetworks(DissociateNetworksInput input) {
DissociateNetworksOutputBuilder opBuilder = new DissociateNetworksOutputBuilder();
SettableFuture<RpcResult<DissociateNetworksOutput>> result = SettableFuture.create();
LOG.debug("dissociateNetworks {}", input);
StringBuilder returnMsg = new StringBuilder();
Uuid vpnId = input.getVpnId();
try {
if (neutronvpnUtils.getVpnMap(vpnId) != null) {
LOG.debug("dissociateNetworks RPC: VpnId {}, networkList {}", vpnId.getValue(), input.getNetworkId());
List<Uuid> netIds = input.getNetworkId();
if (netIds != null && !netIds.isEmpty()) {
List<String> failed = dissociateNetworksFromVpn(vpnId, netIds);
if (!failed.isEmpty()) {
returnMsg.append(failed);
}
}
} else {
returnMsg.append("VPN not found : ").append(vpnId.getValue());
}
if (returnMsg.length() != 0) {
opBuilder.setResponse("ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: " + formatAndLog(LOG::error, "dissociate Networks to vpn {} failed due to {}", vpnId.getValue(), returnMsg));
result.set(RpcResultBuilder.<DissociateNetworksOutput>success().withResult(opBuilder.build()).build());
} else {
result.set(RpcResultBuilder.<DissociateNetworksOutput>success().build());
}
} catch (Exception ex) {
result.set(RpcResultBuilder.<DissociateNetworksOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "dissociate Networks to vpn {} failed due to {}", input.getVpnId().getValue(), ex.getMessage(), ex)).build());
}
LOG.debug("dissociateNetworks returns..");
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.Protocol in project netvirt by opendaylight.
the class NeutronSecurityRuleListener method toAceBuilder.
private AceBuilder toAceBuilder(SecurityRule securityRule, boolean isDeleted) {
AceIpBuilder aceIpBuilder = new AceIpBuilder();
SecurityRuleAttrBuilder securityRuleAttrBuilder = new SecurityRuleAttrBuilder();
DestinationPortRangeBuilder destinationPortRangeBuilder = new DestinationPortRangeBuilder();
boolean isDirectionIngress = false;
if (securityRule.getDirection() != null) {
securityRuleAttrBuilder.setDirection(DIRECTION_MAP.get(securityRule.getDirection()));
isDirectionIngress = securityRule.getDirection().equals(DirectionIngress.class);
}
if (securityRule.getPortRangeMax() != null) {
destinationPortRangeBuilder.setUpperPort(new PortNumber(securityRule.getPortRangeMax()));
}
if (securityRule.getPortRangeMin() != null) {
destinationPortRangeBuilder.setLowerPort(new PortNumber(securityRule.getPortRangeMin()));
// set destination port range if lower port is specified as it is mandatory parameter in acl model
aceIpBuilder.setDestinationPortRange(destinationPortRangeBuilder.build());
}
aceIpBuilder = handleRemoteIpPrefix(securityRule, aceIpBuilder, isDirectionIngress);
if (securityRule.getRemoteGroupId() != null) {
securityRuleAttrBuilder.setRemoteGroupId(securityRule.getRemoteGroupId());
}
if (securityRule.getProtocol() != null) {
SecurityRuleAttributes.Protocol protocol = securityRule.getProtocol();
if (protocol.getUint8() != null) {
// uint8
aceIpBuilder.setProtocol(protocol.getUint8());
} else {
// symbolic protocol name
aceIpBuilder.setProtocol(PROTOCOL_MAP.get(protocol.getIdentityref()));
}
}
securityRuleAttrBuilder.setDeleted(isDeleted);
MatchesBuilder matchesBuilder = new MatchesBuilder();
matchesBuilder.setAceType(aceIpBuilder.build());
// set acl action as permit for the security rule
ActionsBuilder actionsBuilder = new ActionsBuilder();
actionsBuilder.setPacketHandling(new PermitBuilder().setPermit(Empty.getInstance()).build());
AceBuilder aceBuilder = new AceBuilder();
aceBuilder.withKey(new AceKey(securityRule.getUuid().getValue()));
aceBuilder.setRuleName(securityRule.getUuid().getValue());
aceBuilder.setMatches(matchesBuilder.build());
aceBuilder.setActions(actionsBuilder.build());
aceBuilder.addAugmentation(securityRuleAttrBuilder.build());
return aceBuilder;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.Protocol in project netvirt by opendaylight.
the class AclServiceOFFlowBuilder method programOtherProtocolFlow.
/**
* Converts generic protocol matches to flows.
*
* @param acl the access control list
* @return the map containing the flows and the respective flow id
*/
public static Map<String, List<MatchInfoBase>> programOtherProtocolFlow(AceIp acl) {
List<MatchInfoBase> flowMatches = new ArrayList<>();
flowMatches.addAll(addSrcIpMatches(acl));
flowMatches.addAll(addDstIpMatches(acl));
if (acl.getAceIpVersion() instanceof AceIpv4) {
flowMatches.add(MatchEthernetType.IPV4);
} else if (acl.getAceIpVersion() instanceof AceIpv6) {
flowMatches.add(MatchEthernetType.IPV6);
}
flowMatches.add(new MatchIpProtocol(acl.getProtocol().toJava()));
String flowId = "OTHER_PROTO" + acl.getProtocol();
Map<String, List<MatchInfoBase>> flowMatchesMap = new HashMap<>();
flowMatchesMap.put(flowId, flowMatches);
return flowMatchesMap;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.Protocol in project netvirt by opendaylight.
the class AclServiceOFFlowBuilder method programIpFlow.
/**
* Converts IP matches into flows.
* @param matches
* the matches
* @return the map containing the flows and the respective flow id
*/
@Nullable
public static Map<String, List<MatchInfoBase>> programIpFlow(Matches matches) {
if (matches != null) {
AceIp acl = (AceIp) matches.getAceType();
Short protocol = acl.getProtocol() != null ? acl.getProtocol().toJava() : null;
if (protocol == null) {
return programEtherFlow(acl);
} else if (acl.getProtocol().intValue() == NwConstants.IP_PROT_TCP) {
return programTcpFlow(acl);
} else if (acl.getProtocol().intValue() == NwConstants.IP_PROT_UDP) {
return programUdpFlow(acl);
} else if (acl.getProtocol().intValue() == NwConstants.IP_PROT_ICMP) {
return programIcmpFlow(acl);
} else if (acl.getProtocol().intValue() != -1) {
return programOtherProtocolFlow(acl);
}
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.Protocol in project netvirt by opendaylight.
the class NaptSwitchHA method removeSnatFlowsInOldNaptSwitch.
protected void removeSnatFlowsInOldNaptSwitch(Routers extRouter, Uint32 routerId, Uint64 naptSwitch, @Nullable Map<String, Uint32> externalIpmap, String externalVpnName, TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
// remove SNAT flows in old NAPT SWITCH
String routerName = extRouter.getRouterName();
Uuid networkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
String vpnName = getExtNetworkVpnName(routerName, networkId);
if (vpnName == null) {
LOG.error("removeSnatFlowsInOldNaptSwitch : Vpn is not associated to externalN/w of router {}", routerName);
return;
}
ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, networkId);
if (extNwProvType == null) {
LOG.error("removeSnatFlowsInOldNaptSwitch : Unable to retrieve the External Network Provider Type " + "for Router {}", routerName);
return;
}
if (extNwProvType == ProviderTypes.VXLAN) {
evpnNaptSwitchHA.evpnRemoveSnatFlowsInOldNaptSwitch(routerName, routerId, vpnName, naptSwitch, confTx);
} else {
// Remove the Terminating Service table entry which forwards the packet to Outbound NAPT Table
Uint64 tunnelId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, natOverVxlanUtil, elanManager, idManager, routerId, routerName);
String tsFlowRef = externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.INTERNAL_TUNNEL_TABLE, Uint32.valueOf(tunnelId));
FlowEntity tsNatFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.INTERNAL_TUNNEL_TABLE, tsFlowRef);
LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for the old napt switch " + "with the DPN ID {} and router ID {}", NwConstants.INTERNAL_TUNNEL_TABLE, naptSwitch, routerId);
mdsalManager.removeFlow(confTx, tsNatFlowEntity);
}
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
// Remove the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE)
NatUtil.removePreDnatToSnatTableEntry(confTx, mdsalManager, naptSwitch);
}
// Remove the Outbound flow entry which forwards the packet to Outbound NAPT Table
LOG.info("Remove the flow in table {} for the old napt switch with the DPN ID {} and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, naptSwitch, routerId);
String outboundTcpNatFlowRef = externalRouterListener.getFlowRefOutbound(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, routerId, NwConstants.IP_PROT_TCP);
FlowEntity outboundTcpNatFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, outboundTcpNatFlowRef);
mdsalManager.removeFlow(confTx, outboundTcpNatFlowEntity);
String outboundUdpNatFlowRef = externalRouterListener.getFlowRefOutbound(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, routerId, NwConstants.IP_PROT_UDP);
FlowEntity outboundUdpNatFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, outboundUdpNatFlowRef);
mdsalManager.removeFlow(confTx, outboundUdpNatFlowEntity);
String icmpDropFlowRef = externalRouterListener.getFlowRefOutbound(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, routerId, NwConstants.IP_PROT_ICMP);
FlowEntity icmpDropFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, icmpDropFlowRef);
mdsalManager.removeFlow(confTx, icmpDropFlowEntity);
// Remove the NAPT PFIB TABLE (47->21) which forwards the incoming packet to FIB Table matching on the
// External Subnet Vpn Id.
Collection<Uuid> externalSubnetIdsForRouter = NatUtil.getExternalSubnetIdsForRouter(dataBroker, routerName);
for (Uuid externalSubnetId : externalSubnetIdsForRouter) {
Uint32 subnetVpnId = NatUtil.getVpnId(dataBroker, externalSubnetId.getValue());
if (subnetVpnId != NatConstants.INVALID_ID && !NatUtil.checkForRoutersWithSameExtSubnetAndNaptSwitch(dataBroker, externalSubnetId, routerName, naptSwitch)) {
String natPfibSubnetFlowRef = externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.NAPT_PFIB_TABLE, subnetVpnId);
FlowEntity natPfibFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.NAPT_PFIB_TABLE, natPfibSubnetFlowRef);
mdsalManager.removeFlow(confTx, natPfibFlowEntity);
LOG.debug("removeSnatFlowsInOldNaptSwitch : Removed the flow in table {} with external subnet " + "Vpn Id {} as metadata on Napt Switch {}", NwConstants.NAPT_PFIB_TABLE, subnetVpnId, naptSwitch);
}
}
// Remove the NAPT_PFIB_TABLE(47) flow entry forwards the packet to Fib Table for inbound traffic
// matching on the router ID.
String naptPFibflowRef = externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.NAPT_PFIB_TABLE, routerId);
FlowEntity naptPFibFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.NAPT_PFIB_TABLE, naptPFibflowRef);
LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for the old napt switch " + "with the DPN ID {} and router ID {}", NwConstants.NAPT_PFIB_TABLE, naptSwitch, routerId);
mdsalManager.removeFlow(confTx, naptPFibFlowEntity);
// Remove the NAPT_PFIB_TABLE(47) flow entry forwards the packet to Fib Table for outbound traffic
// matching on the vpn ID.
boolean switchSharedByRouters = false;
Uuid extNetworkId = extRouter.getNetworkId();
if (extNetworkId != null && !NatUtil.checkForRoutersWithSameExtNetAndNaptSwitch(dataBroker, extNetworkId, routerName, naptSwitch)) {
List<String> routerNamesAssociated = getRouterIdsForExtNetwork(extNetworkId);
for (String routerNameAssociated : routerNamesAssociated) {
if (!routerNameAssociated.equals(routerName)) {
Uint32 routerIdAssociated = NatUtil.getVpnId(dataBroker, routerNameAssociated);
Uint64 naptDpn = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerNameAssociated);
if (naptDpn != null && naptDpn.equals(naptSwitch)) {
LOG.debug("removeSnatFlowsInOldNaptSwitch : Napt switch {} is also acting as primary " + "for router {}", naptSwitch, routerIdAssociated);
switchSharedByRouters = true;
break;
}
}
}
if (!switchSharedByRouters) {
Uint32 vpnId = NatUtil.getVpnId(dataBroker, externalVpnName);
if (vpnId != NatConstants.INVALID_ID) {
String naptFibflowRef = externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.NAPT_PFIB_TABLE, vpnId);
FlowEntity naptFibFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.NAPT_PFIB_TABLE, naptFibflowRef);
LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for the old napt switch" + " with the DPN ID {} and vpnId {}", NwConstants.NAPT_PFIB_TABLE, naptSwitch, vpnId);
mdsalManager.removeFlow(confTx, naptFibFlowEntity);
} else {
LOG.error("removeSnatFlowsInOldNaptSwitch : Invalid vpnId retrieved for routerId {}", routerId);
return;
}
}
}
// Remove Fib entries,tables 20->44 ,36-> 44
String gwMacAddress = NatUtil.getExtGwMacAddFromRouterName(dataBroker, routerName);
if (externalIpmap != null && !externalIpmap.isEmpty()) {
for (Entry<String, Uint32> entry : externalIpmap.entrySet()) {
String externalIp = entry.getKey();
Uint32 label = entry.getValue();
externalRouterListener.delFibTsAndReverseTraffic(naptSwitch, routerName, routerId, externalIp, vpnName, extNetworkId, label, gwMacAddress, true, confTx);
LOG.debug("removeSnatFlowsInOldNaptSwitch : Successfully removed fib entries in old naptswitch {} " + "for router {} and externalIps {} label {}", naptSwitch, routerId, externalIp, label);
}
} else {
List<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerName);
if (extNetworkId != null) {
externalRouterListener.clearFibTsAndReverseTraffic(naptSwitch, routerId, extNetworkId, externalIps, null, gwMacAddress, confTx);
LOG.debug("removeSnatFlowsInOldNaptSwitch : Successfully removed fib entries in old naptswitch {} for " + "router {} with networkId {} and externalIps {}", naptSwitch, routerId, extNetworkId, externalIps);
} else {
LOG.debug("removeSnatFlowsInOldNaptSwitch : External network not associated to router {}", routerId);
}
externalRouterListener.removeNaptFibExternalOutputFlows(routerId, naptSwitch, extNetworkId, externalIps, confTx);
}
// For the router ID get the internal IP , internal port and the corresponding external IP and external Port.
IpPortMapping ipPortMapping = NatUtil.getIportMapping(dataBroker, routerId);
if (ipPortMapping == null || ipPortMapping.getIntextIpProtocolType() == null || ipPortMapping.getIntextIpProtocolType().isEmpty()) {
LOG.warn("removeSnatFlowsInOldNaptSwitch : No Internal Ip Port mapping associated to router {}, " + "no flows need to be removed in oldNaptSwitch {}", routerId, naptSwitch);
return;
}
Uint64 cookieSnatFlow = NatUtil.getCookieNaptFlow(routerId);
Map<IntextIpProtocolTypeKey, IntextIpProtocolType> keyIntextIpProtocolTypeMap = ipPortMapping.nonnullIntextIpProtocolType();
for (IntextIpProtocolType intextIpProtocolType : keyIntextIpProtocolTypeMap.values()) {
if (intextIpProtocolType.getIpPortMap() == null || intextIpProtocolType.getIpPortMap().isEmpty()) {
LOG.debug("removeSnatFlowsInOldNaptSwitch : No {} session associated to router {}," + "no flows need to be removed in oldNaptSwitch {}", intextIpProtocolType.getProtocol(), routerId, naptSwitch);
continue;
}
String protocol = intextIpProtocolType.getProtocol().name();
Map<IpPortMapKey, IpPortMap> keyIpPortMapMap = intextIpProtocolType.nonnullIpPortMap();
for (IpPortMap ipPortMap : keyIpPortMapMap.values()) {
String ipPortInternal = ipPortMap.getIpPortInternal();
String[] ipPortParts = ipPortInternal.split(":");
if (ipPortParts.length != 2) {
LOG.error("removeSnatFlowsInOldNaptSwitch : Unable to retrieve the Internal IP and port");
continue;
}
String internalIp = ipPortParts[0];
String internalPort = ipPortParts[1];
// Build and remove flow in outbound NAPT table
String switchFlowRef = NatUtil.getNaptFlowRef(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, String.valueOf(routerId), internalIp, Integer.parseInt(internalPort), protocol);
FlowEntity outboundNaptFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, cookieSnatFlow, switchFlowRef);
LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for old napt switch " + "with the DPN ID {} and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, naptSwitch, routerId);
mdsalManager.removeFlow(confTx, outboundNaptFlowEntity);
// Build and remove flow in inbound NAPT table
switchFlowRef = NatUtil.getNaptFlowRef(naptSwitch, NwConstants.INBOUND_NAPT_TABLE, String.valueOf(routerId), internalIp, Integer.parseInt(internalPort), protocol);
FlowEntity inboundNaptFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.INBOUND_NAPT_TABLE, cookieSnatFlow, switchFlowRef);
LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for old napt switch with the " + "DPN ID {} and router ID {}", NwConstants.INBOUND_NAPT_TABLE, naptSwitch, routerId);
mdsalManager.removeFlow(confTx, inboundNaptFlowEntity);
}
}
}
Aggregations