public static String getSubnetCidrAsString(IpPrefix subnet) { return (subnet == null) ? StringUtils.EMPTY : String.valueOf(subnet.getValue()); } public static <T> List<T> emptyIfNull(List<T> list) {
public static int getMask(IpPrefix ip) { StringBuilder buf = new StringBuilder(); boolean foundSlash = false; for (char x : ip.getValue()) { if (!foundSlash && x == '/') { foundSlash = true; continue; } if (foundSlash) { buf.append(x); } } return Integer.parseInt(buf.toString()); }
public static IpAddress getIpAddress(IpPrefix ip) { StringBuilder buf = new StringBuilder(); for (char x : ip.getValue()) { if (x == '/') { break; } buf.append(x); } return new IpAddress(buf.toString().toCharArray()); }
public char[] getValue() { if (_value == null) { if (_ipPrefix != null) { _value = _ipPrefix.getValue(); } else if (_ipAddress != null) { _value = _ipAddress.getValue(); } } return _value == null ? null : _value.clone(); }
protected static Short getIPPrefixFromPort(DataBroker broker, Port port) { Short prefix = new Short((short) 0); String cidr = ""; try { Uuid subnetUUID = port.getFixedIps().get(0).getSubnetId(); SubnetKey subnetkey = new SubnetKey(subnetUUID); InstanceIdentifier<Subnet> subnetidentifier = InstanceIdentifier.create(Neutron.class).child(Subnets .class).child(Subnet.class, subnetkey); Optional<Subnet> subnet = read(broker, LogicalDatastoreType.CONFIGURATION, subnetidentifier); if (subnet.isPresent()) { cidr = String.valueOf(subnet.get().getCidr().getValue()); // Extract the prefix length from cidr String[] parts = cidr.split("/"); if (parts.length == 2) { prefix = Short.valueOf(parts[1]); return prefix; } else { logger.trace("Could not retrieve prefix from subnet CIDR"); System.out.println("Could not retrieve prefix from subnet CIDR"); } } else { logger.trace("Unable to read on subnet datastore"); } } catch (Exception e) { logger.error("Failed to retrieve IP prefix from port : ", e); System.out.println("Failed to retrieve IP prefix from port : " + e.getMessage()); } return null; }
public static InstanceIdentifier<ExternalGatewayAsEndpoint> externalGatewayAsEndpoint(ContextId contextId, IpPrefix ipPrefix, Class<? extends ContextType> contextType) { ExternalGatewayAsEndpointKey key = new ExternalGatewayAsEndpointKey( new String(ipPrefix.getValue()), IpPrefixType.class, contextId, contextType); return InstanceIdentifier.builder( org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings.class) .child(NeutronByGbpMappings.class) .child(ExternalGatewaysAsEndpoints.class) .child(ExternalGatewayAsEndpoint.class, key) .build(); }
} else { LOG.warn("Failed installing route to {}. Reason: InterVPNLink {} is not Active", String.valueOf(route.getDestination().getValue()), interVpnLink.get().getName());
public static ExternalGatewayAsEndpoint createEaxternalGatewayAsEndpoint(ContextId contextId, IpPrefix ipPrefix) { return new ExternalGatewayAsEndpointBuilder().setAddress(new String(ipPrefix.getValue())) .setAddressType(IpPrefixType.class) .setContextId(contextId) .setContextType(MappingUtils.L3_CONTEXT) .build(); }
@Override protected void add(InstanceIdentifier<Subnet> identifier, Subnet input) { if (LOG.isTraceEnabled()) { LOG.trace("Adding Subnet : key: " + identifier + ", value=" + input); } Uuid networkId = input.getNetworkId(); Network network = NeutronvpnUtils.getNeutronNetwork(dataBroker, networkId); if (network == null || !NeutronvpnUtils.isNetworkTypeSupported(network)) { //FIXME: This should be removed when support for VLAN and GRE network types is added LOG.error("neutron vpn doesn't support vlan/gre network provider type for the port {} which is part of network {}." + " Skipping the processing of Subnet add DCN", input.getName(), network); return; } handleNeutronSubnetCreated(input.getUuid(), String.valueOf(input.getCidr().getValue()), networkId, input.getTenantId()); NeutronvpnUtils.addToSubnetCache(input); }
final Eid eid = LispAddressUtil.asIpv4PrefixEid(String.valueOf(subnet.getCidr().getValue()));
final Eid eid = LispAddressUtil.asIpv4PrefixEid(String.valueOf(subnet.getCidr().getValue()));
/** * Removes the corresponding static routes from the specified VPN. These static routes point to an * InterVpnLink endpoint and the specified VPN must be the other end of the InterVpnLink. * * @param vpnName the VPN identifier * @param interVpnLinkRoutes The list of static routes * @param nexthopsXinterVpnLinks A Map with the correspondence nextHop-InterVpnLink */ public void removeInterVpnRoutes(Uuid vpnName, List<Routes> interVpnLinkRoutes, HashMap<String, InterVpnLink> nexthopsXinterVpnLinks) { for ( Routes route : interVpnLinkRoutes ) { String nexthop = String.valueOf(route.getNexthop().getValue()); String destination = String.valueOf(route.getDestination().getValue()); InterVpnLink interVpnLink = nexthopsXinterVpnLinks.get(nexthop); if ( isNexthopTheOtherVpnLinkEndpoint(nexthop, vpnName.getValue(), interVpnLink) ) { RemoveStaticRouteInput rpcInput = new RemoveStaticRouteInputBuilder().setDestination(destination).setNexthop(nexthop) .setVpnInstanceName(vpnName.getValue()) .build(); vpnRpcService.removeStaticRoute(rpcInput); } else { // Any other case is a fault. LOG.warn("route with destination {} and nexthop {} does not apply to any InterVpnLink", String.valueOf(route.getDestination().getValue()), nexthop ); continue; } } }
String tunTypeStr = tunType.getName(); String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(idManagerService, interfaceName, firstEndPt.getIpAddress().getIpv4Address().getValue(), extIp.getIpv4Address().getValue(), tunTypeStr); char[] subnetMaskArray = firstEndPt.getSubnetMask().getValue(); String subnetMaskStr = String.valueOf(subnetMaskArray); SubnetUtils utils = new SubnetUtils(subnetMaskStr);
public SecurityRuleUpdatedImpl(SecurityRule secRule) { Date date= new Date(); timeStamp = new Timestamp(date.getTime()); securityRule = new NeutronSecurityRule(); securityRule.setSecurityRuleID(secRule.getUuid().getValue()); securityRule.setSecurityGroupID(secRule.getSecurityGroupId().getValue()); securityRule.setSecurityTenantID(secRule.getTenantId().getValue()); if (secRule.getDirection() != null) { securityRule.setSecurityRuleDirection(secRule.getDirection().getSimpleName()); } if (secRule.getProtocol() != null) { securityRule.setSecurityRuleProtocol(String.valueOf(secRule.getProtocol().getValue())); } if (secRule.getEthertype() != null) { securityRule.setSecurityRuleEthertype(secRule.getEthertype().getSimpleName()); } if (secRule.getRemoteIpPrefix() != null) { securityRule.setSecurityRuleRemoteIpPrefix(String.valueOf(secRule.getRemoteIpPrefix().getValue())); } if (secRule.getPortRangeMin() != null) { securityRule.setSecurityRulePortMin(secRule.getPortRangeMin()); } if (secRule.getPortRangeMax() != null) { securityRule.setSecurityRulePortMax(secRule.getPortRangeMax()); } } @Override
public SecurityRuleAddedImpl(SecurityRule secRule) { Date date= new Date(); timeStamp = new Timestamp(date.getTime()); securityRule = new NeutronSecurityRule(); securityRule.setSecurityRuleID(secRule.getUuid().getValue()); securityRule.setSecurityGroupID(secRule.getSecurityGroupId().getValue()); securityRule.setSecurityTenantID(secRule.getTenantId().getValue()); if (secRule.getDirection() != null) { securityRule.setSecurityRuleDirection(secRule.getDirection().getSimpleName()); } if (secRule.getProtocol() != null) { securityRule.setSecurityRuleProtocol(String.valueOf(secRule.getProtocol().getValue())); } if (secRule.getEthertype() != null) { securityRule.setSecurityRuleEthertype(secRule.getEthertype().getSimpleName()); } if (secRule.getRemoteIpPrefix() != null) { securityRule.setSecurityRuleRemoteIpPrefix(String.valueOf(secRule.getRemoteIpPrefix().getValue())); } if (secRule.getPortRangeMin() != null) { securityRule.setSecurityRulePortMin(secRule.getPortRangeMin()); } if (secRule.getPortRangeMax() != null) { securityRule.setSecurityRulePortMax(secRule.getPortRangeMax()); } }
public SecurityRuleDeletedImpl(SecurityRule secRule) { Date date= new Date(); timeStamp = new Timestamp(date.getTime()); securityRule = new NeutronSecurityRule(); securityRule.setSecurityRuleID(secRule.getUuid().getValue()); securityRule.setSecurityGroupID(secRule.getSecurityGroupId().getValue()); securityRule.setSecurityTenantID(secRule.getTenantId().getValue()); if (secRule.getDirection() != null) { securityRule.setSecurityRuleDirection(secRule.getDirection().getSimpleName()); } if (secRule.getProtocol() != null) { securityRule.setSecurityRuleProtocol(String.valueOf(secRule.getProtocol().getValue())); } if (secRule.getEthertype() != null) { securityRule.setSecurityRuleEthertype(secRule.getEthertype().getSimpleName()); } if (secRule.getRemoteIpPrefix() != null) { securityRule.setSecurityRuleRemoteIpPrefix(String.valueOf(secRule.getRemoteIpPrefix().getValue())); } if (secRule.getPortRangeMin() != null) { securityRule.setSecurityRulePortMin(secRule.getPortRangeMin()); } if (secRule.getPortRangeMax() != null) { securityRule.setSecurityRulePortMax(secRule.getPortRangeMax()); } } @Override
private NetworkDomain createSubnetWithVirtualRouterIp(IpPrefix gatewayIp, NetworkDomainId subnetId) { Subnet subnet = new SubnetBuilder().setVirtualRouterIp(MappingUtils.ipPrefixToIpAddress(gatewayIp.getValue())).build(); return new NetworkDomainBuilder().setKey(new NetworkDomainKey(subnetId, MappingUtils.SUBNET)) .addAugmentation(SubnetAugmentForwarding.class, new SubnetAugmentForwardingBuilder().setSubnet(subnet).build()) .build(); }
for (final Routes route : router.getRoutes()) { final NeutronRoute routerRoute = new NeutronRoute(); routerRoute.setDestination(String.valueOf(route.getDestination().getValue())); routerRoute.setNextHop(String.valueOf(route.getNexthop().getValue())); routes.add(routerRoute);
protected NeutronMeteringLabelRule fromMd(MeteringRule rule) { final NeutronMeteringLabelRule answer = new NeutronMeteringLabelRule(); if (rule.getUuid() != null) { answer.setID(rule.getUuid().getValue()); } if (rule.getTenantId() != null) { answer.setTenantID(rule.getTenantId()); } if (rule.getMeteringLabelId() != null) { answer.setMeteringLabelRuleLabelID(rule.getMeteringLabelId().getValue()); } if (rule.getDirection() != null) { answer.setMeteringLabelRuleDirection( DIRECTION_MAP.get(rule.getDirection())); } if (rule.getRemoteIpPrefix() != null) { answer.setMeteringLabelRuleRemoteIPPrefix(new String(rule.getRemoteIpPrefix().getValue())); } answer.setMeteringLabelRuleExcluded(rule.isExcluded()); return answer; }
result.setSourceIpPrefix(String.valueOf(mdClassifier.getSourceIpPrefix().getValue()));