本文整理汇总了Java中org.onlab.packet.IpAddress.toIpPrefix方法的典型用法代码示例。如果您正苦于以下问题:Java IpAddress.toIpPrefix方法的具体用法?Java IpAddress.toIpPrefix怎么用?Java IpAddress.toIpPrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.onlab.packet.IpAddress
的用法示例。
在下文中一共展示了IpAddress.toIpPrefix方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUpConnectivityHostToHost
import org.onlab.packet.IpAddress; //导入方法依赖的package包/类
@Override
public void setUpConnectivityHostToHost(IpAddress dstIpAddress,
IpAddress srcIpAddress,
MacAddress srcMacAddress,
ConnectPoint srcConnectPoint) {
checkNotNull(dstIpAddress);
checkNotNull(srcIpAddress);
checkNotNull(srcMacAddress);
checkNotNull(srcConnectPoint);
IpPrefix srcIpPrefix = srcIpAddress.toIpPrefix();
IpPrefix dstIpPrefix = dstIpAddress.toIpPrefix();
ConnectPoint dstConnectPoint = null;
MacAddress dstMacAddress = null;
for (Host host : hostService.getHostsByIp(dstIpAddress)) {
if (host.mac() != null) {
dstMacAddress = host.mac();
dstConnectPoint = host.location();
break;
}
}
if (dstMacAddress == null) {
hostService.startMonitoringIp(dstIpAddress);
return;
}
//
// Handle intent from source host to destination host
//
MultiPointToSinglePointIntent srcToDstIntent =
hostToHostIntentGenerator(dstIpAddress, dstConnectPoint,
dstMacAddress, srcConnectPoint);
submitReactiveIntent(dstIpPrefix, srcToDstIntent);
//
// Handle intent from destination host to source host
//
// Since we proactively handle the intent from destination host to
// source host, we should check whether there is an exiting intent
// first.
if (mp2pIntentExists(srcIpPrefix)) {
updateExistingMp2pIntent(srcIpPrefix, dstConnectPoint);
return;
} else {
// There is no existing intent, create a new one.
MultiPointToSinglePointIntent dstToSrcIntent =
hostToHostIntentGenerator(srcIpAddress, srcConnectPoint,
srcMacAddress, dstConnectPoint);
submitReactiveIntent(srcIpPrefix, dstToSrcIntent);
}
}
示例2: hostToHostIntentGenerator
import org.onlab.packet.IpAddress; //导入方法依赖的package包/类
/**
* Generates MultiPointToSinglePointIntent for both source host and
* destination host located in local SDN network.
*
* @param dstIpAddress the destination IP address
* @param dstConnectPoint the destination host connect point
* @param dstMacAddress the MAC address of destination host
* @param srcConnectPoint the connect point where packet-in from
* @return the generated MultiPointToSinglePointIntent
*/
private MultiPointToSinglePointIntent hostToHostIntentGenerator(
IpAddress dstIpAddress,
ConnectPoint dstConnectPoint,
MacAddress dstMacAddress,
ConnectPoint srcConnectPoint) {
checkNotNull(dstIpAddress);
checkNotNull(dstConnectPoint);
checkNotNull(dstMacAddress);
checkNotNull(srcConnectPoint);
Set<ConnectPoint> ingressPoints = new HashSet<>();
ingressPoints.add(srcConnectPoint);
IpPrefix dstIpPrefix = dstIpAddress.toIpPrefix();
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
if (dstIpAddress.isIp4()) {
selector.matchEthType(Ethernet.TYPE_IPV4);
selector.matchIPDst(dstIpPrefix);
} else {
selector.matchEthType(Ethernet.TYPE_IPV6);
selector.matchIPv6Dst(dstIpPrefix);
}
// Rewrite the destination MAC address
TrafficTreatment.Builder treatment =
DefaultTrafficTreatment.builder().setEthDst(dstMacAddress);
Key key = Key.of(dstIpPrefix.toString(), appId);
int priority = dstIpPrefix.prefixLength() * PRIORITY_MULTIPLIER
+ PRIORITY_OFFSET;
MultiPointToSinglePointIntent intent =
MultiPointToSinglePointIntent.builder()
.appId(appId)
.key(key)
.selector(selector.build())
.treatment(treatment.build())
.ingressPoints(ingressPoints)
.egressPoint(dstConnectPoint)
.priority(priority)
.constraints(CONSTRAINTS)
.build();
log.trace("Generates ConnectivityHostToHost = {} ", intent);
return intent;
}