use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class MappingAddressesTest method testIpv4MappingAddressMethod.
/**
* Tests the ipv4MappingAddress method.
*/
@Test
public void testIpv4MappingAddressMethod() {
IpPrefix ip = IpPrefix.valueOf("1.2.3.4/24");
MappingAddress mappingAddress = MappingAddresses.ipv4MappingAddress(ip);
IPMappingAddress ipMappingAddress = checkAndConvert(mappingAddress, MappingAddress.Type.IPV4, IPMappingAddress.class);
assertThat(ipMappingAddress.ip(), is(equalTo(ip)));
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class DistributedMappingStoreTest method setUp.
/**
* Sets up the storage service test harness.
*/
@Before
public void setUp() {
mappingStore = new DistributedMappingStore();
mappingStore.storageService = new TestStorageService();
mappingStore.deviceService = new InternalDeviceServiceAdapter();
mappingStore.setDelegate(event -> {
});
IpPrefix ipPrefix = IpPrefix.valueOf(IP_ADDRESS);
MappingAddress address = MappingAddresses.ipv4MappingAddress(ipPrefix);
MappingKey key = DefaultMappingKey.builder().withAddress(address).build();
MappingAction action = MappingActions.noAction();
MappingTreatment treatment = DefaultMappingTreatment.builder().withAddress(address).setUnicastPriority(10).setUnicastWeight(10).build();
MappingValue value = DefaultMappingValue.builder().withAction(action).add(treatment).build();
device1 = new MockDevice(ProviderId.NONE, DEVICE_ID_1, Device.Type.OTHER, "foo.inc", "0", "0", "0", null, DefaultAnnotations.builder().build());
device2 = new MockDevice(ProviderId.NONE, DEVICE_ID_2, Device.Type.OTHER, "foo.inc", "0", "0", "0", null, DefaultAnnotations.builder().build());
Mapping originalMapping1 = DefaultMapping.builder().forDevice(DEVICE_ID_1).withId(1000L).withKey(key).withValue(value).build();
Mapping originalMapping2 = DefaultMapping.builder().forDevice(DEVICE_ID_2).withId(2000L).withKey(key).withValue(value).build();
mapping1 = new DefaultMappingEntry(originalMapping1);
mapping2 = new DefaultMappingEntry(originalMapping2);
mappingStore.activate();
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class OpenstackK8sIntegrationWebResource method installCniPtNodeRules.
/**
* Installs CNI pass-through related flow rules for each kubernetes nodes.
*
* @param input JSON string
* @return 200 ok, 400 BAD_REQUEST if the json is malformed
* @throws IOException exception
*/
@PUT
@Path("node/pt-install")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response installCniPtNodeRules(InputStream input) throws IOException {
log.trace("Install K8S CNI pass-through node rules");
JsonNode json = readTreeFromStream(mapper().enable(INDENT_OUTPUT), input);
IpAddress k8sNodeIp = IpAddress.valueOf(json.get(K8S_NODE_IP).asText());
IpPrefix podCidr = IpPrefix.valueOf(json.get(POD_CIDR).asText());
IpPrefix serviceCidr = IpPrefix.valueOf(json.get(SERVICE_CIDR).asText());
IpAddress podGwIp = IpAddress.valueOf(json.get(POD_GW_IP).asText());
String osK8sIntPortName = json.get(OS_K8S_INT_PORT_NAME).asText();
MacAddress k8sIntOsPortMac = MacAddress.valueOf(json.get(K8S_INT_OS_PORT_MAC).asText());
intService.installCniPtNodeRules(k8sNodeIp, podCidr, serviceCidr, podGwIp, osK8sIntPortName, k8sIntOsPortMac);
return Response.ok().build();
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class OpenstackK8sIntegrationWebResource method uninstallCniPtNodeRules.
/**
* Uninstalls CNI pass-through related flow rules for each kubernetes nodes.
*
* @param input JSON string
* @return 200 ok, 400 BAD_REQUEST if the json is malformed
* @throws IOException exception
*/
@PUT
@Path("node/pt-uninstall")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response uninstallCniPtNodeRules(InputStream input) throws IOException {
log.trace("Uninstall K8S CNI pass-through node rules");
JsonNode json = readTreeFromStream(mapper().enable(INDENT_OUTPUT), input);
IpAddress k8sNodeIp = IpAddress.valueOf(json.get(K8S_NODE_IP).asText());
IpPrefix podCidr = IpPrefix.valueOf(json.get(POD_CIDR).asText());
IpPrefix serviceCidr = IpPrefix.valueOf(json.get(SERVICE_CIDR).asText());
IpAddress podGwIp = IpAddress.valueOf(json.get(POD_GW_IP).asText());
String osK8sIntPortName = json.get(OS_K8S_INT_PORT_NAME).asText();
MacAddress k8sIntOsPortMac = MacAddress.valueOf(json.get(K8S_INT_OS_PORT_MAC).asText());
intService.uninstallCniPtNodeRules(k8sNodeIp, podCidr, serviceCidr, podGwIp, osK8sIntPortName, k8sIntOsPortMac);
return Response.ok().build();
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class OpenstackSwitchingDhcpHandlerTest method constructDhcpPacket.
/**
* Constructs an Ethernet packet containing a DHCP payload.
*
* @param msgType DHCP message type
* @return Ethernet packet
*/
private Ethernet constructDhcpPacket(DHCP.MsgType msgType) {
// Ethernet frame
Ethernet ethFrame = new Ethernet();
ethFrame.setSourceMACAddress(CLIENT_HOST.mac());
ethFrame.setDestinationMACAddress(MacAddress.BROADCAST);
ethFrame.setEtherType(Ethernet.TYPE_IPV4);
ethFrame.setVlanID((short) 2);
// IP packet
IPv4 ipv4Pkt = new IPv4();
ipv4Pkt.setSourceAddress(0);
ipv4Pkt.setDestinationAddress(BROADCAST.toInt());
ipv4Pkt.setTtl((byte) 127);
// UDP datagram
UDP udpDatagram = new UDP();
udpDatagram.setSourcePort((byte) UDP.DHCP_CLIENT_PORT);
udpDatagram.setDestinationPort((byte) UDP.DHCP_SERVER_PORT);
// DHCP payload
DHCP dhcp = new DHCP();
dhcp.setOpCode(DHCP.OPCODE_REQUEST);
dhcp.setYourIPAddress(0);
dhcp.setServerIPAddress(0);
dhcp.setTransactionId(TRANSACTION_ID);
dhcp.setClientHardwareAddress(CLIENT_HOST.mac().toBytes());
dhcp.setHardwareType(DHCP.HWTYPE_ETHERNET);
dhcp.setHardwareAddressLength((byte) 6);
// DHCP options start...
DhcpOption option = new DhcpOption();
List<DhcpOption> optionList = new ArrayList<>();
// DHCP message type
option.setCode(OptionCode_MessageType.getValue());
option.setLength((byte) 1);
byte[] optionData = { (byte) msgType.getValue() };
option.setData(optionData);
optionList.add(option);
// DHCP requested IP address
option = new DhcpOption();
option.setCode(OptionCode_RequestedIP.getValue());
option.setLength((byte) 4);
optionData = Ip4Address.valueOf(EXPECTED_IP).toOctets();
option.setData(optionData);
optionList.add(option);
// DHCP domain server
Subnet subnet = dhcpHandler.osNetworkService.subnet("subnet");
option = new DhcpOption();
option.setCode(OptionCode_DomainServer.getValue());
option.setLength((byte) 8);
ByteBuffer dnsByteBuf = ByteBuffer.allocate(8);
dnsByteBuf.put(DEFAULT_PRIMARY_DNS.toOctets());
dnsByteBuf.put(DEFAULT_SECONDARY_DNS.toOctets());
option.setData(dnsByteBuf.array());
optionList.add(option);
// MTU
option = new DhcpOption();
option.setCode(DHCP_OPTION_MTU);
option.setLength((byte) 2);
option.setData(ByteBuffer.allocate(2).putShort(MTU).array());
optionList.add(option);
// classless static route
option = new DhcpOption();
option.setCode(OptionCode_Classless_Static_Route.getValue());
option.setLength((byte) HOST_ROUTES_SIZE);
ByteBuffer hostRouteByteBuf = ByteBuffer.allocate(HOST_ROUTES_SIZE);
subnet.getHostRoutes().forEach(h -> {
IpPrefix ipPrefix = IpPrefix.valueOf(h.getDestination());
hostRouteByteBuf.put(bytesDestinationDescriptor(ipPrefix));
hostRouteByteBuf.put(Ip4Address.valueOf(h.getNexthop()).toOctets());
});
option.setData(hostRouteByteBuf.array());
optionList.add(option);
// default router address setup
option = new DhcpOption();
option.setCode(OptionCode_RouterAddress.getValue());
option.setLength((byte) 4);
option.setData(Ip4Address.valueOf(subnet.getGateway()).toOctets());
optionList.add(option);
// DHCP options end...
option = new DhcpOption();
option.setCode(OptionCode_END.getValue());
option.setLength((byte) 1);
optionList.add(option);
dhcp.setOptions(optionList);
udpDatagram.setPayload(dhcp);
ipv4Pkt.setPayload(udpDatagram);
ethFrame.setPayload(ipv4Pkt);
return ethFrame;
}
Aggregations