use of org.onosproject.simplefabric.api.FabricNetwork in project onos by opennetworkinglab.
the class SimpleFabricRouting method refreshIntercepts.
/**
* Refresh device flow rules for intercepts on local fabricSubnets.
*/
private void refreshIntercepts() {
Set<FlowRule> newInterceptFlowRules = new HashSet<>();
for (Device device : deviceService.getAvailableDevices()) {
for (FabricSubnet subnet : simpleFabric.defaultFabricSubnets()) {
newInterceptFlowRules.add(generateInterceptFlowRule(true, device.id(), subnet.prefix()));
// check if this devices has the fabricSubnet, then add ip broadcast flue rule
FabricNetwork fabricNetwork = simpleFabric.fabricNetwork(subnet.networkName());
if (fabricNetwork != null && fabricNetwork.contains(device.id())) {
newInterceptFlowRules.add(generateLocalSubnetIpBctFlowRule(device.id(), subnet.prefix(), fabricNetwork));
}
// JUST FOR FLOW RULE TEST ONLY
// newInterceptFlowRules.add(generateTestFlowRule(device.id(), subnet.ipPrefix()));
}
for (FabricRoute route : simpleFabric.fabricRoutes()) {
newInterceptFlowRules.add(generateInterceptFlowRule(false, device.id(), route.prefix()));
}
}
if (!newInterceptFlowRules.equals(interceptFlowRules)) {
// NOTE: DO NOT REMOVE INTERCEPT FLOW RULES FOR FAILED DEVICE FLOW UPDATE MIGHT BE BLOCKED
/*
interceptFlowRules.stream()
.filter(rule -> !newInterceptFlowRules.contains(rule))
.forEach(rule -> {
flowRuleService.removeFlowRules(rule);
log.info("simple fabric reactive routing remove intercept flow rule: {}", rule);
});
*/
newInterceptFlowRules.stream().filter(rule -> !interceptFlowRules.contains(rule)).forEach(rule -> {
flowRuleService.applyFlowRules(rule);
log.info("simple fabric routing apply intercept flow rule: {}", rule);
});
interceptFlowRules = newInterceptFlowRules;
}
}
use of org.onosproject.simplefabric.api.FabricNetwork in project onos by opennetworkinglab.
the class DefaultFabricNetworkTest method testConstruction.
/**
* Test object construction.
*/
@Test
public void testConstruction() {
FabricNetwork network = fabricNetwork1;
assertEquals(network.name(), NAME_1);
assertEquals(network.interfaceNames(), INTF_NAME_SET_1);
assertEquals(network.encapsulation(), ENCAP_TYPE_1);
assertEquals(network.isForward(), IS_FORWARD_1);
assertEquals(network.isBroadcast(), IS_BROADCAST_1);
}
use of org.onosproject.simplefabric.api.FabricNetwork in project onos by opennetworkinglab.
the class SimpleFabricManager method refresh.
// Set up from configuration
// returns found isDirty and refresh listeners are called (true) or not (false)
private boolean refresh() {
log.debug("simple fabric refresh");
boolean dirty = false;
SimpleFabricConfig config = configService.getConfig(coreService.registerApplication(APP_ID), SimpleFabricConfig.class);
if (config == null) {
log.debug("No simple fabric config available!");
return false;
}
// fabricNetworks
Set<FabricNetwork> newFabricNetworks = new HashSet<>();
Set<Interface> newInterfaces = new HashSet<>();
for (FabricNetwork newFabricNetworkConfig : config.fabricNetworks()) {
FabricNetwork newFabricNetwork = DefaultFabricNetwork.of(newFabricNetworkConfig);
// fill up interfaces and Hosts with active port only
for (String ifaceName : newFabricNetworkConfig.interfaceNames()) {
Interface iface = getInterfaceByName(ifaceName);
if (iface != null && deviceService.isAvailable(iface.connectPoint().deviceId())) {
newFabricNetwork.addInterface(iface);
newInterfaces.add(iface);
}
}
for (Host host : hostService.getHosts()) {
// consider host with ip only
if (!host.ipAddresses().isEmpty()) {
Interface iface = findAvailableDeviceHostInterface(host);
if (iface != null && newFabricNetwork.contains(iface)) {
newFabricNetwork.addHost(host);
}
}
}
newFabricNetwork.setDirty(true);
// update newFabricNetwork's isDirty flags if same entry already exists
for (FabricNetwork prevFabricNetwork : fabricNetworks) {
if (prevFabricNetwork.equals(newFabricNetwork)) {
newFabricNetwork.setDirty(prevFabricNetwork.isDirty());
break;
}
}
newFabricNetworks.add(newFabricNetwork);
}
if (!fabricNetworks.equals(newFabricNetworks)) {
fabricNetworks = newFabricNetworks;
dirty = true;
}
if (!networkInterfaces.equals(newInterfaces)) {
networkInterfaces = newInterfaces;
dirty = true;
}
// default Fabric Subnets
Set<FabricSubnet> newFabricSubnets = config.fabricSubnets();
InvertedRadixTree<FabricSubnet> newIp4SubnetTable = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
InvertedRadixTree<FabricSubnet> newIp6SubnetTable = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
Map<IpAddress, MacAddress> newVirtualGatewayIpMacMap = Maps.newConcurrentMap();
for (FabricSubnet subnet : newFabricSubnets) {
if (subnet.prefix().isIp4()) {
newIp4SubnetTable.put(createBinaryString(subnet.prefix()), subnet);
} else {
newIp6SubnetTable.put(createBinaryString(subnet.prefix()), subnet);
}
newVirtualGatewayIpMacMap.put(subnet.gatewayIp(), subnet.gatewayMac());
}
if (!fabricSubnets.equals(newFabricSubnets)) {
fabricSubnets = newFabricSubnets;
ip4SubnetTable = newIp4SubnetTable;
ip6SubnetTable = newIp6SubnetTable;
dirty = true;
}
if (!virtualGatewayIpMacMap.equals(newVirtualGatewayIpMacMap)) {
virtualGatewayIpMacMap = newVirtualGatewayIpMacMap;
dirty = true;
}
// fabricRoutes config handling
Set<FabricRoute> newFabricRoutes = config.fabricRoutes();
if (!fabricRoutes.equals(newFabricRoutes)) {
InvertedRadixTree<FabricRoute> newIp4BorderRouteTable = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
InvertedRadixTree<FabricRoute> newIp6BorderRouteTable = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
for (FabricRoute route : newFabricRoutes) {
if (route.prefix().isIp4()) {
newIp4BorderRouteTable.put(createBinaryString(route.prefix()), route);
} else {
newIp6BorderRouteTable.put(createBinaryString(route.prefix()), route);
}
}
fabricRoutes = newFabricRoutes;
ip4BorderRouteTable = newIp4BorderRouteTable;
ip6BorderRouteTable = newIp6BorderRouteTable;
dirty = true;
}
// notify to SimpleFabric listeners
if (dirty) {
log.info("simple fabric refresh; notify events");
process(new SimpleFabricEvent(SimpleFabricEvent.Type.SIMPLE_FABRIC_UPDATED, "updated"));
}
return dirty;
}
use of org.onosproject.simplefabric.api.FabricNetwork in project onos by opennetworkinglab.
the class SimpleFabricManager method requestMac.
@Override
public boolean requestMac(IpAddress ip) {
FabricSubnet fabricSubnet = fabricSubnet(ip);
if (fabricSubnet == null) {
log.warn("simple fabric request mac failed for unknown fabricSubnet: {}", ip);
return false;
}
FabricNetwork fabricNetwork = fabricNetwork(fabricSubnet.networkName());
if (fabricNetwork == null) {
log.warn("simple fabric request mac failed for unknown fabricNetwork name {}: {}", fabricSubnet.networkName(), ip);
return false;
}
log.debug("simple fabric send request mac fabricNetwork {}: {}", fabricNetwork.name(), ip);
for (Interface iface : fabricNetwork.interfaces()) {
Ethernet neighbourReq;
if (ip.isIp4()) {
neighbourReq = ARP.buildArpRequest(fabricSubnet.gatewayMac().toBytes(), fabricSubnet.gatewayIp().toOctets(), ip.toOctets(), iface.vlan().toShort());
} else {
byte[] soliciteIp = IPv6.getSolicitNodeAddress(ip.toOctets());
neighbourReq = NeighborSolicitation.buildNdpSolicit(ip.getIp6Address(), fabricSubnet.gatewayIp().getIp6Address(), Ip6Address.valueOf(soliciteIp), MacAddress.valueOf(fabricSubnet.gatewayMac().toBytes()), MacAddress.valueOf(IPv6.getMCastMacAddress(soliciteIp)), iface.vlan());
}
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(iface.connectPoint().port()).build();
OutboundPacket packet = new DefaultOutboundPacket(iface.connectPoint().deviceId(), treatment, ByteBuffer.wrap(neighbourReq.serialize()));
packetService.emit(packet);
}
return true;
}
use of org.onosproject.simplefabric.api.FabricNetwork in project onos by opennetworkinglab.
the class SimpleFabricNeighbour method handleReply.
/**
* Handles reply messages between VLAN tagged interfaces.
*
* @param context the message context
* @param hostService the host service
*/
protected void handleReply(NeighbourMessageContext context, HostService hostService) {
// Find target L2 Network, then reply to the host
FabricNetwork fabricNetwork = simpleFabric.fabricNetwork(context.inPort(), context.vlan());
if (fabricNetwork != null) {
// TODO: need to check and update simpleFabric.DefaultFabricNetwork
MacAddress mac = simpleFabric.vMacForIp(context.target());
if (mac != null) {
log.trace("simple fabric neightbour response message to virtual gateway; drop: {} {} target={}", context.inPort(), context.vlan(), context.target());
context.drop();
} else {
// forward reply to the hosts of the dstMac
Set<Host> hosts = hostService.getHostsByMac(context.dstMac());
log.trace("simple fabric neightbour response message forward: {} {} target={} -> {}", context.inPort(), context.vlan(), context.target(), hosts);
hosts.stream().map(host -> simpleFabric.hostInterface(host)).filter(Objects::nonNull).forEach(context::forward);
}
} else {
// this might be happened when we remove an interface from L2 Network
// just ignore this message
log.warn("simple fabric neightbour response message drop for unknown fabricNetwork: {} {}", context.inPort(), context.vlan());
context.drop();
}
}
Aggregations