use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.
the class ReactiveRoutingFib method setUpConnectivityHostToInternet.
@Override
public void setUpConnectivityHostToInternet(IpAddress hostIp, IpPrefix prefix, IpAddress nextHopIpAddress) {
// Find the attachment point (egress interface) of the next hop
Interface egressInterface = interfaceService.getMatchingInterface(nextHopIpAddress);
if (egressInterface == null) {
log.warn("No outgoing interface found for {}", nextHopIpAddress);
return;
}
Set<Host> hosts = hostService.getHostsByIp(nextHopIpAddress);
if (hosts.isEmpty()) {
log.warn("No host found for next hop IP address");
return;
}
MacAddress nextHopMacAddress = null;
for (Host host : hosts) {
nextHopMacAddress = host.mac();
break;
}
hosts = hostService.getHostsByIp(hostIp);
if (hosts.isEmpty()) {
log.warn("No host found for host IP address");
return;
}
Host host = hosts.stream().findFirst().get();
ConnectPoint ingressPoint = host.location();
// Generate the intent itself
ConnectPoint egressPort = egressInterface.connectPoint();
log.debug("Generating intent for prefix {}, next hop mac {}", prefix, nextHopMacAddress);
// Match the destination IP prefix at the first hop
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
if (prefix.isIp4()) {
selector.matchEthType(Ethernet.TYPE_IPV4);
selector.matchIPDst(prefix);
} else {
selector.matchEthType(Ethernet.TYPE_IPV6);
selector.matchIPv6Dst(prefix);
}
// Rewrite the destination MAC address
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setEthDst(nextHopMacAddress);
if (!egressInterface.vlan().equals(VlanId.NONE)) {
treatment.setVlanId(egressInterface.vlan());
// If we set VLAN ID, we have to make sure a VLAN tag exists.
// TODO support no VLAN -> VLAN routing
selector.matchVlanId(VlanId.ANY);
}
int priority = prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
Key key = Key.of(prefix.toString() + "-reactive", appId);
MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder().appId(appId).key(key).selector(selector.build()).treatment(treatment.build()).filteredIngressPoints(Collections.singleton(new FilteredConnectPoint(ingressPoint))).filteredEgressPoint(new FilteredConnectPoint(egressPort)).priority(priority).constraints(CONSTRAINTS).build();
submitReactiveIntent(prefix, intent);
}
use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.
the class VirtualHostCreateCommand method doExecute.
@Override
protected void doExecute() {
VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class);
Set<IpAddress> hostIps = new HashSet<>();
if (hostIpStrings != null) {
Arrays.stream(hostIpStrings).forEach(s -> hostIps.add(IpAddress.valueOf(s)));
}
HostLocation hostLocation = new HostLocation(DeviceId.deviceId(hostLocationDeviceId), PortNumber.portNumber(hostLocationPortNumber), System.currentTimeMillis());
MacAddress macAddress = MacAddress.valueOf(mac);
VlanId vlanId = VlanId.vlanId(vlan);
service.createVirtualHost(NetworkId.networkId(networkId), HostId.hostId(macAddress, vlanId), macAddress, vlanId, hostLocation, hostIps);
print("Virtual host successfully created.");
}
use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.
the class VirtualHostCodecTest method testEncode.
@Test
public void testEncode() {
MockCodecContext context = new MockCodecContext();
NetworkId networkId = NetworkId.networkId(TEST_NETWORK_ID);
HostId id = NetTestTools.hid(TEST_HOST_ID);
MacAddress mac = MacAddress.valueOf(TEST_MAC_ADDRESS);
VlanId vlan = VlanId.vlanId(TEST_VLAN_ID);
HostLocation location = new HostLocation(CONNECT_POINT, 0L);
Set<IpAddress> ips = ImmutableSet.of(IpAddress.valueOf(TEST_IP1), IpAddress.valueOf(TEST_IP2));
VirtualHost host = new DefaultVirtualHost(networkId, id, mac, vlan, location, ips);
JsonCodec<VirtualHost> codec = context.codec(VirtualHost.class);
ObjectNode node = codec.encode(host, context);
assertThat(node.get(VirtualHostCodec.NETWORK_ID).asLong(), is(TEST_NETWORK_ID));
assertThat(node.get(VirtualHostCodec.HOST_ID).asText(), is(TEST_HOST_ID));
assertThat(node.get(VirtualHostCodec.MAC_ADDRESS).asText(), is(TEST_MAC_ADDRESS));
assertThat(node.get(VirtualHostCodec.VLAN).asInt(), is((int) TEST_VLAN_ID));
assertThat(node.get(VirtualHostCodec.HOST_LOCATION).get(0).get("elementId").asText(), is(location.deviceId().toString()));
assertThat(node.get(VirtualHostCodec.HOST_LOCATION).get(0).get("port").asLong(), is(location.port().toLong()));
JsonNode jsonIps = node.get(VirtualHostCodec.IP_ADDRESSES);
assertThat(jsonIps, notNullValue());
assertThat(jsonIps.isArray(), is(true));
assertThat(jsonIps.size(), is(ips.size()));
IntStream.of(0, 1).forEach(index -> assertThat(jsonIps.get(index).asText(), isOneOf(TEST_IP1, TEST_IP2)));
}
use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.
the class VbngManager method statusRecovery.
/**
* Recovers from XOS record. Re-sets up the mapping between private IP
* address and public IP address, re-calculates intents and re-installs
* those intents.
*/
private void statusRecovery() {
log.info("vBNG starts to recover from XOS record......");
ObjectNode map;
try {
RestClient restClient = new RestClient(vbngConfigurationService.getXosIpAddress(), vbngConfigurationService.getXosRestPort());
map = restClient.getRest();
} catch (Exception e) {
log.warn("Could not contact XOS {}", e.getMessage());
return;
}
if (map == null) {
log.info("Stop to recover vBNG status due to the vBNG map " + "is null!");
return;
}
log.info("Get record from XOS: {}", map);
ArrayNode array = (ArrayNode) map.get(VBNG_MAP_NAME);
Iterator<JsonNode> entries = array.elements();
while (entries.hasNext()) {
ObjectNode entry = (ObjectNode) entries.next();
IpAddress hostIpAdddress = IpAddress.valueOf(entry.get("private_ip").asText());
IpAddress publicIpAddress = IpAddress.valueOf(entry.get("routeable_subnet").asText());
MacAddress macAddress = MacAddress.valueOf(entry.get("mac").asText());
String hostName = entry.get("hostname").asText();
// Create vBNG
createVbng(hostIpAdddress, publicIpAddress, macAddress, hostName);
}
}
use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.
the class NetworkConfigHostProvider method readInitialConfig.
private void readInitialConfig() {
networkConfigRegistry.getSubjects(HostId.class).forEach(hostId -> {
MacAddress mac = hostId.mac();
VlanId vlan = hostId.vlanId();
BasicHostConfig hostConfig = networkConfigRegistry.getConfig(hostId, BasicHostConfig.class);
Set<IpAddress> ipAddresses = hostConfig.ipAddresses();
Set<HostLocation> locs = hostConfig.locations();
if (locs != null) {
Set<HostLocation> locations = locs.stream().map(hostLocation -> new HostLocation(hostLocation, System.currentTimeMillis())).collect(Collectors.toSet());
// auxLocations allows to be null
Set<HostLocation> auxLocations = hostConfig.auxLocations();
if (auxLocations != null) {
auxLocations = auxLocations.stream().map(auxLocation -> new HostLocation(auxLocation, System.currentTimeMillis())).collect(Collectors.toSet());
}
VlanId innerVlan = hostConfig.innerVlan();
EthType outerTpid = hostConfig.outerTpid();
addHost(mac, vlan, locations, auxLocations, ipAddresses, innerVlan, outerTpid);
} else {
log.warn("Host {} configuration {} is missing locations", hostId, hostConfig);
}
});
}
Aggregations