Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
Showing
15 changed files
with
330 additions
and
166 deletions
| ... | @@ -50,7 +50,10 @@ public class NetworkConfigReader { | ... | @@ -50,7 +50,10 @@ public class NetworkConfigReader { |
| 50 | 50 | ||
| 51 | private final Logger log = getLogger(getClass()); | 51 | private final Logger log = getLogger(getClass()); |
| 52 | 52 | ||
| 53 | - private static final String DEFAULT_CONFIG_FILE = "config/addresses.json"; | 53 | + // Current working dir seems to be /opt/onos/apache-karaf-3.0.2 |
| 54 | + // TODO: Set the path to /opt/onos/config | ||
| 55 | + private static final String CONFIG_DIR = "../config"; | ||
| 56 | + private static final String DEFAULT_CONFIG_FILE = "addresses.json"; | ||
| 54 | private String configFileName = DEFAULT_CONFIG_FILE; | 57 | private String configFileName = DEFAULT_CONFIG_FILE; |
| 55 | 58 | ||
| 56 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 59 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| ... | @@ -60,52 +63,9 @@ public class NetworkConfigReader { | ... | @@ -60,52 +63,9 @@ public class NetworkConfigReader { |
| 60 | protected void activate() { | 63 | protected void activate() { |
| 61 | log.info("Started network config reader"); | 64 | log.info("Started network config reader"); |
| 62 | 65 | ||
| 63 | - log.info("Config file set to {}", configFileName); | ||
| 64 | - | ||
| 65 | AddressConfiguration config = readNetworkConfig(); | 66 | AddressConfiguration config = readNetworkConfig(); |
| 66 | - | ||
| 67 | if (config != null) { | 67 | if (config != null) { |
| 68 | - for (AddressEntry entry : config.getAddresses()) { | 68 | + applyNetworkConfig(config); |
| 69 | - | ||
| 70 | - ConnectPoint cp = new ConnectPoint( | ||
| 71 | - DeviceId.deviceId(dpidToUri(entry.getDpid())), | ||
| 72 | - PortNumber.portNumber(entry.getPortNumber())); | ||
| 73 | - | ||
| 74 | - Set<InterfaceIpAddress> interfaceIpAddresses = new HashSet<>(); | ||
| 75 | - | ||
| 76 | - for (String strIp : entry.getIpAddresses()) { | ||
| 77 | - // Get the IP address and the subnet mask length | ||
| 78 | - try { | ||
| 79 | - String[] splits = strIp.split("/"); | ||
| 80 | - if (splits.length != 2) { | ||
| 81 | - throw new IllegalArgumentException("Invalid IP address and prefix length format"); | ||
| 82 | - } | ||
| 83 | - // NOTE: IpPrefix will mask-out the bits after the prefix length. | ||
| 84 | - IpPrefix subnet = IpPrefix.valueOf(strIp); | ||
| 85 | - IpAddress addr = IpAddress.valueOf(splits[0]); | ||
| 86 | - InterfaceIpAddress ia = | ||
| 87 | - new InterfaceIpAddress(addr, subnet); | ||
| 88 | - interfaceIpAddresses.add(ia); | ||
| 89 | - } catch (IllegalArgumentException e) { | ||
| 90 | - log.warn("Bad format for IP address in config: {}", strIp); | ||
| 91 | - } | ||
| 92 | - } | ||
| 93 | - | ||
| 94 | - MacAddress macAddress = null; | ||
| 95 | - if (entry.getMacAddress() != null) { | ||
| 96 | - try { | ||
| 97 | - macAddress = MacAddress.valueOf(entry.getMacAddress()); | ||
| 98 | - } catch (IllegalArgumentException e) { | ||
| 99 | - log.warn("Bad format for MAC address in config: {}", | ||
| 100 | - entry.getMacAddress()); | ||
| 101 | - } | ||
| 102 | - } | ||
| 103 | - | ||
| 104 | - PortAddresses addresses = new PortAddresses(cp, | ||
| 105 | - interfaceIpAddresses, macAddress); | ||
| 106 | - | ||
| 107 | - hostAdminService.bindAddressesToPort(addresses); | ||
| 108 | - } | ||
| 109 | } | 69 | } |
| 110 | } | 70 | } |
| 111 | 71 | ||
| ... | @@ -114,12 +74,17 @@ public class NetworkConfigReader { | ... | @@ -114,12 +74,17 @@ public class NetworkConfigReader { |
| 114 | log.info("Stopped"); | 74 | log.info("Stopped"); |
| 115 | } | 75 | } |
| 116 | 76 | ||
| 77 | + /** | ||
| 78 | + * Reads the network configuration. | ||
| 79 | + * | ||
| 80 | + * @return the network configuration on success, otherwise null | ||
| 81 | + */ | ||
| 117 | private AddressConfiguration readNetworkConfig() { | 82 | private AddressConfiguration readNetworkConfig() { |
| 118 | - File configFile = new File(configFileName); | 83 | + File configFile = new File(CONFIG_DIR, configFileName); |
| 119 | - | ||
| 120 | ObjectMapper mapper = new ObjectMapper(); | 84 | ObjectMapper mapper = new ObjectMapper(); |
| 121 | 85 | ||
| 122 | try { | 86 | try { |
| 87 | + log.info("Loading config: {}", configFile.getAbsolutePath()); | ||
| 123 | AddressConfiguration config = | 88 | AddressConfiguration config = |
| 124 | mapper.readValue(configFile, AddressConfiguration.class); | 89 | mapper.readValue(configFile, AddressConfiguration.class); |
| 125 | 90 | ||
| ... | @@ -127,12 +92,58 @@ public class NetworkConfigReader { | ... | @@ -127,12 +92,58 @@ public class NetworkConfigReader { |
| 127 | } catch (FileNotFoundException e) { | 92 | } catch (FileNotFoundException e) { |
| 128 | log.warn("Configuration file not found: {}", configFileName); | 93 | log.warn("Configuration file not found: {}", configFileName); |
| 129 | } catch (IOException e) { | 94 | } catch (IOException e) { |
| 130 | - log.error("Unable to read config from file:", e); | 95 | + log.error("Error loading configuration", e); |
| 131 | } | 96 | } |
| 132 | 97 | ||
| 133 | return null; | 98 | return null; |
| 134 | } | 99 | } |
| 135 | 100 | ||
| 101 | + /** | ||
| 102 | + * Applies the network configuration. | ||
| 103 | + * | ||
| 104 | + * @param config the network configuration to apply | ||
| 105 | + */ | ||
| 106 | + private void applyNetworkConfig(AddressConfiguration config) { | ||
| 107 | + for (AddressEntry entry : config.getAddresses()) { | ||
| 108 | + ConnectPoint cp = new ConnectPoint( | ||
| 109 | + DeviceId.deviceId(dpidToUri(entry.getDpid())), | ||
| 110 | + PortNumber.portNumber(entry.getPortNumber())); | ||
| 111 | + | ||
| 112 | + Set<InterfaceIpAddress> interfaceIpAddresses = new HashSet<>(); | ||
| 113 | + for (String strIp : entry.getIpAddresses()) { | ||
| 114 | + // Get the IP address and the subnet mask length | ||
| 115 | + try { | ||
| 116 | + String[] splits = strIp.split("/"); | ||
| 117 | + if (splits.length != 2) { | ||
| 118 | + throw new IllegalArgumentException("Invalid IP address and prefix length format"); | ||
| 119 | + } | ||
| 120 | + // NOTE: IpPrefix will mask-out the bits after the prefix length. | ||
| 121 | + IpPrefix subnet = IpPrefix.valueOf(strIp); | ||
| 122 | + IpAddress addr = IpAddress.valueOf(splits[0]); | ||
| 123 | + InterfaceIpAddress ia = | ||
| 124 | + new InterfaceIpAddress(addr, subnet); | ||
| 125 | + interfaceIpAddresses.add(ia); | ||
| 126 | + } catch (IllegalArgumentException e) { | ||
| 127 | + log.warn("Bad format for IP address in config: {}", strIp); | ||
| 128 | + } | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + MacAddress macAddress = null; | ||
| 132 | + if (entry.getMacAddress() != null) { | ||
| 133 | + try { | ||
| 134 | + macAddress = MacAddress.valueOf(entry.getMacAddress()); | ||
| 135 | + } catch (IllegalArgumentException e) { | ||
| 136 | + log.warn("Bad format for MAC address in config: {}", | ||
| 137 | + entry.getMacAddress()); | ||
| 138 | + } | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + PortAddresses addresses = new PortAddresses(cp, | ||
| 142 | + interfaceIpAddresses, macAddress); | ||
| 143 | + hostAdminService.bindAddressesToPort(addresses); | ||
| 144 | + } | ||
| 145 | + } | ||
| 146 | + | ||
| 136 | private static String dpidToUri(String dpid) { | 147 | private static String dpidToUri(String dpid) { |
| 137 | return "of:" + dpid.replace(":", ""); | 148 | return "of:" + dpid.replace(":", ""); |
| 138 | } | 149 | } | ... | ... |
| 1 | -{ | ||
| 2 | - "interfaces" : [ | ||
| 3 | - { | ||
| 4 | - "dpid" : "00:00:00:00:00:00:01", | ||
| 5 | - "port" : "1", | ||
| 6 | - "ips" : ["192.168.10.101/24"], | ||
| 7 | - "mac" : "00:00:00:11:22:33" | ||
| 8 | - }, | ||
| 9 | - { | ||
| 10 | - "dpid" : "00:00:00:00:00:00:02", | ||
| 11 | - "port" : "1", | ||
| 12 | - "ips" : ["192.168.20.101/24", "192.168.30.101/24"] | ||
| 13 | - }, | ||
| 14 | - { | ||
| 15 | - "dpid" : "00:00:00:00:00:00:03", | ||
| 16 | - "port" : "1", | ||
| 17 | - "ips" : ["10.1.0.1/16"], | ||
| 18 | - "mac" : "00:00:00:00:00:01" | ||
| 19 | - } | ||
| 20 | - ] | ||
| 21 | -} |
| ... | @@ -37,24 +37,31 @@ import com.fasterxml.jackson.databind.ObjectMapper; | ... | @@ -37,24 +37,31 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
| 37 | */ | 37 | */ |
| 38 | public class SdnIpConfigReader implements SdnIpConfigService { | 38 | public class SdnIpConfigReader implements SdnIpConfigService { |
| 39 | 39 | ||
| 40 | - private static final Logger log = LoggerFactory.getLogger(SdnIpConfigReader.class); | 40 | + private final Logger log = LoggerFactory.getLogger(getClass()); |
| 41 | 41 | ||
| 42 | - private static final String DEFAULT_CONFIG_FILE = "config/sdnip.json"; | 42 | + // Current working dir seems to be /opt/onos/apache-karaf-3.0.2 |
| 43 | + // TODO: Set the path to /opt/onos/config | ||
| 44 | + private static final String CONFIG_DIR = "../config"; | ||
| 45 | + private static final String DEFAULT_CONFIG_FILE = "sdnip.json"; | ||
| 43 | private String configFileName = DEFAULT_CONFIG_FILE; | 46 | private String configFileName = DEFAULT_CONFIG_FILE; |
| 47 | + | ||
| 44 | private Map<String, BgpSpeaker> bgpSpeakers = new ConcurrentHashMap<>(); | 48 | private Map<String, BgpSpeaker> bgpSpeakers = new ConcurrentHashMap<>(); |
| 45 | private Map<IpAddress, BgpPeer> bgpPeers = new ConcurrentHashMap<>(); | 49 | private Map<IpAddress, BgpPeer> bgpPeers = new ConcurrentHashMap<>(); |
| 46 | 50 | ||
| 47 | /** | 51 | /** |
| 48 | - * Reads the info contained in the configuration file. | 52 | + * Reads SDN-IP related information contained in the configuration file. |
| 49 | * | 53 | * |
| 50 | - * @param configFilename The name of configuration file for SDN-IP application. | 54 | + * @param configFilename the name of the configuration file for the SDN-IP |
| 55 | + * application | ||
| 51 | */ | 56 | */ |
| 52 | private void readConfiguration(String configFilename) { | 57 | private void readConfiguration(String configFilename) { |
| 53 | - File gatewaysFile = new File(configFilename); | 58 | + File configFile = new File(CONFIG_DIR, configFilename); |
| 54 | ObjectMapper mapper = new ObjectMapper(); | 59 | ObjectMapper mapper = new ObjectMapper(); |
| 55 | 60 | ||
| 56 | try { | 61 | try { |
| 57 | - Configuration config = mapper.readValue(gatewaysFile, Configuration.class); | 62 | + log.info("Loading config: {}", configFile.getAbsolutePath()); |
| 63 | + Configuration config = mapper.readValue(configFile, | ||
| 64 | + Configuration.class); | ||
| 58 | for (BgpSpeaker speaker : config.getBgpSpeakers()) { | 65 | for (BgpSpeaker speaker : config.getBgpSpeakers()) { |
| 59 | bgpSpeakers.put(speaker.name(), speaker); | 66 | bgpSpeakers.put(speaker.name(), speaker); |
| 60 | } | 67 | } |
| ... | @@ -64,13 +71,11 @@ public class SdnIpConfigReader implements SdnIpConfigService { | ... | @@ -64,13 +71,11 @@ public class SdnIpConfigReader implements SdnIpConfigService { |
| 64 | } catch (FileNotFoundException e) { | 71 | } catch (FileNotFoundException e) { |
| 65 | log.warn("Configuration file not found: {}", configFileName); | 72 | log.warn("Configuration file not found: {}", configFileName); |
| 66 | } catch (IOException e) { | 73 | } catch (IOException e) { |
| 67 | - log.error("Error reading JSON file", e); | 74 | + log.error("Error loading configuration", e); |
| 68 | } | 75 | } |
| 69 | } | 76 | } |
| 70 | 77 | ||
| 71 | public void init() { | 78 | public void init() { |
| 72 | - log.debug("Config file set to {}", configFileName); | ||
| 73 | - | ||
| 74 | readConfiguration(configFileName); | 79 | readConfiguration(configFileName); |
| 75 | } | 80 | } |
| 76 | 81 | ... | ... |
| 1 | -ONOS looks for these config files by default in $KARAF_HOME/config/ | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | +The SDN-IP configuration files should be copied to directory | ||
| 2 | + $ONOS_HOME/tools/package/config | ||
| 3 | + | ||
| 4 | +After deployment and starting up the ONOS cluster, ONOS looks for these | ||
| 5 | +configuration files in /opt/onos/config on each cluster member. | ... | ... |
| ... | @@ -28,4 +28,23 @@ public final class AnnotationKeys { | ... | @@ -28,4 +28,23 @@ public final class AnnotationKeys { |
| 28 | * Annotation key for latency. | 28 | * Annotation key for latency. |
| 29 | */ | 29 | */ |
| 30 | public static final String LATENCY = "latency"; | 30 | public static final String LATENCY = "latency"; |
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * Returns the value annotated object for the specified annotation key. | ||
| 34 | + * The annotated value is expected to be String that can be parsed as double. | ||
| 35 | + * If parsing fails, the returned value will be 1.0. | ||
| 36 | + * | ||
| 37 | + * @param annotated annotated object whose annotated value is obtained | ||
| 38 | + * @param key key of annotation | ||
| 39 | + * @return double value of annotated object for the specified key | ||
| 40 | + */ | ||
| 41 | + public static double getAnnotatedValue(Annotated annotated, String key) { | ||
| 42 | + double value; | ||
| 43 | + try { | ||
| 44 | + value = Double.parseDouble(annotated.annotations().value(key)); | ||
| 45 | + } catch (NumberFormatException e) { | ||
| 46 | + value = 1.0; | ||
| 47 | + } | ||
| 48 | + return value; | ||
| 49 | + } | ||
| 31 | } | 50 | } | ... | ... |
| ... | @@ -80,6 +80,7 @@ public class DefaultFlowEntry extends DefaultFlowRule | ... | @@ -80,6 +80,7 @@ public class DefaultFlowEntry extends DefaultFlowRule |
| 80 | this.state = FlowEntryState.FAILED; | 80 | this.state = FlowEntryState.FAILED; |
| 81 | this.errType = errType; | 81 | this.errType = errType; |
| 82 | this.errCode = errCode; | 82 | this.errCode = errCode; |
| 83 | + this.lastSeen = System.currentTimeMillis(); | ||
| 83 | } | 84 | } |
| 84 | 85 | ||
| 85 | @Override | 86 | @Override | ... | ... |
| ... | @@ -21,6 +21,8 @@ import org.onlab.onos.net.resource.LinkResourceService; | ... | @@ -21,6 +21,8 @@ import org.onlab.onos.net.resource.LinkResourceService; |
| 21 | 21 | ||
| 22 | import java.util.Objects; | 22 | import java.util.Objects; |
| 23 | 23 | ||
| 24 | +import static org.onlab.onos.net.AnnotationKeys.getAnnotatedValue; | ||
| 25 | + | ||
| 24 | /** | 26 | /** |
| 25 | * Constraint that evaluates an arbitrary link annotated value is under the specified threshold. | 27 | * Constraint that evaluates an arbitrary link annotated value is under the specified threshold. |
| 26 | */ | 28 | */ |
| ... | @@ -65,25 +67,6 @@ public class AnnotationConstraint extends BooleanConstraint { | ... | @@ -65,25 +67,6 @@ public class AnnotationConstraint extends BooleanConstraint { |
| 65 | return value <= threshold; | 67 | return value <= threshold; |
| 66 | } | 68 | } |
| 67 | 69 | ||
| 68 | - /** | ||
| 69 | - * Returns the annotated value of the specified link. The annotated value | ||
| 70 | - * is expected to be String that can be parsed as double. If parsing fails, | ||
| 71 | - * the returned value will be 1.0. | ||
| 72 | - * | ||
| 73 | - * @param link link whose annotated value is obtained | ||
| 74 | - * @param key key of link annotation | ||
| 75 | - * @return double value of link annotation for the specified key | ||
| 76 | - */ | ||
| 77 | - private double getAnnotatedValue(Link link, String key) { | ||
| 78 | - double value; | ||
| 79 | - try { | ||
| 80 | - value = Double.parseDouble(link.annotations().value(key)); | ||
| 81 | - } catch (NumberFormatException e) { | ||
| 82 | - value = 1.0; | ||
| 83 | - } | ||
| 84 | - return value; | ||
| 85 | - } | ||
| 86 | - | ||
| 87 | @Override | 70 | @Override |
| 88 | public double cost(Link link, LinkResourceService resourceService) { | 71 | public double cost(Link link, LinkResourceService resourceService) { |
| 89 | if (isValid(link, resourceService)) { | 72 | if (isValid(link, resourceService)) { | ... | ... |
| ... | @@ -26,6 +26,7 @@ import java.time.temporal.ChronoUnit; | ... | @@ -26,6 +26,7 @@ import java.time.temporal.ChronoUnit; |
| 26 | import java.util.Objects; | 26 | import java.util.Objects; |
| 27 | 27 | ||
| 28 | import static org.onlab.onos.net.AnnotationKeys.LATENCY; | 28 | import static org.onlab.onos.net.AnnotationKeys.LATENCY; |
| 29 | +import static org.onlab.onos.net.AnnotationKeys.getAnnotatedValue; | ||
| 29 | 30 | ||
| 30 | /** | 31 | /** |
| 31 | * Constraint that evaluates the latency through a path. | 32 | * Constraint that evaluates the latency through a path. |
| ... | @@ -48,16 +49,7 @@ public class LatencyConstraint implements Constraint { | ... | @@ -48,16 +49,7 @@ public class LatencyConstraint implements Constraint { |
| 48 | 49 | ||
| 49 | @Override | 50 | @Override |
| 50 | public double cost(Link link, LinkResourceService resourceService) { | 51 | public double cost(Link link, LinkResourceService resourceService) { |
| 51 | - String value = link.annotations().value(LATENCY); | 52 | + return getAnnotatedValue(link, LATENCY); |
| 52 | - | ||
| 53 | - double latencyInMicroSec; | ||
| 54 | - try { | ||
| 55 | - latencyInMicroSec = Double.parseDouble(value); | ||
| 56 | - } catch (NumberFormatException e) { | ||
| 57 | - latencyInMicroSec = 1.0; | ||
| 58 | - } | ||
| 59 | - | ||
| 60 | - return latencyInMicroSec; | ||
| 61 | } | 53 | } |
| 62 | 54 | ||
| 63 | @Override | 55 | @Override | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2014 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onlab.onos.net.flow; | ||
| 17 | + | ||
| 18 | +import java.util.concurrent.TimeUnit; | ||
| 19 | + | ||
| 20 | +import org.junit.Test; | ||
| 21 | +import org.onlab.onos.net.intent.IntentTestsMocks; | ||
| 22 | + | ||
| 23 | +import com.google.common.testing.EqualsTester; | ||
| 24 | + | ||
| 25 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
| 26 | +import static org.hamcrest.Matchers.greaterThan; | ||
| 27 | +import static org.hamcrest.Matchers.is; | ||
| 28 | +import static org.onlab.onos.net.NetTestTools.did; | ||
| 29 | + | ||
| 30 | +/** | ||
| 31 | + * Unit tests for the DefaultFlowEntry class. | ||
| 32 | + */ | ||
| 33 | +public class DefaultFlowEntryTest { | ||
| 34 | + private static final IntentTestsMocks.MockSelector SELECTOR = | ||
| 35 | + new IntentTestsMocks.MockSelector(); | ||
| 36 | + private static final IntentTestsMocks.MockTreatment TREATMENT = | ||
| 37 | + new IntentTestsMocks.MockTreatment(); | ||
| 38 | + | ||
| 39 | + private static DefaultFlowEntry makeFlowEntry(int uniqueValue) { | ||
| 40 | + return new DefaultFlowEntry(did("id" + Integer.toString(uniqueValue)), | ||
| 41 | + SELECTOR, | ||
| 42 | + TREATMENT, | ||
| 43 | + uniqueValue, | ||
| 44 | + FlowEntry.FlowEntryState.ADDED, | ||
| 45 | + uniqueValue, | ||
| 46 | + uniqueValue, | ||
| 47 | + uniqueValue, | ||
| 48 | + uniqueValue, | ||
| 49 | + uniqueValue); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + final DefaultFlowEntry defaultFlowEntry1 = makeFlowEntry(1); | ||
| 53 | + final DefaultFlowEntry sameAsDefaultFlowEntry1 = makeFlowEntry(1); | ||
| 54 | + final DefaultFlowEntry defaultFlowEntry2 = makeFlowEntry(2); | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * Tests the equals, hashCode and toString methods using Guava EqualsTester. | ||
| 58 | + */ | ||
| 59 | + @Test | ||
| 60 | + public void testEquals() { | ||
| 61 | + new EqualsTester() | ||
| 62 | + .addEqualityGroup(defaultFlowEntry1, sameAsDefaultFlowEntry1) | ||
| 63 | + .addEqualityGroup(defaultFlowEntry2) | ||
| 64 | + .testEquals(); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * Tests the construction of a default flow entry from a device id. | ||
| 69 | + */ | ||
| 70 | + @Test | ||
| 71 | + public void testDeviceBasedObject() { | ||
| 72 | + assertThat(defaultFlowEntry1.deviceId(), is(did("id1"))); | ||
| 73 | + assertThat(defaultFlowEntry1.selector(), is(SELECTOR)); | ||
| 74 | + assertThat(defaultFlowEntry1.treatment(), is(TREATMENT)); | ||
| 75 | + assertThat(defaultFlowEntry1.timeout(), is(1)); | ||
| 76 | + assertThat(defaultFlowEntry1.life(), is(1L)); | ||
| 77 | + assertThat(defaultFlowEntry1.packets(), is(1L)); | ||
| 78 | + assertThat(defaultFlowEntry1.bytes(), is(1L)); | ||
| 79 | + assertThat(defaultFlowEntry1.state(), is(FlowEntry.FlowEntryState.ADDED)); | ||
| 80 | + assertThat(defaultFlowEntry1.lastSeen(), | ||
| 81 | + greaterThan(System.currentTimeMillis() - | ||
| 82 | + TimeUnit.MILLISECONDS.convert(1, TimeUnit.SECONDS))); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * Tests the setters on a default flow entry object. | ||
| 87 | + */ | ||
| 88 | + @Test | ||
| 89 | + public void testSetters() { | ||
| 90 | + final DefaultFlowEntry entry = makeFlowEntry(1); | ||
| 91 | + | ||
| 92 | + entry.setLastSeen(); | ||
| 93 | + entry.setState(FlowEntry.FlowEntryState.PENDING_REMOVE); | ||
| 94 | + entry.setPackets(11); | ||
| 95 | + entry.setBytes(22); | ||
| 96 | + entry.setLife(33); | ||
| 97 | + | ||
| 98 | + assertThat(entry.deviceId(), is(did("id1"))); | ||
| 99 | + assertThat(entry.selector(), is(SELECTOR)); | ||
| 100 | + assertThat(entry.treatment(), is(TREATMENT)); | ||
| 101 | + assertThat(entry.timeout(), is(1)); | ||
| 102 | + assertThat(entry.life(), is(33L)); | ||
| 103 | + assertThat(entry.packets(), is(11L)); | ||
| 104 | + assertThat(entry.bytes(), is(22L)); | ||
| 105 | + assertThat(entry.state(), is(FlowEntry.FlowEntryState.PENDING_REMOVE)); | ||
| 106 | + assertThat(entry.lastSeen(), | ||
| 107 | + greaterThan(System.currentTimeMillis() - | ||
| 108 | + TimeUnit.MILLISECONDS.convert(1, TimeUnit.SECONDS))); | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + /** | ||
| 112 | + * Tests a default flow rule built for an error. | ||
| 113 | + */ | ||
| 114 | + @Test | ||
| 115 | + public void testErrorObject() { | ||
| 116 | + final DefaultFlowEntry errorEntry = | ||
| 117 | + new DefaultFlowEntry(new IntentTestsMocks.MockFlowRule(1), | ||
| 118 | + 111, | ||
| 119 | + 222); | ||
| 120 | + assertThat(errorEntry.errType(), is(111)); | ||
| 121 | + assertThat(errorEntry.errCode(), is(222)); | ||
| 122 | + assertThat(errorEntry.state(), is(FlowEntry.FlowEntryState.FAILED)); | ||
| 123 | + assertThat(errorEntry.lastSeen(), | ||
| 124 | + greaterThan(System.currentTimeMillis() - | ||
| 125 | + TimeUnit.MILLISECONDS.convert(1, TimeUnit.SECONDS))); | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + /** | ||
| 129 | + * Tests a default flow entry constructed from a flow rule. | ||
| 130 | + */ | ||
| 131 | + @Test | ||
| 132 | + public void testFlowBasedObject() { | ||
| 133 | + final DefaultFlowEntry entry = | ||
| 134 | + new DefaultFlowEntry(new IntentTestsMocks.MockFlowRule(1)); | ||
| 135 | + assertThat(entry.priority(), is(1)); | ||
| 136 | + assertThat(entry.appId(), is((short) 0)); | ||
| 137 | + assertThat(entry.lastSeen(), | ||
| 138 | + greaterThan(System.currentTimeMillis() - | ||
| 139 | + TimeUnit.MILLISECONDS.convert(1, TimeUnit.SECONDS))); | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + /** | ||
| 143 | + * Tests a default flow entry constructed from a flow rule plus extra | ||
| 144 | + * parameters. | ||
| 145 | + */ | ||
| 146 | + @Test | ||
| 147 | + public void testFlowBasedObjectWithParameters() { | ||
| 148 | + final DefaultFlowEntry entry = | ||
| 149 | + new DefaultFlowEntry(new IntentTestsMocks.MockFlowRule(33), | ||
| 150 | + FlowEntry.FlowEntryState.REMOVED, | ||
| 151 | + 101, 102, 103); | ||
| 152 | + assertThat(entry.state(), is(FlowEntry.FlowEntryState.REMOVED)); | ||
| 153 | + assertThat(entry.life(), is(101L)); | ||
| 154 | + assertThat(entry.packets(), is(102L)); | ||
| 155 | + assertThat(entry.bytes(), is(103L)); | ||
| 156 | + assertThat(entry.lastSeen(), | ||
| 157 | + greaterThan(System.currentTimeMillis() - | ||
| 158 | + TimeUnit.MILLISECONDS.convert(1, TimeUnit.SECONDS))); | ||
| 159 | + } | ||
| 160 | +} |
| ... | @@ -17,7 +17,6 @@ | ... | @@ -17,7 +17,6 @@ |
| 17 | package org.onlab.onos.net.flow; | 17 | package org.onlab.onos.net.flow; |
| 18 | 18 | ||
| 19 | import org.junit.Test; | 19 | import org.junit.Test; |
| 20 | -import org.onlab.onos.net.DeviceId; | ||
| 21 | import org.onlab.onos.net.intent.IntentTestsMocks; | 20 | import org.onlab.onos.net.intent.IntentTestsMocks; |
| 22 | 21 | ||
| 23 | import com.google.common.testing.EqualsTester; | 22 | import com.google.common.testing.EqualsTester; |
| ... | @@ -25,8 +24,8 @@ import com.google.common.testing.EqualsTester; | ... | @@ -25,8 +24,8 @@ import com.google.common.testing.EqualsTester; |
| 25 | import static org.hamcrest.MatcherAssert.assertThat; | 24 | import static org.hamcrest.MatcherAssert.assertThat; |
| 26 | import static org.hamcrest.Matchers.is; | 25 | import static org.hamcrest.Matchers.is; |
| 27 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass; | 26 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass; |
| 28 | -import static org.onlab.onos.net.NetTestTools.did; | ||
| 29 | import static org.onlab.onos.net.NetTestTools.APP_ID; | 27 | import static org.onlab.onos.net.NetTestTools.APP_ID; |
| 28 | +import static org.onlab.onos.net.NetTestTools.did; | ||
| 30 | 29 | ||
| 31 | /** | 30 | /** |
| 32 | * Unit tests for the default flow rule class. | 31 | * Unit tests for the default flow rule class. |
| ... | @@ -37,63 +36,13 @@ public class DefaultFlowRuleTest { | ... | @@ -37,63 +36,13 @@ public class DefaultFlowRuleTest { |
| 37 | private static final IntentTestsMocks.MockTreatment TREATMENT = | 36 | private static final IntentTestsMocks.MockTreatment TREATMENT = |
| 38 | new IntentTestsMocks.MockTreatment(); | 37 | new IntentTestsMocks.MockTreatment(); |
| 39 | 38 | ||
| 40 | - final FlowRule flowRule1 = new MockFlowRule(1); | 39 | + final FlowRule flowRule1 = new IntentTestsMocks.MockFlowRule(1); |
| 41 | - final FlowRule sameAsFlowRule1 = new MockFlowRule(1); | 40 | + final FlowRule sameAsFlowRule1 = new IntentTestsMocks.MockFlowRule(1); |
| 42 | - final FlowRule flowRule2 = new MockFlowRule(2); | 41 | + final FlowRule flowRule2 = new IntentTestsMocks.MockFlowRule(2); |
| 43 | final DefaultFlowRule defaultFlowRule1 = new DefaultFlowRule(flowRule1); | 42 | final DefaultFlowRule defaultFlowRule1 = new DefaultFlowRule(flowRule1); |
| 44 | final DefaultFlowRule sameAsDefaultFlowRule1 = new DefaultFlowRule(sameAsFlowRule1); | 43 | final DefaultFlowRule sameAsDefaultFlowRule1 = new DefaultFlowRule(sameAsFlowRule1); |
| 45 | final DefaultFlowRule defaultFlowRule2 = new DefaultFlowRule(flowRule2); | 44 | final DefaultFlowRule defaultFlowRule2 = new DefaultFlowRule(flowRule2); |
| 46 | 45 | ||
| 47 | - private static class MockFlowRule implements FlowRule { | ||
| 48 | - | ||
| 49 | - int priority; | ||
| 50 | - MockFlowRule(int priority) { | ||
| 51 | - this.priority = priority; | ||
| 52 | - } | ||
| 53 | - | ||
| 54 | - @Override | ||
| 55 | - public FlowId id() { | ||
| 56 | - return FlowId.valueOf(1); | ||
| 57 | - } | ||
| 58 | - | ||
| 59 | - @Override | ||
| 60 | - public short appId() { | ||
| 61 | - return 0; | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - @Override | ||
| 65 | - public int priority() { | ||
| 66 | - return priority; | ||
| 67 | - } | ||
| 68 | - | ||
| 69 | - @Override | ||
| 70 | - public DeviceId deviceId() { | ||
| 71 | - return did("1"); | ||
| 72 | - } | ||
| 73 | - | ||
| 74 | - @Override | ||
| 75 | - public TrafficSelector selector() { | ||
| 76 | - return SELECTOR; | ||
| 77 | - } | ||
| 78 | - | ||
| 79 | - @Override | ||
| 80 | - public TrafficTreatment treatment() { | ||
| 81 | - return TREATMENT; | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - @Override | ||
| 85 | - public int timeout() { | ||
| 86 | - return 0; | ||
| 87 | - } | ||
| 88 | - | ||
| 89 | - @Override | ||
| 90 | - public boolean isPermanent() { | ||
| 91 | - return false; | ||
| 92 | - } | ||
| 93 | - | ||
| 94 | - | ||
| 95 | - } | ||
| 96 | - | ||
| 97 | /** | 46 | /** |
| 98 | * Checks that the DefaultFlowRule class is immutable but can be inherited | 47 | * Checks that the DefaultFlowRule class is immutable but can be inherited |
| 99 | * from. | 48 | * from. | ... | ... |
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | package org.onlab.onos.net.intent; | 16 | package org.onlab.onos.net.intent; |
| 17 | 17 | ||
| 18 | import static org.onlab.onos.net.NetTestTools.createPath; | 18 | import static org.onlab.onos.net.NetTestTools.createPath; |
| 19 | +import static org.onlab.onos.net.NetTestTools.did; | ||
| 19 | import static org.onlab.onos.net.NetTestTools.link; | 20 | import static org.onlab.onos.net.NetTestTools.link; |
| 20 | 21 | ||
| 21 | import java.util.ArrayList; | 22 | import java.util.ArrayList; |
| ... | @@ -31,6 +32,8 @@ import org.onlab.onos.net.DeviceId; | ... | @@ -31,6 +32,8 @@ import org.onlab.onos.net.DeviceId; |
| 31 | import org.onlab.onos.net.ElementId; | 32 | import org.onlab.onos.net.ElementId; |
| 32 | import org.onlab.onos.net.Link; | 33 | import org.onlab.onos.net.Link; |
| 33 | import org.onlab.onos.net.Path; | 34 | import org.onlab.onos.net.Path; |
| 35 | +import org.onlab.onos.net.flow.FlowId; | ||
| 36 | +import org.onlab.onos.net.flow.FlowRule; | ||
| 34 | import org.onlab.onos.net.flow.TrafficSelector; | 37 | import org.onlab.onos.net.flow.TrafficSelector; |
| 35 | import org.onlab.onos.net.flow.TrafficTreatment; | 38 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 36 | import org.onlab.onos.net.flow.criteria.Criterion; | 39 | import org.onlab.onos.net.flow.criteria.Criterion; |
| ... | @@ -271,4 +274,60 @@ public class IntentTestsMocks { | ... | @@ -271,4 +274,60 @@ public class IntentTestsMocks { |
| 271 | } | 274 | } |
| 272 | } | 275 | } |
| 273 | 276 | ||
| 277 | + private static final IntentTestsMocks.MockSelector SELECTOR = | ||
| 278 | + new IntentTestsMocks.MockSelector(); | ||
| 279 | + private static final IntentTestsMocks.MockTreatment TREATMENT = | ||
| 280 | + new IntentTestsMocks.MockTreatment(); | ||
| 281 | + | ||
| 282 | + public static class MockFlowRule implements FlowRule { | ||
| 283 | + | ||
| 284 | + int priority; | ||
| 285 | + public MockFlowRule(int priority) { | ||
| 286 | + this.priority = priority; | ||
| 287 | + } | ||
| 288 | + | ||
| 289 | + @Override | ||
| 290 | + public FlowId id() { | ||
| 291 | + return FlowId.valueOf(1); | ||
| 292 | + } | ||
| 293 | + | ||
| 294 | + @Override | ||
| 295 | + public short appId() { | ||
| 296 | + return 0; | ||
| 297 | + } | ||
| 298 | + | ||
| 299 | + @Override | ||
| 300 | + public int priority() { | ||
| 301 | + return priority; | ||
| 302 | + } | ||
| 303 | + | ||
| 304 | + @Override | ||
| 305 | + public DeviceId deviceId() { | ||
| 306 | + return did("1"); | ||
| 307 | + } | ||
| 308 | + | ||
| 309 | + @Override | ||
| 310 | + public TrafficSelector selector() { | ||
| 311 | + return SELECTOR; | ||
| 312 | + } | ||
| 313 | + | ||
| 314 | + @Override | ||
| 315 | + public TrafficTreatment treatment() { | ||
| 316 | + return TREATMENT; | ||
| 317 | + } | ||
| 318 | + | ||
| 319 | + @Override | ||
| 320 | + public int timeout() { | ||
| 321 | + return 0; | ||
| 322 | + } | ||
| 323 | + | ||
| 324 | + @Override | ||
| 325 | + public boolean isPermanent() { | ||
| 326 | + return false; | ||
| 327 | + } | ||
| 328 | + | ||
| 329 | + | ||
| 330 | + } | ||
| 331 | + | ||
| 332 | + | ||
| 274 | } | 333 | } | ... | ... |
| ... | @@ -72,7 +72,7 @@ public class DatabaseManager implements DatabaseService, DatabaseAdminService { | ... | @@ -72,7 +72,7 @@ public class DatabaseManager implements DatabaseService, DatabaseAdminService { |
| 72 | public static final String LOG_FILE_PREFIX = "/tmp/onos-copy-cat-log_"; | 72 | public static final String LOG_FILE_PREFIX = "/tmp/onos-copy-cat-log_"; |
| 73 | 73 | ||
| 74 | // Current working dir seems to be /opt/onos/apache-karaf-3.0.2 | 74 | // Current working dir seems to be /opt/onos/apache-karaf-3.0.2 |
| 75 | - // TODO: Get the path to /opt/onos/config | 75 | + // TODO: Set the path to /opt/onos/config |
| 76 | private static final String CONFIG_DIR = "../config"; | 76 | private static final String CONFIG_DIR = "../config"; |
| 77 | 77 | ||
| 78 | private static final String DEFAULT_MEMBER_FILE = "tablets.json"; | 78 | private static final String DEFAULT_MEMBER_FILE = "tablets.json"; | ... | ... |
| ... | @@ -197,6 +197,8 @@ | ... | @@ -197,6 +197,8 @@ |
| 197 | <feature name="onos-app-sdnip" version="1.0.0" | 197 | <feature name="onos-app-sdnip" version="1.0.0" |
| 198 | description="SDN-IP peering application"> | 198 | description="SDN-IP peering application"> |
| 199 | <feature>onos-api</feature> | 199 | <feature>onos-api</feature> |
| 200 | + <feature>onos-app-proxyarp</feature> | ||
| 201 | + <feature>onos-app-config</feature> | ||
| 200 | <bundle>mvn:org.onlab.onos/onos-app-sdnip/1.0.0-SNAPSHOT</bundle> | 202 | <bundle>mvn:org.onlab.onos/onos-app-sdnip/1.0.0-SNAPSHOT</bundle> |
| 201 | </feature> | 203 | </feature> |
| 202 | 204 | ... | ... |
-
Please register or login to post a comment