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 AclServiceTestUtils method prepareAceIpBuilder.
public static AceIpBuilder prepareAceIpBuilder(String srcIpv4Net, String dstIpv4Net, String lowerPort, String upperPort, short protocol) {
AceIpBuilder builder = new AceIpBuilder();
AceIpv4Builder v4builder = new AceIpv4Builder();
if (srcIpv4Net != null) {
v4builder.setSourceIpv4Network(new Ipv4Prefix(srcIpv4Net));
} else {
v4builder.setSourceIpv4Network(null);
}
if (dstIpv4Net != null) {
v4builder.setDestinationIpv4Network(new Ipv4Prefix(dstIpv4Net));
} else {
v4builder.setDestinationIpv4Network(null);
}
builder.setAceIpVersion(v4builder.build());
if (lowerPort != null && upperPort != null) {
SourcePortRangeBuilder srcPortBuilder = new SourcePortRangeBuilder();
srcPortBuilder.setLowerPort(PortNumber.getDefaultInstance(lowerPort));
srcPortBuilder.setUpperPort(PortNumber.getDefaultInstance(upperPort));
builder.setSourcePortRange(srcPortBuilder.build());
DestinationPortRangeBuilder dstPortBuilder = new DestinationPortRangeBuilder();
dstPortBuilder.setLowerPort(PortNumber.getDefaultInstance(lowerPort));
dstPortBuilder.setUpperPort(PortNumber.getDefaultInstance(upperPort));
builder.setDestinationPortRange(dstPortBuilder.build());
}
builder.setProtocol(protocol);
return builder;
}
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 AclServiceTestBaseIPv6 method newMatch.
@Override
protected Matches newMatch(int srcLowerPort, int srcUpperPort, int destLowerPort, int destupperPort, int srcRemoteIpPrefix, int dstRemoteIpPrefix, short protocol) {
AceIpBuilder aceIpBuilder = new AceIpBuilder();
if (destLowerPort != -1) {
DestinationPortRangeBuilder destinationPortRangeBuilder = new DestinationPortRangeBuilder();
destinationPortRangeBuilder.setLowerPort(new PortNumber(destLowerPort));
destinationPortRangeBuilder.setUpperPort(new PortNumber(destupperPort));
aceIpBuilder.setDestinationPortRange(destinationPortRangeBuilder.build());
}
AceIpv6Builder aceIpv6Builder = new AceIpv6Builder();
if (srcRemoteIpPrefix == AclConstants.SOURCE_REMOTE_IP_PREFIX_SPECIFIED) {
aceIpv6Builder.setSourceIpv6Network(new Ipv6Prefix(AclConstants.IPV6_ALL_NETWORK));
}
if (dstRemoteIpPrefix == AclConstants.DEST_REMOTE_IP_PREFIX_SPECIFIED) {
aceIpv6Builder.setSourceIpv6Network(new Ipv6Prefix(AclConstants.IPV6_ALL_NETWORK));
}
if (protocol != -1) {
aceIpBuilder.setProtocol(protocol);
}
aceIpBuilder.setAceIpVersion(aceIpv6Builder.build());
MatchesBuilder matchesBuilder = new MatchesBuilder();
matchesBuilder.setAceType(aceIpBuilder.build());
return matchesBuilder.build();
}
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 AclServiceTestBase method newMatch.
// TODO refactor this instead of stealing it from org.opendaylight.netvirt.neutronvpn.NeutronSecurityRuleListener
protected Matches newMatch(int srcLowerPort, int srcUpperPort, int destLowerPort, int destupperPort, int srcRemoteIpPrefix, int dstRemoteIpPrefix, short protocol) {
AceIpBuilder aceIpBuilder = new AceIpBuilder();
if (destLowerPort != -1) {
DestinationPortRangeBuilder destinationPortRangeBuilder = new DestinationPortRangeBuilder();
destinationPortRangeBuilder.setLowerPort(new PortNumber(destLowerPort));
destinationPortRangeBuilder.setUpperPort(new PortNumber(destupperPort));
aceIpBuilder.setDestinationPortRange(destinationPortRangeBuilder.build());
}
AceIpv4Builder aceIpv4Builder = new AceIpv4Builder();
if (srcRemoteIpPrefix == AclConstants.SOURCE_REMOTE_IP_PREFIX_SPECIFIED) {
aceIpv4Builder.setSourceIpv4Network(new Ipv4Prefix(AclConstants.IPV4_ALL_NETWORK));
}
if (dstRemoteIpPrefix == AclConstants.DEST_REMOTE_IP_PREFIX_SPECIFIED) {
aceIpv4Builder.setSourceIpv4Network(new Ipv4Prefix(AclConstants.IPV4_ALL_NETWORK));
}
if (protocol != -1) {
aceIpBuilder.setProtocol(protocol);
}
aceIpBuilder.setAceIpVersion(aceIpv4Builder.build());
MatchesBuilder matchesBuilder = new MatchesBuilder();
matchesBuilder.setAceType(aceIpBuilder.build());
return matchesBuilder.build();
}
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 DisplayAclDataCaches method printAcl.
private void printAcl(String aclId, Acl acl) {
session.getConsole().println();
session.getConsole().println(ACL_HEADER + String.format("%-32s ", aclId));
if (null != acl.getAccessListEntries() && null != acl.getAccessListEntries().getAce()) {
printHeader(ACL_ENTRIES_HEADERS, ACL_ENTRIES_HEADER_LINE);
List<Ace> aceList = acl.getAccessListEntries().getAce();
for (Ace ace : aceList) {
LOG.info("ace data: {}", ace);
SecurityRuleAttr aceAttr = getAccessListAttributes(ace);
Class<? extends DirectionBase> aceAttrDirection = aceAttr.getDirection();
AceIp aceIp = (AceIp) ace.getMatches().getAceType();
AceIpVersion ipVersion = aceIp.getAceIpVersion();
Uint8 protoNum = aceIp.getProtocol();
String protocol = "Any";
if (null != protoNum) {
protocol = protoMap.get(protoNum.toString());
protocol = (protocol == null) ? protoNum.toString() : protocol;
}
String ipVer = "";
String direction = DirectionEgress.class.equals(aceAttrDirection) ? "Egress" : "Ingress";
String ipPrefix = " -- ";
if (null != ipVersion && ipVersion instanceof AceIpv4) {
ipVer = "IPv4";
Ipv4Prefix srcNetwork = ((AceIpv4) ipVersion).getSourceIpv4Network();
if (null != srcNetwork) {
ipPrefix = srcNetwork.getValue();
}
} else if (null != ipVersion && ipVersion instanceof AceIpv6) {
ipVer = "IPv6";
Ipv6Prefix srcNetwork = ((AceIpv6) ipVersion).getSourceIpv6Network();
if (null != srcNetwork) {
ipPrefix = srcNetwork.getValue();
}
}
String remoteGroupId = "-";
if (aceAttr.getRemoteGroupId() != null) {
remoteGroupId = aceAttr.getRemoteGroupId().getValue();
ipPrefix = "-";
}
String prefixAndRemoteId = ipPrefix + " / " + remoteGroupId;
session.getConsole().print(String.format(ACE_ENTRIES_FORMAT_STRING, ace.key().getRuleName(), direction, protocol, ipVer, prefixAndRemoteId));
}
}
session.getConsole().println();
}
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 NatUtil method removeSnatEntriesForPort.
public static void removeSnatEntriesForPort(DataBroker dataBroker, NaptManager naptManager, IMdsalApiManager mdsalManager, NeutronvpnService neutronVpnService, String interfaceName, String routerName) {
Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("removeSnatEntriesForPort: routerId not found for routername {}", routerName);
return;
}
Uint64 naptSwitch = getPrimaryNaptfromRouterName(dataBroker, routerName);
if (naptSwitch == null || naptSwitch.equals(Uint64.ZERO)) {
LOG.error("removeSnatEntriesForPort: NaptSwitch is not elected for router {}" + "with Id {}", routerName, routerId);
return;
}
// getInternalIp for port
List<String> fixedIps = getFixedIpsForPort(neutronVpnService, interfaceName);
if (fixedIps == null) {
LOG.error("removeSnatEntriesForPort: Internal Ips not found for InterfaceName {} in router {} with id {}", interfaceName, routerName, routerId);
return;
}
List<ProtocolTypes> protocolTypesList = getPortocolList();
for (String internalIp : fixedIps) {
LOG.debug("removeSnatEntriesForPort: Internal Ip retrieved for interface {} is {} in router with Id {}", interfaceName, internalIp, routerId);
for (ProtocolTypes protocol : protocolTypesList) {
List<Uint16> portList = NatUtil.getInternalIpPortListInfo(dataBroker, routerId, internalIp, protocol);
if (portList != null) {
for (Uint16 portnum : portList) {
// build and remove the flow in outbound table
removeNatFlow(mdsalManager, naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, routerId, internalIp, portnum.toJava(), protocol.getName());
// build and remove the flow in inboundtable
removeNatFlow(mdsalManager, naptSwitch, NwConstants.INBOUND_NAPT_TABLE, routerId, internalIp, portnum.toJava(), protocol.getName());
// Get the external IP address and the port from the model
NAPTEntryEvent.Protocol proto = protocol.toString().equals(ProtocolTypes.TCP.toString()) ? NAPTEntryEvent.Protocol.TCP : NAPTEntryEvent.Protocol.UDP;
IpPortExternal ipPortExternal = NatUtil.getExternalIpPortMap(dataBroker, routerId, internalIp, String.valueOf(portnum.toJava()), proto);
if (ipPortExternal == null) {
LOG.error("removeSnatEntriesForPort: Mapping for internalIp {} " + "with port {} is not found in " + "router with Id {}", internalIp, portnum, routerId);
return;
}
String externalIpAddress = ipPortExternal.getIpAddress();
String internalIpPort = internalIp + ":" + portnum.toJava();
// delete the entry from IntExtIpPortMap DS
naptManager.removeFromIpPortMapDS(routerId, internalIpPort, proto);
naptManager.removePortFromPool(internalIpPort, externalIpAddress);
}
} else {
LOG.debug("removeSnatEntriesForPort: No {} session for interface {} with internalIP {} " + "in router with id {}", protocol, interfaceName, internalIp, routerId);
}
}
// delete the entry from SnatIntIpPortMap DS
LOG.debug("removeSnatEntriesForPort: Removing InternalIp :{} of router {} from snatint-ip-port-map", internalIp, routerId);
naptManager.removeFromSnatIpPortDS(routerId, internalIp);
}
}
Aggregations