private int getPriorityFromPrefix(IpPrefix prefix) { return (prefix.isIp4()) ? 2000 * prefix.prefixLength() + MIN_IP_PRIORITY : 500 * prefix.prefixLength() + MIN_IP_PRIORITY; }
/** * Set the encoded source address. * * @param pfx address prefix */ public void setAddr(IpPrefix pfx) { this.addr = pfx.address(); this.masklen = (byte) pfx.prefixLength(); this.family = (byte) ((this.addr.isIp4()) ? PIM.ADDRESS_FAMILY_IP4 : PIM.ADDRESS_FAMILY_IP6); }
/** * PIM Encoded Source Address. * * @param spfx IPv4 or IPv6 address prefix */ public void setAddr(IpPrefix spfx) { this.addr = spfx.address(); this.masklen = (byte) spfx.prefixLength(); this.family = (byte) ((this.addr.isIp4()) ? PIM.ADDRESS_FAMILY_IP4 : PIM.ADDRESS_FAMILY_IP6); }
@Override public int compareTo(Object o) { if (this.equals(o)) { return 0; } if (o instanceof BgpFsDestinationPrefix) { BgpFsDestinationPrefix that = (BgpFsDestinationPrefix) o; if (this.ipPrefix().prefixLength() == that.ipPrefix().prefixLength()) { ByteBuffer value1 = ByteBuffer.wrap(this.ipPrefix.address().toOctets()); ByteBuffer value2 = ByteBuffer.wrap(that.ipPrefix.address().toOctets()); return value1.compareTo(value2); } if (this.ipPrefix().prefixLength() > that.ipPrefix().prefixLength()) { return 1; } else if (this.ipPrefix().prefixLength() < that.ipPrefix().prefixLength()) { return -1; } } return 1; }
@Override public int compareTo(Object o) { if (this.equals(o)) { return 0; } if (o instanceof BgpFsSourcePrefix) { BgpFsSourcePrefix that = (BgpFsSourcePrefix) o; if (this.ipPrefix().prefixLength() == that.ipPrefix().prefixLength()) { ByteBuffer value1 = ByteBuffer.wrap(this.ipPrefix.address().toOctets()); ByteBuffer value2 = ByteBuffer.wrap(that.ipPrefix.address().toOctets()); return value1.compareTo(value2); } if (this.ipPrefix().prefixLength() > that.ipPrefix().prefixLength()) { return 1; } else if (this.ipPrefix().prefixLength() < that.ipPrefix().prefixLength()) { return -1; } } return 1; }
@Override public void write(Kryo kryo, Output output, IpPrefix object) { byte[] octs = object.address().toOctets(); output.writeInt(octs.length); output.writeBytes(octs); output.writeInt(object.prefixLength()); }
private void registerDhcpInfo(OpenstackPort openstackPort) { checkNotNull(openstackPort); checkArgument(!openstackPort.fixedIps().isEmpty()); OpenstackSubnet openstackSubnet = openstackService.subnets().stream() .filter(n -> n.networkId().equals(openstackPort.networkId())) .findFirst().orElse(null); if (openstackSubnet == null) { log.warn("Failed to find subnet for {}", openstackPort); return; } Ip4Address ipAddress = openstackPort.fixedIps().values().stream().findFirst().get(); IpPrefix subnetPrefix = IpPrefix.valueOf(openstackSubnet.cidr()); Ip4Address broadcast = Ip4Address.makeMaskedAddress( ipAddress, subnetPrefix.prefixLength()); // TODO: supports multiple DNS servers Ip4Address domainServer = openstackSubnet.dnsNameservers().isEmpty() ? DNS_SERVER_IP : openstackSubnet.dnsNameservers().get(0); IpAssignment ipAssignment = IpAssignment.builder() .ipAddress(ipAddress) .leasePeriod(DHCP_INFINITE_LEASE) .timestamp(new Date()) .subnetMask(Ip4Address.makeMaskPrefix(subnetPrefix.prefixLength())) .broadcast(broadcast) .domainServer(domainServer) .assignmentStatus(Option_RangeNotEnforced) .routerAddress(Ip4Address.valueOf(openstackSubnet.gatewayIp())) .build(); dhcpService.setStaticMapping(openstackPort.macAddress(), ipAssignment); }
@Override public void init(Criterion criterion, int bitWidth) throws ByteSequenceTrimException { IPCriterion c = (IPCriterion) criterion; initAsLpm(copyFrom(c.ip().address().toOctets()), c.ip().prefixLength(), bitWidth); } }
/** * Reads the channel buffer and returns object of IPv4AddressTlv. * * @param cb channelBuffer * @return object of flow spec source prefix * @throws BgpParseException while parsing BgpFsSourcePrefix */ public static BgpFsSourcePrefix read(ChannelBuffer cb) throws BgpParseException { IpPrefix ipPrefix; int length = cb.readByte(); if (length == 0) { byte[] prefix = new byte[]{0}; ipPrefix = Validation.bytesToPrefix(prefix, length); return new BgpFsSourcePrefix((byte) ipPrefix.prefixLength(), ipPrefix); } int len = length / BYTE_IN_BITS; int reminder = length % BYTE_IN_BITS; if (reminder > 0) { len = len + 1; } if (cb.readableBytes() < len) { Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.MALFORMED_ATTRIBUTE_LIST, cb.readableBytes()); } byte[] prefix = new byte[len]; cb.readBytes(prefix, 0, len); ipPrefix = Validation.bytesToPrefix(prefix, length); return new BgpFsSourcePrefix((byte) ipPrefix.prefixLength(), ipPrefix); }
/** * Reads the channel buffer and returns object of IPv4AddressTlv. * * @param cb channelBuffer * @return object of flow spec destination prefix * @throws BgpParseException while parsing BgpFsDestinationPrefix */ public static BgpFsDestinationPrefix read(ChannelBuffer cb) throws BgpParseException { IpPrefix ipPrefix; int length = cb.readByte(); if (length == 0) { byte[] prefix = new byte[] {0}; ipPrefix = Validation.bytesToPrefix(prefix, length); return new BgpFsDestinationPrefix((byte) ipPrefix.prefixLength(), ipPrefix); } int len = length / BYTE_IN_BITS; int reminder = length % BYTE_IN_BITS; if (reminder > 0) { len = len + 1; } if (cb.readableBytes() < len) { Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.MALFORMED_ATTRIBUTE_LIST, cb.readableBytes()); } byte[] prefix = new byte[len]; cb.readBytes(prefix, 0, len); ipPrefix = Validation.bytesToPrefix(prefix, length); return new BgpFsDestinationPrefix((byte) ipPrefix.prefixLength(), ipPrefix); }
if (prefix.prefixLength() != 0) { selector.matchIPDst(prefix); if (prefix.prefixLength() != 0) { selector.matchIPv6Dst(prefix); prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
return; int mask = ipPrefix.prefixLength(); if (mask <= 0) { return;
.matchEthType(Ethernet.TYPE_IPV4); if (ipPrefix.prefixLength() != 0) { filteredSelector.matchIPDst(ipPrefix);
private ForwardingObjective.Builder generateRibForwardingObj(IpPrefix prefix, Integer nextId) { TrafficSelector selector = DefaultTrafficSelector.builder() .matchEthType(Ethernet.TYPE_IPV4) .matchIPDst(prefix) .build(); int priority = prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET; ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder() .fromApp(routerAppId) .makePermanent() .withSelector(selector) .withPriority(priority) .withFlag(ForwardingObjective.Flag.SPECIFIC); if (nextId == null) { // Route withdraws are not specified with next hops. Generating // dummy treatment as there is no equivalent nextId info. fwdBuilder.withTreatment(DefaultTrafficTreatment.builder().build()); } else { fwdBuilder.nextStep(nextId); } return fwdBuilder; }
if ((flowClassifier.srcIpPrefix() != null) && (flowClassifier.srcIpPrefix().prefixLength() != 0)) { selector.matchIPSrc(flowClassifier.srcIpPrefix()); } else if (fiveTuple != null && fiveTuple.ipSrc() != null) { if ((flowClassifier.dstIpPrefix() != null) && (flowClassifier.dstIpPrefix().prefixLength() != 0)) { selector.matchIPDst(flowClassifier.dstIpPrefix()); } else if (fiveTuple != null && fiveTuple.ipDst() != null) {
IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip(); if (ipv4Dst.isMulticast()) { if (ipv4Dst.prefixLength() != 32) { log.warn("Multicast specific forwarding objective can only be /32"); fail(fwd, ObjectiveError.BADPARAMS); + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); } else { if (ipv4Dst.prefixLength() > 0) { filteredSelector.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst); } else {
IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip(); if (ipv4Dst.isMulticast()) { if (ipv4Dst.prefixLength() != 32) { log.warn("Multicast specific forwarding objective can only be /32"); fail(fwd, ObjectiveError.BADPARAMS); + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); } else { if (ipv4Dst.prefixLength() > 0) { filteredSelector.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst); } else {
@Override public void programSnatSameSegmentUploadControllerRules(DeviceId deviceId, SegmentationId matchVni, IpAddress srcIP, IpAddress dstIP, IpPrefix prefix, Operation type) { TrafficSelector selector = DefaultTrafficSelector.builder() .matchEthType(Ethernet.TYPE_IPV4) .matchTunnelId(Long.parseLong(matchVni.segmentationId())) .matchIPSrc(IpPrefix.valueOf(srcIP, PREFIC_LENGTH)) .matchIPDst(IpPrefix.valueOf(dstIP, prefix.prefixLength())) .build(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.add(Instructions.createOutput(PortNumber.CONTROLLER)); ForwardingObjective.Builder objective = DefaultForwardingObjective .builder().withTreatment(treatment.build()) .withSelector(selector).fromApp(appId).withFlag(Flag.SPECIFIC) .withPriority(SNAT_SAME_SEG_CON_PRIORITY); if (type.equals(Objective.Operation.ADD)) { flowObjectiveService.forward(deviceId, objective.add()); } else { flowObjectiveService.forward(deviceId, objective.remove()); } }
return false; int mask = ipPrefix.prefixLength(); if (mask <= 0) { return false;